File: muicomctrls.pas

package info (click to toggle)
lazarus 2.2.6%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 219,980 kB
  • sloc: pascal: 1,944,919; xml: 357,634; makefile: 270,608; cpp: 57,115; sh: 3,249; java: 609; perl: 297; sql: 222; ansic: 137
file content (596 lines) | stat: -rw-r--r-- 15,298 bytes parent folder | download | duplicates (7)
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
{
 *****************************************************************************
 *                             muicomctrls.pas                               *
 *                              --------------                               *
 *                              MUI ComControls                              *
 *                                                                           *
 *****************************************************************************

 *****************************************************************************
  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.
 *****************************************************************************
}
unit muicomctrls;
{$mode objfpc}{$H+}
interface

uses
  controls, muibaseunit, mui, exec, utility, sysutils, strings, Intuition, Types,
  ComCtrls, LCLMessageGlue, LMessages, LCLType, graphics, Math, tagsparamshelper;

type

  { TMUIGauge }

  TMUIGauge = class(TMUIArea)
  private
    FMinPos: Integer;
    FMaxPos: Integer;
    FShowText: Boolean;
    Text: string;
    function GetMaxPos: Integer;
    function GetMinPos: Integer;
    function GetPosition: Integer;
    function GetShowText: boolean;
    procedure SetMaxPos(AValue: Integer);
    procedure SetMinPos(AValue: Integer);
    procedure SetPosition(AValue: Integer);
    procedure SetShowText(AValue: boolean);
    procedure UpdateText;
  public
    Horiz: Boolean;
    constructor Create(AClassName: PChar; const Tags: TATagList); override;
    property Position: Integer read GetPosition write SetPosition;
    property MinPos: Integer read GetMinPos write SetMinPos;
    property MaxPos: Integer read GetMaxPos write SetMaxPos;
    property ShowText: boolean read GetShowText write SetShowText;
  end;

  TMUIBusy = class(TMUIArea)
  private
  public
    constructor Create(AClassName: PChar; const Tags: TATagList); override;
  end;

  TMUIGroup = class(TMUIArea)
  protected
    procedure BasicInitOnCreate(); override;
    procedure InstallHooks; override;
    function GetActivePage: Integer; virtual;
    procedure SetActivePage(AValue: Integer); virtual;
  public
    procedure SetOwnSize; override;
    property ActivePage: Integer read GetActivePage write SetActivePage;
  end;

  TMUIRegister = class(TMUIGroup)
  private
    FActivePage: Integer;
    FTexts: TMUIGroup;
    FRegisterHeight: Integer;
  protected
    procedure BasicInitOnCreate(); override;
    procedure SetParent(const AValue: TMUIObject); override;
    procedure InstallHooks; override;
    procedure SetLeft(ALeft: Integer); override;
    procedure SetTop(ATop: Integer); override;
    procedure SetWidth(AWidth: Integer); override;
    procedure SetHeight(AHeight: Integer); override;
    function GetHeight: Integer; override;
    function GetActivePage: Integer; override;
    procedure SetActivePage(AValue: Integer); override;
    procedure SetVisible(const AValue: boolean); override;
    procedure SetEnabled(const AValue: boolean); override;
    procedure SetColor(const AValue: TColor); override;
    function GetRegisterHeight: Integer;
    function GetPagesNum: Integer;
  public
    ShowTabs: Boolean;
    FNames: array[0..100] of PChar;
    constructor Create(AClassName: PChar; const Tags: TATagList); overload; reintroduce; virtual;
    destructor Destroy; override;
    procedure AddChild(ChildObj: PObject_); override;
    property RegisterHeight: Integer read GetRegisterHeight;
    property NumPages: Integer read GetPagesNum;
  end;

  TMUINumeric = class(TMUIGroup)
  protected
    procedure SetMinValue(AValue: Integer); virtual;
    procedure SetMaxValue(AValue: Integer); virtual;
    procedure SetValue(AValue: Integer); virtual;
    function GetMinValue: Integer; virtual;
    function GetMaxValue: Integer; virtual;
    function GetValue: Integer; virtual;
  public
    constructor Create(AClassName: PChar; const TagList: TATagList); overload; reintroduce; virtual;
    property MinValue: LongInt read GetMinValue write SetMinValue;
    property MaxValue: LongInt read GetMaxValue write SetMaxValue;
    property Value: LongInt read GetValue write SetValue;
  end;

  TMUISlider = class(TMUINumeric)
  private
    FHoriz: Boolean;
  protected
    procedure SetWidth(AWidth: Integer); override;
    procedure SetHeight(AHeight: Integer); override;
    procedure SetHorizontal(AValue: Boolean); virtual;
    function GetHorizontal: Boolean; virtual;
  public
    property Horizontal: Boolean read GetHorizontal write SetHorizontal;
  end;



