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
;
94 m_windowParent
= 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_windowFont
= 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
; int y
= pos
.y
;
148 int width
= size
.x
; int height
= size
.y
;
151 // Change suggested by Matthew Flatt
152 m_frameShell
= (WXWidget
) XtAppCreateShell(name
, wxTheApp
->GetClassName(), topLevelShellWidgetClass
, (Display
*) wxGetDisplay(), NULL
, 0);
155 m_frameShell
= wxTheApp
->GetTopLevelWidget();
156 wxTopLevelUsed
= TRUE
;
159 XtVaSetValues((Widget
) m_frameShell
,
160 // Allows menu to resize
161 XmNallowShellResize
, True
,
162 XmNdeleteResponse
, XmDO_NOTHING
,
163 XmNmappedWhenManaged
, False
,
164 XmNiconic
, (style
& wxICONIZE
) ? TRUE
: FALSE
,
168 XtVaSetValues((Widget
) m_frameShell
,
169 XmNtitle
, (const char*) title
,
172 m_frameWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
173 xmMainWindowWidgetClass
, (Widget
) m_frameShell
,
174 XmNresizePolicy
, XmRESIZE_NONE
,
177 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
178 xmFormWidgetClass
, (Widget
) m_frameWidget
,
179 XmNresizePolicy
, XmRESIZE_NONE
,
182 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
183 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
186 XmNrightAttachment
, XmATTACH_FORM
,
187 XmNleftAttachment
, XmATTACH_FORM
,
188 XmNtopAttachment
, XmATTACH_FORM
,
189 XmNbottomAttachment
, XmATTACH_FORM
,
190 // XmNresizePolicy, XmRESIZE_ANY,
193 XtAddEventHandler((Widget
) m_clientArea
, ExposureMask
,FALSE
,
194 wxUniversalRepaintProc
, (XtPointer
) this);
196 XtVaSetValues((Widget
) m_frameWidget
,
197 XmNworkWindow
, (Widget
) m_workArea
,
200 XtManageChild((Widget
) m_clientArea
);
201 XtManageChild((Widget
) m_workArea
);
203 wxASSERT_MSG ((wxWidgetHashTable
->Get((long)m_workArea
) == (wxObject
*) NULL
), "Widget table clash in frame.cpp") ;
205 wxAddWindowToTable((Widget
) m_workArea
, this);
209 XtOverrideTranslations((Widget
) m_workArea
,
210 ptr
= XtParseTranslationTable("<Configure>: resize()"));
214 XtAddCallback((Widget
) m_workArea
, XmNfocusCallback
,
215 (XtCallbackProc
)wxFrameFocusProc
, (XtPointer
)this);
217 /* Part of show-&-hide fix */
218 XtAddEventHandler((Widget
) m_frameShell
, StructureNotifyMask
,
219 False
, (XtEventHandler
)wxFrameMapProc
,
220 (XtPointer
)m_workArea
);
223 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
225 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
227 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
229 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
231 m_mainWidget
= m_frameWidget
;
235 // This patch comes from Torsten Liermann lier@lier1.muc.de
236 if (XmIsMotifWMRunning( (Widget
) m_frameShell
))
239 if (style
& wxRESIZE_BORDER
)
240 decor
|= MWM_DECOR_RESIZEH
;
241 if (style
& wxSYSTEM_MENU
)
242 decor
|= MWM_DECOR_MENU
;
243 if ((style
& wxCAPTION
) ||
244 (style
& wxTINY_CAPTION_HORIZ
) ||
245 (style
& wxTINY_CAPTION_VERT
))
246 decor
|= MWM_DECOR_TITLE
;
247 if (style
& wxTHICK_FRAME
)
248 decor
|= MWM_DECOR_BORDER
;
249 if (style
& wxTHICK_FRAME
)
250 decor
|= MWM_DECOR_BORDER
;
251 if (style
& wxMINIMIZE_BOX
)
252 decor
|= MWM_DECOR_MINIMIZE
;
253 if (style
& wxMAXIMIZE_BOX
)
254 decor
|= MWM_DECOR_MAXIMIZE
;
255 XtVaSetValues((Widget
) m_frameShell
,XmNmwmDecorations
,decor
,NULL
) ;
257 // This allows non-Motif window managers to support at least the
258 // no-decorations case.
262 XtVaSetValues((Widget
) m_frameShell
,XmNoverrideRedirect
,TRUE
,NULL
);
264 XtRealizeWidget((Widget
) m_frameShell
);
266 // Intercept CLOSE messages from the window manager
267 Atom WM_DELETE_WINDOW
= XmInternAtom(XtDisplay((Widget
) m_frameShell
), "WM_DELETE_WINDOW", False
);
268 #if (XmREVISION > 1 || XmVERSION > 1)
269 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (XtPointer
)this);
272 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (caddr_t
)this);
274 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (void (*)())wxCloseFrameCallback
, (caddr_t
)this);
278 ChangeBackgroundColour();
282 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
283 sizeEvent
.SetEventObject(this);
285 GetEventHandler()->ProcessEvent(sizeEvent
);
293 XtRemoveEventHandler((Widget
) m_clientArea
, ExposureMask
, FALSE
,
294 wxUniversalRepaintProc
, (XtPointer
) this);
301 m_frameMenuBar
->DestroyMenuBar();
303 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
304 #if MOTIF_MENUBAR_DELETE_FIX
305 GetMenuBar()->SetMainWidget((WXWidget
) NULL
);
307 delete m_frameMenuBar
;
308 m_frameMenuBar
= NULL
;
311 wxTopLevelWindows
.DeleteObject(this);
312 wxModelessWindows
.DeleteObject(this);
314 if (m_frameStatusBar
)
315 delete m_frameStatusBar
;
321 for (i = 0; i < wxMAX_STATUS; i++)
322 if (statusTextWidget[i])
323 XtDestroyWidget (statusTextWidget[i]);
326 XtDestroyWidget (statusLineForm);
328 if (statusLineWidget)
329 XtDestroyWidget (statusLineWidget);
334 wxDeleteWindowFromTable((Widget
) m_workArea
);
336 XtDestroyWidget ((Widget
) m_workArea
);
341 wxDeleteWindowFromTable((Widget
) m_frameWidget
);
342 XtDestroyWidget ((Widget
) m_frameWidget
);
346 XtDestroyWidget ((Widget
) m_frameShell
);
348 SetMainWidget((WXWidget
) NULL
);
350 /* Check if it's the last top-level window */
352 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
354 wxTheApp
->SetTopWindow(NULL
);
356 if (wxTheApp
->GetExitOnFrameDelete())
358 // Signal to the app that we're going to close
359 wxTheApp
->ExitMainLoop();
365 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
366 void wxFrame::GetClientSize(int *x
, int *y
) const
369 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
371 if (m_frameStatusBar
)
374 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
381 m_frameToolBar
->GetSize(& tbw
, & tbh
);
382 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
387 #endif // wxUSE_TOOLBAR
389 if (GetMenuBar() != (wxMenuBar*) NULL)
391 // it seems that if a frame holds a panel, the menu bar size
392 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
393 bool hasSubPanel = FALSE;
394 for(wxNode* node = GetChildren().First(); node; node = node->Next())
396 wxWindow *win = (wxWindow *)node->Data();
397 hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)));
404 XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL);
413 // Set the client size (i.e. leave the calculation of borders etc.
415 void wxFrame::DoSetClientSize(int width
, int height
)
417 // Calculate how large the new main window should be
418 // by finding the difference between the client area and the
419 // main window area, and adding on to the new client area
421 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
425 if (m_frameStatusBar
)
428 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
435 m_frameToolBar
->GetSize(& tbw
, & tbh
);
436 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
441 #endif // wxUSE_TOOLBAR
443 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
447 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
448 sizeEvent
.SetEventObject(this);
450 GetEventHandler()->ProcessEvent(sizeEvent
);
454 void wxFrame::GetSize(int *width
, int *height
) const
457 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
458 *width
= xx
; *height
= yy
;
461 void wxFrame::GetPosition(int *x
, int *y
) const
463 Window parent_window
= XtWindow((Widget
) m_frameShell
),
464 next_parent
= XtWindow((Widget
) m_frameShell
),
465 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
467 // search for the parent that is child of ROOT, because the WM may
468 // reparent twice and notify only the next parent (like FVWM)
469 while (next_parent
!= root
) {
470 Window
*theChildren
; unsigned int n
;
471 parent_window
= next_parent
;
472 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
473 &next_parent
, &theChildren
, &n
);
474 XFree(theChildren
); // not needed
476 int xx
, yy
; unsigned int dummy
;
477 XGetGeometry(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
478 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
483 void wxFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
486 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
488 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
490 XtVaSetValues((Widget
) m_frameWidget
, XmNwidth
, width
, NULL
);
492 XtVaSetValues((Widget
) m_frameWidget
, XmNheight
, height
, NULL
);
494 if (!(height
== -1 && width
== -1))
498 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
499 sizeEvent
.SetEventObject(this);
501 GetEventHandler()->ProcessEvent(sizeEvent
);
505 bool wxFrame::Show(bool show
)
508 return wxWindow::Show(show
);
510 m_visibleStatus
= show
; /* show-&-hide fix */
514 XtMapWidget((Widget
) m_frameShell
);
515 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), XtWindow((Widget
) m_frameShell
));
517 XtUnmapWidget((Widget
) m_frameShell
);
518 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
523 void wxFrame::Iconize(bool iconize
)
529 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, (Boolean
)iconize
, NULL
);
532 // Equivalent to maximize/restore in Windows
533 void wxFrame::Maximize(bool maximize
)
537 if (maximize
&& m_frameShell
)
538 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, FALSE
, NULL
);
541 bool wxFrame::IsIconized() const
547 XtVaGetValues((Widget
) m_frameShell
, XmNiconic
, &iconic
, NULL
);
552 bool wxFrame::IsMaximized(void) const
554 // No maximizing in Motif (?)
558 void wxFrame::SetTitle(const wxString
& title
)
560 if (title
== m_title
)
566 XtVaSetValues((Widget
) m_frameShell
,
567 XmNtitle
, (const char*) title
,
568 XmNiconName
, (const char*) title
,
572 void wxFrame::SetIcon(const wxIcon
& icon
)
579 if (!icon
.Ok() || !icon
.GetPixmap())
582 XtVaSetValues((Widget
) m_frameShell
, XtNiconPixmap
, icon
.GetPixmap(), NULL
);
585 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
586 const wxString
& name
)
588 wxStatusBar
*statusBar
= NULL
;
590 statusBar
= new wxStatusBar(this, id
, wxPoint(0, 0), wxSize(100, 20),
593 // Set the height according to the font and the border size
594 wxClientDC
dc(statusBar
);
595 dc
.SetFont(statusBar
->GetFont());
598 dc
.GetTextExtent("X", &x
, &y
);
600 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
602 statusBar
->SetSize(-1, -1, 100, height
);
604 statusBar
->SetFieldsCount(number
);
608 wxStatusBar
* wxFrame::CreateStatusBar(int number
, long style
, wxWindowID id
,
609 const wxString
& name
)
611 // Calling CreateStatusBar twice is an error.
612 wxCHECK_MSG( m_frameStatusBar
== NULL
, FALSE
,
613 "recreating status bar in wxFrame" );
615 m_frameStatusBar
= OnCreateStatusBar(number
, style
, id
,
617 if ( m_frameStatusBar
)
620 return m_frameStatusBar
;
626 void wxFrame::SetStatusText(const wxString
& text
, int number
)
628 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set text for" );
630 m_frameStatusBar
->SetStatusText(text
, number
);
633 void wxFrame::SetStatusWidths(int n
, const int widths_field
[])
635 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set widths for" );
637 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
641 void wxFrame::PositionStatusBar()
643 if (!m_frameStatusBar
)
647 GetClientSize(&w
, &h
);
649 m_frameStatusBar
->GetSize(&sw
, &sh
);
651 // Since we wish the status bar to be directly under the client area,
652 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
653 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
656 WXWidget
wxFrame::GetMenuBarWidget() const
659 return GetMenuBar()->GetMainWidget();
661 return (WXWidget
) NULL
;
664 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
668 m_frameMenuBar
= NULL
;
672 // Currently can't set it twice
673 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
677 m_frameMenuBar
->DestroyMenuBar();
678 delete m_frameMenuBar
;
681 m_frameMenuBar
= menuBar
;
682 m_frameMenuBar
->CreateMenuBar(this);
687 // Work out max. size
688 wxNode
*node
= GetChildren().First();
693 // Find a child that's a subwindow, but not a dialog box.
694 wxWindow
*win
= (wxWindow
*)node
->Data();
696 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
697 !win
->IsKindOf(CLASSINFO(wxDialog
)))
701 win
->GetSize(&width
, &height
);
702 win
->GetPosition(&x
, &y
);
704 if ((x
+ width
) > max_width
)
705 max_width
= x
+ width
;
706 if ((y
+ height
) > max_height
)
707 max_height
= y
+ height
;
711 SetClientSize(max_width
, max_height
);
714 // Responds to colour changes, and passes event on to children.
715 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
717 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
720 if ( m_frameStatusBar
)
722 wxSysColourChangedEvent event2
;
723 event2
.SetEventObject( m_frameStatusBar
);
724 m_frameStatusBar
->ProcessEvent(event2
);
727 // Propagate the event to the non-top-level children
728 wxWindow::OnSysColourChanged(event
);
731 // Default resizing behaviour - if only ONE subwindow,
732 // resize to client rectangle size
733 void wxFrame::OnSize(wxSizeEvent
& event
)
735 // if we're using constraints - do use them
736 #if wxUSE_CONSTRAINTS
737 if ( GetAutoLayout() ) {
743 // do we have _exactly_ one child?
744 wxWindow
*child
= NULL
;
745 for ( wxNode
*node
= GetChildren().First(); node
; node
= node
->Next() )
747 wxWindow
*win
= (wxWindow
*)node
->Data();
748 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) &&
749 !win
->IsKindOf(CLASSINFO(wxDialog
)) &&
750 (win
!= GetStatusBar())
752 && (win
!= GetToolBar())
753 #endif // wxUSE_TOOLBAR
757 return; // it's our second subwindow - nothing to do
763 // we have exactly one child - set it's size to fill the whole frame
764 int clientW
, clientH
;
765 GetClientSize(&clientW
, &clientH
);
770 child
->SetSize(x
, y
, clientW
, clientH
);
774 // Default activation behaviour - set the focus for the first child
776 void wxFrame::OnActivate(wxActivateEvent
& event
)
778 for(wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
780 // Find a child that's a subwindow, but not a dialog box.
781 wxWindow
*child
= (wxWindow
*)node
->Data();
782 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
783 !child
->IsKindOf(CLASSINFO(wxDialog
)))
791 // The default implementation for the close window event.
792 // OnClose for backward compatibility.
794 void wxFrame::OnCloseWindow(wxCloseEvent
& event
)
799 // Destroy the window (delayed, if a managed window)
800 bool wxFrame::Destroy()
802 if (!wxPendingDelete
.Member(this))
803 wxPendingDelete
.Append(this);
807 // Default menu selection behaviour - display a help string
808 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
812 if (event
.GetMenuId() == -1)
816 wxMenuBar
*menuBar
= GetMenuBar();
819 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
820 if (helpString
!= "")
821 SetStatusText(helpString
);
827 wxMenuBar
*wxFrame::GetMenuBar() const
829 return m_frameMenuBar
;
832 void wxFrame::Centre(int direction
)
834 int display_width
, display_height
, width
, height
, x
, y
;
835 wxDisplaySize(&display_width
, &display_height
);
837 GetSize(&width
, &height
);
840 if (direction
& wxHORIZONTAL
)
841 x
= (int)((display_width
- width
)/2);
842 if (direction
& wxVERTICAL
)
843 y
= (int)((display_height
- height
)/2);
845 SetSize(x
, y
, width
, height
);
848 // Call this to simulate a menu command
849 void wxFrame::Command(int id
)
854 void wxFrame::ProcessCommand(int id
)
856 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
857 commandEvent
.SetInt( id
);
858 commandEvent
.SetEventObject( this );
860 wxMenuBar
*bar
= GetMenuBar() ;
864 /* TODO: check the menu item if required
865 wxMenuItem *item = bar->FindItemForId(id) ;
866 if (item && item->IsCheckable())
868 bar->Check(id,!bar->Checked(id)) ;
872 wxEvtHandler
* evtHandler
= GetEventHandler();
874 evtHandler
->ProcessEvent(commandEvent
);
877 // Checks if there is a toolbar, and returns the first free client position
878 wxPoint
wxFrame::GetClientAreaOrigin() const
885 GetToolBar()->GetSize(& w
, & h
);
887 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
896 #endif // wxUSE_TOOLBAR
901 void wxFrame::ScreenToClient(int *x
, int *y
) const
903 wxWindow::ScreenToClient(x
, y
);
905 // We may be faking the client origin.
906 // So a window that's really at (0, 30) may appear
907 // (to wxWin apps) to be at (0, 0).
908 wxPoint
pt(GetClientAreaOrigin());
913 void wxFrame::ClientToScreen(int *x
, int *y
) const
915 // We may be faking the client origin.
916 // So a window that's really at (0, 30) may appear
917 // (to wxWin apps) to be at (0, 0).
918 wxPoint
pt1(GetClientAreaOrigin());
922 wxWindow::ClientToScreen(x
, y
);
926 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
928 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
929 "recreating toolbar in wxFrame" );
931 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
944 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
946 return new wxToolBar(this, id
, wxPoint(0, 0), wxSize(100, 24), style
, name
);
949 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
951 m_frameToolBar
= toolbar
;
954 wxToolBar
*wxFrame::GetToolBar() const
956 return m_frameToolBar
;
959 void wxFrame::PositionToolBar()
963 GetClientSize(& cw
, &ch
);
968 GetToolBar()->GetSize(& tw
, & th
);
970 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
972 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
973 // means, pretend we don't have toolbar/status bar, so we
974 // have the original client size.
975 GetToolBar()->SetSize(0, 0, tw
, ch
+ th
, wxSIZE_NO_ADJUSTMENTS
);
979 // Use the 'real' position
980 GetToolBar()->SetSize(0, 0, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
984 #endif // wxUSE_TOOLBAR
986 void wxFrame::CaptureMouse()
992 XtAddGrab((Widget
) m_frameShell
, TRUE
, FALSE
);
993 m_winCaptured
= TRUE
;
996 void wxFrame::ReleaseMouse()
1001 if (GetMainWidget())
1002 XtRemoveGrab((Widget
) m_frameShell
);
1003 m_winCaptured
= FALSE
;
1006 void wxFrame::Raise(void)
1008 Window parent_window
= XtWindow((Widget
) m_frameShell
),
1009 next_parent
= XtWindow((Widget
) m_frameShell
),
1010 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
1011 // search for the parent that is child of ROOT, because the WM may
1012 // reparent twice and notify only the next parent (like FVWM)
1013 while (next_parent
!= root
) {
1014 Window
*theChildren
; unsigned int n
;
1015 parent_window
= next_parent
;
1016 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
1017 &next_parent
, &theChildren
, &n
);
1018 XFree(theChildren
); // not needed
1020 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
1023 void wxFrame::Lower(void)
1025 Window parent_window
= XtWindow((Widget
) m_frameShell
),
1026 next_parent
= XtWindow((Widget
) m_frameShell
),
1027 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
1028 // search for the parent that is child of ROOT, because the WM may
1029 // reparent twice and notify only the next parent (like FVWM)
1030 while (next_parent
!= root
) {
1031 Window
*theChildren
; unsigned int n
;
1032 parent_window
= next_parent
;
1033 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
1034 &next_parent
, &theChildren
, &n
);
1035 XFree(theChildren
); // not needed
1037 XLowerWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
1040 void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
1041 XmAnyCallbackStruct
*cbs
)
1043 wxFrame
*frame
= (wxFrame
*)clientData
;
1045 // wxDebugMsg("focus proc from frame %ld\n",(long)frame);
1047 // frame->GetEventHandler()->OnSetFocus();
1050 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
1051 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
1052 XCrossingEvent
* event
)
1054 wxFrame
*frame
= (wxFrame
*)wxWidgetHashTable
->Get((long)clientData
);
1057 XEvent
*e
= (XEvent
*)event
;
1059 if (e
->xany
.type
== MapNotify
)
1062 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
1063 if (!frame
->GetVisibleStatus())
1065 /* We really wanted this to be hidden! */
1066 XtUnmapWidget((Widget
) frame
->GetShellWidget());
1069 else if (e
->xany
.type
== UnmapNotify
)
1071 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)True
, NULL
);
1076 bool wxFrame::PreResize()
1080 #endif // wxUSE_TOOLBAR
1081 PositionStatusBar();
1085 WXWidget
wxFrame::GetClientWidget() const
1087 return m_clientArea
;
1090 void wxFrame::ChangeFont(bool keepOriginalSize
)
1095 void wxFrame::ChangeBackgroundColour()
1097 if (GetClientWidget())
1098 DoChangeBackgroundColour(GetClientWidget(), m_backgroundColour
);
1101 void wxFrame::ChangeForegroundColour()
1103 if (GetClientWidget())
1104 DoChangeForegroundColour(GetClientWidget(), m_foregroundColour
);
1107 void wxCloseFrameCallback(Widget widget
, XtPointer client_data
, XmAnyCallbackStruct
*cbs
)
1109 wxFrame
*frame
= (wxFrame
*)client_data
;
1111 wxCloseEvent
closeEvent(wxEVT_CLOSE_WINDOW
, frame
->GetId());
1112 closeEvent
.SetEventObject(frame
);
1114 // May delete the frame (with delayed deletion)
1115 frame
->GetEventHandler()->ProcessEvent(closeEvent
);