Finishes implementing Spin Edit for wince

git-svn-id: trunk@19460 -
This commit is contained in:
sekelsenmat 2009-04-16 23:14:41 +00:00
parent 8e845b1091
commit 97bbdab0c8
2 changed files with 54 additions and 37 deletions

View File

@ -816,42 +816,38 @@ Var
Result := WindowInfo^.isComboEdit and (ComboBoxHandleSizeWindow = Windows.GetParent(Window)); Result := WindowInfo^.isComboEdit and (ComboBoxHandleSizeWindow = Windows.GetParent(Window));
end; end;
{ procedure HandleSpinEditChange(ASpinEdit: TCustomFloatSpinEdit); procedure HandleSpinEditChange(ASpinEdit: TCustomFloatSpinEdit);
var var
lWindowInfo: PWindowInfo; lWindowInfo: PWindowInfo;
lNewValue: Double;
begin begin
lWindowInfo := GetWindowInfo(ASpinEdit.Handle); lWindowInfo := GetWindowInfo(ASpinEdit.Handle);
if lWindowInfo = @DefaultWindowInfo then exit; if lWindowInfo = @DefaultWindowInfo then exit;
lNewValue := StrToFloatDef(ASpinEdit.Text, lWindowInfo^.spinValue);
if lNewValue <> lWindowInfo^.spinValue then lWindowInfo^.spinValue := ASpinEdit.StrToValue(ASpinEdit.Text);
begin
lWindowInfo^.spinValue := lNewValue; LMessage.Msg := CM_TEXTCHANGED;
LMessage.Msg := CM_TEXTCHANGED;
end;
end; end;
procedure HandleSpinEditDeltaPos(AUpDownMsg: PNMUpDown); procedure HandleSpinEditDeltaPos(AUpDownMsg: PNMUpDown);
var var
lSpinEdit: TCustomFloatSpinEdit; SpinEdit: TCustomFloatSpinEdit;
spinHandle: HWND; spinHandle: HWND;
newValue: Double; newValue: Double;
begin begin
lSpinEdit := TCustomFloatSpinEdit(WindowInfo^.WinControl); SpinEdit := TCustomFloatSpinEdit(WindowInfo^.WinControl);
newValue := WindowInfo^.spinValue + AUpDownMsg^.iDelta * lSpinEdit.Increment;
if (lSpinEdit.MinValue <> 0) or (lSpinEdit.MaxValue <> 0) then if not SpinEdit.ReadOnly then
begin begin
if newValue > lSpinEdit.MaxValue then NewValue := SpinEdit.GetLimitedValue(
newValue := lSpinEdit.MaxValue; WindowInfo^.spinValue + AUpDownMsg^.iDelta * SpinEdit.Increment);
if newValue < lSpinEdit.MinValue then WindowInfo^.spinValue := NewValue;
newValue := lSpinEdit.MinValue;
spinHandle := AUpDownMsg^.hdr.hwndFrom;
UpdateFloatSpinEditText(SpinEdit, NewValue);
Windows.SendMessage(spinHandle, UDM_SETPOS32, 0, 500);
end; end;
spinHandle := AUpDownMsg^.hdr.hwndFrom;
UpdateFloatSpinEditText(spinHandle, NewValue, lSpinEdit.DecimalPlaces);
Windows.SendMessage(spinHandle, UDM_SETPOS32, 0, 500);
WindowInfo^.spinValue := newValue;
end; end;
}
procedure SetMinMaxInfo(var MinMaxInfo: TMINMAXINFO); procedure SetMinMaxInfo(var MinMaxInfo: TMINMAXINFO);
procedure SetWin32SizePoint(AWidth, AHeight: integer; var pt: TPoint); procedure SetWin32SizePoint(AWidth, AHeight: integer; var pt: TPoint);
var var
@ -1161,10 +1157,10 @@ begin
case Hi(WParam) of case Hi(WParam) of
EN_CHANGE: LMessage.Msg := CM_TEXTCHANGED; EN_CHANGE: LMessage.Msg := CM_TEXTCHANGED;
end end
{ else if (lWinControl is TCustomFloatSpinEdit) then else if (lWinControl is TCustomFloatSpinEdit) then
case Hi(WParam) of case Hi(WParam) of
EN_CHANGE: HandleSpinEditChange(TCustomFloatSpinEdit(lWinControl)); EN_CHANGE: HandleSpinEditChange(TCustomFloatSpinEdit(lWinControl));
end} end
else if (lWinControl is TCustomMemo) then else if (lWinControl is TCustomMemo) then
case Hi(WParam) of case Hi(WParam) of
// multiline edit doesn't send EN_CHANGE, so use EN_UPDATE // multiline edit doesn't send EN_CHANGE, so use EN_UPDATE
@ -1707,17 +1703,17 @@ begin
{$endif} {$endif}
case PNMHdr(LParam)^.code of case PNMHdr(LParam)^.code of
0 :; 0 :;
{ MCN_SELCHANGE: MCN_SELCHANGE:
begin begin
LMessage.Msg := LM_CHANGED; LMessage.Msg := LM_CHANGED;
if WindowInfo^.WinControl <> nil then if WindowInfo^.WinControl <> nil then
lWinControl := WindowInfo^.WinControl; lWinControl := WindowInfo^.WinControl;
end;} end;
{ UDN_DELTAPOS: UDN_DELTAPOS:
begin begin
if WindowInfo^.WinControl <> nil then if WindowInfo^.WinControl <> nil then
HandleSpinEditDeltaPos(PNMUpDown(LParam)); HandleSpinEditDeltaPos(PNMUpDown(LParam));
end;} end;
else else
PLMsg:=@LMNotify; PLMsg:=@LMNotify;
with LMNotify Do with LMNotify Do

