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 extern wxHashTable
*wxWidgetHashTable
;
55 void wxCloseFrameCallback(Widget
, XtPointer
, XmAnyCallbackStruct
*cbs
);
56 void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
57 XmAnyCallbackStruct
*cbs
);
58 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
59 XCrossingEvent
* event
);
61 extern wxList wxModelessWindows
;
62 extern wxList wxPendingDelete
;
64 // TODO: this should be tidied so that any frame can be the
66 static bool wxTopLevelUsed
= FALSE
;
68 #if !USE_SHARED_LIBRARY
69 BEGIN_EVENT_TABLE(wxFrame
, wxWindow
)
70 EVT_SIZE(wxFrame::OnSize
)
71 EVT_ACTIVATE(wxFrame::OnActivate
)
72 EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight
)
73 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
74 EVT_IDLE(wxFrame::OnIdle
)
75 EVT_CLOSE(wxFrame::OnCloseWindow
)
78 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxWindow
)
81 #if wxUSE_NATIVE_STATUSBAR
82 bool wxFrame::m_useNativeStatusBar
= TRUE
;
84 bool wxFrame::m_useNativeStatusBar
= FALSE
;
90 m_frameToolBar
= NULL
;
91 #endif // wxUSE_TOOLBAR
93 m_frameMenuBar
= NULL
;
94 m_frameStatusBar
= NULL
;
100 m_frameShell
= (WXWidget
) NULL
;
101 m_frameWidget
= (WXWidget
) NULL
;;
102 m_workArea
= (WXWidget
) NULL
;;
103 m_clientArea
= (WXWidget
) NULL
;;
104 m_visibleStatus
= TRUE
;
108 bool wxFrame::Create(wxWindow
*parent
,
110 const wxString
& title
,
114 const wxString
& name
)
117 wxTopLevelWindows
.Append(this);
121 m_windowStyle
= style
;
122 m_frameMenuBar
= NULL
;
124 m_frameToolBar
= NULL
;
125 #endif // wxUSE_TOOLBAR
126 m_frameStatusBar
= NULL
;
129 m_frameShell
= (WXWidget
) NULL
;
130 m_frameWidget
= (WXWidget
) NULL
;;
131 m_workArea
= (WXWidget
) NULL
;;
132 m_clientArea
= (WXWidget
) NULL
;;
133 m_visibleStatus
= TRUE
;
136 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
137 m_foregroundColour
= *wxBLACK
;
138 m_font
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
143 m_windowId
= (int)NewControlId();
145 if (parent
) parent
->AddChild(this);
147 wxModelessWindows
.Append(this);
149 int x
= pos
.x
; int y
= pos
.y
;
150 int width
= size
.x
; int height
= size
.y
;
153 // Change suggested by Matthew Flatt
154 m_frameShell
= (WXWidget
) XtAppCreateShell(name
, wxTheApp
->GetClassName(), topLevelShellWidgetClass
, (Display
*) wxGetDisplay(), NULL
, 0);
157 m_frameShell
= wxTheApp
->GetTopLevelWidget();
158 wxTopLevelUsed
= TRUE
;
161 XtVaSetValues((Widget
) m_frameShell
,
162 // Allows menu to resize
163 XmNallowShellResize
, True
,
164 XmNdeleteResponse
, XmDO_NOTHING
,
165 XmNmappedWhenManaged
, False
,
166 XmNiconic
, (style
& wxICONIZE
) ? TRUE
: FALSE
,
170 XtVaSetValues((Widget
) m_frameShell
,
171 XmNtitle
, (const char*) title
,
174 m_frameWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
175 xmMainWindowWidgetClass
, (Widget
) m_frameShell
,
176 XmNresizePolicy
, XmRESIZE_NONE
,
179 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
180 xmFormWidgetClass
, (Widget
) m_frameWidget
,
181 XmNresizePolicy
, XmRESIZE_NONE
,
184 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
185 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
188 XmNrightAttachment
, XmATTACH_FORM
,
189 XmNleftAttachment
, XmATTACH_FORM
,
190 XmNtopAttachment
, XmATTACH_FORM
,
191 XmNbottomAttachment
, XmATTACH_FORM
,
192 // XmNresizePolicy, XmRESIZE_ANY,
195 XtAddEventHandler((Widget
) m_clientArea
, ExposureMask
,FALSE
,
196 wxUniversalRepaintProc
, (XtPointer
) this);
198 XtVaSetValues((Widget
) m_frameWidget
,
199 XmNworkWindow
, (Widget
) m_workArea
,
202 XtManageChild((Widget
) m_clientArea
);
203 XtManageChild((Widget
) m_workArea
);
205 wxASSERT_MSG ((wxWidgetHashTable
->Get((long)m_workArea
) == (wxObject
*) NULL
), "Widget table clash in frame.cpp") ;
207 wxAddWindowToTable((Widget
) m_workArea
, this);
211 XtOverrideTranslations((Widget
) m_workArea
,
212 ptr
= XtParseTranslationTable("<Configure>: resize()"));
216 XtAddCallback((Widget
) m_workArea
, XmNfocusCallback
,
217 (XtCallbackProc
)wxFrameFocusProc
, (XtPointer
)this);
219 /* Part of show-&-hide fix */
220 XtAddEventHandler((Widget
) m_frameShell
, StructureNotifyMask
,
221 False
, (XtEventHandler
)wxFrameMapProc
,
222 (XtPointer
)m_workArea
);
225 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
227 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
229 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
231 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
233 m_mainWidget
= m_frameWidget
;
237 // This patch comes from Torsten Liermann lier@lier1.muc.de
238 if (XmIsMotifWMRunning( (Widget
) m_frameShell
))
241 if (style
& wxRESIZE_BORDER
)
242 decor
|= MWM_DECOR_RESIZEH
;
243 if (style
& wxSYSTEM_MENU
)
244 decor
|= MWM_DECOR_MENU
;
245 if ((style
& wxCAPTION
) ||
246 (style
& wxTINY_CAPTION_HORIZ
) ||
247 (style
& wxTINY_CAPTION_VERT
))
248 decor
|= MWM_DECOR_TITLE
;
249 if (style
& wxTHICK_FRAME
)
250 decor
|= MWM_DECOR_BORDER
;
251 if (style
& wxTHICK_FRAME
)
252 decor
|= MWM_DECOR_BORDER
;
253 if (style
& wxMINIMIZE_BOX
)
254 decor
|= MWM_DECOR_MINIMIZE
;
255 if (style
& wxMAXIMIZE_BOX
)
256 decor
|= MWM_DECOR_MAXIMIZE
;
257 XtVaSetValues((Widget
) m_frameShell
,XmNmwmDecorations
,decor
,NULL
) ;
259 // This allows non-Motif window managers to support at least the
260 // no-decorations case.
264 XtVaSetValues((Widget
) m_frameShell
,XmNoverrideRedirect
,TRUE
,NULL
);
266 XtRealizeWidget((Widget
) m_frameShell
);
268 // Intercept CLOSE messages from the window manager
269 Atom WM_DELETE_WINDOW
= XmInternAtom(XtDisplay((Widget
) m_frameShell
), "WM_DELETE_WINDOW", False
);
270 #if (XmREVISION > 1 || XmVERSION > 1)
271 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (XtPointer
)this);
274 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (caddr_t
)this);
276 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (void (*)())wxCloseFrameCallback
, (caddr_t
)this);
280 ChangeBackgroundColour();
284 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
285 sizeEvent
.SetEventObject(this);
287 GetEventHandler()->ProcessEvent(sizeEvent
);
295 XtRemoveEventHandler((Widget
) m_clientArea
, ExposureMask
, FALSE
,
296 wxUniversalRepaintProc
, (XtPointer
) this);
303 m_frameMenuBar
->DestroyMenuBar();
305 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
306 #if MOTIF_MENUBAR_DELETE_FIX
307 GetMenuBar()->SetMainWidget((WXWidget
) NULL
);
309 delete m_frameMenuBar
;
310 m_frameMenuBar
= NULL
;
313 wxTopLevelWindows
.DeleteObject(this);
314 wxModelessWindows
.DeleteObject(this);
316 if (m_frameStatusBar
)
317 delete m_frameStatusBar
;
323 for (i = 0; i < wxMAX_STATUS; i++)
324 if (statusTextWidget[i])
325 XtDestroyWidget (statusTextWidget[i]);
328 XtDestroyWidget (statusLineForm);
330 if (statusLineWidget)
331 XtDestroyWidget (statusLineWidget);
336 wxDeleteWindowFromTable((Widget
) m_workArea
);
338 XtDestroyWidget ((Widget
) m_workArea
);
343 wxDeleteWindowFromTable((Widget
) m_frameWidget
);
344 XtDestroyWidget ((Widget
) m_frameWidget
);
348 XtDestroyWidget ((Widget
) m_frameShell
);
350 SetMainWidget((WXWidget
) NULL
);
352 /* Check if it's the last top-level window */
354 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
356 wxTheApp
->SetTopWindow(NULL
);
358 if (wxTheApp
->GetExitOnFrameDelete())
360 // Signal to the app that we're going to close
361 wxTheApp
->ExitMainLoop();
367 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
368 void wxFrame::GetClientSize(int *x
, int *y
) const
371 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
373 if (m_frameStatusBar
)
376 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
383 m_frameToolBar
->GetSize(& tbw
, & tbh
);
384 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
389 #endif // wxUSE_TOOLBAR
391 if (GetMenuBar() != (wxMenuBar*) NULL)
393 // it seems that if a frame holds a panel, the menu bar size
394 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
395 bool hasSubPanel = FALSE;
396 for(wxNode* node = GetChildren().First(); node; node = node->Next())
398 wxWindow *win = (wxWindow *)node->Data();
399 hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)));
406 XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL);
415 // Set the client size (i.e. leave the calculation of borders etc.
417 void wxFrame::DoSetClientSize(int width
, int height
)
419 // Calculate how large the new main window should be
420 // by finding the difference between the client area and the
421 // main window area, and adding on to the new client area
423 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
427 if (m_frameStatusBar
)
430 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
437 m_frameToolBar
->GetSize(& tbw
, & tbh
);
438 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
443 #endif // wxUSE_TOOLBAR
445 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
449 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
450 sizeEvent
.SetEventObject(this);
452 GetEventHandler()->ProcessEvent(sizeEvent
);
456 void wxFrame::GetSize(int *width
, int *height
) const
459 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
460 *width
= xx
; *height
= yy
;
463 void wxFrame::GetPosition(int *x
, int *y
) const
465 Window parent_window
= XtWindow((Widget
) m_frameShell
),
466 next_parent
= XtWindow((Widget
) m_frameShell
),
467 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
469 // search for the parent that is child of ROOT, because the WM may
470 // reparent twice and notify only the next parent (like FVWM)
471 while (next_parent
!= root
) {
472 Window
*theChildren
; unsigned int n
;
473 parent_window
= next_parent
;
474 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
475 &next_parent
, &theChildren
, &n
);
476 XFree(theChildren
); // not needed
478 int xx
, yy
; unsigned int dummy
;
479 XGetGeometry(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
480 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
485 void wxFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
488 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
490 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
492 XtVaSetValues((Widget
) m_frameWidget
, XmNwidth
, width
, NULL
);
494 XtVaSetValues((Widget
) m_frameWidget
, XmNheight
, height
, NULL
);
496 if (!(height
== -1 && width
== -1))
500 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
501 sizeEvent
.SetEventObject(this);
503 GetEventHandler()->ProcessEvent(sizeEvent
);
507 bool wxFrame::Show(bool show
)
510 return wxWindow::Show(show
);
512 m_visibleStatus
= show
; /* show-&-hide fix */
516 XtMapWidget((Widget
) m_frameShell
);
517 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), XtWindow((Widget
) m_frameShell
));
519 XtUnmapWidget((Widget
) m_frameShell
);
520 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
525 void wxFrame::Iconize(bool iconize
)
531 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, (Boolean
)iconize
, NULL
);
534 // Equivalent to maximize/restore in Windows
535 void wxFrame::Maximize(bool maximize
)
539 if (maximize
&& m_frameShell
)
540 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, FALSE
, NULL
);
543 bool wxFrame::IsIconized() const
549 XtVaGetValues((Widget
) m_frameShell
, XmNiconic
, &iconic
, NULL
);
554 bool wxFrame::IsMaximized(void) const
556 // No maximizing in Motif (?)
560 void wxFrame::SetTitle(const wxString
& title
)
562 if (title
== m_title
)
568 XtVaSetValues((Widget
) m_frameShell
,
569 XmNtitle
, (const char*) title
,
570 XmNiconName
, (const char*) title
,
574 void wxFrame::SetIcon(const wxIcon
& icon
)
581 if (!icon
.Ok() || !icon
.GetPixmap())
584 XtVaSetValues((Widget
) m_frameShell
, XtNiconPixmap
, icon
.GetPixmap(), NULL
);
587 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
588 const wxString
& name
)
590 wxStatusBar
*statusBar
= NULL
;
592 statusBar
= new wxStatusBar(this, id
, wxPoint(0, 0), wxSize(100, 20),
595 // Set the height according to the font and the border size
596 wxClientDC
dc(statusBar
);
597 dc
.SetFont(statusBar
->GetFont());
600 dc
.GetTextExtent("X", &x
, &y
);
602 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
604 statusBar
->SetSize(-1, -1, 100, height
);
606 statusBar
->SetFieldsCount(number
);
610 wxStatusBar
* wxFrame::CreateStatusBar(int number
, long style
, wxWindowID id
,
611 const wxString
& name
)
613 // Calling CreateStatusBar twice is an error.
614 wxCHECK_MSG( m_frameStatusBar
== NULL
, FALSE
,
615 "recreating status bar in wxFrame" );
617 m_frameStatusBar
= OnCreateStatusBar(number
, style
, id
,
619 if ( m_frameStatusBar
)
622 return m_frameStatusBar
;
628 void wxFrame::SetStatusText(const wxString
& text
, int number
)
630 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set text for" );
632 m_frameStatusBar
->SetStatusText(text
, number
);
635 void wxFrame::SetStatusWidths(int n
, const int widths_field
[])
637 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set widths for" );
639 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
643 void wxFrame::PositionStatusBar()
645 if (!m_frameStatusBar
)
649 GetClientSize(&w
, &h
);
651 m_frameStatusBar
->GetSize(&sw
, &sh
);
653 // Since we wish the status bar to be directly under the client area,
654 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
655 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
658 WXWidget
wxFrame::GetMenuBarWidget() const
661 return GetMenuBar()->GetMainWidget();
663 return (WXWidget
) NULL
;
666 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
670 m_frameMenuBar
= NULL
;
674 // Currently can't set it twice
675 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
679 m_frameMenuBar
->DestroyMenuBar();
680 delete m_frameMenuBar
;
683 m_frameMenuBar
= menuBar
;
684 m_frameMenuBar
->CreateMenuBar(this);
689 // Work out max. size
690 wxNode
*node
= GetChildren().First();
695 // Find a child that's a subwindow, but not a dialog box.
696 wxWindow
*win
= (wxWindow
*)node
->Data();
698 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
699 !win
->IsKindOf(CLASSINFO(wxDialog
)))
703 win
->GetSize(&width
, &height
);
704 win
->GetPosition(&x
, &y
);
706 if ((x
+ width
) > max_width
)
707 max_width
= x
+ width
;
708 if ((y
+ height
) > max_height
)
709 max_height
= y
+ height
;
713 SetClientSize(max_width
, max_height
);
716 // Responds to colour changes, and passes event on to children.
717 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
719 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
722 if ( m_frameStatusBar
)
724 wxSysColourChangedEvent event2
;
725 event2
.SetEventObject( m_frameStatusBar
);
726 m_frameStatusBar
->ProcessEvent(event2
);
729 // Propagate the event to the non-top-level children
730 wxWindow::OnSysColourChanged(event
);
733 // Default resizing behaviour - if only ONE subwindow,
734 // resize to client rectangle size
735 void wxFrame::OnSize(wxSizeEvent
& event
)
737 // if we're using constraints - do use them
738 #if wxUSE_CONSTRAINTS
739 if ( GetAutoLayout() ) {
745 // do we have _exactly_ one child?
746 wxWindow
*child
= NULL
;
747 for ( wxNode
*node
= GetChildren().First(); node
; node
= node
->Next() )
749 wxWindow
*win
= (wxWindow
*)node
->Data();
750 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) &&
751 !win
->IsKindOf(CLASSINFO(wxDialog
)) &&
752 (win
!= GetStatusBar())
754 && (win
!= GetToolBar())
755 #endif // wxUSE_TOOLBAR
759 return; // it's our second subwindow - nothing to do
765 // we have exactly one child - set it's size to fill the whole frame
766 int clientW
, clientH
;
767 GetClientSize(&clientW
, &clientH
);
772 child
->SetSize(x
, y
, clientW
, clientH
);
776 // Default activation behaviour - set the focus for the first child
778 void wxFrame::OnActivate(wxActivateEvent
& event
)
780 for(wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
782 // Find a child that's a subwindow, but not a dialog box.
783 wxWindow
*child
= (wxWindow
*)node
->Data();
784 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
785 !child
->IsKindOf(CLASSINFO(wxDialog
)))
793 // The default implementation for the close window event.
794 // OnClose for backward compatibility.
796 void wxFrame::OnCloseWindow(wxCloseEvent
& event
)
801 // Destroy the window (delayed, if a managed window)
802 bool wxFrame::Destroy()
804 if (!wxPendingDelete
.Member(this))
805 wxPendingDelete
.Append(this);
809 // Default menu selection behaviour - display a help string
810 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
814 if (event
.GetMenuId() == -1)
818 wxMenuBar
*menuBar
= GetMenuBar();
821 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
822 if (helpString
!= "")
823 SetStatusText(helpString
);
829 wxMenuBar
*wxFrame::GetMenuBar() const
831 return m_frameMenuBar
;
834 void wxFrame::Centre(int direction
)
836 int display_width
, display_height
, width
, height
, x
, y
;
837 wxDisplaySize(&display_width
, &display_height
);
839 GetSize(&width
, &height
);
842 if (direction
& wxHORIZONTAL
)
843 x
= (int)((display_width
- width
)/2);
844 if (direction
& wxVERTICAL
)
845 y
= (int)((display_height
- height
)/2);
847 SetSize(x
, y
, width
, height
);
850 // Call this to simulate a menu command
851 void wxFrame::Command(int id
)
856 void wxFrame::ProcessCommand(int id
)
858 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
859 commandEvent
.SetInt( id
);
860 commandEvent
.SetEventObject( this );
862 wxMenuBar
*bar
= GetMenuBar() ;
866 /* TODO: check the menu item if required
867 wxMenuItem *item = bar->FindItemForId(id) ;
868 if (item && item->IsCheckable())
870 bar->Check(id,!bar->Checked(id)) ;
874 wxEvtHandler
* evtHandler
= GetEventHandler();
876 evtHandler
->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
);