source: trunk/Packages/DpiControls/Dpi.StdCtrls.pas

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