~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to lcl/interfaces/customdrawn/customdrawnwscomctrls.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
2
 *****************************************************************************
 
3
 *                           CustomDrawnWSComCtrls.pas                       *
 
4
 *                              ---------------                              *
 
5
 *                                                                           *
 
6
 *                                                                           *
 
7
 *****************************************************************************
 
8
 
 
9
 *****************************************************************************
 
10
 *                                                                           *
 
11
 *  This file is part of the Lazarus Component Library (LCL)                 *
 
12
 *                                                                           *
 
13
 *  See the file COPYING.modifiedLGPL.txt, included in this distribution,    *
 
14
 *  for details about the copyright.                                         *
 
15
 *                                                                           *
 
16
 *  This program is distributed in the hope that it will be useful,          *
 
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
 
19
 *                                                                           *
 
20
 *****************************************************************************
 
21
}
 
22
unit CustomDrawnWSComCtrls;
 
23
 
 
24
{$mode objfpc}{$H+}
 
25
 
 
26
interface
 
27
 
 
28
//{$I qtdefines.inc}
 
29
 
 
30
uses
 
31
  // LCL
 
32
  SysUtils, Classes, Types, ComCtrls, Controls, LCLType, Graphics, StdCtrls,
 
33
  LCLProc, LCLIntf, Forms, ImgList,
 
34
  customdrawncontrols, customdrawn_common,
 
35
  // Widgetset
 
36
  WSProc, WSComCtrls, WSLCLClasses,
 
37
  // LCL-CustomDrawn
 
38
  customdrawnproc, customdrawnwscontrols, customdrawnprivate;
 
39
 
 
40
type
 
41
  { TCDWSCustomPage }
 
42
 
 
43
  TCDWSCustomPage = class(TWSCustomPage)
 
44
  published
 
45
{    class function CreateHandle(const AWinControl: TWinControl;
 
46
          const AParams: TCreateParams): TLCLIntfHandle; override;
 
47
    class procedure UpdateProperties(const ACustomPage: TCustomPage); override;}
 
48
  end;
 
49
 
 
50
  { TCDWSCustomTabControl }
 
51
 
 
52
  TCDWSCustomTabControl = class(TWSCustomTabControl)
 
53
  public
 
54
    class procedure CreateCDControl(const AWinControl: TWinControl; var ACDControlField: TCDControl);
 
55
  published
 
56
    class function  CreateHandle(const AWinControl: TWinControl;
 
57
          const AParams: TCreateParams): TLCLIntfHandle; override;
 
58
    class procedure ShowHide(const AWinControl: TWinControl); 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;
 
65
      const AIndex: integer); override;
 
66
 
 
67
    class function GetCapabilities: TCTabControlCapabilities; override;
 
68
    class function GetDesignInteractive(const AWinControl: TWinControl; AClientPos: TPoint): Boolean; 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
  { TCDWSStatusBar }
 
79
 
 
80
  TCDWSStatusBar = class(TWSStatusBar)
 
81
  published
 
82
{    class function  CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
 
83
    class procedure DestroyHandle(const AWinControl: TWinControl); override;
 
84
    class procedure PanelUpdate(const AStatusBar: TStatusBar; PanelIndex: integer); override;
 
85
    class procedure SetPanelText(const AStatusBar: TStatusBar; PanelIndex: integer); override;
 
86
    class procedure SetSizeGrip(const AStatusBar: TStatusBar; SizeGrip: Boolean); override;
 
87
    class procedure Update(const AStatusBar: TStatusBar); override;}
 
88
  end;
 
89
 
 
90
  { TCDWSTabSheet }
 
91
 
 
92
  TCDWSTabSheet = class(TWSTabSheet)
 
93
  published
 
94
  end;
 
95
 
 
96
  { TCDWSPageControl }
 
97
 
 
98
  TCDWSPageControl = class(TWSPageControl)
 
99
  published
 
100
  end;
 
101
 
 
102
  { TCDWSCustomListView }
 
103
 
 
104
  TCDWSCustomListView = class(TWSCustomListView)
 
105
  published
 
106
{    class function CreateHandle(const AWinControl: TWinControl;
 
107
     const AParams: TCreateParams): TLCLIntfHandle; override;
 
108
    class procedure ColumnDelete(const ALV: TCustomListView; const AIndex: Integer); override;
 
109
    class procedure ColumnInsert(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn); override;
 
110
    class function  ColumnGetWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn): Integer; override;
 
111
    class procedure ColumnSetWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AWidth: Integer); override;
 
112
    class procedure ColumnSetVisible(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AVisible: Boolean); override;
 
113
    class procedure ColumnSetAlignment(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AAlignment: TAlignment); override;
 
114
    class procedure ColumnSetAutoSize(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AAutoSize: Boolean); override;
 
115
    class procedure ColumnSetCaption(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const ACaption: String); override;
 
116
    class procedure ColumnSetImage(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AImageIndex: Integer); override;
 
117
 
 
118
    class procedure ColumnSetMinWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AMinWidth: integer); override;
 
119
    class procedure ColumnMove(const ALV: TCustomListView; const AOldIndex, ANewIndex: Integer; const AColumn: TListColumn); override;
 
120
 
 
121
 
 
122
    {items}
 
123
    class procedure ItemInsert(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem); override;
 
124
    class procedure ItemDelete(const ALV: TCustomListView; const AIndex: Integer); override;
 
125
    class procedure ItemExchange(const ALV: TCustomListView; AItem: TListItem; const AIndex1, AIndex2: Integer); override;
 
126
    class procedure ItemMove(const ALV: TCustomListView; AItem: TListItem; const AFromIndex, AToIndex: Integer); override;
 
127
    class function  ItemGetChecked(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem): Boolean; override;
 
128
    class procedure ItemSetChecked(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const AChecked: Boolean); override;
 
129
    class function  ItemGetPosition(const ALV: TCustomListView; const AIndex: Integer): TPoint; override;
 
130
    class function  ItemGetState(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const AState: TListItemState; out AIsSet: Boolean): Boolean; override; // returns True if supported
 
131
    class procedure ItemSetImage(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const ASubIndex, AImageIndex: Integer); override;
 
132
    class procedure ItemSetState(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const AState: TListItemState; const AIsSet: Boolean); override;
 
133
    class procedure ItemSetText(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const ASubIndex: Integer; const AText: String); override;
 
134
    class procedure ItemShow(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const PartialOK: Boolean); override;
 
135
    class function  ItemDisplayRect(const ALV: TCustomListView; const AIndex, ASubItem: Integer; ACode: TDisplayCode): TRect; override;
 
136
 
 
137
    {parent}
 
138
    class procedure BeginUpdate(const ALV: TCustomListView); override;
 
139
    class procedure EndUpdate(const ALV: TCustomListView); override;
 
140
 
 
141
    class function GetFocused(const ALV: TCustomListView): Integer; override;
 
142
    class function GetItemAt(const ALV: TCustomListView; x,y: integer): Integer; override;
 
143
    class function GetSelCount(const ALV: TCustomListView): Integer; override;
 
144
    class function GetSelection(const ALV: TCustomListView): Integer; override;
 
145
    class function GetTopItem(const ALV: TCustomListView): Integer; override;
 
146
    class procedure SetSort(const ALV: TCustomListView; const AType: TSortType; const AColumn: Integer;
 
147
      const ASortDirection: TSortDirection); override;
 
148
 
 
149
    class function GetBoundingRect(const ALV: TCustomListView): TRect; override;
 
150
    class function GetViewOrigin(const ALV: TCustomListView): TPoint; override;
 
151
    class function GetVisibleRowCount(const ALV: TCustomListView): Integer; override;
 
152
 
 
153
    class procedure SetAllocBy(const ALV: TCustomListView; const AValue: Integer); override;
 
154
    class procedure SetIconArrangement(const ALV: TCustomListView; const AValue: TIconArrangement); override;
 
155
    class procedure SetItemsCount(const ALV: TCustomListView; const Avalue: Integer); override;
 
156
    class procedure SetOwnerData(const ALV: TCustomListView; const AValue: Boolean); override;
 
157
 
 
158
    class procedure SetProperty(const ALV: TCustomListView; const AProp: TListViewProperty; const AIsSet: Boolean); override;
 
159
    class procedure SetProperties(const ALV: TCustomListView; const AProps: TListViewProperties); override;
 
160
 
 
161
    class procedure SetScrollBars(const ALV: TCustomListView; const AValue: TScrollStyle); override;
 
162
    class procedure SetViewStyle(const ALV: TCustomListView; const Avalue: TViewStyle); override;
 
163
           }
 
164
    (*
 
165
    // Column
 
166
 
 
167
    class procedure ColumnSetMaxWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AMaxWidth: Integer); override;
 
168
 
 
169
 
 
170
    // Item
 
171
    class function ItemSetPosition(const ALV: TCustomListView; const AIndex: Integer; const ANewPosition: TPoint): Boolean; virtual;
 
172
 
 
173
    // LV
 
174
 
 
175
    class function GetDropTarget(const ALV: TCustomListView): Integer; virtual;
 
176
 
 
177
    class function GetHoverTime(const ALV: TCustomListView): Integer; virtual;
 
178
    class function GetViewOrigin(const ALV: TCustomListView): TPoint; virtual;
 
179
 
 
180
    class procedure SetDefaultItemHeight(const ALV: TCustomListView; const AValue: Integer); virtual;
 
181
    class procedure SetHotTrackStyles(const ALV: TCustomListView; const AValue: TListHotTrackStyles); virtual;
 
182
    class procedure SetHoverTime(const ALV: TCustomListView; const AValue: Integer); virtual;
 
183
    class procedure SetImageList(const ALV: TCustomListView; const AList: TListViewImageList; const AValue: TCustomImageList); virtual;
 
184
 
 
185
    class procedure SetViewOrigin(const ALV: TCustomListView; const AValue: TPoint); virtual;
 
186
    *)
 
187
  end;
 
188
 
 
189
  { TCDWSListView }
 
190
 
 
191
  TCDWSListView = class(TWSListView)
 
192
  published
 
193
  end;
 
194
 
 
195
  { TCDWSProgressBar }
 
196
 
 
197
  TCDWSProgressBar = class(TWSProgressBar)
 
198
  public
 
199
    class procedure CreateCDControl(const AWinControl: TWinControl; var ACDControlField: TCDControl);
 
200
  published
 
201
    class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
 
202
    class procedure ShowHide(const AWinControl: TWinControl); override;
 
203
    class procedure ApplyChanges(const AProgressBar: TCustomProgressBar); override;
 
204
    class procedure SetPosition(const AProgressBar: TCustomProgressBar; const NewPosition: integer); override;
 
205
//    class procedure SetStyle(const AProgressBar: TCustomProgressBar; const NewStyle: TProgressBarStyle); override;
 
206
  end;
 
207
 
 
208
  { TCDWSCustomUpDown }
 
209
 
 
210
  TCDWSCustomUpDown = class(TWSCustomUpDown)
 
211
  published
 
212
  end;
 
213
 
 
214
  { TCDWSUpDown }
 
215
 
 
216
  TCDWSUpDown = class(TWSUpDown)
 
217
  published
 
218
  end;
 
219
 
 
220
  { TCDWSToolButton }
 
221
 
 
222
  TCDWSToolButton = class(TWSToolButton)
 
223
  published
 
224
  end;
 
225
 
 
226
  { TCDWSToolBar }
 
227
 
 
228
  TCDWSToolBar = class(TWSToolBar)
 
229
  published
 
230
//    class function  CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
 
231
  end;
 
232
 
 
233
  { TCDWSTrackBar }
 
234
 
 
235
  TCDWSTrackBar = class(TWSTrackBar)
 
236
  public
 
237
    class procedure CreateCDControl(const AWinControl: TWinControl; var ACDControlField: TCDControl);
 
238
  published
 
239
    class function  CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
 
240
    class procedure ShowHide(const AWinControl: TWinControl); override;
 
241
    class procedure ApplyChanges(const ATrackBar: TCustomTrackBar); override;
 
242
    class function  GetPosition(const ATrackBar: TCustomTrackBar): integer; override;
 
243
    class procedure SetPosition(const ATrackBar: TCustomTrackBar; const NewPosition: integer); override;
 
244
    class procedure SetOrientation(const ATrackBar: TCustomTrackBar; const AOrientation: TTrackBarOrientation); override;
 
245
  end;
 
246
 
 
247
  { TCDWSCustomTreeView }
 
248
 
 
249
  TCDWSCustomTreeView = class(TWSCustomTreeView)
 
250
  published
 
251
  end;
 
252
 
 
253
  { TCDWSTreeView }
 
254
 
 
255
  TCDWSTreeView = class(TWSTreeView)
 
256
  published
 
257
  end;
 
258
 
 
259
 
 
260
implementation
 
261
 
 
262
{ TCDWSCustomTabControl }
 
263
 
 
264
class procedure TCDWSCustomTabControl.CreateCDControl(
 
265
  const AWinControl: TWinControl; var ACDControlField: TCDControl);
 
266
begin
 
267
  ACDControlField := TCDIntfPageControl.Create(AWinControl);
 
268
  TCDIntfPageControl(ACDControlField).LCLControl := TCustomTabControl(AWinControl);
 
269
  ACDControlField.Parent := AWinControl;
 
270
  ACDControlField.Align := alClient;
 
271
end;
 
