1{
2 *****************************************************************************
3 *                             Gtk3WSComCtrls.pp                             *
4 *                             -----------------                             *
5 *                                                                           *
6 *                                                                           *
7 *****************************************************************************
8
9 *****************************************************************************
10  This file is part of the Lazarus Component Library (LCL)
11
12  See the file COPYING.modifiedLGPL.txt, included in this distribution,
13  for details about the license.
14 *****************************************************************************
15}
16unit Gtk3WSComCtrls;
17
18{$mode objfpc}{$H+}
19{$I gtk3defines.inc}
20
21interface
22
23uses
24  // libs
25  LazGtk3, LazGdk3, LazGlib2,
26  // RTL, FCL, LCL
27  ComCtrls, Classes, LCLType, LMessages, Controls, Graphics, StdCtrls, Forms,
28  LCLProc, LCLIntf, ImgList, Math, Sysutils, ctypes, InterfaceBase,
29  // widgetset
30  WSComCtrls, WSLCLClasses, WSControls, WSProc,
31  Gtk3WSControls, Gtk3Int, gtk3widgets;
32
33type
34  { TGtk3WSCustomPage }
35
36  TGtk3WSCustomPage = class(TWSCustomPage)
37  published
38    class function CreateHandle(const AWinControl: TWinControl;
39      const AParams: TCreateParams): TLCLIntfHandle; override;
40    class procedure UpdateProperties(const ACustomPage: TCustomPage); override;
41    class procedure SetBounds(const {%H-}AWinControl: TWinControl; const {%H-}ALeft, {%H-}ATop, {%H-}AWidth, {%H-}AHeight: Integer); override;
42    class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
43    class procedure ShowHide(const AWinControl: TWinControl); override;
44    class function GetDefaultClientRect(const AWinControl: TWinControl;
45             const {%H-}aLeft, {%H-}aTop, {%H-}aWidth, {%H-}aHeight: integer; var aClientRect: TRect
46             ): boolean; override;
47  end;
48
49  { TGtk3WSCustomTabControl }
50
51  TGtk3WSCustomTabControl = class(TWSCustomTabControl)
52  published
53    class function CreateHandle(const AWinControl: TWinControl;
54                                const AParams: TCreateParams): TLCLIntfHandle; override;
55    (*
56    class function GetDefaultClientRect(const AWinControl: TWinControl;
57            const {%H-}aLeft, {%H-}aTop, aWidth, aHeight: integer; var aClientRect: TRect
58            ): boolean; override;
59    *)
60    class procedure AddPage(const ATabControl: TCustomTabControl;
61      const AChild: TCustomPage; const AIndex: integer); override;
62    class procedure MovePage(const ATabControl: TCustomTabControl;
63      const AChild: TCustomPage; const NewIndex: integer); override;
64    class procedure RemovePage(const ATabControl: TCustomTabControl; const AIndex: integer); override;
65
66    class function GetCapabilities: TCTabControlCapabilities; override;
67    class function GetNotebookMinTabHeight(const AWinControl: TWinControl): integer; override;
68    class function GetNotebookMinTabWidth(const AWinControl: TWinControl): integer; override;
69    class function GetTabIndexAtPos(const ATabControl: TCustomTabControl; const AClientPos: TPoint): integer; override;
70    class function GetTabRect(const ATabControl: TCustomTabControl; const AIndex: Integer): TRect; override;
71    class procedure SetPageIndex(const ATabControl: TCustomTabControl; const AIndex: integer); override;
72    class procedure SetTabCaption(const ATabControl: TCustomTabControl; const AChild: TCustomPage; const AText: string); override;
73    class procedure SetTabPosition(const ATabControl: TCustomTabControl; const ATabPosition: TTabPosition); override;
74    class procedure ShowTabs(const ATabControl: TCustomTabControl; AShowTabs: boolean); override;
75    class procedure UpdateProperties(const ATabControl: TCustomTabControl); override;
76  end;
77
78  { TGtk3WSStatusBar }
79
80  TGtk3WSStatusBar = class(TWSStatusBar)
81  published
82    class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
83    class procedure PanelUpdate(const AStatusBar: TStatusBar; PanelIndex: integer); override;
84    class procedure SetPanelText(const AStatusBar: TStatusBar; PanelIndex: integer); override;
85    class procedure Update(const AStatusBar: TStatusBar); override;
86    class procedure GetPreferredSize(const {%H-}AWinControl: TWinControl;
87                        var {%H-}PreferredWidth, PreferredHeight: integer;
88                        {%H-}WithThemeSpace: Boolean); override;
89
90    class procedure SetSizeGrip(const AStatusBar: TStatusBar; {%H-}SizeGrip: Boolean); override;
91  end;
92
93  { TGtk3WSTabSheet }
94
95  TGtk3WSTabSheet = class(TWSTabSheet)
96  published
97  end;
98
99  { TGtk3WSPageControl }
100
101  TGtk3WSPageControl = class(TWSPageControl)
102  published
103  end;
104
105  { TGtk3WSCustomListView }
106
107  TGtk3WSCustomListView = class(TWSCustomListView)
108  private
109    class procedure SetPropertyInternal(const ALV: TCustomListView; const AProp: TListViewProperty; const AIsSet: Boolean);
110  published
111    // columns
112    class procedure ColumnDelete(const ALV: TCustomListView; const AIndex: Integer); override;
113    class function  ColumnGetWidth(const ALV: TCustomListView; const {%H-}AIndex: Integer; const AColumn: TListColumn): Integer; override;
114    class procedure ColumnInsert(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn); override;
115    class procedure ColumnMove(const ALV: TCustomListView; const AOldIndex, ANewIndex: Integer; const {%H-}AColumn: TListColumn); override;
116    class procedure ColumnSetAlignment(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AColumn: TListColumn; const AAlignment: TAlignment); override;
117    class procedure ColumnSetAutoSize(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AColumn: TListColumn; const AAutoSize: Boolean); override;
118    class procedure ColumnSetCaption(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AColumn: TListColumn; const ACaption: String); override;
119    class procedure ColumnSetImage(const ALV: TCustomListView; const {%H-}AIndex: Integer; const {%H-}AColumn: TListColumn; const {%H-}AImageIndex: Integer); override;
120    class procedure ColumnSetMaxWidth(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AColumn: TListColumn; const AMaxWidth: Integer); override;
121    class procedure ColumnSetMinWidth(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AColumn: TListColumn; const AMinWidth: integer); override;
122    class procedure ColumnSetWidth(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AColumn: TListColumn; const AWidth: Integer); override;
123    class procedure ColumnSetVisible(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AColumn: TListColumn; const AVisible: Boolean); override;
124    class procedure ColumnSetSortIndicator(const ALV: TCustomListView; const AIndex: Integer;
125      const AColumn: TListColumn; const ASortIndicator: TSortIndicator);override;
126
127    // items
128    class procedure ItemDelete(const ALV: TCustomListView; const AIndex: Integer); override;
129    class function  ItemDisplayRect(const ALV: TCustomListView; const AIndex, ASubItem: Integer; {%H-}ACode: TDisplayCode): TRect; override;
130    class procedure ItemExchange(const ALV: TCustomListView; {%H-}AItem: TListItem; const AIndex1, AIndex2: Integer); override;
131    class procedure ItemMove(const ALV: TCustomListView; {%H-}AItem: TListItem; const AFromIndex, AToIndex: Integer); override;
132    class function  ItemGetChecked(const {%H-}ALV: TCustomListView; const {%H-}AIndex: Integer; const AItem: TListItem): Boolean; override;
133    class function  ItemGetState(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AItem: TListItem; const AState: TListItemState; out AIsSet: Boolean): Boolean; override; // returns True if supported
134    class procedure ItemInsert(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AItem: TListItem); override;
135    class procedure ItemSetChecked(const ALV: TCustomListView; const {%H-}AIndex: Integer; const {%H-}AItem: TListItem; const {%H-}AChecked: Boolean); override;
136    class procedure ItemSetImage(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AItem: TListItem; const {%H-}ASubIndex, AImageIndex: Integer); override;
137    class procedure ItemSetState(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AItem: TListItem; const AState: TListItemState; const AIsSet: Boolean); override;
138    class procedure ItemSetText(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AItem: TListItem; const {%H-}ASubIndex: Integer; const {%H-}AText: String); override;
139    class procedure ItemShow(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AItem: TListItem; const {%H-}PartialOK: Boolean); override;
140    class function  ItemGetPosition(const ALV: TCustomListView; const AIndex: Integer): TPoint; override;
141    class procedure ItemUpdate(const ALV: TCustomListView; const {%H-}AIndex: Integer; const {%H-}AItem: TListItem); override;
142
143    // lv
144    class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
145    // class procedure DestroyHandle(const AWinControl: TWinControl); override;
146
147    class procedure BeginUpdate(const ALV: TCustomListView); override;
148    class procedure EndUpdate(const ALV: TCustomListView); override;
149
150    class function GetBoundingRect(const ALV: TCustomListView): TRect; override;
151    class function GetDropTarget(const ALV: TCustomListView): Integer; override;
152    class function GetFocused(const ALV: TCustomListView): Integer; override;
153    class function GetHoverTime(const ALV: TCustomListView): Integer; override;
154    class function GetItemAt(const ALV: TCustomListView; x,y: integer): Integer; override;
155    class function GetSelCount(const ALV: TCustomListView): Integer; override;
156    class function GetSelection(const ALV: TCustomListView): Integer; override;
157    class function GetTopItem(const ALV: TCustomListView): Integer; override;
158    class function GetViewOrigin(const ALV: TCustomListView): TPoint; override;
159    class function GetVisibleRowCount(const ALV: TCustomListView): Integer; override;
160
161    class procedure SetAllocBy(const ALV: TCustomListView; const {%H-}AValue: Integer); override;
162    class procedure SetColor(const AWinControl: TWinControl); override;
163    class procedure SetDefaultItemHeight(const ALV: TCustomListView; const {%H-}AValue: Integer); override;
164    class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
165    class procedure SetHotTrackStyles(const ALV: TCustomListView; const {%H-}AValue: TListHotTrackStyles); override;
166    class procedure SetHoverTime(const ALV: TCustomListView; const {%H-}AValue: Integer); override;
167    //    class procedure SetIconOptions(const ALV: TCustomListView; const AValue: TIconOptions); override;
168    class procedure SetImageList(const ALV: TCustomListView; const AList: TListViewImageList; const AValue: TCustomImageListResolution); override;
169    class procedure SetItemsCount(const ALV: TCustomListView; const {%H-}Avalue: Integer); override;
170    class procedure SetProperty(const ALV: TCustomListView; const AProp: TListViewProperty; const AIsSet: Boolean); override;
171    class procedure SetProperties(const ALV: TCustomListView; const AProps: TListViewProperties); override;
172    class procedure SetScrollBars(const ALV: TCustomListView; const AValue: TScrollStyle); override;
173    class procedure SetSort(const ALV: TCustomListView; const {%H-}AType: TSortType; const {%H-}AColumn: Integer;
174      const {%H-}ASortDirection: TSortDirection); override;
175    class procedure SetViewOrigin(const ALV: TCustomListView; const AValue: TPoint); override;
176    class procedure SetViewStyle(const ALV: TCustomListView; const AValue: TViewStyle); override;
177  end;
178
179  { TGtk3WSListView }
180
181  TGtk3WSListView = class(TWSListView)
182  published
183  end;
184
185  { TGtk3WSProgressBar }
186
187  TGtk3WSProgressBar = class(TWSProgressBar)
188  published
189    class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
190    class procedure ApplyChanges(const AProgressBar: TCustomProgressBar); override;
191    class procedure SetPosition(const AProgressBar: TCustomProgressBar; const NewPosition: integer); override;
192    class procedure SetStyle(const AProgressBar: TCustomProgressBar; const NewStyle: TProgressBarStyle); override;
193  end;
194
195  { TGtk3WSCustomUpDown }
196
197  TGtk3WSCustomUpDown = class(TWSCustomUpDown)
198  published
199  end;
200
201  { TGtk3WSUpDown }
202
203  TGtk3WSUpDown = class(TWSUpDown)
204  published
205  end;
206
207  { TGtk3WSToolButton }
208
209  TGtk3WSToolButton = class(TWSToolButton)
210  published
211  end;
212
213  { TGtk3WSToolBar }
214
215  TGtk3WSToolBar = class(TWSToolBar)
216  published
217    class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
218  end;
219
220  { TGtk3WSTrackBar }
221
222  TGtk3WSTrackBar = class(TWSTrackBar)
223  published
224    class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
225    class procedure ApplyChanges(const ATrackBar: TCustomTrackBar); override;
226    class function  GetPosition(const ATrackBar: TCustomTrackBar): integer; override;
227    class procedure SetPosition(const ATrackBar: TCustomTrackBar; const NewPosition: integer); override;
228    class procedure SetOrientation(const ATrackBar: TCustomTrackBar; const {%H-}AOrientation: TTrackBarOrientation); override;
229  end;
230
231  { TGtk3WSCustomTreeView }
232
233  TGtk3WSCustomTreeView = class(TWSCustomTreeView)
234  published
235  end;
236
237  { TGtk3WSTreeView }
238
239  TGtk3WSTreeView = class(TWSTreeView)
240  published
241  end;
242
243
244implementation
245uses gtk3procs;
246
247{ TGtk3WSTrackBar }
248
249class function TGtk3WSTrackBar.CreateHandle(const AWinControl: TWinControl;
250  const AParams: TCreateParams): TLCLIntfHandle;
251var
252  ATrack: TGtk3TrackBar;
253  APt: TPoint;
254begin
255  ATrack := TGtk3TrackBar.Create(AWinControl, AParams);
256  Result := TLCLIntfHandle(ATrack);
257end;
258
259class procedure TGtk3WSTrackBar.ApplyChanges(const ATrackBar: TCustomTrackBar);
260var
261  ATrack: TGtk3TrackBar;
262  APt: TPoint;
263begin
264  // inherited ApplyChanges(ATrackBar);
265  if not WSCheckHandleAllocated(ATrackBar, 'ApplyChanges') then
266    Exit;
267  ATrack := TGtk3TrackBar(ATrackBar.Handle);
268  APt.X := ATrackBar.Min;
269  APt.Y := ATrackBar.Max;
270  ATrack.Range := APt;
271  ATrack.SetStep(ATrackBar.Frequency, ATrackBar.PageSize);
272  ATrack.SetScalePos(ATrackBar.ScalePos);
273  ATrack.SetTickMarks(ATrackbar.TickMarks, ATrackBar.TickStyle);
274  ATrack.Reversed := ATrackBar.Reversed;
275end;
276
277class function TGtk3WSTrackBar.GetPosition(const ATrackBar: TCustomTrackBar
278  ): integer;
279begin
280  if not WSCheckHandleAllocated(ATrackBar, 'GetPosition') then
281    Exit(0);
282  Result := TGtk3TrackBar(ATrackBar.Handle).Position;
283end;
284
285class procedure TGtk3WSTrackBar.SetPosition(const ATrackBar: TCustomTrackBar;
286  const NewPosition: integer);
287begin
288  if not WSCheckHandleAllocated(ATrackBar, 'SetPosition') then
289    Exit;
290  TGtk3TrackBar(ATrackBar.Handle).BeginUpdate;
291  TGtk3TrackBar(ATrackBar.Handle).Position := NewPosition;
292  TGtk3TrackBar(ATrackBar.Handle).EndUpdate;
293end;
294
295class procedure TGtk3WSTrackBar.SetOrientation(
296  const ATrackBar: TCustomTrackBar; const AOrientation: TTrackBarOrientation);
297begin
298  // inherited SetOrientation(ATrackBar, AOrientation);
299  if not WSCheckHandleAllocated(ATrackBar, 'SetOrientation') then
300    Exit;
301  if TGtk3TrackBar(ATrackBar.Handle).GetTrackBarOrientation <> AOrientation then
302    RecreateWnd(ATrackBar);
303end;
304
305{ TGtk3WSToolBar }
306
307class function TGtk3WSToolBar.CreateHandle(const AWinControl: TWinControl;
308  const AParams: TCreateParams): TLCLIntfHandle;
309var
310  AToolBar: TGtk3ToolBar;
311begin
312  AToolBar := TGtk3ToolBar.Create(AWinControl, AParams);
313  Result := TLCLIntfHandle(AToolBar);
314end;
315
316{ TGtk3WSProgressBar }
317
318class function TGtk3WSProgressBar.CreateHandle(const AWinControl: TWinControl;
319  const AParams: TCreateParams): TLCLIntfHandle;
320var
321  AProgress: TGtk3ProgressBar;
322begin
323  AProgress := TGtk3ProgressBar.Create(AWinControl, AParams);
324  Result := TLCLIntfHandle(AProgress);
325end;
326
327class procedure TGtk3WSProgressBar.ApplyChanges(
328  const AProgressBar: TCustomProgressBar);
329begin
330  // inherited ApplyChanges(AProgressBar);
331  if not WSCheckHandleAllocated(AProgressBar, 'ApplyChanges') then
332    Exit;
333  TGtk3ProgressBar(AProgressBar.Handle).BeginUpdate;
334  SetPosition(AProgressBar, AProgressBar.Position);
335  SetStyle(AProgressBar, AProgressBar.Style);
336  TGtk3ProgressBar(AProgressBar.Handle).ShowText := AProgressBar.BarShowText;
337  TGtk3ProgressBar(AProgressBar.Handle).Orientation := AProgressBar.Orientation;
338  TGtk3ProgressBar(AProgressBar.Handle).EndUpdate;
339end;
340
341class procedure TGtk3WSProgressBar.SetPosition(
342  const AProgressBar: TCustomProgressBar; const NewPosition: integer);
343begin
344  if not WSCheckHandleAllocated(AProgressBar, 'SetPosition') then
345    Exit;
346  TGtk3ProgressBar(AProgressBar.Handle).BeginUpdate;
347  TGtk3ProgressBar(AProgressBar.Handle).Position := NewPosition;
348  TGtk3ProgressBar(AProgressBar.Handle).EndUpdate;
349end;
350
351class procedure TGtk3WSProgressBar.SetStyle(
352  const AProgressBar: TCustomProgressBar; const NewStyle: TProgressBarStyle);
353begin
354  // inherited SetStyle(AProgressBar, NewStyle);
355  if not WSCheckHandleAllocated(AProgressBar, 'SetStyle') then
356    Exit;
357  TGtk3ProgressBar(AProgressBar.Handle).BeginUpdate;
358  TGtk3ProgressBar(AProgressBar.Handle).Style := NewStyle;
359  TGtk3ProgressBar(AProgressBar.Handle).EndUpdate;
360end;
361
362{ TGtk3WSCustomListView }
363
364class function TGtk3WSCustomListView.CreateHandle(
365  const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
366var
367  AListView: TGtk3ListView;
368begin
369  // DebugLn('TGtk3WSCustomListView.CreateHandle');
370  AListView := TGtk3ListView.Create(AWinControl, AParams);
371  Result := TLCLIntfHandle(AListView);
372end;
373(*
374class procedure TGtk3WSCustomListView.DestroyHandle(
375  const AWinControl: TWinControl);
376begin
377  inherited DestroyHandle(AWinControl);
378end;
379*)
380
381class procedure TGtk3WSCustomListView.SetPropertyInternal(
382  const ALV: TCustomListView; const AProp: TListViewProperty;
383  const AIsSet: Boolean);
384const
385  BoolToSelectionMode: array[Boolean] of TGtkSelectionMode = (
386    1 {GTK_SELECTION_SINGLE},
387    3 {GTK_SELECTION_MULTIPLE}
388  );
389begin
390  case AProp of
391    lvpAutoArrange:
392    begin
393      // TODO: implement ??
394    end;
395    lvpCheckboxes:
396    begin
397      // if TListView(ALV).ViewStyle in [vsReport,vsList] then
398      // AddRemoveCheckboxRenderer(ALV, GetWidgetInfo(Widgets^.MainView), AIsSet);
399    end;
400    lvpColumnClick:
401    begin
402      // allow only column modifications when in report mode
403      if TListView(ALV).ViewStyle <> vsReport then Exit;
404      if TGtk3ListView(ALV.Handle).IsTreeView then
405        PGtkTreeView(TGtk3ListView(ALV.Handle).GetContainerWidget)^.set_headers_clickable(AIsSet);
406    end;
407    lvpFlatScrollBars:
408    begin
409      // TODO: implement ??
410    end;
411    lvpFullDrag:
412    begin
413      // TODO: implement ??
414    end;
415    lvpGridLines:
416    begin
417      // TODO: better implementation
418      // maybe possible with some cellwidget hacking
419      // this create rows with alternating colors
420      if TGtk3ListView(ALV.Handle).IsTreeView then
421      begin
422        if AIsSet then
423          PGtkTreeView(TGtk3ListView(ALV.Handle).GetContainerWidget)^.set_grid_lines(GTK_TREE_VIEW_GRID_LINES_BOTH)
424        else
425          PGtkTreeView(TGtk3ListView(ALV.Handle).GetContainerWidget)^.set_grid_lines(GTK_TREE_VIEW_GRID_LINES_NONE);
426      end;
427    end;
428    lvpHideSelection:
429    begin
430      // TODO: implement
431      // should be possible with some focus in/out events
432    end;
433    lvpHotTrack:
434    begin
435      // TODO: implement
436      // should be possible with some mouse tracking
437    end;
438    lvpMultiSelect:
439    begin
440      if TGtk3ListView(ALV.Handle).IsTreeView then
441        PGtkTreeView(TGtk3ListView(ALV.Handle).GetContainerWidget)^.get_selection^.set_mode(BoolToSelectionMode[AIsSet])
442      else
443        PGtkIconView(TGtk3ListView(ALV.Handle).GetContainerWidget)^.set_selection_mode(BoolToSelectionMode[AIsSet]);
444    end;
445    lvpOwnerDraw:
446    begin
447      // TODO: implement
448      // use custom images/widgets ?
449    end;
450    lvpReadOnly:
451    begin
452      // TODO: implement inline editor ?
453    end;
454    lvpRowSelect:
455    begin
456      // TODO: implement ???
457      // how to do cell select
458    end;
459    lvpShowColumnHeaders:
460    begin
461      // allow only column modifications when in report mode
462      if not (TListView(ALV).ViewStyle in [vsList, vsReport]) then Exit;
463      if TGtk3ListView(ALV.Handle).IsTreeView then
464      begin
465        PGtkTreeView(TGtk3ListView(ALV.Handle).GetContainerWidget)^.set_headers_visible(AIsSet and (TListView(ALV).ViewStyle = vsReport));
466        PGtkTreeView(TGtk3ListView(ALV.Handle).GetContainerWidget)^.resize_children;
467      end;
468    end;
469    lvpShowWorkAreas:
470    begin
471      // TODO: implement ???
472    end;
473    lvpWrapText:
474    begin
475      // TODO: implement ???
476    end;
477  end;
478end;
479
480class procedure TGtk3WSCustomListView.ColumnDelete(const ALV: TCustomListView;
481  const AIndex: Integer);
482begin
483  if not WSCheckHandleAllocated(ALV, 'ColumnDelete') then
484    Exit;
485  // DebugLn('TGtk3WSCustomListView.ColumnDelete ');
486  TGtk3ListView(ALV.Handle).ColumnDelete(AIndex);
487end;
488
489class function TGtk3WSCustomListView.ColumnGetWidth(const ALV: TCustomListView;
490  const AIndex: Integer; const AColumn: TListColumn): Integer;
491begin
492  if not WSCheckHandleAllocated(ALV, 'ColumnGetWidth') then
493    Exit;
494  // DebugLn('TGtk3WSCustomListView.ColumnGetWidth ');
495  Result := TGtk3ListView(ALV.Handle).ColumnGetWidth(AIndex);
496end;
497
498class procedure TGtk3WSCustomListView.ColumnInsert(const ALV: TCustomListView;
499  const AIndex: Integer; const AColumn: TListColumn);
500begin
501  // DebugLn('TGtk3WSCustomListView.ColumnInsert ');
502  if not WSCheckHandleAllocated(ALV, 'ColumnInsert') then
503    Exit;
504  TGtk3ListView(ALV.Handle).ColumnInsert(AIndex, AColumn);
505  // inherited ColumnInsert(ALV, AIndex, AColumn);
506end;
507
508class procedure TGtk3WSCustomListView.ColumnMove(const ALV: TCustomListView;
509  const AOldIndex, ANewIndex: Integer; const AColumn: TListColumn);
510begin
511  DebugLn('TGtk3WSCustomListView.ColumnMove ');
512  // inherited ColumnMove(ALV, AOldIndex, ANewIndex, AColumn);
513end;
514
515class procedure TGtk3WSCustomListView.ColumnSetAlignment(
516  const ALV: TCustomListView; const AIndex: Integer;
517  const AColumn: TListColumn; const AAlignment: TAlignment);
518begin
519  if not WSCheckHandleAllocated(ALV, 'ColumnSetAlignment') then
520    Exit;
521  // DebugLn('TGtk3WSCustomListView.ColumnSetAlignment ');
522  // inherited ColumnSetAlignment(ALV, AIndex, AColumn, AAlignment);
523  TGtk3ListView(ALV.Handle).SetAlignment(AIndex, AColumn, AAlignment);
524end;
525
526class procedure TGtk3WSCustomListView.ColumnSetAutoSize(
527  const ALV: TCustomListView; const AIndex: Integer;
528  const AColumn: TListColumn; const AAutoSize: Boolean);
529begin
530  if not WSCheckHandleAllocated(ALV, 'ColumnSetAutoSize') then
531    Exit;
532  // DebugLn('TGtk3WSCustomListView.ColumnSetAutoSize ');
533  TGtk3ListView(ALV.Handle).SetColumnAutoSize(AIndex, AColumn, AAutoSize);
534  // inherited ColumnSetAutoSize(ALV, AIndex, AColumn, AAutoSize);
535end;
536
537class procedure TGtk3WSCustomListView.ColumnSetCaption(
538  const ALV: TCustomListView; const AIndex: Integer;
539  const AColumn: TListColumn; const ACaption: String);
540begin
541  if not WSCheckHandleAllocated(ALV, 'ColumnSetCaption') then
542    Exit;
543  // DebugLn('TGtk3WSCustomListView.ColumnSetCaption ');
544  // inherited ColumnSetCaption(ALV, AIndex, AColumn, ACaption);
545  TGtk3ListView(ALV.Handle).SetColumnCaption(AIndex, AColumn, ACaption);
546end;
547
548class procedure TGtk3WSCustomListView.ColumnSetImage(
549  const ALV: TCustomListView; const AIndex: Integer;
550  const AColumn: TListColumn; const AImageIndex: Integer);
551begin
552  // DebugLn('TGtk3WSCustomListView.ColumnSetImage ');
553  // inherited ColumnSetImage(ALV, AIndex, AColumn, AImageIndex);
554end;
555
556class procedure TGtk3WSCustomListView.ColumnSetMaxWidth(
557  const ALV: TCustomListView; const AIndex: Integer;
558  const AColumn: TListColumn; const AMaxWidth: Integer);
559begin
560  if not WSCheckHandleAllocated(ALV, 'ColumnSetMaxWidth') then
561    Exit;
562  // DebugLn('TGtk3WSCustomListView.ColumnSetMaxWidth ');
563  TGtk3ListView(ALV.Handle).SetColumnMaxWidth(AIndex, AColumn, AMaxWidth);
564  // inherited ColumnSetMaxWidth(ALV, AIndex, AColumn, AMaxWidth);
565end;
566
567class procedure TGtk3WSCustomListView.ColumnSetMinWidth(
568  const ALV: TCustomListView; const AIndex: Integer;
569  const AColumn: TListColumn; const AMinWidth: integer);
570begin
571  if not WSCheckHandleAllocated(ALV, 'ColumnSetMinWidth') then
572    Exit;
573  // DebugLn('TGtk3WSCustomListView.ColumnSetMinWidth ');
574  TGtk3ListView(ALV.Handle).SetColumnMinWidth(AIndex, AColumn, AMinWidth);
575  // inherited ColumnSetMinWidth(ALV, AIndex, AColumn, AMinWidth);
576end;
577
578class procedure TGtk3WSCustomListView.ColumnSetWidth(
579  const ALV: TCustomListView; const AIndex: Integer;
580  const AColumn: TListColumn; const AWidth: Integer);
581begin
582  if not WSCheckHandleAllocated(ALV, 'ColumnSetWidth') then
583    Exit;
584  // DebugLn('TGtk3WSCustomListView.ColumnSetWidth ');
585  // inherited ColumnSetWidth(ALV, AIndex, AColumn, AWidth);
586  TGtk3ListView(ALV.Handle).SetColumnWidth(AIndex, AColumn, AWidth);
587end;
588
589class procedure TGtk3WSCustomListView.ColumnSetVisible(
590  const ALV: TCustomListView; const AIndex: Integer;
591  const AColumn: TListColumn; const AVisible: Boolean);
592begin
593  if not WSCheckHandleAllocated(ALV, 'ColumnSetVisible') then
594    Exit;
595  // DebugLn('TGtk3WSCustomListView.ColumnSetVisible ');
596  // inherited ColumnSetVisible(ALV, AIndex, AColumn, AVisible);
597  TGtk3ListView(ALV.Handle).SetColumnVisible(AIndex, AColumn, AVisible);
598end;
599
600class procedure TGtk3WSCustomListView.ColumnSetSortIndicator(
601  const ALV: TCustomListView; const AIndex: Integer;
602  const AColumn: TListColumn; const ASortIndicator: TSortIndicator);
603begin
604  if not WSCheckHandleAllocated(ALV, 'ColumnSetSortIndicator') then
605    Exit;
606
607  TGtk3ListView(ALV.Handle).ColumnSetSortIndicator(AIndex,AColumn,ASortIndicator);
608end;
609
610
611
612
613type
614  TListItemHack = class(TListItem)
615  end;
616
617class procedure TGtk3WSCustomListView.ItemDelete(const ALV: TCustomListView;
618  const AIndex: Integer);
619begin
620  if not WSCheckHandleAllocated(ALV, 'ItemDelete') then
621    Exit;
622  TGtk3ListView(ALV.Handle).ItemDelete(AIndex);
623  // DebugLn('TGtk3WSCustomListView.ItemDelete ');
624  // inherited ItemDelete(ALV, AIndex);
625end;
626
627class function TGtk3WSCustomListView.ItemDisplayRect(
628  const ALV: TCustomListView; const AIndex, ASubItem: Integer;
629  ACode: TDisplayCode): TRect;
630begin
631  DebugLn('TGtk3WSCustomListView.ItemDisplayRect ');
632  Result := Rect(0, 0, 0, 0);
633end;
634
635class procedure TGtk3WSCustomListView.ItemExchange(const ALV: TCustomListView;
636  AItem: TListItem; const AIndex1, AIndex2: Integer);
637begin
638  DebugLn('TGtk3WSCustomListView.ItemExchange ');
639  // inherited ItemExchange(ALV, AItem, AIndex1, AIndex2);
640end;
641
642class procedure TGtk3WSCustomListView.ItemMove(const ALV: TCustomListView;
643  AItem: TListItem; const AFromIndex, AToIndex: Integer);
644begin
645  DebugLn('TGtk3WSCustomListView.ItemMove ');
646  // inherited ItemMove(ALV, AItem, AFromIndex, AToIndex);
647end;
648
649class function TGtk3WSCustomListView.ItemGetChecked(const ALV: TCustomListView;
650  const AIndex: Integer; const AItem: TListItem): Boolean;
651begin
652  if not WSCheckHandleAllocated(ALV, 'ItemGetChecked') then
653    Exit;
654  // DebugLn('TGtk3WSCustomListView.ItemGetChecked ');
655  Result := TListItemHack(AItem).GetCheckedInternal;
656end;
657
658class function TGtk3WSCustomListView.ItemGetState(const ALV: TCustomListView;
659  const AIndex: Integer; const AItem: TListItem; const AState: TListItemState;
660  out AIsSet: Boolean): Boolean;
661begin
662  if not WSCheckHandleAllocated(ALV, 'ItemGetState') then
663    Exit;
664  // DebugLn('TGtk3WSCustomListView.ItemGetState ');
665  Result := TGtk3ListView(ALV.Handle).ItemGetState(AIndex, AItem, AState, AIsSet);
666end;
667
668class procedure TGtk3WSCustomListView.ItemInsert(const ALV: TCustomListView;
669  const AIndex: Integer; const AItem: TListItem);
670begin
671  if not WSCheckHandleAllocated(ALV, 'ItemInsert') then
672    Exit;
673  // DebugLn('TGtk3WSCustomListView.ItemInsert ');
674  TGtk3ListView(ALV.Handle).ItemInsert(AIndex, AItem);
675end;
676
677class procedure TGtk3WSCustomListView.ItemSetChecked(
678  const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem;
679  const AChecked: Boolean);
680begin
681  if not WSCheckHandleAllocated(ALV, 'ItemSetChecked') then
682    Exit;
683  // not needed
684  // DebugLn('TGtk3WSCustomListView.ItemSetChecked ');
685  // inherited ItemSetChecked(ALV, AIndex, AItem, AChecked);
686end;
687
688class procedure TGtk3WSCustomListView.ItemSetImage(const ALV: TCustomListView;
689  const AIndex: Integer; const AItem: TListItem; const ASubIndex,
690  AImageIndex: Integer);
691begin
692  // DebugLn('TGtk3WSCustomListView.ItemSetImage ');
693  // inherited ItemSetImage(ALV, AIndex, AItem, ASubIndex, AImageIndex);
694end;
695
696class procedure TGtk3WSCustomListView.ItemSetState(const ALV: TCustomListView;
697  const AIndex: Integer; const AItem: TListItem; const AState: TListItemState;
698  const AIsSet: Boolean);
699begin
700  if not WSCheckHandleAllocated(ALV, 'ItemSetState') then
701    Exit;
702   // DebugLn('TGtk3WSCustomListView.ItemSetState ');
703  // inherited ItemSetState(ALV, AIndex, AItem, AState, AIsSet);
704  TGtk3ListView(ALV.Handle).BeginUpdate;
705  TGtk3ListView(ALV.Handle).ItemSetState(AIndex, AItem, AState, AIsSet);
706  TGtk3ListView(ALV.Handle).EndUpdate;
707end;
708
709class procedure TGtk3WSCustomListView.ItemSetText(const ALV: TCustomListView;
710  const AIndex: Integer; const AItem: TListItem; const ASubIndex: Integer;
711  const AText: String);
712begin
713  if not WSCheckHandleAllocated(ALV, 'ItemSetText') then
714    Exit;
715  // DebugLn('TGtk3WSCustomListView.ItemSetText ');
716  TGtk3ListView(ALV.Handle).ItemSetText(AIndex, ASubIndex, AItem, AText);
717end;
718
719class procedure TGtk3WSCustomListView.ItemShow(const ALV: TCustomListView;
720  const AIndex: Integer; const AItem: TListItem; const PartialOK: Boolean);
721begin
722  DebugLn('TGtk3WSCustomListView.ItemShow ');
723  // inherited ItemShow(ALV, AIndex, AItem, PartialOK);
724end;
725
726class function TGtk3WSCustomListView.ItemGetPosition(
727  const ALV: TCustomListView; const AIndex: Integer): TPoint;
728begin
729  DebugLn('TGtk3WSCustomListView.ItemGetPosition ');
730  Result := Point(0, 0); // inherited ItemGetPosition(ALV, AIndex);
731end;
732
733class procedure TGtk3WSCustomListView.ItemUpdate(const ALV: TCustomListView;
734  const AIndex: Integer; const AItem: TListItem);
735begin
736  DebugLn('TGtk3WSCustomListView.ItemUpdate ');
737  // inherited ItemUpdate(ALV, AIndex, AItem);
738end;
739
740class procedure TGtk3WSCustomListView.BeginUpdate(const ALV: TCustomListView);
741begin
742  // inherited BeginUpdate(ALV);
743  DebugLn('TGtk3WSCustomListView.BeginUpdate ');
744end;
745
746class procedure TGtk3WSCustomListView.EndUpdate(const ALV: TCustomListView);
747begin
748  // inherited EndUpdate(ALV);
749  DebugLn('TGtk3WSCustomListView.EndUpdate ');
750end;
751
752class function TGtk3WSCustomListView.GetBoundingRect(const ALV: TCustomListView
753  ): TRect;
754begin
755  DebugLn('TGtk3WSCustomListView.GetBoundingRect ');
756  Result := Rect(0, 0, 0, 0);
757end;
758
759class function TGtk3WSCustomListView.GetDropTarget(const ALV: TCustomListView
760  ): Integer;
761begin
762  DebugLn('TGtk3WSCustomListView.GetDropTarget ');
763  Result := -1;
764end;
765
766class function TGtk3WSCustomListView.GetFocused(const ALV: TCustomListView
767  ): Integer;
768begin
769  DebugLn('TGtk3WSCustomListView.GetFocused ');
770  Result := -1;
771end;
772
773class function TGtk3WSCustomListView.GetHoverTime(const ALV: TCustomListView
774  ): Integer;
775begin
776  DebugLn('TGtk3WSCustomListView.GetHoverTime ');
777  Result := 0;
778end;
779
780class function TGtk3WSCustomListView.GetItemAt(const ALV: TCustomListView; x,
781  y: integer): Integer;
782var
783  ItemPath: PGtkTreePath;
784  Column: PGtkTreeViewColumn;
785  cx, cy: gint;
786begin
787  Result := -1;
788  if not WSCheckHandleAllocated(ALV, 'GetItemAt') then
789    Exit;
790  if TGtk3ListView(ALV.Handle).IsTreeView then
791  begin
792    //PGtkTreeView(TGtk3ListView(ALV.Handle).GetContainerWidget)^.get_bin_window^.get_position(@cx, @cy);
793    //Dec(x, cx);
794    //Dec(y, cy);
795    ItemPath := nil;
796    Column := nil;
797    if PGtkTreeView(TGtk3ListView(ALV.Handle).GetContainerWidget)^.get_path_at_pos(x, y, @ItemPath, @Column, nil, nil) then
798    begin
799      if ItemPath <> nil then
800      begin
801        Result := gtk_tree_path_get_indices(ItemPath)^;
802        gtk_tree_path_free(ItemPath);
803      end;
804    end;
805  end else
806  begin
807    ItemPath := PGtkIconView(TGtk3ListView(ALV.Handle).GetContainerWidget)^.get_path_at_pos(x, y);
808    if ItemPath <> nil then
809    begin
810      Result := gtk_tree_path_get_indices(ItemPath)^;
811      gtk_tree_path_free(ItemPath);
812    end;
813  end;
814end;
815
816class function TGtk3WSCustomListView.GetSelCount(const ALV: TCustomListView
817  ): Integer;
818begin
819  DebugLn('TGtk3WSCustomListView.GetSelCount ');
820  Result := 0;
821end;
822
823class function TGtk3WSCustomListView.GetSelection(const ALV: TCustomListView
824  ): Integer;
825begin
826  DebugLn('TGtk3WSCustomListView.GetSelection ');
827  Result := -1;
828end;
829
830class function TGtk3WSCustomListView.GetTopItem(const ALV: TCustomListView
831  ): Integer;
832begin
833  DebugLn('TGtk3WSCustomListView.GetTopItem ');
834  Result := 0;
835end;
836
837class function TGtk3WSCustomListView.GetViewOrigin(const ALV: TCustomListView
838  ): TPoint;
839begin
840  DebugLn('TGtk3WSCustomListView.GetViewOrigin ');
841  Result := Point(0, 0);
842  // Result:=inherited GetViewOrigin(ALV);
843end;
844
845class function TGtk3WSCustomListView.GetVisibleRowCount(
846  const ALV: TCustomListView): Integer;
847begin
848  DebugLn('TGtk3WSCustomListView.GetVisibleRowCount ');
849  Result := 0;
850  // Result:=inherited GetVisibleRowCount(ALV);
851end;
852
853class procedure TGtk3WSCustomListView.SetAllocBy(const ALV: TCustomListView;
854  const AValue: Integer);
855begin
856  // DebugLn('TGtk3WSCustomListView.SetAllocBy ');
857  // inherited SetAllocBy(ALV, AValue);
858end;
859
860class procedure TGtk3WSCustomListView.SetColor(const AWinControl: TWinControl);
861begin
862  DebugLn('TGtk3WSCustomListView.SetColor ');
863  inherited SetColor(AWinControl);
864end;
865
866class procedure TGtk3WSCustomListView.SetDefaultItemHeight(
867  const ALV: TCustomListView; const AValue: Integer);
868begin
869  if not WSCheckHandleAllocated(ALV, 'SetDefaultItemHeight') then
870    Exit;
871  // DebugLn('TGtk3WSCustomListView.SetDefaultItemHeight ',dbgs(AValue));
872  if TGtk3ListView(ALV.Handle).IsTreeView then
873    PGtkTreeView(TGtk3ListView(ALV.Handle).GetContainerWidget)^.set_fixed_height_mode(AValue > 0);
874end;
875
876class procedure TGtk3WSCustomListView.SetFont(const AWinControl: TWinControl;
877  const AFont: TFont);
878begin
879  DebugLn('TGtk3WSCustomListView.SetFont ');
880  inherited SetFont(AWinControl, AFont);
881end;
882
883class procedure TGtk3WSCustomListView.SetHotTrackStyles(
884  const ALV: TCustomListView; const AValue: TListHotTrackStyles);
885begin
886  // DebugLn('TGtk3WSCustomListView.SetHotTrackStyles ');
887  // inherited SetHotTrackStyles(ALV, AValue);
888end;
889
890class procedure TGtk3WSCustomListView.SetHoverTime(const ALV: TCustomListView;
891  const AValue: Integer);
892begin
893  // DebugLn('TGtk3WSCustomListView.SetHoverTime ');
894  // inherited SetHoverTime(ALV, AValue);
895end;
896
897class procedure TGtk3WSCustomListView.SetImageList(const ALV: TCustomListView;
898  const AList: TListViewImageList; const AValue: TCustomImageListResolution);
899var
900  AView: TGtk3ListView;
901  i: Integer;
902  Bmp: TBitmap;
903begin
904  if not WSCheckHandleAllocated(ALV, 'SetImageList') then
905    exit;
906  DebugLn('TGtk3WSCustomListView.SetImageList ');
907  AView := TGtk3ListView(ALV.Handle);
908  // inherited SetImageList(ALV, AList, AValue);
909  if ((AList = lvilLarge) and not AView.IsTreeView) or
910     ((AList = lvilSmall) and AView.IsTreeView) then
911  begin
912    if Assigned(AView.Images) then
913      AView.ClearImages
914    else
915      AView.Images := TFPList.Create;
916    if Assigned(AValue) then
917    begin
918      for i := 0 to AValue.Count - 1 do
919      begin
920        Bmp := TBitmap.Create;
921        AValue.GetBitmap(i, Bmp);
922        AView.Images.Add(Bmp);
923      end;
924    end;
925
926    if AView.IsTreeView then
927      AView.UpdateImageCellsSize;
928
929    AView.Update(nil);
930  end;
931end;
932
933class procedure TGtk3WSCustomListView.SetItemsCount(const ALV: TCustomListView;
934  const Avalue: Integer);
935begin
936  DebugLn('TGtk3WSCustomListView.SetItemsCount ');
937  // inherited SetItemsCount(ALV, Avalue);
938end;
939
940class procedure TGtk3WSCustomListView.SetProperty(const ALV: TCustomListView;
941  const AProp: TListViewProperty; const AIsSet: Boolean);
942begin
943  if not WSCheckHandleAllocated(ALV, 'SetProperty') then
944    Exit;
945  // DebugLn('TGtk3WSCustomListView.SetProperty ');
946  SetPropertyInternal(ALV, AProp, AIsSet);
947end;
948
949class procedure TGtk3WSCustomListView.SetProperties(const ALV: TCustomListView;
950  const AProps: TListViewProperties);
951var
952  Prop: TListViewProperty;
953begin
954  if not WSCheckHandleAllocated(ALV, 'SetProperties') then
955    Exit;
956  for Prop := Low(Prop) to High(Prop) do
957    SetPropertyInternal(ALV, Prop, Prop in AProps);
958end;
959
960class procedure TGtk3WSCustomListView.SetScrollBars(const ALV: TCustomListView;
961  const AValue: TScrollStyle);
962var
963  SS: TPoint;
964begin
965  if not WSCheckHandleAllocated(ALV, 'SetScrollBars') then
966    Exit;
967  // DebugLn('TGtk3WSCustomListView.SetScrollbars ');
968  // inherited SetScrollBars(ALV, AValue);
969  SS := Gtk3TranslateScrollStyle(AValue);
970  TGtk3ListView(ALV.Handle).GetScrolledWindow^.set_policy(SS.X, SS.Y);
971end;
972
973class procedure TGtk3WSCustomListView.SetSort(const ALV: TCustomListView;
974  const AType: TSortType; const AColumn: Integer;
975  const ASortDirection: TSortDirection);
976begin
977  if not WSCheckHandleAllocated(ALV, 'SetSort') then
978    Exit;
979  if TGtk3ListView(ALV.Handle).GetContainerWidget^.get_realized then
980    TGtk3ListView(ALV.Handle).GetContainerWidget^.queue_draw;
981  // DebugLn('TGtk3WSCustomListView.SetSort ');
982  // inherited SetSort(ALV, AType, AColumn, ASortDirection);
983end;
984
985class procedure TGtk3WSCustomListView.SetViewOrigin(const ALV: TCustomListView;
986  const AValue: TPoint);
987begin
988  if not WSCheckHandleAllocated(ALV, 'SetViewOrigin') then
989    Exit;
990  if not TGtk3ListView(ALV.Handle).GetContainerWidget^.get_realized then
991    exit;
992  // DebugLn('TGtk3WSCustomListView.SetViewOrigin ');
993  if TGtk3ListView(ALV.Handle).IsTreeView then
994    PGtkTreeView(TGtk3ListView(ALV.Handle).GetContainerWidget)^.scroll_to_point(AValue.X, AValue.Y);
995  // TODO: else
996  //  PGtkIconView(TGtk3ListView(ALV.Handle).GetContainerWidget)^.scroll_to_path();
997end;
998
999class procedure TGtk3WSCustomListView.SetViewStyle(const ALV: TCustomListView;
1000  const AValue: TViewStyle);
1001begin
1002  if not WSCheckHandleAllocated(ALV, 'SetViewStyle') then
1003    Exit;
1004  DebugLn('TGtk3WSCustomListView.SetViewStyle ');
1005  // inherited SetViewStyle(ALV, AValue);
1006end;
1007
1008{ TGtk3WSStatusBar }
1009
1010class function TGtk3WSStatusBar.CreateHandle(const AWinControl: TWinControl;
1011  const AParams: TCreateParams): TLCLIntfHandle;
1012var
1013  AStatusBar: TGtk3StatusBar;
1014begin
1015  AStatusBar := TGtk3StatusBar.Create(AWinControl, AParams);
1016  Result := TLCLIntfHandle(AStatusBar);
1017end;
1018
1019class procedure TGtk3WSStatusBar.PanelUpdate(const AStatusBar: TStatusBar;
1020  PanelIndex: integer);
1021begin
1022  // inherited PanelUpdate(AStatusBar, PanelIndex);
1023end;
1024
1025class procedure TGtk3WSStatusBar.SetPanelText(const AStatusBar: TStatusBar;
1026  PanelIndex: integer);
1027begin
1028  // inherited SetPanelText(AStatusBar, PanelIndex);
1029end;
1030
1031class procedure TGtk3WSStatusBar.Update(const AStatusBar: TStatusBar);
1032begin
1033  // inherited Update(AStatusBar);
1034end;
1035
1036class procedure TGtk3WSStatusBar.GetPreferredSize(
1037  const AWinControl: TWinControl; var PreferredWidth, PreferredHeight: integer;
1038  WithThemeSpace: Boolean);
1039begin
1040  inherited GetPreferredSize(AWinControl, PreferredWidth, PreferredHeight,
1041    WithThemeSpace);
1042end;
1043
1044class procedure TGtk3WSStatusBar.SetSizeGrip(const AStatusBar: TStatusBar;
1045  SizeGrip: Boolean);
1046begin
1047  // inherited SetSizeGrip(AStatusBar, SizeGrip);
1048end;
1049
1050{ TGtk3WSCustomTabControl }
1051
1052class function TGtk3WSCustomTabControl.CreateHandle(
1053  const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
1054begin
1055  if AWinControl is TTabControl then
1056    Result := TLCLIntfHandle(TGtk3CustomControl.Create(AWinControl, AParams))
1057  else
1058    Result := TLCLIntfHandle(TGtk3NoteBook.Create(AWinControl, AParams));
1059end;
1060
1061(*
1062class function TGtk3WSCustomTabControl.GetDefaultClientRect(
1063  const AWinControl: TWinControl; const aLeft, aTop, aWidth, aHeight: integer;
1064  var aClientRect: TRect): boolean;
1065begin
1066  Result:=inherited GetDefaultClientRect(AWinControl, aLeft, aTop, aWidth,
1067    aHeight, aClientRect);
1068end;
1069*)
1070
1071class procedure TGtk3WSCustomTabControl.AddPage(
1072  const ATabControl: TCustomTabControl; const AChild: TCustomPage;
1073  const AIndex: integer);
1074begin
1075  if not WSCheckHandleAllocated(ATabControl, 'AddPage') then
1076    Exit;
1077  // set LCL size
1078  AChild.SetBounds(AChild.Left, AChild.Top, ATabControl.ClientWidth, ATabControl.ClientHeight);
1079
1080  if AChild.TabVisible then
1081    TGtk3Widget(AChild.Handle).Show;
1082
1083  if ATabControl is TTabControl then
1084    exit;
1085
1086  TGtk3Notebook(ATabControl.Handle).InsertPage(AChild, AIndex);
1087end;
1088
1089class procedure TGtk3WSCustomTabControl.MovePage(
1090  const ATabControl: TCustomTabControl; const AChild: TCustomPage;
1091  const NewIndex: integer);
1092begin
1093  if not WSCheckHandleAllocated(ATabControl, 'MovePage') then
1094    Exit;
1095  if (ATabControl is TTabControl) then
1096    exit;
1097  TGtk3Notebook(ATabControl.Handle).MovePage(AChild, NewIndex);
1098end;
1099
1100class procedure TGtk3WSCustomTabControl.RemovePage(
1101  const ATabControl: TCustomTabControl; const AIndex: integer);
1102begin
1103  if not WSCheckHandleAllocated(ATabControl, 'RemovePage') then
1104    Exit;
1105  if (ATabControl is TTabControl) then
1106    exit;
1107  TGtk3Notebook(ATabControl.Handle).RemovePage(AIndex);
1108end;
1109
1110class function TGtk3WSCustomTabControl.GetCapabilities: TCTabControlCapabilities;
1111begin
1112  Result := [nbcShowCloseButtons, nbcMultiLine, nbcPageListPopup, nbcShowAddTabButton];
1113end;
1114
1115class function TGtk3WSCustomTabControl.GetNotebookMinTabHeight(
1116  const AWinControl: TWinControl): integer;
1117begin
1118  Result := inherited GetNotebookMinTabHeight(AWinControl);
1119  // inherited GetNotebookMinTabHeight(AWinControl);
1120end;
1121
1122class function TGtk3WSCustomTabControl.GetNotebookMinTabWidth(
1123  const AWinControl: TWinControl): integer;
1124begin
1125  Result := TWSCustomTabControl.GetNotebookMinTabWidth(AWinControl);
1126end;
1127
1128class function TGtk3WSCustomTabControl.GetTabIndexAtPos(
1129  const ATabControl: TCustomTabControl; const AClientPos: TPoint): integer;
1130var
1131  NoteBookWidget: PGtkNotebook;
1132  TabWidget, PageWidget: PGtkWidget;
1133  i: integer;
1134  AList: PGList;
1135  Allocation: TGtkAllocation;
1136  ARect: TRect;
1137begin
1138  Result:=-1;
1139  if (ATabControl is TTabControl) then
1140    exit;
1141  NoteBookWidget := PGtkNotebook(TGtk3NoteBook(ATabControl.Handle).GetContainerWidget);
1142  if (NotebookWidget=nil) then exit;
1143
1144  AList := NoteBookWidget^.get_children;
1145  try
1146    for i := 0 to g_list_length(AList) - 1 do
1147    begin
1148      PageWidget := NoteBookWidget^.get_nth_page(i);
1149      if (PageWidget<>nil) then
1150      begin
1151        TabWidget := NoteBookWidget^.get_tab_label(PageWidget);
1152        if TabWidget <> nil then
1153        begin
1154          gtk_widget_get_allocation(TabWidget, @Allocation);
1155          ARect := RectFromGdkRect(Allocation);
1156          if PtInRect(ARect, AClientPos) then
1157          begin
1158            Result := I;
1159            break;
1160          end;
1161        end;
1162      end;
1163    end;
1164  finally
1165    if AList <> nil then
1166      g_list_free(Alist);
1167  end;
1168end;
1169
1170class function TGtk3WSCustomTabControl.GetTabRect(
1171  const ATabControl: TCustomTabControl; const AIndex: Integer): TRect;
1172var
1173  NoteBookWidget: PGtkNotebook;
1174  TabWidget, PageWidget: PGtkWidget;
1175  Count: guint;
1176  AList: PGList;
1177  Allocation: TGtkAllocation;
1178  X, Y: gint;
1179begin
1180  Result := inherited;
1181  if (ATabControl is TTabControl) then
1182    exit;
1183  Result := Rect(0, 0, 0, 0);
1184
1185  NoteBookWidget := PGtkNotebook(TGtk3NoteBook(ATabControl.Handle).GetContainerWidget);
1186  if (NotebookWidget=nil) then exit;
1187
1188  AList := NoteBookWidget^.get_children;
1189  try
1190    Count := g_list_length(AList);
1191    PageWidget := NoteBookWidget^.get_nth_page(AIndex);
1192    if (PageWidget<>nil) and (AIndex < Count) then
1193    begin
1194      TabWidget := NoteBookWidget^.get_tab_label(PageWidget);
1195      if TabWidget <> nil then
1196      begin
1197        gtk_widget_get_allocation(TabWidget, @Allocation);
1198        Result := RectFromGdkRect(Allocation);
1199        gtk_widget_get_allocation(NoteBookWidget, @Allocation);
1200        Y := Allocation.y;
1201        X := Allocation.x;
1202        if Y <= 0 then
1203          exit;
1204        case ATabControl.TabPosition of
1205          tpTop, tpBottom:
1206              OffsetRect(Result, 0, -Y);
1207          tpLeft, tpRight:
1208            OffsetRect(Result, -X, -Y);
1209        end;
1210      end;
1211    end;
1212  finally
1213    if AList <> nil then
1214      g_list_free(Alist);
1215  end;
1216end;
1217
1218class procedure TGtk3WSCustomTabControl.SetPageIndex(
1219  const ATabControl: TCustomTabControl; const AIndex: integer);
1220begin
1221  if (ATabControl is TTabControl) then
1222    exit;
1223  if not WSCheckHandleAllocated(ATabControl, 'SetPageIndex') then
1224    Exit;
1225  TGtk3Notebook(ATabControl.Handle).BeginUpdate;
1226  TGtk3Notebook(ATabControl.Handle).SetPageIndex(AIndex);
1227  TGtk3Notebook(ATabControl.Handle).EndUpdate;
1228end;
1229
1230class procedure TGtk3WSCustomTabControl.SetTabCaption(
1231  const ATabControl: TCustomTabControl; const AChild: TCustomPage;
1232  const AText: string);
1233begin
1234  if (ATabControl is TTabControl) then
1235    exit;
1236  if not WSCheckHandleAllocated(ATabControl, 'SetTabCaption') then
1237    Exit;
1238  TGtk3NoteBook(ATabControl.Handle).SetTabLabelText(AChild, AText);
1239end;
1240
1241class procedure TGtk3WSCustomTabControl.SetTabPosition(
1242  const ATabControl: TCustomTabControl; const ATabPosition: TTabPosition);
1243begin
1244  if (ATabControl is TTabControl) then
1245    exit;
1246  if not WSCheckHandleAllocated(ATabControl, 'SetTabPosition') then
1247    Exit;
1248  TGtk3NoteBook(ATabControl.Handle).SetTabPosition(ATabPosition);
1249end;
1250
1251class procedure TGtk3WSCustomTabControl.ShowTabs(
1252  const ATabControl: TCustomTabControl; AShowTabs: boolean);
1253begin
1254  if ATabControl is TTabControl then
1255    exit;
1256  if not WSCheckHandleAllocated(ATabControl, 'ShowTabs') then
1257    Exit;
1258  TGtk3NoteBook(ATabControl.Handle).SetShowTabs(AShowTabs);
1259end;
1260
1261class procedure TGtk3WSCustomTabControl.UpdateProperties(
1262  const ATabControl: TCustomTabControl);
1263begin
1264  if ATabControl is TTabControl then
1265    exit;
1266  // inherited UpdateProperties(ATabControl);
1267  if not WSCheckHandleAllocated(ATabControl, 'ATabControl') then
1268    Exit;
1269
1270  if (nboHidePageListPopup in ATabControl.Options) then
1271    PGtkNotebook(TGtk3NoteBook(ATabControl.Handle).GetContainerWidget)^.popup_disable
1272  else
1273    PGtkNotebook(TGtk3NoteBook(ATabControl.Handle).GetContainerWidget)^.popup_enable;
1274end;
1275
1276
1277{ TGtk3WSCustomPage }
1278
1279class function TGtk3WSCustomPage.CreateHandle(const AWinControl: TWinControl;
1280  const AParams: TCreateParams): TLCLIntfHandle;
1281begin
1282  Result := TLCLIntfHandle(TGtk3Page.Create(AWinControl, AParams));
1283end;
1284
1285class procedure TGtk3WSCustomPage.UpdateProperties(
1286  const ACustomPage: TCustomPage);
1287begin
1288  // inherited UpdateProperties(ACustomPage);
1289  DebugLn('TGtk3WSCustomPage.UpdateProperties missing implementation ');
1290end;
1291
1292class procedure TGtk3WSCustomPage.SetBounds(const AWinControl: TWinControl;
1293  const ALeft, ATop, AWidth, AHeight: Integer);
1294begin
1295  // ignore lcl bounds
1296  // inherited SetBounds(AWinControl, ALeft, ATop, AWidth, AHeight);
1297end;
1298
1299class procedure TGtk3WSCustomPage.SetFont(const AWinControl: TWinControl;
1300  const AFont: TFont);
1301begin
1302  inherited SetFont(AWinControl, AFont);
1303end;
1304
1305class procedure TGtk3WSCustomPage.ShowHide(const AWinControl: TWinControl);
1306begin
1307  // DebugLn('TGtk3WSCustomPage.ShowHide ',AWinControl.Caption);
1308  inherited ShowHide(AWinControl);
1309end;
1310
1311class function TGtk3WSCustomPage.GetDefaultClientRect(
1312  const AWinControl: TWinControl; const aLeft, aTop, aWidth, aHeight: integer;
1313  var aClientRect: TRect): boolean;
1314begin
1315  Result:=false;
1316  if AWinControl.Parent = nil then exit;
1317  if AWinControl.HandleAllocated and AWinControl.Parent.HandleAllocated and
1318    (TGtk3Widget(AWinControl.Handle).Widget^.parent <> nil) then
1319  begin
1320
1321  end else
1322  begin
1323    Result := True;
1324    aClientRect := AWinControl.Parent.ClientRect;
1325    // DebugLn(['TGtk3WSCustomPage.GetDefaultClientRect ',DbgSName(AWinControl),' Parent=',DbgSName(AWinControl.Parent),' ParentBounds=',dbgs(AWinControl.Parent.BoundsRect),' ParentClient=',dbgs(AWinControl.Parent.ClientRect)]);
1326  end;
1327end;
1328
1329end.
1330