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
;
135 m_windowId
= (int)NewControlId();
137 if (parent
) parent
->AddChild(this);
139 wxModelessWindows
.Append(this);
141 int x
= pos
.x
; int y
= pos
.y
;
142 int width
= size
.x
; int height
= size
.y
;
145 // Change suggested by Matthew Flatt
146 m_frameShell
= (WXWidget
) XtAppCreateShell(name
, wxTheApp
->GetClassName(), topLevelShellWidgetClass
, (Display
*) wxGetDisplay(), NULL
, 0);
149 m_frameShell
= wxTheApp
->GetTopLevelWidget();
150 wxTopLevelUsed
= TRUE
;
153 XtVaSetValues((Widget
) m_frameShell
,
154 // Allows menu to resize
155 XmNallowShellResize
, True
,
156 XmNdeleteResponse
, XmDO_NOTHING
,
157 XmNmappedWhenManaged
, False
,
158 XmNiconic
, (style
& wxICONIZE
) ? TRUE
: FALSE
,
162 XtVaSetValues((Widget
) m_frameShell
,
163 XmNtitle
, (const char*) title
,
166 m_frameWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
167 xmMainWindowWidgetClass
, (Widget
) m_frameShell
,
168 XmNresizePolicy
, XmRESIZE_NONE
,
171 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
172 xmFormWidgetClass
, (Widget
) m_frameWidget
,
173 XmNresizePolicy
, XmRESIZE_NONE
,
176 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
177 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
180 XmNrightAttachment
, XmATTACH_FORM
,
181 XmNleftAttachment
, XmATTACH_FORM
,
182 XmNtopAttachment
, XmATTACH_FORM
,
183 XmNbottomAttachment
, XmATTACH_FORM
,
184 // XmNresizePolicy, XmRESIZE_ANY,
187 XtVaSetValues((Widget
) m_frameWidget
,
188 XmNworkWindow
, (Widget
) m_workArea
,
192 XtManageChild((Widget
) m_clientArea
);
193 XtManageChild((Widget
) m_workArea
);
195 wxASSERT_MSG ((wxWidgetHashTable
->Get((long)m_workArea
) == (wxObject
*) NULL
), "Widget table clash in frame.cpp") ;
197 wxAddWindowToTable((Widget
) m_workArea
, this);
201 XtOverrideTranslations((Widget
) m_workArea
,
202 ptr
= XtParseTranslationTable("<Configure>: resize()"));
206 XtAddCallback((Widget
) m_workArea
, XmNfocusCallback
,
207 (XtCallbackProc
)wxFrameFocusProc
, (XtPointer
)this);
209 /* Part of show-&-hide fix */
210 XtAddEventHandler((Widget
) m_frameShell
, StructureNotifyMask
,
211 False
, (XtEventHandler
)wxFrameMapProc
,
212 (XtPointer
)m_workArea
);
215 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
217 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
219 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
221 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
223 m_mainWidget
= m_frameWidget
;
225 // This patch comes from Torsten Liermann lier@lier1.muc.de
226 if (XmIsMotifWMRunning( (Widget
) m_frameShell
))
229 if (style
& wxRESIZE_BORDER
)
230 decor
|= MWM_DECOR_RESIZEH
;
231 if (style
& wxSYSTEM_MENU
)
232 decor
|= MWM_DECOR_MENU
;
233 if ((style
& wxCAPTION
) ||
234 (style
& wxTINY_CAPTION_HORIZ
) ||
235 (style
& wxTINY_CAPTION_VERT
))
236 decor
|= MWM_DECOR_TITLE
;
237 if (style
& wxTHICK_FRAME
)
238 decor
|= MWM_DECOR_BORDER
;
239 if (style
& wxTHICK_FRAME
)
240 decor
|= MWM_DECOR_BORDER
;
241 if (style
& wxMINIMIZE_BOX
)
242 decor
|= MWM_DECOR_MINIMIZE
;
243 if (style
& wxMAXIMIZE_BOX
)
244 decor
|= MWM_DECOR_MAXIMIZE
;
245 XtVaSetValues((Widget
) m_frameShell
,XmNmwmDecorations
,decor
,NULL
) ;
247 // This allows non-Motif window managers to support at least the
248 // no-decorations case.
252 XtVaSetValues((Widget
) m_frameShell
,XmNoverrideRedirect
,TRUE
,NULL
);
254 XtRealizeWidget((Widget
) m_frameShell
);
256 // Intercept CLOSE messages from the window manager
257 Atom WM_DELETE_WINDOW
= XmInternAtom(XtDisplay((Widget
) m_frameShell
), "WM_DELETE_WINDOW", False
);
258 #if (XmREVISION > 1 || XmVERSION > 1)
259 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (XtPointer
)this);
262 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (caddr_t
)this);
264 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (void (*)())wxCloseFrameCallback
, (caddr_t
)this);
268 ChangeBackgroundColour();
272 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
273 sizeEvent
.SetEventObject(this);
275 GetEventHandler()->ProcessEvent(sizeEvent
);
287 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
288 #if MOTIF_MENUBAR_DELETE_FIX
289 GetMenuBar()->SetMainWidget((WXWidget
) NULL
);
291 delete m_frameMenuBar
;
292 m_frameMenuBar
= NULL
;
295 wxTopLevelWindows
.DeleteObject(this);
296 wxModelessWindows
.DeleteObject(this);
298 if (m_frameStatusBar
)
299 delete m_frameStatusBar
;
305 for (i = 0; i < wxMAX_STATUS; i++)
306 if (statusTextWidget[i])
307 XtDestroyWidget (statusTextWidget[i]);
310 XtDestroyWidget (statusLineForm);
312 if (statusLineWidget)
313 XtDestroyWidget (statusLineWidget);
318 wxDeleteWindowFromTable((Widget
) m_workArea
);
320 XtDestroyWidget ((Widget
) m_workArea
);
325 wxDeleteWindowFromTable((Widget
) m_frameWidget
);
326 XtDestroyWidget ((Widget
) m_frameWidget
);
330 XtDestroyWidget ((Widget
) m_frameShell
);
332 SetMainWidget((WXWidget
) NULL
);
334 /* Check if it's the last top-level window */
336 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
338 wxTheApp
->SetTopWindow(NULL
);
340 if (wxTheApp
->GetExitOnFrameDelete())
342 // Signal to the app that we're going to close
343 wxTheApp
->ExitMainLoop();
349 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
350 void wxFrame::GetClientSize(int *x
, int *y
) const
353 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
355 if (m_frameStatusBar
)
358 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
364 m_frameToolBar
->GetSize(& tbw
, & tbh
);
365 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
371 if (GetMenuBar() != (wxMenuBar*) NULL)
373 // it seems that if a frame holds a panel, the menu bar size
374 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
375 bool hasSubPanel = FALSE;
376 for(wxNode* node = GetChildren()->First(); node; node = node->Next())
378 wxWindow *win = (wxWindow *)node->Data();
379 hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)));
386 XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL);
395 // Set the client size (i.e. leave the calculation of borders etc.
397 void wxFrame::SetClientSize(int width
, int height
)
399 // Calculate how large the new main window should be
400 // by finding the difference between the client area and the
401 // main window area, and adding on to the new client area
403 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
407 if (m_frameStatusBar
)
410 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
416 m_frameToolBar
->GetSize(& tbw
, & tbh
);
417 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
423 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
427 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
428 sizeEvent
.SetEventObject(this);
430 GetEventHandler()->ProcessEvent(sizeEvent
);
434 void wxFrame::GetSize(int *width
, int *height
) const
437 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
438 *width
= xx
; *height
= yy
;
441 void wxFrame::GetPosition(int *x
, int *y
) const
443 Window parent_window
= XtWindow((Widget
) m_frameShell
),
444 next_parent
= XtWindow((Widget
) m_frameShell
),
445 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
447 // search for the parent that is child of ROOT, because the WM may
448 // reparent twice and notify only the next parent (like FVWM)
449 while (next_parent
!= root
) {
450 Window
*theChildren
; unsigned int n
;
451 parent_window
= next_parent
;
452 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
453 &next_parent
, &theChildren
, &n
);
454 XFree(theChildren
); // not needed
456 int xx
, yy
; unsigned int dummy
;
457 XGetGeometry(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
458 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
463 void wxFrame::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
466 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
468 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
470 XtVaSetValues((Widget
) m_frameWidget
, XmNwidth
, width
, NULL
);
472 XtVaSetValues((Widget
) m_frameWidget
, XmNheight
, height
, NULL
);
474 if (!(height
== -1 && width
== -1))
477 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
478 sizeEvent
.SetEventObject(this);
480 GetEventHandler()->ProcessEvent(sizeEvent
);
484 bool wxFrame::Show(bool show
)
486 m_visibleStatus
= show
; /* show-&-hide fix */
490 XtMapWidget((Widget
) m_frameShell
);
491 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), XtWindow((Widget
) m_frameShell
));
493 XtUnmapWidget((Widget
) m_frameShell
);
494 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
499 void wxFrame::Iconize(bool iconize
)
504 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, (Boolean
)iconize
, NULL
);
507 // Equivalent to maximize/restore in Windows
508 void wxFrame::Maximize(bool maximize
)
513 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, FALSE
, NULL
);
516 bool wxFrame::IsIconized() const
519 XtVaGetValues((Widget
) m_frameShell
, XmNiconic
, &iconic
, NULL
);
523 void wxFrame::SetTitle(const wxString
& title
)
525 if (title
== m_title
)
531 XtVaSetValues((Widget
) m_frameShell
,
532 XmNtitle
, (const char*) title
,
533 XmNiconName
, (const char*) title
,
537 void wxFrame::SetIcon(const wxIcon
& icon
)
543 if (!icon.Ok() || !icon.GetPixmap())
546 XtVaSetValues((Widget) m_frameShell, XtNiconPixmap, icon->.GetPixmap(), NULL);
550 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
551 const wxString
& name
)
553 wxStatusBar
*statusBar
= NULL
;
555 statusBar
= new wxStatusBar(this, id
, wxPoint(0, 0), wxSize(100, 20),
558 // Set the height according to the font and the border size
559 wxClientDC
dc(statusBar
);
560 dc
.SetFont(* statusBar
->GetFont());
563 dc
.GetTextExtent("X", &x
, &y
);
565 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
567 statusBar
->SetSize(-1, -1, 100, height
);
569 statusBar
->SetFieldsCount(number
);
573 wxStatusBar
* wxFrame::CreateStatusBar(int number
, long style
, wxWindowID id
,
574 const wxString
& name
)
576 // Calling CreateStatusBar twice is an error.
577 wxCHECK_MSG( m_frameStatusBar
== NULL
, FALSE
,
578 "recreating status bar in wxFrame" );
580 m_frameStatusBar
= OnCreateStatusBar(number
, style
, id
,
582 if ( m_frameStatusBar
)
585 return m_frameStatusBar
;
591 void wxFrame::SetStatusText(const wxString
& text
, int number
)
593 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set text for" );
595 m_frameStatusBar
->SetStatusText(text
, number
);
598 void wxFrame::SetStatusWidths(int n
, const int widths_field
[])
600 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set widths for" );
602 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
606 void wxFrame::PositionStatusBar()
608 if (!m_frameStatusBar
)
612 GetClientSize(&w
, &h
);
614 m_frameStatusBar
->GetSize(&sw
, &sh
);
616 // Since we wish the status bar to be directly under the client area,
617 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
618 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
621 WXWidget
wxFrame::GetMenuBarWidget() const
624 return GetMenuBar()->GetMainWidget();
626 return (WXWidget
) NULL
;
629 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
633 m_frameMenuBar
= NULL
;
637 // Currently can't set it twice
638 wxASSERT_MSG( (m_frameMenuBar
== (wxMenuBar
*) NULL
), "Cannot set the menubar more than once");
640 m_frameMenuBar
= menuBar
;
642 Widget menuBarW
= XmCreateMenuBar ((Widget
) m_frameWidget
, "MenuBar", NULL
, 0);
643 m_frameMenuBar
->SetMainWidget( (WXWidget
) menuBarW
);
646 for (i
= 0; i
< menuBar
->GetMenuCount(); i
++)
648 wxMenu
*menu
= menuBar
->GetMenu(i
);
649 wxString
title(menuBar
->m_titles
[i
]);
650 menu
->SetButtonWidget(menu
->CreateMenu (menuBar
, menuBarW
, menu
, title
, TRUE
));
653 * COMMENT THIS OUT IF YOU DON'T LIKE A RIGHT-JUSTIFIED HELP MENU
655 wxStripMenuCodes ((char*) (const char*) title
, wxBuffer
);
657 if (strcmp (wxBuffer
, "Help") == 0)
658 XtVaSetValues ((Widget
) menuBarW
, XmNmenuHelpWidget
, (Widget
) menu
->GetButtonWidget(), NULL
);
661 XtRealizeWidget ((Widget
) menuBarW
);
662 XtManageChild ((Widget
) menuBarW
);
663 menuBar
->SetMenuBarFrame(this);
668 // Work out max. size
669 wxNode
*node
= GetChildren()->First();
674 // Find a child that's a subwindow, but not a dialog box.
675 wxWindow
*win
= (wxWindow
*)node
->Data();
677 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
678 !win
->IsKindOf(CLASSINFO(wxDialog
)))
682 win
->GetSize(&width
, &height
);
683 win
->GetPosition(&x
, &y
);
685 if ((x
+ width
) > max_width
)
686 max_width
= x
+ width
;
687 if ((y
+ height
) > max_height
)
688 max_height
= y
+ height
;
692 SetClientSize(max_width
, max_height
);
695 // Responds to colour changes, and passes event on to children.
696 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
698 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
701 if ( m_frameStatusBar
)
703 wxSysColourChangedEvent event2
;
704 event2
.SetEventObject( m_frameStatusBar
);
705 m_frameStatusBar
->ProcessEvent(event2
);
708 // Propagate the event to the non-top-level children
709 wxWindow::OnSysColourChanged(event
);
712 // Default resizing behaviour - if only ONE subwindow,
713 // resize to client rectangle size
714 void wxFrame::OnSize(wxSizeEvent
& event
)
716 // if we're using constraints - do use them
717 #if wxUSE_CONSTRAINTS
718 if ( GetAutoLayout() ) {
724 // do we have _exactly_ one child?
725 wxWindow
*child
= NULL
;
726 for ( wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next() )
728 wxWindow
*win
= (wxWindow
*)node
->Data();
729 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) &&
730 !win
->IsKindOf(CLASSINFO(wxDialog
)) &&
731 (win
!= GetStatusBar()) &&
732 (win
!= GetToolBar()) )
735 return; // it's our second subwindow - nothing to do
741 // we have exactly one child - set it's size to fill the whole frame
742 int clientW
, clientH
;
743 GetClientSize(&clientW
, &clientH
);
748 child
->SetSize(x
, y
, clientW
, clientH
);
752 // Default activation behaviour - set the focus for the first child
754 void wxFrame::OnActivate(wxActivateEvent
& event
)
756 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
758 // Find a child that's a subwindow, but not a dialog box.
759 wxWindow
*child
= (wxWindow
*)node
->Data();
760 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
761 !child
->IsKindOf(CLASSINFO(wxDialog
)))
764 wxDebugMsg("wxFrame::OnActivate: about to set the child's focus.\n");
772 // The default implementation for the close window event - calls
773 // OnClose for backward compatibility.
775 void wxFrame::OnCloseWindow(wxCloseEvent
& event
)
778 if ( GetEventHandler()->OnClose() || event
.GetForce())
784 bool wxFrame::OnClose()
789 // Destroy the window (delayed, if a managed window)
790 bool wxFrame::Destroy()
792 if (!wxPendingDelete
.Member(this))
793 wxPendingDelete
.Append(this);
797 // Default menu selection behaviour - display a help string
798 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
802 if (event
.GetMenuId() == -1)
806 wxMenuBar
*menuBar
= GetMenuBar();
809 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
810 if (helpString
!= "")
811 SetStatusText(helpString
);
817 wxMenuBar
*wxFrame::GetMenuBar() const
819 return m_frameMenuBar
;
822 void wxFrame::Centre(int direction
)
824 int display_width
, display_height
, width
, height
, x
, y
;
825 wxDisplaySize(&display_width
, &display_height
);
827 GetSize(&width
, &height
);
830 if (direction
& wxHORIZONTAL
)
831 x
= (int)((display_width
- width
)/2);
832 if (direction
& wxVERTICAL
)
833 y
= (int)((display_height
- height
)/2);
835 SetSize(x
, y
, width
, height
);
838 // Call this to simulate a menu command
839 void wxFrame::Command(int id
)
844 void wxFrame::ProcessCommand(int id
)
846 wxCommandEvent
commandEvent(wxEVENT_TYPE_MENU_COMMAND
, id
);
847 commandEvent
.SetInt( id
);
848 commandEvent
.SetEventObject( this );
850 wxMenuBar
*bar
= GetMenuBar() ;
854 /* TODO: check the menu item if required
855 wxMenuItem *item = bar->FindItemForId(id) ;
856 if (item && item->IsCheckable())
858 bar->Check(id,!bar->Checked(id)) ;
862 GetEventHandler()->ProcessEvent(commandEvent
);
865 // Checks if there is a toolbar, and returns the first free client position
866 wxPoint
wxFrame::GetClientAreaOrigin() const
872 GetToolBar()->GetSize(& w
, & h
);
874 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
886 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
888 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
889 "recreating toolbar in wxFrame" );
891 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
904 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
906 return new wxToolBar(this, id
, wxPoint(0, 0), wxSize(100, 24), style
, name
);
909 void wxFrame::PositionToolBar()
913 GetClientSize(& cw
, &ch
);
918 GetToolBar()->GetSize(& tw
, & th
);
920 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
922 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
923 // means, pretend we don't have toolbar/status bar, so we
924 // have the original client size.
925 GetToolBar()->SetSize(0, 0, tw
, ch
+ th
, wxSIZE_NO_ADJUSTMENTS
);
929 // Use the 'real' position
930 GetToolBar()->SetSize(0, 0, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
935 void wxFrame::CaptureMouse()
941 XtAddGrab((Widget
) m_frameShell
, TRUE
, FALSE
);
942 m_winCaptured
= TRUE
;
945 void wxFrame::ReleaseMouse()
951 XtRemoveGrab((Widget
) m_frameShell
);
952 m_winCaptured
= FALSE
;
955 void wxFrame::Raise(void)
957 Window parent_window
= XtWindow((Widget
) m_frameShell
),
958 next_parent
= XtWindow((Widget
) m_frameShell
),
959 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
960 // search for the parent that is child of ROOT, because the WM may
961 // reparent twice and notify only the next parent (like FVWM)
962 while (next_parent
!= root
) {
963 Window
*theChildren
; unsigned int n
;
964 parent_window
= next_parent
;
965 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
966 &next_parent
, &theChildren
, &n
);
967 XFree(theChildren
); // not needed
969 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
972 void wxFrame::Lower(void)
974 Window parent_window
= XtWindow((Widget
) m_frameShell
),
975 next_parent
= XtWindow((Widget
) m_frameShell
),
976 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
977 // search for the parent that is child of ROOT, because the WM may
978 // reparent twice and notify only the next parent (like FVWM)
979 while (next_parent
!= root
) {
980 Window
*theChildren
; unsigned int n
;
981 parent_window
= next_parent
;
982 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
983 &next_parent
, &theChildren
, &n
);
984 XFree(theChildren
); // not needed
986 XLowerWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
989 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
990 { m_frameToolBar
= toolbar
; }
992 wxToolBar
*wxFrame::GetToolBar() const
993 { return m_frameToolBar
; }
995 void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
996 XmAnyCallbackStruct
*cbs
)
998 wxFrame
*frame
= (wxFrame
*)clientData
;
1000 // wxDebugMsg("focus proc from frame %ld\n",(long)frame);
1002 // frame->GetEventHandler()->OnSetFocus();
1005 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
1006 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
1007 XCrossingEvent
* event
)
1009 wxFrame
*frame
= (wxFrame
*)wxWidgetHashTable
->Get((long)clientData
);
1012 XEvent
*e
= (XEvent
*)event
;
1014 if (e
->xany
.type
== MapNotify
)
1017 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
1018 if (!frame
->GetVisibleStatus())
1020 /* We really wanted this to be hidden! */
1021 XtUnmapWidget((Widget
) frame
->GetShellWidget());
1024 else if (e
->xany
.type
== UnmapNotify
)
1026 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)True
, NULL
);
1031 bool wxFrame::PreResize()
1034 PositionStatusBar();
1038 WXWidget
wxFrame::GetClientWidget() const
1040 return m_clientArea
;
1043 void wxFrame::ChangeFont()
1048 void wxFrame::ChangeBackgroundColour()
1053 void wxFrame::ChangeForegroundColour()
1058 void wxCloseFrameCallback(Widget widget
, XtPointer client_data
, XmAnyCallbackStruct
*cbs
)
1060 wxFrame
*frame
= (wxFrame
*)client_data
;
1062 wxCloseEvent
closeEvent(wxEVT_CLOSE_WINDOW
, frame
->GetId());
1063 closeEvent
.SetEventObject(frame
);
1065 // May delete the frame (with delayed deletion)
1066 frame
->GetEventHandler()->ProcessEvent(closeEvent
);