implementation

{ TMUIGauge }

constructor TMUIGauge.Create(AClassName: PChar; const Tags: TATagList);
begin
  inherited;
  FMinPos := 0;
  FMaxPos := 100;
end;

function TMUIGauge.GetMaxPos: Integer;
begin
  Result := GetAttribute(MUIA_Gauge_Max) + FMinPos;
end;

function TMUIGauge.GetMinPos: Integer;
begin
  Result := FMinPos;
end;

function TMUIGauge.GetPosition: Integer;
begin
  Result := GetAttribute(MUIA_Gauge_Current) + FMinPos;
end;

function TMUIGauge.GetShowText: boolean;
begin
  Result := FShowText;
end;

procedure TMUIGauge.SetMaxPos(AValue: Integer);
begin
  FMaxPos := AValue;
  if FMaxPos - FMinPos > 0 then
  begin
    SetAttribute(MUIA_Gauge_Max, FMaxPos - FMinPos);
    if FShowText then
      UpdateText;
  end;
end;

procedure TMUIGauge.SetMinPos(AValue: Integer);
begin
  FMinPos := AValue;
  SetMaxPos(FMaxPos);
end;

procedure TMUIGauge.SetPosition(AValue: Integer);
begin
  SetAttribute(MUIA_Gauge_Current, AValue - FMinPos);
  if FShowText then
    UpdateText;
end;

procedure TMUIGauge.SetShowText(AValue: boolean);
begin
  FShowText := AValue;
  UpdateText;
end;

procedure TMUIGauge.UpdateText;
var
  Pos: Integer;
begin
  Text := '';
  if FShowText and ((FMaxPos - FMinPos) > 0) then
  begin
    Pos := Position;
    if not Horiz then
      Text := IntToStr(Pos)
    else
      Text := IntToStr(Pos) + ' from ['+IntToStr(FMinPos)+'-'+IntToStr(FMaxPos)+']('+IntToStr(Round(100*(Pos/(FMaxPos-FMinPos))))+'%%)'
  end;
  SetAttribute(MUIA_Gauge_InfoText, PChar(Text));
end;

{ TMUIBusy }

constructor TMUIBusy.Create(AClassName: PChar; const Tags: TATagList);
begin
  inherited Create(AClassName, Tags);
end;

{ TMUIGroup }

function TMUIGroup.GetActivePage: Integer;
begin
  Result := GetAttribute(MUIA_Group_ActivePage);
end;

procedure TMUIGroup.SetActivePage(AValue: Integer);
var
  i: Integer;
  Res: NativeUInt;
begin
  for i := 0 to FChilds.Count - 1 do
  begin
    TMUIObject(FChilds[i]).Visible := i = AValue;
  end;
  SetAttribute(MUIA_Group_ActivePage, AValue);
  MuiApp.AddInvalidatedObject(GetParentWindow);
end;

procedure TMUIGroup.BasicInitOnCreate();
begin
  inherited;
