wince: port win32 modal forms handling

git-svn-id: trunk@18656 -
This commit is contained in:
paul 2009-02-13 06:44:04 +00:00
parent 6547cc249c
commit d94aea3830
5 changed files with 20 additions and 104 deletions

View File

@ -130,6 +130,7 @@ var
DoubleBufferBitmap: HBITMAP = 0;
DoubleBufferBitmapWidth: integer = 0;
DoubleBufferBitmapHeight: integer = 0;
DisabledForms: TList = nil;
function CheckMouseMovement: boolean;
// returns true if mouse did not move between lmousebutton down
@ -1301,15 +1302,15 @@ begin
end;
WM_ENABLE:
begin
If WParam <> 0 Then
if WParam <> 0 then
LMessage.Msg := LM_SETEDITABLE;
If Window=TWinCEWidgetSet(WidgetSet).FAppHandle then
if WParam=0 then
DisableApplicationWindows(Window)
if Window = TWinCEWidgetSet(WidgetSet).FAppHandle then
if WParam = 0 then
DisabledForms := Screen.DisableForms(nil, DisabledForms)
else
EnableApplicationWindows(Window);
Screen.EnableForms(DisabledForms);
If (lWinControl is TCustomFloatSpinEdit) then
if (lWinControl is TCustomFloatSpinEdit) then
EnableFloatSpinEditBuddy(Window, WParam<>0);
end;
WM_ERASEBKGND:

View File

@ -168,7 +168,7 @@ type
function WinRegister: Boolean;
Public
public
{ Creates a callback of Lazarus message Msg for Sender }
procedure SetCallback(Msg: LongInt; Sender: TObject); virtual;
{ Removes all callbacks for Sender }
@ -180,6 +180,7 @@ type
destructor Destroy; override;
function LCLPlatform: TLCLPlatform; override;
function GetLCLCapability(ACapability: TLCLCapability): PtrUInt; override;
{ Initialize the API }
procedure AppInit(var ScreenInfo: TScreenInfo); override;

View File

