1{
2 *****************************************************************************
3 *                              QtWSExtCtrls.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 QtWSExtCtrls;
17
18{$mode objfpc}{$H+}
19
20interface
21
22{$I qtdefines.inc}
23
24uses
25  // Bindings
26  qt5,
27  qtwidgets, qtobjects, qtproc, QtWSControls,
28  // LCL
29  SysUtils, Classes, Controls, Graphics, Forms, ExtCtrls, LCLType, LazUTF8,
30  // Widgetset
31  WSExtCtrls, WSLCLClasses;
32
33type
34  { TQtWSPage }
35
36  TQtWSPage = class(TWSPage)
37  published
38  end;
39
40  { TQtWSNotebook }
41
42  TQtWSNotebook = class(TWSNotebook)
43  published
44  end;
45
46  { TQtWSShape }
47
48  TQtWSShape = class(TWSShape)
49  published
50  end;
51
52  { TQtWSCustomSplitter }
53
54  TQtWSCustomSplitter = class(TWSCustomSplitter)
55  published
56  end;
57
58  { TQtWSSplitter }
59
60  TQtWSSplitter = class(TWSSplitter)
61  published
62  end;
63
64  { TQtWSPaintBox }
65
66  TQtWSPaintBox = class(TWSPaintBox)
67  published
68  end;
69
70  { TQtWSCustomImage }
71
72  TQtWSCustomImage = class(TWSCustomImage)
73  published
74  end;
75
76  { TQtWSImage }
77
78  TQtWSImage = class(TWSImage)
79  published
80  end;
81
82  { TQtWSBevel }
83
84  TQtWSBevel = class(TWSBevel)
85  published
86  end;
87
88  { TQtWSCustomRadioGroup }
89
90  TQtWSCustomRadioGroup = class(TWSCustomRadioGroup)
91  published
92    class function  CreateHandle(const AWinControl: TWinControl;
93      const AParams: TCreateParams): TLCLIntfHandle; override;
94  end;
95
96  { TQtWSRadioGroup }
97
98  TQtWSRadioGroup = class(TWSRadioGroup)
99  published
100  end;
101
102  { TQtWSCustomCheckGroup }
103
104  TQtWSCustomCheckGroup = class(TWSCustomCheckGroup)
105  published
106    class function  CreateHandle(const AWinControl: TWinControl;
107      const AParams: TCreateParams): TLCLIntfHandle; override;
108  end;
109
110  { TQtWSCheckGroup }
111
112  TQtWSCheckGroup = class(TWSCheckGroup)
113  published
114  end;
115
116  { TQtWSCustomLabeledEdit }
117
118  TQtWSCustomLabeledEdit = class(TWSCustomLabeledEdit)
119  published
120  end;
121
122  { TQtWSLabeledEdit }
123
124  TQtWSLabeledEdit = class(TWSLabeledEdit)
125  published
126  end;
127
128  { TQtWSCustomPanel }
129
130  TQtWSCustomPanel = class(TWSCustomPanel)
131  published
132    class function CreateHandle(const AWinControl: TWinControl;
133          const AParams: TCreateParams): TLCLIntfHandle; override;
134    class function GetDefaultColor(const AControl: TControl; const ADefaultColorType: TDefaultColorType): TColor; override;
135  end;
136
137  { TQtWSPanel }
138
139  TQtWSPanel = class(TWSPanel)
140  published
141  end;
142
143  { TQtWSCustomTrayIcon }
144
145  TQtWSCustomTrayIcon = class(TWSCustomTrayIcon)
146  published
147    class function Hide(const ATrayIcon: TCustomTrayIcon): Boolean; override;
148    class function Show(const ATrayIcon: TCustomTrayIcon): Boolean; override;
149    class procedure InternalUpdate(const ATrayIcon: TCustomTrayIcon); override;
150    class function ShowBalloonHint(const ATrayIcon: TCustomTrayIcon): Boolean; override;
151    class function GetPosition(const ATrayIcon: TCustomTrayIcon): TPoint; override;
152    class function GetCanvas(const ATrayIcon: TCustomTrayIcon): TCanvas; override;
153  end;
154
155implementation
156uses qtsystemtrayicon;
157
158{ TQtWSCustomPanel }
159
160{------------------------------------------------------------------------------
161  Method: TQtWSCustomPanel.CreateHandle
162  Params:  None
163  Returns: Nothing
164
165  Allocates memory and resources for the control and shows it
166 ------------------------------------------------------------------------------}
167class function TQtWSCustomPanel.CreateHandle(const AWinControl: TWinControl;
168  const AParams: TCreateParams): TLCLIntfHandle;
169var
170  QtFrame: TQtFrame;
171begin
172  QtFrame := TQtFrame.Create(AWinControl, AParams);
173  QtFrame.AttachEvents;
174
175  // Set's initial properties
176  QtFrame.setFrameShape(TBorderStyleToQtFrameShapeMap[TCustomPanel(AWinControl).BorderStyle]);
177
178  // Return the Handle
179  Result := TLCLIntfHandle(QtFrame);
180end;
181
182class function TQtWSCustomPanel.GetDefaultColor(const AControl: TControl;
183  const ADefaultColorType: TDefaultColorType): TColor;
184const
185  DefColors: array[TDefaultColorType] of TColor = (
186 { dctBrush } clBackground,
187 { dctFont  } clBtnText
188  );
189begin
190  Result := DefColors[ADefaultColorType];
191end;
192
193{ TQtWSCustomRadioGroup }
194
195{------------------------------------------------------------------------------
196  Method: TQtWSCustomRadioGroup.CreateHandle
197  Params:  None
198  Returns: Nothing
199
200  Allocates memory and resources for the control and shows it
201 ------------------------------------------------------------------------------}
202
203class function TQtWSCustomRadioGroup.CreateHandle(const AWinControl: TWinControl;
204  const AParams: TCreateParams): TLCLIntfHandle;
205var
206  QtGroupBox: TQtGroupBox;
207  Str: WideString;
208begin
209  QtGroupBox := TQtGroupBox.Create(AWinControl, AParams);
210  QtGroupBox.GroupBoxType := tgbtRadioGroup;
211
212  Str := GetUtf8String(AWinControl.Caption);
213  QGroupBox_setTitle(QGroupBoxH(QtGroupBox.Widget), @Str);
214
215  QtGroupBox.AttachEvents;
216
217  Result := TLCLIntfHandle(QtGroupBox);
218end;
219
220{ TQtWSCustomCheckGroup }
221
222{------------------------------------------------------------------------------
223  Method: TQtWSCustomCheckGroup.CreateHandle
224  Params:  None
225  Returns: Nothing
226
227  Allocates memory and resources for the control and shows it
228 ------------------------------------------------------------------------------}
229class function TQtWSCustomCheckGroup.CreateHandle(const AWinControl: TWinControl;
230  const AParams: TCreateParams): TLCLIntfHandle;
231var
232  QtGroupBox: TQtGroupBox;
233  Str: WideString;
234begin
235  QtGroupBox := TQtGroupBox.Create(AWinControl, AParams);
236  QtGroupBox.GroupBoxType := tgbtCheckGroup;
237
238  Str := GetUtf8String(AWinControl.Caption);
239  QGroupBox_setTitle(QGroupBoxH(QtGroupBox.Widget), @Str);
240
241  QtGroupBox.AttachEvents;
242
243  Result := TLCLIntfHandle(QtGroupBox);
244end;
245
246{ TQtWSCustomTrayIcon }
247
248class function TQtWSCustomTrayIcon.Hide(const ATrayIcon: TCustomTrayIcon): Boolean;
249var
250  SystemTrayIcon: TQtSystemTrayIcon;
251begin
252  Result := False;
253
254  SystemTrayIcon := TQtSystemTrayIcon(ATrayIcon.Handle);
255
256  SystemTrayIcon.Hide;
257
258  SystemTrayIcon.Free;
259
260  ATrayIcon.Handle := 0;
261
262  Result := True;
263end;
264
265class function TQtWSCustomTrayIcon.Show(const ATrayIcon: TCustomTrayIcon): Boolean;
266var
267  Text: WideString;
268  SystemTrayIcon: TQtSystemTrayIcon;
269  IconH: QIconH;
270begin
271  Result := False;
272
273  if ATrayIcon.Icon.Handle = 0 then
274    IconH := nil
275  else
276    IconH := TQtIcon(ATrayIcon.Icon.Handle).Handle;
277
278  SystemTrayIcon := TQtSystemTrayIcon.Create(IconH);
279  SystemTrayIcon.FTrayIcon := ATrayIcon;
280
281  ATrayIcon.Handle := HWND(SystemTrayIcon);
282
283  Text := UTF8ToUTF16(ATrayIcon.Hint);
284  SystemTrayIcon.setToolTip(Text);
285
286  if Assigned(ATrayIcon.PopUpMenu) then
287    if TQtMenu(ATrayIcon.PopUpMenu.Handle).Widget <> nil then
288      SystemTrayIcon.setContextMenu(QMenuH(TQtMenu(ATrayIcon.PopUpMenu.Handle).Widget));
289
290  SystemTrayIcon.show;
291
292  Result := True;
293end;
294
295{*******************************************************************
296*  TQtWSCustomTrayIcon.InternalUpdate ()
297*
298*  DESCRIPTION:    Makes modifications to the Icon while running
299*                  i.e. without hiding it and showing again
300*******************************************************************}
301class procedure TQtWSCustomTrayIcon.InternalUpdate(const ATrayIcon: TCustomTrayIcon);
302var
303  SystemTrayIcon: TQtSystemTrayIcon;
304  AIcon: QIconH;
305  AHint: WideString;
306begin
307  if (ATrayIcon.Handle = 0) then Exit;
308
309  SystemTrayIcon := TQtSystemTrayIcon(ATrayIcon.Handle);
310  if Assigned(ATrayIcon.Icon) then
311  begin
312    // animate
313    if ATrayIcon.Animate and Assigned(ATrayIcon.Icons) then
314      SystemTrayIcon.setIcon(TQtImage(ATrayIcon.Icon.BitmapHandle).AsIcon)
315    else
316    // normal
317    if (ATrayIcon.Icon.Handle <> 0) then
318      SystemTrayIcon.setIcon(TQtIcon(ATrayIcon.Icon.Handle).Handle)
319    else
320    begin
321      AIcon := QIcon_create();
322      SystemTrayIcon.setIcon(AIcon);
323      QIcon_destroy(AIcon);
324    end;
325  end else
326  begin
327    AIcon := QIcon_create;
328    SystemTrayIcon.setIcon(AIcon);
329    QIcon_destroy(AIcon);
330  end;
331
332
333  { PopUpMenu }
334  if Assigned(ATrayIcon.PopUpMenu) then
335    if TQtMenu(ATrayIcon.PopUpMenu.Handle).Widget <> nil then
336      SystemTrayIcon.setContextMenu(QMenuH(TQtMenu(ATrayIcon.PopUpMenu.Handle).Widget));
337
338  AHint := UTF8ToUTF16(ATrayIcon.Hint);
339  SystemTrayIcon.setToolTip(AHint);
340
341  SystemTrayIcon.UpdateSystemTrayWidget;
342end;
343
344class function TQtWSCustomTrayIcon.ShowBalloonHint(
345  const ATrayIcon: TCustomTrayIcon): Boolean;
346var
347  QtTrayIcon: TQtSystemTrayIcon;
348begin
349  Result := False;
350  if (ATrayIcon.Handle = 0) then Exit;
351  QtTrayIcon := TQtSystemTrayIcon(ATrayIcon.Handle);
352
353  QtTrayIcon.showBaloonHint(ATrayIcon.BalloonTitle, ATrayIcon.BalloonHint,
354    QSystemTrayIconMessageIcon(Ord(ATrayIcon.BalloonFlags)),
355    ATrayIcon.BalloonTimeout);
356
357  Result := True;
358end;
359
360class function TQtWSCustomTrayIcon.GetPosition(const ATrayIcon: TCustomTrayIcon): TPoint;
361begin
362  Result := Point(0, 0);
363  if (ATrayIcon.Handle = 0) then
364    exit;
365  Result := TQtSystemTrayIcon(ATrayIcon.Handle).GetPosition;
366end;
367
368class function TQtWSCustomTrayIcon.GetCanvas(const ATrayIcon: TCustomTrayIcon
369  ): TCanvas;
370begin
371  Result := nil;
372  if (ATrayIcon.Handle <> 0) then
373    Result := TQtSystemTrayIcon(ATrayIcon.Handle).Canvas;
374end;
375
376end.
377