X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/da175b2ce4dc35cc4c0baa8bbdc16bf4de6c7684..ee3510132b8b4160f848bd4f502a6f5315f90dbc:/src/motif/dialog.cpp diff --git a/src/motif/dialog.cpp b/src/motif/dialog.cpp index d298056eb6..19a321cc02 100644 --- a/src/motif/dialog.cpp +++ b/src/motif/dialog.cpp @@ -6,19 +6,29 @@ // Created: 17/09/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ #pragma implementation "dialog.h" #endif +#ifdef __VMS +#define XtDisplay XTDISPLAY +#define XtWindow XTWINDOW +#define XtParent XTPARENT +#define XtScreen XTSCREEN +#endif + #include "wx/dialog.h" #include "wx/utils.h" #include "wx/frame.h" #include "wx/app.h" #include "wx/settings.h" +#ifdef __VMS__ +#pragma message disable nosimpint +#endif #include #include @@ -38,6 +48,9 @@ #if XmVersion > 1000 #include #endif +#ifdef __VMS__ +#pragma message enable nosimpint +#endif #include "wx/motif/private.h" @@ -60,28 +73,25 @@ wxList wxModalDialogs; wxList wxModelessWindows; // Frames and modeless dialogs extern wxList wxPendingDelete; -extern wxHashTable *wxWidgetHashTable; - #define wxUSE_INVISIBLE_RESIZE 1 -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxPanel) BEGIN_EVENT_TABLE(wxDialog, wxPanel) -EVT_BUTTON(wxID_OK, wxDialog::OnOK) -EVT_BUTTON(wxID_APPLY, wxDialog::OnApply) -EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel) -EVT_CHAR_HOOK(wxDialog::OnCharHook) -EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged) -EVT_CLOSE(wxDialog::OnCloseWindow) + EVT_SIZE(wxDialog::OnSize) + EVT_BUTTON(wxID_OK, wxDialog::OnOK) + EVT_BUTTON(wxID_APPLY, wxDialog::OnApply) + EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel) + EVT_CHAR_HOOK(wxDialog::OnCharHook) + EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged) + EVT_CLOSE(wxDialog::OnCloseWindow) END_EVENT_TABLE() -#endif wxDialog::wxDialog() { m_modalShowing = FALSE; - m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); + m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); } bool wxDialog::Create(wxWindow *parent, wxWindowID id, @@ -94,43 +104,43 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, m_windowStyle = style; m_modalShowing = FALSE; m_dialogTitle = title; - - m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); + + m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); m_foregroundColour = *wxBLACK; - + SetName(name); - + if (!parent) wxTopLevelWindows.Append(this); - + if (parent) parent->AddChild(this); - + if ( id == -1 ) m_windowId = (int)NewControlId(); else m_windowId = id; - + Widget parentWidget = (Widget) 0; if (parent) parentWidget = (Widget) parent->GetTopWidget(); if (!parent) parentWidget = (Widget) wxTheApp->GetTopLevelWidget(); - + wxASSERT_MSG( (parentWidget != (Widget) 0), "Could not find a suitable parent shell for dialog." ); - + Arg args[2]; XtSetArg (args[0], XmNdefaultPosition, False); XtSetArg (args[1], XmNautoUnmanage, False); Widget dialogShell = XmCreateBulletinBoardDialog(parentWidget, (char*) (const char*) name, args, 2); m_mainWidget = (WXWidget) dialogShell; - + // We don't want margins, since there is enough elsewhere. XtVaSetValues(dialogShell, XmNmarginHeight, 0, XmNmarginWidth, 0, XmNresizePolicy, XmRESIZE_NONE, NULL) ; - + Widget shell = XtParent(dialogShell) ; if (!title.IsNull()) { @@ -140,21 +150,21 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, NULL); XmStringFree(str); } - - m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); + + m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); ChangeFont(FALSE); - + wxAddWindowToTable(dialogShell, this); - + // Intercept CLOSE messages from the window manager Atom WM_DELETE_WINDOW = XmInternAtom(XtDisplay(shell), "WM_DELETE_WINDOW", False); - + /* Remove and add WM_DELETE_WINDOW so ours is only handler */ /* Why do we have to do this for wxDialog, but not wxFrame? */ XmRemoveWMProtocols(shell, &WM_DELETE_WINDOW, 1); XmAddWMProtocols(shell, &WM_DELETE_WINDOW, 1); XmActivateWMProtocol(shell, WM_DELETE_WINDOW); - + // Modified Steve Hammes for Motif 2.0 #if (XmREVISION > 1 || XmVERSION > 1) XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, (XtCallbackProc) wxCloseDialogCallback, (XtPointer)this); @@ -163,14 +173,14 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, #else XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, (void (*)())wxCloseDialogCallback, (caddr_t)this); #endif - + XtTranslations ptr ; XtOverrideTranslations(dialogShell, ptr = XtParseTranslationTable(": resize()")); XtFree((char *)ptr); - + // Can't remember what this was about... but I think it's necessary. - + if (wxUSE_INVISIBLE_RESIZE) { if (pos.x > -1) @@ -179,13 +189,13 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, if (pos.y > -1) XtVaSetValues(dialogShell, XmNy, pos.y, NULL); - + if (size.x > -1) XtVaSetValues(dialogShell, XmNwidth, size.x, NULL); if (size.y > -1) XtVaSetValues(dialogShell, XmNheight, size.y, NULL); } - + // This patch come from Torsten Liermann lier@lier1.muc.de if (XmIsMotifWMRunning(shell)) { @@ -204,7 +214,7 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, decor |= MWM_DECOR_MINIMIZE; if (m_windowStyle & wxMAXIMIZE_BOX) decor |= MWM_DECOR_MAXIMIZE; - + XtVaSetValues(shell,XmNmwmDecorations,decor,NULL) ; } // This allows non-Motif window managers to support at least the @@ -214,18 +224,18 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, if ((m_windowStyle & wxCAPTION) != wxCAPTION) XtVaSetValues((Widget) shell,XmNoverrideRedirect,TRUE,NULL); } - + XtRealizeWidget(dialogShell); - + XtAddCallback(dialogShell,XmNunmapCallback, (XtCallbackProc)wxUnmapBulletinBoard,this) ; - + // Positioning of the dialog doesn't work properly unless the dialog // is managed, so we manage without mapping to the screen. // To show, we map the shell (actually it's parent). if (!wxUSE_INVISIBLE_RESIZE) XtVaSetValues(shell, XmNmappedWhenManaged, FALSE, NULL); - + if (!wxUSE_INVISIBLE_RESIZE) { XtManageChild(dialogShell); @@ -233,15 +243,15 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, } XtAddEventHandler(dialogShell,ExposureMask,FALSE, wxUniversalRepaintProc, (XtPointer) this); - + XtAddEventHandler(dialogShell, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | KeyPressMask, FALSE, wxDialogBoxEventHandler, (XtPointer)this); - + ChangeBackgroundColour(); - + return TRUE; } @@ -252,7 +262,7 @@ void wxDialog::SetModal(bool flag) else if ( m_windowStyle & wxDIALOG_MODAL ) m_windowStyle -= wxDIALOG_MODAL ; - + wxModelessWindows.DeleteObject(this); if (!flag) wxModelessWindows.Append(this); @@ -260,32 +270,34 @@ void wxDialog::SetModal(bool flag) wxDialog::~wxDialog() { + m_isBeingDeleted = TRUE; + if (m_mainWidget) XtRemoveEventHandler((Widget) m_mainWidget, ExposureMask, FALSE, wxUniversalRepaintProc, (XtPointer) this); - + m_modalShowing = FALSE; if (!wxUSE_INVISIBLE_RESIZE && m_mainWidget) { XtUnmapWidget((Widget) m_mainWidget); } - + wxTopLevelWindows.DeleteObject(this); - + if ( (GetWindowStyleFlag() & wxDIALOG_MODAL) != wxDIALOG_MODAL ) wxModelessWindows.DeleteObject(this); - + // If this is the last top-level window, exit. if (wxTheApp && (wxTopLevelWindows.Number() == 0)) { wxTheApp->SetTopWindow(NULL); - + if (wxTheApp->GetExitOnFrameDelete()) { wxTheApp->ExitMainLoop(); } } - + // This event-flushing code used to be in wxWindow::PostDestroyChildren (wx_dialog.cpp) // but I think this should work, if we destroy the children first. // Note that this might need to be done for wxFrame also. @@ -312,7 +324,7 @@ void wxDialog::OnCharHook(wxKeyEvent& event) wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); cancelEvent.SetEventObject( this ); GetEventHandler()->ProcessEvent(cancelEvent); - + return; } // We didn't process this event. @@ -326,6 +338,45 @@ void wxDialog::Iconize(bool WXUNUSED(iconize)) // XtVaSetValues((Widget) m_mainWidget, XmNiconic, iconize, NULL); } +// Default resizing behaviour - if only ONE subwindow, +// resize to client rectangle size +void wxDialog::OnSize(wxSizeEvent& WXUNUSED(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)) ) + { + 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); + } +} + + bool wxDialog::IsIconized() const { /* @@ -355,7 +406,7 @@ void wxDialog::SetTitle(const wxString& title) if (!title.IsNull()) { XmString str = XmStringCreateSimple((char*) (const char*) title); - XtVaSetValues((Widget) m_mainWidget, + XtVaSetValues((Widget) m_mainWidget, XmNtitle, (char*) (const char*) title, XmNdialogTitle, str, // Roberto Cocchi XmNiconName, (char*) (const char*) title, @@ -369,35 +420,6 @@ wxString wxDialog::GetTitle() const return m_dialogTitle; } -void wxDialog::Centre(int direction) -{ - int x_offset,y_offset ; - int display_width, display_height; - int width, height, x, y; - wxWindow *parent = GetParent(); - if ((direction & wxCENTER_FRAME) && parent) - { - parent->GetPosition(&x_offset,&y_offset) ; - parent->GetSize(&display_width,&display_height) ; - } - else - { - wxDisplaySize(&display_width, &display_height); - x_offset = 0 ; - y_offset = 0 ; - } - - 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+x_offset, y+y_offset, width, height); -} - void wxDialog::Raise() { Window parent_window = XtWindow((Widget) m_mainWidget), @@ -435,16 +457,16 @@ void wxDialog::Lower() bool wxDialog::Show(bool show) { m_isShown = show; - + if (show) { if (!wxUSE_INVISIBLE_RESIZE) XtMapWidget(XtParent((Widget) m_mainWidget)); else - XtManageChild((Widget) m_mainWidget) ; - + XtManageChild((Widget) m_mainWidget) ; + XRaiseWindow(XtDisplay((Widget) m_mainWidget), XtWindow((Widget) m_mainWidget)); - + } else { @@ -452,11 +474,11 @@ bool wxDialog::Show(bool show) XtUnmapWidget(XtParent((Widget) m_mainWidget)); else XtUnmanageChild((Widget) m_mainWidget) ; - + XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget())); XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE); } - + return TRUE; } @@ -464,43 +486,57 @@ bool wxDialog::Show(bool show) int wxDialog::ShowModal() { m_windowStyle |= wxDIALOG_MODAL; - + Show(TRUE); - + if (m_modalShowing) return 0; - + wxModalShowingStack.Insert((wxObject *)TRUE); - + m_modalShowing = TRUE; XtAddGrab((Widget) m_mainWidget, TRUE, FALSE); - + XEvent event; - + // Loop until we signal that the dialog should be closed while ((wxModalShowingStack.Number() > 0) && ((int)(wxModalShowingStack.First()->Data()) != 0)) { // XtAppProcessEvent((XtAppContext) wxTheApp->GetAppContext(), XtIMAll); - + XtAppNextEvent((XtAppContext) wxTheApp->GetAppContext(), &event); wxTheApp->ProcessXEvent((WXEvent*) &event); + + if (XtAppPending( (XtAppContext) wxTheApp->GetAppContext() ) == 0) + { + if (!wxTheApp->ProcessIdle()) + { +#if wxUSE_THREADS + // leave the main loop to give other threads a chance to + // perform their GUI work + wxMutexGuiLeave(); + wxUsleep(20); + wxMutexGuiEnter(); +#endif + } + } } - + // Remove modal dialog flag from stack wxNode *node = wxModalShowingStack.First(); if (node) delete node; - + // Now process all events in case they get sent to a destroyed dialog XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE); while (XtAppPending((XtAppContext) wxTheApp->GetAppContext())) { XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget())); XtAppNextEvent((XtAppContext) wxTheApp->GetAppContext(), &event); - + wxTheApp->ProcessXEvent((WXEvent*) &event); } - + // TODO: is it safe to call this, if the dialog may have been deleted // by now? Probably only if we're using delayed deletion of dialogs. return GetReturnCode(); @@ -510,16 +546,16 @@ void wxDialog::EndModal(int retCode) { if (!m_modalShowing) return; - + SetReturnCode(retCode); - + // Strangely, we don't seem to need this now. // XtRemoveGrab((Widget) m_mainWidget); - + Show(FALSE); - + m_modalShowing = FALSE; - + wxNode *node = wxModalShowingStack.First(); if (node) node->SetData((wxObject *)FALSE); @@ -558,7 +594,7 @@ void wxDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) } } -void wxDialog::OnCloseWindow(wxCloseEvent& event) +void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) { // We'll send a Cancel message by default, // which may close the dialog. @@ -575,12 +611,12 @@ void wxDialog::OnCloseWindow(wxCloseEvent& event) // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog. static wxList closing; - + if ( closing.Member(this) ) return; - + closing.Append(this); - + wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); cancelEvent.SetEventObject( this ); GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog @@ -603,33 +639,28 @@ bool wxDialog::Destroy() void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)) { - SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); + SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); Refresh(); } -void wxDialog::Fit() -{ - wxWindow::Fit(); -} - // Handle a close event from the window manager -static void wxCloseDialogCallback( Widget WXUNUSED(widget), XtPointer client_data, +static void wxCloseDialogCallback( Widget WXUNUSED(widget), XtPointer client_data, XmAnyCallbackStruct *WXUNUSED(cbs)) { wxDialog *dialog = (wxDialog *)client_data; wxCloseEvent closeEvent(wxEVT_CLOSE_WINDOW, dialog->GetId()); closeEvent.SetEventObject(dialog); - + // May delete the dialog (with delayed deletion) dialog->GetEventHandler()->ProcessEvent(closeEvent); } -void wxDialogBoxEventHandler (Widget wid, - XtPointer WXUNUSED(client_data), - XEvent* event, - Boolean *continueToDispatch) +void wxDialogBoxEventHandler(Widget wid, + XtPointer WXUNUSED(client_data), + XEvent* event, + Boolean* continueToDispatch) { - wxDialog *dialog = (wxDialog *)wxWidgetHashTable->Get((long)wid); + wxDialog *dialog = (wxDialog *)wxGetWindowFromTable(wid); if (dialog) { wxMouseEvent wxevent(wxEVT_NULL); @@ -667,7 +698,7 @@ void wxDialogBoxEventHandler (Widget wid, { keyEvent.SetEventType(wxEVT_CHAR); dialog->GetEventHandler()->ProcessEvent(keyEvent); - } + } } } }