/usr/lib/lazarus/0.9.30.4/lcl/pairsplitter.pas is in lazarus-src-0.9.30.4 0.9.30.4-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | { $Id: pairsplitter.pas 31082 2011-06-04 15:49:35Z juha $ }
{
/***************************************************************************
pairsplitter.pas
----------------
Component Library Controls
***************************************************************************/
*****************************************************************************
* *
* This file is part of the Lazarus Component Library (LCL) *
* *
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
Author: Mattias Gaertner
Abstract:
TPairSplitter component. A component with two TPairSplitterSide children.
Both child components can contain other components and the children are
divided by a splitter which can be dragged by the user.
}
unit PairSplitter;
{$mode objfpc}{$H+}
interface
uses
Types, Classes, SysUtils,
LCLType, LCLProc, LMessages, Graphics, GraphType, LCLIntf, Controls, ExtCtrls;
type
TCustomPairSplitter = class;
{ TPairSplitterSide }
TPairSplitterSide = class(TWinControl)
private
fCreatedBySplitter: boolean;
function GetSplitter: TCustomPairSplitter;
protected
class procedure WSRegisterClass; override;
procedure SetParent(AParent: TWinControl); override;
procedure WMPaint(var PaintMessage: TLMPaint); message LM_PAINT;
procedure Paint; virtual;
property Align;
property Anchors;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
public
property Splitter: TCustomPairSplitter read GetSplitter;
property Visible;
property Left;
property Top;
property Width;
property Height;
published
property ChildSizing;
property ClientWidth;
property ClientHeight;
property Cursor;
property Enabled;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property ShowHint;
property ParentShowHint;
property PopupMenu;
end;
{ TCustomPairSplitter }
TPairSplitterType = (
pstHorizontal,
pstVertical
);
TCustomPairSplitter = class(TWinControl)
private
FPosition: integer;
FSides: array[0..1] of TPairSplitterSide;
FSplitterType: TPairSplitterType;
FDoNotCreateSides: boolean;
FLoadCursor: TCursor;
function GetPosition: integer;
function GetSides(Index: integer): TPairSplitterSide;
procedure SetPosition(const AValue: integer);
procedure SetSplitterType(const AValue: TPairSplitterType);
procedure AddSide(ASide: TPairSplitterSide);
procedure RemoveSide(ASide: TPairSplitterSide);
protected
class procedure WSRegisterClass; override;
function GetCursor: TCursor; override;
procedure SetCursor(Value: TCursor); override;
class function GetControlClassDefaultSize: TSize; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure CreateWnd; override;
procedure UpdatePosition;
procedure CreateSides;
procedure Loaded; override;
function ChildClassAllowed(ChildClass: TClass): boolean; override;
public
property Cursor default crHSplit;
property Sides[Index: integer]: TPairSplitterSide read GetSides;
property SplitterType: TPairSplitterType read FSplitterType
write SetSplitterType default pstHorizontal;
property Position: integer read GetPosition write SetPosition;
end;
{ TPairSplitter }
TPairSplitter = class(TCustomPairSplitter)
published
property Align;
property Anchors;
property BorderSpacing;
property Cursor;
property Enabled;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnChangeBounds;
property ParentShowHint;
property PopupMenu;
property Position;
property ShowHint;
property SplitterType;
property Visible;
end;
procedure Register;
implementation
uses
WSPairSplitter;
procedure Register;
begin
RegisterComponents('Additional',[TPairSplitter]);
RegisterNoIcon([TPairSplitterSide]);
end;
{ TPairSplitterSide }
function TPairSplitterSide.GetSplitter: TCustomPairSplitter;
begin
if (Parent<>nil) and (Parent is TCustomPairSplitter) then
Result:=TCustomPairSplitter(Parent)
else
Result:=nil;
end;
class procedure TPairSplitterSide.WSRegisterClass;
begin
inherited WSRegisterClass;
RegisterPairSplitterSide;
end;
procedure TPairSplitterSide.SetParent(AParent: TWinControl);
var
ASplitter: TCustomPairSplitter;
begin
CheckNewParent(AParent);
// remove from side list of old parent
ASplitter := Splitter;
if ASplitter <> nil then
ASplitter.RemoveSide(Self);
inherited SetParent(AParent);
// add to side list of new parent
ASplitter:=Splitter;
if ASplitter <> nil then
ASplitter.AddSide(Self);
end;
procedure TPairSplitterSide.WMPaint(var PaintMessage: TLMPaint);
begin
if (csDestroying in ComponentState) or (not HandleAllocated) then
Exit;
Include(FControlState, csCustomPaint);
inherited WMPaint(PaintMessage);
Paint;
Exclude(FControlState, csCustomPaint);
end;
procedure TPairSplitterSide.Paint;
var
ACanvas: TControlCanvas;
begin
if csDesigning in ComponentState then
begin
ACanvas := TControlCanvas.Create;
with ACanvas do
begin
Control := Self;
Pen.Style := psDash;
Frame(0,0,Width-1,Height-1);
Free;
end;
end;
end;
constructor TPairSplitterSide.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FCompStyle := csPairSplitterSide;
ControlStyle := ControlStyle + [csAcceptsControls];
end;
destructor TPairSplitterSide.Destroy;
begin
inherited Destroy;
end;
{ TCustomPairSplitter }
function TCustomPairSplitter.GetSides(Index: integer): TPairSplitterSide;
begin
if (Index < 0) or (Index > 1) then
RaiseGDBException('TCustomPairSplitter.GetSides: Index out of bounds');
Result := FSides[Index];
end;
function TCustomPairSplitter.GetPosition: integer;
begin
if HandleAllocated and (not (csLoading in ComponentState)) then
UpdatePosition;
Result := FPosition;
end;
procedure TCustomPairSplitter.SetPosition(const AValue: integer);
begin
if FPosition = AValue then
Exit;
FPosition := AValue;
if FPosition < 0 then
FPosition := 0;
if HandleAllocated and (not (csLoading in ComponentState)) then
TWSCustomPairSplitterClass(WidgetSetClass).SetPosition(Self, FPosition);
end;
procedure TCustomPairSplitter.SetSplitterType(const AValue: TPairSplitterType);
const
DefaultCursors: array[TPairSplitterType] of TCursor =
(
{ pstHorizontal } crHSplit,
{ pstVertical } crVSplit
);
begin
if FSplitterType = AValue then
Exit;
if Cursor = DefaultCursors[FSplitterType] then
Cursor := DefaultCursors[AValue];
FSplitterType := AValue;
// TODO: Remove RecreateWnd
if HandleAllocated then
RecreateWnd(Self);
end;
procedure TCustomPairSplitter.AddSide(ASide: TPairSplitterSide);
var
i: Integer;
begin
if ASide = nil then
Exit;
i := Low(FSides);
repeat
if FSides[i] = ASide then
Exit;
if FSides[i] =nil then
begin
FSides[i] := ASide;
if HandleAllocated then
TWSCustomPairSplitterClass(WidgetSetClass).AddSide(Self, ASide, i);
break;
end;
inc(i);
if i > High(FSides) then
RaiseGDBException('TCustomPairSplitter.AddSide no free side left');
until False;
end;
procedure TCustomPairSplitter.RemoveSide(ASide: TPairSplitterSide);
var
i: Integer;
begin
if ASide = nil then
Exit;
for i := Low(FSides) to High(FSides) do
if FSides[i]=ASide then
begin
if HandleAllocated and ASide.HandleAllocated then
TWSCustomPairSplitterClass(WidgetSetClass).RemoveSide(Self, ASide, i);
FSides[i] := nil;
end;
// if the user deletes a side at designtime, autocreate a new one
if (csDesigning in ComponentState) then
CreateSides;
end;
class procedure TCustomPairSplitter.WSRegisterClass;
begin
inherited WSRegisterClass;
RegisterCustomPairSplitter;
end;
function TCustomPairSplitter.GetCursor: TCursor;
begin
// Paul Ishenin: I do not know another method to tell internal splitter about
// cursor changes
// if widgetset class do not want to get cursor (has no internal splitter) then
// use default lcl handler
if not TWSCustomPairSplitterClass(WidgetSetClass).GetSplitterCursor(Self, Result) then
Result := inherited GetCursor;
end;
procedure TCustomPairSplitter.SetCursor(Value: TCursor);
begin
FLoadCursor := Value;
if not HandleAllocated then
Exit;
// if widgetset class do not want to set cursor (has no internal splitter) then
// use default lcl handler
if not TWSCustomPairSplitterClass(WidgetSetClass).SetSplitterCursor(Self, Value) then
inherited SetCursor(Value);
end;
class function TCustomPairSplitter.GetControlClassDefaultSize: TSize;
begin
Result.CX := 90;
Result.CY := 90;
end;
constructor TCustomPairSplitter.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FCompStyle := csPairSplitter;
ControlStyle := ControlStyle - [csAcceptsControls];
FSplitterType := pstHorizontal;
Cursor := crHSplit;
with GetControlClassDefaultSize do
SetInitialBounds(0, 0, CX, CY);
FPosition:=45;
if not (csDesigning in ComponentState) then
CreateSides;
end;
destructor TCustomPairSplitter.Destroy;
var
i: Integer;
begin
// destroy the sides
fDoNotCreateSides:=true;
for i:=Low(FSides) to High(FSides) do
if (FSides[i]<>nil) and (FSides[i].fCreatedBySplitter) then
FSides[i].Free;
inherited Destroy;
end;
procedure TCustomPairSplitter.CreateWnd;
var
i: Integer;
APosition: Integer;
begin
CreateSides;
inherited CreateWnd;
for i := Low(FSides) to High(FSides) do
if FSides[i] <> nil then
TWSCustomPairSplitterClass(WidgetSetClass).AddSide(Self, FSides[i], i);
APosition := FPosition;
TWSCustomPairSplitterClass(WidgetSetClass).SetPosition(Self, APosition);
SetCursor(FLoadCursor);
if not (csLoading in ComponentState) then
FPosition := APosition;
end;
procedure TCustomPairSplitter.UpdatePosition;
var
CurPosition: Integer;
begin
if HandleAllocated then
begin
CurPosition := -1;
TWSCustomPairSplitterClass(WidgetSetClass).SetPosition(Self, CurPosition);
FPosition := CurPosition;
end;
end;
procedure TCustomPairSplitter.CreateSides;
var
ASide: TPairSplitterSide;
i: Integer;
begin
if fDoNotCreateSides or (csDestroying in ComponentState)
or (csLoading in ComponentState)
or ((Owner<>nil) and (csLoading in Owner.ComponentState)) then exit;
// create the missing side controls
for i := Low(FSides) to High(FSides) do
if FSides[i]=nil then
begin
// For streaming it is important that the side controls are owned by
// the owner of the splitter
ASide:=TPairSplitterSide.Create(Owner);
ASide.fCreatedBySplitter:=true;
ASide.Parent:=Self;
end;
end;
procedure TCustomPairSplitter.Loaded;
begin
inherited Loaded;
CreateSides;
if HandleAllocated then
TWSCustomPairSplitterClass(WidgetSetClass).SetPosition(Self, FPosition);
end;
function TCustomPairSplitter.ChildClassAllowed(ChildClass: TClass): boolean;
begin
Result := ChildClass.InheritsFrom(TPairSplitterSide) or
ChildClass.InheritsFrom(TSplitter);
end;
end.
|