1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
  
     | 
    
      {%MainUnit ../comctrls.pp}
{******************************************************************************
                                  TCustomTrackBar
 ******************************************************************************
 *****************************************************************************
  This file is part of the Lazarus Component Library (LCL)
  See the file COPYING.modifiedLGPL.txt, included in this distribution,
  for details about the license.
 *****************************************************************************
  current design flaws:
  - I decided to support some gtk-specific properties in this class. This
    won't break Delphi compatibility but for 100% Delphi compatibility
    a better approach would be to derive another class.
    BTW: When porting to another widget library you can safely ignore
           FScalePosition, FScaleDigits
  Delphi compatibility:
   - the interface is almost like in delphi 4
   - some Delphi properties are not supported by GTK and are currently not
     implemented here, These are:
       frequency, tickstyle and tickmark
   - what about these private procs
      procedure CNHScroll(var Message: TWMHScroll); message CN_HSCROLL;
      procedure CNVScroll(var Message: TWMVScroll); message CN_VSCROLL;
   - there is a new property which I've implemented because it is a
     nice addon for the GTK interface
      * ScalePos (left, top, right, bottom)
  TODO:
    - implement some more Delphi stuff
    - range checking for min/max could raise an exception
    - use RecreateWnd when the orientation changes!
}
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.Create
  Params:  AOwner: the owner of the class
  Returns: Nothing
  Constructor for the trackbar.
 ------------------------------------------------------------------------------}
constructor TCustomTrackBar.Create (AOwner : TComponent);
begin
  inherited Create (aOwner);
  fCompStyle := csTrackbar;
  ControlStyle := ControlStyle - [csCaptureMouse];
  FLineSize := 1;
  FMax := 10;
  FMin := 0;
  FPosition := 0;
  FPageSize := 2;
  FFrequency := 1;
  FOrientation := trHorizontal;
  FScalePos := trTop;
  FScaleDigits := 0;
  FTickMarks := tmBottomRight;
  FTickStyle := tsAuto;
  FSelStart := 0;
  FSelEnd := 0;
  FShowSelRange := True;
  FReversed := False;
  TabStop := True;
  with GetControlClassDefaultSize do
    SetInitialBounds(0, 0, CX, CY);
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.InitializeWnd
  Params: none
  Returns: Nothing
  Set all properties after visual component has been created. Will be called
  from TWinControl.
 ------------------------------------------------------------------------------}
procedure TCustomTrackBar.InitializeWnd;
begin
  inherited InitializeWnd;
  ApplyChanges;
end;
procedure TCustomTrackBar.Loaded;
begin
  inherited Loaded;
  ApplyChanges;
end;
procedure TCustomTrackBar.ShouldAutoAdjust(var AWidth, AHeight: Boolean);
begin
  if Orientation = trHorizontal then
    begin
      AWidth := True;
      AHeight := not AutoSize;
    end
  else
    begin
      AWidth := not AutoSize;
      AHeight := True;
    end
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.SetTick
  Params: Value : new tick
  Returns: Nothing
 ------------------------------------------------------------------------------}
procedure TCustomTrackBar.SetTick(Value: Integer);
begin
  if HandleAllocated then
    TWSTrackBarClass(WidgetSetClass).SetTick(Self, Value);
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.SetOrientation
  Params: Value : new orientation
  Returns: Nothing
  Change the orientation of the trackbar.
------------------------------------------------------------------------------}
procedure TCustomTrackBar.SetOrientation(Value: TTrackBarOrientation);
var
  OldWidth: LongInt;
  OldHeight: LongInt;
begin
  if FOrientation <> Value then
  begin
    FOrientation := Value;
    // switch width and height, but not when loading, because we assume that the
    // lfm contains a consistent combination of Orientation and (width, height)
    if not (csLoading in ComponentState) then
    begin
      OldWidth:=Width;
      OldHeight:=Height;
      Constraints.UpdateInterfaceConstraints;
      SetBounds(Left,Top,OldHeight,OldWidth);
      if HandleAllocated then
        TWSTrackBarClass(WidgetSetClass).SetOrientation(Self, FOrientation);
    end;
  end;
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.SetParams
  Params:  APosition : new position
           AMin      : new minimum
           AMax      : new maximum
  Returns: Nothing
  Set new parameters for the trackbar.
 ------------------------------------------------------------------------------}
procedure TCustomTrackBar.SetParams(APosition, AMin, AMax: Integer);
begin
  if not (csLoading in ComponentState) then
    FixParams(APosition, AMin, AMax);
  if (FPosition = APosition) and (FMin = AMin) and (FMax = AMax) then
    Exit;
  FPosition := APosition;
  FMax := AMax;
  FMin := AMin;
  ApplyChanges;
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.SetPosition
  Params: Value : new position
  Returns: Nothing
  Set actual position of the trackbar.
 ------------------------------------------------------------------------------}
procedure TCustomTrackBar.SetPosition(Value: Integer);
begin
  FixParams(Value, FMin, FMax);
  if FPosition <> Value then
  begin
    FPosition := Value;
    if HandleAllocated then
      TWSTrackBarClass(WidgetSetClass).SetPosition(Self, FPosition);
    if not (csLoading in ComponentState) then 
      Changed;
  end;
