Fixes Groupbox child control positioning and TCustomCheckBox descendents autosizing under WinCE.

git-svn-id: trunk@14123 -
This commit is contained in:
sekelsenmat 2008-02-13 17:26:10 +00:00
parent 4c570d42ab
commit fa9e26c441
5 changed files with 62 additions and 43 deletions

View File

@ -864,18 +864,18 @@ begin
end; end;
if (TheWinControl is TCustomGroupBox) then if (TheWinControl is TCustomGroupBox) then
begin begin
// The client area of a groupbox under win32 is the whole size, including // The client area of a groupbox under winapi is the whole size, including
// the frame. The LCL defines the client area without the frame. // the frame. The LCL defines the client area without the frame.
// -> Adjust the position // -> Adjust the position
DC := Windows.GetDC(Handle);
// add the upper frame with the caption // add the upper frame with the caption
DC := Windows.GetDC(Handle);
GetTextMetrics(DC, TM); GetTextMetrics(DC, TM);
ORect.Top := TM.TMHeight; ORect.Top := TM.TMHeight;
// add the left frame border ReleaseDC(Handle, DC);
// add the left, right and bottom frame borders
ORect.Left := 2; ORect.Left := 2;
ORect.Right := -2; ORect.Right := -2;
ORect.Bottom := -2; ORect.Bottom := -2;
ReleaseDC(Handle, DC);
end else end else
if TheWinControl is TCustomNoteBook then if TheWinControl is TCustomNoteBook then
begin begin

View File

@ -409,12 +409,10 @@ Var
end; end;
if ParentPaintWindow <> 0 then if ParentPaintWindow <> 0 then
GetWin32ControlPos(Window, ParentPaintWindow, parLeft, parTop); GetWin32ControlPos(Window, ParentPaintWindow, parLeft, parTop);
if not GetLCLClientBoundsOffset(lWinControl, ORect) then //Is not necessary to check the result of GetLCLClientBoundsOffset since
begin //the false condition (lWincontrol = nil or lWincontrol <> TWinControl) is never met
ORect.Left := 0; //The rect is always initialized with 0
ORect.Top := 0; GetLCLClientBoundsOffset(lWinControl, ORect);
{ we don't use ORect.Right and ORect.Bottom, initialize here if needed }
end;
PaintMsg.Msg := LM_PAINT; PaintMsg.Msg := LM_PAINT;
PaintMsg.PaintStruct := @PS; PaintMsg.PaintStruct := @PS;
if not useDoubleBuffer then if not useDoubleBuffer then
@ -1134,12 +1132,19 @@ begin
} }
WM_CTLCOLORMSGBOX..WM_CTLCOLORSTATIC: WM_CTLCOLORMSGBOX..WM_CTLCOLORSTATIC:
begin begin
// it's needed for winxp themes where controls send the WM_ERASEBKGND { it's needed for winxp themes where controls send the WM_ERASEBKGND
// message to their parent to clear their background and then draw message to their parent to clear their background and then draw
// transparently transparently
// only static and button controls have transparent parts only static and button controls have transparent parts
// others need to erased with their window color others need to erased with their window color
// scrollbar also has buttons scrollbar also has buttons
Handling this message is the method provided to change the background
color of many Windows Standard Controls, like TGroupBox, TCheckBox, etc.
Note that here ChildWinControl represents the control about to be
painted. A RadioButton for example. lWinControl represents the Form.
}
ChildWindowInfo := GetWindowInfo(LParam); ChildWindowInfo := GetWindowInfo(LParam);
ChildWinControl := ChildWindowInfo^.WinControl; ChildWinControl := ChildWindowInfo^.WinControl;
if ChildWinControl = nil then if ChildWinControl = nil then

View File

