win32: start work on implementation of MainFormOnTaskBar

git-svn-id: trunk@29266 -
This commit is contained in:
paul 2011-01-31 09:07:31 +00:00
parent caf018bbb4
commit dca336b627
6 changed files with 100 additions and 56 deletions

View File

@ -1950,7 +1950,9 @@ begin
if (Parent = nil) and (ParentWindow = 0) then if (Parent = nil) and (ParentWindow = 0) then
begin begin
// define Parent according to PopupMode and PopupParent // define Parent according to PopupMode and PopupParent
if not (csDesigning in ComponentState) and (Application.MainForm <> Self) then if not (csDesigning in ComponentState) then
begin
if (Application.MainForm <> Self) then
begin begin
case PopupMode of case PopupMode of
pmNone:; pmNone:;
@ -1961,8 +1963,9 @@ begin
if (PopupParent <> nil) then if (PopupParent <> nil) then
WndParent := PopupParent.Handle; WndParent := PopupParent.Handle;
end; end;
end;
if (WndParent = 0) and (GetEffectiveShowInTaskBar = stAlways) then if (WndParent = 0) and
(((Self = Application.MainForm) and Application.MainFormOnTaskBar) or (GetEffectiveShowInTaskBar = stAlways)) then
ExStyle := ExStyle or WS_EX_APPWINDOW; ExStyle := ExStyle or WS_EX_APPWINDOW;
end; end;
Style := Style and not Cardinal(WS_GROUP or WS_TABSTOP or WS_CHILD); Style := Style and not Cardinal(WS_GROUP or WS_TABSTOP or WS_CHILD);

View File

