- fix destroying of PopupMenu
- implemented setShowInTaskBar
- better handling of BorderStyle = bsNone
- hide menuBar if there is no MainMenu
- allow creating of MDIForm and MDIChild form (qt has implementation)
- fix problem with overlaying menubar by other widgets

git-svn-id: trunk@11452 -
This commit is contained in:
paul 2007-07-10 03:01:25 +00:00
parent bada39fac6
commit 212f9b4855
5 changed files with 161 additions and 41 deletions

View File

@ -1267,17 +1267,17 @@ Procedure TCustomForm.SetFormStyle(Value : TFormStyle);
var var
OldFormStyle: TFormStyle; OldFormStyle: TFormStyle;
Begin Begin
if FFormStyle = Value then exit; if FFormStyle = Value then
if (Value in [fsMDIChild, fsMDIForm]) then exit;
raise Exception.Create('TCustomForm.SetFormStyle MDI forms are not implemented yet'); OldFormStyle := FFormStyle;
OldFormStyle:=FFormStyle;
FFormStyle := Value; FFormStyle := Value;
Include(FFormState,fsFormStyleChanged); Include(FFormState, fsFormStyleChanged);
if FFormStyle=fsSplash then begin
BorderStyle:=bsNone; if FFormStyle = fsSplash then
end else if OldFormStyle=fsSplash then begin BorderStyle := bsNone
BorderStyle:=bsSizeable; else
end; if OldFormStyle = fsSplash then
BorderStyle := bsSizeable;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------

View File

@ -5490,7 +5490,8 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TWinControl.DestroyWnd; procedure TWinControl.DestroyWnd;
begin begin
if HandleAllocated then begin if HandleAllocated then
begin
FinalizeWnd; FinalizeWnd;
TWSWinControlClass(WidgetSetClass).DestroyHandle(Self); TWSWinControlClass(WidgetSetClass).DestroyHandle(Self);
Handle := 0; Handle := 0;

View File

