1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "frame.h"
17 #include "wx/statusbr.h"
18 #include "wx/toolbar.h"
19 #include "wx/menuitem.h"
21 #include "wx/dcclient.h"
22 #include "wx/dialog.h"
23 #include "wx/settings.h"
27 #if defined(__ultrix) || defined(__sgi)
32 #include <X11/Shell.h>
38 #include <Xm/MwmUtil.h>
39 #include <Xm/BulletinB.h>
42 #include <Xm/RowColumn.h>
44 #include <Xm/AtomMgr.h>
45 #include <Xm/LabelG.h>
47 #include <Xm/DrawingA.h>
49 #include <Xm/Protocols.h>
52 #include "wx/motif/private.h"
54 void wxCloseFrameCallback(Widget
, XtPointer
, XmAnyCallbackStruct
*cbs
);
55 void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
56 XmAnyCallbackStruct
*cbs
);
57 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
58 XCrossingEvent
* event
);
61 extern void wxCanvasRepaintProc (Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
62 extern void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
64 extern wxList wxModelessWindows
;
65 extern wxList wxPendingDelete
;
67 // TODO: this should be tidied so that any frame can be the
69 static bool wxTopLevelUsed
= FALSE
;
71 #if !USE_SHARED_LIBRARY
72 BEGIN_EVENT_TABLE(wxFrame
, wxWindow
)
73 EVT_SIZE(wxFrame::OnSize
)
74 EVT_ACTIVATE(wxFrame::OnActivate
)
75 EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight
)
76 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
77 EVT_IDLE(wxFrame::OnIdle
)
78 EVT_CLOSE(wxFrame::OnCloseWindow
)
81 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
)
84 #if wxUSE_NATIVE_STATUSBAR
85 bool wxFrame::m_useNativeStatusBar
= TRUE
;
87 bool wxFrame::m_useNativeStatusBar
= FALSE
;
93 m_frameToolBar
= NULL
;
94 #endif // wxUSE_TOOLBAR
96 m_frameMenuBar
= NULL
;
97 m_frameStatusBar
= NULL
;
99 m_windowParent
= NULL
;
103 m_frameShell
= (WXWidget
) NULL
;
104 m_frameWidget
= (WXWidget
) NULL
;;
105 m_workArea
= (WXWidget
) NULL
;;
106 m_clientArea
= (WXWidget
) NULL
;;
107 m_visibleStatus
= TRUE
;
111 bool wxFrame::Create(wxWindow
*parent
,
113 const wxString
& title
,
117 const wxString
& name
)
120 wxTopLevelWindows
.Append(this);
124 m_windowStyle
= style
;
125 m_frameMenuBar
= NULL
;
127 m_frameToolBar
= NULL
;
128 #endif // wxUSE_TOOLBAR
129 m_frameStatusBar
= NULL
;
132 m_frameShell
= (WXWidget
) NULL
;
133 m_frameWidget
= (WXWidget
) NULL
;;
134 m_workArea
= (WXWidget
) NULL
;;
135 m_clientArea
= (WXWidget
) NULL
;;
136 m_visibleStatus
= TRUE
;
139 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
140 m_foregroundColour
= *wxBLACK
;
141 m_windowFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
146 m_windowId
= (int)NewControlId();
148 if (parent
) parent
->AddChild(this);
150 wxModelessWindows
.Append(this);
152 int x
= pos
.x
; int y
= pos
.y
;
153 int width
= size
.x
; int height
= size
.y
;
156 // Change suggested by Matthew Flatt
157 m_frameShell
= (WXWidget
) XtAppCreateShell(name
, wxTheApp
->GetClassName(), topLevelShellWidgetClass
, (Display
*) wxGetDisplay(), NULL
, 0);
160 m_frameShell
= wxTheApp
->GetTopLevelWidget();
161 wxTopLevelUsed
= TRUE
;
164 XtVaSetValues((Widget
) m_frameShell
,
165 // Allows menu to resize
166 XmNallowShellResize
, True
,
167 XmNdeleteResponse
, XmDO_NOTHING
,
168 XmNmappedWhenManaged
, False
,
169 XmNiconic
, (style
& wxICONIZE
) ? TRUE
: FALSE
,
173 XtVaSetValues((Widget
) m_frameShell
,
174 XmNtitle
, (const char*) title
,
177 m_frameWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
178 xmMainWindowWidgetClass
, (Widget
) m_frameShell
,
179 XmNresizePolicy
, XmRESIZE_NONE
,
182 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
183 xmFormWidgetClass
, (Widget
) m_frameWidget
,
184 XmNresizePolicy
, XmRESIZE_NONE
,
187 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
188 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
191 XmNrightAttachment
, XmATTACH_FORM
,
192 XmNleftAttachment
, XmATTACH_FORM
,
193 XmNtopAttachment
, XmATTACH_FORM
,
194 XmNbottomAttachment
, XmATTACH_FORM
,
195 // XmNresizePolicy, XmRESIZE_ANY,
198 XtAddCallback ((Widget
) m_clientArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
199 XtAddCallback ((Widget
) m_clientArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
201 XtVaSetValues((Widget
) m_frameWidget
,
202 XmNworkWindow
, (Widget
) m_workArea
,
205 XtManageChild((Widget
) m_clientArea
);
206 XtManageChild((Widget
) m_workArea
);
208 wxASSERT_MSG ((wxWidgetHashTable
->Get((long)m_workArea
) == (wxObject
*) NULL
), "Widget table clash in frame.cpp") ;
210 wxAddWindowToTable((Widget
) m_workArea
, this);
214 XtOverrideTranslations((Widget
) m_workArea
,
215 ptr
= XtParseTranslationTable("<Configure>: resize()"));
219 XtAddCallback((Widget
) m_workArea
, XmNfocusCallback
,
220 (XtCallbackProc
)wxFrameFocusProc
, (XtPointer
)this);
222 /* Part of show-&-hide fix */
223 XtAddEventHandler((Widget
) m_frameShell
, StructureNotifyMask
,
224 False
, (XtEventHandler
)wxFrameMapProc
,
225 (XtPointer
)m_workArea
);
228 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
230 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
232 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
234 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
236 m_mainWidget
= m_frameWidget
;
240 // This patch comes from Torsten Liermann lier@lier1.muc.de
241 if (XmIsMotifWMRunning( (Widget
) m_frameShell
))
244 if (style
& wxRESIZE_BORDER
)
245 decor
|= MWM_DECOR_RESIZEH
;
246 if (style
& wxSYSTEM_MENU
)
247 decor
|= MWM_DECOR_MENU
;
248 if ((style
& wxCAPTION
) ||
249 (style
& wxTINY_CAPTION_HORIZ
) ||
250 (style
& wxTINY_CAPTION_VERT
))
251 decor
|= MWM_DECOR_TITLE
;
252 if (style
& wxTHICK_FRAME
)
253 decor
|= MWM_DECOR_BORDER
;
254 if (style
& wxTHICK_FRAME
)
255 decor
|= MWM_DECOR_BORDER
;
256 if (style
& wxMINIMIZE_BOX
)
257 decor
|= MWM_DECOR_MINIMIZE
;
258 if (style
& wxMAXIMIZE_BOX
)
259 decor
|= MWM_DECOR_MAXIMIZE
;
260 XtVaSetValues((Widget
) m_frameShell
,XmNmwmDecorations
,decor
,NULL
) ;
262 // This allows non-Motif window managers to support at least the
263 // no-decorations case.
267 XtVaSetValues((Widget
) m_frameShell
,XmNoverrideRedirect
,TRUE
,NULL
);
269 XtRealizeWidget((Widget
) m_frameShell
);
271 // Intercept CLOSE messages from the window manager
272 Atom WM_DELETE_WINDOW
= XmInternAtom(XtDisplay((Widget
) m_frameShell
), "WM_DELETE_WINDOW", False
);
273 #if (XmREVISION > 1 || XmVERSION > 1)
274 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (XtPointer
)this);
277 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (caddr_t
)this);
279 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (void (*)())wxCloseFrameCallback
, (caddr_t
)this);
283 ChangeBackgroundColour();
287 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
288 sizeEvent
.SetEventObject(this);
290 GetEventHandler()->ProcessEvent(sizeEvent
);
300 XtRemoveCallback ((Widget
) m_clientArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
301 XtRemoveCallback ((Widget
) m_clientArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
305 m_frameMenuBar
->DestroyMenuBar();
307 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
308 #if MOTIF_MENUBAR_DELETE_FIX
309 GetMenuBar()->SetMainWidget((WXWidget
) NULL
);
311 delete m_frameMenuBar
;
312 m_frameMenuBar
= NULL
;
315 wxTopLevelWindows
.DeleteObject(this);
316 wxModelessWindows
.DeleteObject(this);
318 if (m_frameStatusBar
)
319 delete m_frameStatusBar
;
325 for (i = 0; i < wxMAX_STATUS; i++)
326 if (statusTextWidget[i])
327 XtDestroyWidget (statusTextWidget[i]);
330 XtDestroyWidget (statusLineForm);
332 if (statusLineWidget)
333 XtDestroyWidget (statusLineWidget);
338 wxDeleteWindowFromTable((Widget
) m_workArea
);
340 XtDestroyWidget ((Widget
) m_workArea
);
345 wxDeleteWindowFromTable((Widget
) m_frameWidget
);
346 XtDestroyWidget ((Widget
) m_frameWidget
);
350 XtDestroyWidget ((Widget
) m_frameShell
);
352 SetMainWidget((WXWidget
) NULL
);
354 /* Check if it's the last top-level window */
356 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
358 wxTheApp
->SetTopWindow(NULL
);
360 if (wxTheApp
->GetExitOnFrameDelete())
362 // Signal to the app that we're going to close
363 wxTheApp
->ExitMainLoop();
369 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
370 void wxFrame::GetClientSize(int *x
, int *y
) const
373 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
375 if (m_frameStatusBar
)
378 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
385 m_frameToolBar
->GetSize(& tbw
, & tbh
);
386 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
391 #endif // wxUSE_TOOLBAR
393 if (GetMenuBar() != (wxMenuBar*) NULL)
395 // it seems that if a frame holds a panel, the menu bar size
396 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
397 bool hasSubPanel = FALSE;
398 for(wxNode* node = GetChildren().First(); node; node = node->Next())
400 wxWindow *win = (wxWindow *)node->Data();
401 hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)));
408 XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL);
417 // Set the client size (i.e. leave the calculation of borders etc.
419 void wxFrame::SetClientSize(int width
, int height
)
421 // Calculate how large the new main window should be
422 // by finding the difference between the client area and the
423 // main window area, and adding on to the new client area
425 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
429 if (m_frameStatusBar
)
432 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
439 m_frameToolBar
->GetSize(& tbw
, & tbh
);
440 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
445 #endif // wxUSE_TOOLBAR
447 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
451 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
452 sizeEvent
.SetEventObject(this);
454 GetEventHandler()->ProcessEvent(sizeEvent
);
458 void wxFrame::GetSize(int *width
, int *height
) const
461 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
462 *width
= xx
; *height
= yy
;
465 void wxFrame::GetPosition(int *x
, int *y
) const
467 Window parent_window
= XtWindow((Widget
) m_frameShell
),
468 next_parent
= XtWindow((Widget
) m_frameShell
),
469 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
471 // search for the parent that is child of ROOT, because the WM may
472 // reparent twice and notify only the next parent (like FVWM)
473 while (next_parent
!= root
) {
474 Window
*theChildren
; unsigned int n
;
475 parent_window
= next_parent
;
476 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
477 &next_parent
, &theChildren
, &n
);
478 XFree(theChildren
); // not needed
480 int xx
, yy
; unsigned int dummy
;
481 XGetGeometry(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
482 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
487 void wxFrame::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
490 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
492 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
494 XtVaSetValues((Widget
) m_frameWidget
, XmNwidth
, width
, NULL
);
496 XtVaSetValues((Widget
) m_frameWidget
, XmNheight
, height
, NULL
);
498 if (!(height
== -1 && width
== -1))
502 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
503 sizeEvent
.SetEventObject(this);
505 GetEventHandler()->ProcessEvent(sizeEvent
);
509 bool wxFrame::Show(bool show
)
512 return wxWindow::Show(show
);
514 m_visibleStatus
= show
; /* show-&-hide fix */
518 XtMapWidget((Widget
) m_frameShell
);
519 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), XtWindow((Widget
) m_frameShell
));
521 XtUnmapWidget((Widget
) m_frameShell
);
522 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
527 void wxFrame::Iconize(bool iconize
)
533 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, (Boolean
)iconize
, NULL
);
536 // Equivalent to maximize/restore in Windows
537 void wxFrame::Maximize(bool maximize
)
541 if (maximize
&& m_frameShell
)
542 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, FALSE
, NULL
);
545 bool wxFrame::IsIconized() const
551 XtVaGetValues((Widget
) m_frameShell
, XmNiconic
, &iconic
, NULL
);
556 bool wxFrame::IsMaximized(void) const
558 // No maximizing in Motif (?)
562 void wxFrame::SetTitle(const wxString
& title
)
564 if (title
== m_title
)
570 XtVaSetValues((Widget
) m_frameShell
,
571 XmNtitle
, (const char*) title
,
572 XmNiconName
, (const char*) title
,
576 void wxFrame::SetIcon(const wxIcon
& icon
)
583 if (!icon
.Ok() || !icon
.GetPixmap())
586 XtVaSetValues((Widget
) m_frameShell
, XtNiconPixmap
, icon
.GetPixmap(), NULL
);
589 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
590 const wxString
& name
)
592 wxStatusBar
*statusBar
= NULL
;
594 statusBar
= new wxStatusBar(this, id
, wxPoint(0, 0), wxSize(100, 20),
597 // Set the height according to the font and the border size
598 wxClientDC
dc(statusBar
);
599 dc
.SetFont(statusBar
->GetFont());
602 dc
.GetTextExtent("X", &x
, &y
);
604 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
606 statusBar
->SetSize(-1, -1, 100, height
);
608 statusBar
->SetFieldsCount(number
);
612 wxStatusBar
* wxFrame::CreateStatusBar(int number
, long style
, wxWindowID id
,
613 const wxString
& name
)
615 // Calling CreateStatusBar twice is an error.
616 wxCHECK_MSG( m_frameStatusBar
== NULL
, FALSE
,
617 "recreating status bar in wxFrame" );
619 m_frameStatusBar
= OnCreateStatusBar(number
, style
, id
,
621 if ( m_frameStatusBar
)
624 return m_frameStatusBar
;
630 void wxFrame::SetStatusText(const wxString
& text
, int number
)
632 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set text for" );
634 m_frameStatusBar
->SetStatusText(text
, number
);
637 void wxFrame::SetStatusWidths(int n
, const int widths_field
[])
639 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set widths for" );
641 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
645 void wxFrame::PositionStatusBar()
647 if (!m_frameStatusBar
)
651 GetClientSize(&w
, &h
);
653 m_frameStatusBar
->GetSize(&sw
, &sh
);
655 // Since we wish the status bar to be directly under the client area,
656 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
657 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
660 WXWidget
wxFrame::GetMenuBarWidget() const
663 return GetMenuBar()->GetMainWidget();
665 return (WXWidget
) NULL
;
668 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
672 m_frameMenuBar
= NULL
;
676 // Currently can't set it twice
677 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
681 m_frameMenuBar
->DestroyMenuBar();
682 delete m_frameMenuBar
;
685 m_frameMenuBar
= menuBar
;
686 m_frameMenuBar
->CreateMenuBar(this);
691 // Work out max. size
692 wxNode
*node
= GetChildren().First();
697 // Find a child that's a subwindow, but not a dialog box.
698 wxWindow
*win
= (wxWindow
*)node
->Data();
700 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
701 !win
->IsKindOf(CLASSINFO(wxDialog
)))
705 win
->GetSize(&width
, &height
);
706 win
->GetPosition(&x
, &y
);
708 if ((x
+ width
) > max_width
)
709 max_width
= x
+ width
;
710 if ((y
+ height
) > max_height
)
711 max_height
= y
+ height
;
715 SetClientSize(max_width
, max_height
);
718 // Responds to colour changes, and passes event on to children.
719 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
721 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
724 if ( m_frameStatusBar
)
726 wxSysColourChangedEvent event2
;
727 event2
.SetEventObject( m_frameStatusBar
);
728 m_frameStatusBar
->ProcessEvent(event2
);
731 // Propagate the event to the non-top-level children
732 wxWindow::OnSysColourChanged(event
);
735 // Default resizing behaviour - if only ONE subwindow,
736 // resize to client rectangle size
737 void wxFrame::OnSize(wxSizeEvent
& event
)
739 // if we're using constraints - do use them
740 #if wxUSE_CONSTRAINTS
741 if ( GetAutoLayout() ) {
747 // do we have _exactly_ one child?
748 wxWindow
*child
= NULL
;
749 for ( wxNode
*node
= GetChildren().First(); node
; node
= node
->Next() )
751 wxWindow
*win
= (wxWindow
*)node
->Data();
752 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) &&
753 !win
->IsKindOf(CLASSINFO(wxDialog
)) &&
754 (win
!= GetStatusBar())
756 && (win
!= GetToolBar())
757 #endif // wxUSE_TOOLBAR
761 return; // it's our second subwindow - nothing to do
767 // we have exactly one child - set it's size to fill the whole frame
768 int clientW
, clientH
;
769 GetClientSize(&clientW
, &clientH
);
774 child
->SetSize(x
, y
, clientW
, clientH
);
778 // Default activation behaviour - set the focus for the first child
780 void wxFrame::OnActivate(wxActivateEvent
& event
)
782 for(wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
784 // Find a child that's a subwindow, but not a dialog box.
785 wxWindow
*child
= (wxWindow
*)node
->Data();
786 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
787 !child
->IsKindOf(CLASSINFO(wxDialog
)))
795 // The default implementation for the close window event.
796 // OnClose for backward compatibility.
798 void wxFrame::OnCloseWindow(wxCloseEvent
& event
)
803 // Destroy the window (delayed, if a managed window)
804 bool wxFrame::Destroy()
806 if (!wxPendingDelete
.Member(this))
807 wxPendingDelete
.Append(this);
811 // Default menu selection behaviour - display a help string
812 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
816 if (event
.GetMenuId() == -1)
820 wxMenuBar
*menuBar
= GetMenuBar();
823 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
824 if (helpString
!= "")
825 SetStatusText(helpString
);
831 wxMenuBar
*wxFrame::GetMenuBar() const
833 return m_frameMenuBar
;
836 void wxFrame::Centre(int direction
)
838 int display_width
, display_height
, width
, height
, x
, y
;
839 wxDisplaySize(&display_width
, &display_height
);
841 GetSize(&width
, &height
);
844 if (direction
& wxHORIZONTAL
)
845 x
= (int)((display_width
- width
)/2);
846 if (direction
& wxVERTICAL
)
847 y
= (int)((display_height
- height
)/2);
849 SetSize(x
, y
, width
, height
);
852 // Call this to simulate a menu command
853 void wxFrame::Command(int id
)
858 void wxFrame::ProcessCommand(int id
)
860 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
861 commandEvent
.SetInt( id
);
862 commandEvent
.SetEventObject( this );
864 wxMenuBar
*bar
= GetMenuBar() ;
868 /* TODO: check the menu item if required
869 wxMenuItem *item = bar->FindItemForId(id) ;
870 if (item && item->IsCheckable())
872 bar->Check(id,!bar->Checked(id)) ;
876 GetEventHandler()->ProcessEvent(commandEvent
);
879 // Checks if there is a toolbar, and returns the first free client position
880 wxPoint
wxFrame::GetClientAreaOrigin() const
887 GetToolBar()->GetSize(& w
, & h
);
889 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
898 #endif // wxUSE_TOOLBAR
903 void wxFrame::ScreenToClient(int *x
, int *y
) const
905 wxWindow::ScreenToClient(x
, y
);
907 // We may be faking the client origin.
908 // So a window that's really at (0, 30) may appear
909 // (to wxWin apps) to be at (0, 0).
910 wxPoint
pt(GetClientAreaOrigin());
915 void wxFrame::ClientToScreen(int *x
, int *y
) const
917 // We may be faking the client origin.
918 // So a window that's really at (0, 30) may appear
919 // (to wxWin apps) to be at (0, 0).
920 wxPoint
pt1(GetClientAreaOrigin());
924 wxWindow::ClientToScreen(x
, y
);
928 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
930 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
931 "recreating toolbar in wxFrame" );
933 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
946 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
948 return new wxToolBar(this, id
, wxPoint(0, 0), wxSize(100, 24), style
, name
);
951 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
953 m_frameToolBar
= toolbar
;
956 wxToolBar
*wxFrame::GetToolBar() const
958 return m_frameToolBar
;
961 void wxFrame::PositionToolBar()
965 GetClientSize(& cw
, &ch
);
970 GetToolBar()->GetSize(& tw
, & th
);
972 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
974 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
975 // means, pretend we don't have toolbar/status bar, so we
976 // have the original client size.
977 GetToolBar()->SetSize(0, 0, tw
, ch
+ th
, wxSIZE_NO_ADJUSTMENTS
);
981 // Use the 'real' position
982 GetToolBar()->SetSize(0, 0, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
986 #endif // wxUSE_TOOLBAR
988 void wxFrame::CaptureMouse()
994 XtAddGrab((Widget
) m_frameShell
, TRUE
, FALSE
);
995 m_winCaptured
= TRUE
;
998 void wxFrame::ReleaseMouse()
1003 if (GetMainWidget())
1004 XtRemoveGrab((Widget
) m_frameShell
);
1005 m_winCaptured
= FALSE
;
1008 void wxFrame::Raise(void)
1010 Window parent_window
= XtWindow((Widget
) m_frameShell
),
1011 next_parent
= XtWindow((Widget
) m_frameShell
),
1012 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
1013 // search for the parent that is child of ROOT, because the WM may
1014 // reparent twice and notify only the next parent (like FVWM)
1015 while (next_parent
!= root
) {
1016 Window
*theChildren
; unsigned int n
;
1017 parent_window
= next_parent
;
1018 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
1019 &next_parent
, &theChildren
, &n
);
1020 XFree(theChildren
); // not needed
1022 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
1025 void wxFrame::Lower(void)
1027 Window parent_window
= XtWindow((Widget
) m_frameShell
),
1028 next_parent
= XtWindow((Widget
) m_frameShell
),
1029 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
1030 // search for the parent that is child of ROOT, because the WM may
1031 // reparent twice and notify only the next parent (like FVWM)
1032 while (next_parent
!= root
) {
1033 Window
*theChildren
; unsigned int n
;
1034 parent_window
= next_parent
;
1035 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
1036 &next_parent
, &theChildren
, &n
);
1037 XFree(theChildren
); // not needed
1039 XLowerWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
1042 void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
1043 XmAnyCallbackStruct
*cbs
)
1045 wxFrame
*frame
= (wxFrame
*)clientData
;
1047 // wxDebugMsg("focus proc from frame %ld\n",(long)frame);
1049 // frame->GetEventHandler()->OnSetFocus();
1052 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
1053 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
1054 XCrossingEvent
* event
)
1056 wxFrame
*frame
= (wxFrame
*)wxWidgetHashTable
->Get((long)clientData
);
1059 XEvent
*e
= (XEvent
*)event
;
1061 if (e
->xany
.type
== MapNotify
)
1064 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
1065 if (!frame
->GetVisibleStatus())
1067 /* We really wanted this to be hidden! */
1068 XtUnmapWidget((Widget
) frame
->GetShellWidget());
1071 else if (e
->xany
.type
== UnmapNotify
)
1073 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)True
, NULL
);
1078 bool wxFrame::PreResize()
1082 #endif // wxUSE_TOOLBAR
1083 PositionStatusBar();
1087 WXWidget
wxFrame::GetClientWidget() const
1089 return m_clientArea
;
1092 void wxFrame::ChangeFont(bool keepOriginalSize
)
1097 void wxFrame::ChangeBackgroundColour()
1099 if (GetClientWidget())
1100 DoChangeBackgroundColour(GetClientWidget(), m_backgroundColour
);
1103 void wxFrame::ChangeForegroundColour()
1105 if (GetClientWidget())
1106 DoChangeForegroundColour(GetClientWidget(), m_foregroundColour
);
1109 void wxCloseFrameCallback(Widget widget
, XtPointer client_data
, XmAnyCallbackStruct
*cbs
)
1111 wxFrame
*frame
= (wxFrame
*)client_data
;
1113 wxCloseEvent
closeEvent(wxEVT_CLOSE_WINDOW
, frame
->GetId());
1114 closeEvent
.SetEventObject(frame
);
1116 // May delete the frame (with delayed deletion)
1117 frame
->GetEventHandler()->ProcessEvent(closeEvent
);