end;

procedure TMUIGroup.InstallHooks;
begin
end;

procedure TMUIGroup.SetOwnSize;
var
  i: longint;
  w,h: LongInt;
begin
  //writeln(self.classname, '-->setownsize');
  if not Assigned(FObject) then
    Exit;
  if BlockRedraw or BlockLayout then
    Exit;
  w := Min(FWidth, LongInt(OBJ_MaxWidth(FObject)));
  w := Max(w, LongInt(OBJ_MinWidth(FObject)));
  h := Min(FHeight, LongInt(OBJ_MaxHeight(FObject)));
  h := Max(h, LongInt(OBJ_MinHeight(FObject)));
  //writeln(self.classname,' setsize ', FLeft, ', ', FTop, ' - ', FWidth, ', ', FHeight,' count: ', Fchilds.Count, ' obj ', HexStr(FObject));
  MUI_Layout(FObject, FLeft, FTop, w, h, 0);
  //writeln(self.classname, '  setsize done');
  for i := 0 to FChilds.Count - 1 do
  begin
    //writeln(self.classname, '  Child ', i);
    if FChilds.Items[i] is TMUIObject then
      TMuiObject(FChilds.Items[i]).SetOwnSize;
  end;
  //writeln(self.classname, '<--setownsize');
end;

{ TMUIRegister }

constructor TMUIRegister.Create(AClassName: PChar; const Tags: TATagList);
begin
  FColor := clNone;
  FActivePage := -1;
  FRegisterHeight := 30;
  //writeln('I got it');
  {FNames[0] := GetMem(100);
  StrCopy(FNames[0], ' ');
  FNames[1] := nil;
  AddTags(tg, [MUIA_Register_Titles, IPTR(@FNames[0])]);
  FTexts := TMUIGroup.create(MUIC_Register, GetTagPtr(tg));}
  ShowTabs := False;
  FTexts := nil;
  //
  Tags.AddTags([
    MUIA_InnerTop, 0,
    MUIA_InnerLeft, 0,
    MUIA_InnerBottom, 0,
    MUIA_InnerRight, 0,
    {$ifndef AROS} // buggy in AROS, without also works (make not visible in TMUIRegister)
    MUIA_Group_PageMode, LTrue,
    {$endif}
    MUIA_Frame, MUIV_Frame_Group
    ]);
  inherited Create(AClassName, Tags);
end;

procedure TMUIRegister.BasicInitOnCreate();
begin
  inherited;
end;

destructor TMUIRegister.Destroy;
begin
  inherited;
  FTexts.Free;
end;

procedure TMUIRegister.InstallHooks;
begin
end;

procedure TMUIRegister.SetParent(const AValue: TMUIObject);
begin
  //writeln(self.classname + '  ' + self.pasobject.classname +' muiregsiter set parent ', AValue.classname, ' ', AValue.pasobject.classname);
  inherited SetParent(AValue);
  if ShowTabs and Assigned(FTexts) then
    FTexts.Parent := AValue;
end;

procedure TMUIRegister.SetLeft(ALeft: Integer);
begin
  inherited SetLeft(ALeft);
  if ShowTabs and Assigned(FTexts) then
    FTexts.Left := ALeft;
end;

procedure TMUIRegister.SetTop(ATop: Integer);
begin
  if ShowTabs and Assigned(FTexts) then
  begin
    inherited SetTop(ATop + RegisterHeight);
    FTexts.Top := ATop;
  end else
  begin
    inherited SetTop(ATop);
  end;
end;

procedure TMUIRegister.SetWidth(AWidth: Integer);
begin
  inherited SetWidth(AWidth);
  if ShowTabs and Assigned(FTexts) then
    FTexts.Width := AWidth;
end;