@ -91,6 +91,7 @@ type
procedure WindowTitle(Str: PWideString); procedure WindowTitle(Str: PWideString);
procedure Hide; procedure Hide;
procedure Show; procedure Show;
function getVisible: boolean;
procedure setEnabled(p1: Boolean); procedure setEnabled(p1: Boolean);
procedure setVisible(visible: Boolean); procedure setVisible(visible: Boolean);
function windowModality: QtWindowModality; function windowModality: QtWindowModality;
@ -158,6 +159,7 @@ type
protected protected
function CreateWidget(const AParams: TCreateParams):QWidgetH; override; function CreateWidget(const AParams: TCreateParams):QWidgetH; override;
public public
LayoutWidget: QBoxLayoutH;
{$ifdef USE_QT_4_3} {$ifdef USE_QT_4_3}
MDIAreaHandle: QMDIAreaH; MDIAreaHandle: QMDIAreaH;
{$endif} {$endif}
@ -167,10 +169,11 @@ type
ToolBar: TQtToolBar; ToolBar: TQtToolBar;
Canvas: TQtDeviceContext; Canvas: TQtDeviceContext;
destructor Destroy; override; destructor Destroy; override;
function GetContainerWidget: QWidgetH; override; function GetContainerWidget: QWidgetH; override;
procedure setTabOrders; procedure setTabOrders;
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override; function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override;
procedure SlotWindowStateChange; cdecl; procedure SlotWindowStateChange; cdecl;
procedure setShowInTaskBar(AValue: Boolean);
end; end;
{ TQtStaticText } { TQtStaticText }
@ -510,7 +513,9 @@ type
constructor Create(const AHandle: QMenuH); overload; constructor Create(const AHandle: QMenuH); overload;
destructor Destroy; override; destructor Destroy; override;
public public
procedure SlotDestroy; cdecl;
procedure SlotTriggered(checked: Boolean = False); cdecl; procedure SlotTriggered(checked: Boolean = False); cdecl;
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override;
public public
procedure PopUp(pos: PQtPoint; at: QActionH = nil); procedure PopUp(pos: PQtPoint; at: QActionH = nil);
function actionHandle: QActionH; function actionHandle: QActionH;
@ -528,6 +533,7 @@ type
TQtMenuBar = class(TQtWidget) TQtMenuBar = class(TQtWidget)
private private
FVisible: Boolean;
public public
constructor Create(const AParent: QWidgetH); overload; constructor Create(const AParent: QWidgetH); overload;
destructor Destroy; override; destructor Destroy; override;
@ -1360,6 +1366,11 @@ begin
QWidget_show(Widget); QWidget_show(Widget);
end; end;
function TQtWidget.getVisible: boolean;
begin
Result := QWidget_isVisible(Widget);
end;
procedure TQtWidget.setEnabled(p1: Boolean); procedure TQtWidget.setEnabled(p1: Boolean);
begin begin
QWidget_setEnabled(Widget, p1); QWidget_setEnabled(Widget, p1);
@ -2000,7 +2011,7 @@ begin
{$endif} {$endif}
w := QApplication_activeWindow; w := QApplication_activeWindow;
if not Assigned(w) and not ((Application.MainForm <> nil) and (Application.MainForm.Visible)) then if not Assigned(w) and not ((Application.MainForm <> nil) and (Application.MainForm.Visible)) then
begin begin
Result := QMainWindow_create(nil, QtWindow); Result := QMainWindow_create(nil, QtWindow);
@ -2020,15 +2031,20 @@ begin
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
if Assigned(Application.MainForm) and Assigned(Application.MainForm.Menu) then 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} {$ifdef USE_QT_4_3}
MDIAreaHandle := QMdiArea_create(Result); if (Application.MainForm <> nil) and (Application.MainForm.FormStyle = fsMDIForm) then
begin
CentralWidget := MDIAreaHandle; MDIAreaHandle := QMdiArea_create(Result);
CentralWidget := MDIAreaHandle;
QMainWindow_setCentralWidget(QMainWindowH(Result), MDIAreaHandle); end
else
begin
CentralWidget := QWidget_create(Result);
MDIAreaHandle := nil
end;
QMainWindow_setCentralWidget(QMainWindowH(Result), CentralWidget);
QMainWindow_setDockOptions(QMainWindowH(Result), QMainWindowAnimatedDocks); QMainWindow_setDockOptions(QMainWindowH(Result), QMainWindowAnimatedDocks);
{$else} {$else}
CentralWidget := QWidget_create(Result); CentralWidget := QWidget_create(Result);
@ -2039,13 +2055,13 @@ begin
else else
begin begin
{$ifdef USE_QT_4_3} {$ifdef USE_QT_4_3}
if LCLObject.Tag = 9999 then if (LCLObject is TCustomForm) and (TCustomForm(LCLObject).FormStyle = fsMDIChild) then
begin begin
Result := QMdiSubWindow_create(NiL, QtWindow); Result := QMdiSubWindow_create(niL, QtWindow);
mdiHandle := TQtMainWindow(Application.MainForm.Handle).MDIAreaHandle; mdiHandle := TQtMainWindow(Application.MainForm.Handle).MDIAreaHandle;
if Assigned(mdiHandle) then if Assigned(mdiHandle) then
QMdiArea_addSubWindow(mdiHandle, QMdiSubWindowH(Result), QtWindow); QMdiArea_addSubWindow(mdiHandle, QMdiSubWindowH(Result), QtWindow);
end end
else else
Result := QWidget_create(nil, QtWindow); Result := QWidget_create(nil, QtWindow);
@ -2055,6 +2071,14 @@ begin
// Main menu bar // Main menu bar
MenuBar := TQtMenuBar.Create(Result); 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;
end; end;
@ -2094,11 +2118,15 @@ end;
function TQtMainWindow.GetContainerWidget: QWidgetH; function TQtMainWindow.GetContainerWidget: QWidgetH;
begin begin
{$ifdef USE_QT_4_3} {$ifdef USE_QT_4_3}
if (CentralWidget <> nil) and (MDIAreaHandle = NiL) then Result := CentralWidget if (CentralWidget <> nil) then
else Result := Widget; Result := CentralWidget
else
Result := Widget;
{$else} {$else}
if CentralWidget <> nil then Result := CentralWidget if CentralWidget <> nil then
else Result := Widget; Result := CentralWidget
else
Result := Widget;
{$endif} {$endif}
end; end;
@ -2201,6 +2229,34 @@ begin
end; end;
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 } { TQtStaticText }
function TQtStaticText.CreateWidget(const AParams: TCreateParams): QWidgetH; function TQtStaticText.CreateWidget(const AParams: TCreateParams): QWidgetH;
@ -4083,6 +4139,11 @@ begin
inherited Destroy; inherited Destroy;
end; end;
procedure TQtMenu.SlotDestroy; cdecl;
begin
Widget := nil;
end;
procedure TQtMenu.PopUp(pos: PQtPoint; at: QActionH); procedure TQtMenu.PopUp(pos: PQtPoint; at: QActionH);
begin begin
QMenu_Popup(QMenuH(Widget), pos, at); QMenu_Popup(QMenuH(Widget), pos, at);
@ -4162,11 +4223,22 @@ begin
MenuItem.OnClick(Self.MenuItem); MenuItem.OnClick(Self.MenuItem);
end; end;
function TQtMenu.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
begin
Result := False;
case QEvent_type(Event) of
QEventDestroy: SlotDestroy;
end;
end;
{ TQtMenuBar } { TQtMenuBar }
constructor TQtMenuBar.Create(const AParent: QWidgetH); constructor TQtMenuBar.Create(const AParent: QWidgetH);
begin begin
Widget := QMenuBar_create(AParent); Widget := QMenuBar_create(AParent);
FVisible := False;
setVisible(FVisible);
end; end;
destructor TQtMenuBar.Destroy; destructor TQtMenuBar.Destroy;
@ -4176,11 +4248,21 @@ end;
function TQtMenuBar.addMenu(title: PWideString): TQtMenu; function TQtMenuBar.addMenu(title: PWideString): TQtMenu;
begin begin
if not FVisible then
begin
FVisible := True;
setVisible(FVisible);
end;
Result := TQtMenu.Create(QMenuBar_addMenu(QMenuBarH(Widget), title)); Result := TQtMenu.Create(QMenuBar_addMenu(QMenuBarH(Widget), title));
end; end;
function TQtMenuBar.addSeparator: TQtMenu; function TQtMenuBar.addSeparator: TQtMenu;
begin begin
if not FVisible then
begin
FVisible := True;
setVisible(FVisible);
end;
Result := TQtMenu.Create(QMenuBar_addMenu(QMenuBarH(Widget), nil)); Result := TQtMenu.Create(QMenuBar_addMenu(QMenuBarH(Widget), nil));
Result.setSeparator(True); Result.setSeparator(True);
end; end;
@ -4701,3 +4783,4 @@ end;
end. end.

