lazdialogs patch from Giuliano and also a minor improvement for handle handling in LCL-CustomDrawn-Win32 MessageBox

git-svn-id: trunk@38882 -
This commit is contained in:
sekelsenmat 2012-09-28 08:36:33 +00:00
parent 9a097510c9
commit 3f7d870c4d
2 changed files with 38 additions and 21 deletions

View File

@ -2605,11 +2605,22 @@ end;*)
function TCDWidgetSet.MessageBox(HWnd: HWND; LPText, LPCaption: PChar; UType: Cardinal): Integer; function TCDWidgetSet.MessageBox(HWnd: HWND; LPText, LPCaption: PChar; UType: Cardinal): Integer;
var var
WideLPText, WideLPCaption: widestring; WideLPText, WideLPCaption: widestring;
lWindowInfo: TWindowInfo;
lHandle: HWND;
begin begin
if HWnd = 0 then
begin
lHandle := 0;
end
else
begin
lWindowInfo := TWindowInfo(HWnd);
lHandle := lWindowInfo.NativeHandle;
end;
WideLPText := UTF8ToUTF16(string(LPText)); WideLPText := UTF8ToUTF16(string(LPText));
WideLPCaption := UTF8ToUTF16(string(LPCaption)); WideLPCaption := UTF8ToUTF16(string(LPCaption));
Result := Windows.MessageBoxW(HWnd, PWideChar(WideLPText), Result := Windows.MessageBoxW(lHandle, PWideChar(WideLPText),
PWideChar(WideLPCaption), UType); PWideChar(WideLPCaption), UType);
end; end;

View File

@ -75,18 +75,17 @@ type
TLazMessageDialog = class(TForm) TLazMessageDialog = class(TForm)
private private
Image1: TImage; Image1: TImage;
Label1: TStaticText; Label1: TLabel; // we need a TLabel to be able to resize it properly
btnList: array [0..11] of TBitBtn; btnList: array [0..11] of TBitBtn;
NumButtons: Integer; NumButtons: Integer;
public public
constructor CreateNew(TheOwner: TComponent; Num: Integer = 0); override; constructor CreateNew(TheOwner: TComponent; Num: Integer = 0); override;
end; end;
function LazMessageDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType; function LazMessageDlg(const aCaption, aMsg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer; Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
function LazMessageDlg(const aMsg: string; DlgType: TMsgDlgType; function LazMessageDlg(const aMsg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer; Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
implementation implementation
@ -335,7 +334,7 @@ Var
textWidth: Integer; textWidth: Integer;
ButtonPos: Integer; ButtonPos: Integer;
RequiredWidth: Integer; RequiredWidth: Integer;
BlankRight: Integer; // blank space at the right of last button
begin begin
{$ifdef LCLCustomdrawn} if not assigned(LazMessageDialog) then {$endif} {$ifdef LCLCustomdrawn} if not assigned(LazMessageDialog) then {$endif}
LazMessageDialog:= TLazMessageDialog.CreateNew(Application); LazMessageDialog:= TLazMessageDialog.CreateNew(Application);
@ -454,27 +453,34 @@ begin
for I:= 0 to NumButtons -1 do begin for I:= 0 to NumButtons -1 do begin
btnList[I].Constraints.MinHeight:= 25; btnList[I].Constraints.MinHeight:= 25;
btnList[I].Constraints.MinWidth:= 75; btnList[I].Constraints.MinWidth:= 75;
//btnList[I].DefaultCaption:= True;
//btnList[I].AutoSize:= True;
btnList[I].Left:= ButtonPos; btnList[I].Left:= ButtonPos;
btnList[I].Top:= Image1.Top + Image1.Height + 10; btnList[I].Top:= Image1.Top + Image1.Height + 10;
// next line is required until Autosize is implemented {next line is required because even if Auyosize is true,
{btnList[I].Width:= label1.Canvas.TextExtent(btnList[I].Caption).cx width property is changed only when the button is
+ btnList[I].Glyph.Width + 16;} painted. Either we wait (but Application.ProcessMessages is not enough)
btnList[I].AutoSize := True; or we force the actual width. We may safely use form canvas, because our
components inherit the font from the form (ParentFont = true by default)}
btnList[I].Width:= LazMessageDialog.Canvas.TextExtent(btnList[I].Caption).cx
+ btnList[I].Glyph.Width + 20;
btnList[I].Visible:= True; btnList[I].Visible:= True;
//Application.ProcessMessages; currently not required. It may become
//necessary if Autosize is set, and width computed automagically. Maybe
//outside the loop (run just once)
ButtonPos:= ButtonPos + btnList[I].Width + 8; ButtonPos:= ButtonPos + btnList[I].Width + 8;
end; end;
//textWidth:= label1.Canvas.TextExtent(Label1.Caption).cx;
//Label1.Width:= textWidth; { See comment above for width property. Static Text apparently doesn't behave
label1.AutoSize := True; properly when Text is changed at run time. The width is set as appropriate, but
the text is written only up to the previous width. Therefore we must use a TLabel}
textWidth:= LazMessageDialog.Canvas.TextExtent(Label1.Caption).cx;
Label1.Width:= textWidth;
textWidth:= label1.Left + label1.Width; textWidth:= label1.Left + label1.Width;
RequiredWidth:= Max(textWidth,ButtonPos); RequiredWidth:= Max(textWidth,ButtonPos);
Width := RequiredWidth + 10; Width := RequiredWidth + 10;
Height:= btnList[0].Top + btnList[0].Height + 10; Height:= btnList[0].Top + btnList[0].Height + 10;
// now let's move our buttons to the right side of dialog, if appropriate
BlankRight:= Width - ButtonPos;
if BlankRight > 10 then
for I:= 0 to NumButtons-1 do btnList[I].Left:= btnList[I].Left+BlankRight ;
end; end;
result := LazMessageDialog.ShowModal; result := LazMessageDialog.ShowModal;
{$ifndef LCLCustomdrawn}LazMessageDialog.Release;{$endif} {$ifndef LCLCustomdrawn}LazMessageDialog.Release;{$endif}
@ -498,7 +504,7 @@ begin
Image1.Left:= 10; Image1.Left:= 10;
Image1.Width:= 48; Image1.Width:= 48;
Image1.Height:= 48; Image1.Height:= 48;
Label1 := TStaticText.Create(Self); Label1 := TLabel.Create(Self);
Label1.Top:= Image1.Top; Label1.Top:= Image1.Top;
Label1.Left:= Image1.Left + Image1.Width + 10; Label1.Left:= Image1.Left + Image1.Width + 10;
Label1.Caption:= 'Label1'; Label1.Caption:= 'Label1';