end;
procedure TCustomTrackBar.SetReversed(const AValue: Boolean);
begin
  if FReversed <> AValue then
  begin
    FReversed := AValue;
    ApplyChanges;
  end;
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.SetMin
  Params: Value : new minimum
  Returns: Nothing
  Set minimum value of the trackbar.
 ------------------------------------------------------------------------------}
procedure TCustomTrackBar.SetMin(Value: Integer);
begin
  if FMin <> Value then
    SetParams(FPosition, Value, FMax);
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.SetMax
  Params: Value : new maximum
  Returns: Nothing
  Set maximum value of the trackbar.
 ------------------------------------------------------------------------------}
procedure TCustomTrackBar.SetMax(Value: Integer);
begin
  if FMax <> Value then
    SetParams(FPosition, FMin, Value);
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.SetFrequency
  Params: Value : new frequency
  Returns: Nothing
 ------------------------------------------------------------------------------}
procedure TCustomTrackBar.SetFrequency(Value: Integer);
begin
  if FFrequency <> Value then
  begin
    FFrequency := Value;
    ApplyChanges;
  end;
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.SetTickStyle
  Params: Value : new tickstyle
  Returns: Nothing
 ------------------------------------------------------------------------------}
procedure TCustomTrackBar.SetTickStyle(Value: TTickStyle);
begin
  if FTickStyle <> Value then
  begin
    FTickStyle := Value;
    ApplyChanges;
    Constraints.UpdateInterfaceConstraints;
    DoAutoSize;
    if HandleAllocated then
      TWSTrackBarClass(WidgetSetClass).SetTickStyle(Self, FTickStyle);
  end;
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.SetTickMarks
  Params: Value : new tickmarks
  Returns: Nothing
 ------------------------------------------------------------------------------}
procedure TCustomTrackBar.SetTickMarks(Value: TTickMark);
begin
  if FTickMarks <> Value then
  begin
    FTickMarks := Value;
    ApplyChanges;
  end;
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.SetLineSize
  Params: Value : new linesize
  Returns: Nothing
  Set the increment which is used when one of the arrow-keys is pressed.
 ------------------------------------------------------------------------------}
procedure TCustomTrackBar.SetLineSize(Value: Integer);
begin
  if FLineSize <> Value then
  begin
    FLineSize := Value;
    ApplyChanges;
  end
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.SetPageSize
  Params:  Value : new pagesize
  Returns: Nothing
  Set the increment which is used when one of the arrow-keys is pressed together
  with a modifier or when PgUp/PgDwn are pressed.
 ------------------------------------------------------------------------------}
procedure TCustomTrackBar.SetPageSize(Value: Integer);
begin
  if FPageSize <> Value then
  begin
    FPageSize := Value;
    ApplyChanges;
  end;
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.UpdateSelection
  Params:
  Returns: Nothing
 ------------------------------------------------------------------------------}
procedure TCustomTrackBar.UpdateSelection;
begin
end;
class procedure TCustomTrackBar.WSRegisterClass;
begin
  inherited WSRegisterClass;
  RegisterCustomTrackBar;
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.ApplyChanges
  Params: none
  Returns: Nothing
  Sends message to update the visual apperance of the object.
 ------------------------------------------------------------------------------}
procedure TCustomTrackBar.ApplyChanges;
begin
  if HandleAllocated and (not (csLoading in ComponentState)) then
    TWSTrackBarClass(WidgetSetClass).ApplyChanges(Self);
end;
procedure TCustomTrackBar.Changed;
begin
  if Assigned (FOnChange) then
    FOnChange(Self);
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.DoChange
  Params:  Msg  (longint = LM_CHANGE)
  Returns: Nothing
  Update position and call user's callback for Change event.
 ------------------------------------------------------------------------------}
procedure TCustomTrackBar.DoChange(var msg);
begin
  FPosition := TWSTrackBarClass(WidgetSetClass).GetPosition(Self);
  Assert(True, 'Trace:Trackbar received a message -CHANGE');
  if [csLoading,csDestroying,csDesigning]*ComponentState<>[] then
    Exit;
  EditingDone;
  Changed;
end;
procedure TCustomTrackBar.FixParams(var APosition, AMin, AMax: Integer);
begin
  if AMin > AMax then AMin := AMax;
  if APosition < AMin then APosition := AMin;
  if APosition > AMax then APosition := AMax;
end;
class function TCustomTrackBar.GetControlClassDefaultSize: TSize;
begin
  Result.CX := 100;
  Result.CY := 25;
end;
{------------------------------------------------------------------------------
  Method: TCustomTrackBar.SetScalePos
  Params:  value : position of the scaling text
  Returns: Nothing
 ------------------------------------------------------------------------------}
procedure TCustomTrackBar.SetScalePos(Value: TTrackBarScalePos);
begin
  if FScalePos <> Value then
  begin
    FScalePos := Value;
    ApplyChanges;
  end;
end;
procedure TCustomTrackBar.SetSelEnd(const AValue: Integer);
begin
  if FSelEnd <> AValue then
  begin
    FSelEnd := AValue;
    ApplyChanges;
  end;
end;
procedure TCustomTrackBar.SetSelStart(const AValue: Integer);
begin
  if FSelStart <> AValue then
  begin
    FSelStart := AValue;
    ApplyChanges;
  end;
end;
procedure TCustomTrackBar.SetShowSelRange(const AValue: Boolean);
begin
  if FShowSelRange <> AValue then
  begin
    FShowSelRange := AValue;
    ApplyChanges;
  end;
end;
 
     |