1///////////////////////////////////////////////////////////////////////////// 2// Name: src/os2/msgdlg.cpp 3// Purpose: wxMessageDialog 4// Author: David Webster 5// Modified by: 6// Created: 10/10/99 7// RCS-ID: $Id: msgdlg.cpp 39326 2006-05-25 07:07:23Z ABX $ 8// Copyright: (c) David Webster 9// Licence: wxWindows licence 10///////////////////////////////////////////////////////////////////////////// 11 12// For compilers that support precompilation, includes "wx.h". 13#include "wx/wxprec.h" 14 15#include "wx/msgdlg.h" 16 17#ifndef WX_PRECOMP 18 #include <stdio.h> 19 #include "wx/utils.h" 20 #include "wx/dialog.h" 21 #include "wx/app.h" 22 #include "wx/math.h" 23#endif 24 25#include "wx/os2/private.h" 26 27#include <stdlib.h> 28#include <string.h> 29 30#define wxDIALOG_DEFAULT_X 300 31#define wxDIALOG_DEFAULT_Y 300 32 33IMPLEMENT_CLASS(wxMessageDialog, wxDialog) 34 35wxMessageDialog::wxMessageDialog( wxWindow* WXUNUSED(pParent), 36 const wxString& rsMessage, 37 const wxString& rsCaption, 38 long lStyle, 39 const wxPoint& WXUNUSED(pPos) ) 40{ 41 m_sCaption = rsCaption; 42 m_sMessage = rsMessage; 43 m_pParent = NULL; // pParent; 44 SetMessageDialogStyle(lStyle); 45} // end of wxMessageDialog::wxMessageDialog 46 47int wxMessageDialog::ShowModal() 48{ 49 HWND hWnd = 0; 50 ULONG ulStyle = MB_OK; 51 int nAns = wxOK; 52 const long lStyle = GetMessageDialogStyle(); 53 54 if (!wxTheApp->GetTopWindow()) 55 { 56 // 57 // when the message box is shown from wxApp::OnInit() (i.e. before the 58 // message loop is entered), this must be done or the next message box 59 // will never be shown - just try putting 2 calls to wxMessageBox() in 60 // OnInit() to see it 61 // 62 while (wxTheApp->Pending()) 63 wxTheApp->Dispatch(); 64 } 65 66 if (m_pParent) 67 hWnd = (HWND) m_pParent->GetHWND(); 68 else 69 hWnd = HWND_DESKTOP; 70 if (lStyle & wxYES_NO) 71 { 72 if (lStyle & wxCANCEL) 73 ulStyle = MB_YESNOCANCEL; 74 else 75 ulStyle = MB_YESNO; 76 77 if (lStyle & wxNO_DEFAULT) 78 ulStyle |= MB_DEFBUTTON2; 79 } 80 81 if (lStyle & wxOK) 82 { 83 if (lStyle & wxCANCEL) 84 ulStyle = MB_OKCANCEL; 85 else 86 ulStyle = MB_OK; 87 } 88 if (lStyle & wxICON_EXCLAMATION) 89 ulStyle |= MB_ICONEXCLAMATION; 90 else if (lStyle & wxICON_HAND) 91 ulStyle |= MB_ICONHAND; 92 else if (lStyle & wxICON_INFORMATION) 93 ulStyle |= MB_ICONEXCLAMATION; 94 else if (lStyle & wxICON_QUESTION) 95 ulStyle |= MB_ICONQUESTION; 96 97 if (hWnd != HWND_DESKTOP) 98 ulStyle |= MB_APPLMODAL; 99 else 100 ulStyle |= MB_SYSTEMMODAL; 101 102 // 103 // This little line of code is get message boxes under OS/2 to 104 // behve like the other ports. In OS/2 if the parent is a window 105 // it displays, clipped, in the window. This centers it on the 106 // desktop, like the other ports but still allows control over modality 107 // 108 hWnd = HWND_DESKTOP; 109 110 ULONG ulAns = ::WinMessageBox( hWnd 111 ,hWnd 112 ,(PSZ)m_sMessage.c_str() 113 ,(PSZ)m_sCaption.c_str() 114 ,0L 115 ,ulStyle); 116 switch (ulAns) 117 { 118 case MBID_CANCEL: 119 nAns = wxID_CANCEL; 120 break; 121 case MBID_OK: 122 nAns = wxID_OK; 123 break; 124 case MBID_YES: 125 nAns = wxID_YES; 126 break; 127 case MBID_NO: 128 nAns = wxID_NO; 129 break; 130 default: 131 nAns = wxID_CANCEL; 132 } 133 return nAns; 134} // end of wxMessageDialog::ShowModal 135