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 been
153 // MB TODO: something better than these arbitrary values ?
154 // VZ should use X resources for this...
160 int displayW
, displayH
;
161 wxDisplaySize( &displayW
, &displayH
);
165 x
= (displayW
- width
) / 2;
170 y
= (displayH
- height
) / 2;
176 // Change suggested by Matthew Flatt
177 m_frameShell
= (WXWidget
)XtAppCreateShell
180 wxTheApp
->GetClassName(),
181 topLevelShellWidgetClass
,
182 (Display
*) wxGetDisplay(),
189 m_frameShell
= wxTheApp
->GetTopLevelWidget();
190 wxTopLevelUsed
= TRUE
;
193 XtVaSetValues((Widget
) m_frameShell
,
194 // Allows menu to resize
195 XmNallowShellResize
, True
,
196 XmNdeleteResponse
, XmDO_NOTHING
,
197 XmNmappedWhenManaged
, False
,
198 XmNiconic
, (style
& wxICONIZE
) ? TRUE
: FALSE
,
202 XtVaSetValues((Widget
) m_frameShell
,
203 XmNtitle
, (const char*) title
,
206 m_frameWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
207 xmMainWindowWidgetClass
, (Widget
) m_frameShell
,
208 XmNresizePolicy
, XmRESIZE_NONE
,
211 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
212 xmFormWidgetClass
, (Widget
) m_frameWidget
,
213 XmNresizePolicy
, XmRESIZE_NONE
,
216 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
217 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
220 XmNrightAttachment
, XmATTACH_FORM
,
221 XmNleftAttachment
, XmATTACH_FORM
,
222 XmNtopAttachment
, XmATTACH_FORM
,
223 XmNbottomAttachment
, XmATTACH_FORM
,
224 // XmNresizePolicy, XmRESIZE_ANY,
227 wxLogDebug("Created frame (0x%08x) with work area 0x%08x and client "
228 "area 0x%08x", m_frameWidget
, m_workArea
, m_clientArea
);
230 XtAddEventHandler((Widget
) m_clientArea
, ExposureMask
,FALSE
,
231 wxUniversalRepaintProc
, (XtPointer
) this);
233 XtVaSetValues((Widget
) m_frameWidget
,
234 XmNworkWindow
, (Widget
) m_workArea
,
237 XtManageChild((Widget
) m_clientArea
);
238 XtManageChild((Widget
) m_workArea
);
240 wxAddWindowToTable((Widget
) m_workArea
, this);
244 XtOverrideTranslations((Widget
) m_workArea
,
245 ptr
= XtParseTranslationTable("<Configure>: resize()"));
249 XtAddCallback((Widget
) m_workArea
, XmNfocusCallback
,
250 (XtCallbackProc
)wxFrameFocusProc
, (XtPointer
)this);
252 /* Part of show-&-hide fix */
253 XtAddEventHandler((Widget
) m_frameShell
, StructureNotifyMask
,
254 False
, (XtEventHandler
)wxFrameMapProc
,
255 (XtPointer
)m_workArea
);
258 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
260 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
262 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
264 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
266 m_mainWidget
= m_frameWidget
;
270 // This patch comes from Torsten Liermann lier@lier1.muc.de
271 if (XmIsMotifWMRunning( (Widget
) m_frameShell
))
274 if (style
& wxRESIZE_BORDER
)
275 decor
|= MWM_DECOR_RESIZEH
;
276 if (style
& wxSYSTEM_MENU
)
277 decor
|= MWM_DECOR_MENU
;
278 if ((style
& wxCAPTION
) ||
279 (style
& wxTINY_CAPTION_HORIZ
) ||
280 (style
& wxTINY_CAPTION_VERT
))
281 decor
|= MWM_DECOR_TITLE
;
282 if (style
& wxTHICK_FRAME
)
283 decor
|= MWM_DECOR_BORDER
;
284 if (style
& wxTHICK_FRAME
)
285 decor
|= MWM_DECOR_BORDER
;
286 if (style
& wxMINIMIZE_BOX
)
287 decor
|= MWM_DECOR_MINIMIZE
;
288 if (style
& wxMAXIMIZE_BOX
)
289 decor
|= MWM_DECOR_MAXIMIZE
;
290 XtVaSetValues((Widget
) m_frameShell
,XmNmwmDecorations
,decor
,NULL
) ;
292 // This allows non-Motif window managers to support at least the
293 // no-decorations case.
297 XtVaSetValues((Widget
) m_frameShell
,XmNoverrideRedirect
,TRUE
,NULL
);
299 XtRealizeWidget((Widget
) m_frameShell
);
301 // Intercept CLOSE messages from the window manager
302 Atom WM_DELETE_WINDOW
= XmInternAtom(XtDisplay((Widget
) m_frameShell
), "WM_DELETE_WINDOW", False
);
303 #if (XmREVISION > 1 || XmVERSION > 1)
304 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (XtPointer
)this);
307 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (caddr_t
)this);
309 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (void (*)())wxCloseFrameCallback
, (caddr_t
)this);
313 ChangeBackgroundColour();
317 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
318 sizeEvent
.SetEventObject(this);
320 GetEventHandler()->ProcessEvent(sizeEvent
);
327 m_isBeingDeleted
= TRUE
;
330 XtRemoveEventHandler((Widget
) m_clientArea
, ExposureMask
, FALSE
,
331 wxUniversalRepaintProc
, (XtPointer
) this);
338 m_frameMenuBar
->DestroyMenuBar();
340 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
341 #if MOTIF_MENUBAR_DELETE_FIX
342 GetMenuBar()->SetMainWidget((WXWidget
) NULL
);
344 delete m_frameMenuBar
;
345 m_frameMenuBar
= NULL
;
348 wxTopLevelWindows
.DeleteObject(this);
349 wxModelessWindows
.DeleteObject(this);
351 if (m_frameStatusBar
)
352 delete m_frameStatusBar
;
358 for (i = 0; i < wxMAX_STATUS; i++)
359 if (statusTextWidget[i])
360 XtDestroyWidget (statusTextWidget[i]);
363 XtDestroyWidget (statusLineForm);
365 if (statusLineWidget)
366 XtDestroyWidget (statusLineWidget);
371 wxDeleteWindowFromTable((Widget
) m_workArea
);
373 XtDestroyWidget ((Widget
) m_workArea
);
378 wxDeleteWindowFromTable((Widget
) m_frameWidget
);
379 XtDestroyWidget ((Widget
) m_frameWidget
);
383 XtDestroyWidget ((Widget
) m_frameShell
);
385 SetMainWidget((WXWidget
) NULL
);
387 /* Check if it's the last top-level window */
389 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
391 wxTheApp
->SetTopWindow(NULL
);
393 if (wxTheApp
->GetExitOnFrameDelete())
395 // Signal to the app that we're going to close
396 wxTheApp
->ExitMainLoop();
402 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
403 void wxFrame::DoGetClientSize(int *x
, int *y
) const
406 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
408 if (m_frameStatusBar
)
411 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
418 m_frameToolBar
->GetSize(& tbw
, & tbh
);
419 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
424 #endif // wxUSE_TOOLBAR
426 if (GetMenuBar() != (wxMenuBar*) NULL)
428 // it seems that if a frame holds a panel, the menu bar size
429 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
430 bool hasSubPanel = FALSE;
431 for(wxNode* node = GetChildren().First(); node; node = node->Next())
433 wxWindow *win = (wxWindow *)node->Data();
434 hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)));
441 XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL);
450 // Set the client size (i.e. leave the calculation of borders etc.
452 void wxFrame::DoSetClientSize(int width
, int height
)
454 // Calculate how large the new main window should be
455 // by finding the difference between the client area and the
456 // main window area, and adding on to the new client area
458 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
462 if (m_frameStatusBar
)
465 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
472 m_frameToolBar
->GetSize(& tbw
, & tbh
);
473 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
478 #endif // wxUSE_TOOLBAR
480 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
484 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
485 sizeEvent
.SetEventObject(this);
487 GetEventHandler()->ProcessEvent(sizeEvent
);
491 void wxFrame::DoGetSize(int *width
, int *height
) const
494 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
495 *width
= xx
; *height
= yy
;
498 void wxFrame::DoGetPosition(int *x
, int *y
) const
500 Window parent_window
= XtWindow((Widget
) m_frameShell
),
501 next_parent
= XtWindow((Widget
) m_frameShell
),
502 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
504 // search for the parent that is child of ROOT, because the WM may
505 // reparent twice and notify only the next parent (like FVWM)
506 while (next_parent
!= root
) {
507 Window
*theChildren
; unsigned int n
;
508 parent_window
= next_parent
;
509 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
510 &next_parent
, &theChildren
, &n
);
511 XFree(theChildren
); // not needed
513 int xx
, yy
; unsigned int dummy
;
514 XGetGeometry(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
515 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
520 void wxFrame::DoSetSize(int x
, int y
, int width
, int height
, int WXUNUSED(sizeFlags
))
523 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
525 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
527 XtVaSetValues((Widget
) m_frameWidget
, XmNwidth
, width
, NULL
);
529 XtVaSetValues((Widget
) m_frameWidget
, XmNheight
, height
, NULL
);
531 if (!(height
== -1 && width
== -1))
535 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
536 sizeEvent
.SetEventObject(this);
538 GetEventHandler()->ProcessEvent(sizeEvent
);
542 bool wxFrame::Show(bool show
)
545 return wxWindow::Show(show
);
547 m_visibleStatus
= show
; /* show-&-hide fix */
551 XtMapWidget((Widget
) m_frameShell
);
552 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), XtWindow((Widget
) m_frameShell
));
554 XtUnmapWidget((Widget
) m_frameShell
);
555 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
560 void wxFrame::Iconize(bool iconize
)
566 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, (Boolean
)iconize
, NULL
);
569 // Equivalent to maximize/restore in Windows
570 void wxFrame::Maximize(bool maximize
)
574 if (maximize
&& m_frameShell
)
575 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, FALSE
, NULL
);
578 bool wxFrame::IsIconized() const
584 XtVaGetValues((Widget
) m_frameShell
, XmNiconic
, &iconic
, NULL
);
589 bool wxFrame::IsMaximized(void) const
591 // No maximizing in Motif (?)
595 void wxFrame::SetTitle(const wxString
& title
)
597 if (title
== m_title
)
603 XtVaSetValues((Widget
) m_frameShell
,
604 XmNtitle
, (const char*) title
,
605 XmNiconName
, (const char*) title
,
609 void wxFrame::SetIcon(const wxIcon
& icon
)
616 if (!icon
.Ok() || !icon
.GetPixmap())
619 XtVaSetValues((Widget
) m_frameShell
, XtNiconPixmap
, icon
.GetPixmap(), NULL
);
622 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
623 const wxString
& name
)
625 wxStatusBar
*statusBar
= NULL
;
627 statusBar
= new wxStatusBar(this, id
, wxPoint(0, 0), wxSize(100, 20),
630 // Set the height according to the font and the border size
631 wxClientDC
dc(statusBar
);
632 dc
.SetFont(statusBar
->GetFont());
635 dc
.GetTextExtent("X", &x
, &y
);
637 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
639 statusBar
->SetSize(-1, -1, 100, height
);
641 statusBar
->SetFieldsCount(number
);
645 wxStatusBar
* wxFrame::CreateStatusBar(int number
, long style
, wxWindowID id
,
646 const wxString
& name
)
648 // Calling CreateStatusBar twice is an error.
649 wxCHECK_MSG( m_frameStatusBar
== NULL
, FALSE
,
650 "recreating status bar in wxFrame" );
652 m_frameStatusBar
= OnCreateStatusBar(number
, style
, id
,
654 if ( m_frameStatusBar
)
657 return m_frameStatusBar
;
663 void wxFrame::SetStatusText(const wxString
& text
, int number
)
665 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set text for" );
667 m_frameStatusBar
->SetStatusText(text
, number
);
670 void wxFrame::SetStatusWidths(int n
, const int widths_field
[])
672 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set widths for" );
674 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
678 void wxFrame::PositionStatusBar()
680 if (!m_frameStatusBar
)
684 GetClientSize(&w
, &h
);
686 m_frameStatusBar
->GetSize(&sw
, &sh
);
688 // Since we wish the status bar to be directly under the client area,
689 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
690 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
693 WXWidget
wxFrame::GetMenuBarWidget() const
696 return GetMenuBar()->GetMainWidget();
698 return (WXWidget
) NULL
;
701 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
705 m_frameMenuBar
= NULL
;
709 // Currently can't set it twice
710 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
714 m_frameMenuBar
->DestroyMenuBar();
715 delete m_frameMenuBar
;
718 m_frameMenuBar
= menuBar
;
719 m_frameMenuBar
->CreateMenuBar(this);
724 // Work out max. size
725 wxNode
*node
= GetChildren().First();
730 // Find a child that's a subwindow, but not a dialog box.
731 wxWindow
*win
= (wxWindow
*)node
->Data();
733 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
734 !win
->IsKindOf(CLASSINFO(wxDialog
)))
738 win
->GetSize(&width
, &height
);
739 win
->GetPosition(&x
, &y
);
741 if ((x
+ width
) > max_width
)
742 max_width
= x
+ width
;
743 if ((y
+ height
) > max_height
)
744 max_height
= y
+ height
;
748 SetClientSize(max_width
, max_height
);
751 // Responds to colour changes, and passes event on to children.
752 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
754 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
757 if ( m_frameStatusBar
)
759 wxSysColourChangedEvent event2
;
760 event2
.SetEventObject( m_frameStatusBar
);
761 m_frameStatusBar
->ProcessEvent(event2
);
764 // Propagate the event to the non-top-level children
765 wxWindow::OnSysColourChanged(event
);
768 // Default resizing behaviour - if only ONE subwindow,
769 // resize to client rectangle size
770 void wxFrame::OnSize(wxSizeEvent
& WXUNUSED(event
))
772 // if we're using constraints - do use them
773 #if wxUSE_CONSTRAINTS
774 if ( GetAutoLayout() ) {
780 // do we have _exactly_ one child?
781 wxWindow
*child
= NULL
;
782 for ( wxNode
*node
= GetChildren().First(); node
; node
= node
->Next() )
784 wxWindow
*win
= (wxWindow
*)node
->Data();
785 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) &&
786 !win
->IsKindOf(CLASSINFO(wxDialog
)) &&
787 (win
!= GetStatusBar())
789 && (win
!= GetToolBar())
790 #endif // wxUSE_TOOLBAR
794 return; // it's our second subwindow - nothing to do
800 // we have exactly one child - set it's size to fill the whole frame
801 int clientW
, clientH
;
802 GetClientSize(&clientW
, &clientH
);
807 child
->SetSize(x
, y
, clientW
, clientH
);
811 // Default activation behaviour - set the focus for the first child
813 void wxFrame::OnActivate(wxActivateEvent
& event
)
815 if (!event
.GetActive())
818 for(wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
820 // Find a child that's a subwindow, but not a dialog box.
821 wxWindow
*child
= (wxWindow
*)node
->Data();
822 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
823 !child
->IsKindOf(CLASSINFO(wxDialog
)))
831 // The default implementation for the close window event.
832 // OnClose for backward compatibility.
834 void wxFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
839 // Destroy the window (delayed, if a managed window)
840 bool wxFrame::Destroy()
842 if (!wxPendingDelete
.Member(this))
843 wxPendingDelete
.Append(this);
847 // Default menu selection behaviour - display a help string
848 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
852 if (event
.GetMenuId() == -1)
856 wxMenuBar
*menuBar
= GetMenuBar();
859 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
860 if (helpString
!= "")
861 SetStatusText(helpString
);
867 wxMenuBar
*wxFrame::GetMenuBar() const
869 return m_frameMenuBar
;
872 void wxFrame::Centre(int direction
)
874 int display_width
, display_height
, width
, height
, x
, y
;
875 wxDisplaySize(&display_width
, &display_height
);
877 GetSize(&width
, &height
);
880 if (direction
& wxHORIZONTAL
)
881 x
= (int)((display_width
- width
)/2);
882 if (direction
& wxVERTICAL
)
883 y
= (int)((display_height
- height
)/2);
885 SetSize(x
, y
, width
, height
);
888 // Call this to simulate a menu command
889 void wxFrame::Command(int id
)
894 void wxFrame::ProcessCommand(int id
)
896 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
897 commandEvent
.SetInt( id
);
898 commandEvent
.SetEventObject( this );
900 wxMenuBar
*bar
= GetMenuBar() ;
904 /* TODO: check the menu item if required
905 wxMenuItem *item = bar->FindItemForId(id) ;
906 if (item && item->IsCheckable())
908 bar->Check(id,!bar->Checked(id)) ;
912 wxEvtHandler
* evtHandler
= GetEventHandler();
914 evtHandler
->ProcessEvent(commandEvent
);
917 // Checks if there is a toolbar, and returns the first free client position
918 wxPoint
wxFrame::GetClientAreaOrigin() const
925 GetToolBar()->GetSize(& w
, & h
);
927 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
936 #endif // wxUSE_TOOLBAR
941 void wxFrame::ScreenToClient(int *x
, int *y
) const
943 wxWindow::ScreenToClient(x
, y
);
945 // We may be faking the client origin.
946 // So a window that's really at (0, 30) may appear
947 // (to wxWin apps) to be at (0, 0).
948 wxPoint
pt(GetClientAreaOrigin());
953 void wxFrame::ClientToScreen(int *x
, int *y
) const
955 // We may be faking the client origin.
956 // So a window that's really at (0, 30) may appear
957 // (to wxWin apps) to be at (0, 0).
958 wxPoint
pt1(GetClientAreaOrigin());
962 wxWindow::ClientToScreen(x
, y
);
966 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
968 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
969 "recreating toolbar in wxFrame" );
971 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
984 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
986 return new wxToolBar(this, id
, wxPoint(0, 0), wxSize(100, 24), style
, name
);
989 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
991 m_frameToolBar
= toolbar
;
994 wxToolBar
*wxFrame::GetToolBar() const
996 return m_frameToolBar
;
999 void wxFrame::PositionToolBar()
1003 GetClientSize(& cw
, &ch
);
1008 GetToolBar()->GetSize(& tw
, & th
);
1010 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
1012 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
1013 // means, pretend we don't have toolbar/status bar, so we
1014 // have the original client size.
1015 GetToolBar()->SetSize(0, 0, tw
, ch
+ th
, wxSIZE_NO_ADJUSTMENTS
);
1019 // Use the 'real' position
1020 GetToolBar()->SetSize(0, 0, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
1024 #endif // wxUSE_TOOLBAR
1026 void wxFrame::CaptureMouse()
1031 if (GetMainWidget())
1032 XtAddGrab((Widget
) m_frameShell
, TRUE
, FALSE
);
1033 m_winCaptured
= TRUE
;
1036 void wxFrame::ReleaseMouse()
1041 if (GetMainWidget())
1042 XtRemoveGrab((Widget
) m_frameShell
);
1043 m_winCaptured
= FALSE
;
1046 void wxFrame::Raise(void)
1048 Window parent_window
= XtWindow((Widget
) m_frameShell
),
1049 next_parent
= XtWindow((Widget
) m_frameShell
),
1050 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
1051 // search for the parent that is child of ROOT, because the WM may
1052 // reparent twice and notify only the next parent (like FVWM)
1053 while (next_parent
!= root
) {
1054 Window
*theChildren
; unsigned int n
;
1055 parent_window
= next_parent
;
1056 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
1057 &next_parent
, &theChildren
, &n
);
1058 XFree(theChildren
); // not needed
1060 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
1063 void wxFrame::Lower(void)
1065 Window parent_window
= XtWindow((Widget
) m_frameShell
),
1066 next_parent
= XtWindow((Widget
) m_frameShell
),
1067 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
1068 // search for the parent that is child of ROOT, because the WM may
1069 // reparent twice and notify only the next parent (like FVWM)
1070 while (next_parent
!= root
) {
1071 Window
*theChildren
; unsigned int n
;
1072 parent_window
= next_parent
;
1073 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
1074 &next_parent
, &theChildren
, &n
);
1075 XFree(theChildren
); // not needed
1077 XLowerWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
1080 void wxFrameFocusProc(Widget
WXUNUSED(workArea
), XtPointer
WXUNUSED(clientData
),
1081 XmAnyCallbackStruct
*WXUNUSED(cbs
))
1083 // wxDebugMsg("focus proc from frame %ld\n",(long)frame);
1085 // wxFrame *frame = (wxFrame *)clientData;
1086 // frame->GetEventHandler()->OnSetFocus();
1089 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
1090 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
1091 XCrossingEvent
* event
)
1093 wxFrame
*frame
= (wxFrame
*)wxGetWindowFromTable((Widget
)clientData
);
1096 XEvent
*e
= (XEvent
*)event
;
1098 if (e
->xany
.type
== MapNotify
)
1101 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
1102 if (!frame
->GetVisibleStatus())
1104 /* We really wanted this to be hidden! */
1105 XtUnmapWidget((Widget
) frame
->GetShellWidget());
1108 else if (e
->xany
.type
== UnmapNotify
)
1110 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)True
, NULL
);
1115 bool wxFrame::PreResize()
1119 #endif // wxUSE_TOOLBAR
1120 PositionStatusBar();
1124 WXWidget
wxFrame::GetClientWidget() const
1126 return m_clientArea
;
1129 void wxFrame::ChangeFont(bool WXUNUSED(keepOriginalSize
))
1134 void wxFrame::ChangeBackgroundColour()
1136 if (GetClientWidget())
1137 DoChangeBackgroundColour(GetClientWidget(), m_backgroundColour
);
1140 void wxFrame::ChangeForegroundColour()
1142 if (GetClientWidget())
1143 DoChangeForegroundColour(GetClientWidget(), m_foregroundColour
);
1146 void wxCloseFrameCallback(Widget
WXUNUSED(widget
), XtPointer client_data
, XmAnyCallbackStruct
*WXUNUSED(cbs
))
1148 wxFrame
*frame
= (wxFrame
*)client_data
;
1150 wxCloseEvent
closeEvent(wxEVT_CLOSE_WINDOW
, frame
->GetId());
1151 closeEvent
.SetEventObject(frame
);
1153 // May delete the frame (with delayed deletion)
1154 frame
->GetEventHandler()->ProcessEvent(closeEvent
);