File: muiformsunit.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 (783 lines) | stat: -rw-r--r-- 20,645 bytes parent folder | download | duplicates (3)
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
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
{
 *****************************************************************************
 *                             MuiFormsUnit.pas                              *
 *                              --------------                               *
 *                    MUI Windows and related things                         *
 *                                                                           *
 *****************************************************************************

 *****************************************************************************
  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 MuiFormsUnit;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Controls, Contnrs, Exec, AmigaDos, Intuition, Utility, Mui,
  Forms, MuiBaseUnit, LCLMessageGlue, Menus, Math, Types, LCLType,
  StrUtils, tagsparamshelper, muiglobal;

const
  NM_Barlabel = -1;

type

  { TMuiFamily }

  TMuiFamily = class(TMuiObject)
  private
    ChildList: TObjectList;
  protected
    procedure InstallHooks; override;
  public
    Par: TMUIFamily;
    procedure AddHead(AChild: TMuiFamily);
    procedure AddTail(AChild: TMuiFamily);
    procedure Remove(AChild: TMuiFamily);
    function GetList: PMinList;
    destructor Destroy; override;
  end;

  { TMuiMenuItem }

  TMuiMenuItem = class(TMuiFamily)
  private
    FTitle: string;
    FShortCut: string;
  protected
    function GetChecked: Boolean;
    function GetCheckIt: Boolean;
    function GetEnabled: Boolean; override;
    function GetMenuItem: TMenuItem;
    function GetShortCut: string;
    function GetTitle: string;
    procedure SetChecked(const AValue: Boolean);
    procedure SetCheckIt(const AValue: Boolean);
    procedure SetEnabled(const AValue: Boolean); override;
    procedure SetShortCut(const AValue: string);
    procedure SetTitle(const AValue: string);
  public
    constructor Create(const Tags: TATagList); reintroduce overload virtual;
    procedure DoMUIDraw(); override;
    property Checked: Boolean read GetChecked write SetChecked;
    property CheckIt: Boolean read GetCheckIt write SetCheckIt;
    property Enabled: Boolean read GetEnabled write SetEnabled;
    property ShortCut: string read GetShortCut write SetShortCut;
    property Title: string read GetTitle write SetTitle;
    property MenuItem: TMenuItem read GetMenuItem;
  end;

  { TMuiMenu }

  TMuiMenu = class(TMuiFamily)
  private
    FTitle: string;
  protected
    function GetEnabled: Boolean;  override;
    function GetTitle: string;
    procedure SetEnabled(const AValue: Boolean); override;
    procedure SetTitle(const AValue: string);
  public
    constructor Create(const Tags: TATagList); reintroduce overload virtual;
    destructor Destroy; override;
    procedure DoMUIDraw(); override;
    property Enabled: Boolean read GetEnabled write SetEnabled;
    property Title: string read GetTitle write SetTitle;
  end;

  { TMuiMenuStrip }

  TMuiMenuStrip = class(TMuiFamily)
  protected
    function GetEnabled: Boolean; override;
    procedure SetEnabled(const AValue: Boolean); override;
  public
    constructor Create(const Tags: TATagList);
    procedure DoMUIDraw(); override;
    Destructor Destroy; override;
    property Enabled: Boolean read GetEnabled write SetEnabled;
  end;

  { TMuiWindow }

  TMuiWindow = class(TMUIObject)
  private
    FCaption: string;
    FInitWindow: Boolean; // SetVisible
    FBlockSizeMsg: Boolean;// disable resize loopback in layout -> GetSizes
    FMainMenu: TMuiMenuStrip;
    FSizeable: Boolean;
    FHasMenu: Boolean;
    FInMoveEvent: Boolean;
    FFocusedControl: TMuiObject;
    FBlocksize, FBlockMove: Boolean;
    function GetCaption: string;
    procedure SetCaption(const AValue: string);
    function GetWindow: PWindow;
  protected
    function GetVisible: Boolean; override;
    procedure SetVisible(const AValue: Boolean); override;
    procedure AddChild(ChildObj: PObject_); override;
    procedure RemoveChild(ChildObj: PObject_); override;
    procedure SetLeft(ALeft: LongInt); override;
    procedure SetTop(ATop: LongInt); override;
    function GetTop(): Integer; override;
    function GetLeft(): Integer; override;
    function GetWidth(): Integer; override;
    function GetHeight(): Integer; override;
    procedure SetFocusedControl(AControl: TMUIObject); virtual;
    procedure InstallHooks; override;
    procedure SetEnabled(const AEnabled: Boolean); override;
    function GetEnabled: Boolean; override;
  public
    constructor Create(const TagList: TATagList); overload; reintroduce; virtual;
    destructor Destroy; override;
    procedure GetSizes;
    procedure DoMUIDraw(); override;
    function GetClientRect: TRect; override;
    function GetWindowOffset: Types.TPoint; override;
    procedure GetBoundsFromMUI;
    procedure Redraw; override;
    property Caption: string read GetCaption write SetCaption;
    property MainMenu: TMuiMenuStrip read FMainMenu;
    property HasMenu: Boolean read FHasMenu write FHasMenu;
    property Sizeable: Boolean read FSizeable write FSizeable;
    property FocusedControl: TMUIObject read FFocusedControl write SetFocusedControl;
    property Window: PWindow read GetWindow;
  end;

  { TMuiGroup }

  TMuiGroup = class(TMuiObject)
  private

  public
    constructor Create(const TagList: TATagList); overload; reintroduce; virtual;
  end;

implementation

{ TMuiWindow }

function LayoutFunc(Hook: PHook; Obj: PObject_; Msg:Pointer): Longint;
var
  LMsg: pMUI_LayoutMsg;
  i: LongInt;
  Win: TMuiWindow;
  AWin: PWindow;
  PasWin: TWinControl;
  BW, BH: Integer;
  Miw, Mih, Maw, Mah: Integer;
begin
  LMsg := Msg;
  Result := LongInt(True);
  Win := TMuiWindow(Hook^.h_Data);
  BW := 0;
  BH := 0;
  {$if defined(Amiga) or defined(MorphOS)}
  AWin := Win.Window;
  if Assigned(AWin) then
  begin
    BW := AWin^.BorderLeft + AWin^.BorderRight;
    BH := AWin^.BorderTop + AWin^.BorderBottom;
  end;
  {$endif}
  case LMsg^.lm_type of
    MUILM_MINMAX: begin
      if Win.Sizeable then
      begin
        Miw := 100;
        Mih := 20;
        Maw := MUI_MAXMAX;
        Mah := MUI_MAXMAX;
        if Assigned(Win.PasObject) then
        begin
          PasWin := TWinControl(Win.PasObject);
          MiW := Max(PasWin.Constraints.MinWidth, 100);
          MiH := Max(PasWin.Constraints.MinHeight, 20);
          if PasWin.Constraints.MaxWidth > 0 then
            MaW := Min(PasWin.Constraints.MaxWidth, MUI_MAXMAX);
          if PasWin.Constraints.MaxHeight > 0 then
            MaH := Min(PasWin.Constraints.MaxHeight, MUI_MAXMAX);
          LMsg^.lm_MinMax.MinWidth := MiW;
          LMsg^.lm_MinMax.MinHeight := MiH;
          LMsg^.lm_MinMax.MaxWidth :=  MaW;
          LMsg^.lm_MinMax.MaxHeight := MaH;
        end;
        LMsg^.lm_MinMax.DefWidth := Win.FWidth - BW;
        LMsg^.lm_MinMax.DefHeight := Win.FHeight - BH;
      end else
      begin
        LMsg^.lm_MinMax.MinWidth := Win.FWidth - BW;
        LMsg^.lm_MinMax.MinHeight := Win.FHeight - BH;
        LMsg^.lm_MinMax.MaxWidth := Win.FWidth - BW;
        LMsg^.lm_MinMax.MaxHeight := Win.FHeight - BH;
        LMsg^.lm_MinMax.DefWidth := Win.FWidth - BW;
        LMsg^.lm_MinMax.DefHeight := Win.FHeight - BH;
      end;
      TWinControl(Win.PasObject).Realign;
    end;
    MUILM_LAYOUT:
    begin
      Win.GetSizes;
      for i:= 0 to Win.FChilds.Count - 1 do
      begin
        if Win.FChilds.Items[i] is TMUIObject then
          TMuiObject(Win.FChilds.Items[i]).SetOwnSize;
      end;
    end;
  end;
end;

{ TMuiMenuStrip }

function TMuiMenuStrip.GetEnabled: Boolean;
begin
  Result := LongBool(GetAttribute(MUIA_Menu_Enabled));
end;

procedure TMuiMenuStrip.SetEnabled(const AValue: Boolean);
begin
  SetAttribute(MUIA_Menuitem_Enabled, AValue);
end;

constructor TMuiMenuStrip.Create(const Tags: TATagList);
begin
  inherited Create(MUIC_MenuStrip, Tags);
  Par := nil;
end;

destructor TMuiMenuStrip.Destroy;
begin
  FObject := nil;
  inherited;
end;

procedure TMUIMenuStrip.DoMUIDraw();
begin

end;

{ TMuiMenu }

function TMuiMenu.GetEnabled: Boolean;
begin
  Result := LongBool(GetAttribute(MUIA_Menu_Enabled));
end;

function TMuiMenu.GetTitle: string;
begin
  Result := string(PChar(GetAttribute(MUIA_Menuitem_Title)));
end;

procedure TMuiMenu.SetEnabled(const AValue: Boolean);
begin
  SetAttribute(MUIA_Menuitem_Enabled, AValue);
end;

procedure TMuiMenu.SetTitle(const AValue: string);
begin
  FTitle := AValue;
  SetAttribute(MUIA_Menuitem_Title, PChar(FTitle));
end;

constructor TMuiMenu.Create(const Tags: TATagList);
begin
  inherited Create(MUIC_Menu, tags);
  Par := nil;
end;

destructor TMuiMenu.Destroy;
begin
  inherited;
end;

procedure TMUIMenu.DoMUIDraw();
begin
  //
end;

{ TMuiMenuItem }

function TMuiMenuItem.GetChecked: Boolean;
begin
  Result := LongBool(GetAttribute(MUIA_Menuitem_Checked));
end;

function TMuiMenuItem.GetCheckIt: Boolean;
begin
   Result := LongBool(GetAttribute(MUIA_Menuitem_CheckIt));
end;

function TMuiMenuItem.GetEnabled: Boolean;
begin
   Result := LongBool(GetAttribute(MUIA_Menuitem_Enabled));
end;

function TMuiMenuItem.GetMenuItem: TMenuItem;
begin
  Result := TMenuItem(TObject(PasObject));
end;

function TMuiMenuItem.GetShortCut: string;
begin
  Result := string(PChar(GetAttribute(MUIA_Menuitem_ShortCut)));
end;

function TMuiMenuItem.GetTitle: string;
begin
  Result := string(PChar(GetAttribute(MUIA_Menuitem_Title)));
end;

procedure TMuiMenuItem.SetChecked(const AValue: Boolean);
var
  I: Integer;
  MI: TMuiMenuItem;
begin
  if AValue and Assigned(MenuItem) and (MenuItem.GroupIndex > 0) then
  begin
    if Assigned(Par) then
    begin
      for i := 0 to Par.ChildList.Count - 1 do
      begin
        if Par.ChildList.Items[i] is TMuiMenuItem then
        begin
          MI := TMuiMenuItem(Par.ChildList.Items[i]);
          if MI.MenuItem.GroupIndex = MenuItem.GroupIndex then
            MI.Checked := False;
        end;
      end;
    end;
  end;
  SetAttribute(MUIA_Menuitem_Checked, AValue);
end;

procedure TMuiMenuItem.SetCheckIt(const AValue: Boolean);
begin
  SetAttribute(MUIA_Menuitem_CheckIt, AValue);
end;

procedure TMuiMenuItem.SetEnabled(const AValue: Boolean);
begin
  //writeln('SetEnabled: ',AValue);
  SetAttribute(MUIA_Menuitem_Enabled, AValue);
  //writeln('getEnabled: ', GetEnabled);
end;

procedure TMuiMenuItem.SetShortCut(const AValue: string);
begin
  FShortCut := AValue;
  //SetAttribute([MUIA_Menuitem_CommandString, 1, LongInt(MUIA_Menuitem_ShortCut), PChar(FShortCut), TAG_END]);
end;

procedure TMuiMenuItem.SetTitle(const AValue: string);
begin
  FTitle := AValue;
  if AValue = '-' then
    SetAttribute(MUIA_Menuitem_Title, NativeUInt(NM_BARLABEL))
  else
    SetAttribute(MUIA_Menuitem_Title, PChar(FTitle));
end;

function MenuClickedFunc(Hook: PHook; Obj: PObject_; Msg:Pointer): LongInt;
var
  MuiObject: TMuiMenuItem;
  TargetObject: TObject;
begin
  Result := 0;
  if TObject(Hook^.h_Data) is TMuiMenuItem then
  begin
    MuiObject := TMuiMenuItem(Hook^.h_Data);
    TargetObject := MuiObject.pasobject;
    TMenuItem(TargetObject).Click;
  end;
end;

constructor TMuiMenuItem.Create(const Tags: TATagList);
begin
  inherited Create(MUIC_MenuItem, Tags);
  Par := nil;
  ConnectHook(MUIA_Menuitem_Trigger, LongWord(MUIV_EveryTime), @MenuClickedFunc);
end;

procedure TMuiMenuItem.DoMUIDraw();
begin

end;

{ TMuiFamily }

procedure TMuiFamily.InstallHooks;
begin
  ChildList := TObjectList.Create;
  ChildList.OwnsObjects := False;
end;

destructor TMuiFamily.Destroy;
var
  i: Integer;
  MUIObject: TMuiObject;
begin
  for i := 0 to ChildList.Count - 1 do
  begin
    MUIObject := TMUIObject(ChildList[i]);
    MUIObject.FObject := nil;
    MUIObject.Free;
  end;
  ChildList.Free;
  inherited;
end;

procedure TMuiFamily.AddHead(AChild: TMuiFamily);
begin
  ChildList.Insert(0,AChild);
  DoMethod([NativeUInt(MUIM_Family_AddHead), NativeUInt(AChild.Obj)]);
end;

procedure TMuiFamily.AddTail(AChild: TMuiFamily);
begin
  ChildList.Add(AChild);
  DoMethod([NativeUInt(MUIM_Family_AddTail), NativeUInt(AChild.Obj)]);
end;

procedure TMuiFamily.Remove(AChild: TMuiFamily);
begin
  ChildList.Remove(AChild);
  DoMethod([NativeUInt(MUIM_Family_Remove), NativeUInt(AChild.Obj)]);
end;

function TMuiFamily.GetList: PMinList;
begin
  Result := PMinList(GetAttribute(MUIA_Family_List));
end;

function CloseWinFunc(Hook: PHook; Obj: PObject_; Msg:Pointer): Longint;
var
  MuiObject: TMuiWindow;
begin
  if TObject(Hook^.h_Data) is TMuiWindow then
  begin
    MuiObject := TMuiWindow(Hook^.h_Data);
    Result := LCLSendCloseQueryMsg(MuiObject.pasobject);
  end;
end;

function MoveWinFunc(Hook: PHook; Obj: PObject_; Msg:Pointer): Longint;
var
  MuiObject: TMuiWindow;
begin
  if TObject(Hook^.h_Data) is TMuiWindow then
  begin
    MuiObject := TMuiWindow(Hook^.h_Data);
    if Assigned(MuiObject.PasObject) and (not TMUIWindow(MUIObject).FBlockMove) then
    begin
      Result := LCLSendMoveMsg(MuiObject.pasobject, MuiObject.Left, MuiObject.Top, Move_Default, False);
    end;
  end;
end;

function SizeWinFunc(Hook: PHook; Obj: PObject_; Msg:Pointer): Longint;
var
  MuiObject: TMuiWindow;
begin
  if TObject(Hook^.h_Data) is TMuiWindow then
  begin
    MuiObject := TMuiWindow(Hook^.h_Data);
    if Assigned(MuiObject.PasObject) and (not TMUIWindow(MUIObject).FBlockSize) then
    begin
      Result := LCLSendSizeMsg(MuiObject.pasobject, MuiObject.Width, MuiObject.Height, SIZENORMAL, False);
    end;
  end;
end;

constructor TMuiWindow.Create(const TagList: TATagList);
var
  LT: TATagList;
  GrpTags: TATagList;
  AltLeft, AltTop, AltHeight, AltWidth: Integer;
begin
  FBlockSize := False;
  FBlockMove := False;
  FFocusedControl := Self;
  LT.Clear;
  FMainMenu := TMuiMenuStrip.Create(LT);
  HasMenu := False;
  FInMoveEvent := False;
  //FGrpObj := MUI_NewObject(MUIC_Group,[LongInt(MUIA_Group_LayoutHook), @LayoutHook, TAG_END]);
  //
  SetHook(LayoutHook, @LayoutFunc, self);
  //
  GrpTags.AddTags([
    MUIA_Group_LayoutHook, NativeUInt(@LayoutHook),
    MUIA_Frame, MUIV_Frame_None,
    //MUIA_FillArea, LFalse,
    MUIA_InnerLeft, 0,
    MUIA_InnerTop, 0,
    MUIA_InnerRight, 0,
    MUIA_InnerBottom, 0
    ]);
  FGrpObj := NewObjectA(LCLGroupClass, nil, GrpTags);
  if Assigned(FGrpObj) then
    Pointer(INST_DATA(LCLGroupClass, Pointer(FGrpObj))^) := Self;
  //
  AltLeft := 0;
  AltTop := 0;
  AltWidth := IntuitionBase^.ActiveScreen^.Width;
  AltHeight := IntuitionBase^.ActiveScreen^.Height - IntuitionBase^.ActiveScreen^.BarHeight;
  TagList.AddTags([
    MUIA_Window_AltLeftEdge , AltLeft,
    MUIA_Window_AltTopEdge , AltTop,
    MUIA_Window_AltWidth , AltWidth,
    MUIA_Window_AltHeight , AltHeight,
    MUIA_Window_Menustrip, NativeUInt(FMainMenu.Obj),
    MUIA_Window_RootObject, NativeUInt(FGrpObj)
    ]);
  inherited Create(MUIC_Window, TagList);
  //
  Self.Parent := MUIApp;
  if MuiApp.MainWin = obj then
    SetAttribute(MUIA_Window_Activate, True);
end;

destructor TMuiWindow.Destroy;
begin
  FMainMenu.Free;
  inherited Destroy;
end;

procedure TMuiWindow.InstallHooks;
begin
  //inherited;
  ConnectHook(MUIA_Window_CloseRequest, LongWord(LTrue), @CloseWinFunc);
  // Move Window
  ConnectHook(MUIA_Window_LeftEdge, LongWord(MUIV_EveryTime), @MoveWinFunc);
  ConnectHook(MUIA_Window_TopEdge, LongWord(MUIV_EveryTime), @MoveWinFunc);
  // Resize Window
  ConnectHook(MUIA_Window_Width, LongWord(MUIV_EveryTime), @SizeWinFunc);
  ConnectHook(MUIA_Window_Height, LongWord(MUIV_EveryTime), @SizeWinFunc);
end;

procedure TMuiWindow.GetSizes;
begin
  FBlockSizeMsg := not FInitWindow;
  Left := GetAttribute(MUIA_Window_LeftEdge);
  Top := GetAttribute(MUIA_Window_TopEdge);
  //
  if not Sizeable then
  begin
    Width := GetAttribute(MUIA_Window_Width);
    Height := GetAttribute(MUIA_Window_Height);
  end else
  begin
    Width := GetAttribute(MUIA_Window_Width);
    Height := GetAttribute(MUIA_Window_Height);
  end;
  TWinControl(PasObject).SetBounds(Left, Top, Width, Height);
  FBlockSizeMsg := False;
end;

procedure TMuiWindow.Redraw;
var
  Msg: LongWord;
begin
  if BlockRedraw then
    Exit;
  DoMethodObj(FGrpObj, [MUIM_Group_InitChange]);
  DoMethodObj(FGrpObj, [MUIM_Group_ExitChange]);
end;

procedure TMuiWindow.DoMUIDraw();
begin
  //inherited;
  if Assigned(FGrpObj) then
    MUI_Redraw(FGrpobj, $805);//MADF_DRAWOBJECT);
end;

function TMuiWindow.GetClientRect: TRect;
var
  win: PWindow;
begin
  Result := inherited;
  Result.Left := 0;
  Result.Top := 0;
  Result.Right := Width;
  Result.Bottom := Height;
  {$if defined(Amiga) or defined(MorphOS)}
  Win := Self.Window;
  if Assigned(Win) then
  begin
    Result.Width := Result.Width - (Win^.BorderLeft + Win^.BorderRight);
    Result.Height := Result.Height - (Win^.BorderTop + Win^.BorderBottom);
  end else
  begin
    if Sizeable then
    begin
      Result.Width := Result.Width - 8;
      Result.Height := Result.Height - 21
    end
    else
    begin
      Result.Width := Result.Width - 8;
      Result.Height := Result.Height - 13
    end;
  end;
  {$endif}
end;

function TMuiWindow.GetWindow: PWindow;
begin
  Result := PWindow(GetAttribute(MUIA_Window_Window));
end;

function TMuiWindow.GetWindowOffset: TPoint;
begin
  Result.X := 0;
  Result.Y := 0;
end;

procedure TMuiWindow.SetLeft(ALeft: LongInt);
begin
  if FBlockSizeMsg then
    Exit;
  FBlockMove := True;
  inherited;
  SetAttribute(MUIA_Window_LeftEdge, ALeft);
  FBlockMove := False;
end;

procedure TMuiWindow.SetTop(ATop: LongInt);
begin
  if FBlockSizeMsg then
    Exit;
  FBlockMove := True;
  inherited;
  SetAttribute(MUIA_Window_TopEdge, ATop);
  FBlockMove := False;
end;

function TMuiWindow.GetTop(): Integer;
begin
  Result := GetAttribute(MUIA_Window_TopEdge);
end;

function TMuiWindow.GetLeft(): Integer;
begin
  Result := GetAttribute(MUIA_Window_LeftEdge);
end;

function TMuiWindow.GetWidth(): Integer;
begin
  if Sizeable then
    Result := GetAttribute(MUIA_Window_Width)
  else
    Result := PasObject.Width;
end;

function TMuiWindow.GetHeight(): Integer;
begin
  if Sizeable then
    Result := GetAttribute(MUIA_Window_Height)
  else
    Result := PasObject.Height;
end;

function TMuiWindow.GetCaption: string;
begin
  inherited;
  //Result := FCaption;
  Result := PChar(GetAttribute(MUIA_Window_Title));
end;

function TMuiWindow.GetVisible: Boolean;
begin
  Result := Boolean(GetAttribute(MUIA_Window_Open));
end;

procedure TMuiWindow.SetCaption(const AValue: string);
var
  PC: PChar;
begin
  FCaption := AValue;
  PC := PChar(FCaption);
  SetAttribute(MUIA_Window_Title, PC);
end;

procedure TMuiWindow.SetVisible(const AValue: Boolean);
begin
  FInitWindow := True;
  SetAttribute(MUIA_Window_Open, AValue);
  if AValue then
  begin
    GetSizes;
    TWinControl(PasObject).InvalidateClientRectCache(True);
  end;
  FInitWindow := False;
end;

procedure TMuiWindow.AddChild(ChildObj: PObject_);
begin
  if Assigned(FGrpObj) and Assigned(ChildObj) then
  begin
    DoMethodObj(FGrpObj, [MUIM_Group_InitChange]);
    DoMethodObj(FGrpObj, [OM_ADDMEMBER, PtrUInt(ChildObj)]);
    DoMethodObj(FGrpObj, [MUIM_Group_ExitChange]);
  end;
end;

procedure TMuiWindow.RemoveChild(ChildObj: PObject_);
begin
  //writeln('-> window remove child ', HexStr(Child), ' ', HexStr(Child.obj), ' ', HexStr(Self), ' ', HexStr(FGrpObj));
  if Assigned(FGrpObj) and Assigned(ChildObj) then
  begin
    //DoMethodObj(FGrpObj, [MUIM_Group_InitChange]);
    DoMethodObj(FGrpObj, [OM_REMMEMBER, PtrUInt(ChildObj)]);
    //DoMethodObj(FGrpObj, [MUIM_Group_ExitChange]);
  end;
  //writeln('<-window remove child');
end;

procedure TMuiWindow.GetBoundsFromMUI;
begin
  FLeft := GetAttribute(MUIA_Window_LeftEdge);
  FTop := GetAttribute(MUIA_Window_TopEdge);
  FWidth := GetAttribute(MUIA_Window_Width);
  FHeight := GetAttribute(MUIA_Window_Height);
end;

procedure TMuiWindow.SetFocusedControl(AControl: TMUIObject);
begin
  FFocusedControl := AControl;
  if Assigned(AControl) then
  begin
    SetAttribute([MUIA_Window_Activate, TagTrue, MUIA_Window_ActiveObject, NativeUInt(AControl.FocusObject)]);
  end;
end;

procedure TMuiWindow.SetEnabled(const AEnabled: Boolean);
begin
  //writeln('Enabled: ', AEnabled);
  //SetAttObj(FgrpObj, [MUIA_Disabled, ifthen(AEnabled, LFalse, LTrue)]);
end;

function TMuiWindow.GetEnabled: Boolean;
begin
  Result := True;//not boolean(GetAttObj(FGrpObj, MUIA_Disabled));
end;


{ TMuiGroup }

constructor TMuiGroup.Create(const TagList: TATagList);
begin
  inherited Create(MUIC_Group, TagList);
end;

end.