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
; int y
= pos
.y
;
148 int width
= size
.x
; int height
= size
.y
;
152 // Change suggested by Matthew Flatt
153 m_frameShell
= (WXWidget
)XtAppCreateShell
156 wxTheApp
->GetClassName(),
157 topLevelShellWidgetClass
,
158 (Display
*) wxGetDisplay(),
165 m_frameShell
= wxTheApp
->GetTopLevelWidget();
166 wxTopLevelUsed
= TRUE
;
169 XtVaSetValues((Widget
) m_frameShell
,
170 // Allows menu to resize
171 XmNallowShellResize
, True
,
172 XmNdeleteResponse
, XmDO_NOTHING
,
173 XmNmappedWhenManaged
, False
,
174 XmNiconic
, (style
& wxICONIZE
) ? TRUE
: FALSE
,
178 XtVaSetValues((Widget
) m_frameShell
,
179 XmNtitle
, (const char*) title
,
182 m_frameWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
183 xmMainWindowWidgetClass
, (Widget
) m_frameShell
,
184 XmNresizePolicy
, XmRESIZE_NONE
,
187 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
188 xmFormWidgetClass
, (Widget
) m_frameWidget
,
189 XmNresizePolicy
, XmRESIZE_NONE
,
192 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
193 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
196 XmNrightAttachment
, XmATTACH_FORM
,
197 XmNleftAttachment
, XmATTACH_FORM
,
198 XmNtopAttachment
, XmATTACH_FORM
,
199 XmNbottomAttachment
, XmATTACH_FORM
,
200 // XmNresizePolicy, XmRESIZE_ANY,
203 wxLogDebug("Created frame (0x%08x) with work area 0x%08x and client "
204 "area 0x%08x", m_frameWidget
, m_workArea
, m_clientArea
);
206 XtAddEventHandler((Widget
) m_clientArea
, ExposureMask
,FALSE
,
207 wxUniversalRepaintProc
, (XtPointer
) this);
209 XtVaSetValues((Widget
) m_frameWidget
,
210 XmNworkWindow
, (Widget
) m_workArea
,
213 XtManageChild((Widget
) m_clientArea
);
214 XtManageChild((Widget
) m_workArea
);
216 wxAddWindowToTable((Widget
) m_workArea
, this);
220 XtOverrideTranslations((Widget
) m_workArea
,
221 ptr
= XtParseTranslationTable("<Configure>: resize()"));
225 XtAddCallback((Widget
) m_workArea
, XmNfocusCallback
,
226 (XtCallbackProc
)wxFrameFocusProc
, (XtPointer
)this);
228 /* Part of show-&-hide fix */
229 XtAddEventHandler((Widget
) m_frameShell
, StructureNotifyMask
,
230 False
, (XtEventHandler
)wxFrameMapProc
,
231 (XtPointer
)m_workArea
);
234 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
236 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
238 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
240 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
242 m_mainWidget
= m_frameWidget
;
246 // This patch comes from Torsten Liermann lier@lier1.muc.de
247 if (XmIsMotifWMRunning( (Widget
) m_frameShell
))
250 if (style
& wxRESIZE_BORDER
)
251 decor
|= MWM_DECOR_RESIZEH
;
252 if (style
& wxSYSTEM_MENU
)
253 decor
|= MWM_DECOR_MENU
;
254 if ((style
& wxCAPTION
) ||
255 (style
& wxTINY_CAPTION_HORIZ
) ||
256 (style
& wxTINY_CAPTION_VERT
))
257 decor
|= MWM_DECOR_TITLE
;
258 if (style
& wxTHICK_FRAME
)
259 decor
|= MWM_DECOR_BORDER
;
260 if (style
& wxTHICK_FRAME
)
261 decor
|= MWM_DECOR_BORDER
;
262 if (style
& wxMINIMIZE_BOX
)
263 decor
|= MWM_DECOR_MINIMIZE
;
264 if (style
& wxMAXIMIZE_BOX
)
265 decor
|= MWM_DECOR_MAXIMIZE
;
266 XtVaSetValues((Widget
) m_frameShell
,XmNmwmDecorations
,decor
,NULL
) ;
268 // This allows non-Motif window managers to support at least the
269 // no-decorations case.
273 XtVaSetValues((Widget
) m_frameShell
,XmNoverrideRedirect
,TRUE
,NULL
);
275 XtRealizeWidget((Widget
) m_frameShell
);
277 // Intercept CLOSE messages from the window manager
278 Atom WM_DELETE_WINDOW
= XmInternAtom(XtDisplay((Widget
) m_frameShell
), "WM_DELETE_WINDOW", False
);
279 #if (XmREVISION > 1 || XmVERSION > 1)
280 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (XtPointer
)this);
283 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (caddr_t
)this);
285 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (void (*)())wxCloseFrameCallback
, (caddr_t
)this);
289 ChangeBackgroundColour();
293 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
294 sizeEvent
.SetEventObject(this);
296 GetEventHandler()->ProcessEvent(sizeEvent
);
303 m_isBeingDeleted
= TRUE
;
306 XtRemoveEventHandler((Widget
) m_clientArea
, ExposureMask
, FALSE
,
307 wxUniversalRepaintProc
, (XtPointer
) this);
314 m_frameMenuBar
->DestroyMenuBar();
316 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
317 #if MOTIF_MENUBAR_DELETE_FIX
318 GetMenuBar()->SetMainWidget((WXWidget
) NULL
);
320 delete m_frameMenuBar
;
321 m_frameMenuBar
= NULL
;
324 wxTopLevelWindows
.DeleteObject(this);
325 wxModelessWindows
.DeleteObject(this);
327 if (m_frameStatusBar
)
328 delete m_frameStatusBar
;
334 for (i = 0; i < wxMAX_STATUS; i++)
335 if (statusTextWidget[i])
336 XtDestroyWidget (statusTextWidget[i]);
339 XtDestroyWidget (statusLineForm);
341 if (statusLineWidget)
342 XtDestroyWidget (statusLineWidget);
347 wxDeleteWindowFromTable((Widget
) m_workArea
);
349 XtDestroyWidget ((Widget
) m_workArea
);
354 wxDeleteWindowFromTable((Widget
) m_frameWidget
);
355 XtDestroyWidget ((Widget
) m_frameWidget
);
359 XtDestroyWidget ((Widget
) m_frameShell
);
361 SetMainWidget((WXWidget
) NULL
);
363 /* Check if it's the last top-level window */
365 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
367 wxTheApp
->SetTopWindow(NULL
);
369 if (wxTheApp
->GetExitOnFrameDelete())
371 // Signal to the app that we're going to close
372 wxTheApp
->ExitMainLoop();
378 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
379 void wxFrame::GetClientSize(int *x
, int *y
) const
382 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
384 if (m_frameStatusBar
)
387 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
394 m_frameToolBar
->GetSize(& tbw
, & tbh
);
395 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
400 #endif // wxUSE_TOOLBAR
402 if (GetMenuBar() != (wxMenuBar*) NULL)
404 // it seems that if a frame holds a panel, the menu bar size
405 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
406 bool hasSubPanel = FALSE;
407 for(wxNode* node = GetChildren().First(); node; node = node->Next())
409 wxWindow *win = (wxWindow *)node->Data();
410 hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)));
417 XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL);
426 // Set the client size (i.e. leave the calculation of borders etc.
428 void wxFrame::DoSetClientSize(int width
, int height
)
430 // Calculate how large the new main window should be
431 // by finding the difference between the client area and the
432 // main window area, and adding on to the new client area
434 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
438 if (m_frameStatusBar
)
441 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
448 m_frameToolBar
->GetSize(& tbw
, & tbh
);
449 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
454 #endif // wxUSE_TOOLBAR
456 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
460 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
461 sizeEvent
.SetEventObject(this);
463 GetEventHandler()->ProcessEvent(sizeEvent
);
467 void wxFrame::GetSize(int *width
, int *height
) const
470 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
471 *width
= xx
; *height
= yy
;
474 void wxFrame::GetPosition(int *x
, int *y
) const
476 Window parent_window
= XtWindow((Widget
) m_frameShell
),
477 next_parent
= XtWindow((Widget
) m_frameShell
),
478 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
480 // search for the parent that is child of ROOT, because the WM may
481 // reparent twice and notify only the next parent (like FVWM)
482 while (next_parent
!= root
) {
483 Window
*theChildren
; unsigned int n
;
484 parent_window
= next_parent
;
485 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
486 &next_parent
, &theChildren
, &n
);
487 XFree(theChildren
); // not needed
489 int xx
, yy
; unsigned int dummy
;
490 XGetGeometry(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
491 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
496 void wxFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
499 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
501 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
503 XtVaSetValues((Widget
) m_frameWidget
, XmNwidth
, width
, NULL
);
505 XtVaSetValues((Widget
) m_frameWidget
, XmNheight
, height
, NULL
);
507 if (!(height
== -1 && width
== -1))
511 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
512 sizeEvent
.SetEventObject(this);
514 GetEventHandler()->ProcessEvent(sizeEvent
);
518 bool wxFrame::Show(bool show
)
521 return wxWindow::Show(show
);
523 m_visibleStatus
= show
; /* show-&-hide fix */
527 XtMapWidget((Widget
) m_frameShell
);
528 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), XtWindow((Widget
) m_frameShell
));
530 XtUnmapWidget((Widget
) m_frameShell
);
531 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
536 void wxFrame::Iconize(bool iconize
)
542 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, (Boolean
)iconize
, NULL
);
545 // Equivalent to maximize/restore in Windows
546 void wxFrame::Maximize(bool maximize
)
550 if (maximize
&& m_frameShell
)
551 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, FALSE
, NULL
);
554 bool wxFrame::IsIconized() const
560 XtVaGetValues((Widget
) m_frameShell
, XmNiconic
, &iconic
, NULL
);
565 bool wxFrame::IsMaximized(void) const
567 // No maximizing in Motif (?)
571 void wxFrame::SetTitle(const wxString
& title
)
573 if (title
== m_title
)
579 XtVaSetValues((Widget
) m_frameShell
,
580 XmNtitle
, (const char*) title
,
581 XmNiconName
, (const char*) title
,
585 void wxFrame::SetIcon(const wxIcon
& icon
)
592 if (!icon
.Ok() || !icon
.GetPixmap())
595 XtVaSetValues((Widget
) m_frameShell
, XtNiconPixmap
, icon
.GetPixmap(), NULL
);
598 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
599 const wxString
& name
)
601 wxStatusBar
*statusBar
= NULL
;
603 statusBar
= new wxStatusBar(this, id
, wxPoint(0, 0), wxSize(100, 20),
606 // Set the height according to the font and the border size
607 wxClientDC
dc(statusBar
);
608 dc
.SetFont(statusBar
->GetFont());
611 dc
.GetTextExtent("X", &x
, &y
);
613 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
615 statusBar
->SetSize(-1, -1, 100, height
);
617 statusBar
->SetFieldsCount(number
);
621 wxStatusBar
* wxFrame::CreateStatusBar(int number
, long style
, wxWindowID id
,
622 const wxString
& name
)
624 // Calling CreateStatusBar twice is an error.
625 wxCHECK_MSG( m_frameStatusBar
== NULL
, FALSE
,
626 "recreating status bar in wxFrame" );
628 m_frameStatusBar
= OnCreateStatusBar(number
, style
, id
,
630 if ( m_frameStatusBar
)
633 return m_frameStatusBar
;
639 void wxFrame::SetStatusText(const wxString
& text
, int number
)
641 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set text for" );
643 m_frameStatusBar
->SetStatusText(text
, number
);
646 void wxFrame::SetStatusWidths(int n
, const int widths_field
[])
648 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set widths for" );
650 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
654 void wxFrame::PositionStatusBar()
656 if (!m_frameStatusBar
)
660 GetClientSize(&w
, &h
);
662 m_frameStatusBar
->GetSize(&sw
, &sh
);
664 // Since we wish the status bar to be directly under the client area,
665 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
666 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
669 WXWidget
wxFrame::GetMenuBarWidget() const
672 return GetMenuBar()->GetMainWidget();
674 return (WXWidget
) NULL
;
677 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
681 m_frameMenuBar
= NULL
;
685 // Currently can't set it twice
686 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
690 m_frameMenuBar
->DestroyMenuBar();
691 delete m_frameMenuBar
;
694 m_frameMenuBar
= menuBar
;
695 m_frameMenuBar
->CreateMenuBar(this);
700 // Work out max. size
701 wxNode
*node
= GetChildren().First();
706 // Find a child that's a subwindow, but not a dialog box.
707 wxWindow
*win
= (wxWindow
*)node
->Data();
709 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
710 !win
->IsKindOf(CLASSINFO(wxDialog
)))
714 win
->GetSize(&width
, &height
);
715 win
->GetPosition(&x
, &y
);
717 if ((x
+ width
) > max_width
)
718 max_width
= x
+ width
;
719 if ((y
+ height
) > max_height
)
720 max_height
= y
+ height
;
724 SetClientSize(max_width
, max_height
);
727 // Responds to colour changes, and passes event on to children.
728 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
730 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
733 if ( m_frameStatusBar
)
735 wxSysColourChangedEvent event2
;
736 event2
.SetEventObject( m_frameStatusBar
);
737 m_frameStatusBar
->ProcessEvent(event2
);
740 // Propagate the event to the non-top-level children
741 wxWindow::OnSysColourChanged(event
);
744 // Default resizing behaviour - if only ONE subwindow,
745 // resize to client rectangle size
746 void wxFrame::OnSize(wxSizeEvent
& event
)
748 // if we're using constraints - do use them
749 #if wxUSE_CONSTRAINTS
750 if ( GetAutoLayout() ) {
756 // do we have _exactly_ one child?
757 wxWindow
*child
= NULL
;
758 for ( wxNode
*node
= GetChildren().First(); node
; node
= node
->Next() )
760 wxWindow
*win
= (wxWindow
*)node
->Data();
761 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) &&
762 !win
->IsKindOf(CLASSINFO(wxDialog
)) &&
763 (win
!= GetStatusBar())
765 && (win
!= GetToolBar())
766 #endif // wxUSE_TOOLBAR
770 return; // it's our second subwindow - nothing to do
776 // we have exactly one child - set it's size to fill the whole frame
777 int clientW
, clientH
;
778 GetClientSize(&clientW
, &clientH
);
783 child
->SetSize(x
, y
, clientW
, clientH
);
787 // Default activation behaviour - set the focus for the first child
789 void wxFrame::OnActivate(wxActivateEvent
& event
)
791 for(wxNode
*node
= GetChildren().First(); node
; node
= node
->Next())
793 // Find a child that's a subwindow, but not a dialog box.
794 wxWindow
*child
= (wxWindow
*)node
->Data();
795 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
796 !child
->IsKindOf(CLASSINFO(wxDialog
)))
804 // The default implementation for the close window event.
805 // OnClose for backward compatibility.
807 void wxFrame::OnCloseWindow(wxCloseEvent
& event
)
812 // Destroy the window (delayed, if a managed window)
813 bool wxFrame::Destroy()
815 if (!wxPendingDelete
.Member(this))
816 wxPendingDelete
.Append(this);
820 // Default menu selection behaviour - display a help string
821 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
825 if (event
.GetMenuId() == -1)
829 wxMenuBar
*menuBar
= GetMenuBar();
832 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
833 if (helpString
!= "")
834 SetStatusText(helpString
);
840 wxMenuBar
*wxFrame::GetMenuBar() const
842 return m_frameMenuBar
;
845 void wxFrame::Centre(int direction
)
847 int display_width
, display_height
, width
, height
, x
, y
;
848 wxDisplaySize(&display_width
, &display_height
);
850 GetSize(&width
, &height
);
853 if (direction
& wxHORIZONTAL
)
854 x
= (int)((display_width
- width
)/2);
855 if (direction
& wxVERTICAL
)
856 y
= (int)((display_height
- height
)/2);
858 SetSize(x
, y
, width
, height
);
861 // Call this to simulate a menu command
862 void wxFrame::Command(int id
)
867 void wxFrame::ProcessCommand(int id
)
869 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
870 commandEvent
.SetInt( id
);
871 commandEvent
.SetEventObject( this );
873 wxMenuBar
*bar
= GetMenuBar() ;
877 /* TODO: check the menu item if required
878 wxMenuItem *item = bar->FindItemForId(id) ;
879 if (item && item->IsCheckable())
881 bar->Check(id,!bar->Checked(id)) ;
885 wxEvtHandler
* evtHandler
= GetEventHandler();
887 evtHandler
->ProcessEvent(commandEvent
);
890 // Checks if there is a toolbar, and returns the first free client position
891 wxPoint
wxFrame::GetClientAreaOrigin() const
898 GetToolBar()->GetSize(& w
, & h
);
900 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
909 #endif // wxUSE_TOOLBAR
914 void wxFrame::ScreenToClient(int *x
, int *y
) const
916 wxWindow::ScreenToClient(x
, y
);
918 // We may be faking the client origin.
919 // So a window that's really at (0, 30) may appear
920 // (to wxWin apps) to be at (0, 0).
921 wxPoint
pt(GetClientAreaOrigin());
926 void wxFrame::ClientToScreen(int *x
, int *y
) const
928 // We may be faking the client origin.
929 // So a window that's really at (0, 30) may appear
930 // (to wxWin apps) to be at (0, 0).
931 wxPoint
pt1(GetClientAreaOrigin());
935 wxWindow::ClientToScreen(x
, y
);
939 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
941 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
942 "recreating toolbar in wxFrame" );
944 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
957 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
959 return new wxToolBar(this, id
, wxPoint(0, 0), wxSize(100, 24), style
, name
);
962 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
964 m_frameToolBar
= toolbar
;
967 wxToolBar
*wxFrame::GetToolBar() const
969 return m_frameToolBar
;
972 void wxFrame::PositionToolBar()
976 GetClientSize(& cw
, &ch
);
981 GetToolBar()->GetSize(& tw
, & th
);
983 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
985 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
986 // means, pretend we don't have toolbar/status bar, so we
987 // have the original client size.
988 GetToolBar()->SetSize(0, 0, tw
, ch
+ th
, wxSIZE_NO_ADJUSTMENTS
);
992 // Use the 'real' position
993 GetToolBar()->SetSize(0, 0, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
997 #endif // wxUSE_TOOLBAR
999 void wxFrame::CaptureMouse()
1004 if (GetMainWidget())
1005 XtAddGrab((Widget
) m_frameShell
, TRUE
, FALSE
);
1006 m_winCaptured
= TRUE
;
1009 void wxFrame::ReleaseMouse()
1014 if (GetMainWidget())
1015 XtRemoveGrab((Widget
) m_frameShell
);
1016 m_winCaptured
= FALSE
;
1019 void wxFrame::Raise(void)
1021 Window parent_window
= XtWindow((Widget
) m_frameShell
),
1022 next_parent
= XtWindow((Widget
) m_frameShell
),
1023 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
1024 // search for the parent that is child of ROOT, because the WM may
1025 // reparent twice and notify only the next parent (like FVWM)
1026 while (next_parent
!= root
) {
1027 Window
*theChildren
; unsigned int n
;
1028 parent_window
= next_parent
;
1029 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
1030 &next_parent
, &theChildren
, &n
);
1031 XFree(theChildren
); // not needed
1033 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
1036 void wxFrame::Lower(void)
1038 Window parent_window
= XtWindow((Widget
) m_frameShell
),
1039 next_parent
= XtWindow((Widget
) m_frameShell
),
1040 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
1041 // search for the parent that is child of ROOT, because the WM may
1042 // reparent twice and notify only the next parent (like FVWM)
1043 while (next_parent
!= root
) {
1044 Window
*theChildren
; unsigned int n
;
1045 parent_window
= next_parent
;
1046 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
1047 &next_parent
, &theChildren
, &n
);
1048 XFree(theChildren
); // not needed
1050 XLowerWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
1053 void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
1054 XmAnyCallbackStruct
*cbs
)
1056 // wxDebugMsg("focus proc from frame %ld\n",(long)frame);
1058 // wxFrame *frame = (wxFrame *)clientData;
1059 // frame->GetEventHandler()->OnSetFocus();
1062 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
1063 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
1064 XCrossingEvent
* event
)
1066 wxFrame
*frame
= (wxFrame
*)wxGetWindowFromTable((Widget
)clientData
);
1069 XEvent
*e
= (XEvent
*)event
;
1071 if (e
->xany
.type
== MapNotify
)
1074 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
1075 if (!frame
->GetVisibleStatus())
1077 /* We really wanted this to be hidden! */
1078 XtUnmapWidget((Widget
) frame
->GetShellWidget());
1081 else if (e
->xany
.type
== UnmapNotify
)
1083 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)True
, NULL
);
1088 bool wxFrame::PreResize()
1092 #endif // wxUSE_TOOLBAR
1093 PositionStatusBar();
1097 WXWidget
wxFrame::GetClientWidget() const
1099 return m_clientArea
;
1102 void wxFrame::ChangeFont(bool keepOriginalSize
)
1107 void wxFrame::ChangeBackgroundColour()
1109 if (GetClientWidget())
1110 DoChangeBackgroundColour(GetClientWidget(), m_backgroundColour
);
1113 void wxFrame::ChangeForegroundColour()
1115 if (GetClientWidget())
1116 DoChangeForegroundColour(GetClientWidget(), m_foregroundColour
);
1119 void wxCloseFrameCallback(Widget widget
, XtPointer client_data
, XmAnyCallbackStruct
*cbs
)
1121 wxFrame
*frame
= (wxFrame
*)client_data
;
1123 wxCloseEvent
closeEvent(wxEVT_CLOSE_WINDOW
, frame
->GetId());
1124 closeEvent
.SetEventObject(frame
);
1126 // May delete the frame (with delayed deletion)
1127 frame
->GetEventHandler()->ProcessEvent(closeEvent
);