File: cocoawsspin.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (129 lines) | stat: -rw-r--r-- 4,962 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{
 *****************************************************************************
 *                                CocoaWSSpin.pas                            *
 *                                -----------                                * 
 *                                                                           *
 *                                                                           *
 *****************************************************************************

 *****************************************************************************
  This file is part of the Lazarus Component Library (LCL)

  See the file COPYING.modifiedLGPL.txt, included in this distribution,
  for details about the license.
 *****************************************************************************
}
unit CocoaWSSpin;

{$mode objfpc}{$H+}
{$modeswitch objectivec1}

interface

uses
  // rtl+lcl
  Controls, Spin, LCLType,
  // widgetset
  WSSpin, WSLCLClasses,
  // cocoa ws
  CocoaPrivate, CocoaWSCommon, CocoaTextEdits;

type

  { TCocoaWSCustomFloatSpinEdit }

  TCocoaWSCustomFloatSpinEdit = class(TWSCustomFloatSpinEdit)
  published
    class function  CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
    class procedure DestroyHandle(const AWinControl: TWinControl); override;
    class function  GetValue(const ACustomFloatSpinEdit: TCustomFloatSpinEdit): Double; override;
    class procedure UpdateControl(const ACustomFloatSpinEdit: TCustomFloatSpinEdit); override;
    class procedure SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer); override;
  end;

implementation

procedure UpdateControlLCLToCocoa(src: TCustomFloatSpinEdit; dst: TCocoaSpinEdit);
begin
  dst.UpdateControl(src.MinValue, src.MaxValue, src.Increment, src.Value, src.DecimalPlaces);
end;

{ TCocoaWSCustomFloatSpinEdit }

{------------------------------------------------------------------------------
  Method:  TCocoaWSCustomFloatSpinEdit.CreateHandle
  Params:  AWinControl - LCL control
           AParams     - Creation parameters
  Returns: Handle to the control in Carbon interface

  Creates new spin edit in Carbon interface with the specified parameters
 ------------------------------------------------------------------------------}
class function TCocoaWSCustomFloatSpinEdit.CreateHandle(const AWinControl: TWinControl;
  const AParams: TCreateParams): TLCLIntfHandle;
var
  lSpin: TCocoaSpinEdit;
begin
  lSpin := TCocoaSpinEdit.alloc.lclInitWithCreateParams(AParams);
  Result := TLCLIntfHandle(lSpin);
  if Result = 0 then Exit;
  lSpin.decimalPlaces := -1;
  lSpin.lclCreateSubcontrols(AParams);
  lSpin.callback := TLCLCommonCallback.Create(lSpin, AWinControl);
end;

class procedure TCocoaWSCustomFloatSpinEdit.DestroyHandle(const AWinControl: TWinControl);
begin
  if not AWinControl.HandleAllocated then Exit;
  TCocoaSpinEdit(AWinControl.Handle).lclReleaseSubcontrols;
  TCocoaWSWinControl.DestroyHandle(AWinControl);
end;

{------------------------------------------------------------------------------
  Method:  TCocoaWSCustomFloatSpinEdit.GetValue
  Params:  ACustomFloatSpinEdit - LCL custom float spin edit
  Returns: The float spin edit value
 ------------------------------------------------------------------------------}
class function TCocoaWSCustomFloatSpinEdit.GetValue(const ACustomFloatSpinEdit: TCustomFloatSpinEdit): Double;
var
  lSpin: TCocoaSpinEdit;
begin
  Result := 0;
  if ACustomFloatSpinEdit = nil then Exit;
  if not ACustomFloatSpinEdit.HandleAllocated then Exit;
  lSpin := TCocoaSpinEdit(ACustomFloatSpinEdit.Handle);

  Result := lSpin.Stepper.doubleValue();
end;

{------------------------------------------------------------------------------
  Method:  TCocoaWSCustomFloatSpinEdit.UpdateControl
  Params:  ACustomFloatSpinEdit - LCL custom float spin edit
  
  Update the value, min, max and increment of custom float spin edit in Cocoa
  interface
 ------------------------------------------------------------------------------}
class procedure TCocoaWSCustomFloatSpinEdit.UpdateControl(const ACustomFloatSpinEdit: TCustomFloatSpinEdit);
var
  lSpin: TCocoaSpinEdit;
begin
  if ACustomFloatSpinEdit = nil then Exit;
  if not ACustomFloatSpinEdit.HandleAllocated then Exit;
  lSpin := TCocoaSpinEdit(ACustomFloatSpinEdit.Handle);
  UpdateControlLCLToCocoa(ACustomFloatSpinEdit, lSpin);
end;

class procedure TCocoaWSCustomFloatSpinEdit.SetBounds(
  const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer);
var
  lSpin: TCocoaSpinEdit;
  ACustomFloatSpinEdit: TCustomFloatSpinEdit absolute AWinControl;
begin
  if ACustomFloatSpinEdit = nil then Exit;
  if not ACustomFloatSpinEdit.HandleAllocated then Exit;
  lSpin := TCocoaSpinEdit(ACustomFloatSpinEdit.Handle);

  TCocoaWSWinControl.SetBounds(AWinControl, ALeft, ATop, AWidth, AHeight);
  lSpin.PositionSubcontrols(ALeft, ATop, AWidth, AHeight);
end;

end.