View File

@ -156,18 +156,23 @@ begin
QtMainWindow := TQtMainWindow.Create(AWinControl, AParams); 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); Str := UTF8Decode(AWinControl.Caption);
QtMainWindow.SetWindowTitle(@Str); QtMainWindow.SetWindowTitle(@Str);
SetQtWindowBorderStyle(QtMainWindow, TCustomForm(AWinControl).BorderStyle); SetQtWindowBorderStyle(QtMainWindow, TCustomForm(AWinControl).BorderStyle);
SetQtBorderIcons(QtMainWindow, TCustomForm(AWinControl).BorderIcons); SetQtBorderIcons(QtMainWindow, TCustomForm(AWinControl).BorderIcons);
// Sets Various Events // Sets Various Events
Hook := QObject_hook_create(QtMainWindow.Widget); Hook := QObject_hook_create(QtMainWindow.Widget);
@ -268,8 +273,18 @@ end;
Returns: Nothing Returns: Nothing
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
class procedure TQtWSCustomForm.SetShowInTaskbar(const AForm: TCustomForm; const AValue: TShowInTaskbar); class procedure TQtWSCustomForm.SetShowInTaskbar(const AForm: TCustomForm; const AValue: TShowInTaskbar);
var
Enable: Boolean;
begin 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; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -340,7 +355,7 @@ begin
case AFormBorderStyle of case AFormBorderStyle of
bsNone: bsNone:
begin begin
Flags := Flags or QtFramelessWindowHint; Flags := (Flags or QtFramelessWindowHint) and not QtWindowTitleHint;
Flags := Flags and not QtOnlyDialog; Flags := Flags and not QtOnlyDialog;
end; end;
bsSingle: bsSingle:
@ -388,6 +403,7 @@ class procedure TQtWSCustomForm.SetQtBorderIcons(const AHandle: TQtMainWindow;
const ABorderIcons: TBorderIcons); const ABorderIcons: TBorderIcons);
var var
Flags: QtWindowFlags; Flags: QtWindowFlags;
ShowAny: Boolean;
begin begin
Flags := AHandle.windowFlags; Flags := AHandle.windowFlags;
@ -395,17 +411,28 @@ begin
WriteLn('Trace:> [TQtWSCustomForm.SetBorderIcons] Flags: ', IntToHex(Flags, 8)); WriteLn('Trace:> [TQtWSCustomForm.SetBorderIcons] Flags: ', IntToHex(Flags, 8));
{$endif} {$endif}
if biSystemMenu in ABorderIcons then Flags := Flags or QtWindowSystemMenuHint ShowAny := ((Flags and QtFramelessWindowHint) = 0) or
else Flags := Flags and not QtWindowSystemMenuHint; ((Flags and QtWindowTitleHint) <> 0);
if biMinimize in ABorderIcons then Flags := Flags or QtWindowMinimizeButtonHint if (biSystemMenu in ABorderIcons) and ShowAny then
else Flags := Flags and not QtWindowMinimizeButtonHint; Flags := Flags or QtWindowSystemMenuHint
else
Flags := Flags and not QtWindowSystemMenuHint;
if biMaximize in ABorderIcons then Flags := Flags or QtWindowMaximizeButtonHint if (biMinimize in ABorderIcons) and ShowAny then
else Flags := Flags and not QtWindowMaximizeButtonHint; Flags := Flags or QtWindowMinimizeButtonHint
else
Flags := Flags and not QtWindowMinimizeButtonHint;
if biHelp in ABorderIcons then Flags := Flags or QtWindowContextHelpButtonHint if (biMaximize in ABorderIcons) and ShowAny then
else Flags := Flags and not QtWindowContextHelpButtonHint; 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} {$ifdef VerboseQt}
WriteLn('Trace:< [TQtWSCustomForm.SetBorderIcons] Flags: ', IntToHex(Flags, 8)); WriteLn('Trace:< [TQtWSCustomForm.SetBorderIcons] Flags: ', IntToHex(Flags, 8));

