X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/da8bed9bfd3e15e637feb4ed3fa783c82759fefc..b3402d0df8c9f763da1e32fc28c824014e5516c6:/src/motif/frame.cpp?ds=sidebyside diff --git a/src/motif/frame.cpp b/src/motif/frame.cpp index f0ddb991e0..54a0466fff 100644 --- a/src/motif/frame.cpp +++ b/src/motif/frame.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: frame.cpp +// Name: motif/frame.cpp // Purpose: wxFrame // Author: Julian Smart // Modified by: @@ -9,8 +9,16 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + #ifdef __GNUG__ -#pragma implementation "frame.h" + #pragma implementation "frame.h" #endif #include "wx/frame.h" @@ -24,16 +32,20 @@ #include "wx/app.h" #include "wx/utils.h" +#ifdef __VMS__ + #pragma message disable nosimpint +#endif + #if defined(__ultrix) || defined(__sgi) -#include + #include #endif #include #include #if XmVersion >= 1002 -#include + #include #else -#include + #include #endif #include #include @@ -45,17 +57,29 @@ #include #include #if XmVersion > 1000 -#include + #include +#endif + +#ifdef __VMS__ + #pragma message enable nosimpint #endif #include "wx/motif/private.h" -void wxCloseFrameCallback(Widget, XtPointer, XmAnyCallbackStruct *cbs); -void wxFrameFocusProc(Widget workArea, XtPointer clientData, - XmAnyCallbackStruct *cbs); +// ---------------------------------------------------------------------------- +// private functions +// ---------------------------------------------------------------------------- + +static void wxCloseFrameCallback(Widget, XtPointer, XmAnyCallbackStruct *cbs); +static void wxFrameFocusProc(Widget workArea, XtPointer clientData, + XmAnyCallbackStruct *cbs); static void wxFrameMapProc(Widget frameShell, XtPointer clientData, XCrossingEvent * event); +// ---------------------------------------------------------------------------- +// globals +// ---------------------------------------------------------------------------- + extern wxList wxModelessWindows; extern wxList wxPendingDelete; @@ -63,35 +87,27 @@ extern wxList wxPendingDelete; // top frame static bool wxTopLevelUsed = FALSE; -#if !USE_SHARED_LIBRARY -BEGIN_EVENT_TABLE(wxFrame, wxWindow) - EVT_SIZE(wxFrame::OnSize) - EVT_ACTIVATE(wxFrame::OnActivate) - EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) - EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) - EVT_IDLE(wxFrame::OnIdle) - EVT_CLOSE(wxFrame::OnCloseWindow) +// ---------------------------------------------------------------------------- +// wxWin macros +// ---------------------------------------------------------------------------- + +BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) + EVT_ACTIVATE(wxFrame::OnActivate) + EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) -#endif -#if wxUSE_NATIVE_STATUSBAR -bool wxFrame::m_useNativeStatusBar = TRUE; -#else -bool wxFrame::m_useNativeStatusBar = FALSE; -#endif - -wxFrame::wxFrame() -{ -#if wxUSE_TOOLBAR - m_frameToolBar = NULL ; -#endif // wxUSE_TOOLBAR +// ============================================================================ +// implementation +// ============================================================================ - m_frameMenuBar = NULL; - m_frameStatusBar = NULL; +// ---------------------------------------------------------------------------- +// frame construction +// ---------------------------------------------------------------------------- - m_parent = NULL; +void wxFrame::Init() +{ m_iconized = FALSE; //// Motif-specific @@ -100,7 +116,6 @@ wxFrame::wxFrame() m_workArea = (WXWidget) NULL;; m_clientArea = (WXWidget) NULL;; m_visibleStatus = TRUE; - m_title = ""; } bool wxFrame::Create(wxWindow *parent, @@ -111,25 +126,16 @@ bool wxFrame::Create(wxWindow *parent, long style, const wxString& name) { - if (!parent) + if ( parent ) + AddChild(this); + else wxTopLevelWindows.Append(this); + wxModelessWindows.Append(this); + SetName(name); m_windowStyle = style; - m_frameMenuBar = NULL; -#if wxUSE_TOOLBAR - m_frameToolBar = NULL ; -#endif // wxUSE_TOOLBAR - m_frameStatusBar = NULL; - - //// Motif-specific - m_frameShell = (WXWidget) NULL; - m_frameWidget = (WXWidget) NULL;; - m_workArea = (WXWidget) NULL;; - m_clientArea = (WXWidget) NULL;; - m_visibleStatus = TRUE; - m_title = ""; m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE); m_foregroundColour = *wxBLACK; @@ -140,10 +146,6 @@ bool wxFrame::Create(wxWindow *parent, else m_windowId = (int)NewControlId(); - if (parent) parent->AddChild(this); - - wxModelessWindows.Append(this); - int x = pos.x, y = pos.y; int width = size.x, height = size.y; @@ -171,6 +173,7 @@ bool wxFrame::Create(wxWindow *parent, if (y < 10) y = 10; } + // VZ: what does this do?? if (wxTopLevelUsed) { // Change suggested by Matthew Flatt @@ -198,9 +201,9 @@ bool wxFrame::Create(wxWindow *parent, XmNiconic, (style & wxICONIZE) ? TRUE : FALSE, NULL); - if (!title.IsNull()) + if (!title.IsEmpty()) XtVaSetValues((Widget) m_frameShell, - XmNtitle, (const char*) title, + XmNtitle, title.c_str(), NULL); m_frameWidget = (WXWidget) XtVaCreateManagedWidget("main_window", @@ -224,7 +227,8 @@ bool wxFrame::Create(wxWindow *parent, // XmNresizePolicy, XmRESIZE_ANY, NULL); - wxLogDebug("Created frame (0x%08x) with work area 0x%08x and client " + wxLogTrace(wxTRACE_Messages, + "Created frame (0x%08x) with work area 0x%08x and client " "area 0x%08x", m_frameWidget, m_workArea, m_clientArea); XtAddEventHandler((Widget) m_clientArea, ExposureMask,FALSE, @@ -239,7 +243,7 @@ bool wxFrame::Create(wxWindow *parent, wxAddWindowToTable((Widget) m_workArea, this); - XtTranslations ptr ; + XtTranslations ptr; XtOverrideTranslations((Widget) m_workArea, ptr = XtParseTranslationTable(": resize()")); @@ -270,9 +274,9 @@ bool wxFrame::Create(wxWindow *parent, // This patch comes from Torsten Liermann lier@lier1.muc.de if (XmIsMotifWMRunning( (Widget) m_frameShell )) { - int decor = 0 ; + int decor = 0; if (style & wxRESIZE_BORDER) - decor |= MWM_DECOR_RESIZEH ; + decor |= MWM_DECOR_RESIZEH; if (style & wxSYSTEM_MENU) decor |= MWM_DECOR_MENU; if ((style & wxCAPTION) || @@ -287,7 +291,7 @@ bool wxFrame::Create(wxWindow *parent, decor |= MWM_DECOR_MINIMIZE; if (style & wxMAXIMIZE_BOX) decor |= MWM_DECOR_MAXIMIZE; - XtVaSetValues((Widget) m_frameShell,XmNmwmDecorations,decor,NULL) ; + XtVaSetValues((Widget) m_frameShell,XmNmwmDecorations,decor,NULL); } // This allows non-Motif window managers to support at least the // no-decorations case. @@ -349,23 +353,13 @@ wxFrame::~wxFrame() wxModelessWindows.DeleteObject(this); if (m_frameStatusBar) + { delete m_frameStatusBar; + m_frameStatusBar = NULL; + } DestroyChildren(); - /* - int i; - for (i = 0; i < wxMAX_STATUS; i++) - if (statusTextWidget[i]) - XtDestroyWidget (statusTextWidget[i]); - - if (statusLineForm) - XtDestroyWidget (statusLineForm); - - if (statusLineWidget) - XtDestroyWidget (statusLineWidget); - */ - if (m_workArea) { wxDeleteWindowFromTable((Widget) m_workArea); @@ -396,11 +390,10 @@ wxFrame::~wxFrame() wxTheApp->ExitMainLoop(); } } - } // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. -void wxFrame::GetClientSize(int *x, int *y) const +void wxFrame::DoGetClientSize(int *x, int *y) const { Dimension xx, yy; XtVaGetValues((Widget) m_workArea, XmNwidth, &xx, XmNheight, &yy, NULL); @@ -488,14 +481,14 @@ void wxFrame::DoSetClientSize(int width, int height) } -void wxFrame::GetSize(int *width, int *height) const +void wxFrame::DoGetSize(int *width, int *height) const { Dimension xx, yy; XtVaGetValues((Widget) m_frameShell, XmNwidth, &xx, XmNheight, &yy, NULL); *width = xx; *height = yy; } -void wxFrame::GetPosition(int *x, int *y) const +void wxFrame::DoGetPosition(int *x, int *y) const { Window parent_window = XtWindow((Widget) m_frameShell), next_parent = XtWindow((Widget) m_frameShell), @@ -517,7 +510,7 @@ void wxFrame::GetPosition(int *x, int *y) const if (y) *y = yy; } -void wxFrame::DoSetSize(int x, int y, int width, int height, int sizeFlags) +void wxFrame::DoSetSize(int x, int y, int width, int height, int WXUNUSED(sizeFlags)) { if (x > -1) XtVaSetValues((Widget) m_frameShell, XmNx, x, NULL); @@ -566,13 +559,18 @@ void wxFrame::Iconize(bool iconize) XtVaSetValues((Widget) m_frameShell, XmNiconic, (Boolean)iconize, NULL); } -// Equivalent to maximize/restore in Windows +void wxFrame::Restore() +{ + if ( m_frameShell ) + XtVaSetValues((Widget) m_frameShell, XmNiconic, FALSE, NULL); +} + void wxFrame::Maximize(bool maximize) { Show(TRUE); - if (maximize && m_frameShell) - XtVaSetValues((Widget) m_frameShell, XmNiconic, FALSE, NULL); + if ( maximize ) + Restore(); } bool wxFrame::IsIconized() const @@ -586,7 +584,7 @@ bool wxFrame::IsIconized() const } // Is it maximized? -bool wxFrame::IsMaximized(void) const +bool wxFrame::IsMaximized() const { // No maximizing in Motif (?) return FALSE; @@ -601,8 +599,8 @@ void wxFrame::SetTitle(const wxString& title) if (!title.IsNull()) XtVaSetValues((Widget) m_frameShell, - XmNtitle, (const char*) title, - XmNiconName, (const char*) title, + XmNtitle, title.c_str(), + XmNiconName, title.c_str(), NULL); } @@ -619,62 +617,6 @@ void wxFrame::SetIcon(const wxIcon& icon) XtVaSetValues((Widget) m_frameShell, XtNiconPixmap, icon.GetPixmap(), NULL); } -wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, - const wxString& name) -{ - wxStatusBar *statusBar = NULL; - - statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20), - style, name); - - // Set the height according to the font and the border size - wxClientDC dc(statusBar); - dc.SetFont(statusBar->GetFont()); - - long x, y; - dc.GetTextExtent("X", &x, &y); - - int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY()); - - statusBar->SetSize(-1, -1, 100, height); - - statusBar->SetFieldsCount(number); - return statusBar; -} - -wxStatusBar* wxFrame::CreateStatusBar(int number, long style, wxWindowID id, - const wxString& name) -{ - // Calling CreateStatusBar twice is an error. - wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, - "recreating status bar in wxFrame" ); - - m_frameStatusBar = OnCreateStatusBar(number, style, id, - name); - if ( m_frameStatusBar ) - { - PositionStatusBar(); - return m_frameStatusBar; - } - else - return NULL; -} - -void wxFrame::SetStatusText(const wxString& text, int number) -{ - wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" ); - - m_frameStatusBar->SetStatusText(text, number); -} - -void wxFrame::SetStatusWidths(int n, const int widths_field[]) -{ - wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" ); - - m_frameStatusBar->SetStatusWidths(n, widths_field); - PositionStatusBar(); -} - void wxFrame::PositionStatusBar() { if (!m_frameStatusBar) @@ -719,35 +661,6 @@ void wxFrame::SetMenuBar(wxMenuBar *menuBar) m_frameMenuBar->CreateMenuBar(this); } -void wxFrame::Fit() -{ - // Work out max. size - wxNode *node = GetChildren().First(); - int max_width = 0; - int max_height = 0; - while (node) - { - // Find a child that's a subwindow, but not a dialog box. - wxWindow *win = (wxWindow *)node->Data(); - - if (!win->IsKindOf(CLASSINFO(wxFrame)) && - !win->IsKindOf(CLASSINFO(wxDialog))) - { - int width, height; - int x, y; - win->GetSize(&width, &height); - win->GetPosition(&x, &y); - - if ((x + width) > max_width) - max_width = x + width; - if ((y + height) > max_height) - max_height = y + height; - } - node = node->Next(); - } - SetClientSize(max_width, max_height); -} - // Responds to colour changes, and passes event on to children. void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) { @@ -765,53 +678,13 @@ void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) wxWindow::OnSysColourChanged(event); } -// Default resizing behaviour - if only ONE subwindow, -// resize to client rectangle size -void wxFrame::OnSize(wxSizeEvent& event) -{ - // if we're using constraints - do use them -#if wxUSE_CONSTRAINTS - if ( GetAutoLayout() ) { - Layout(); - return; - } -#endif - - // do we have _exactly_ one child? - wxWindow *child = NULL; - for ( wxNode *node = GetChildren().First(); node; node = node->Next() ) - { - wxWindow *win = (wxWindow *)node->Data(); - if ( !win->IsKindOf(CLASSINFO(wxFrame)) && - !win->IsKindOf(CLASSINFO(wxDialog)) && - (win != GetStatusBar()) -#if wxUSE_TOOLBAR - && (win != GetToolBar()) -#endif // wxUSE_TOOLBAR - ) - { - if ( child ) - return; // it's our second subwindow - nothing to do - child = win; - } - } - - if ( child ) { - // we have exactly one child - set it's size to fill the whole frame - int clientW, clientH; - GetClientSize(&clientW, &clientH); - - int x = 0; - int y = 0; - - child->SetSize(x, y, clientW, clientH); - } -} - // Default activation behaviour - set the focus for the first child // subwindow found. void wxFrame::OnActivate(wxActivateEvent& event) { + if (!event.GetActive()) + return; + for(wxNode *node = GetChildren().First(); node; node = node->Next()) { // Find a child that's a subwindow, but not a dialog box. @@ -825,182 +698,27 @@ void wxFrame::OnActivate(wxActivateEvent& event) } } -// The default implementation for the close window event. -// OnClose for backward compatibility. - -void wxFrame::OnCloseWindow(wxCloseEvent& event) -{ - this->Destroy(); -} - -// Destroy the window (delayed, if a managed window) -bool wxFrame::Destroy() -{ - if (!wxPendingDelete.Member(this)) - wxPendingDelete.Append(this); - return TRUE; -} - -// Default menu selection behaviour - display a help string -void wxFrame::OnMenuHighlight(wxMenuEvent& event) -{ - if (GetStatusBar()) - { - if (event.GetMenuId() == -1) - SetStatusText(""); - else - { - wxMenuBar *menuBar = GetMenuBar(); - if (menuBar) - { - wxString helpString(menuBar->GetHelpString(event.GetMenuId())); - if (helpString != "") - SetStatusText(helpString); - } - } - } -} - -wxMenuBar *wxFrame::GetMenuBar() const -{ - return m_frameMenuBar; -} - -void wxFrame::Centre(int direction) -{ - int display_width, display_height, width, height, x, y; - wxDisplaySize(&display_width, &display_height); - - GetSize(&width, &height); - GetPosition(&x, &y); - - if (direction & wxHORIZONTAL) - x = (int)((display_width - width)/2); - if (direction & wxVERTICAL) - y = (int)((display_height - height)/2); - - SetSize(x, y, width, height); -} - -// Call this to simulate a menu command -void wxFrame::Command(int id) -{ - ProcessCommand(id); -} - -void wxFrame::ProcessCommand(int id) -{ - wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id); - commandEvent.SetInt( id ); - commandEvent.SetEventObject( this ); - - wxMenuBar *bar = GetMenuBar() ; - if (!bar) - return; - -/* TODO: check the menu item if required - wxMenuItem *item = bar->FindItemForId(id) ; - if (item && item->IsCheckable()) - { - bar->Check(id,!bar->Checked(id)) ; - } -*/ - - wxEvtHandler* evtHandler = GetEventHandler(); - - evtHandler->ProcessEvent(commandEvent); -} - -// Checks if there is a toolbar, and returns the first free client position -wxPoint wxFrame::GetClientAreaOrigin() const -{ - wxPoint pt(0, 0); #if wxUSE_TOOLBAR - if (GetToolBar()) - { - int w, h; - GetToolBar()->GetSize(& w, & h); - if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) - { - pt.x += w; - } - else - { - pt.y += h; - } - } -#endif // wxUSE_TOOLBAR - - return pt; -} - -void wxFrame::ScreenToClient(int *x, int *y) const -{ - wxWindow::ScreenToClient(x, y); - - // We may be faking the client origin. - // So a window that's really at (0, 30) may appear - // (to wxWin apps) to be at (0, 0). - wxPoint pt(GetClientAreaOrigin()); - *x -= pt.x; - *y -= pt.y; -} - -void wxFrame::ClientToScreen(int *x, int *y) const -{ - // We may be faking the client origin. - // So a window that's really at (0, 30) may appear - // (to wxWin apps) to be at (0, 0). - wxPoint pt1(GetClientAreaOrigin()); - *x += pt1.x; - *y += pt1.y; - - wxWindow::ClientToScreen(x, y); -} - -#if wxUSE_TOOLBAR -wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) +wxToolBar* wxFrame::CreateToolBar(long style, + wxWindowID id, + const wxString& name) { - wxCHECK_MSG( m_frameToolBar == NULL, FALSE, - "recreating toolbar in wxFrame" ); - - wxToolBar* toolBar = OnCreateToolBar(style, id, name); - if (toolBar) + if ( wxFrameBase::CreateToolBar(style, id, name) ) { - SetToolBar(toolBar); PositionToolBar(); - return toolBar; - } - else - { - return NULL; } -} -wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name) -{ - return new wxToolBar(this, id, wxPoint(0, 0), wxSize(100, 24), style, name); -} - -void wxFrame::SetToolBar(wxToolBar *toolbar) -{ - m_frameToolBar = toolbar; -} - -wxToolBar *wxFrame::GetToolBar() const -{ return m_frameToolBar; } void wxFrame::PositionToolBar() { - int cw, ch; - - GetClientSize(& cw, &ch); - if (GetToolBar()) { + int cw, ch; + GetClientSize(& cw, &ch); + int tw, th; GetToolBar()->GetSize(& tw, & th); @@ -1020,27 +738,7 @@ void wxFrame::PositionToolBar() } #endif // wxUSE_TOOLBAR -void wxFrame::CaptureMouse() -{ - if (m_winCaptured) - return; - - if (GetMainWidget()) - XtAddGrab((Widget) m_frameShell, TRUE, FALSE); - m_winCaptured = TRUE; -} - -void wxFrame::ReleaseMouse() -{ - if (!m_winCaptured) - return; - - if (GetMainWidget()) - XtRemoveGrab((Widget) m_frameShell); - m_winCaptured = FALSE; -} - -void wxFrame::Raise(void) +void wxFrame::Raise() { Window parent_window = XtWindow((Widget) m_frameShell), next_parent = XtWindow((Widget) m_frameShell), @@ -1057,7 +755,7 @@ void wxFrame::Raise(void) XRaiseWindow(XtDisplay((Widget) m_frameShell), parent_window); } -void wxFrame::Lower(void) +void wxFrame::Lower() { Window parent_window = XtWindow((Widget) m_frameShell), next_parent = XtWindow((Widget) m_frameShell), @@ -1074,8 +772,8 @@ void wxFrame::Lower(void) XLowerWindow(XtDisplay((Widget) m_frameShell), parent_window); } -void wxFrameFocusProc(Widget workArea, XtPointer clientData, - XmAnyCallbackStruct *cbs) +void wxFrameFocusProc(Widget WXUNUSED(workArea), XtPointer WXUNUSED(clientData), + XmAnyCallbackStruct *WXUNUSED(cbs)) { // wxDebugMsg("focus proc from frame %ld\n",(long)frame); // TODO @@ -1114,7 +812,11 @@ bool wxFrame::PreResize() #if wxUSE_TOOLBAR PositionToolBar(); #endif // wxUSE_TOOLBAR + +#if wxUSE_STATUSBAR PositionStatusBar(); +#endif // wxUSE_STATUSBAR + return TRUE; } @@ -1123,7 +825,7 @@ WXWidget wxFrame::GetClientWidget() const return m_clientArea; } -void wxFrame::ChangeFont(bool keepOriginalSize) +void wxFrame::ChangeFont(bool WXUNUSED(keepOriginalSize)) { // TODO } @@ -1140,7 +842,7 @@ void wxFrame::ChangeForegroundColour() DoChangeForegroundColour(GetClientWidget(), m_foregroundColour); } -void wxCloseFrameCallback(Widget widget, XtPointer client_data, XmAnyCallbackStruct *cbs) +void wxCloseFrameCallback(Widget WXUNUSED(widget), XtPointer client_data, XmAnyCallbackStruct *WXUNUSED(cbs)) { wxFrame *frame = (wxFrame *)client_data;