@ -949,40 +949,51 @@ var
Handle: HWND; Handle: HWND;
TheWinControl: TWinControl; TheWinControl: TWinControl;
ARect: TRect; ARect: TRect;
Ignore: Integer;
Begin Begin
Result:=false; Result:=false;
if (Sender = nil) or (not (Sender is TWinControl)) then exit; if (Sender = nil) or (not (Sender is TWinControl)) then exit;
TheWinControl:=TWinControl(Sender); TheWinControl:=TWinControl(Sender);
if not TheWinControl.HandleAllocated then exit; if not TheWinControl.HandleAllocated then exit;
Handle := TheWinControl.Handle; Handle := TheWinControl.Handle;
ORect.Left := 0; FillChar(ORect, SizeOf(ORect), 0);
ORect.Top := 0;
if TheWinControl is TScrollingWinControl then if TheWinControl is TScrollingWinControl then
with TScrollingWinControl(TheWinControl) do with TScrollingWinControl(TheWinControl) do
begin begin
if HorzScrollBar <> nil then if HorzScrollBar <> nil then
begin
// left and right bounds are shifted by scroll position
ORect.Left := -HorzScrollBar.Position; ORect.Left := -HorzScrollBar.Position;
if VertScrollBar <> nil then ORect.Right := -HorzScrollBar.Position;
ORect.Top := -VertScrollBar.Position;
end; end;
ORect.Bottom := 0; if VertScrollBar <> nil then
ORect.Right := 0; begin
If (TheWinControl is TCustomGroupBox) Then // top and bottom bounds are shifted by scroll position
Begin ORect.Top := -VertScrollBar.Position;
// The client area of a groupbox under win32 is the whole size, including ORect.Bottom := -VertScrollBar.Position;
end;
end;
if (TheWinControl is TCustomGroupBox) then
begin
// The client area of a groupbox under winapi is the whole size, including
// the frame. The LCL defines the client area without the frame. // the frame. The LCL defines the client area without the frame.
// -> Adjust the position // -> Adjust the position
DC := Windows.GetDC(Handle);
// add the upper frame with the caption // add the upper frame with the caption
DC := Windows.GetDC(Handle);
GetTextMetrics(DC, TM); GetTextMetrics(DC, TM);
ORect.Top := TM.TMHeight; ORect.Top := TM.TMHeight;
// add the left frame border
ORect.Left := 1;
ORect.Right := -1;
ORect.Bottom := -1;
ReleaseDC(Handle, DC); ReleaseDC(Handle, DC);
End Else { GetTextMetrics may not be supported on all devices, so we
If TheWinControl is TCustomNoteBook then begin have fallback to GetSystemMetrics if it doesn't work.
Also careful that SM_CYSMCAPTION returns 0 on the emulator }
if ORect.Top = 0 then ORect.Top := GetSystemMetrics(SM_CYCAPTION);
// add the left, right and bottom frame borders
ORect.Left := 2;
ORect.Right := -2;
ORect.Bottom := -2;
end else
if TheWinControl is TCustomNoteBook then
begin
// Can't use complete client rect in win32 interface, top part contains the tabs // Can't use complete client rect in win32 interface, top part contains the tabs
Windows.GetClientRect(Handle, @ARect); Windows.GetClientRect(Handle, @ARect);
ORect := ARect; ORect := ARect;
@ -991,13 +1002,13 @@ Begin
Dec(ORect.Bottom, ARect.Bottom); Dec(ORect.Bottom, ARect.Bottom);
end; end;
{ {
if (Windows.GetWindowLong(Handle, GWL_EXSTYLE) and WS_EX_CLIENTEDGE) <> 0 then if (GetWindowLong(Handle, GWL_EXSTYLE) and WS_EX_CLIENTEDGE) <> 0 then
begin begin
Dec(LeftOffset, Windows.GetSystemMetrics(SM_CXEDGE)); Dec(LeftOffset, Windows.GetSystemMetrics(SM_CXEDGE));
Dec(TopOffset, Windows.GetSystemMetrics(SM_CYEDGE)); Dec(TopOffset, Windows.GetSystemMetrics(SM_CYEDGE));
end; end;
} }
Result:=true; Result := True;
end; end;
function GetLCLClientBoundsOffset(Handle: HWnd; var Rect: TRect): boolean; function GetLCLClientBoundsOffset(Handle: HWnd; var Rect: TRect): boolean;
@ -1281,9 +1292,11 @@ begin
canvasHandle := GetDC(winHandle); canvasHandle := GetDC(winHandle);
oldFontHandle := SelectObject(canvasHandle, Windows.SendMessage(winHandle, WM_GetFont, 0, 0)); oldFontHandle := SelectObject(canvasHandle, Windows.SendMessage(winHandle, WM_GetFont, 0, 0));
DeleteAmpersands(Text); DeleteAmpersands(Text);
tmpText := StringToPWideChar(Text); tmpText := StringToPWideChar(Text);
Result := Windows.GetTextExtentPoint32(canvasHandle, PWideChar(tmpText), Length(Text), @textSize); Result := Windows.GetTextExtentPoint32(canvasHandle, PWideChar(tmpText), Length(Text), @textSize);
FreeMem(tmpText); FreeMem(tmpText);
if Result then if Result then
begin begin
Width := textSize.cx; Width := textSize.cx;