procedure TMUIRegister.SetHeight(AHeight: Integer);
begin
  if ShowTabs and Assigned(FTexts) then
  begin
    inherited SetHeight(AHeight - RegisterHeight);
    FTexts.Height := RegisterHeight;
  end else
  begin
    inherited SetHeight(AHeight);
  end;
end;

function TMUIRegister.GetHeight: Integer;
begin
  if ShowTabs and Assigned(FTexts) then
  begin
    Result := FHeight + RegisterHeight;
  end else
  begin
    Result := FHeight;
  end;
end;

function TMUIRegister.GetActivePage: Integer;
begin
  Result := GetAttribute(MUIA_Group_ActivePage);
end;

procedure TMUIRegister.SetActivePage(AValue: Integer);
var
  PGIdx: Integer;
begin
  if AValue < 0 then
    AValue := 0;
  FActivePage := AValue;
  TCustomTabControl(PasObject).PageIndex := AValue;
  inherited SetActivePage(AValue);
  if ShowTabs and Assigned(FTexts) and Assigned(FTexts.Obj) then
  begin
    PGIdx := GetAttObj(FTexts.Obj, MUIA_Group_ActivePage);
    if PGIdx <> FActivePage then
    begin
      SetAttObj(FTexts.Obj, [MUIA_Group_ActivePage, AValue]);
    end;
    PasObject.Invalidate;
  end;
end;

procedure TMUIRegister.SetVisible(const AValue: boolean);
begin
  inherited SetVisible(AValue);
  if Assigned(FTexts) then
    FTexts.Visible := AValue;
end;

procedure TMUIRegister.SetEnabled(const AValue: boolean);
begin
  inherited SetEnabled(AValue);
  if Assigned(FTexts) then
    FTexts.Enabled := AValue;
end;

function TMUIRegister.GetRegisterHeight: Integer;
begin
  Result := 0;
  if Assigned(FTexts) then
    Result := GetAttObj(FTexts.Obj, MUIA_InnerTop);
  if Result = 0 then
    Result := FRegisterHeight;
end;

function TMUIRegister.GetPagesNum: Integer;
begin
  Result := FChilds.Count;
end;

procedure TMUIRegister.SetColor(const AValue: TColor);
begin
  FColor := AValue;
  if Assigned(FTexts) then
  begin
    FTexts.Color := FColor;
  end;
end;

function TabIdxFunc(Hook: PHook; Obj: PObject_; Msg: Pointer): LongInt;
var
  MUIRegister: TMUIRegister;
  PGIdx: Integer;
  Mess: TLMNotify;
  NMHdr: tagNMHDR;
begin
  Result := 0;
  if TObject(Hook^.h_Data) is TMUIRegister then
  begin
    MUIRegister := TMUIRegister(Hook^.h_Data);
    PGIdx := MUIRegister.GetAttObj(MUIRegister.FTexts.Obj, MUIA_Group_ActivePage);
    //
    FillChar(Mess, SizeOf(Mess), 0);
    Mess.Msg := LM_Notify;
    FillChar(NMHdr, SizeOf(NMHdr), 0);
    NMHdr.Code := TCN_SELCHANGING;
    NMHdr.hwndFrom := PtrUInt(MUIRegister);
    NMHdr.idFrom := PGIdx;
    Mess.NMHdr := @NMHdr;
    DeliverMessage(MUIRegister.PasObject, Mess);
    // forbidden to change
    if Mess.Result <> 0 then
    begin
      PGIdx := MUIRegister.FActivePage;
      if Assigned(MUIRegister.FTexts) then
        MUIRegister.SetAttObj(MUIRegister.FTexts.Obj, [MUIA_Group_ActivePage, MUIRegister.FActivePage]);
      Exit;
    end;
    MUIRegister.ActivePage := PGIdx;
    TCustomTabControl(MUIRegister.Pasobject).PageIndex := PGIdx;
    FillChar(Mess, SizeOf(Mess), 0);
    Mess.Msg := LM_Notify;
    FillChar(NMHdr, SizeOf(NMHdr), 0);
    NMHdr.Code := TCN_SELCHANGE;
    NMHdr.hwndFrom := PtrUInt(MUIRegister);
    NMHdr.idFrom := PGIdx;
    Mess.NMHdr := @NMHdr;
    DeliverMessage(MUIRegister.PasObject, Mess);
    //LCLSendChangedMsg(MUIRegister.PasObject, PGIdx);
  end;