@ -443,6 +443,15 @@ begin
Result:= lpWinCE;
end;
function TWinCEWidgetSet.GetLCLCapability(ACapability: TLCLCapability): PtrUInt;
begin
case ACapability of
lcModalWindow: Result := 0;
else
Result := inherited;
end;
end;
{------------------------------------------------------------------------------
function: CreateTimer
Params: Interval:

View File

@ -32,7 +32,6 @@ type
PWinControl: TWinControl; // control to paint for
AWinControl: TWinControl; // control associated with (for buddy controls)
List: TStrings;
DisabledWindowList: TList;// a list of windows that were disabled when showing modal
needParentPaint: boolean; // has a tabpage as parent, and is winxp themed
isTabPage: boolean; // is window of tabpage
isComboEdit: boolean; // is buddy of combobox, the edit control
@ -90,9 +89,6 @@ function GetFileVersion(FileName: string): dword;
function AllocWindowInfo(Window: HWND): PWindowInfo;
function DisposeWindowInfo(Window: HWND): boolean;
function GetWindowInfo(Window: HWND): PWindowInfo;
function DisableWindowsProc(Window: HWND; Data: LParam): LongBool; {$ifdef Win32}stdcall;{$else}cdecl;{$endif}
procedure DisableApplicationWindows(Window: HWND);
procedure EnableApplicationWindows(Window: HWND);
procedure AddToChangedMenus(Window: HWnd);
procedure RedrawMenus;
function MeasureText(const AWinControl: TWinControl; Text: string; var Width, Height: integer): boolean;
@ -106,14 +102,6 @@ function WideStrCmp(W1, W2: PWideChar): Integer;
{ Automatic detection of platform }
function GetWinCEPlatform: TApplicationType;
type
PDisableWindowsInfo = ^TDisableWindowsInfo;
TDisableWindowsInfo = record
NewModalWindow: HWND;
ProcessID: DWORD;
DisabledWindowList: TList;
end;
var
DefaultWindowInfo: TWindowInfo;
OverwriteCheck: Integer = 0;
@ -1232,10 +1220,7 @@ begin
WindowInfo := PWindowInfo(WinCEExtra.GetProp(Window{, PChar(dword(WindowInfoAtom))}));
Result := WinCEExtra.RemoveProp(Window{, PChar(dword(WindowInfoAtom))})<>0;
if Result then
begin
WindowInfo^.DisabledWindowList.Free;
Dispose(WindowInfo);
end;
end;
function GetWindowInfo(Window: HWND): PWindowInfo;
@ -1287,80 +1272,6 @@ begin
'Window = ' + IntToStr(Window) + ' ClassName = ' + WndClassName(Window) + ' Thread id = ' + IntToStr(GetWindowThreadProcessId(Window, nil)));
end;}
{-----------------------------------------------------------------------------
Function: DisableWindowsProc
Params: Window - handle of toplevel windows to be disabled
Data - handle of current window form
Returns: True if the enumeration should continue, False otherwise
Used in LM_SHOWMODAL to disable the windows of application thread
except the current form.
-----------------------------------------------------------------------------}
function DisableWindowsProc(Window: HWND; Data: LParam): LongBool; {$ifdef Win32}stdcall;{$else}cdecl;{$endif}
var
DisableWindowsInfo: PDisableWindowsInfo absolute Data;
begin
Result := True;
// Only disable windows from our application
if DisableWindowsInfo^.ProcessID <> GetWindowThreadProcessId(Window, nil) then
Exit;
// Don't disable the current window form or menu of that form
if (Window = DisableWindowsInfo^.NewModalWindow) then
Exit;
if not IsWindowVisible(Window) or
not IsWindowEnabled(Window) or
IsAlienWindow(Window) then
Exit;
DisableWindowsInfo^.DisabledWindowList.Add(Pointer(Window));
//LogWindow(Window);
EnableWindow(Window, False);
end;
var
InDisableApplicationWindows: boolean = false;
procedure DisableApplicationWindows(Window: HWND);
var
DisableWindowsInfo: PDisableWindowsInfo;
WindowInfo: PWindowInfo;
begin
// prevent recursive calling when the AppHandle window is disabled
if InDisableApplicationWindows then exit;
InDisableApplicationWindows := True;
New(DisableWindowsInfo);
DisableWindowsInfo^.NewModalWindow := Window;
DisableWindowsInfo^.DisabledWindowList := TList.Create;
WindowInfo := GetWindowInfo(DisableWindowsInfo^.NewModalWindow);
WindowInfo^.DisabledWindowList := DisableWindowsInfo^.DisabledWindowList;
// EnumThreadWindows isn't available for WinCE, so we
// improvise with EnumWindows
DisableWindowsInfo^.ProcessID := GetWindowThreadProcessId(DisableWindowsInfo^.NewModalWindow, nil);
EnumWindows(@DisableWindowsProc, LPARAM(DisableWindowsInfo));
Dispose(DisableWindowsInfo);
InDisableApplicationWindows := false;
end;
procedure EnableApplicationWindows(Window: HWND);
var
WindowInfo: PWindowInfo;
I: integer;
begin
WindowInfo := GetWindowInfo(Window);
if WindowInfo^.DisabledWindowList <> nil then
begin
for I := 0 to WindowInfo^.DisabledWindowList.Count - 1 do
EnableWindow(HWND(WindowInfo^.DisabledWindowList.Items[I]), true);
FreeAndNil(WindowInfo^.DisabledWindowList);
end;
end;
function MeasureText(const AWinControl: TWinControl; Text: string; var Width, Height: integer): boolean;
var
textSize: Windows.SIZE;

View File

@ -74,7 +74,6 @@ type
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): HWND; override;
class procedure CloseModal(const ACustomForm: TCustomForm); override;
class procedure SetBounds(const AWinControl: TWinControl;
const ALeft, ATop, AWidth, AHeight: Integer); override;
class procedure SetBorderIcons(const AForm: TCustomForm;
@ -339,11 +338,6 @@ begin
{$endif}
end;
class procedure TWinCEWSCustomForm.CloseModal(const ACustomForm: TCustomForm);
begin
EnableApplicationWindows(ACustomForm.Handle);
end;
class procedure TWinCEWSCustomForm.SetBorderIcons(const AForm: TCustomForm;
const ABorderIcons: TBorderIcons);
begin
@ -370,6 +364,8 @@ begin
SizeRect.Bottom := ATop + AHeight;
SizeRect.Right := ALeft + AWidth;
BorderStyle := TCustomForm(AWinControl).BorderStyle;
{ Verifies if the size should be overriden, acording to the ApplicationType }
if (Application.ApplicationType in [atPDA, atSmartphone, atDefault]) then
begin
@ -392,7 +388,6 @@ begin
{ the LCL defines the size of a form without border, winceapi with.
-> adjust size according to BorderStyle
Must be done after setting sizeRect }
BorderStyle := TCustomForm(AWinControl).BorderStyle;
Windows.AdjustWindowRectEx(@SizeRect, BorderStyleToWinAPIFlags(
BorderStyle), false, BorderStyleToWinAPIFlagsEx(TCustomForm(AWinControl), BorderStyle));
@ -422,7 +417,6 @@ end;
class procedure TWinCEWSCustomForm.ShowModal(const ACustomForm: TCustomForm);
begin
DisableApplicationWindows(ACustomForm.Handle);
ShowWindow(ACustomForm.Handle, SW_SHOW);
BringWindowToTop(ACustomForm.Handle);
end;