@ -784,12 +784,12 @@ var
and (Application.MainForm <> ParentForm) and (Application.MainForm <> ParentForm)
and Application.MainForm.HandleAllocated then and Application.MainForm.HandleAllocated then
begin begin
targetWindow := Application.MainForm.Handle; TargetWindow := Application.MainFormHandle;
if IsWindowEnabled(targetWindow) and IsWindowVisible(targetWindow) then if IsWindowEnabled(TargetWindow) and IsWindowVisible(TargetWindow) then
begin begin
prevFocus := Windows.GetFocus; prevFocus := Windows.GetFocus;
Windows.SetFocus(targetWindow); Windows.SetFocus(targetWindow);
PLMsg^.Result := Windows.SendMessage(targetWindow, WM_SYSCOMMAND, WParam, LParam); PLMsg^.Result := Windows.SendMessage(TargetWindow, WM_SYSCOMMAND, WParam, LParam);
Windows.SetFocus(prevFocus); Windows.SetFocus(prevFocus);
WinProcess := False; WinProcess := False;
end; end;
@ -798,44 +798,56 @@ var
SC_MINIMIZE: SC_MINIMIZE:
begin begin
if Assigned(Application) then
if (Application <> nil) and (lWinControl <> nil) and
(Application.MainForm <> nil) and
(Application.MainForm = lWinControl) then
Window := TWin32WidgetSet(WidgetSet).AppHandle;//redirection
if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and
(Application <> nil) then
begin begin
if (Application.MainForm <> nil) then if Assigned(lWinControl) and (Application.MainForm = lWinControl) and not Application.MainFormOnTaskBar then
Window := Win32WidgetSet.AppHandle;//redirection
if (Window = Win32WidgetSet.AppHandle) and not Application.MainFormOnTaskBar then
begin
if Assigned(Application.MainForm) then
begin begin
Windows.SetWindowPos(Window, HWND_TOP, Windows.SetWindowPos(Window, HWND_TOP,
Application.MainForm.Left, Application.MainForm.Top, Application.MainForm.Left, Application.MainForm.Top,
Application.MainForm.Width, 0, SWP_NOACTIVATE); Application.MainForm.Width, 0, SWP_NOACTIVATE);
if Application.MainForm.HandleAllocated then if Application.MainForm.HandleAllocated then
Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); Windows.ShowWindow(Application.MainFormHandle, SW_HIDE);
end; end;
PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam);
WinProcess := False; WinProcess := False;
Application.IntfAppMinimize; Application.IntfAppMinimize;
end
else
if Assigned(lWinControl) and (lWinControl = Application.MainForm) then
begin
PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam);
WinProcess := False;
Application.IntfAppMinimize;
end;
end; end;
end; end;
SC_RESTORE: SC_RESTORE:
begin begin
if Assigned(Application) then
if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and begin
(Application <> nil) then if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and not Application.MainFormOnTaskBar then
begin begin
PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam);
WinProcess := False; WinProcess := False;
if (Application.MainForm <> nil) and Application.MainForm.HandleAllocated then if Assigned(Application.MainForm) and Application.MainForm.HandleAllocated then
begin begin
if Application.MainForm.HandleObjectShouldBeVisible then if Application.MainForm.HandleObjectShouldBeVisible then
Windows.ShowWindow(Application.MainForm.Handle, SW_SHOWNA); Windows.ShowWindow(Application.MainFormHandle, SW_SHOWNA);
end; end;
Application.IntfAppRestore; Application.IntfAppRestore;
end
else
if Assigned(lWinControl) and (lWinControl = Application.MainForm) then
begin
Application.IntfAppRestore;
end;
end; end;
end; end;
end; end;
@ -1177,9 +1189,9 @@ begin
WM_CLOSE: WM_CLOSE:
begin begin
if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and
(Application.MainForm <> nil) then Assigned(Application.MainForm) then
begin begin
Windows.SendMessage(Application.MainForm.Handle, WM_CLOSE, 0, 0); Windows.SendMessage(Application.MainFormHandle, WM_CLOSE, 0, 0);
end end
else begin else begin
LMessage.Msg := LM_CLOSEQUERY; LMessage.Msg := LM_CLOSEQUERY;
@ -2075,15 +2087,15 @@ begin
Status := LParam; Status := LParam;
end; end;
//DebugLn(GetStackTrace(false)); //DebugLn(GetStackTrace(false));
if assigned(lWinControl) and ((WParam<>0) or not lWinControl.Visible) if Assigned(lWinControl) and ((WParam <> 0) or not lWinControl.Visible) and
and ((WParam=0) or lWinControl.Visible) ((WParam = 0) or lWinControl.Visible) and Assigned(Application) and
and (Application<>nil) and (lWinControl=Application.MainForm) then (lWinControl = Application.MainForm) and not Application.MainFormOnTaskBar then
begin begin
if WParam=0 then if WParam=0 then
Flags := SW_HIDE Flags := SW_HIDE
else else
Flags := SW_SHOWNOACTIVATE; Flags := SW_SHOWNOACTIVATE;
Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, Flags); Windows.ShowWindow(TWin32WidgetSet(WidgetSet).AppHandle, Flags);
end; end;
end; end;
WM_SYSCHAR: WM_SYSCHAR:
@ -2306,7 +2318,7 @@ begin
if Assigned(Application.MainForm) and Application.MainForm.HandleAllocated then if Assigned(Application.MainForm) and Application.MainForm.HandleAllocated then
begin begin
lWinControl := Application.MainForm; lWinControl := Application.MainForm;
Window := Application.MainForm.Handle; Window := Application.MainFormHandle;
end; end;
end; end;
if IsIconic(Window) then if IsIconic(Window) then

View File

@ -176,6 +176,7 @@ type
procedure AppSetVisible(const AVisible: Boolean); override; procedure AppSetVisible(const AVisible: Boolean); override;
function AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; override; function AppRemoveStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; override;
function AppRestoreStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; override; function AppRestoreStayOnTopFlags(const ASystemTopAlso: Boolean = False): Boolean; override;
procedure AppSetMainFormOnTaskBar(const DoSet: Boolean); override;
function InitStockFont(AFont: TObject; AStockFont: TStockFont): Boolean; override; function InitStockFont(AFont: TObject; AStockFont: TStockFont): Boolean; override;

View File