272
 
 
273
class function TCDWSCustomTabControl.CreateHandle(
 
274
  const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
 
275
var
 
276
  lCDWinControl: TCDWinControl;
 
277
begin
 
278
  Result := TCDWSWinControl.CreateHandle(AWinControl, AParams);
 
279
  lCDWinControl := TCDWinControl(Result);
 
280
end;
 
281
 
 
282
class procedure TCDWSCustomTabControl.ShowHide(const AWinControl: TWinControl);
 
283
var
 
284
  lCDWinControl: TCDWinControl;
 
285
begin
 
286
  lCDWinControl := TCDWinControl(AWinControl.Handle);
 
287
 
 
288
  TCDWSWinControl.ShowHide(AWinControl);
 
289
 
 
290
  if lCDWinControl.CDControl = nil then
 
291
    CreateCDControl(AWinControl, lCDWinControl.CDControl);
 
292
end;
 
293
 
 
294
class procedure TCDWSCustomTabControl.AddPage(
 
295
  const ATabControl: TCustomTabControl; const AChild: TCustomPage;
 
296
  const AIndex: integer);
 
297
var
 
298
  lCDWinControl: TCDWinControl;
 
299
begin
 
300
  lCDWinControl := TCDWinControl(ATabControl.Handle);
 
301
 
 
302
  if lCDWinControl.CDControl = nil then
 
303
    CreateCDControl(ATabControl, lCDWinControl.CDControl);
 
304
 
 
305
  TCDPageControl(lCDWinControl.CDControl).InsertPage(AIndex, AChild.Caption);
 
306
end;
 
307
 
 
308
class procedure TCDWSCustomTabControl.MovePage(
 
309
  const ATabControl: TCustomTabControl; const AChild: TCustomPage;
 
310
  const NewIndex: integer);
 
311
begin
 
312
  inherited MovePage(ATabControl, AChild, NewIndex);
 
313
end;
 
314
 
 
315
class procedure TCDWSCustomTabControl.RemovePage(
 
316
  const ATabControl: TCustomTabControl; const AIndex: integer);
 
317
begin
 
318
  inherited RemovePage(ATabControl, AIndex);
 
319
end;
 
320
 
 
321
class function TCDWSCustomTabControl.GetCapabilities: TCTabControlCapabilities;
 
322
begin
 
323
  Result:=inherited GetCapabilities;
 
324
end;
 
325
 
 
326
class function TCDWSCustomTabControl.GetDesignInteractive(
 
327
  const AWinControl: TWinControl; AClientPos: TPoint): Boolean;
 
328
begin
 
329
  Result:=inherited GetDesignInteractive(AWinControl, AClientPos);
 
330
end;
 
331
 
 
332
class function TCDWSCustomTabControl.GetTabIndexAtPos(
 
333
  const ATabControl: TCustomTabControl; const AClientPos: TPoint): integer;
 
334
begin
 
335
  Result:=inherited GetTabIndexAtPos(ATabControl, AClientPos);
 
336
end;
 
337
 
 
338
class function TCDWSCustomTabControl.GetTabRect(
 
339
  const ATabControl: TCustomTabControl; const AIndex: Integer): TRect;
 
340
begin
 
341
  Result:=inherited GetTabRect(ATabControl, AIndex);
 
342
end;
 
343
 
 
344
class procedure TCDWSCustomTabControl.SetPageIndex(
 
345
  const ATabControl: TCustomTabControl; const AIndex: integer);
 
346
begin
 
347
  inherited SetPageIndex(ATabControl, AIndex);
 
348
end;
 
349
 
 
350
class procedure TCDWSCustomTabControl.SetTabCaption(
 
351
  const ATabControl: TCustomTabControl; const AChild: TCustomPage;
 
352
  const AText: string);
 
353
begin
 
354
  inherited SetTabCaption(ATabControl, AChild, AText);
 
355
end;
 
356
 
 
357
class procedure TCDWSCustomTabControl.SetTabPosition(
 
358
  const ATabControl: TCustomTabControl; const ATabPosition: TTabPosition);
 
359
begin
 
360
  inherited SetTabPosition(ATabControl, ATabPosition);
 
361
end;
 
362
 
 
363
class procedure TCDWSCustomTabControl.ShowTabs(
 
364
  const ATabControl: TCustomTabControl; AShowTabs: boolean);
 
365
begin
 
366
  inherited ShowTabs(ATabControl, AShowTabs);
 
367
end;
 
368
 
 
369
class procedure TCDWSCustomTabControl.UpdateProperties(
 
370
  const ATabControl: TCustomTabControl);
 
371
begin
 
372
  inherited UpdateProperties(ATabControl);
 
373
end;
 
374
 
 
375
(*{ TCDWSToolBar }
 
376
 
 
377
class function TCDWSToolBar.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
 
378
var
 
379
  QtToolBar: TQtCustomControl;
 
380
begin
 
381
  {$note TToolBar implementation under LCL is wrong. TToolBar isn't
 
382
  TCustomControl but TWinControl.
 
383
  To avoid theoretical crashes we use TQtCustomControl here, but indeed it
 
384
  should be TQtWidget - so no viewport.}
 
385
  QtToolBar := TQtCustomControl.Create(AWinControl, AParams);
 
386
  QtToolBar.setFrameShape(QFrameNoFrame);
 
387
  QtToolBar.viewportNeeded;
 
388
  QtToolBar.setFocusPolicy(QtTabFocus);
 
389
  QtToolBar.AttachEvents;
 
390
  Result := TLCLIntfHandle(QtToolBar);
 
391
end;*)
 
392
 
 
393
{ TCDWSTrackBar }
 
394
 
 
395
class procedure TCDWSTrackBar.CreateCDControl(const AWinControl: TWinControl; var ACDControlField: TCDControl);
 
396
begin
 
397
  ACDControlField := TCDIntfTrackBar.Create(AWinControl);
 
398
  TCDIntfTrackBar(ACDControlField).LCLControl := TCustomTrackBar(AWinControl);
 
399
  ACDControlField.Parent := AWinControl;
 
400
  ACDControlField.Align := alClient;
 
401
end;
 
402
 
 
403
class function TCDWSTrackBar.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
 
404
var
 
405
  lCDWinControl: TCDWinControl;
 
406
begin
 
407
  Result := TCDWSWinControl.CreateHandle(AWinControl, AParams);
 
408
  lCDWinControl := TCDWinControl(Result);
 
409
end;
 
410
 
 
411
class procedure TCDWSTrackBar.ShowHide(const AWinControl: TWinControl);
 
412
var
 
413
  lCDWinControl: TCDWinControl;
 
414
begin
 
415
  lCDWinControl := TCDWinControl(AWinControl.Handle);
 
416
 
 
417
  TCDWSWinControl.ShowHide(AWinControl);
 
418
 
 
419
  if lCDWinControl.CDControl = nil then
 
420
    CreateCDControl(AWinControl, lCDWinControl.CDControl);
 
421
end;
 
422
 
 
423
class procedure TCDWSTrackBar.ApplyChanges(const ATrackBar: TCustomTrackBar);
 
424
var
 
425
  lCDWinControl: TCDWinControl;
 
426
begin
 
427
  lCDWinControl := TCDWinControl(ATrackBar.Handle);
 
428
 
 
429
  if lCDWinControl.CDControl = nil then
 
430
    CreateCDControl(ATrackBar, lCDWinControl.CDControl);
 
431
 
 
432
  TCDTrackBar(lCDWinControl.CDControl).Position := ATrackBar.Position;
 
433
 
 
434
{  QtTrackBar.BeginUpdate;
 
435
  try
 
436
    QtTrackBar.setRange(ATrackBar.Min, ATrackBar.Max);
 
437
 
 
438
    if ATrackBar.TickStyle = tsNone then
 
439
      QtTrackBar.SetTickPosition(QSliderNoTicks)
 
440
    else
 
441
      QtTrackBar.SetTickPosition(TickMarkToQtSliderTickPositionMap[ATrackBar.TickMarks]);
 
442
 
 
443
    if QtTrackBar.getPageStep <> ATrackBar.PageSize then
 
444
      QtTrackBar.setPageStep(ATrackBar.PageSize);
 
445
    if QtTrackBar.getTickInterval <> ATrackBar.Frequency then
 
446
      QtTrackBar.setTickInterval(ATrackBar.Frequency);
 
447
    if QtTrackBar.getSliderPosition <> ATrackBar.Position then
 
448
      QtTrackBar.setSliderPosition(ATrackBar.Position);
 
449
 
 
450
    if (QtTrackBar.getOrientation <>
 
451
      TrackBarOrientationToQtOrientationMap[ATrackBar.Orientation])
 
452
      or TrackBarReversed(ATrackBar, QtTrackBar) then
 
453
    begin
 
454
      QtTrackBar.Hide;
 
455
      QtTrackBar.setOrientation(TrackBarOrientationToQtOrientationMap[ATrackBar.Orientation]);
 
456
      if ATrackBar.Orientation = trHorizontal then
 
457
        QtTrackBar.setInvertedAppereance(ATrackBar.Reversed)
 
458
      else
 
459
        {make it delphi and msdn compatibile when vertical then 0 = top}
 
460
        QtTrackBar.setInvertedAppereance(not ATrackBar.Reversed);
 
461
      QtTrackBar.setInvertedControls(False);
 
462
      QtTrackBar.Show;
 
463
    end;
 
464
  finally
 
465
    QtTrackBar.EndUpdate;
 
466
  end;}
 
467
end;
 
468
 
 
469
class function  TCDWSTrackBar.GetPosition(const ATrackBar: TCustomTrackBar): integer;
 
470
var
 
471
  lCDWinControl: TCDWinControl;
 
472
begin
 
473
  lCDWinControl := TCDWinControl(ATrackBar.Handle);
 
474
 
 
475
  if lCDWinControl.CDControl = nil then
 
476
    CreateCDControl(ATrackBar, lCDWinControl.CDControl);
 
477
 
 
478
  Result := TCDTrackBar(lCDWinControl.CDControl).Position;
 
479
end;
 
480
 
 
481
class procedure TCDWSTrackBar.SetPosition(const ATrackBar: TCustomTrackBar; const NewPosition: integer);
 
482
var
 
483
  lCDWinControl: TCDWinControl;
 
484
begin
 
485
  lCDWinControl := TCDWinControl(ATrackBar.Handle);
 
486
 
 
487
  if lCDWinControl.CDControl = nil then
 
488
    CreateCDControl(ATrackBar, lCDWinControl.CDControl);
 
489
 
 
490
  TCDTrackBar(lCDWinControl.CDControl).Position := NewPosition;
 
491
end;
 
492
 
 
493
class procedure TCDWSTrackBar.SetOrientation(const ATrackBar: TCustomTrackBar;
 
494
  const AOrientation: TTrackBarOrientation);
 
495
begin
 
496
{  if not WSCheckHandleAllocated(ATrackBar, 'SetOrientation') then
 
497
    Exit;
 
498
  QtTrackBar := TQtTrackBar(ATrackBar.Handle);
 
499
  QtTrackBar.BeginUpdate;
 
500
  try
 
501
    if (QtTrackBar.getOrientation <>
 
502
      TrackBarOrientationToQtOrientationMap[ATrackBar.Orientation])
 
503
      or TrackBarReversed(ATrackBar, QtTrackBar) then
 
504
    begin
 
505
      QtTrackBar.Hide;
 
506
      QtTrackBar.setOrientation(TrackBarOrientationToQtOrientationMap[ATrackBar.Orientation]);
 
507
      if ATrackBar.Orientation = trHorizontal then
 
508
        QtTrackBar.setInvertedAppereance(ATrackBar.Reversed)
 
509
      else
 
510
        {make it delphi and msdn compatibile when vertical then 0 = top}
 
511
        QtTrackBar.setInvertedAppereance(not ATrackBar.Reversed);
 
512
      QtTrackBar.setInvertedControls(False);
 
513
      QtTrackBar.Show;
 
514
    end;
 
515
  finally
 
516
    QtTrackBar.EndUpdate;
 
517
  end;}
 
518
end;
 
519
 
 
520
{ TCDWSProgressBar }
 
521
 
 
522
class procedure TCDWSProgressBar.CreateCDControl(const AWinControl: TWinControl; var ACDControlField: TCDControl);
 
523
begin
 
524
  ACDControlField := TCDIntfProgressBar.Create(AWinControl);
 
525
  TCDIntfProgressBar(ACDControlField).LCLControl := TCustomProgressBar(AWinControl);
 
526
  ACDControlField.Parent := AWinControl;
 
527
  ACDControlField.Align := alClient;
 
528
end;
 
529
 
 
530
class function TCDWSProgressBar.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
 
531
var
 
532
  lCDWinControl: TCDWinControl;
 
533
begin
 
534
  Result := TCDWSWinControl.CreateHandle(AWinControl, AParams);
 
535
  lCDWinControl := TCDWinControl(Result);
 
536
end;
 
537
 
 
538
class procedure TCDWSProgressBar.ShowHide(const AWinControl: TWinControl);
 
539
var
 
540
  lCDWinControl: TCDWinControl;
 
541
begin
 
542
  lCDWinControl := TCDWinControl(AWinControl.Handle);
 
543
 
 
544
  TCDWSWinControl.ShowHide(AWinControl);
 
545
 
 
546
  if lCDWinControl.CDControl = nil then
 
547
    CreateCDControl(AWinControl, lCDWinControl.CDControl);
 
548
end;
 
549
 
 
550
class procedure TCDWSProgressBar.ApplyChanges(const AProgressBar: TCustomProgressBar);
 
551
var
 
552
  lCDWinControl: TCDWinControl;
 
553
begin
 
554
  lCDWinControl := TCDWinControl(AProgressBar.Handle);
 
555
 
 
556
  if lCDWinControl.CDControl = nil then
 
557
    CreateCDControl(AProgressBar, lCDWinControl.CDControl);
 
558
 
 
559
  TCDProgressBar(lCDWinControl.CDControl).Position := AProgressBar.Position;
 
560
 
 
561
{  // AProgressBar.Smooth is not supported by qt
 
562
 
 
563
  case AProgressBar.Orientation of
 
564
    pbVertical:
 
565
      begin
 
566
        QtProgressBar.setOrientation(QtVertical);
 
567
        QtProgressBar.setInvertedAppearance(False);
 
568
      end;
 
569
    pbRightToLeft:
 
570
      begin
 
571
        QtProgressBar.setOrientation(QtHorizontal);
 
572
        QtProgressBar.setInvertedAppearance(True);
 
573
      end;
 
574
    pbTopDown:
 
575
      begin
 
576
        QtProgressBar.setOrientation(QtVertical);
 
577
        QtProgressBar.setInvertedAppearance(True);
 
578
      end;
 
579
  else { pbHorizontal is default }
 
580
    begin
 
581
      QtProgressBar.setOrientation(QtHorizontal);
 
582
      QtProgressBar.setInvertedAppearance(False);
 
583
    end;
 
584
  end;
 
585
 
 
586
  QtProgressBar.setTextVisible(AProgressBar.BarShowText);
 
587
 
 
588
  // The position, minumum and maximum values
 
589
  SetRangeStyle(QtProgressBar, AProgressBar.Style,
 
590
    AProgressBar.Min, AProgressBar.Max,
 
591
    csDesigning in AProgressBar.ComponentState);
 
592
  QtProgressBar.BeginUpdate;
 
593
  QtProgressBar.setValue(AProgressBar.Position);
 
594
  QtProgressBar.EndUpdate;}
 
595
end;
 
596
 
 
597
class procedure TCDWSProgressBar.SetPosition(const AProgressBar: TCustomProgressBar; const NewPosition: integer);
 
598
var
 
599
  lCDWinControl: TCDWinControl;
 
600
begin
 
601
  lCDWinControl := TCDWinControl(AProgressBar.Handle);
 
602
 
 
603
  if lCDWinControl.CDControl = nil then
 
604
    CreateCDControl(AProgressBar, lCDWinControl.CDControl);
 
605
 
 
606
  TCDProgressBar(lCDWinControl.CDControl).Position := NewPosition;
 
607
end;
 
608
 
 
609
(*class procedure TCDWSProgressBar.SetStyle(
 
610
  const AProgressBar: TCustomProgressBar; const NewStyle: TProgressBarStyle);
 
611
var
 
612
  QProgressBar: TQtProgressBar;
 
613
begin
 
614
  if not WSCheckHandleAllocated(AProgressBar, 'SetStyle') then
 
615
    Exit;
 
616
  QProgressBar := TQtProgressBar(AProgressBar.Handle);
 
617
  QProgressBar.reset;
 
618
  SetRangeStyle(QProgressBar, NewStyle, AProgressBar.Min, AProgressBar.Max,
 
619
    csDesigning in AProgressBar.ComponentState);
 
620
  if NewStyle = pbstNormal then
 
621
    QProgressBar.setValue(AProgressBar.Position);
 
622
end;
 
623
 
 
624
{ TCDWSStatusBar }
 
625
 
 
626
class procedure TCDWSStatusBar.ClearPanels(const Widget: TQtStatusBar);
 
627
var
 
628
  i: integer;
 
629
begin
 
630
  if length(Widget.Panels) > 0 then
 
631
  begin
 
632
    Widget.setUpdatesEnabled(False);
 
633
    for i := High(Widget.Panels) downto 0 do
 
634
    begin
 
635
      Widget.removeWidget(Widget.Panels[i].Widget);
 
636
      Widget.Panels[i].DetachEvents;
 
637
      QLabel_destroy(QLabelH(Widget.Panels[i].Widget));
 
638
      Widget.Panels[i].Widget := nil;
 
639
      Widget.Panels[i].Free;
 
640
    end;
 
641
    Widget.setUpdatesEnabled(True);
 
642
    SetLength(Widget.Panels, 0);
 
643
  end;
 
644
end;
 
645
 
 
646
class procedure TCDWSStatusBar.RecreatePanels(const AStatusBar: TStatusBar;
 
647
  const Widget: TQtStatusBar);
 
648
var
 
649
  Str: WideString;
 
650
  i: Integer;
 
651
begin
 
652
  Str := '';
 
653
  //clean up. http://bugs.freepascal.org/view.php?id=18683
 
654
  Widget.showMessage(@Str);
 
655
  ClearPanels(Widget);
 
656
  if AStatusBar.SimplePanel then
 
657
  begin
 
658
    Str := GetUtf8String(AStatusBar.SimpleText);
 
659
    Widget.showMessage(@Str);
 
660
  end else
 
661
  if AStatusBar.Panels.Count > 0 then
 
662
  begin
 
663
    Widget.setUpdatesEnabled(False);
 
664
    SetLength(Widget.Panels, AStatusBar.Panels.Count);
 
665
    for i := 0 to AStatusBar.Panels.Count - 1 do
 
666
    begin
 
667
      Str := GetUtf8String(AStatusBar.Panels[i].Text);
 
668
      Widget.Panels[i] := TQtStatusBarPanel.CreateFrom(AStatusBar,
 
669
        QLabel_create(@Str, Widget.Widget));
 
670
      Widget.Panels[i].HasPaint := AStatusBar.Panels[i].Style = psOwnerDraw;
 
671
      Widget.Panels[i].ID := AStatusBar.Panels[i].ID;
 
672
      QLabel_setText(QLabelH(Widget.Panels[i].Widget), @Str);
 
673
      QLabel_setAlignment(QLabelH(Widget.Panels[i].Widget),
 
674
        AlignmentToQtAlignmentMap[AStatusBar.Panels[i].Alignment]);
 
675
      QWidget_setMinimumWidth(Widget.Panels[i].Widget, AStatusBar.Panels[i].Width);
 
676
      Widget.Panels[i].AttachEvents;
 
677
      Widget.addWidget(Widget.Panels[i].Widget, ord(i = AStatusBar.Panels.Count - 1));
 
678
    end;
 
679
    Widget.setUpdatesEnabled(True);
 
680
  end;
 
681
end;
 
682
 
 
683
class function TCDWSStatusBar.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
 
684
var
 
685
  QtStatusBar: TQtStatusBar;
 
686
begin
 
687
  QtStatusBar := TQtStatusBar.Create(AWinControl, AParams);
 
688
  QtStatusBar.setSizeGripEnabled(TStatusBar(AWinControl).SizeGrip and
 
689
    TStatusBar(AWinControl).SizeGripEnabled);
 
690
 
 
691
  RecreatePanels(TStatusBar(AWinControl), QtStatusBar);
 
692
 
 
693
  QtStatusBar.AttachEvents;
 
694
 
 
695
  // Return handle
 
696
 
 
697
  Result := TLCLIntfHandle(QtStatusBar);
 
698
end;
 
699
 
 
700
class procedure TCDWSStatusBar.DestroyHandle(const AWinControl: TWinControl);
 
701
var
 
702
  QtStatusBar: TQtStatusBar;
 
703
begin
 
704
  QtStatusBar := TQtStatusBar(AWinControl.Handle);
 
705
  ClearPanels(QtStatusBar);
 
706
  QtStatusBar.Release;
 
707
end;
 
708
 
 
709
class procedure TCDWSStatusBar.PanelUpdate(const AStatusBar: TStatusBar; PanelIndex: integer);
 
710
var
 
711
  QtStatusBar: TQtStatusBar;
 
712
  Str: Widestring;
 
713
begin
 
714
  QtStatusBar := TQtStatusBar(AStatusBar.Handle);
 
715
  if AStatusBar.SimplePanel then
 
716
  begin
 
717
    ClearPanels(QtStatusBar);
 
718
    Str := GetUtf8String(AStatusBar.SimpleText);
 
719
    QtStatusBar.showMessage(@Str);
 
720
  end else
 
721
  if AStatusBar.Panels.Count > 0 then
 
722
  begin
 
723
    QStatusBar_clearMessage(QStatusBarH(QtStatusBar.Widget));
 
724
 
 
725
    if (PanelIndex >= Low(QtStatusBar.Panels)) and
 
726
      (PanelIndex <= High(QtStatusBar.Panels)) then
 
727
    begin
 
728
      Str := GetUtf8String(AStatusBar.Panels[PanelIndex].Text);
 
729
      QLabel_setText(QLabelH(QtStatusBar.Panels[PanelIndex].Widget), @Str);
 
730
      QLabel_setAlignment(QLabelH(QtStatusBar.Panels[PanelIndex].Widget),
 
731
        AlignmentToQtAlignmentMap[AStatusBar.Panels[PanelIndex].Alignment]);
 
732
      QWidget_setMinimumWidth(QtStatusBar.Panels[PanelIndex].Widget,
 
733
        AStatusBar.Panels[PanelIndex].Width);
 
734
    end;
 
735
  end;
 
736
end;
 
737
 
 
738
class procedure TCDWSStatusBar.SetPanelText(const AStatusBar: TStatusBar; PanelIndex: integer);
 
739
var
 
740
  QtStatusBar: TQtStatusBar;
 
741
  Str: Widestring;
 
742
begin
 
743
  QtStatusBar := TQtStatusBar(AStatusBar.Handle);
 
744
  if AStatusBar.SimplePanel then
 
745
  begin
 
746
    Str := GetUtf8String(AStatusBar.SimpleText);
 
747
    QtStatusBar.showMessage(@Str);
 
748
  end else
 
749
  begin
 
750
    if (PanelIndex >= Low(QtStatusBar.Panels)) and
 
751
      (PanelIndex <= High(QtStatusBar.Panels)) then
 
752
    begin
 
753
      Str := GetUtf8String(AStatusBar.Panels[PanelIndex].Text);
 
754
      QLabel_setText(QLabelH(QtStatusBar.Panels[PanelIndex].Widget), @Str);
 
755
    end;
 
756
  end;
 
757
end;
 
758
 
 
759
class procedure TCDWSStatusBar.SetSizeGrip(const AStatusBar: TStatusBar;
 
760
  SizeGrip: Boolean);
 
761
var
 
762
  QtStatusBar: TQtStatusBar;
 
763
begin
 
764
  if not WSCheckHandleAllocated(AStatusBar, 'SetSizeGrip') then
 
765
    Exit;
 
766
  QtStatusBar := TQtStatusBar(AStatusBar.Handle);
 
767
  QtStatusBar.setSizeGripEnabled(SizeGrip and AStatusBar.SizeGripEnabled);
 
768
end;
 
769
 
 
770
class procedure TCDWSStatusBar.Update(const AStatusBar: TStatusBar);
 
771
var
 
772
  QtStatusBar: TQtStatusBar;
 
773
begin
 
774
  QtStatusBar := TQtStatusBar(AStatusBar.Handle);
 
775
  RecreatePanels(AStatusBar, QtStatusBar);
 
776
end;
 
777
 
 
778
{ TCDWSCustomListView }
 
779
 
 
780
{------------------------------------------------------------------------------
 
781
  Method: TCDWSCustomListView.CreateHandle
 
782
  Params:  None
 
783
  Returns: Nothing
 
784
 ------------------------------------------------------------------------------}
 
785
 
 
786
class function TCDWSCustomListView.IsIconView(const AList: TCustomListView): boolean;
 
787
begin
 
788
  Result := TListView(AList).ViewStyle <> vsReport;
 
789
end;
 
790
 
 
791
class function TCDWSCustomListView.CreateHandle(const AWinControl: TWinControl;
 
792
  const AParams: TCreateParams): TLCLIntfHandle;
 
793
var
 
794
  QtTreeWidget: TQtTreeWidget;
 
795
  QtListWidget: TQtListWidget;
 
796
begin
 
797
  if IsIconView(TCustomListView(AWinControl)) then
 
798
  begin
 
799
    QtListWidget := TQtListWidget.Create(AWinControl, AParams);
 
800
    QtListWidget.ViewStyle := Ord(TListView(AWinControl).ViewStyle);
 
801
    if TListView(AWinControl).ViewStyle in [vsIcon, vsSmallIcon] then
 
802
    begin
 
803
      // emabarcadero docs says
 
804
      // vsIcon, vsSmallIcon
 
805
      // Each item appears as a full-sized icon with a label below it.
 
806
      // The user can drag the items to any location in the list view window.
 
807
      QtListWidget.setViewMode(QListViewIconMode);
 
808
      QtListWidget.setResizeMode(QListViewAdjust);
 
809
      QtListWidget.setMovement(QListViewFree);
 
810
 
 
811
      with TCustomListView(AWinControl) do
 
812
      begin
 
813
        QtListWidget.setWrapping(IconOptions.AutoArrange);
 
814
        QtListWidget.setViewFlow(IconArngToQListFlow[IconOptions.Arrangement]);
 
815
        QtListWidget.setWordWrap(IconOptions.WrapText);
 
816
      end;
 
817
 
 
818
    end else
 
819
      QtListWidget.setViewMode(QListViewListMode);
 
820
 
 
821
    QtListWidget.Checkable := TCustomListView(AWinControl).Checkboxes;
 
822
    QtListWidget.AttachEvents;
 
823
    Result := TLCLIntfHandle(QtListWidget);
 
824
  end else
 
825
  begin
 
826
    QtTreeWidget := TQtTreeWidget.Create(AWinControl, AParams);
 
827
    QtTreeWidget.ViewStyle := Ord(TListView(AWinControl).ViewStyle);
 
828
    QtTreeWidget.setStretchLastSection(False);
 
829
    QtTreeWidget.setRootIsDecorated(False);
 
830
    QtTreeWidget.AttachEvents;
 
831
    Result := TLCLIntfHandle(QtTreeWidget);
 
832
  end;
 
833
end;
 
834
 
 
835
{------------------------------------------------------------------------------
 
836
  Method: TCDWSCustomListView.ColumnDelete
 
837
  Params:  None
 
838
  Returns: Nothing
 
839
 ------------------------------------------------------------------------------}
 
840
class procedure TCDWSCustomListView.ColumnDelete(const ALV: TCustomListView;
 
841
  const AIndex: Integer);
 
842
begin
 
843
  if not WSCheckHandleAllocated(ALV, 'ColumnDelete') then
 
844
    Exit;
 
845
 
 
846
  // TODO: columns in vsIcon mode
 
847
  if IsIconView(ALV) then
 
848
    exit;
 
849
 
 
850
  // we must recreate handle since there's no column removal support
 
851
  // in our bindings (protected methods in qt).
 
852
  RecreateWnd(ALV);
 
853
end;
 
854
 
 
855
{------------------------------------------------------------------------------
 
856
  Method: TCDWSCustomListView.ColumnInsert
 
857
  Params:  None
 
858
  Returns: Nothing
 
859
 ------------------------------------------------------------------------------}
 
860
class procedure TCDWSCustomListView.ColumnInsert(const ALV: TCustomListView;
 
861
  const AIndex: Integer; const AColumn: TListColumn);
 
862
var
 
863
  QtTreeWidget: TQtTreeWidget;
 
864
  TWI: QTreeWidgetItemH;
 
865
  TWIChild: QTreeWidgetItemH;
 
866
  Str: WideString;
 
867
begin
 
868
  if not WSCheckHandleAllocated(ALV, 'ColumnInsert') then
 
869
    Exit;
 
870
 
 
871
  // TODO: columns in vsIcon mode
 
872
  if IsIconView(ALV) then
 
873
    exit;
 
874
 
 
875
  QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
876
 
 
877
  if QtTreeWidget.ColCount <> TListView(ALV).Columns.Count then
 
878
        QtTreeWidget.ColCount := TListView(ALV).Columns.Count;
 
879
 
 
880
  if (QtTreeWidget.ColCount <= 1) and TListView(ALV).ShowColumnHeaders then
 
881
    QtTreeWidget.setHeaderVisible(True);
 
882
 
 
883
  TWI := QtTreeWidget.headerItem;
 
884
 
 
885
  if QTreeWidgetItem_childCount(TWI) < (AIndex + 1) then
 
886
  begin
 
887
    TWIChild := QTreeWidgetItem_create(0);
 
888
    QTreeWidgetItem_setFlags(TWIChild, QtItemIsEnabled);
 
889
    QTreeWidgetItem_addChild(TWI, TWIChild);
 
890
    Str := GetUtf8String(ALV.Column[AIndex].Caption);
 
891
    QTreeWidgetItem_setText(TWI, AIndex, @Str);
 
892
  end;
 
893
 
 
894
  if (csDesigning in ALV.ComponentState) then
 
895
    exit;
 
896
 
 
897
        QtTreeWidget.Header.Clickable := TListView(ALV).ColumnClick;
 
898
end;
 
899
 
 
900
{------------------------------------------------------------------------------
 
901
  Method: TCDWSCustomListView.ColumnGetWidth
 
902
  Params:  None
 
903
  Returns: Integer
 
904
 ------------------------------------------------------------------------------}
 
905
class function  TCDWSCustomListView.ColumnGetWidth(const ALV: TCustomListView;
 
906
  const AIndex: Integer; const AColumn: TListColumn): Integer;
 
907
var
 
908
  QtTreeWidget: TQtTreeWidget;
 
909
begin
 
910
  if not WSCheckHandleAllocated(ALV, 'ColumnGetWidth') then
 
911
    Exit;
 
912
 
 
913
  // TODO: columns in vsIcon mode
 
914
  if IsIconView(ALV) then
 
915
    exit;
 
916
 
 
917
  QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
918
  Result := QtTreeWidget.ColWidth[AIndex];
 
919
end;
 
920
 
 
921
{------------------------------------------------------------------------------
 
922
  Method: TCDWSCustomListView.ColumnMove
 
923
  Params:  None
 
924
  Returns: Nothing
 
925
 ------------------------------------------------------------------------------}
 
926
class procedure TCDWSCustomListView.ColumnMove(const ALV: TCustomListView;
 
927
  const AOldIndex, ANewIndex: Integer; const AColumn: TListColumn);
 
928
var
 
929
  QtTreeWidget: TQtTreeWidget;
 
930
begin
 
931
  if not WSCheckHandleAllocated(ALV, 'ColumnMove') then
 
932
    Exit;
 
933
 
 
934
  if (csDesigning in ALV.ComponentState) then
 
935
    exit;
 
936
 
 
937
  // TODO: columns in vsIcon mode
 
938
  if IsIconView(ALV) then
 
939
    exit;
 
940
 
 
941
  QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
942
  QtTreeWidget.Header.moveSection(AOldIndex, ANewIndex);
 
943
end;
 
944
 
 
945
{------------------------------------------------------------------------------
 
946
  Method: TCDWSCustomListView.ColumnSetAlignment
 
947
  Params:  None
 
948
  Returns: Nothing
 
949
 ------------------------------------------------------------------------------}
 
950
class procedure TCDWSCustomListView.ColumnSetAlignment(const ALV: TCustomListView;
 
951
  const AIndex: Integer; const AColumn: TListColumn; const AAlignment: TAlignment);
 
952
var
 
953
  QtTreeWidget: TQtTreeWidget;
 
954
  TWI: QTreeWidgetItemH;
 
955
  i: Integer;
 
956
begin
 
957
  if not WSCheckHandleAllocated(ALV, 'ColumnSetAlignment') then
 
958
    Exit;
 
959
 
 
960
  // TODO: columns in vsIcon mode
 
961
  if IsIconView(ALV) then
 
962
    exit;
 
963
 
 
964
  QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
965
  TWI := QtTreeWidget.headerItem;
 
966
  QTreeWidgetItem_setTextAlignment(TWI, AIndex,
 
967
    AlignmentToQtAlignmentMap[AAlignment]);
 
968
 
 
969
 
 
970
  if not (csLoading in ALV.ComponentState) then
 
971
    for i := 0 to QtTreeWidget.ItemCount - 1 do
 
972
    begin
 
973
      TWI := QtTreeWidget.topLevelItem(i);
 
974
      if TWI <> nil then
 
975
        QTreeWidgetItem_setTextAlignment(TWI, AIndex,
 
976
          AlignmentToQtAlignmentMap[AAlignment]);
 
977
    end;
 
978
end;
 
979
 
 
980
{------------------------------------------------------------------------------
 
981
  Method: TCDWSCustomListView.ColumnSetAutoSize
 
982
  Params:  None
 
983
  Returns: Nothing
 
984
 ------------------------------------------------------------------------------}
 
985
class procedure TCDWSCustomListView.ColumnSetAutoSize(const ALV: TCustomListView;
 
986
  const AIndex: Integer; const AColumn: TListColumn; const AAutoSize: Boolean);
 
987
var
 
988
  QtTreeWidget: TQtTreeWidget;
 
989
begin
 
990
  if not WSCheckHandleAllocated(ALV, 'ColumnSetAutoSize') then
 
991
    Exit;
 
992
 
 
993
  if (csDesigning in ALV.ComponentState) then
 
994
    exit;
 
995
 
 
996
  // TODO: columns in vsIcon mode
 
997
  if IsIconView(ALV) then
 
998
    exit;
 
999
 
 
1000
  QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1001
  if AAutoSize then
 
1002
    QtTreeWidget.Header.setResizeMode(AIndex, QHeaderViewResizeToContents)
 
1003
  else
 
1004
    QtTreeWidget.Header.setResizeMode(AIndex, QHeaderViewInteractive);
 
1005
end;
 
1006
 
 
1007
{------------------------------------------------------------------------------
 
1008
  Method: TCDWSCustomListView.ColumnSetCaption
 
1009
  Params:  None
 
1010
  Returns: Nothing
 
1011
 ------------------------------------------------------------------------------}
 
1012
class procedure TCDWSCustomListView.ColumnSetCaption(const ALV: TCustomListView;
 
1013
  const AIndex: Integer; const AColumn: TListColumn; const ACaption: String);
 
1014
var
 
1015
  Str: WideString;
 
1016
  QtTreeWidget: TQtTreeWidget;
 
1017
  TWI: QTreeWidgetItemH;
 
1018
begin
 
1019
  if not WSCheckHandleAllocated(ALV, 'ColumnSetCaption') then
 
1020
    Exit;
 
1021
 
 
1022
  // TODO: columns in vsIcon mode
 
1023
  if IsIconView(ALV) then
 
1024
    exit;
 
1025
 
 
1026
  QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1027
  TWI := QtTreeWidget.headerItem;
 
1028
  if TWI <> NiL then
 
1029
  begin
 
1030
    Str := GetUtf8String(ACaption);
 
1031
    QTreeWidgetItem_setText(TWI, AIndex, @Str);
 
1032
  end;
 
1033
end;
 
1034
 
 
1035
{------------------------------------------------------------------------------
 
1036
  Method: TCDWSCustomListView.ColumnSetImage
 
1037
  Params:  None
 
1038
  Returns: Nothing
 
1039
 ------------------------------------------------------------------------------}
 
1040
class procedure TCDWSCustomListView.ColumnSetImage(const ALV: TCustomListView;
 
1041
  const AIndex: Integer; const AColumn: TListColumn; const AImageIndex: Integer);
 
1042
var
 
1043
  QtTreeWidget: TQtTreeWidget;
 
1044
  TWI: QTreeWidgetItemH;
 
1045
  Bmp: TBitmap;
 
1046
  ImgList: TImageList;
 
1047
begin
 
1048
  if not WSCheckHandleAllocated(ALV, 'ColumnSetImage') then
 
1049
    Exit;
 
1050
 
 
1051
  // TODO: columns in vsIcon mode
 
1052
  if IsIconView(ALV) then
 
1053
    exit;
 
1054
 
 
1055
  QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1056
  TWI := QtTreeWidget.headerItem;
 
1057
  if TWI <> NiL then
 
1058
  begin
 
1059
    ImgList := TImageList.Create(nil);
 
1060
    try
 
1061
      if (TListView(ALV).ViewStyle = vsIcon) and
 
1062
        Assigned(TListView(ALV).LargeImages) then
 
1063
        ImgList.Assign(TListView(ALV).LargeImages);
 
1064
 
 
1065
      if (TListView(ALV).ViewStyle in [vsSmallIcon, vsReport, vsList]) and
 
1066
        Assigned(TListView(ALV).SmallImages) then
 
1067
        ImgList.Assign(TListView(ALV).SmallImages);
 
1068
 
 
1069
      if (ImgList.Count > 0) and
 
1070
        ((AImageIndex >= 0) and (AImageIndex < ImgList.Count)) then
 
1071
      begin
 
1072
        Bmp := TBitmap.Create;
 
1073
        try
 
1074
          ImgList.GetBitmap(AImageIndex, Bmp);
 
1075
          QTreeWidgetItem_setIcon(TWI, AIndex, TQtImage(Bmp.Handle).AsIcon);
 
1076
        finally
 
1077
          Bmp.Free;
 
1078
        end;
 
1079
      end;
 
1080
    finally
 
1081
      ImgList.Free;
 
1082
    end;
 
1083
  end;
 
1084
end;
 
1085
 
 
1086
{------------------------------------------------------------------------------
 
1087
  Method: TCDWSCustomListView.ColumnSetMinWidth
 
1088
  Params:  None
 
1089
  Returns: Nothing
 
1090
 ------------------------------------------------------------------------------}
 
1091
class procedure TCDWSCustomListView.ColumnSetMinWidth(const ALV: TCustomListView;
 
1092
  const AIndex: Integer; const AColumn: TListColumn; const AMinWidth: integer);
 
1093
var
 
1094
  QtTreeWidget: TQtTreeWidget;
 
1095
begin
 
1096
  if not WSCheckHandleAllocated(ALV, 'ColumnSetMinWidth') then
 
1097
    Exit;
 
1098
 
 
1099
  // TODO: columns in vsIcon mode
 
1100
  if IsIconView(ALV) then
 
1101
    exit;
 
1102
 
 
1103
  QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1104
  QtTreeWidget.MinColSize[AIndex] := AMinWidth;
 
1105
end;
 
1106
 
 
1107
{------------------------------------------------------------------------------
 
1108
  Method: TCDWSCustomListView.ColumnSetWidth
 
1109
  Params:  None
 
1110
  Returns: Nothing
 
1111
 ------------------------------------------------------------------------------}
 
1112
class procedure TCDWSCustomListView.ColumnSetWidth(const ALV: TCustomListView;
 
1113
  const AIndex: Integer; const AColumn: TListColumn; const AWidth: Integer);
 
1114
var
 
1115
  QtTreeWidget: TQtTreeWidget;
 
1116
begin
 
1117
  if not WSCheckHandleAllocated(ALV, 'ColumnSetWidth') then
 
1118
    Exit;
 
1119
 
 
1120
  // TODO: columns in vsIcon mode
 
1121
  if IsIconView(ALV) then
 
1122
    exit;
 
1123
 
 
1124
  QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1125
  QtTreeWidget.ColWidth[AIndex] := AWidth;
 
1126
end;
 
1127
 
 
1128
{------------------------------------------------------------------------------
 
1129
  Method: TCDWSCustomListView.ColumnSetVisible
 
1130
  Params:  None
 
1131
  Returns: Nothing
 
1132
 ------------------------------------------------------------------------------}
 
1133
class procedure TCDWSCustomListView.ColumnSetVisible(const ALV: TCustomListView;
 
1134
  const AIndex: Integer; const AColumn: TListColumn; const AVisible: Boolean);
 
1135
var
 
1136
  QtTreeWidget: TQtTreeWidget;
 
1137
begin
 
1138
  if not WSCheckHandleAllocated(ALV, 'ColumnSetVisible') then
 
1139
    Exit;
 
1140
 
 
1141
  // TODO: columns in vsIcon mode
 
1142
  if IsIconView(ALV) then
 
1143
    exit;
 
1144
 
 
1145
  QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1146
  QtTreeWidget.ColVisible[AIndex] := AVisible;
 
1147
end;
 
1148
 
 
1149
{------------------------------------------------------------------------------
 
1150
  Method: TCDWSCustomListView.ItemDelete
 
1151
  Params:  None
 
1152
  Returns: Nothing
 
1153
 ------------------------------------------------------------------------------}
 
1154
class procedure TCDWSCustomListView.ItemDelete(const ALV: TCustomListView;
 
1155
  const AIndex: Integer);
 
1156
var
 
1157
  QtTreeWidget: TQtTreeWidget;
 
1158
begin
 
1159
  if not WSCheckHandleAllocated(ALV, 'ItemDelete') then
 
1160
    Exit;
 
1161
  if IsIconView(ALV) then
 
1162
    TQtListWidget(ALV.Handle).removeItem(AIndex)
 
1163
  else
 
1164
  begin
 
1165
    TQtListWidget(ALV.Handle).BeginUpdate;
 
1166
    try
 
1167
      QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1168
      QtTreeWidget.DeleteItem(AIndex);
 
1169
    finally
 
1170
      TQtListWidget(ALV.Handle).EndUpdate;
 
1171
    end;
 
1172
  end;
 
1173
end;
 
1174
 
 
1175
class procedure TCDWSCustomListView.ItemExchange(const ALV: TCustomListView;
 
1176
  AItem: TListItem; const AIndex1, AIndex2: Integer);
 
1177
var
 
1178
  QtTreeWidget: TQtTreeWidget;
 
1179
  QtListWidget: TQtListWidget;
 
1180
begin
 
1181
  if not WSCheckHandleAllocated(ALV, 'ItemExchange') then
 
1182
    Exit;
 
1183
  if IsIconView(ALV) then
 
1184
  begin
 
1185
    QtListWidget := TQtListWidget(ALV.Handle);
 
1186
    QtListWidget.BeginUpdate;
 
1187
    QtListWidget.ExchangeItems(AIndex1, AIndex2);
 
1188
    QtListWidget.EndUpdate;
 
1189
  end else
 
1190
  begin
 
1191
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1192
    QtTreeWidget.BeginUpdate;
 
1193
    QtTreeWidget.ExchangeItems(AIndex1, AIndex2);
 
1194
    QtTreeWidget.EndUpdate;
 
1195
  end;
 
1196
end;
 
1197
 
 
1198
class procedure TCDWSCustomListView.ItemMove(const ALV: TCustomListView;
 
1199
  AItem: TListItem; const AFromIndex, AToIndex: Integer);
 
1200
var
 
1201
  QtTreeWidget: TQtTreeWidget;
 
1202
  QtListWidget: TQtListWidget;
 
1203
begin
 
1204
  if not WSCheckHandleAllocated(ALV, 'ItemMove') then
 
1205
    Exit;
 
1206
  if IsIconView(ALV) then
 
1207
  begin
 
1208
    QtListWidget := TQtListWidget(ALV.Handle);
 
1209
    QtListWidget.BeginUpdate;
 
1210
    QtListWidget.MoveItem(AFromIndex, AToIndex);
 
1211
    QtListWidget.EndUpdate;
 
1212
  end else
 
1213
  begin
 
1214
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1215
    QtTreeWidget.BeginUpdate;
 
1216
    QtTreeWidget.MoveItem(AFromIndex, AToIndex);
 
1217
    QtTreeWidget.EndUpdate;
 
1218
  end;
 
1219
end;
 
1220
 
 
1221
{------------------------------------------------------------------------------
 
1222
  Method: TCDWSCustomListView.ItemGetChecked
 
1223
  Params:  None
 
1224
  Returns: Nothing
 
1225
 ------------------------------------------------------------------------------}
 
1226
class function  TCDWSCustomListView.ItemGetChecked(const ALV: TCustomListView;
 
1227
  const AIndex: Integer; const AItem: TListItem): Boolean;
 
1228
var
 
1229
  QtTreeWidget: TQtTreeWidget;
 
1230
  TWI: QTreeWidgetItemH;
 
1231
  LWI: QListWidgetItemH;
 
1232
  AState: QtCheckState;
 
1233
begin
 
1234
  if not WSCheckHandleAllocated(ALV, 'ItemGetChecked') then
 
1235
    Exit;
 
1236
 
 
1237
  Result := ALV.CheckBoxes;
 
1238
  if not Result then
 
1239
    exit;
 
1240
 
 
1241
  AState := QtUnChecked;
 
1242
 
 
1243
  if IsIconView(ALV) then
 
1244
  begin
 
1245
    LWI := TQtListWidget(ALV.Handle).getItem(AIndex);
 
1246
    if LWI <> nil then
 
1247
      AState := QListWidgetItem_checkState(LWI);
 
1248
  end else
 
1249
  begin
 
1250
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1251
    TWI := QtTreeWidget.topLevelItem(AIndex);
 
1252
    if TWI <> nil then
 
1253
      AState := QTreeWidgetItem_checkState(TWI, 0);
 
1254
  end;
 
1255
  Result := AState = QtChecked;
 
1256
end;
 
1257
 
 
1258
{------------------------------------------------------------------------------
 
1259
  Method: TCDWSCustomListView.ItemGetPosition
 
1260
  Params:  None
 
1261
  Returns: TPoint
 
1262
 ------------------------------------------------------------------------------}
 
1263
class function  TCDWSCustomListView.ItemGetPosition(const ALV: TCustomListView;
 
1264
  const AIndex: Integer): TPoint;
 
1265
var
 
1266
  QtListWidget: TQtListWidget;
 
1267
  QtTreeWidget: TQtTreeWidget;
 
1268
  TWI: QTreeWidgetItemH;
 
1269
  R: TRect;
 
1270
begin
 
1271
  if not WSCheckHandleAllocated(ALV, 'ItemGetPosition') then
 
1272
    Exit;
 
1273
 
 
1274
  R := Rect(0, 0, 0, 0);
 
1275
  if IsIconView(ALV) then
 
1276
  begin
 
1277
    QtListWidget := TQtListWidget(ALV.Handle);
 
1278
    R := QtListWidget.getVisualItemRect(QtListWidget.getItem(AIndex));
 
1279
  end else
 
1280
  begin
 
1281
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1282
    TWI := QtTreeWidget.topLevelItem(AIndex);
 
1283
    R := QtTreeWidget.visualItemRect(TWI);
 
1284
  end;
 
1285
  Result.X := R.Left;
 
1286
  Result.Y := R.Top;
 
1287
end;
 
1288
 
 
1289
{------------------------------------------------------------------------------
 
1290
  Method: TCDWSCustomListView.ItemGetState
 
1291
  Params:  None
 
1292
  Returns: TPoint
 
1293
 ------------------------------------------------------------------------------}
 
1294
class function  TCDWSCustomListView.ItemGetState(const ALV: TCustomListView;
 
1295
  const AIndex: Integer; const AItem: TListItem;
 
1296
  const AState: TListItemState; out AIsSet: Boolean): Boolean;
 
1297
var
 
1298
  QtListWidget: TQtListWidget;
 
1299
  LWI: QListWidgetItemH;
 
1300
  QtTreeWidget: TQtTreeWidget;
 
1301
  TWI: QTreeWidgetItemH;
 
1302
  i: Integer;
 
1303
  Arr: TPtrIntArray;
 
1304
begin
 
1305
  if not WSCheckHandleAllocated(ALV, 'ItemGetState') then
 
1306
    Exit;
 
1307
 
 
1308
  AIsSet := False;
 
1309
  if IsIconView(ALV) then
 
1310
  begin
 
1311
    QtListWidget := TQtListWidget(ALV.Handle);
 
1312
    LWI := QtListWidget.getItem(AIndex);
 
1313
    if LWI <> nil then
 
1314
      case AState of
 
1315
        lisFocused: AIsSet := LWI = QtListWidget.currentItem;
 
1316
        lisSelected: AIsSet := QtListWidget.getItemSelected(LWI);
 
1317
      end;
 
1318
  end else
 
1319
  begin
 
1320
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1321
    TWI := QtTreeWidget.topLevelItem(AIndex);
 
1322
    if TWI <> nil then
 
1323
    begin
 
1324
      case AState of
 
1325
        lisFocused: AIsSet := TWI = QtTreeWidget.currentItem;
 
1326
        lisSelected:
 
1327
        begin
 
1328
          Arr := QtTreeWidget.selectedItems;
 
1329
          for i := 0 to High(Arr) do
 
1330
          begin
 
1331
            TWI := QTreeWidgetItemH(Arr[i]);
 
1332
            if AIndex = QtTreeWidget.getRow(TWI) then
 
1333
            begin
 
1334
              AIsSet := True;
 
1335
              break;
 
1336
            end;
 
1337
          end;
 
1338
        end;
 
1339
      end;
 
1340
    end;
 
1341
  end;
 
1342
  Result := True;
 
1343
 
 
1344
end;
 
1345
 
 
1346
class procedure TCDWSCustomListView.ItemSetImage(const ALV: TCustomListView;
 
1347
  const AIndex: Integer; const AItem: TListItem; const ASubIndex,
 
1348
  AImageIndex: Integer);
 
1349
var
 
1350
  QtListWidget: TQtListWidget;
 
1351
  LWI: QListWidgetItemH;
 
1352
  QtTreeWidget: TQtTreeWidget;
 
1353
  TWI: QTreeWidgetItemH;
 
1354
  Bmp: TBitmap;
 
1355
  ImgList: TImageList;
 
1356
begin
 
1357
  if not WSCheckHandleAllocated(ALV, 'ItemSetImage') then
 
1358
    Exit;
 
1359
 
 
1360
  if not Assigned(TListView(ALV).LargeImages) and not
 
1361
    Assigned(TListView(ALV).SmallImages) then
 
1362
      exit;
 
1363
  TWI := nil;
 
1364
  LWI := nil;
 
1365
  if IsIconView(ALV) then
 
1366
  begin
 
1367
    QtListWidget := TQtListWidget(ALV.Handle);
 
1368
    LWI := QtListWidget.getItem(AIndex);
 
1369
  end else
 
1370
  begin
 
1371
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1372
    TWI := QtTreeWidget.topLevelItem(AIndex);
 
1373
  end;
 
1374
  if (TWI <> nil) or (LWI <> nil) then
 
1375
  begin
 
1376
    ImgList := TImageList.Create(nil);
 
1377
    try
 
1378
      if (TListView(ALV).ViewStyle = vsIcon) and
 
1379
        Assigned(TListView(ALV).LargeImages) then
 
1380
        ImgList.Assign(TListView(ALV).LargeImages);
 
1381
 
 
1382
      if (TListView(ALV).ViewStyle in [vsSmallIcon, vsReport, vsList]) and
 
1383
        Assigned(TListView(ALV).SmallImages) then
 
1384
        ImgList.Assign(TListView(ALV).SmallImages);
 
1385
 
 
1386
      if (ImgList.Count > 0) and
 
1387
        ((AImageIndex >= 0) and (AImageIndex < ImgList.Count)) then
 
1388
      begin
 
1389
        Bmp := TBitmap.Create;
 
1390
        try
 
1391
          ImgList.GetBitmap(AImageIndex, Bmp);
 
1392
          if LWI <> nil then
 
1393
            QListWidgetItem_setIcon(LWI, TQtImage(Bmp.Handle).AsIcon)
 
1394
          else
 
1395
            QTreeWidgetItem_setIcon(TWI, ASubIndex, TQtImage(Bmp.Handle).AsIcon);
 
1396
        finally
 
1397
          Bmp.Free;
 
1398
        end;
 
1399
      end;
 
1400
    finally
 
1401
      ImgList.Free;
 
1402
    end;
 
1403
  end;
 
1404
end;
 
1405
 
 
1406
{------------------------------------------------------------------------------
 
1407
  Method: TCDWSCustomListView.ItemSetChecked
 
1408
  Params:  None
 
1409
  Returns: Nothing
 
1410
 ------------------------------------------------------------------------------}
 
1411
class procedure TCDWSCustomListView.ItemSetChecked(const ALV: TCustomListView;
 
1412
  const AIndex: Integer; const AItem: TListItem; const AChecked: Boolean);
 
1413
var
 
1414
  QtListWidget: TQtListWidget;
 
1415
  QtTreeWidget: TQtTreeWidget;
 
1416
begin
 
1417
  if not WSCheckHandleAllocated(ALV, 'ItemSetChecked') then
 
1418
    Exit;
 
1419
 
 
1420
  if not ALV.CheckBoxes then
 
1421
    exit;
 
1422
 
 
1423
  if IsIconView(ALV) then
 
1424
  begin
 
1425
    QtListWidget := TQtListWidget(ALV.Handle);
 
1426
    QtListWidget.ItemChecked[AIndex] := AChecked;
 
1427
  end else
 
1428
  begin
 
1429
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1430
    QtTreeWidget.ItemChecked[AIndex] := AChecked;
 
1431
  end;
 
1432
end;
 
1433
 
 
1434
{------------------------------------------------------------------------------
 
1435
  Method: TCDWSCustomListView.ItemSetState
 
1436
  Params:  None
 
1437
  Returns: Nothing
 
1438
 ------------------------------------------------------------------------------}
 
1439
class procedure TCDWSCustomListView.ItemSetState(const ALV: TCustomListView;
 
1440
  const AIndex: Integer; const AItem: TListItem;
 
1441
  const AState: TListItemState; const AIsSet: Boolean);
 
1442
var
 
1443
  QtListWidget: TQtListWidget;
 
1444
  LWI: QListWidgetItemH;
 
1445
  QtTreeWidget: TQtTreeWidget;
 
1446
  TWI: QTreeWidgetItemH;
 
1447
begin
 
1448
  if not WSCheckHandleAllocated(ALV, 'ItemSetState') then
 
1449
    Exit;
 
1450
  if IsIconView(ALV) then
 
1451
  begin
 
1452
    QtListWidget := TQtListWidget(ALV.Handle);
 
1453
    LWI := QtListWidget.getItem(AIndex);
 
1454
    QtListWidget.BeginUpdate;
 
1455
    case AState of
 
1456
      lisFocused: QtListWidget.setCurrentItem(LWI);
 
1457
      lisSelected:
 
1458
      begin
 
1459
        if AIsSet and not ALV.MultiSelect then
 
1460
          QtListWidget.setCurrentItem(LWI);
 
1461
        QtListWidget.setItemSelected(LWI, AIsSet);
 
1462
      end;
 
1463
    end;
 
1464
    QtListWidget.EndUpdate;
 
1465
  end else
 
1466
  begin
 
1467
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1468
    TWI := QtTreeWidget.topLevelItem(AIndex);
 
1469
    QtTreeWidget.BeginUpdate;
 
1470
    case AState of
 
1471
      lisFocused: QtTreeWidget.setCurrentItem(TWI);
 
1472
      lisSelected:
 
1473
      begin
 
1474
        if ALV.RowSelect and AIsSet and not ALV.MultiSelect then
 
1475
          QtTreeWidget.setCurrentItem(TWI);
 
1476
        QtTreeWidget.setItemSelected(TWI, AIsSet);
 
1477
      end;
 
1478
    end;
 
1479
    QtTreeWidget.EndUpdate;
 
1480
  end;
 
1481
end;
 
1482
 
 
1483
{------------------------------------------------------------------------------
 
1484
  Method: TCDWSCustomListView.ItemInsert
 
1485
  Params:  None
 
1486
  Returns: Nothing
 
1487
 ------------------------------------------------------------------------------}
 
1488
class procedure TCDWSCustomListView.ItemInsert(const ALV: TCustomListView;
 
1489
  const AIndex: Integer; const AItem: TListItem);
 
1490
var
 
1491
  QtListWidget: TQtListWidget;
 
1492
  QtTreeWidget: TQtTreeWidget;
 
1493
  TWI: QTreeWidgetItemH;
 
1494
  Str: WideString;
 
1495
  i: Integer;
 
1496
  AAlignment: QtAlignment;
 
1497
begin
 
1498
  if not WSCheckHandleAllocated(ALV, 'ItemInsert') then
 
1499
    Exit;
 
1500
 
 
1501
  if IsIconView(ALV) then
 
1502
  begin
 
1503
    QtListWidget := TQtListWidget(ALV.Handle);
 
1504
    QtListWidget.Checkable := ALV.Checkboxes;
 
1505
    QtListWidget.insertItem(AIndex, AItem.Caption);
 
1506
  end else
 
1507
  begin
 
1508
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1509
    TWI := QTreeWidgetItem_create(Integer(0));
 
1510
    if AItem.Caption <> '' then
 
1511
      Str := GetUtf8String(AItem.Caption)
 
1512
    else
 
1513
      Str := '';
 
1514
 
 
1515
    if ALV.CheckBoxes then
 
1516
    begin
 
1517
      if AItem.Checked then
 
1518
        QTreeWidgetItem_setCheckState(TWI, 0, QtChecked)
 
1519
      else
 
1520
        QTreeWidgetItem_setCheckState(TWI, 0, QtUnchecked);
 
1521
    end;
 
1522
 
 
1523
    AAlignment := QtAlignLeft;
 
1524
    if TListView(ALV).Columns.Count > 0 then
 
1525
      AAlignment := AlignmentToQtAlignmentMap[ALV.Column[0].Alignment];
 
1526
 
 
1527
    if Str <> '' then
 
1528
      QtTreeWidget.setItemText(TWI, 0, Str, AAlignment);
 
1529
 
 
1530
    QtTreeWidget.setItemData(TWI, 0, AItem);
 
1531
 
 
1532
    for i := 0 to AItem.SubItems.Count - 1 do
 
1533
    begin
 
1534
      AAlignment := QtAlignLeft;
 
1535
      if (TListView(ALV).Columns.Count > 0) and (i + 1 < TListView(ALV).Columns.Count) then
 
1536
        AAlignment := AlignmentToQtAlignmentMap[ALV.Column[i + 1].Alignment];
 
1537
      if AItem.Subitems.Strings[i] <> '' then
 
1538
      begin
 
1539
        Str := GetUtf8String(AItem.Subitems.Strings[i]);
 
1540
        QtTreeWidget.setItemText(TWI, i + 1, Str, AAlignment);
 
1541
        QtTreeWidget.setItemData(TWI, i + 1, AItem);
 
1542
      end;
 
1543
    end;
 
1544
    QtTreeWidget.insertTopLevelItem(AIndex, TWI);
 
1545
  end;
 
1546
end;
 
1547
 
 
1548
{------------------------------------------------------------------------------
 
1549
  Method: TCDWSCustomListView.ItemSetText
 
1550
  Params:  None
 
1551
  Returns: Nothing
 
1552
 ------------------------------------------------------------------------------}
 
1553
class procedure TCDWSCustomListView.ItemSetText(const ALV: TCustomListView;
 
1554
  const AIndex: Integer; const AItem: TListItem; const ASubIndex: Integer;
 
1555
  const AText: String);
 
1556
var
 
1557
  QtListWidget: TQtListWidget;
 
1558
  QtTreeWidget: TQtTreeWidget;
 
1559
  TWI: QTreeWidgetItemH;
 
1560
  Str: WideString;
 
1561
  AAlignment: QtAlignment;
 
1562
begin
 
1563
  if not WSCheckHandleAllocated(ALV, 'ItemSetText') then
 
1564
    Exit;
 
1565
 
 
1566
  if IsIconView(ALV) then
 
1567
  begin
 
1568
    QtListWidget := TQtListWidget(ALV.Handle);
 
1569
    AAlignment := QtAlignLeft;
 
1570
    if (TListView(ALV).Columns.Count > 0) and (ASubIndex < TListView(ALV).Columns.Count)  then
 
1571
      AAlignment := AlignmentToQtAlignmentMap[ALV.Column[ASubIndex].Alignment];
 
1572
    QtListWidget.setItemText(AIndex, AText, AAlignment);
 
1573
  end else
 
1574
  begin
 
1575
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1576
    Str := GetUtf8String(AText);
 
1577
    TWI := QtTreeWidget.topLevelItem(AIndex);
 
1578
    if TWI <> NiL then
 
1579
    begin
 
1580
      AAlignment := QtAlignLeft;
 
1581
      if (TListView(ALV).Columns.Count > 0) and (ASubIndex < TListView(ALV).Columns.Count)  then
 
1582
        AAlignment := AlignmentToQtAlignmentMap[ALV.Column[ASubIndex].Alignment];
 
1583
      QtTreeWidget.setItemText(TWI, ASubIndex, Str, AAlignment);
 
1584
    end;
 
1585
  end;
 
1586
end;
 
1587
 
 
1588
{------------------------------------------------------------------------------
 
1589
  Method: TCDWSCustomListView.ItemShow
 
1590
  Params:  None
 
1591
  Returns: Nothing
 
1592
 ------------------------------------------------------------------------------}
 
1593
class procedure TCDWSCustomListView.ItemShow(const ALV: TCustomListView;
 
1594
  const AIndex: Integer; const AItem: TListItem; const PartialOK: Boolean);
 
1595
var
 
1596
  QtListWidget: TQtListWidget;
 
1597
  LWI: QListWidgetItemH;
 
1598
  QtTreeWidget: TQtTreeWidget;
 
1599
  TWI: QTreeWidgetItemH;
 
1600
begin
 
1601
  if not WSCheckHandleAllocated(ALV, 'ItemShow') then
 
1602
    Exit;
 
1603
  if IsIconView(ALV) then
 
1604
  begin
 
1605
    QtListWidget := TQtListWidget(ALV.Handle);
 
1606
    LWI := QtListWidget.getItem(AIndex);
 
1607
    QtListWidget.setItemVisible(LWI, True);
 
1608
  end else
 
1609
  begin
 
1610
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1611
    TWI := QtTreeWidget.topLevelItem(AIndex);
 
1612
    QtTreeWidget.setItemVisible(TWI, True);
 
1613
  end;
 
1614
end;
 
1615
 
 
1616
 
 
1617
{------------------------------------------------------------------------------
 
1618
  Method: TCDWSCustomListView.ItemDisplayRect
 
1619
  Params:  None
 
1620
  Returns: Nothing
 
1621
 ------------------------------------------------------------------------------}
 
1622
class function  TCDWSCustomListView.ItemDisplayRect(const ALV: TCustomListView;
 
1623
  const AIndex, ASubItem: Integer; ACode: TDisplayCode): TRect;
 
1624
var
 
1625
  QtListWidget: TQtListWidget;
 
1626
  LWI: QListWidgetItemH;
 
1627
  QtTreeWidget: TQtTreeWidget;
 
1628
  TWI: QTreeWidgetItemH;
 
1629
begin
 
1630
  if not WSCheckHandleAllocated(ALV, 'ItemDisplayRect') then
 
1631
    Exit;
 
1632
 
 
1633
  if IsIconView(ALV) then
 
1634
  begin
 
1635
    QtListWidget := TQtListWidget(ALV.Handle);
 
1636
    LWI := QtListWidget.getItem(AIndex);
 
1637
    Result := QtListWidget.getVisualItemRect(LWI);
 
1638
  end else
 
1639
  begin
 
1640
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1641
    TWI := QtTreeWidget.topLevelItem(AIndex);
 
1642
    if QTreeWidgetItem_childCount(TWI) > 0 then
 
1643
      Result := QtTreeWidget.visualItemRect(QTreeWidgetItem_child(TWI, ASubItem))
 
1644
    else
 
1645
      Result := QtTreeWidget.visualItemRect(TWI);
 
1646
  end;
 
1647
end;
 
1648
 
 
1649
class procedure TCDWSCustomListView.BeginUpdate(const ALV: TCustomListView);
 
1650
var
 
1651
  QtWidget: TQtWidget;
 
1652
begin
 
1653
  if not WSCheckHandleAllocated(ALV, 'BeginUpdate') then
 
1654
    Exit;
 
1655
  QtWidget := TQtWidget(ALV.Handle);
 
1656
  if not QtWidget.InUpdate then
 
1657
    QtWidget.setUpdatesEnabled(False);
 
1658
  QtWidget.BeginUpdate;
 
1659
end;
 
1660
 
 
1661
class procedure TCDWSCustomListView.EndUpdate(const ALV: TCustomListView);
 
1662
var
 
1663
  QtWidget: TQtWidget;
 
1664
begin
 
1665
  if not WSCheckHandleAllocated(ALV, 'EndUpdate') then
 
1666
    Exit;
 
1667
  QtWidget := TQtWidget(ALV.Handle);
 
1668
  QtWidget.EndUpdate;
 
1669
  if not QtWidget.InUpdate then
 
1670
    QtWidget.setUpdatesEnabled(True);
 
1671
end;
 
1672
 
 
1673
{------------------------------------------------------------------------------
 
1674
  Method: TCDWSCustomListView.GetFocused
 
1675
  Params:  None
 
1676
  Returns: Nothing
 
1677
 ------------------------------------------------------------------------------}
 
1678
class function TCDWSCustomListView.GetFocused(const ALV: TCustomListView): Integer;
 
1679
var
 
1680
  QtListWidget: TQtListWidget;
 
1681
  LWI: QListWidgetItemH;
 
1682
  QtTreeWidget: TQtTreeWidget;
 
1683
  TWI: QTreeWidgetItemH;
 
1684
  i: Integer;
 
1685
begin
 
1686
  if not WSCheckHandleAllocated(ALV, 'GetFocused') then
 
1687
    Exit;
 
1688
 
 
1689
  if IsIconView(ALV) then
 
1690
  begin
 
1691
    QtListWidget := TQtListWidget(ALV.Handle);
 
1692
    LWI := QtListWidget.currentItem;
 
1693
    if QtListWidget.getItemSelected(LWI) then
 
1694
      Result := QtListWidget.getRow(LWI)
 
1695
    else
 
1696
      Result := -1;
 
1697
  end else
 
1698
  begin
 
1699
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1700
    TWI := QtTreeWidget.currentItem;
 
1701
    i := QtTreeWidget.getRow(TWI);
 
1702
    if QTreeWidgetItem_isSelected(TWI) then
 
1703
      Result := i
 
1704
    else
 
1705
      Result := -1;
 
1706
  end;
 
1707
end;
 
1708
 
 
1709
{------------------------------------------------------------------------------
 
1710
  Method: TCDWSCustomListView.GetItemAt
 
1711
  Params:  None
 
1712
  Returns: Nothing
 
1713
 ------------------------------------------------------------------------------}
 
1714
class function TCDWSCustomListView.GetItemAt(const ALV: TCustomListView; x,y: integer): Integer;
 
1715
var
 
1716
  QtListWidget: TQtListWidget;
 
1717
  LWI: QListWidgetItemH;
 
1718
  QtTreeWidget: TQtTreeWidget;
 
1719
  TWI: QTreeWidgetItemH;
 
1720
  AOrientation: QtOrientation;
 
1721
  HeaderOffset: Integer;
 
1722
begin
 
1723
  if not WSCheckHandleAllocated(ALV, 'GetItemAt') then
 
1724
    Exit;
 
1725
  if IsIconView(ALV) then
 
1726
  begin
 
1727
    QtListWidget := TQtListWidget(ALV.Handle);
 
1728
    LWI := QtListWidget.itemAt(x, y);
 
1729
    Result := QtListWidget.getRow(LWI);
 
1730
  end else
 
1731
  begin
 
1732
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1733
    HeaderOffset := QtTreeWidget.getHeaderHeight(AOrientation);
 
1734
 
 
1735
    HeaderOffset := y - HeaderOffset;
 
1736
    if HeaderOffset < 0 then
 
1737
      HeaderOffset := 0;
 
1738
    TWI := QtTreeWidget.itemAt(x, HeaderOffset);
 
1739
    Result := QtTreeWidget.getRow(TWI);
 
1740
  end;
 
1741
end;
 
1742
 
 
1743
{------------------------------------------------------------------------------
 
1744
  Method: TCDWSCustomListView.GetSelCount
 
1745
  Params:  None
 
1746
  Returns: Nothing
 
1747
 ------------------------------------------------------------------------------}
 
1748
class function TCDWSCustomListView.GetSelCount(const ALV: TCustomListView): Integer;
 
1749
begin
 
1750
  if not WSCheckHandleAllocated(ALV, 'GetSelCount') then
 
1751
    Exit;
 
1752
  if IsIconView(ALV) then
 
1753
    Result := TQtListWidget(ALV.Handle).getSelCount
 
1754
  else
 
1755
    Result := TQtTreeWidget(ALV.Handle).selCount;
 
1756
end;
 
1757
 
 
1758
{------------------------------------------------------------------------------
 
1759
  Method: TCDWSCustomListView.GetSelection
 
1760
  Params:  None
 
1761
  Returns: Nothing
 
1762
 ------------------------------------------------------------------------------}
 
1763
class function TCDWSCustomListView.GetSelection(const ALV: TCustomListView): Integer;
 
1764
var
 
1765
  QtListWidget: TQtListWidget;
 
1766
  QtTreeWidget: TQtTreeWidget;
 
1767
  FPInts: TPtrIntArray;
 
1768
begin
 
1769
  if not WSCheckHandleAllocated(ALV, 'GetSelection') then
 
1770
    Exit;
 
1771
  if IsIconView(ALV) then
 
1772
  begin
 
1773
    QtListWidget := TQtListWidget(ALV.Handle);
 
1774
    FPInts := QtListWidget.selectedItems;
 
1775
  end else
 
1776
  begin
 
1777
    {implement selection event so we can return Alv.Selected.Index}
 
1778
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1779
    FPInts := QtTreeWidget.selectedItems;
 
1780
  end;
 
1781
  if Length(FPInts)>0 then
 
1782
    Result := FPInts[0]
 
1783
  else
 
1784
    Result := -1;
 
1785
end;
 
1786
 
 
1787
class function TCDWSCustomListView.GetTopItem(const ALV: TCustomListView
 
1788
  ): Integer;
 
1789
var
 
1790
  QtItemView: TQtAbstractItemView;
 
1791
begin
 
1792
  Result := -1;
 
1793
  if not WSCheckHandleAllocated(ALV, 'GetTopItem') then
 
1794
    Exit;
 
1795
  // according to embarcadero docs this should return
 
1796
  // only for vsList and vsReport
 
1797
  if not (TListView(ALV).ViewStyle in [vsList, vsReport]) then
 
1798
    exit;
 
1799
  QtItemView := TQtAbstractItemView(ALV.Handle);
 
1800
  Result := QtItemView.getTopItem;
 
1801
end;
 
1802
 
 
1803
 
 
1804
{------------------------------------------------------------------------------
 
1805
  Method: TCDWSCustomListView.InternalUpdateItems
 
1806
  Params:  TCustomListView
 
1807
  Returns: Nothing
 
1808
  Sync TCustomListView with QTreeWidget items.
 
1809
 ------------------------------------------------------------------------------}
 
1810
class procedure TCDWSCustomListView.InternalUpdateItems(
 
1811
  const AList: TCustomListView);
 
1812
var
 
1813
  QtTreeWidget: TQtTreeWidget;
 
1814
  i: Integer;
 
1815
  j: Integer;
 
1816
  AItem: TListItem;
 
1817
  WStr: WideString;
 
1818
  Item: QTreeWidgetItemH;
 
1819
  AAlignment: QtAlignment;
 
1820
  ImgList: TImageList;
 
1821
  Bmp: TBitmap;
 
1822
begin
 
1823
  QtTreeWidget := TQtTreeWidget(AList.Handle);
 
1824
  ImgList := TImageList.Create(nil);
 
1825
 
 
1826
  if (TListView(AList).ViewStyle = vsIcon) and
 
1827
    Assigned(TListView(AList).LargeImages) then
 
1828
    ImgList.Assign(TListView(AList).LargeImages);
 
1829
 
 
1830
  if (TListView(AList).ViewStyle in [vsSmallIcon, vsReport, vsList]) and
 
1831
    Assigned(TListView(AList).SmallImages) then
 
1832
    ImgList.Assign(TListView(AList).SmallImages);
 
1833
 
 
1834
  BeginUpdate(AList);
 
1835
  try
 
1836
    for i := 0 to AList.Items.Count - 1 do
 
1837
    begin
 
1838
      AItem := AList.Items[i];
 
1839
      WStr := GetUTF8String(AItem.Caption);
 
1840
      Item := QtTreeWidget.topLevelItem(i);
 
1841
      QtTreeWidget.setItemText(Item, 0, WStr, AlignmentToQtAlignmentMap[AList.Column[0].Alignment]);
 
1842
      QtTreeWidget.setItemData(Item, 0, AItem);
 
1843
      if AList.Checkboxes then
 
1844
      begin
 
1845
        if AItem.Checked then
 
1846
          QTreeWidgetItem_setCheckState(Item, 0, QtChecked)
 
1847
        else
 
1848
          QTreeWidgetItem_setCheckState(Item, 0, QtUnChecked);
 
1849
      end;
 
1850
 
 
1851
      if (ImgList.Count > 0) and
 
1852
        ((AItem.ImageIndex >= 0) and (AItem.ImageIndex < ImgList.Count)) then
 
1853
      begin
 
1854
        Bmp := TBitmap.Create;
 
1855
        try
 
1856
          ImgList.GetBitmap(AItem.ImageIndex, Bmp);
 
1857
          QTreeWidgetItem_setIcon(Item, 0, TQtImage(Bmp.Handle).AsIcon);
 
1858
        finally
 
1859
          Bmp.Free;
 
1860
        end;
 
1861
      end;
 
1862
 
 
1863
      // subitems
 
1864
      for j := 0 to AItem.SubItems.Count - 1 do
 
1865
      begin
 
1866
        AAlignment := QtAlignLeft;
 
1867
        if (TListView(AList).Columns.Count > 0) and (j + 1 < TListView(AList).Columns.Count) then
 
1868
          AAlignment := AlignmentToQtAlignmentMap[TListView(AList).Column[j + 1].Alignment];
 
1869
        WStr := GetUtf8String(AItem.Subitems.Strings[j]);
 
1870
        QtTreeWidget.setItemText(Item, j + 1, WStr, AAlignment);
 
1871
        QtTreeWidget.setItemData(Item, j + 1, AItem);
 
1872
      end;
 
1873
    end;
 
1874
 
 
1875
  finally
 
1876
    ImgList.Free;
 
1877
    EndUpdate(AList);
 
1878
  end;
 
1879
end;
 
1880
 
 
1881
{------------------------------------------------------------------------------
 
1882
  Method: TCDWSCustomListView.SetSort
 
1883
  Params:  None
 
1884
  Returns: Nothing
 
1885
 ------------------------------------------------------------------------------}
 
1886
class procedure TCDWSCustomListView.SetSort(const ALV: TCustomListView;
 
1887
  const AType: TSortType; const AColumn: Integer; const ASortDirection: TSortDirection);
 
1888
var
 
1889
  QtTreeWidget: TQtTreeWidget;
 
1890
  {$IFDEF TEST_QT_SORTING}
 
1891
  StdModel: QStandardItemModelH;
 
1892
  {$ELSE}
 
1893
  CanSort: Boolean;
 
1894
  {$ENDIF}
 
1895
begin
 
1896
  if not WSCheckHandleAllocated(ALV, 'SetSort') then
 
1897
    Exit;
 
1898
 
 
1899
  if (csDesigning in ALV.ComponentState) then
 
1900
    exit;
 
1901
 
 
1902
  if IsIconView(ALV) then
 
1903
    exit;
 
1904
 
 
1905
  QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
1906
 
 
1907
  if AType = stNone then
 
1908
    QtTreeWidget.Header.SetSortIndicatorVisible(False)
 
1909
  else
 
1910
  begin
 
1911
    {$IFDEF TEST_QT_SORTING}
 
1912
    // QTreeWidget crashes sometimes on changing sort role (possible qt bug).
 
1913
    // need deeper investigation.
 
1914
    if QtTreeWidget.ItemCount > 0 then
 
1915
    begin
 
1916
      StdModel := QStandardItemModelH(QtTreeWidget.getModel);
 
1917
      if QStandardItemModel_sortRole(StdModel) <> Ord(QtUserRole) then
 
1918
        QStandardItemModel_setSortRole(StdModel, Ord(QtUserRole));
 
1919
    end;
 
1920
    {$ELSE}
 
1921
    with QtTreeWidget do
 
1922
    begin
 
1923
      CanSort := ItemCount > 0;
 
1924
      Header.SetSortIndicatorVisible(True);
 
1925
      if (AColumn >= 0) and (AColumn < ColCount) and
 
1926
        CanSort then
 
1927
      begin
 
1928
        Header.SetSortIndicator(AColumn, QtSortOrder(Ord(ASortDirection)));
 
1929
        InternalUpdateItems(ALV);
 
1930
      end;
 
1931
    end;
 
1932
    {$ENDIF}
 
1933
  end;
 
1934
end;
 
1935
 
 
1936
 
 
1937
{------------------------------------------------------------------------------
 
1938
  Method: TCDWSCustomListView.GetBoundingRect
 
1939
  Params:  None
 
1940
  Returns: Nothing
 
1941
 ------------------------------------------------------------------------------}
 
1942
class function TCDWSCustomListView.GetBoundingRect(const ALV: TCustomListView): TRect;
 
1943
begin
 
1944
  if not WSCheckHandleAllocated(ALV, 'GetBoundingRect') then
 
1945
    Exit;
 
1946
  Result := TQtWidget(ALV.Handle).getFrameGeometry;
 
1947
end;
 
1948
 
 
1949
class function TCDWSCustomListView.GetViewOrigin(const ALV: TCustomListView
 
1950
  ): TPoint;
 
1951
var
 
1952
  QtItemView: TQtAbstractItemView;
 
1953
begin
 
1954
  Result := Point(0, 0);
 
1955
  if not WSCheckHandleAllocated(ALV, 'GetViewOrigin') then
 
1956
    Exit;
 
1957
  QtItemView := TQtAbstractItemView(ALV.Handle);
 
1958
  Result := QtItemView.getViewOrigin;
 
1959
end;
 
1960
 
 
1961
class function TCDWSCustomListView.GetVisibleRowCount(const ALV: TCustomListView
 
1962
  ): Integer;
 
1963
begin
 
1964
  Result := 0;
 
1965
  if not WSCheckHandleAllocated(ALV, 'GetVisibleRowCount') then
 
1966
    Exit;
 
1967
  Result := TQtAbstractItemView(ALV.Handle).getVisibleRowCount;
 
1968
end;
 
1969
 
 
1970
class procedure TCDWSCustomListView.SetAllocBy(const ALV: TCustomListView;
 
1971
  const AValue: Integer);
 
1972
var
 
1973
  QtList: TQtListWidget;
 
1974
  NewValue: integer;
 
1975
begin
 
1976
  if not WSCheckHandleAllocated(ALV, 'SetAllocBy') then
 
1977
    Exit;
 
1978
  if TListView(ALV).ViewStyle <> vsReport then
 
1979
  begin
 
1980
    NewValue := AValue;
 
1981
    if NewValue < 0 then
 
1982
      NewValue := 0;
 
1983
    QtList := TQtListWidget(ALV.Handle);
 
1984
    if NewValue > 0 then
 
1985
    begin
 
1986
      QtList.setLayoutMode(QListViewBatched);
 
1987
      QtList.BatchSize := NewValue;
 
1988
    end else
 
1989
      QtList.setLayoutMode(QListViewSinglePass);
 
1990
  end;
 
1991
end;
 
1992
 
 
1993
class procedure TCDWSCustomListView.SetIconArrangement(
 
1994
  const ALV: TCustomListView; const AValue: TIconArrangement);
 
1995
var
 
1996
  QtList: TQtListWidget;
 
1997
begin
 
1998
  if not WSCheckHandleAllocated(ALV, 'SetIconArrangement') then
 
1999
    Exit;
 
2000
  if IsIconView(ALV) then
 
2001
  begin
 
2002
    // hm...seem that QListView have bug, doesn't want to rearrange items
 
2003
    // in any case when iaTop and AutoArrange=True (then it looks same as
 
2004
    // iaLeft without arrange, so we must set GridSize in that case
 
2005
    // update: bug is fixed in Qt-4.6.2
 
2006
    {$note set workaround for QListView bug via QtList.GridSize}
 
2007
    QtList := TQtListWidget(ALV.Handle);
 
2008
    if QtList.ViewStyle <> Ord(vsList) then
 
2009
      QtList.setViewFlow(IconArngToQListFlow[AValue]);
 
2010
  end;
 
2011
end;
 
2012
 
 
2013
class procedure TCDWSCustomListView.SetItemsCount(const ALV: TCustomListView;
 
2014
  const Avalue: Integer);
 
2015
var
 
2016
  QtListWidget: TQtListWidget;
 
2017
  QtTreeWidget: TQtTreeWidget;
 
2018
begin
 
2019
  if not WSCheckHandleAllocated(ALV, 'SetItemsCount') then
 
2020
    Exit;
 
2021
  if IsIconView(ALV) then
 
2022
  begin
 
2023
    QtListWidget := TQtListWidget(ALV.Handle);
 
2024
    QtListWidget.ItemCount := AValue;
 
2025
  end else
 
2026
  begin
 
2027
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
2028
    QtTreeWidget.ItemCount := AValue;
 
2029
  end;
 
2030
end;
 
2031
 
 
2032
class procedure TCDWSCustomListView.SetOwnerData(const ALV: TCustomListView;
 
2033
  const AValue: Boolean);
 
2034
var
 
2035
  QtItemView: TQtAbstractItemView;
 
2036
begin
 
2037
  if not WSCheckHandleAllocated(ALV, 'SetOwnerData') then
 
2038
    Exit;
 
2039
  QtItemView := TQtAbstractItemView(ALV.Handle);
 
2040
  QtItemView.OwnerData := AValue;
 
2041
end;
 
2042
 
 
2043
class procedure TCDWSCustomListView.SetProperty(const ALV: TCustomListView;
 
2044
  const AProp: TListViewProperty; const AIsSet: Boolean);
 
2045
const
 
2046
  BoolToSelectionMode: array[Boolean] of QAbstractItemViewSelectionMode =
 
2047
  (
 
2048
    QAbstractItemViewSingleSelection,
 
2049
    QAbstractItemViewExtendedSelection
 
2050
  );
 
2051
  BoolToSelectionBehavior: array[Boolean] of QAbstractItemViewSelectionBehavior =
 
2052
  (
 
2053
    QAbstractItemViewSelectItems,
 
2054
    QAbstractItemViewSelectRows
 
2055
  );
 
2056
  BoolToEditTriggers: array[Boolean] of QAbstractItemViewEditTriggers =
 
2057
  (
 
2058
    QAbstractItemViewSelectedClicked,
 
2059
    QAbstractItemViewNoEditTriggers
 
2060
  );
 
2061
var
 
2062
  SavedCheckable: Boolean;
 
2063
  QtItemView: TQtAbstractItemView;
 
2064
begin
 
2065
  if not WSCheckHandleAllocated(ALV, 'SetProperty')
 
2066
  then Exit;
 
2067
  QtItemView := TQtAbstractItemView(ALV.Handle);
 
2068
  case AProp of
 
2069
    lvpAutoArrange:
 
2070
      begin
 
2071
        if IsIconView(ALV) and
 
2072
          (TQtListWidget(ALV.Handle).ViewStyle <> Ord(vsList)) then
 
2073
          TQtListWidget(ALV.Handle).setWrapping(AIsSet);
 
2074
      end;
 
2075
    lvpCheckboxes:
 
2076
      begin
 
2077
        SavedCheckable := QtItemView.Checkable;
 
2078
        QtItemView.Checkable := AIsSet;
 
2079
        if SavedCheckable <> AIsSet then
 
2080
          RecreateWnd(ALV);
 
2081
      end;
 
2082
    lvpMultiSelect:
 
2083
      begin
 
2084
        if (QtItemView.getSelectionMode <> QAbstractItemViewNoSelection) then
 
2085
          QtItemView.setSelectionMode(BoolToSelectionMode[AIsSet]);
 
2086
      end;
 
2087
    lvpShowColumnHeaders:
 
2088
      begin
 
2089
        if not IsIconView(ALV) then
 
2090
          with TQtTreeWidget(ALV.Handle) do
 
2091
            setHeaderVisible(AIsSet and (TListView(ALV).ViewStyle = vsReport)
 
2092
              and (TListView(ALV).Columns.Count > 0) );
 
2093
      end;
 
2094
    lvpReadOnly: QtItemView.setEditTriggers(BoolToEditTriggers[AIsSet]);
 
2095
    lvpRowSelect:
 
2096
      begin
 
2097
        if not IsIconView(ALV) then
 
2098
          TQtTreeWidget(ALV.Handle).setAllColumnsShowFocus(AIsSet);
 
2099
        QtItemView.setSelectionBehavior(BoolToSelectionBehavior[AIsSet]);
 
2100
      end;
 
2101
    lvpWrapText: QtItemView.setWordWrap(AIsSet);
 
2102
    lvpHideSelection: QtItemView.HideSelection := AIsSet;
 
2103
  end;
 
2104
end;
 
2105
 
 
2106
class procedure TCDWSCustomListView.SetProperties(const ALV: TCustomListView;
 
2107
  const AProps: TListViewProperties);
 
2108
var
 
2109
  i: TListViewProperty;
 
2110
begin
 
2111
  if not WSCheckHandleAllocated(ALV, 'SetProperties')
 
2112
  then Exit;
 
2113
  for i := Low(TListViewProperty) to High(TListViewProperty) do
 
2114
    SetProperty(ALV, i, i in AProps);
 
2115
end;
 
2116
 
 
2117
class procedure TCDWSCustomListView.SetScrollBars(const ALV: TCustomListView;
 
2118
  const AValue: TScrollStyle);
 
2119
var
 
2120
  QtItemView: TQtAbstractItemView;
 
2121
begin
 
2122
  if not WSCheckHandleAllocated(ALV, 'SetScrollBars') then
 
2123
    Exit;
 
2124
  QtItemView := TQtAbstractItemView(ALV.Handle);
 
2125
  {always reset before applying new TScrollStyle}
 
2126
  QtItemView.setScrollStyle(ssNone);
 
2127
  if AValue <> ssNone then
 
2128
    QtItemView.setScrollStyle(AValue);
 
2129
end;
 
2130
 
 
2131
class procedure TCDWSCustomListView.SetViewStyle(const ALV: TCustomListView;
 
2132
  const AValue: TViewStyle);
 
2133
var
 
2134
  QtItemView: TQtAbstractItemView;
 
2135
  QtListWidget: TQtListWidget;
 
2136
  LWI: QListWidgetItemH;
 
2137
  QtTreeWidget: TQtTreeWidget;
 
2138
  ItemViewWidget: QAbstractItemViewH;
 
2139
  Item: QTreeWidgetItemH;
 
2140
  Size: TSize;
 
2141
  x: Integer;
 
2142
  j: Integer;
 
2143
begin
 
2144
  if not WSCheckHandleAllocated(ALV, 'SetViewStyle') then
 
2145
    Exit;
 
2146
  QtItemView := TQtAbstractItemView(ALV.Handle);
 
2147
 
 
2148
  if (QtItemView.ViewStyle <> Ord(AValue)) then
 
2149
  begin
 
2150
    RecreateWnd(ALV);
 
2151
    exit;
 
2152
  end;
 
2153
 
 
2154
  if IsIconView(ALV) then
 
2155
  begin
 
2156
    QtListWidget := TQtListWidget(ALV.Handle);
 
2157
    ItemViewWidget := QListWidgetH(QtListWidget.Widget);
 
2158
  end else
 
2159
  begin
 
2160
    QtTreeWidget := TQtTreeWidget(ALV.Handle);
 
2161
    ItemViewWidget := QTreeWidgetH(QtTreeWidget.Widget);
 
2162
    with QtTreeWidget do
 
2163
      setHeaderVisible(TListView(ALV).ShowColumnHeaders and (AValue = vsReport)
 
2164
        and (TListView(ALV).Columns.Count > 0) );
 
2165
  end;
 
2166
  case AValue of
 
2167
    vsIcon:
 
2168
       begin
 
2169
        x := QStyle_pixelMetric(QApplication_style(), QStylePM_IconViewIconSize,
 
2170
          nil, ItemViewWidget);
 
2171
        Size.cx := x;
 
2172
        Size.cy := x;
 
2173
        if Assigned(TListView(ALV).LargeImages) then
 
2174
        begin
 
2175
          Size.cy := TListView(ALV).LargeImages.Height;
 
2176
          Size.cx := TListView(ALV).LargeImages.Width;
 
2177
        end;
 
2178
      end;
 
2179
    vsSmallIcon:
 
2180
      begin
 
2181
        x := QStyle_pixelMetric(QApplication_style(), QStylePM_ListViewIconSize,
 
2182
          nil, ItemViewWidget);
 
2183
        Size.cx := x;
 
2184
        Size.cy := x;
 
2185
        if Assigned(TListView(ALV).SmallImages) then
 
2186
        begin
 
2187
          Size.cy := TListView(ALV).SmallImages.Height;
 
2188
          Size.cx := TListView(ALV).SmallImages.Width;
 
2189
        end;
 
2190
      end;
 
2191
    vsList, vsReport:
 
2192
      begin
 
2193
        x := QStyle_pixelMetric(QApplication_style(), QStylePM_ListViewIconSize,
 
2194
          nil, ItemViewWidget);
 
2195
        Size.cx := x;
 
2196
        Size.cy := x;
 
2197
      end;
 
2198
  end;
 
2199
 
 
2200
  TQtAbstractItemView(ALV.Handle).IconSize := Size;
 
2201
 
 
2202
  if IsIconView(ALV) then
 
2203
  begin
 
2204
    LWI := QtListWidget.getItem(0);
 
2205
    if LWI <> nil then
 
2206
    begin
 
2207
      X := Size.CY;
 
2208
      QListWidgetItem_sizeHint(LWI, @Size);
 
2209
      Size.Cy := X;
 
2210
      QListWidgetItem_setSizeHint(LWI, @Size);
 
2211
    end;
 
2212
  end else
 
2213
  begin
 
2214
    Item := QtTreeWidget.topLevelItem(0);
 
2215
    if Item <> nil then
 
2216
    begin
 
2217
      X := Size.CY;
 
2218
      QTreeWidgetItem_sizeHint(Item, @Size, 0);
 
2219
      Size.Cy := X;
 
2220
      QTreeWidgetItem_setSizeHint(Item, 0, @Size);
 
2221
 
 
2222
      for j := 0 to QtTreeWidget.ColCount - 1 do
 
2223
      begin
 
2224
        Item := QtTreeWidget.itemAt(j, 0);
 
2225
        QTreeWidgetItem_setSizeHint(Item, j, @Size);
 
2226
      end;
 
2227
    end;
 
2228
    QtTreeWidget.UniformRowHeights := True;
 
2229
  end;
 
2230
end;*)
 
2231
 
 
2232
end.