View File

@ -33,6 +33,7 @@ uses
// uncomment only when needed for registration // uncomment only when needed for registration
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
Spin, Controls, StdCtrls, LCLType, commctrl, Spin, Controls, StdCtrls, LCLType, commctrl,
LCLProc,
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
WSSpin, WSLCLClasses, Windows, WinCEInt, WinCEProc, WSSpin, WSLCLClasses, Windows, WinCEInt, WinCEProc,
WinCEWSStdCtrls, WinCEWSControls; WinCEWSStdCtrls, WinCEWSControls;
@ -52,8 +53,10 @@ type
class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override; class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override;
class function GetValue(const ACustomFloatSpinEdit: TCustomFloatSpinEdit): Double; override; class function GetValue(const ACustomFloatSpinEdit: TCustomFloatSpinEdit): Double; override;
class procedure SetReadOnly(const ACustomEdit: TCustomEdit; NewReadOnly: boolean); override;
class procedure SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); override; class procedure SetSelStart(const ACustomEdit: TCustomEdit; NewStart: integer); override;
class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); override; class procedure SetSelLength(const ACustomEdit: TCustomEdit; NewLength: integer); override;
class procedure SetText(const AWinControl: TWinControl; const AText: string); override;
class procedure ShowHide(const AWinControl: TWinControl); override; class procedure ShowHide(const AWinControl: TWinControl); override;
class procedure UpdateControl(const ACustomFloatSpinEdit: TCustomFloatSpinEdit); override; class procedure UpdateControl(const ACustomFloatSpinEdit: TCustomFloatSpinEdit); override;
@ -67,8 +70,8 @@ function SpinBuddyWindowProc(Window: HWnd; Msg: UInt; WParam: Windows.WParam;
LParam: Windows.LParam): LResult; cdecl; LParam: Windows.LParam): LResult; cdecl;
procedure UpdateFloatSpinEditControl(const Handle: HWND; procedure UpdateFloatSpinEditControl(const Handle: HWND;
const AFloatSpinEdit: TCustomFloatSpinEdit); const AFloatSpinEdit: TCustomFloatSpinEdit);
procedure UpdateFloatSpinEditText(const ASpinHandle: HWND; const ANewValue: Double; procedure UpdateFloatSpinEditText(const ASpinEdit: TCustomFloatSpinEdit;
const ADecimalPlaces: integer); const ANewValue: Double);
implementation implementation
@ -124,19 +127,19 @@ begin
if lWindowInfo <> @DefaultWindowInfo then if lWindowInfo <> @DefaultWindowInfo then
begin begin
lWindowInfo^.spinValue := AFloatSpinEdit.Value; lWindowInfo^.spinValue := AFloatSpinEdit.Value;
UpdateFloatSpinEditText(Handle, AFloatSpinEdit.Value, AFloatSpinEdit.DecimalPlaces); UpdateFloatSpinEditText(AFloatSpinEdit, AFloatSpinEdit.Value);
end; end;
end; end;
procedure UpdateFloatSpinEditText(const ASpinHandle: HWND; const ANewValue: Double; procedure UpdateFloatSpinEditText(const ASpinEdit: TCustomFloatSpinEdit;
const ADecimalPlaces: integer); const ANewValue: Double);
var var
editHandle: HWND; editHandle: HWND;
newValueText: string; newValueText: widestring;
begin begin
editHandle := GetBuddyWindow(ASpinHandle); editHandle := GetBuddyWindow(ASpinEdit.Handle);
newValueText := FloatToStrF(ANewValue, ffFixed, 20, ADecimalPlaces); newValueText := UTF8Decode(ASpinEdit.ValueToStr(ANewValue));
Windows.SendMessageW(editHandle, WM_SETTEXT, 0, Windows.LPARAM(PWideChar(UTF8Decode(newValueText)))); Windows.SendMessageW(editHandle, WM_SETTEXT, 0, Windows.LPARAM(PWideChar(newValueText)));
end; end;
class function TWinCEWSCustomFloatSpinEdit.CreateHandle(const AWinControl: TWinControl; class function TWinCEWSCustomFloatSpinEdit.CreateHandle(const AWinControl: TWinControl;
@ -168,6 +171,9 @@ begin
Params.SubClassWndProc := @SpinBuddyWindowProc; Params.SubClassWndProc := @SpinBuddyWindowProc;
WindowCreateInitBuddy(AWinControl, Params); WindowCreateInitBuddy(AWinControl, Params);
Params.BuddyWindowInfo^.isChildEdit := true; Params.BuddyWindowInfo^.isChildEdit := true;
// make possible LCL Wincontrol identification by Buddy handle
// TODO: should move to widget specific SetProp method
SetProp(Params.Buddy, 'WinControl', PtrUInt(AWinControl));
Result := Params.Window; Result := Params.Window;
end; end;
@ -218,6 +224,13 @@ begin
Result := GetWindowInfo(ACustomFloatSpinEdit.Handle)^.spinValue; Result := GetWindowInfo(ACustomFloatSpinEdit.Handle)^.spinValue;
end; end;
class procedure TWinCEWSCustomFloatSpinEdit.SetReadOnly(
const ACustomEdit: TCustomEdit; NewReadOnly: boolean);
begin
Windows.SendMessage(GetBuddyWindow(ACustomEdit.Handle), EM_SETREADONLY,
Windows.WPARAM(NewReadOnly), 0);
end;
class procedure TWinCEWSCustomFloatSpinEdit.SetSelStart(const ACustomEdit: TCustomEdit; class procedure TWinCEWSCustomFloatSpinEdit.SetSelStart(const ACustomEdit: TCustomEdit;
NewStart: integer); NewStart: integer);
begin begin
@ -230,6 +243,14 @@ begin
EditSetSelLength(GetBuddyWindow(ACustomEdit.Handle), NewLength); EditSetSelLength(GetBuddyWindow(ACustomEdit.Handle), NewLength);
end; end;
class procedure TWinCEWSCustomFloatSpinEdit.SetText(
const AWinControl: TWinControl; const AText: string);
begin
Windows.SetWindowTextW(
GetBuddyWindow(AWinControl.Handle),
PWideChar(UTF8ToUTF16(AText)));
end;
class procedure TWinCEWSCustomFloatSpinEdit.ShowHide(const AWinControl: TWinControl); class procedure TWinCEWSCustomFloatSpinEdit.ShowHide(const AWinControl: TWinControl);
var var
Buddy: HWND; Buddy: HWND;