From dca336b62780ff3fc7dd061b481b878d8850d79f Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 31 Jan 2011 09:07:31 +0000 Subject: [PATCH] win32: start work on implementation of MainFormOnTaskBar git-svn-id: trunk@29266 - --- lcl/include/customform.inc | 25 +++---- lcl/interfaces/win32/win32callback.inc | 88 ++++++++++++++----------- lcl/interfaces/win32/win32int.pp | 1 + lcl/interfaces/win32/win32object.inc | 27 ++++++-- lcl/interfaces/win32/win32wscontrols.pp | 2 - lcl/interfaces/win32/win32wsforms.pp | 13 ++++ 6 files changed, 100 insertions(+), 56 deletions(-) diff --git a/lcl/include/customform.inc b/lcl/include/customform.inc index 6b78bae2fb..dd6e305603 100644 --- a/lcl/include/customform.inc +++ b/lcl/include/customform.inc @@ -1950,19 +1950,22 @@ begin if (Parent = nil) and (ParentWindow = 0) then begin // define Parent according to PopupMode and PopupParent - if not (csDesigning in ComponentState) and (Application.MainForm <> Self) then + if not (csDesigning in ComponentState) then begin - case PopupMode of - pmNone:; - pmAuto: - if (Screen.ActiveForm <> nil) then - WndParent := Screen.ActiveForm.Handle; - pmExplicit: - if (PopupParent <> nil) then - WndParent := PopupParent.Handle; + if (Application.MainForm <> Self) then + begin + case PopupMode of + pmNone:; + pmAuto: + if (Screen.ActiveForm <> nil) then + WndParent := Screen.ActiveForm.Handle; + pmExplicit: + if (PopupParent <> nil) then + WndParent := PopupParent.Handle; + 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; end; Style := Style and not Cardinal(WS_GROUP or WS_TABSTOP or WS_CHILD); diff --git a/lcl/interfaces/win32/win32callback.inc b/lcl/interfaces/win32/win32callback.inc index a88392bfe8..d6847d624e 100644 --- a/lcl/interfaces/win32/win32callback.inc +++ b/lcl/interfaces/win32/win32callback.inc @@ -784,12 +784,12 @@ var and (Application.MainForm <> ParentForm) and Application.MainForm.HandleAllocated then begin - targetWindow := Application.MainForm.Handle; - if IsWindowEnabled(targetWindow) and IsWindowVisible(targetWindow) then + TargetWindow := Application.MainFormHandle; + if IsWindowEnabled(TargetWindow) and IsWindowVisible(TargetWindow) then begin prevFocus := Windows.GetFocus; Windows.SetFocus(targetWindow); - PLMsg^.Result := Windows.SendMessage(targetWindow, WM_SYSCOMMAND, WParam, LParam); + PLMsg^.Result := Windows.SendMessage(TargetWindow, WM_SYSCOMMAND, WParam, LParam); Windows.SetFocus(prevFocus); WinProcess := False; end; @@ -798,44 +798,56 @@ var SC_MINIMIZE: begin - - 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 + if Assigned(Application) then begin - if (Application.MainForm <> nil) then - begin - Windows.SetWindowPos(Window, HWND_TOP, - Application.MainForm.Left, Application.MainForm.Top, - Application.MainForm.Width, 0, SWP_NOACTIVATE); - if Application.MainForm.HandleAllocated then - Windows.ShowWindow(Application.MainForm.Handle, SW_HIDE); - end; + if Assigned(lWinControl) and (Application.MainForm = lWinControl) and not Application.MainFormOnTaskBar then + Window := Win32WidgetSet.AppHandle;//redirection - PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); - WinProcess := False; - Application.IntfAppMinimize; + if (Window = Win32WidgetSet.AppHandle) and not Application.MainFormOnTaskBar then + begin + if Assigned(Application.MainForm) then + begin + Windows.SetWindowPos(Window, HWND_TOP, + Application.MainForm.Left, Application.MainForm.Top, + Application.MainForm.Width, 0, SWP_NOACTIVATE); + if Application.MainForm.HandleAllocated then + Windows.ShowWindow(Application.MainFormHandle, SW_HIDE); + end; + + PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); + WinProcess := False; + 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; SC_RESTORE: begin - - if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and - (Application <> nil) then + if Assigned(Application) then begin - PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); - WinProcess := False; - if (Application.MainForm <> nil) and Application.MainForm.HandleAllocated then + if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and not Application.MainFormOnTaskBar then begin - if Application.MainForm.HandleObjectShouldBeVisible then - Windows.ShowWindow(Application.MainForm.Handle, SW_SHOWNA); + PLMsg^.Result := Windows.DefWindowProc(Window, WM_SYSCOMMAND, WParam, LParam); + WinProcess := False; + if Assigned(Application.MainForm) and Application.MainForm.HandleAllocated then + begin + if Application.MainForm.HandleObjectShouldBeVisible then + Windows.ShowWindow(Application.MainFormHandle, SW_SHOWNA); + end; + Application.IntfAppRestore; + end + else + if Assigned(lWinControl) and (lWinControl = Application.MainForm) then + begin + Application.IntfAppRestore; end; - Application.IntfAppRestore; end; end; end; @@ -1177,9 +1189,9 @@ begin WM_CLOSE: begin if (Window = TWin32WidgetSet(WidgetSet).AppHandle) and - (Application.MainForm <> nil) then + Assigned(Application.MainForm) then begin - Windows.SendMessage(Application.MainForm.Handle, WM_CLOSE, 0, 0); + Windows.SendMessage(Application.MainFormHandle, WM_CLOSE, 0, 0); end else begin LMessage.Msg := LM_CLOSEQUERY; @@ -2075,15 +2087,15 @@ begin Status := LParam; end; //DebugLn(GetStackTrace(false)); - if assigned(lWinControl) and ((WParam<>0) or not lWinControl.Visible) - and ((WParam=0) or lWinControl.Visible) - and (Application<>nil) and (lWinControl=Application.MainForm) then + if Assigned(lWinControl) and ((WParam <> 0) or not lWinControl.Visible) and + ((WParam = 0) or lWinControl.Visible) and Assigned(Application) and + (lWinControl = Application.MainForm) and not Application.MainFormOnTaskBar then begin if WParam=0 then Flags := SW_HIDE else Flags := SW_SHOWNOACTIVATE; - Windows.ShowWindow(TWin32WidgetSet(WidgetSet).FAppHandle, Flags); + Windows.ShowWindow(TWin32WidgetSet(WidgetSet).AppHandle, Flags); end; end; WM_SYSCHAR: @@ -2306,7 +2318,7 @@ begin if Assigned(Application.MainForm) and Application.MainForm.HandleAllocated then begin lWinControl := Application.MainForm; - Window := Application.MainForm.Handle; + Window := Application.MainFormHandle; end; end; if IsIconic(Window) then diff --git a/lcl/interfaces/win32/win32int.pp b/lcl/interfaces/win32/win32int.pp index 3117b5882d..c06dead94c 100644 --- a/lcl/interfaces/win32/win32int.pp +++ b/lcl/interfaces/win32/win32int.pp @@ -176,6 +176,7 @@ type procedure AppSetVisible(const AVisible: Boolean); override; function AppRemoveStayOnTopFlags(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; diff --git a/lcl/interfaces/win32/win32object.inc b/lcl/interfaces/win32/win32object.inc index e3dbf57b7c..0f5c6a60a0 100644 --- a/lcl/interfaces/win32/win32object.inc +++ b/lcl/interfaces/win32/win32object.inc @@ -176,8 +176,10 @@ end; ------------------------------------------------------------------------------} procedure TWin32WidgetSet.AppMinimize; begin - if FAppHandle <> 0 then - Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_MINIMIZE, 0); + if Assigned(Application) and Application.MainFormOnTaskBar then + Windows.SendMessage(Application.MainFormHandle, WM_SYSCOMMAND, SC_MINIMIZE, 0) + else + Windows.SendMessage(FAppHandle, WM_SYSCOMMAND, SC_MINIMIZE, 0) end; {------------------------------------------------------------------------------ @@ -189,7 +191,9 @@ end; ------------------------------------------------------------------------------} procedure TWin32WidgetSet.AppRestore; 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); end; @@ -203,7 +207,7 @@ end; ------------------------------------------------------------------------------} procedure TWin32WidgetSet.AppBringToFront; begin - if FAppHandle <> 0 then + if (FAppHandle <> 0) and not (Assigned(Application) and Application.MainFormOnTaskBar) then Windows.SetForegroundWindow(FAppHandle); end; @@ -482,7 +486,7 @@ end; procedure TWin32WidgetSet.AppSetVisible(const AVisible: Boolean); begin - if FAppHandle <> 0 then + if (FAppHandle <> 0) and not (Assigned(Application) and Application.MainFormOnTaskBar) then begin if AVisible then Windows.ShowWindow(FAppHandle, SW_SHOW) @@ -505,6 +509,18 @@ begin Result := True; 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; begin Result:= lpWin32; @@ -518,6 +534,7 @@ begin lcDragDockStartOnTitleClick: Result := LCL_CAPABILITY_YES; lcApplicationWindow: Result := LCL_CAPABILITY_YES; lcLMHelpSupport: Result := LCL_CAPABILITY_YES; + lcNeedMininimizeAppWithMainForm: Result := LCL_CAPABILITY_NO; else Result := inherited; end; diff --git a/lcl/interfaces/win32/win32wscontrols.pp b/lcl/interfaces/win32/win32wscontrols.pp index 1127c5ff87..377d2915e6 100644 --- a/lcl/interfaces/win32/win32wscontrols.pp +++ b/lcl/interfaces/win32/win32wscontrols.pp @@ -160,8 +160,6 @@ begin Flags := CreateParams.Style; FlagsEx := CreateParams.ExStyle; Parent := CreateParams.WndParent; - if (Parent = 0) then - Parent := Win32WidgetSet.AppHandle; StrCaption := CreateParams.Caption; Left := CreateParams.X; diff --git a/lcl/interfaces/win32/win32wsforms.pp b/lcl/interfaces/win32/win32wsforms.pp index 326c3ab3b1..dc99766b47 100644 --- a/lcl/interfaces/win32/win32wsforms.pp +++ b/lcl/interfaces/win32/win32wsforms.pp @@ -370,6 +370,19 @@ begin // customization of Params with Params do 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); pClassName := @ClsName[0]; WindowTitle := StrCaption;