View File

@ -114,6 +114,7 @@ var
MenuBar: TQtMenuBar; MenuBar: TQtMenuBar;
Text: WideString; Text: WideString;
Method: TMethod; Method: TMethod;
Hook: QObject_hookH;
begin begin
{$ifdef VerboseQt} {$ifdef VerboseQt}
WriteLn('trace:> [TQtWSMenuItem.CreateHandle] Caption: ', AMenuItem.Caption, WriteLn('trace:> [TQtWSMenuItem.CreateHandle] Caption: ', AMenuItem.Caption,
@ -121,6 +122,8 @@ begin
Write('trace:< [TQtWSMenuItem.CreateHandle]'); Write('trace:< [TQtWSMenuItem.CreateHandle]');
{$endif} {$endif}
Menu := nil;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
This case should not happen. A menu item must have a parent, but it seams LCL This case should not happen. A menu item must have a parent, but it seams LCL
@ -224,8 +227,14 @@ begin
// Trigger event // Trigger event
QAction_triggered_Event(Method) := Menu.SlotTriggered; QAction_triggered_Event(Method) := Menu.SlotTriggered;
QAction_hook_hook_triggered(QAction_hook_create(Menu.ActionHandle), Method); 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; end;
{$ifdef VerboseQt} {$ifdef VerboseQt}