end;


procedure TMUIRegister.AddChild(ChildObj: PObject_);
var
  i: Integer;
  MyStr: string;
  l,t,w,h: Integer;
  TG: TATagList;
  Tab: TCustomTabControl;
begin
  inherited;
  if not ShowTabs and Assigned(FTexts) then
  begin
    FTexts.Free;
    FTexts := nil;
  end;
  if ShowTabs and (PasObject is TCustomTabControl) then
  begin
    Tab := TCustomTabControl(PasObject);
    if Assigned(FTexts) then
    begin
      l := FTexts.Left;
      t := FTexts.Top;
      w := FTexts.Width;
      h := FTexts.Height;
      FTexts.Free;
    end;
    for i := 0 to Tab.Pages.Count - 1 do
    begin
      if Assigned(FNames[i]) then
        FreeMem(FNames[i]);
      MyStr := Tab.Pages[i];
      FNames[i] := GetMem(Length(FNames) + 1);
      strings.StrCopy(FNames[i], PChar(MyStr));
    end;
    FNames[FChilds.Count + 1] := nil;
    TG.AddTags([
      MUIA_Register_Titles, NativeUInt(@FNames[0]),
      MUIA_Frame, MUIV_Frame_None,
      MUIA_Register_Frame, TagFalse
      ]);
    FTexts := TMUIGroup.create(MUIC_Register, TG);
    FTexts.Top := t;
    FTexts.Left := l;
    FTexts.Width := w;
    FTexts.Height := h;
    FTexts.Parent := Parent;
    FTexts.Color := FColor;
    ConnectHookObject(FTexts.Obj, MUIA_Group_ActivePage, MUIV_EveryTime, @TabIdxFunc);
  end;
end;

{ TMUINumeric }

constructor TMUINumeric.Create(AClassName: PChar; const TagList: TATagList);
begin
  inherited Create(AClassname, TagList);
end;


procedure TMUINumeric.SetMinValue(AValue: Integer);
begin
  if AValue = MinValue then
    Exit;
  SetAttribute(MUIA_Numeric_Min, AValue);
end;

procedure TMUINumeric.SetMaxValue(AValue: Integer);
begin
  if AValue = MaxValue then
    Exit;
  SetAttribute(MUIA_Numeric_Max, AValue);
end;

procedure TMUINumeric.SetValue(AValue: Integer);
begin
  if AValue = GetValue then
    Exit;
  SetAttribute(MUIA_Numeric_Value, AValue);
end;

function TMUINumeric.GetMinValue: Integer;
begin
  Result := GetAttribute(MUIA_Numeric_Min);
end;

function TMUINumeric.GetMaxValue: Integer;
begin
  Result := GetAttribute(MUIA_Numeric_Max);
end;

function TMUINumeric.GetValue: Integer;
begin
  Result := GetAttribute(MUIA_Numeric_Value);
end;

{ TMUISlider }

function TMUISlider.GetHorizontal: Boolean;
begin
  Result := FHoriz;
end;

procedure TMUISlider.SetHorizontal(AValue: Boolean);
begin
  FHoriz := AValue;
end;

procedure TMUISlider.SetWidth(AWidth: Integer);
begin
  //if not FHoriz then
  //  AWidth := 25;
  inherited SetWidth(AWidth);
end;

procedure TMUISlider.SetHeight(AHeight: Integer);
begin
  //if FHoriz then
  //  AHeight := 25;
  inherited SetHeight(AHeight);
end;


end.