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>
48 #include <Xm/Protocols.h>
51 #include "wx/motif/private.h"
53 void wxCloseFrameCallback(Widget
, XtPointer
, XmAnyCallbackStruct
*cbs
);
54 void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
55 XmAnyCallbackStruct
*cbs
);
56 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
57 XCrossingEvent
* event
);
59 extern wxList wxModelessWindows
;
60 extern wxList wxPendingDelete
;
62 // TODO: this should be tidied so that any frame can be the
64 static bool wxTopLevelUsed
= FALSE
;
66 #if !USE_SHARED_LIBRARY
67 BEGIN_EVENT_TABLE(wxFrame
, wxWindow
)
68 EVT_SIZE(wxFrame::OnSize
)
69 EVT_ACTIVATE(wxFrame::OnActivate
)
70 EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight
)
71 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
72 EVT_IDLE(wxFrame::OnIdle
)
73 EVT_CLOSE(wxFrame::OnCloseWindow
)
76 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
)
79 #if wxUSE_NATIVE_STATUSBAR
80 bool wxFrame::m_useNativeStatusBar
= TRUE
;
82 bool wxFrame::m_useNativeStatusBar
= FALSE
;
88 m_frameToolBar
= NULL
;
89 #endif // wxUSE_TOOLBAR
91 m_frameMenuBar
= NULL
;
92 m_frameStatusBar
= NULL
;
98 m_frameShell
= (WXWidget
) NULL
;
99 m_frameWidget
= (WXWidget
) NULL
;;
100 m_workArea
= (WXWidget
) NULL
;;
101 m_clientArea
= (WXWidget
) NULL
;;
102 m_visibleStatus
= TRUE
;
106 bool wxFrame::Create(wxWindow
*parent
,
108 const wxString
& title
,
112 const wxString
& name
)
115 wxTopLevelWindows
.Append(this);
119 m_windowStyle
= style
;
120 m_frameMenuBar
= NULL
;
122 m_frameToolBar
= NULL
;
123 #endif // wxUSE_TOOLBAR
124 m_frameStatusBar
= NULL
;
127 m_frameShell
= (WXWidget
) NULL
;
128 m_frameWidget
= (WXWidget
) NULL
;;
129 m_workArea
= (WXWidget
) NULL
;;
130 m_clientArea
= (WXWidget
) NULL
;;
131 m_visibleStatus
= TRUE
;
134 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
135 m_foregroundColour
= *wxBLACK
;
136 m_font
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
141 m_windowId
= (int)NewControlId();
143 if (parent
) parent
->AddChild(this);
145 wxModelessWindows
.Append(this);
147 int x
= pos
.x
, y
= pos
.y
;
148 int width
= size
.x
, height
= size
.y
;
150 // Set reasonable values for position and size if defaults have
153 // MB TODO: something better than these arbitrary values ?
155 if ( width
== -1 ) width
= 400;
156 if ( height
= -1 ) height
= 400;
158 int displayW
, displayH
;
159 wxDisplaySize( &displayW
, &displayH
);
163 x
= (displayW
- width
) / 2;
168 y
= (displayH
- height
) / 2;
174 // Change suggested by Matthew Flatt
175 m_frameShell
= (WXWidget
)XtAppCreateShell
178 wxTheApp
->GetClassName(),
179 topLevelShellWidgetClass
,
180 (Display
*) wxGetDisplay(),
187 m_frameShell
= wxTheApp
->GetTopLevelWidget();
188 wxTopLevelUsed
= TRUE
;
191 XtVaSetValues((Widget
) m_frameShell
,
192 // Allows menu to resize
193 XmNallowShellResize
, True
,
194 XmNdeleteResponse
, XmDO_NOTHING
,
195 XmNmappedWhenManaged
, False
,
196 XmNiconic
, (style
& wxICONIZE
) ? TRUE
: FALSE
,
200 XtVaSetValues((Widget
) m_frameShell
,
201 XmNtitle
, (const char*) title
,
204 m_frameWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
205 xmMainWindowWidgetClass
, (Widget
) m_frameShell
,
206 XmNresizePolicy
, XmRESIZE_NONE
,
209 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
210 xmFormWidgetClass
, (Widget
) m_frameWidget
,
211 XmNresizePolicy
, XmRESIZE_NONE
,
214 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
215 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
218 XmNrightAttachment
, XmATTACH_FORM
,
219 XmNleftAttachment
, XmATTACH_FORM
,
220 XmNtopAttachment
, XmATTACH_FORM
,
221 XmNbottomAttachment
, XmATTACH_FORM
,
222 // XmNresizePolicy, XmRESIZE_ANY,
225 wxLogDebug("Created frame (0x%08x) with work area 0x%08x and client "
226 "area 0x%08x", m_frameWidget
, m_workArea
, m_clientArea
);
228 XtAddEventHandler((Widget
) m_clientArea
, ExposureMask
,FALSE
,
229 wxUniversalRepaintProc
, (XtPointer
) this);
231 XtVaSetValues((Widget
) m_frameWidget
,
232 XmNworkWindow
, (Widget
) m_workArea
,
235 XtManageChild((Widget
) m_clientArea
);
236 XtManageChild((Widget
) m_workArea
);
238 wxAddWindowToTable((Widget
) m_workArea
, this);
242 XtOverrideTranslations((Widget
) m_workArea
,
243 ptr
= XtParseTranslationTable("<Configure>: resize()"));
247 XtAddCallback((Widget
) m_workArea
, XmNfocusCallback
,
248 (XtCallbackProc
)wxFrameFocusProc
, (XtPointer
)this);
250 /* Part of show-&-hide fix */
251 XtAddEventHandler((Widget
) m_frameShell
, StructureNotifyMask
,
252 False
, (XtEventHandler
)wxFrameMapProc
,
253 (XtPointer
)m_workArea
);
256 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
258 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
260 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
262 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
264 m_mainWidget
= m_frameWidget
;
268 // This patch comes from Torsten Liermann lier@lier1.muc.de
269 if (XmIsMotifWMRunning( (Widget
) m_frameShell
))
272 if (style
& wxRESIZE_BORDER
)
273 decor
|= MWM_DECOR_RESIZEH
;
274 if (style
& wxSYSTEM_MENU
)
275 decor
|= MWM_DECOR_MENU
;
276 if ((style
& wxCAPTION
) ||
277 (style
& wxTINY_CAPTION_HORIZ
) ||
278 (style
& wxTINY_CAPTION_VERT
))
279 decor
|= MWM_DECOR_TITLE
;
280 if (style
& wxTHICK_FRAME
)
281 decor
|= MWM_DECOR_BORDER
;
282 if (style
& wxTHICK_FRAME
)
283 decor
|= MWM_DECOR_BORDER
;
284 if (style
& wxMINIMIZE_BOX
)
285 decor
|= MWM_DECOR_MINIMIZE
;
286 if (style
& wxMAXIMIZE_BOX
)
287 decor
|= MWM_DECOR_MAXIMIZE
;
288 XtVaSetValues((Widget
) m_frameShell
,XmNmwmDecorations
,decor
,NULL
) ;
290 // This allows non-Motif window managers to support at least the
291 // no-decorations case.
295 XtVaSetValues((Widget
) m_frameShell
,XmNoverrideRedirect
,TRUE
,NULL
);
297 XtRealizeWidget((Widget
) m_frameShell
);
299 // Intercept CLOSE messages from the window manager
300 Atom WM_DELETE_WINDOW
= XmInternAtom(XtDisplay((Widget
) m_frameShell
), "WM_DELETE_WINDOW", False
);
301 #if (XmREVISION > 1 || XmVERSION > 1)
302 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (XtPointer
)this);
305 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (caddr_t
)this);
307 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (void (*)())wxCloseFrameCallback
, (caddr_t
)this);
311 ChangeBackgroundColour();
315 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
316 sizeEvent
.SetEventObject(this);
318 GetEventHandler()->ProcessEvent(sizeEvent
);
325 m_isBeingDeleted
= TRUE
;
328 XtRemoveEventHandler((Widget
) m_clientArea
, ExposureMask
, FALSE
,
329 wxUniversalRepaintProc
, (XtPointer
) this);
336 m_frameMenuBar
->DestroyMenuBar();
338 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
339 #if MOTIF_MENUBAR_DELETE_FIX
340 GetMenuBar()->SetMainWidget((WXWidget
) NULL
);
342 delete m_frameMenuBar
;
343 m_frameMenuBar
= NULL
;
346 wxTopLevelWindows
.DeleteObject(this);
347 wxModelessWindows
.DeleteObject(this);
349 if (m_frameStatusBar
)
350 delete m_frameStatusBar
;
356 for (i = 0; i < wxMAX_STATUS; i++)
357 if (statusTextWidget[i])
358 XtDestroyWidget (statusTextWidget[i]);
361 XtDestroyWidget (statusLineForm);
363 if (statusLineWidget)
364 XtDestroyWidget (statusLineWidget);
369 wxDeleteWindowFromTable((Widget
) m_workArea
);
371 XtDestroyWidget ((Widget
) m_workArea
);
376 wxDeleteWindowFromTable((Widget
) m_frameWidget
);
377 XtDestroyWidget ((Widget
) m_frameWidget
);
381 XtDestroyWidget ((Widget
) m_frameShell
);
383 SetMainWidget((WXWidget
) NULL
);
385 /* Check if it's the last top-level window */
387 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
389 wxTheApp
->SetTopWindow(NULL
);
391 if (wxTheApp
->GetExitOnFrameDelete())
393 // Signal to the app that we're going to close
394 wxTheApp
->ExitMainLoop();
400 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
401 void wxFrame::GetClientSize(int *x
, int *y
) const
404 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
406 if (m_frameStatusBar
)
409 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
416 m_frameToolBar
->GetSize(& tbw
, & tbh
);
417 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
422 #endif // wxUSE_TOOLBAR
424 if (GetMenuBar() != (wxMenuBar*) NULL)
426 // it seems that if a frame holds a panel, the menu bar size
427 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
428 bool hasSubPanel = FALSE;
429 for(wxNode* node = GetChildren().First(); node; node = node->Next())
431 wxWindow *win = (wxWindow *)node->Data();
432 hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)));
439 XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL);
448 // Set the client size (i.e. leave the calculation of borders etc.
450 void wxFrame::DoSetClientSize(int width
, int height
)
452 // Calculate how large the new main window should be
453 // by finding the difference between the client area and the
454 // main window area, and adding on to the new client area
456 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
460 if (m_frameStatusBar
)
463 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
470 m_frameToolBar
->GetSize(& tbw
, & tbh
);
471 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
476 #endif // wxUSE_TOOLBAR
478 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
482 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
483 sizeEvent
.SetEventObject(this);
485 GetEventHandler()->ProcessEvent(sizeEvent
);
489 void wxFrame::GetSize(int *width
, int *height
) const
492 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
493 *width
= xx
; *height
= yy
;
496 void wxFrame::GetPosition(int *x
, int *y
) const
498 Window parent_window
= XtWindow((Widget
) m_frameShell
),
499 next_parent
= XtWindow((Widget
) m_frameShell
),
500 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
502 // search for the parent that is child of ROOT, because the WM may
503 // reparent twice and notify only the next parent (like FVWM)
504 while (next_parent
!= root
) {
505 Window
*theChildren
; unsigned int n
;
506 parent_window
= next_parent
;
507 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
508 &next_parent
, &theChildren
, &n
);
509 XFree(theChildren
); // not needed
511 int xx
, yy
; unsigned int dummy
;
512 XGetGeometry(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
513 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
518 void wxFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
521 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
523 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
525 XtVaSetValues((Widget
) m_frameWidget
, XmNwidth
, width
, NULL
);
527 XtVaSetValues((Widget
) m_frameWidget
, XmNheight
, height
, NULL
);
529 if (!(height
== -1 && width
== -1))
533 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
534 sizeEvent
.SetEventObject(this);
536 GetEventHandler()->ProcessEvent(sizeEvent
);
540 bool wxFrame::Show(bool show
)
543 return wxWindow::Show(show
);
545 m_visibleStatus
= show
; /* show-&-hide fix */
549 XtMapWidget((Widget
) m_frameShell
);
550 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), XtWindow((Widget
) m_frameShell
));
552 XtUnmapWidget((Widget
) m_frameShell
);
553 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
558 void wxFrame::Iconize(bool iconize
)
564 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, (Boolean
)iconize
, NULL
);
567 // Equivalent to maximize/restore in Windows
568 void wxFrame::Maximize(bool maximize
)
572 if (maximize
&& m_frameShell
)
573 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, FALSE
, NULL
);
576 bool wxFrame::IsIconized() const
582 XtVaGetValues((Widget
) m_frameShell
, XmNiconic
, &iconic
, NULL
);
587 bool wxFrame::IsMaximized(void) const
589 // No maximizing in Motif (?)
593 void wxFrame::SetTitle(const wxString
& title
)
595 if (title
== m_title
)
601 XtVaSetValues((Widget
) m_frameShell
,
602 XmNtitle
, (const char*) title
,
603 XmNiconName
, (const char*) title
,
607 void wxFrame::SetIcon(const wxIcon
& icon
)
614 if (!icon
.Ok() || !icon
.GetPixmap())
617 XtVaSetValues((Widget
) m_frameShell
, XtNiconPixmap
, icon
.GetPixmap(), NULL
);
620 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
621 const wxString
& name
)
623 wxStatusBar
*statusBar
= NULL
;
625 statusBar
= new wxStatusBar(this, id
, wxPoint(0, 0), wxSize(100, 20),
628 // Set the height according to the font and the border size
629 wxClientDC
dc(statusBar
);
630 dc
.SetFont(statusBar
->GetFont());
633 dc
.GetTextExtent("X", &x
, &y
);
635 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
637 statusBar
->SetSize(-1, -1, 100, height
);
639 statusBar
->SetFieldsCount(number
);
643 wxStatusBar
* wxFrame::CreateStatusBar(int number
, long style
, wxWindowID id
,
644 const wxString
& name
)
646 // Calling CreateStatusBar twice is an error.
647 wxCHECK_MSG( m_frameStatusBar
== NULL
, FALSE
,
648 "recreating status bar in wxFrame" );
650 m_frameStatusBar
= OnCreateStatusBar(number
, style
, id
,
652 if ( m_frameStatusBar
)
655 return m_frameStatusBar
;
661 void wxFrame::SetStatusText(const wxString
& text
, int number
)
663 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set text for" );
665 m_frameStatusBar
->SetStatusText(text
, number
);
668 void wxFrame::SetStatusWidths(int n
, const int widths_field
[])
670 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set widths for" );
672 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
676 void wxFrame::PositionStatusBar()
678 if (!m_frameStatusBar
)
682 GetClientSize(&w
, &h
);
684 m_frameStatusBar
->GetSize(&sw
, &sh
);
686 // Since we wish the status bar to be directly under the client area,
687 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
688 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
691 WXWidget
wxFrame::GetMenuBarWidget() const
694 return GetMenuBar()->GetMainWidget();
696 return (WXWidget
) NULL
;
699 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
703 m_frameMenuBar
= NULL
;
707 // Currently can't set it twice
708 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
712 m_frameMenuBar
->DestroyMenuBar();
713 delete m_frameMenuBar
;
716 m_frameMenuBar
= menuBar
;
717 m_frameMenuBar
->CreateMenuBar(this);
722 // Work out max. size
723 wxNode
*node
= GetChildren().First();
728 // Find a child that's a subwindow, but not a dialog box.
729 wxWindow
*win
= (wxWindow
*)node
->Data();
731 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
732 !win
->IsKindOf(CLASSINFO(wxDialog
)))
736 win
->GetSize(&width
, &height
);
737 win
->GetPosition(&x
, &y
);
739 if ((x
+ width
) > max_width
)
740 max_width
= x
+ width
;
741 if ((y
+ height
) > max_height
)
742 max_height
= y
+ height
;
746 SetClientSize(max_width
, max_height
);
749 // Responds to colour changes, and passes event on to children.
750 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
752 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
755 if ( m_frameStatusBar
)
757 wxSysColourChangedEvent event2
;
758 event2
.SetEventObject( m_frameStatusBar
);
759 m_frameStatusBar
->ProcessEvent(event2
);
762 // Propagate the event to the non-top-level children
763 wxWindow::OnSysColourChanged(event
);
766 // Default resizing behaviour - if only ONE subwindow,
767 // resize to client rectangle size
768 void wxFrame::OnSize(wxSizeEvent
& event
)
770 // if we're using constraints - do use them
771 #if wxUSE_CONSTRAINTS
772 if ( GetAutoLayout() ) {
778 // do we have _exactly_ one child?
779 wxWindow
*child
= NULL
;
780 for ( wxNode
*node
= GetChildren().First(); node
; node
= node
->Next() )
782 wxWindow
*win
= (wxWindow
*)node
->Data();
783 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) &&
784 !win
->IsKindOf(CLASSINFO(wxDialog
)) &&
785 (win
!= GetStatusBar())
787 && (win
!= GetToolBar())
788 #endif // wxUSE_TOOLBAR
792 return; // it's our second subwindow - nothing to do
798 // we have exactly one child - set it's size to fill the whole frame
799 int clientW
, clientH
;
800 GetClientSize(&clientW
, &clientH
);
805 child
->SetSize(x
, y
, clientW
, clientH
);
809 // Default activation behaviour - set the focus for the first child
811 void wxFrame::OnActivate(wxActivateEvent
& event
)
813 for(wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
815 // Find a child that's a subwindow, but not a dialog box.
816 wxWindow
*child
= (wxWindow
*)node
->Data();
817 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
818 !child
->IsKindOf(CLASSINFO(wxDialog
)))
826 // The default implementation for the close window event.
827 // OnClose for backward compatibility.
829 void wxFrame::OnCloseWindow(wxCloseEvent
& event
)
834 // Destroy the window (delayed, if a managed window)
835 bool wxFrame::Destroy()
837 if (!wxPendingDelete
.Member(this))
838 wxPendingDelete
.Append(this);
842 // Default menu selection behaviour - display a help string
843 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
847 if (event
.GetMenuId() == -1)
851 wxMenuBar
*menuBar
= GetMenuBar();
854 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
855 if (helpString
!= "")
856 SetStatusText(helpString
);
862 wxMenuBar
*wxFrame::GetMenuBar() const
864 return m_frameMenuBar
;
867 void wxFrame::Centre(int direction
)
869 int display_width
, display_height
, width
, height
, x
, y
;
870 wxDisplaySize(&display_width
, &display_height
);
872 GetSize(&width
, &height
);
875 if (direction
& wxHORIZONTAL
)
876 x
= (int)((display_width
- width
)/2);
877 if (direction
& wxVERTICAL
)
878 y
= (int)((display_height
- height
)/2);
880 SetSize(x
, y
, width
, height
);
883 // Call this to simulate a menu command
884 void wxFrame::Command(int id
)
889 void wxFrame::ProcessCommand(int id
)
891 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
892 commandEvent
.SetInt( id
);
893 commandEvent
.SetEventObject( this );
895 wxMenuBar
*bar
= GetMenuBar() ;
899 /* TODO: check the menu item if required
900 wxMenuItem *item = bar->FindItemForId(id) ;
901 if (item && item->IsCheckable())
903 bar->Check(id,!bar->Checked(id)) ;
907 wxEvtHandler
* evtHandler
= GetEventHandler();
909 evtHandler
->ProcessEvent(commandEvent
);
912 // Checks if there is a toolbar, and returns the first free client position
913 wxPoint
wxFrame::GetClientAreaOrigin() const
920 GetToolBar()->GetSize(& w
, & h
);
922 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
931 #endif // wxUSE_TOOLBAR
936 void wxFrame::ScreenToClient(int *x
, int *y
) const
938 wxWindow::ScreenToClient(x
, y
);
940 // We may be faking the client origin.
941 // So a window that's really at (0, 30) may appear
942 // (to wxWin apps) to be at (0, 0).
943 wxPoint
pt(GetClientAreaOrigin());
948 void wxFrame::ClientToScreen(int *x
, int *y
) const
950 // We may be faking the client origin.
951 // So a window that's really at (0, 30) may appear
952 // (to wxWin apps) to be at (0, 0).
953 wxPoint
pt1(GetClientAreaOrigin());
957 wxWindow::ClientToScreen(x
, y
);
961 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
963 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
964 "recreating toolbar in wxFrame" );
966 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
979 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
981 return new wxToolBar(this, id
, wxPoint(0, 0), wxSize(100, 24), style
, name
);
984 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
986 m_frameToolBar
= toolbar
;
989 wxToolBar
*wxFrame::GetToolBar() const
991 return m_frameToolBar
;
994 void wxFrame::PositionToolBar()
998 GetClientSize(& cw
, &ch
);
1003 GetToolBar()->GetSize(& tw
, & th
);
1005 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1007 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
1008 // means, pretend we don't have toolbar/status bar, so we
1009 // have the original client size.
1010 GetToolBar()->SetSize(0, 0, tw
, ch
+ th
, wxSIZE_NO_ADJUSTMENTS
);
1014 // Use the 'real' position
1015 GetToolBar()->SetSize(0, 0, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
1019 #endif // wxUSE_TOOLBAR
1021 void wxFrame::CaptureMouse()
1026 if (GetMainWidget())
1027 XtAddGrab((Widget
) m_frameShell
, TRUE
, FALSE
);
1028 m_winCaptured
= TRUE
;
1031 void wxFrame::ReleaseMouse()
1036 if (GetMainWidget())
1037 XtRemoveGrab((Widget
) m_frameShell
);
1038 m_winCaptured
= FALSE
;
1041 void wxFrame::Raise(void)
1043 Window parent_window
= XtWindow((Widget
) m_frameShell
),
1044 next_parent
= XtWindow((Widget
) m_frameShell
),
1045 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
1046 // search for the parent that is child of ROOT, because the WM may
1047 // reparent twice and notify only the next parent (like FVWM)
1048 while (next_parent
!= root
) {
1049 Window
*theChildren
; unsigned int n
;
1050 parent_window
= next_parent
;
1051 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
1052 &next_parent
, &theChildren
, &n
);
1053 XFree(theChildren
); // not needed
1055 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
1058 void wxFrame::Lower(void)
1060 Window parent_window
= XtWindow((Widget
) m_frameShell
),
1061 next_parent
= XtWindow((Widget
) m_frameShell
),
1062 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
1063 // search for the parent that is child of ROOT, because the WM may
1064 // reparent twice and notify only the next parent (like FVWM)
1065 while (next_parent
!= root
) {
1066 Window
*theChildren
; unsigned int n
;
1067 parent_window
= next_parent
;
1068 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
1069 &next_parent
, &theChildren
, &n
);
1070 XFree(theChildren
); // not needed
1072 XLowerWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
1075 void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
1076 XmAnyCallbackStruct
*cbs
)
1078 // wxDebugMsg("focus proc from frame %ld\n",(long)frame);
1080 // wxFrame *frame = (wxFrame *)clientData;
1081 // frame->GetEventHandler()->OnSetFocus();
1084 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
1085 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
1086 XCrossingEvent
* event
)
1088 wxFrame
*frame
= (wxFrame
*)wxGetWindowFromTable((Widget
)clientData
);
1091 XEvent
*e
= (XEvent
*)event
;
1093 if (e
->xany
.type
== MapNotify
)
1096 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
1097 if (!frame
->GetVisibleStatus())
1099 /* We really wanted this to be hidden! */
1100 XtUnmapWidget((Widget
) frame
->GetShellWidget());
1103 else if (e
->xany
.type
== UnmapNotify
)
1105 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)True
, NULL
);
1110 bool wxFrame::PreResize()
1114 #endif // wxUSE_TOOLBAR
1115 PositionStatusBar();
1119 WXWidget
wxFrame::GetClientWidget() const
1121 return m_clientArea
;
1124 void wxFrame::ChangeFont(bool keepOriginalSize
)
1129 void wxFrame::ChangeBackgroundColour()
1131 if (GetClientWidget())
1132 DoChangeBackgroundColour(GetClientWidget(), m_backgroundColour
);
1135 void wxFrame::ChangeForegroundColour()
1137 if (GetClientWidget())
1138 DoChangeForegroundColour(GetClientWidget(), m_foregroundColour
);
1141 void wxCloseFrameCallback(Widget widget
, XtPointer client_data
, XmAnyCallbackStruct
*cbs
)
1143 wxFrame
*frame
= (wxFrame
*)client_data
;
1145 wxCloseEvent
closeEvent(wxEVT_CLOSE_WINDOW
, frame
->GetId());
1146 closeEvent
.SetEventObject(frame
);
1148 // May delete the frame (with delayed deletion)
1149 frame
->GetEventHandler()->ProcessEvent(closeEvent
);