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 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
134 m_windowId
= (int)NewControlId();
136 if (parent
) parent
->AddChild(this);
138 wxModelessWindows
.Append(this);
140 int x
= pos
.x
; int y
= pos
.y
;
141 int width
= size
.x
; int height
= size
.y
;
144 // Change suggested by Matthew Flatt
145 m_frameShell
= (WXWidget
) XtAppCreateShell(name
, wxTheApp
->GetClassName(), topLevelShellWidgetClass
, (Display
*) wxGetDisplay(), NULL
, 0);
148 m_frameShell
= wxTheApp
->GetTopLevelWidget();
149 wxTopLevelUsed
= TRUE
;
152 XtVaSetValues((Widget
) m_frameShell
,
153 // Allows menu to resize
154 XmNallowShellResize
, True
,
155 XmNdeleteResponse
, XmDO_NOTHING
,
156 XmNmappedWhenManaged
, False
,
157 XmNiconic
, (style
& wxICONIZE
) ? TRUE
: FALSE
,
161 XtVaSetValues((Widget
) m_frameShell
,
162 XmNtitle
, (const char*) title
,
165 m_frameWidget
= (WXWidget
) XtVaCreateManagedWidget("main_window",
166 xmMainWindowWidgetClass
, (Widget
) m_frameShell
,
167 XmNresizePolicy
, XmRESIZE_NONE
,
170 m_workArea
= (WXWidget
) XtVaCreateWidget("form",
171 xmFormWidgetClass
, (Widget
) m_frameWidget
,
172 XmNresizePolicy
, XmRESIZE_NONE
,
175 m_clientArea
= (WXWidget
) XtVaCreateWidget("client",
176 xmBulletinBoardWidgetClass
, (Widget
) m_workArea
,
179 XmNrightAttachment
, XmATTACH_FORM
,
180 XmNleftAttachment
, XmATTACH_FORM
,
181 XmNtopAttachment
, XmATTACH_FORM
,
182 XmNbottomAttachment
, XmATTACH_FORM
,
183 // XmNresizePolicy, XmRESIZE_ANY,
186 XtVaSetValues((Widget
) m_frameWidget
,
187 XmNworkWindow
, (Widget
) m_workArea
,
191 XtManageChild((Widget
) m_clientArea
);
192 XtManageChild((Widget
) m_workArea
);
194 wxASSERT_MSG ((wxWidgetHashTable
->Get((long)m_workArea
) == (wxObject
*) NULL
), "Widget table clash in frame.cpp") ;
196 wxAddWindowToTable((Widget
) m_workArea
, this);
200 XtOverrideTranslations((Widget
) m_workArea
,
201 ptr
= XtParseTranslationTable("<Configure>: resize()"));
205 XtAddCallback((Widget
) m_workArea
, XmNfocusCallback
,
206 (XtCallbackProc
)wxFrameFocusProc
, (XtPointer
)this);
208 /* Part of show-&-hide fix */
209 XtAddEventHandler((Widget
) m_frameShell
, StructureNotifyMask
,
210 False
, (XtEventHandler
)wxFrameMapProc
,
211 (XtPointer
)m_workArea
);
214 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
216 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
218 XtVaSetValues((Widget
) m_frameShell
, XmNwidth
, width
, NULL
);
220 XtVaSetValues((Widget
) m_frameShell
, XmNheight
, height
, NULL
);
222 m_mainWidget
= m_frameWidget
;
224 // This patch comes from Torsten Liermann lier@lier1.muc.de
225 if (XmIsMotifWMRunning( (Widget
) m_frameShell
))
228 if (style
& wxRESIZE_BORDER
)
229 decor
|= MWM_DECOR_RESIZEH
;
230 if (style
& wxSYSTEM_MENU
)
231 decor
|= MWM_DECOR_MENU
;
232 if ((style
& wxCAPTION
) ||
233 (style
& wxTINY_CAPTION_HORIZ
) ||
234 (style
& wxTINY_CAPTION_VERT
))
235 decor
|= MWM_DECOR_TITLE
;
236 if (style
& wxTHICK_FRAME
)
237 decor
|= MWM_DECOR_BORDER
;
238 if (style
& wxTHICK_FRAME
)
239 decor
|= MWM_DECOR_BORDER
;
240 if (style
& wxMINIMIZE_BOX
)
241 decor
|= MWM_DECOR_MINIMIZE
;
242 if (style
& wxMAXIMIZE_BOX
)
243 decor
|= MWM_DECOR_MAXIMIZE
;
244 XtVaSetValues((Widget
) m_frameShell
,XmNmwmDecorations
,decor
,NULL
) ;
246 // This allows non-Motif window managers to support at least the
247 // no-decorations case.
251 XtVaSetValues((Widget
) m_frameShell
,XmNoverrideRedirect
,TRUE
,NULL
);
253 XtRealizeWidget((Widget
) m_frameShell
);
255 // Intercept CLOSE messages from the window manager
256 Atom WM_DELETE_WINDOW
= XmInternAtom(XtDisplay((Widget
) m_frameShell
), "WM_DELETE_WINDOW", False
);
257 #if (XmREVISION > 1 || XmVERSION > 1)
258 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (XtPointer
)this);
261 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (XtCallbackProc
) wxCloseFrameCallback
, (caddr_t
)this);
263 XmAddWMProtocolCallback((Widget
) m_frameShell
, WM_DELETE_WINDOW
, (void (*)())wxCloseFrameCallback
, (caddr_t
)this);
269 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
270 sizeEvent
.SetEventObject(this);
272 GetEventHandler()->ProcessEvent(sizeEvent
);
284 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
285 #if MOTIF_MENUBAR_DELETE_FIX
286 GetMenuBar()->SetMainWidget((WXWidget
) NULL
);
288 delete m_frameMenuBar
;
289 m_frameMenuBar
= NULL
;
292 wxTopLevelWindows
.DeleteObject(this);
293 wxModelessWindows
.DeleteObject(this);
295 if (m_frameStatusBar
)
296 delete m_frameStatusBar
;
302 for (i = 0; i < wxMAX_STATUS; i++)
303 if (statusTextWidget[i])
304 XtDestroyWidget (statusTextWidget[i]);
307 XtDestroyWidget (statusLineForm);
309 if (statusLineWidget)
310 XtDestroyWidget (statusLineWidget);
315 wxDeleteWindowFromTable((Widget
) m_workArea
);
317 XtDestroyWidget ((Widget
) m_workArea
);
322 wxDeleteWindowFromTable((Widget
) m_frameWidget
);
323 XtDestroyWidget ((Widget
) m_frameWidget
);
327 XtDestroyWidget ((Widget
) m_frameShell
);
329 SetMainWidget((WXWidget
) NULL
);
331 /* Check if it's the last top-level window */
333 if (wxTheApp
&& (wxTopLevelWindows
.Number() == 0))
335 wxTheApp
->SetTopWindow(NULL
);
337 if (wxTheApp
->GetExitOnFrameDelete())
339 // Signal to the app that we're going to close
340 wxTheApp
->ExitMainLoop();
346 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
347 void wxFrame::GetClientSize(int *x
, int *y
) const
350 XtVaGetValues((Widget
) m_workArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
352 if (m_frameStatusBar
)
355 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
361 m_frameToolBar
->GetSize(& tbw
, & tbh
);
362 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
368 if (GetMenuBar() != (wxMenuBar*) NULL)
370 // it seems that if a frame holds a panel, the menu bar size
371 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
372 bool hasSubPanel = FALSE;
373 for(wxNode* node = GetChildren()->First(); node; node = node->Next())
375 wxWindow *win = (wxWindow *)node->Data();
376 hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)));
383 XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL);
392 // Set the client size (i.e. leave the calculation of borders etc.
394 void wxFrame::SetClientSize(int width
, int height
)
396 // Calculate how large the new main window should be
397 // by finding the difference between the client area and the
398 // main window area, and adding on to the new client area
400 XtVaSetValues((Widget
) m_workArea
, XmNwidth
, width
, NULL
);
404 if (m_frameStatusBar
)
407 m_frameStatusBar
->GetSize(& sbw
, & sbh
);
413 m_frameToolBar
->GetSize(& tbw
, & tbh
);
414 if (m_frameToolBar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
420 XtVaSetValues((Widget
) m_workArea
, XmNheight
, height
, NULL
);
424 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
425 sizeEvent
.SetEventObject(this);
427 GetEventHandler()->ProcessEvent(sizeEvent
);
431 void wxFrame::GetSize(int *width
, int *height
) const
434 XtVaGetValues((Widget
) m_frameShell
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
435 *width
= xx
; *height
= yy
;
438 void wxFrame::GetPosition(int *x
, int *y
) const
440 Window parent_window
= XtWindow((Widget
) m_frameShell
),
441 next_parent
= XtWindow((Widget
) m_frameShell
),
442 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
444 // search for the parent that is child of ROOT, because the WM may
445 // reparent twice and notify only the next parent (like FVWM)
446 while (next_parent
!= root
) {
447 Window
*theChildren
; unsigned int n
;
448 parent_window
= next_parent
;
449 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
450 &next_parent
, &theChildren
, &n
);
451 XFree(theChildren
); // not needed
453 int xx
, yy
; unsigned int dummy
;
454 XGetGeometry(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
455 &xx
, &yy
, &dummy
, &dummy
, &dummy
, &dummy
);
460 void wxFrame::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
463 XtVaSetValues((Widget
) m_frameShell
, XmNx
, x
, NULL
);
465 XtVaSetValues((Widget
) m_frameShell
, XmNy
, y
, NULL
);
467 XtVaSetValues((Widget
) m_frameWidget
, XmNwidth
, width
, NULL
);
469 XtVaSetValues((Widget
) m_frameWidget
, XmNheight
, height
, NULL
);
471 if (!(height
== -1 && width
== -1))
474 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
475 sizeEvent
.SetEventObject(this);
477 GetEventHandler()->ProcessEvent(sizeEvent
);
481 bool wxFrame::Show(bool show
)
483 m_visibleStatus
= show
; /* show-&-hide fix */
487 XtMapWidget((Widget
) m_frameShell
);
488 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), XtWindow((Widget
) m_frameShell
));
490 XtUnmapWidget((Widget
) m_frameShell
);
491 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
496 void wxFrame::Iconize(bool iconize
)
501 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, (Boolean
)iconize
, NULL
);
504 // Equivalent to maximize/restore in Windows
505 void wxFrame::Maximize(bool maximize
)
510 XtVaSetValues((Widget
) m_frameShell
, XmNiconic
, FALSE
, NULL
);
513 bool wxFrame::IsIconized() const
516 XtVaGetValues((Widget
) m_frameShell
, XmNiconic
, &iconic
, NULL
);
520 void wxFrame::SetTitle(const wxString
& title
)
522 if (title
== m_title
)
528 XtVaSetValues((Widget
) m_frameShell
,
529 XmNtitle
, (const char*) title
,
530 XmNiconName
, (const char*) title
,
534 void wxFrame::SetIcon(const wxIcon
& icon
)
540 if (!icon.Ok() || !icon.GetPixmap())
543 XtVaSetValues((Widget) m_frameShell, XtNiconPixmap, icon->.GetPixmap(), NULL);
547 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
, long style
, wxWindowID id
,
548 const wxString
& name
)
550 wxStatusBar
*statusBar
= NULL
;
552 statusBar
= new wxStatusBar(this, id
, wxPoint(0, 0), wxSize(100, 20),
555 // Set the height according to the font and the border size
556 wxClientDC
dc(statusBar
);
557 dc
.SetFont(* statusBar
->GetFont());
560 dc
.GetTextExtent("X", &x
, &y
);
562 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
564 statusBar
->SetSize(-1, -1, 100, height
);
566 statusBar
->SetFieldsCount(number
);
570 wxStatusBar
* wxFrame::CreateStatusBar(int number
, long style
, wxWindowID id
,
571 const wxString
& name
)
573 // Calling CreateStatusBar twice is an error.
574 wxCHECK_MSG( m_frameStatusBar
== NULL
, FALSE
,
575 "recreating status bar in wxFrame" );
577 m_frameStatusBar
= OnCreateStatusBar(number
, style
, id
,
579 if ( m_frameStatusBar
)
582 return m_frameStatusBar
;
588 void wxFrame::SetStatusText(const wxString
& text
, int number
)
590 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set text for" );
592 m_frameStatusBar
->SetStatusText(text
, number
);
595 void wxFrame::SetStatusWidths(int n
, const int widths_field
[])
597 wxCHECK_RET( m_frameStatusBar
!= NULL
, "no statusbar to set widths for" );
599 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
603 void wxFrame::PositionStatusBar()
605 if (!m_frameStatusBar
)
609 GetClientSize(&w
, &h
);
611 m_frameStatusBar
->GetSize(&sw
, &sh
);
613 // Since we wish the status bar to be directly under the client area,
614 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
615 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
618 WXWidget
wxFrame::GetMenuBarWidget() const
621 return GetMenuBar()->GetMainWidget();
623 return (WXWidget
) NULL
;
626 void wxFrame::SetMenuBar(wxMenuBar
*menuBar
)
630 m_frameMenuBar
= NULL
;
634 // Currently can't set it twice
635 wxASSERT_MSG( (m_frameMenuBar
== (wxMenuBar
*) NULL
), "Cannot set the menubar more than once");
637 m_frameMenuBar
= menuBar
;
639 Widget menuBarW
= XmCreateMenuBar ((Widget
) m_frameWidget
, "MenuBar", NULL
, 0);
640 m_frameMenuBar
->SetMainWidget( (WXWidget
) menuBarW
);
643 for (i
= 0; i
< menuBar
->GetMenuCount(); i
++)
645 wxMenu
*menu
= menuBar
->GetMenu(i
);
646 wxString
title(menuBar
->m_titles
[i
]);
647 menu
->SetButtonWidget(menu
->CreateMenu (menuBar
, menuBarW
, menu
, title
, TRUE
));
650 * COMMENT THIS OUT IF YOU DON'T LIKE A RIGHT-JUSTIFIED HELP MENU
652 wxStripMenuCodes ((char*) (const char*) title
, wxBuffer
);
654 if (strcmp (wxBuffer
, "Help") == 0)
655 XtVaSetValues ((Widget
) menuBarW
, XmNmenuHelpWidget
, (Widget
) menu
->GetButtonWidget(), NULL
);
658 XtRealizeWidget ((Widget
) menuBarW
);
659 XtManageChild ((Widget
) menuBarW
);
660 menuBar
->SetMenuBarFrame(this);
665 // Work out max. size
666 wxNode
*node
= GetChildren()->First();
671 // Find a child that's a subwindow, but not a dialog box.
672 wxWindow
*win
= (wxWindow
*)node
->Data();
674 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
675 !win
->IsKindOf(CLASSINFO(wxDialog
)))
679 win
->GetSize(&width
, &height
);
680 win
->GetPosition(&x
, &y
);
682 if ((x
+ width
) > max_width
)
683 max_width
= x
+ width
;
684 if ((y
+ height
) > max_height
)
685 max_height
= y
+ height
;
689 SetClientSize(max_width
, max_height
);
692 // Responds to colour changes, and passes event on to children.
693 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
695 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
698 if ( m_frameStatusBar
)
700 wxSysColourChangedEvent event2
;
701 event2
.SetEventObject( m_frameStatusBar
);
702 m_frameStatusBar
->ProcessEvent(event2
);
705 // Propagate the event to the non-top-level children
706 wxWindow::OnSysColourChanged(event
);
709 // Default resizing behaviour - if only ONE subwindow,
710 // resize to client rectangle size
711 void wxFrame::OnSize(wxSizeEvent
& event
)
713 // if we're using constraints - do use them
714 #if wxUSE_CONSTRAINTS
715 if ( GetAutoLayout() ) {
721 // do we have _exactly_ one child?
722 wxWindow
*child
= NULL
;
723 for ( wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next() )
725 wxWindow
*win
= (wxWindow
*)node
->Data();
726 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) &&
727 !win
->IsKindOf(CLASSINFO(wxDialog
)) &&
728 (win
!= GetStatusBar()) &&
729 (win
!= GetToolBar()) )
732 return; // it's our second subwindow - nothing to do
738 // we have exactly one child - set it's size to fill the whole frame
739 int clientW
, clientH
;
740 GetClientSize(&clientW
, &clientH
);
745 child
->SetSize(x
, y
, clientW
, clientH
);
749 // Default activation behaviour - set the focus for the first child
751 void wxFrame::OnActivate(wxActivateEvent
& event
)
753 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
755 // Find a child that's a subwindow, but not a dialog box.
756 wxWindow
*child
= (wxWindow
*)node
->Data();
757 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) &&
758 !child
->IsKindOf(CLASSINFO(wxDialog
)))
761 wxDebugMsg("wxFrame::OnActivate: about to set the child's focus.\n");
769 // The default implementation for the close window event - calls
770 // OnClose for backward compatibility.
772 void wxFrame::OnCloseWindow(wxCloseEvent
& event
)
775 if ( GetEventHandler()->OnClose() || event
.GetForce())
781 bool wxFrame::OnClose()
786 // Destroy the window (delayed, if a managed window)
787 bool wxFrame::Destroy()
789 if (!wxPendingDelete
.Member(this))
790 wxPendingDelete
.Append(this);
794 // Default menu selection behaviour - display a help string
795 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
799 if (event
.GetMenuId() == -1)
803 wxMenuBar
*menuBar
= GetMenuBar();
806 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
807 if (helpString
!= "")
808 SetStatusText(helpString
);
814 wxMenuBar
*wxFrame::GetMenuBar() const
816 return m_frameMenuBar
;
819 void wxFrame::Centre(int direction
)
821 int display_width
, display_height
, width
, height
, x
, y
;
822 wxDisplaySize(&display_width
, &display_height
);
824 GetSize(&width
, &height
);
827 if (direction
& wxHORIZONTAL
)
828 x
= (int)((display_width
- width
)/2);
829 if (direction
& wxVERTICAL
)
830 y
= (int)((display_height
- height
)/2);
832 SetSize(x
, y
, width
, height
);
835 // Call this to simulate a menu command
836 void wxFrame::Command(int id
)
841 void wxFrame::ProcessCommand(int id
)
843 wxCommandEvent
commandEvent(wxEVENT_TYPE_MENU_COMMAND
, id
);
844 commandEvent
.SetInt( id
);
845 commandEvent
.SetEventObject( this );
847 wxMenuBar
*bar
= GetMenuBar() ;
851 /* TODO: check the menu item if required
852 wxMenuItem *item = bar->FindItemForId(id) ;
853 if (item && item->IsCheckable())
855 bar->Check(id,!bar->Checked(id)) ;
859 GetEventHandler()->ProcessEvent(commandEvent
);
862 // Checks if there is a toolbar, and returns the first free client position
863 wxPoint
wxFrame::GetClientAreaOrigin() const
869 GetToolBar()->GetSize(& w
, & h
);
871 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
883 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
885 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
886 "recreating toolbar in wxFrame" );
888 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
901 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
903 return new wxToolBar(this, id
, wxPoint(0, 0), wxSize(100, 24), style
, name
);
906 void wxFrame::PositionToolBar()
910 GetClientSize(& cw
, &ch
);
915 GetToolBar()->GetSize(& tw
, & th
);
917 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL
)
919 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
920 // means, pretend we don't have toolbar/status bar, so we
921 // have the original client size.
922 GetToolBar()->SetSize(0, 0, tw
, ch
+ th
, wxSIZE_NO_ADJUSTMENTS
);
926 // Use the 'real' position
927 GetToolBar()->SetSize(0, 0, cw
, th
, wxSIZE_NO_ADJUSTMENTS
);
932 void wxFrame::CaptureMouse()
938 XtAddGrab((Widget
) m_frameShell
, TRUE
, FALSE
);
939 m_winCaptured
= TRUE
;
942 void wxFrame::ReleaseMouse()
948 XtRemoveGrab((Widget
) m_frameShell
);
949 m_winCaptured
= FALSE
;
952 void wxFrame::Raise(void)
954 Window parent_window
= XtWindow((Widget
) m_frameShell
),
955 next_parent
= XtWindow((Widget
) m_frameShell
),
956 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
957 // search for the parent that is child of ROOT, because the WM may
958 // reparent twice and notify only the next parent (like FVWM)
959 while (next_parent
!= root
) {
960 Window
*theChildren
; unsigned int n
;
961 parent_window
= next_parent
;
962 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
963 &next_parent
, &theChildren
, &n
);
964 XFree(theChildren
); // not needed
966 XRaiseWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
969 void wxFrame::Lower(void)
971 Window parent_window
= XtWindow((Widget
) m_frameShell
),
972 next_parent
= XtWindow((Widget
) m_frameShell
),
973 root
= RootWindowOfScreen(XtScreen((Widget
) m_frameShell
));
974 // search for the parent that is child of ROOT, because the WM may
975 // reparent twice and notify only the next parent (like FVWM)
976 while (next_parent
!= root
) {
977 Window
*theChildren
; unsigned int n
;
978 parent_window
= next_parent
;
979 XQueryTree(XtDisplay((Widget
) m_frameShell
), parent_window
, &root
,
980 &next_parent
, &theChildren
, &n
);
981 XFree(theChildren
); // not needed
983 XLowerWindow(XtDisplay((Widget
) m_frameShell
), parent_window
);
986 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
987 { m_frameToolBar
= toolbar
; }
989 wxToolBar
*wxFrame::GetToolBar() const
990 { return m_frameToolBar
; }
992 void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
993 XmAnyCallbackStruct
*cbs
)
995 wxFrame
*frame
= (wxFrame
*)clientData
;
997 // wxDebugMsg("focus proc from frame %ld\n",(long)frame);
999 // frame->GetEventHandler()->OnSetFocus();
1002 /* MATTEW: Used to insure that hide-&-show within an event cycle works */
1003 static void wxFrameMapProc(Widget frameShell
, XtPointer clientData
,
1004 XCrossingEvent
* event
)
1006 wxFrame
*frame
= (wxFrame
*)wxWidgetHashTable
->Get((long)clientData
);
1009 XEvent
*e
= (XEvent
*)event
;
1011 if (e
->xany
.type
== MapNotify
)
1014 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)False
, NULL
);
1015 if (!frame
->GetVisibleStatus())
1017 /* We really wanted this to be hidden! */
1018 XtUnmapWidget((Widget
) frame
->GetShellWidget());
1021 else if (e
->xany
.type
== UnmapNotify
)
1023 XtVaSetValues(frameShell
, XmNiconic
, (Boolean
)True
, NULL
);
1028 bool wxFrame::PreResize()
1031 PositionStatusBar();
1035 WXWidget
wxFrame::GetClientWidget() const
1037 return m_clientArea
;
1040 void wxCloseFrameCallback(Widget widget
, XtPointer client_data
, XmAnyCallbackStruct
*cbs
)
1042 wxFrame
*frame
= (wxFrame
*)client_data
;
1044 wxCloseEvent
closeEvent(wxEVT_CLOSE_WINDOW
, frame
->GetId());
1045 closeEvent
.SetEventObject(frame
);
1047 // May delete the frame (with delayed deletion)
1048 frame
->GetEventHandler()->ProcessEvent(closeEvent
);