View File

@ -175,9 +175,7 @@ begin
Assert(False, 'Trace:Setting window'); Assert(False, 'Trace:Setting window');
if AWinControl.Parent <> nil then if AWinControl.Parent <> nil then
begin Parent := AWinControl.Parent.Handle
Parent := AWinControl.Parent.Handle;
end
else else
Parent := TWinCEWidgetSet(WidgetSet).AppHandle; Parent := TWinCEWidgetSet(WidgetSet).AppHandle;
@ -198,7 +196,7 @@ begin
if AWinControl.TabStop then if AWinControl.TabStop then
Flags := Flags or WS_TABSTOP; Flags := Flags or WS_TABSTOP;
Assert(False, 'Trace:Setting dimentions'); Assert(False, 'Trace:Setting dimentions');
// LCLBoundsToWin32Bounds(AWinControl, Left, Top, Width, Height);//roozbeh:i dont think we need it yet LCLBoundsToWin32Bounds(AWinControl, Left, Top, Width, Height);
if AWinControl is TCustomControl then if AWinControl is TCustomControl then
if TCustomControl(AWinControl).BorderStyle = bsSingle then if TCustomControl(AWinControl).BorderStyle = bsSingle then
FlagsEx := FlagsEx or WS_EX_CLIENTEDGE; FlagsEx := FlagsEx or WS_EX_CLIENTEDGE;

View File

@ -1164,7 +1164,6 @@ begin
FinishCreateWindow(AWinControl, Params, false); FinishCreateWindow(AWinControl, Params, false);
FreeMem(Params.WindowTitle); FreeMem(Params.WindowTitle);
Result := Params.Window; Result := Params.Window;
end; end;
class procedure TWinCEWSCustomCheckBox.GetPreferredSize(const AWinControl: TWinControl; class procedure TWinCEWSCustomCheckBox.GetPreferredSize(const AWinControl: TWinControl;
@ -1179,6 +1178,14 @@ begin
iconHeight := GetSystemMetrics(SM_CYMENUCHECK); iconHeight := GetSystemMetrics(SM_CYMENUCHECK);
if iconHeight > PreferredHeight then if iconHeight > PreferredHeight then
PreferredHeight := iconHeight; PreferredHeight := iconHeight;
if WithThemeSpace then begin
Inc(PreferredWidth, 6);
Inc(PreferredHeight, 6);
end;
// All TCustomCheckBox descendents were consistently too small
// on autosize, so an extra spacing is added it to fix that
Inc(PreferredWidth, 10);
end; end;
end; end;
@ -1238,9 +1245,6 @@ class function TWinCEWSRadioButton.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND; const AParams: TCreateParams): HWND;
var var
Params: TCreateWindowExParams; Params: TCreateWindowExParams;
hwnd: THandle;
Str: array[0..255] of WideChar;
begin begin
{$ifdef VerboseWinCE} {$ifdef VerboseWinCE}
WriteLn('TWinCEWSRadioButton.CreateHandle'); WriteLn('TWinCEWSRadioButton.CreateHandle');
@ -1252,14 +1256,13 @@ begin
with Params do with Params do
begin begin
pClassName := @ButtonClsName; pClassName := @ButtonClsName;
WindowTitle := StringToPWideChar(AWinControl.Caption); WindowTitle := StrCaption;
// BS_AUTORADIOBUTTON may hang the application, // BS_AUTORADIOBUTTON may hang the application,
// if the radiobuttons are not consecutive controls.//roozbeh:is it so in wince? // if the radiobuttons are not consecutive controls.//roozbeh:is it so in wince?
Flags := Flags or BS_AUTORADIOBUTTON; Flags := Flags or BS_RADIOBUTTON;
end; end;
// create window // create window
FinishCreateWindow(AWinControl, Params, false); FinishCreateWindow(AWinControl, Params, false);
FreeMem(Params.WindowTitle);
Result := Params.Window; Result := Params.Window;
end; end;