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
;
87 m_frameToolBar
= NULL
;
88 m_frameMenuBar
= NULL
;
89 m_frameStatusBar
= NULL
;
91 m_windowParent
= NULL
;
95 m_frameShell
= (WXWidget
) NULL
;
96 m_frameWidget
= (WXWidget
) NULL
;;
97 m_workArea
= (WXWidget
) NULL
;;
98 m_clientArea
= (WXWidget
) NULL
;;
99 m_visibleStatus
= TRUE
;
103 bool wxFrame::Create(wxWindow
*parent
,
105 const wxString
& title
,
109 const wxString
& name
)
112 wxTopLevelWindows
.Append(this);
116 m_windowStyle
= style
;
117 m_frameMenuBar
= NULL
;
118 m_frameToolBar
= NULL
;
119 m_frameStatusBar
= NULL
;
122 m_frameShell
= (WXWidget
) NULL
;
123 m_frameWidget
= (WXWidget
) NULL
;;
124 m_workArea
= (WXWidget
) NULL
;;
125 m_clientArea
= (WXWidget
) NULL
;;
126 m_visibleStatus
= TRUE
;
129 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
130 m_foregroundColour
= *wxBLACK
;
131 m_windowFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
136 m_windowId
= (int)NewControlId();
138 if (parent
) parent
->AddChild(this);
140 wxModelessWindows
.Append(this);
142 int x
= pos
.x
; int y
= pos
.y
;
143 int width
= size
.x
; int height
= size
.y
;
146 // Change suggested by Matthew Flatt
147 m_frameShell
= (WXWidget
) XtAppCreateShell(name
, wxTheApp
->GetClassName(), topLevelShellWidgetClass
, (Display
*) wxGetDisplay(), NULL
, 0);
150 m_frameShell
= wxTheApp
->GetTopLevelWidget();
151 wxTopLevelUsed
= TRUE
;
154 XtVaSetValues((Widget
) m_frameShell
,
155 // Allows menu to resize
156 XmNallowShellResize
, True
,
157 XmNdeleteResponse
, XmDO_NOTHING
,
158 XmNmappedWhenManaged
, False
,
159 XmNiconic
, (style
& wxICONIZE
) ? TRUE
: FALSE
,
163 XtVaSetValues((Widget
) m_frameShell
,
164 XmNtitle
, (const char*) title
,
167 m_frameWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
168 xmMainWindowWidgetClass
, (Widget
) m_frameShell
,
169 XmNresizePolicy
, XmRESIZE_NONE
,
172 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
173 xmFormWidgetClass
, (Widget
) m_frameWidget
,
174 XmNresizePolicy
, XmRESIZE_NONE
,
177 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
178 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
181 XmNrightAttachment
, XmATTACH_FORM
,
182 XmNleftAttachment
, XmATTACH_FORM
,
183 XmNtopAttachment
, XmATTACH_FORM
,
184 XmNbottomAttachment
, XmATTACH_FORM
,
185 // XmNresizePolicy, XmRESIZE_ANY,
188 XtVaSetValues((Widget
) m_frameWidget
,
189 XmNworkWindow
, (Widget
) m_workArea
,
193 XtManageChild((Widget
) m_clientArea
);
194 XtManageChild((Widget
) m_workArea
);
196 wxASSERT_MSG ((wxWidgetHashTable
->Get((long)m_workArea
) == (wxObject
*) NULL
), "Widget table clash in frame.cpp") ;
198 wxAddWindowToTable((Widget
) m_workArea
, this);
202 XtOverrideTranslations((Widget
) m_workArea
,
203 ptr
= XtParseTranslationTable("<Configure>: resize()"));
207 XtAddCallback((Widget
) m_workArea
, XmNfocusCallback
,
208 (XtCallbackProc
)wxFrameFocusProc
, (XtPointer
)this);
210 /* Part of show-&-hide fix */
211 XtAddEventHandler((Widget
) m_frameShell
, StructureNotifyMask
,
212 False
, (XtEventHandler
)wxFrameMapProc
,
213 (XtPointer
)m_workArea
);
216 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
218 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
220 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
222 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
224 m_mainWidget
= m_frameWidget
;
228 // This patch comes from Torsten Liermann lier@lier1.muc.de
229 if (XmIsMotifWMRunning( (Widget
) m_frameShell
))
232 if (style
& wxRESIZE_BORDER
)
233 decor
|= MWM_DECOR_RESIZEH
;
234 if (style
& wxSYSTEM_MENU
)
235 decor
|= MWM_DECOR_MENU
;
236 if ((style
& wxCAPTION
) ||
237 (style
& wxTINY_CAPTION_HORIZ
) ||
238 (style
& wxTINY_CAPTION_VERT
))
239 decor
|= MWM_DECOR_TITLE
;
240 if (style
& wxTHICK_FRAME
)
241 decor
|= MWM_DECOR_BORDER
;
242 if (style
& wxTHICK_FRAME
)
243 decor
|= MWM_DECOR_BORDER
;
244 if (style
& wxMINIMIZE_BOX
)
245 decor
|= MWM_DECOR_MINIMIZE
;
246 if (style
& wxMAXIMIZE_BOX
)
247 decor
|= MWM_DECOR_MAXIMIZE
;
248 XtVaSetValues((Widget
) m_frameShell
,XmNmwmDecorations
,decor
,NULL
) ;
250 // This allows non-Motif window managers to support at least the
251 // no-decorations case.
255 XtVaSetValues((Widget
) m_frameShell
,XmNoverrideRedirect
,TRUE
,NULL
);
257 XtRealizeWidget((Widget
) m_frameShell
);
259 // Intercept CLOSE messages from the window manager
260 Atom WM_DELETE_WINDOW
= XmInternAtom(XtDisplay((Widget
) m_frameShell
), "WM_DELETE_WINDOW", False
);
261 #if (XmREVISION > 1 || XmVERSION > 1)
262 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (XtPointer
)this);
265 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (caddr_t
)this);
267 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (void (*)())wxCloseFrameCallback
, (caddr_t
)this);
271 ChangeBackgroundColour();
275 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
276 sizeEvent
.SetEventObject(this);
278 GetEventHandler()->ProcessEvent(sizeEvent
);
290 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
291 #if MOTIF_MENUBAR_DELETE_FIX
292 GetMenuBar()->SetMainWidget((WXWidget
) NULL
);
294 delete m_frameMenuBar
;
295 m_frameMenuBar
= NULL
;
298 wxTopLevelWindows
.DeleteObject(this);
299 wxModelessWindows
.DeleteObject(this);
301 if (m_frameStatusBar
)
302 delete m_frameStatusBar
;
308 for (i = 0; i < wxMAX_STATUS; i++)
309 if (statusTextWidget[i])
310 XtDestroyWidget (statusTextWidget[i]);
313 XtDestroyWidget (statusLineForm);
315 if (statusLineWidget)
316 XtDestroyWidget (statusLineWidget);
321 wxDeleteWindowFromTable((Widget
) m_workArea
);
323 XtDestroyWidget ((Widget
) m_workArea
);
328 wxDeleteWindowFromTable((Widget
) m_frameWidget
);
329 XtDestroyWidget ((Widget
) m_frameWidget
);
333 XtDestroyWidget ((Widget
) m_frameShell
);
335 SetMainWidget((WXWidget
) NULL
);
337 /* Check if it's the last top-level window */
339 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
341 wxTheApp
->SetTopWindow(NULL
);
343 if (wxTheApp
->GetExitOnFrameDelete())
345 // Signal to the app that we're going to close
346 wxTheApp
->ExitMainLoop();
352 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
353 void wxFrame::GetClientSize(int *x
, int *y
) const
356 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
358 if (m_frameStatusBar
)
361 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
367 m_frameToolBar
->GetSize(& tbw
, & tbh
);
368 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
374 if (GetMenuBar() != (wxMenuBar*) NULL)
376 // it seems that if a frame holds a panel, the menu bar size
377 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
378 bool hasSubPanel = FALSE;
379 for(wxNode* node = GetChildren()->First(); node; node = node->Next())
381 wxWindow *win = (wxWindow *)node->Data();
382 hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)));
389 XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL);
398 // Set the client size (i.e. leave the calculation of borders etc.
400 void wxFrame::SetClientSize(int width
, int height
)
402 // Calculate how large the new main window should be
403 // by finding the difference between the client area and the
404 // main window area, and adding on to the new client area
406 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
410 if (m_frameStatusBar
)
413 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
419 m_frameToolBar
->GetSize(& tbw
, & tbh
);
420 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
426 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
430 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
431 sizeEvent
.SetEventObject(this);
433 GetEventHandler()->ProcessEvent(sizeEvent
);
437 void wxFrame::GetSize(int *width
, int *height
) const
440 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
441 *width
= xx
; *height
= yy
;
444 void wxFrame::GetPosition(int *x
, int *y
) const
446 Window parent_window
= XtWindow((Widget
) m_frameShell
),
447 next_parent
= XtWindow((Widget
) m_frameShell
),
448 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
450 // search for the parent that is child of ROOT, because the WM may
451 // reparent twice and notify only the next parent (like FVWM)
452 while (next_parent
!= root
) {
453 Window
*theChildren
; unsigned int n
;
454 parent_window
= next_parent
;
455 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
456 &next_parent
, &theChildren
, &n
);
457 XFree(theChildren
); // not needed
459 int xx
, yy
; unsigned int dummy
;
460 XGetGeometry(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
461 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
466 void wxFrame::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
469 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
471 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
473 XtVaSetValues((Widget
) m_frameWidget
, XmNwidth
, width
, NULL
);
475 XtVaSetValues((Widget
) m_frameWidget
, XmNheight
, height
, NULL
);
477 if (!(height
== -1 && width
== -1))
480 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
481 sizeEvent
.SetEventObject(this);
483 GetEventHandler()->ProcessEvent(sizeEvent
);
487 bool wxFrame::Show(bool show
)
489 m_visibleStatus
= show
; /* show-&-hide fix */
493 XtMapWidget((Widget
) m_frameShell
);
494 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), XtWindow((Widget
) m_frameShell
));
496 XtUnmapWidget((Widget
) m_frameShell
);
497 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
502 void wxFrame::Iconize(bool iconize
)
507 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, (Boolean
)iconize
, NULL
);
510 // Equivalent to maximize/restore in Windows
511 void wxFrame::Maximize(bool maximize
)
516 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, FALSE
, NULL
);
519 bool wxFrame::IsIconized() const
522 XtVaGetValues((Widget
) m_frameShell
, XmNiconic
, &iconic
, NULL
);
526 void wxFrame::SetTitle(const wxString
& title
)
528 if (title
== m_title
)
534 XtVaSetValues((Widget
) m_frameShell
,
535 XmNtitle
, (const char*) title
,
536 XmNiconName
, (const char*) title
,
540 void wxFrame::SetIcon(const wxIcon
& icon
)
546 if (!icon.Ok() || !icon.GetPixmap())
549 XtVaSetValues((Widget) m_frameShell, XtNiconPixmap, icon->.GetPixmap(), NULL);
553 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
554 const wxString
& name
)
556 wxStatusBar
*statusBar
= NULL
;
558 statusBar
= new wxStatusBar(this, id
, wxPoint(0, 0), wxSize(100, 20),
561 // Set the height according to the font and the border size
562 wxClientDC
dc(statusBar
);
563 dc
.SetFont(* statusBar
->GetFont());
566 dc
.GetTextExtent("X", &x
, &y
);
568 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
570 statusBar
->SetSize(-1, -1, 100, height
);
572 statusBar
->SetFieldsCount(number
);
576 wxStatusBar
* wxFrame::CreateStatusBar(int number
, long style
, wxWindowID id
,
577 const wxString
& name
)
579 // Calling CreateStatusBar twice is an error.
580 wxCHECK_MSG( m_frameStatusBar
== NULL
, FALSE
,
581 "recreating status bar in wxFrame" );
583 m_frameStatusBar
= OnCreateStatusBar(number
, style
, id
,
585 if ( m_frameStatusBar
)
588 return m_frameStatusBar
;
594 void wxFrame::SetStatusText(const wxString
& text
, int number
)
596 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set text for" );
598 m_frameStatusBar
->SetStatusText(text
, number
);
601 void wxFrame::SetStatusWidths(int n
, const int widths_field
[])
603 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set widths for" );
605 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
609 void wxFrame::PositionStatusBar()
611 if (!m_frameStatusBar
)
615 GetClientSize(&w
, &h
);
617 m_frameStatusBar
->GetSize(&sw
, &sh
);
619 // Since we wish the status bar to be directly under the client area,
620 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
621 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
624 WXWidget
wxFrame::GetMenuBarWidget() const
627 return GetMenuBar()->GetMainWidget();
629 return (WXWidget
) NULL
;
632 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
636 m_frameMenuBar
= NULL
;
640 // Currently can't set it twice
641 wxASSERT_MSG( (m_frameMenuBar
== (wxMenuBar
*) NULL
), "Cannot set the menubar more than once");
643 m_frameMenuBar
= menuBar
;
645 Widget menuBarW
= XmCreateMenuBar ((Widget
) m_frameWidget
, "MenuBar", NULL
, 0);
646 m_frameMenuBar
->SetMainWidget( (WXWidget
) menuBarW
);
649 for (i
= 0; i
< menuBar
->GetMenuCount(); i
++)
651 wxMenu
*menu
= menuBar
->GetMenu(i
);
652 wxString
title(menuBar
->m_titles
[i
]);
653 menu
->SetButtonWidget(menu
->CreateMenu (menuBar
, menuBarW
, menu
, title
, TRUE
));
656 * COMMENT THIS OUT IF YOU DON'T LIKE A RIGHT-JUSTIFIED HELP MENU
658 wxStripMenuCodes ((char*) (const char*) title
, wxBuffer
);
660 if (strcmp (wxBuffer
, "Help") == 0)
661 XtVaSetValues ((Widget
) menuBarW
, XmNmenuHelpWidget
, (Widget
) menu
->GetButtonWidget(), NULL
);
664 XtRealizeWidget ((Widget
) menuBarW
);
665 XtManageChild ((Widget
) menuBarW
);
666 menuBar
->SetMenuBarFrame(this);
671 // Work out max. size
672 wxNode
*node
= GetChildren()->First();
677 // Find a child that's a subwindow, but not a dialog box.
678 wxWindow
*win
= (wxWindow
*)node
->Data();
680 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
681 !win
->IsKindOf(CLASSINFO(wxDialog
)))
685 win
->GetSize(&width
, &height
);
686 win
->GetPosition(&x
, &y
);
688 if ((x
+ width
) > max_width
)
689 max_width
= x
+ width
;
690 if ((y
+ height
) > max_height
)
691 max_height
= y
+ height
;
695 SetClientSize(max_width
, max_height
);
698 // Responds to colour changes, and passes event on to children.
699 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
701 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
704 if ( m_frameStatusBar
)
706 wxSysColourChangedEvent event2
;
707 event2
.SetEventObject( m_frameStatusBar
);
708 m_frameStatusBar
->ProcessEvent(event2
);
711 // Propagate the event to the non-top-level children
712 wxWindow::OnSysColourChanged(event
);
715 // Default resizing behaviour - if only ONE subwindow,
716 // resize to client rectangle size
717 void wxFrame::OnSize(wxSizeEvent
& event
)
719 // if we're using constraints - do use them
720 #if wxUSE_CONSTRAINTS
721 if ( GetAutoLayout() ) {
727 // do we have _exactly_ one child?
728 wxWindow
*child
= NULL
;
729 for ( wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next() )
731 wxWindow
*win
= (wxWindow
*)node
->Data();
732 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) &&
733 !win
->IsKindOf(CLASSINFO(wxDialog
)) &&
734 (win
!= GetStatusBar()) &&
735 (win
!= GetToolBar()) )
738 return; // it's our second subwindow - nothing to do
744 // we have exactly one child - set it's size to fill the whole frame
745 int clientW
, clientH
;
746 GetClientSize(&clientW
, &clientH
);
751 child
->SetSize(x
, y
, clientW
, clientH
);
755 // Default activation behaviour - set the focus for the first child
757 void wxFrame::OnActivate(wxActivateEvent
& event
)
759 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
761 // Find a child that's a subwindow, but not a dialog box.
762 wxWindow
*child
= (wxWindow
*)node
->Data();
763 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
764 !child
->IsKindOf(CLASSINFO(wxDialog
)))
767 wxDebugMsg("wxFrame::OnActivate: about to set the child's focus.\n");
775 // The default implementation for the close window event - calls
776 // OnClose for backward compatibility.
778 void wxFrame::OnCloseWindow(wxCloseEvent
& event
)
781 if ( GetEventHandler()->OnClose() || event
.GetForce())
787 bool wxFrame::OnClose()
792 // Destroy the window (delayed, if a managed window)
793 bool wxFrame::Destroy()
795 if (!wxPendingDelete
.Member(this))
796 wxPendingDelete
.Append(this);
800 // Default menu selection behaviour - display a help string
801 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
805 if (event
.GetMenuId() == -1)
809 wxMenuBar
*menuBar
= GetMenuBar();
812 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
813 if (helpString
!= "")
814 SetStatusText(helpString
);
820 wxMenuBar
*wxFrame::GetMenuBar() const
822 return m_frameMenuBar
;
825 void wxFrame::Centre(int direction
)
827 int display_width
, display_height
, width
, height
, x
, y
;
828 wxDisplaySize(&display_width
, &display_height
);
830 GetSize(&width
, &height
);
833 if (direction
& wxHORIZONTAL
)
834 x
= (int)((display_width
- width
)/2);
835 if (direction
& wxVERTICAL
)
836 y
= (int)((display_height
- height
)/2);
838 SetSize(x
, y
, width
, height
);
841 // Call this to simulate a menu command
842 void wxFrame::Command(int id
)
847 void wxFrame::ProcessCommand(int id
)
849 wxCommandEvent
commandEvent(wxEVENT_TYPE_MENU_COMMAND
, id
);
850 commandEvent
.SetInt( id
);
851 commandEvent
.SetEventObject( this );
853 wxMenuBar
*bar
= GetMenuBar() ;
857 /* TODO: check the menu item if required
858 wxMenuItem *item = bar->FindItemForId(id) ;
859 if (item && item->IsCheckable())
861 bar->Check(id,!bar->Checked(id)) ;
865 GetEventHandler()->ProcessEvent(commandEvent
);
868 // Checks if there is a toolbar, and returns the first free client position
869 wxPoint
wxFrame::GetClientAreaOrigin() const
875 GetToolBar()->GetSize(& w
, & h
);
877 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
889 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
891 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
892 "recreating toolbar in wxFrame" );
894 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
907 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
909 return new wxToolBar(this, id
, wxPoint(0, 0), wxSize(100, 24), style
, name
);
912 void wxFrame::PositionToolBar()
916 GetClientSize(& cw
, &ch
);
921 GetToolBar()->GetSize(& tw
, & th
);
923 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
925 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
926 // means, pretend we don't have toolbar/status bar, so we
927 // have the original client size.
928 GetToolBar()->SetSize(0, 0, tw
, ch
+ th
, wxSIZE_NO_ADJUSTMENTS
);
932 // Use the 'real' position
933 GetToolBar()->SetSize(0, 0, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
938 void wxFrame::CaptureMouse()
944 XtAddGrab((Widget
) m_frameShell
, TRUE
, FALSE
);
945 m_winCaptured
= TRUE
;
948 void wxFrame::ReleaseMouse()
954 XtRemoveGrab((Widget
) m_frameShell
);
955 m_winCaptured
= FALSE
;
958 void wxFrame::Raise(void)
960 Window parent_window
= XtWindow((Widget
) m_frameShell
),
961 next_parent
= XtWindow((Widget
) m_frameShell
),
962 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
963 // search for the parent that is child of ROOT, because the WM may
964 // reparent twice and notify only the next parent (like FVWM)
965 while (next_parent
!= root
) {
966 Window
*theChildren
; unsigned int n
;
967 parent_window
= next_parent
;
968 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
969 &next_parent
, &theChildren
, &n
);
970 XFree(theChildren
); // not needed
972 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
975 void wxFrame::Lower(void)
977 Window parent_window
= XtWindow((Widget
) m_frameShell
),
978 next_parent
= XtWindow((Widget
) m_frameShell
),
979 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
980 // search for the parent that is child of ROOT, because the WM may
981 // reparent twice and notify only the next parent (like FVWM)
982 while (next_parent
!= root
) {
983 Window
*theChildren
; unsigned int n
;
984 parent_window
= next_parent
;
985 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
986 &next_parent
, &theChildren
, &n
);
987 XFree(theChildren
); // not needed
989 XLowerWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
992 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
993 { m_frameToolBar
= toolbar
; }
995 wxToolBar
*wxFrame::GetToolBar() const
996 { return m_frameToolBar
; }
998 void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
999 XmAnyCallbackStruct
*cbs
)
1001 wxFrame
*frame
= (wxFrame
*)clientData
;
1003 // wxDebugMsg("focus proc from frame %ld\n",(long)frame);
1005 // frame->GetEventHandler()->OnSetFocus();
1008 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
1009 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
1010 XCrossingEvent
* event
)
1012 wxFrame
*frame
= (wxFrame
*)wxWidgetHashTable
->Get((long)clientData
);
1015 XEvent
*e
= (XEvent
*)event
;
1017 if (e
->xany
.type
== MapNotify
)
1020 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
1021 if (!frame
->GetVisibleStatus())
1023 /* We really wanted this to be hidden! */
1024 XtUnmapWidget((Widget
) frame
->GetShellWidget());
1027 else if (e
->xany
.type
== UnmapNotify
)
1029 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)True
, NULL
);
1034 bool wxFrame::PreResize()
1037 PositionStatusBar();
1041 WXWidget
wxFrame::GetClientWidget() const
1043 return m_clientArea
;
1046 void wxFrame::ChangeFont(bool keepOriginalSize
)
1051 void wxFrame::ChangeBackgroundColour()
1056 void wxFrame::ChangeForegroundColour()
1061 void wxCloseFrameCallback(Widget widget
, XtPointer client_data
, XmAnyCallbackStruct
*cbs
)
1063 wxFrame
*frame
= (wxFrame
*)client_data
;
1065 wxCloseEvent
closeEvent(wxEVT_CLOSE_WINDOW
, frame
->GetId());
1066 closeEvent
.SetEventObject(frame
);
1068 // May delete the frame (with delayed deletion)
1069 frame
->GetEventHandler()->ProcessEvent(closeEvent
);