source: branches/zoom/Packages/DpiControls/Dpi.StdCtrls.pas

Last change on this file was 673, checked in by chronos, 6 weeks ago
  • Fixed: Black strip on the bottom of Draft dialog.
  • Fixed: Make selected book or map visible in the list on application start.
File size: 15.8 KB
Line 
1unit Dpi.StdCtrls;
2
3interface
4
5uses
6 Classes, SysUtils, Controls, StdCtrls, Forms, Dpi.Controls, Dpi.Graphics;
7
8type
9 { TMemo }
10
11 TMemo = class(TWinControl)
12 private
13 NativeMemo: StdCtrls.TMemo;
14 function GetLines: TStrings;
15 function GetReadOnly: Boolean;
16 function GetScrollBars: TScrollStyle;
17 function GetWordWrap: Boolean;
18 procedure SetLines(AValue: TStrings);
19 procedure SetReadOnly(AValue: Boolean);
20 procedure SetScrollBars(AValue: TScrollStyle);
21 procedure SetWordWrap(AValue: Boolean);
22 protected
23 function GetNativeWinControl: Controls.TWinControl; override;
24 function GetNativeMemo: StdCtrls.TMemo; virtual;
25 public
26 procedure Clear;
27 constructor Create(TheOwner: TComponent); override;
28 destructor Destroy; override;
29 published
30 property Lines: TStrings read GetLines write SetLines;
31 property WordWrap: Boolean read GetWordWrap write SetWordWrap default True;
32 property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
33 property ScrollBars: TScrollStyle read GetScrollBars write SetScrollBars default ssNone;
34 end;
35
36 { TEdit }
37
38 TEdit = class(TWinControl)
39 private
40 function GetSelLength: Integer;
41 function GetSelStart: Integer;
42 procedure SetSelLength(AValue: Integer);
43 procedure SetSelStart(AValue: Integer);
44 protected
45 function GetNativeWinControl: Controls.TWinControl; override;
46 function GetNativeEdit: StdCtrls.TEdit; virtual;
47 function GetText: TCaption; override;
48 procedure SetText(AValue: TCaption); override;
49 public
50 NativeEdit: StdCtrls.TEdit;
51 destructor Destroy; override;
52 property SelLength: Integer read GetSelLength write SetSelLength;
53 property SelStart: Integer read GetSelStart write SetSelStart;
54 published
55 property Text;
56 property BorderStyle default bsSingle;
57 property ParentFont;
58 end;
59
60 { TComboBox }
61
62 TComboBox = class(TWinControl)
63 private
64 NativeComboBox: StdCtrls.TComboBox;
65 public
66 function GetNativeComboBox: StdCtrls.TComboBox;
67 constructor Create(TheOwner: TComponent); override;
68 destructor Destroy; override;
69 end;
70
71 { TCheckBox }
72
73 TCheckBox = class(TWinControl)
74 private
75 NativeCheckBox: StdCtrls.TCheckBox;
76 public
77 function GetNativeCheckBox: StdCtrls.TCheckBox;
78 constructor Create(TheOwner: TComponent); override;
79 destructor Destroy; override;
80 end;
81
82 { TRadioButton }
83
84 TRadioButton = class(TWinControl)
85 private
86 NativeRadioButton: StdCtrls.TRadioButton;
87 public
88 function GetNativeRadioButton: StdCtrls.TRadioButton;
89 constructor Create(TheOwner: TComponent); override;
90 destructor Destroy; override;
91 end;
92
93 { TButton }
94
95 TButton = class(TWinControl)
96 private
97 protected
98 function GetNativeWinControl: Controls.TWinControl; override;
99 public
100 NativeButton: StdCtrls.TButton;
101 destructor Destroy; override;
102 published
103 property Visible;
104 end;
105
106 TDrawItemEvent = procedure(Control: TWinControl; Index: Integer;
107 ARect: TRect; State: TOwnerDrawState) of object;
108 TListBoxStyle = StdCtrls.TListBoxStyle;
109
110 { TListBox }
111
112 TListBox = class(TWinControl)
113 private
114 FCanvas: TCanvas;
115 FOnDrawItem: TDrawItemEvent;
116 function GetBorderStyle: TBorderStyle;
117 function GetCount: Integer;
118 function GetExtendedSelect: Boolean;
119 function GetIntegralHeight: Boolean;
120 function GetItemHeight: Integer;
121 function GetItemIndex: Integer;
122 function GetItems: TStrings;
123 function GetOnSelectionChange: TSelectionChangeEvent;
124 function GetParentFont: Boolean;
125 function GetScrollWidth: Integer;
126 function GetStyle: TListBoxStyle;
127 function GetTopIndex: Integer;
128 procedure SetBorderStyle(AValue: TBorderStyle);
129 procedure SetExtendedSelect(AValue: Boolean);
130 procedure SetIntegralHeight(AValue: Boolean);
131 procedure SetItemHeight(AValue: Integer);
132 procedure SetItemIndex(AValue: Integer);
133 procedure SetItems(AValue: TStrings);
134 procedure SetOnDrawItem(AValue: TDrawItemEvent);
135 procedure SetOnSelectionChange(AValue: TSelectionChangeEvent);
136 procedure SetParentFont(AValue: Boolean);
137 procedure SetScrollWidth(AValue: Integer);
138 procedure SetStyle(AValue: TListBoxStyle);
139 procedure SetTopIndex(AValue: Integer);
140 procedure DoDrawItemNative(Control: Controls.TWinControl; Index: Integer;
141 ARect: TRect; State: TOwnerDrawState);
142 protected
143 function GetNativeWinControl: Controls.TWinControl; override;
144 function GetNativeListBox: StdCtrls.TListBox; virtual;
145 public
146 NativeListBox: StdCtrls.TListBox;
147 constructor Create(AOwner: TComponent); override;
148 destructor Destroy; override;
149 procedure MakeCurrentVisible;
150 property ItemIndex: Integer read GetItemIndex write SetItemIndex;
151 property Items: TStrings read GetItems write SetItems;
152 property Count: Integer read GetCount;
153 property Canvas: TCanvas read FCanvas;
154 published
155 property ParentColor;
156 property TopIndex: Integer read GetTopIndex write SetTopIndex default 0;
157 property ScrollWidth: Integer read GetScrollWidth write SetScrollWidth default 0;
158 property ParentFont: Boolean read GetParentFont write SetParentFont default True;
159 property ItemHeight: Integer read GetItemHeight write SetItemHeight;
160 property IntegralHeight: Boolean read GetIntegralHeight write SetIntegralHeight default False;
161 property ExtendedSelect: Boolean read GetExtendedSelect write SetExtendedSelect default True;
162 property BorderStyle: TBorderStyle read GetBorderStyle write SetBorderStyle default bsNone;
163 property Visible;
164 property Anchors;
165 property OnSelectionChange: TSelectionChangeEvent read GetOnSelectionChange
166 write SetOnSelectionChange;
167 property Style: TListBoxStyle read GetStyle write SetStyle default lbStandard;
168 property OnDrawItem: TDrawItemEvent read FOnDrawItem write SetOnDrawItem;
169 end;
170
171 { TScrollBar }
172
173 TScrollBar = class(TWinControl)
174 private
175 function GetKind: TScrollBarKind;
176 function GetMax: Integer;
177 function GetMin: Integer;
178 function GetOnChange: TNotifyEvent;
179 function GetPageSize: Integer;
180 function GetPosition: Integer;
181 procedure SetKind(AValue: TScrollBarKind);
182 procedure SetMax(AValue: Integer);
183 procedure SetMin(AValue: Integer);
184 procedure SetOnChange(AValue: TNotifyEvent);
185 procedure SetPageSize(AValue: Integer);
186 procedure SetPosition(AValue: Integer);
187 protected
188 function GetNativeWinControl: Controls.TWinControl; override;
189 function GetNativeScrollBar: StdCtrls.TScrollBar; virtual;
190 public
191 NativeScrollBar: StdCtrls.TScrollBar;
192 constructor Create(TheOwner: TComponent); override;
193 destructor Destroy; override;
194 published
195 property PageSize: Integer read GetPageSize write SetPageSize;
196 property Min: Integer read GetMin write SetMin default 0;
197 property Max: Integer read GetMax write SetMax default 100;
198 property Position: Integer read GetPosition write SetPosition default 0;
199 property Kind: TScrollBarKind read GetKind write SetKind default sbHorizontal;
200 property OnChange: TNotifyEvent read GetOnChange write SetOnChange;
201 property Visible;
202 end;
203
204procedure Register;
205
206
207implementation
208
209uses
210 Dpi.Common;
211
212procedure Register;
213begin
214 RegisterComponents(DpiControlsComponentPaletteName, [TEdit, TButton,
215 TScrollBar, TListBox, TCheckBox, TComboBox]);
216end;
217
218{ TMemo }
219
220function TMemo.GetLines: TStrings;
221begin
222 Result := GetNativeMemo.Lines;
223end;
224
225function TMemo.GetReadOnly: Boolean;
226begin
227 Result := GetNativeMemo.ReadOnly;
228end;
229
230function TMemo.GetScrollBars: TScrollStyle;
231begin
232 Result := GetNativeMemo.ScrollBars;
233end;
234
235function TMemo.GetWordWrap: Boolean;
236begin
237 Result := GetNativeMemo.WordWrap;
238end;
239
240procedure TMemo.SetLines(AValue: TStrings);
241begin
242 GetNativeMemo.Lines := AValue;
243end;
244
245procedure TMemo.SetReadOnly(AValue: Boolean);
246begin
247 GetNativeMemo.ReadOnly := AValue;
248end;
249
250procedure TMemo.SetScrollBars(AValue: TScrollStyle);
251begin
252 GetNativeMemo.ScrollBars := AValue;
253end;
254
255procedure TMemo.SetWordWrap(AValue: Boolean);
256begin
257 GetNativeMemo.WordWrap := AValue;
258end;
259
260function TMemo.GetNativeWinControl: Controls.TWinControl;
261begin
262 Result := GetNativeMemo;
263end;
264
265procedure TMemo.Clear;
266begin
267 GetNativeMemo.Clear;
268end;
269
270function TMemo.GetNativeMemo: StdCtrls.TMemo;
271begin
272 if not Assigned(NativeMemo) then NativeMemo := StdCtrls.TMemo.Create(nil);
273 Result := NativeMemo;
274end;
275
276constructor TMemo.Create(TheOwner: TComponent);
277begin
278 inherited Create(TheOwner);
279end;
280
281destructor TMemo.Destroy;
282begin
283 FreeAndNil(NativeMemo);
284 inherited;
285end;
286
287{ TEdit }
288
289function TEdit.GetText: TCaption;
290begin
291 Result := GetNativeEdit.Text;
292end;
293
294procedure TEdit.SetText(AValue: TCaption);
295begin
296 GetNativeEdit.Text := AValue;
297end;
298
299destructor TEdit.Destroy;
300begin
301 FreeAndNil(NativeEdit);
302 inherited;
303end;
304
305function TEdit.GetSelLength: Integer;
306begin
307 Result := GetNativeEdit.SelLength;
308end;
309
310function TEdit.GetSelStart: Integer;
311begin
312 Result := GetNativeEdit.SelStart;
313end;
314
315procedure TEdit.SetSelLength(AValue: Integer);
316begin
317 GetNativeEdit.SelLength := AValue;
318end;
319
320procedure TEdit.SetSelStart(AValue: Integer);
321begin
322 GetNativeEdit.SelStart := AValue;
323end;
324
325function TEdit.GetNativeWinControl: Controls.TWinControl;
326begin
327 Result := GetNativeEdit;
328end;
329
330function TEdit.GetNativeEdit: StdCtrls.TEdit;
331begin
332 if not Assigned(NativeEdit) then NativeEdit := StdCtrls.TEdit.Create(nil);
333 Result := NativeEdit;
334end;
335
336{ TCheckBox }
337
338function TCheckBox.GetNativeCheckBox: StdCtrls.TCheckBox;
339begin
340 if not Assigned(NativeCheckBox) then NativeCheckBox := StdCtrls.TCheckBox.Create(nil);
341 Result := NativeCheckBox;
342end;
343
344constructor TCheckBox.Create(TheOwner: TComponent);
345begin
346 inherited Create(TheOwner);
347end;
348
349destructor TCheckBox.Destroy;
350begin
351 FreeAndNil(NativeCheckBox);
352 inherited;
353end;
354
355{ TComboBox }
356
357function TComboBox.GetNativeComboBox: StdCtrls.TComboBox;
358begin
359 if not Assigned(NativeComboBox) then NativeComboBox := StdCtrls.TComboBox.Create(nil);
360 Result := NativeComboBox;
361end;
362
363constructor TComboBox.Create(TheOwner: TComponent);
364begin
365 inherited Create(TheOwner);
366end;
367
368destructor TComboBox.Destroy;
369begin
370 FreeAndNil(NativeComboBox);
371 inherited;
372end;
373
374{ TRadioButton }
375
376function TRadioButton.GetNativeRadioButton: StdCtrls.TRadioButton;
377begin
378 if not Assigned(NativeRadioButton) then NativeRadioButton := StdCtrls.TRadioButton.Create(nil);
379 Result := NativeRadioButton;
380end;
381
382constructor TRadioButton.Create(TheOwner: TComponent);
383begin
384 inherited Create(TheOwner);
385end;
386
387destructor TRadioButton.Destroy;
388begin
389 FreeAndNil(NativeRadioButton);
390 inherited;
391end;
392
393{ TButton }
394
395function TButton.GetNativeWinControl: Controls.TWinControl;
396begin
397 if not Assigned(NativeButton) then NativeButton := StdCtrls.TButton.Create(nil);
398 Result := NativeButton;
399end;
400
401destructor TButton.Destroy;
402begin
403 FreeAndNil(NativeButton);
404 inherited;
405end;
406
407{ TScrollBar }
408
409function TScrollBar.GetKind: TScrollBarKind;
410begin
411 Result := GetNativeScrollBar.Kind;
412end;
413
414function TScrollBar.GetMax: Integer;
415begin
416 Result := GetNativeScrollBar.Max;
417end;
418
419function TScrollBar.GetMin: Integer;
420begin
421 Result := GetNativeScrollBar.Min;
422end;
423
424function TScrollBar.GetOnChange: TNotifyEvent;
425begin
426 Result := GetNativeScrollBar.OnChange;
427end;
428
429function TScrollBar.GetPageSize: Integer;
430begin
431 Result := GetNativeScrollBar.PageSize;
432end;
433
434function TScrollBar.GetPosition: Integer;
435begin
436 Result := GetNativeScrollBar.Position;
437end;
438
439procedure TScrollBar.SetKind(AValue: TScrollBarKind);
440begin
441 GetNativeScrollBar.Kind := AValue;
442end;
443
444procedure TScrollBar.SetMax(AValue: Integer);
445begin
446 GetNativeScrollBar.Max := AValue;
447end;
448
449procedure TScrollBar.SetMin(AValue: Integer);
450begin
451 GetNativeScrollBar.Min := Avalue;
452end;
453
454procedure TScrollBar.SetOnChange(AValue: TNotifyEvent);
455begin
456 GetNativeScrollBar.OnChange := AValue;
457end;
458
459procedure TScrollBar.SetPageSize(AValue: Integer);
460begin
461 GetNativeScrollBar.PageSize := AValue;
462end;
463
464procedure TScrollBar.SetPosition(AValue: Integer);
465begin
466 GetNativeScrollBar.Position := AValue;
467end;
468
469function TScrollBar.GetNativeWinControl: Controls.TWinControl;
470begin
471 Result := GetNativeScrollBar;
472end;
473
474function TScrollBar.GetNativeScrollBar: StdCtrls.TScrollBar;
475begin
476 if not Assigned(NativeScrollBar) then NativeScrollBar := StdCtrls.TScrollBar.Create(nil);
477 Result := NativeScrollBar;
478end;
479
480constructor TScrollBar.Create(TheOwner: TComponent);
481begin
482 inherited;
483end;
484
485destructor TScrollBar.Destroy;
486begin
487 FreeAndNil(NativeScrollBar);
488 inherited;
489end;
490
491{ TListBox }
492
493function TListBox.GetBorderStyle: TBorderStyle;
494begin
495 Result := GetNativeListBox.BorderStyle;
496end;
497
498function TListBox.GetCount: Integer;
499begin
500 Result := GetNativeListBox.Count;
501end;
502
503function TListBox.GetExtendedSelect: Boolean;
504begin
505 Result := GetNativeListBox.ExtendedSelect;
506end;
507
508function TListBox.GetIntegralHeight: Boolean;
509begin
510 Result := GetNativeListBox.IntegralHeight;
511end;
512
513function TListBox.GetItemHeight: Integer;
514begin
515 Result := ScaleFromNative(GetNativeListBox.ItemHeight);
516end;
517
518function TListBox.GetItemIndex: Integer;
519begin
520 Result := GetNativeListBox.ItemIndex;
521end;
522
523function TListBox.GetItems: TStrings;
524begin
525 Result := GetNativeListBox.Items;
526end;
527
528function TListBox.GetOnSelectionChange: TSelectionChangeEvent;
529begin
530 Result := GetNativeListBox.OnSelectionChange;
531end;
532
533function TListBox.GetParentFont: Boolean;
534begin
535 Result := GetNativeListBox.ParentFont;
536end;
537
538function TListBox.GetScrollWidth: Integer;
539begin
540 Result := GetNativeListBox.ScrollWidth;
541end;
542
543function TListBox.GetStyle: TListBoxStyle;
544begin
545 Result := GetNativeListBox.Style;
546end;
547
548function TListBox.GetTopIndex: Integer;
549begin
550 Result := GetNativeListBox.TopIndex;
551end;
552
553procedure TListBox.SetBorderStyle(AValue: TBorderStyle);
554begin
555 GetNativeListBox.BorderStyle := AValue;
556end;
557
558procedure TListBox.SetExtendedSelect(AValue: Boolean);
559begin
560 GetNativeListBox.ExtendedSelect := AValue;
561end;
562
563procedure TListBox.SetIntegralHeight(AValue: Boolean);
564begin
565 GetNativeListBox.IntegralHeight := AValue;
566end;
567
568procedure TListBox.SetItemHeight(AValue: Integer);
569begin
570 GetNativeListBox.ItemHeight := ScaleToNative(AValue);
571end;
572
573procedure TListBox.SetItemIndex(AValue: Integer);
574begin
575 GetNativeListBox.ItemIndex := AValue;
576end;
577
578procedure TListBox.SetItems(AValue: TStrings);
579begin
580 GetNativeListBox.Items := AValue;
581end;
582
583procedure TListBox.SetOnDrawItem(AValue: TDrawItemEvent);
584begin
585 FOnDrawItem := AValue;
586 if Assigned(AValue) then
587 GetNativeListBox.OnDrawItem := DoDrawItemNative
588 else GetNativeListBox.OnDrawItem := nil;
589end;
590
591procedure TListBox.SetOnSelectionChange(AValue: TSelectionChangeEvent);
592begin
593 GetNativeListBox.OnSelectionChange := AValue;
594end;
595
596procedure TListBox.SetParentFont(AValue: Boolean);
597begin
598 GetNativeListBox.ParentFont := AValue;
599end;
600
601procedure TListBox.SetScrollWidth(AValue: Integer);
602begin
603 GetNativeListBox.ScrollWidth := AValue;
604end;
605
606procedure TListBox.SetStyle(AValue: TListBoxStyle);
607begin
608 GetNativeListBox.Style := AValue;
609end;
610
611procedure TListBox.SetTopIndex(AValue: Integer);
612begin
613 GetNativeListBox.TopIndex := AValue;
614end;
615
616procedure TListBox.DoDrawItemNative(Control: Controls.TWinControl;
617 Index: Integer; ARect: TRect; State: TOwnerDrawState);
618begin
619 if Assigned(FOnDrawItem) then
620 FOnDrawItem(Self, Index, ScaleRectFromNative(ARect), State);
621end;
622
623function TListBox.GetNativeWinControl: Controls.TWinControl;
624begin
625 Result := GetNativeListBox;
626end;
627
628function TListBox.GetNativeListBox: StdCtrls.TListBox;
629begin
630 if not Assigned(NativeListBox) then NativeListBox := StdCtrls.TListBox.Create(nil);
631 Result := NativeListBox;
632end;
633
634constructor TListBox.Create(AOwner: TComponent);
635begin
636 inherited;
637 FCanvas := TCanvas.Create;
638 FCanvas.NativeCanvas := GetNativeListBox.Canvas;
639end;
640
641destructor TListBox.Destroy;
642begin
643 FreeAndNil(FCanvas);
644 FreeAndNil(NativeListBox);
645 inherited;
646end;
647
648procedure TListBox.MakeCurrentVisible;
649begin
650 GetNativeListBox.MakeCurrentVisible;
651end;
652
653
654initialization
655
656RegisterClasses([TButton]);
657
658end.
659
Note: See TracBrowser for help on using the repository browser.