diff --git a/lcl/include/customform.inc b/lcl/include/customform.inc index 73642b60fb..8ee0bc0073 100644 --- a/lcl/include/customform.inc +++ b/lcl/include/customform.inc @@ -1267,17 +1267,17 @@ Procedure TCustomForm.SetFormStyle(Value : TFormStyle); var OldFormStyle: TFormStyle; Begin - if FFormStyle = Value then exit; - if (Value in [fsMDIChild, fsMDIForm]) then - raise Exception.Create('TCustomForm.SetFormStyle MDI forms are not implemented yet'); - OldFormStyle:=FFormStyle; + if FFormStyle = Value then + exit; + OldFormStyle := FFormStyle; FFormStyle := Value; - Include(FFormState,fsFormStyleChanged); - if FFormStyle=fsSplash then begin - BorderStyle:=bsNone; - end else if OldFormStyle=fsSplash then begin - BorderStyle:=bsSizeable; - end; + Include(FFormState, fsFormStyleChanged); + + if FFormStyle = fsSplash then + BorderStyle := bsNone + else + if OldFormStyle = fsSplash then + BorderStyle := bsSizeable; end; {------------------------------------------------------------------------------ diff --git a/lcl/include/wincontrol.inc b/lcl/include/wincontrol.inc index 73652c80f4..468b2bcddd 100644 --- a/lcl/include/wincontrol.inc +++ b/lcl/include/wincontrol.inc @@ -5490,7 +5490,8 @@ end; ------------------------------------------------------------------------------} procedure TWinControl.DestroyWnd; begin - if HandleAllocated then begin + if HandleAllocated then + begin FinalizeWnd; TWSWinControlClass(WidgetSetClass).DestroyHandle(Self); Handle := 0; diff --git a/lcl/interfaces/qt/qtwidgets.pas b/lcl/interfaces/qt/qtwidgets.pas index 463de9ef7c..8c568bb91f 100644 --- a/lcl/interfaces/qt/qtwidgets.pas +++ b/lcl/interfaces/qt/qtwidgets.pas @@ -91,6 +91,7 @@ type procedure WindowTitle(Str: PWideString); procedure Hide; procedure Show; + function getVisible: boolean; procedure setEnabled(p1: Boolean); procedure setVisible(visible: Boolean); function windowModality: QtWindowModality; @@ -158,6 +159,7 @@ type protected function CreateWidget(const AParams: TCreateParams):QWidgetH; override; public + LayoutWidget: QBoxLayoutH; {$ifdef USE_QT_4_3} MDIAreaHandle: QMDIAreaH; {$endif} @@ -167,10 +169,11 @@ type ToolBar: TQtToolBar; Canvas: TQtDeviceContext; destructor Destroy; override; - function GetContainerWidget: QWidgetH; override; + function GetContainerWidget: QWidgetH; override; procedure setTabOrders; function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override; procedure SlotWindowStateChange; cdecl; + procedure setShowInTaskBar(AValue: Boolean); end; { TQtStaticText } @@ -510,7 +513,9 @@ type constructor Create(const AHandle: QMenuH); overload; destructor Destroy; override; public + procedure SlotDestroy; cdecl; procedure SlotTriggered(checked: Boolean = False); cdecl; + function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override; public procedure PopUp(pos: PQtPoint; at: QActionH = nil); function actionHandle: QActionH; @@ -528,6 +533,7 @@ type TQtMenuBar = class(TQtWidget) private + FVisible: Boolean; public constructor Create(const AParent: QWidgetH); overload; destructor Destroy; override; @@ -1360,6 +1366,11 @@ begin QWidget_show(Widget); end; +function TQtWidget.getVisible: boolean; +begin + Result := QWidget_isVisible(Widget); +end; + procedure TQtWidget.setEnabled(p1: Boolean); begin QWidget_setEnabled(Widget, p1); @@ -2000,7 +2011,7 @@ begin {$endif} w := QApplication_activeWindow; - + if not Assigned(w) and not ((Application.MainForm <> nil) and (Application.MainForm.Visible)) then begin Result := QMainWindow_create(nil, QtWindow); @@ -2020,15 +2031,20 @@ begin ------------------------------------------------------------------------------} if Assigned(Application.MainForm) and Assigned(Application.MainForm.Menu) then - QMainWindow_setMenuBar(QMainWindowH(Result), QMenuBarH(MenuBar.Widget)); + QMainWindow_setMenuBar(QMainWindowH(Result), QMenuBarH(MenuBar.Widget)); {$ifdef USE_QT_4_3} - MDIAreaHandle := QMdiArea_create(Result); - - CentralWidget := MDIAreaHandle; - - QMainWindow_setCentralWidget(QMainWindowH(Result), MDIAreaHandle); - + if (Application.MainForm <> nil) and (Application.MainForm.FormStyle = fsMDIForm) then + begin + MDIAreaHandle := QMdiArea_create(Result); + CentralWidget := MDIAreaHandle; + end + else + begin + CentralWidget := QWidget_create(Result); + MDIAreaHandle := nil + end; + QMainWindow_setCentralWidget(QMainWindowH(Result), CentralWidget); QMainWindow_setDockOptions(QMainWindowH(Result), QMainWindowAnimatedDocks); {$else} CentralWidget := QWidget_create(Result); @@ -2039,13 +2055,13 @@ begin else begin {$ifdef USE_QT_4_3} - if LCLObject.Tag = 9999 then + if (LCLObject is TCustomForm) and (TCustomForm(LCLObject).FormStyle = fsMDIChild) then begin - Result := QMdiSubWindow_create(NiL, QtWindow); + Result := QMdiSubWindow_create(niL, QtWindow); mdiHandle := TQtMainWindow(Application.MainForm.Handle).MDIAreaHandle; if Assigned(mdiHandle) then - QMdiArea_addSubWindow(mdiHandle, QMdiSubWindowH(Result), QtWindow); + QMdiArea_addSubWindow(mdiHandle, QMdiSubWindowH(Result), QtWindow); end else Result := QWidget_create(nil, QtWindow); @@ -2055,6 +2071,14 @@ begin // Main menu bar MenuBar := TQtMenuBar.Create(Result); + CentralWidget := QWidget_create(Result); + + LayoutWidget := QBoxLayout_create(QBoxLayoutTopToBottom, Result); + QBoxLayout_setSpacing(LayoutWidget, 0); + QLayout_setContentsMargins(LayoutWidget, 0, 0, 0, 0); + QLayout_setMenuBar(LayoutWidget, MenuBar.Widget); + QLayout_addWidget(LayoutWidget, CentralWidget); + QWidget_setLayout(Result, QLayoutH(LayoutWidget)); end; end; @@ -2094,11 +2118,15 @@ end; function TQtMainWindow.GetContainerWidget: QWidgetH; begin {$ifdef USE_QT_4_3} - if (CentralWidget <> nil) and (MDIAreaHandle = NiL) then Result := CentralWidget - else Result := Widget; + if (CentralWidget <> nil) then + Result := CentralWidget + else + Result := Widget; {$else} - if CentralWidget <> nil then Result := CentralWidget - else Result := Widget; + if CentralWidget <> nil then + Result := CentralWidget + else + Result := Widget; {$endif} end; @@ -2201,6 +2229,34 @@ begin end; end; +procedure TQtMainWindow.setShowInTaskBar(AValue: Boolean); +var + w: QWidgetH; + Flags: QtWindowFlags; + Visible: Boolean; +begin + if not AValue then + begin + w := TQtMainWindow(Application.MainForm.Handle).Widget; + if w <> Widget then + begin + Visible := getVisible; + Flags := windowFlags; + setParent(w); + setWindowFlags(Flags); + setVisible(Visible); + end; + end + else + begin + Visible := getVisible; + Flags := windowFlags; + setParent(nil); + setWindowFlags(Flags); + setVisible(Visible); + end; +end; + { TQtStaticText } function TQtStaticText.CreateWidget(const AParams: TCreateParams): QWidgetH; @@ -4083,6 +4139,11 @@ begin inherited Destroy; end; +procedure TQtMenu.SlotDestroy; cdecl; +begin + Widget := nil; +end; + procedure TQtMenu.PopUp(pos: PQtPoint; at: QActionH); begin QMenu_Popup(QMenuH(Widget), pos, at); @@ -4162,11 +4223,22 @@ begin MenuItem.OnClick(Self.MenuItem); end; +function TQtMenu.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; +begin + Result := False; + + case QEvent_type(Event) of + QEventDestroy: SlotDestroy; + end; +end; + { TQtMenuBar } constructor TQtMenuBar.Create(const AParent: QWidgetH); begin Widget := QMenuBar_create(AParent); + FVisible := False; + setVisible(FVisible); end; destructor TQtMenuBar.Destroy; @@ -4176,11 +4248,21 @@ end; function TQtMenuBar.addMenu(title: PWideString): TQtMenu; begin + if not FVisible then + begin + FVisible := True; + setVisible(FVisible); + end; Result := TQtMenu.Create(QMenuBar_addMenu(QMenuBarH(Widget), title)); end; function TQtMenuBar.addSeparator: TQtMenu; begin + if not FVisible then + begin + FVisible := True; + setVisible(FVisible); + end; Result := TQtMenu.Create(QMenuBar_addMenu(QMenuBarH(Widget), nil)); Result.setSeparator(True); end; @@ -4701,3 +4783,4 @@ end; end. + diff --git a/lcl/interfaces/qt/qtwsforms.pp b/lcl/interfaces/qt/qtwsforms.pp index 359e46fea1..4c910b1d31 100644 --- a/lcl/interfaces/qt/qtwsforms.pp +++ b/lcl/interfaces/qt/qtwsforms.pp @@ -156,18 +156,23 @@ begin QtMainWindow := TQtMainWindow.Create(AWinControl, AParams); - // Setīs initial properties + if (TCustomForm(AWinControl).ShowInTaskBar in [stDefault, stNever]) and + (Application <> nil) and + (Application.MainForm <> nil) and + (Application.MainForm.HandleAllocated) and + (Application.MainForm <> AWinControl) then + QtMainWindow.setShowInTaskBar(False); + // Setīs initial properties Str := UTF8Decode(AWinControl.Caption); QtMainWindow.SetWindowTitle(@Str); - SetQtWindowBorderStyle(QtMainWindow, TCustomForm(AWinControl).BorderStyle); + SetQtWindowBorderStyle(QtMainWindow, TCustomForm(AWinControl).BorderStyle); SetQtBorderIcons(QtMainWindow, TCustomForm(AWinControl).BorderIcons); - // Sets Various Events Hook := QObject_hook_create(QtMainWindow.Widget); @@ -268,8 +273,18 @@ end; Returns: Nothing ------------------------------------------------------------------------------} class procedure TQtWSCustomForm.SetShowInTaskbar(const AForm: TCustomForm; const AValue: TShowInTaskbar); +var + Enable: Boolean; begin - inherited SetShowInTaskbar(AForm, AValue); + if (AForm.Parent<>nil) or not (AForm.HandleAllocated) then exit; + + Enable := AValue <> stNever; + if (AValue = stDefault) and + (Application<>nil) and + (Application.MainForm <> nil) and + (Application.MainForm <> AForm) then + Enable := false; + TQtMainWindow(AForm.Handle).setShowInTaskBar(Enable); end; {------------------------------------------------------------------------------ @@ -340,7 +355,7 @@ begin case AFormBorderStyle of bsNone: begin - Flags := Flags or QtFramelessWindowHint; + Flags := (Flags or QtFramelessWindowHint) and not QtWindowTitleHint; Flags := Flags and not QtOnlyDialog; end; bsSingle: @@ -388,6 +403,7 @@ class procedure TQtWSCustomForm.SetQtBorderIcons(const AHandle: TQtMainWindow; const ABorderIcons: TBorderIcons); var Flags: QtWindowFlags; + ShowAny: Boolean; begin Flags := AHandle.windowFlags; @@ -395,17 +411,28 @@ begin WriteLn('Trace:> [TQtWSCustomForm.SetBorderIcons] Flags: ', IntToHex(Flags, 8)); {$endif} - if biSystemMenu in ABorderIcons then Flags := Flags or QtWindowSystemMenuHint - else Flags := Flags and not QtWindowSystemMenuHint; + ShowAny := ((Flags and QtFramelessWindowHint) = 0) or + ((Flags and QtWindowTitleHint) <> 0); - if biMinimize in ABorderIcons then Flags := Flags or QtWindowMinimizeButtonHint - else Flags := Flags and not QtWindowMinimizeButtonHint; + if (biSystemMenu in ABorderIcons) and ShowAny then + Flags := Flags or QtWindowSystemMenuHint + else + Flags := Flags and not QtWindowSystemMenuHint; - if biMaximize in ABorderIcons then Flags := Flags or QtWindowMaximizeButtonHint - else Flags := Flags and not QtWindowMaximizeButtonHint; + if (biMinimize in ABorderIcons) and ShowAny then + Flags := Flags or QtWindowMinimizeButtonHint + else + Flags := Flags and not QtWindowMinimizeButtonHint; - if biHelp in ABorderIcons then Flags := Flags or QtWindowContextHelpButtonHint - else Flags := Flags and not QtWindowContextHelpButtonHint; + if (biMaximize in ABorderIcons) and ShowAny then + Flags := Flags or QtWindowMaximizeButtonHint + else + Flags := Flags and not QtWindowMaximizeButtonHint; + + if (biHelp in ABorderIcons) and ShowAny then + Flags := Flags or QtWindowContextHelpButtonHint + else + Flags := Flags and not QtWindowContextHelpButtonHint; {$ifdef VerboseQt} WriteLn('Trace:< [TQtWSCustomForm.SetBorderIcons] Flags: ', IntToHex(Flags, 8)); diff --git a/lcl/interfaces/qt/qtwsmenus.pp b/lcl/interfaces/qt/qtwsmenus.pp index 71b057d6e0..57840f510e 100644 --- a/lcl/interfaces/qt/qtwsmenus.pp +++ b/lcl/interfaces/qt/qtwsmenus.pp @@ -114,6 +114,7 @@ var MenuBar: TQtMenuBar; Text: WideString; Method: TMethod; + Hook: QObject_hookH; begin {$ifdef VerboseQt} WriteLn('trace:> [TQtWSMenuItem.CreateHandle] Caption: ', AMenuItem.Caption, @@ -121,6 +122,8 @@ begin Write('trace:< [TQtWSMenuItem.CreateHandle]'); {$endif} + + Menu := nil; {------------------------------------------------------------------------------ This case should not happen. A menu item must have a parent, but it seams LCL @@ -224,8 +227,14 @@ begin // Trigger event QAction_triggered_Event(Method) := Menu.SlotTriggered; - + QAction_hook_hook_triggered(QAction_hook_create(Menu.ActionHandle), Method); + + Hook := QObject_hook_create(Menu.Widget); + + TEventFilterMethod(Method) := Menu.EventFilter; + + QObject_hook_hook_events(Hook, Method); end; {$ifdef VerboseQt}