@ -176,8 +176,10 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TWin32WidgetSet.AppMinimize; procedure TWin32WidgetSet.AppMinimize;
begin begin
if FAppHandle <> 0 then if Assigned(Application) and Application.MainFormOnTaskBar then
Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_MINIMIZE, 0); Windows.SendMessage(Application.MainFormHandle, WM_SYSCOMMAND, SC_MINIMIZE, 0)
else
Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_MINIMIZE, 0)
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -189,7 +191,9 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TWin32WidgetSet.AppRestore; procedure TWin32WidgetSet.AppRestore;
begin begin
if FAppHandle <> 0 then if Assigned(Application) and Application.MainFormOnTaskBar then
Windows.SendMessage(Application.MainFormHandle, WM_SYSCOMMAND, SC_RESTORE, 0)
else
Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0); Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_RESTORE, 0);
end; end;
@ -203,7 +207,7 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TWin32WidgetSet.AppBringToFront; procedure TWin32WidgetSet.AppBringToFront;
begin begin
if FAppHandle <> 0 then if (FAppHandle <> 0) and not (Assigned(Application) and Application.MainFormOnTaskBar) then
Windows.SetForegroundWindow(FAppHandle); Windows.SetForegroundWindow(FAppHandle);
end; end;
@ -482,7 +486,7 @@ end;
procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean);
begin begin
if FAppHandle <> 0 then if (FAppHandle <> 0) and not (Assigned(Application) and Application.MainFormOnTaskBar) then
begin begin
if AVisible then if AVisible then
Windows.ShowWindow(FAppHandle, SW_SHOW) Windows.ShowWindow(FAppHandle, SW_SHOW)
@ -505,6 +509,18 @@ begin
Result := True; Result := True;
end; end;
procedure TWin32WidgetSet.AppSetMainFormOnTaskBar(const DoSet: Boolean);
begin
// 1. Update the visibility of the TaskBar window
if DoSet then
ShowWindow(AppHandle, SW_HIDE)
else
ShowWindow(AppHandle, SW_SHOW);
// 2. Recreate the main form - so it will (not) have an own taskbar item and WndParent = 0 (AppHandle)
if Assigned(Application.MainForm) and Application.MainForm.HandleAllocated then
RecreateWnd(Application.MainForm);
end;
function TWin32WidgetSet.LCLPlatform: TLCLPlatform; function TWin32WidgetSet.LCLPlatform: TLCLPlatform;
begin begin
Result:= lpWin32; Result:= lpWin32;
@ -518,6 +534,7 @@ begin
lcDragDockStartOnTitleClick: Result := LCL_CAPABILITY_YES; lcDragDockStartOnTitleClick: Result := LCL_CAPABILITY_YES;
lcApplicationWindow: Result := LCL_CAPABILITY_YES; lcApplicationWindow: Result := LCL_CAPABILITY_YES;
lcLMHelpSupport: Result := LCL_CAPABILITY_YES; lcLMHelpSupport: Result := LCL_CAPABILITY_YES;
lcNeedMininimizeAppWithMainForm: Result := LCL_CAPABILITY_NO;
else else
Result := inherited; Result := inherited;
end; end;

View File

@ -160,8 +160,6 @@ begin
Flags := CreateParams.Style; Flags := CreateParams.Style;
FlagsEx := CreateParams.ExStyle; FlagsEx := CreateParams.ExStyle;
Parent := CreateParams.WndParent; Parent := CreateParams.WndParent;
if (Parent = 0) then
Parent := Win32WidgetSet.AppHandle;
StrCaption := CreateParams.Caption; StrCaption := CreateParams.Caption;
Left := CreateParams.X; Left := CreateParams.X;

View File

@ -370,6 +370,19 @@ begin
// customization of Params // customization of Params
with Params do with Params do
begin begin
if (Parent = 0) then
begin
if not Application.MainFormOnTaskBar then
Parent := Win32WidgetSet.AppHandle
else
if (AWinControl <> Application.MainForm) then
begin
if Assigned(Application.MainForm) and Application.MainForm.HandleAllocated then
Parent := Application.MainFormHandle
else
Parent := Win32WidgetSet.AppHandle;
end;
end;
CalcFormWindowFlags(lForm, Flags, FlagsEx); CalcFormWindowFlags(lForm, Flags, FlagsEx);
pClassName := @ClsName[0]; pClassName := @ClsName[0];
WindowTitle := StrCaption; WindowTitle := StrCaption;