From ebea0891d0a5531cfd1ff85e6d77fab66dcf834b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Karsten=20Ball=C3=BCder?= Date: Mon, 5 Jul 1999 11:22:45 +0000 Subject: [PATCH] Made icons configurable via a wxMApp virtual function. Tested on wxGTK only, added it for all ports, though. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2953 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/app.tex | 12 +++++ include/wx/defs.h | 4 +- include/wx/generic/error.xpm | 2 +- include/wx/generic/info.xpm | 2 +- include/wx/generic/question.xpm | 2 +- include/wx/generic/warning.xpm | 2 +- include/wx/gtk/app.h | 4 ++ include/wx/gtk1/app.h | 4 ++ include/wx/mac/app.h | 5 ++ include/wx/motif/app.h | 4 ++ include/wx/msw/app.h | 4 ++ include/wx/qt/app.h | 3 ++ include/wx/stubs/app.h | 4 ++ src/generic/msgdlgg.cpp | 87 ++++++++++++++++----------------- src/generic/progdlgg.cpp | 12 +++-- src/gtk/app.cpp | 28 +++++++++++ src/gtk/button.cpp | 3 +- src/gtk/msgdlg.cpp | 26 +++------- src/gtk1/app.cpp | 28 +++++++++++ src/gtk1/button.cpp | 3 +- src/gtk1/msgdlg.cpp | 26 +++------- src/msw/app.cpp | 27 +++++++++- 22 files changed, 200 insertions(+), 92 deletions(-) diff --git a/docs/latex/wx/app.tex b/docs/latex/wx/app.tex index b8833be0e6..12e553cd56 100644 --- a/docs/latex/wx/app.tex +++ b/docs/latex/wx/app.tex @@ -441,3 +441,15 @@ needs to use the top window. \helpref{wxApp::GetTopWindow}{wxappgettopwindow}, \helpref{wxApp::OnInit}{wxapponinit} +\membersection{wxApp::GetStdIcon}\label{wxappgetstdicon} + +\func{virtual wxIcon}{GetStdIcon}{\param{int }{which}} const + +Returns the icons used by wxWindows internally, e.g. the ones used for +message boxes. This function is used internally and +can be overridden by the user to change the default icons. + +\wxheading{Parameters} + +\docparam{which}{One of the wxICON_XXX defines and chooses which icon to return.} + diff --git a/include/wx/defs.h b/include/wx/defs.h index 679247afa2..565f80c520 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -402,7 +402,7 @@ enum wxMGL_UNIX, // MGL with direct hardware access wxMGL_X, // MGL on X wxMGL_WIN32, // MGL on Win32 - wxMGL_OS2, // MGL on OS/2 + wxMGL_OS2 // MGL on OS/2 }; // ---------------------------------------------------------------------------- @@ -862,6 +862,8 @@ typedef wxUint16 wxWord; #define wxICON_EXCLAMATION 0x00000040 #define wxICON_HAND 0x00000080 +#define wxICON_WARNING wxICON_EXCLAMATION +#define wxICON_ERROR wxICON_HAND #define wxICON_QUESTION 0x00000100 #define wxICON_INFORMATION 0x00000200 #define wxICON_STOP wxICON_HAND diff --git a/include/wx/generic/error.xpm b/include/wx/generic/error.xpm index 2d40c4f95b..4e9f8b0c22 100644 --- a/include/wx/generic/error.xpm +++ b/include/wx/generic/error.xpm @@ -1,5 +1,5 @@ /* XPM */ -static char * error[] = { +static char * error_xpm[] = { "48 48 78 1", " c None", ". c #000000", diff --git a/include/wx/generic/info.xpm b/include/wx/generic/info.xpm index 54fc246dfb..8fb53a9db8 100644 --- a/include/wx/generic/info.xpm +++ b/include/wx/generic/info.xpm @@ -1,5 +1,5 @@ /* XPM */ -static char * info[] = { +static char * info_xpm[] = { "48 48 159 2", " c None", ". c #12165C", diff --git a/include/wx/generic/question.xpm b/include/wx/generic/question.xpm index 4e835602bd..da37081123 100644 --- a/include/wx/generic/question.xpm +++ b/include/wx/generic/question.xpm @@ -1,5 +1,5 @@ /* XPM */ -static char * question[] = { +static char * question_xpm[] = { "48 48 165 2", " c None", ". c #000000", diff --git a/include/wx/generic/warning.xpm b/include/wx/generic/warning.xpm index f1b4d9162d..f030fa3313 100644 --- a/include/wx/generic/warning.xpm +++ b/include/wx/generic/warning.xpm @@ -1,5 +1,5 @@ /* XPM */ -static char * warning[] = { +static char * warning_xpm[] = { "48 48 151 2", " c None", ". c #C70707", diff --git a/include/wx/gtk/app.h b/include/wx/gtk/app.h index dbf52b110c..fc88199936 100644 --- a/include/wx/gtk/app.h +++ b/include/wx/gtk/app.h @@ -17,6 +17,7 @@ #include "wx/defs.h" #include "wx/window.h" #include "wx/frame.h" +#include "wx/icon.h" //----------------------------------------------------------------------------- // classes @@ -81,6 +82,9 @@ class wxApp: public wxEvtHandler virtual bool Pending(); virtual void Dispatch(); + /** Returns the standard icons for the msg dialogs, implemented in + src/generic/msgdlgg.cpp and src/gtk/app.cpp. */ + virtual wxIcon GetStdIcon(int which) const; inline void SetWantDebugOutput( bool flag ) { m_wantDebugOutput = flag; } inline bool GetWantDebugOutput() { return m_wantDebugOutput; } diff --git a/include/wx/gtk1/app.h b/include/wx/gtk1/app.h index dbf52b110c..fc88199936 100644 --- a/include/wx/gtk1/app.h +++ b/include/wx/gtk1/app.h @@ -17,6 +17,7 @@ #include "wx/defs.h" #include "wx/window.h" #include "wx/frame.h" +#include "wx/icon.h" //----------------------------------------------------------------------------- // classes @@ -81,6 +82,9 @@ class wxApp: public wxEvtHandler virtual bool Pending(); virtual void Dispatch(); + /** Returns the standard icons for the msg dialogs, implemented in + src/generic/msgdlgg.cpp and src/gtk/app.cpp. */ + virtual wxIcon GetStdIcon(int which) const; inline void SetWantDebugOutput( bool flag ) { m_wantDebugOutput = flag; } inline bool GetWantDebugOutput() { return m_wantDebugOutput; } diff --git a/include/wx/mac/app.h b/include/wx/mac/app.h index 02ed040e88..7cab45cffa 100644 --- a/include/wx/mac/app.h +++ b/include/wx/mac/app.h @@ -67,6 +67,11 @@ class WXDLLEXPORT wxApp: public wxEvtHandler virtual int OnRun() { return MainLoop(); }; virtual int OnExit() { return 0; } + + /** Returns the standard icons for the msg dialogs, implemented in + src/generic/msgdlgg.cpp and src/gtk/app.cpp. */ + virtual wxIcon GetStdIcon(int which) const; + inline void SetPrintMode(int mode) { m_printMode = mode; } inline int GetPrintMode() const { return m_printMode; } diff --git a/include/wx/motif/app.h b/include/wx/motif/app.h index 2b24418913..d70e0d98be 100644 --- a/include/wx/motif/app.h +++ b/include/wx/motif/app.h @@ -67,6 +67,10 @@ class WXDLLEXPORT wxApp: public wxEvtHandler virtual int OnRun() { return MainLoop(); }; virtual int OnExit() { return 0; } + /** Returns the standard icons for the msg dialogs, implemented in + src/generic/msgdlgg.cpp and src/gtk/app.cpp. */ + virtual wxIcon GetStdIcon(int which) const; + inline void SetPrintMode(int mode) { m_printMode = mode; } inline int GetPrintMode() const { return m_printMode; } diff --git a/include/wx/msw/app.h b/include/wx/msw/app.h index 0b79229f8b..b6b47fc9fb 100644 --- a/include/wx/msw/app.h +++ b/include/wx/msw/app.h @@ -19,6 +19,7 @@ #include "wx/defs.h" #include "wx/object.h" #include "wx/event.h" +#include "wx/icon.h" class WXDLLEXPORT wxFrame; class WXDLLEXPORT wxWindow; @@ -67,6 +68,9 @@ class WXDLLEXPORT wxApp: public wxEvtHandler // Called to set off the main loop virtual int OnRun() { return MainLoop(); }; virtual int OnExit() { return 0; } + /** Returns the standard icons for the msg dialogs, implemented in + src/generic/msgdlgg.cpp and src/gtk/app.cpp. */ + virtual wxIcon GetStdIcon(int which) const; // called when a fatal exception occurs, this function should take care not // to do anything which might provoke a nested exception! diff --git a/include/wx/qt/app.h b/include/wx/qt/app.h index cb50ba9c9e..8535882520 100644 --- a/include/wx/qt/app.h +++ b/include/wx/qt/app.h @@ -68,6 +68,9 @@ class WXDLLEXPORT wxApp: public wxEvtHandler // Called to set off the main loop virtual int OnRun() { return MainLoop(); }; virtual int OnExit() { return 0; } + /** Returns the standard icons for the msg dialogs, implemented in + src/generic/msgdlgg.cpp and src/gtk/app.cpp. */ + virtual wxIcon GetStdIcon(int which) const; inline void SetPrintMode(int mode) { m_printMode = mode; } inline int GetPrintMode() const { return m_printMode; } diff --git a/include/wx/stubs/app.h b/include/wx/stubs/app.h index 67bceb9169..fba1c3f241 100644 --- a/include/wx/stubs/app.h +++ b/include/wx/stubs/app.h @@ -67,6 +67,10 @@ class WXDLLEXPORT wxApp: public wxEvtHandler virtual int OnRun() { return MainLoop(); }; virtual int OnExit() { return 0; } + /** Returns the standard icons for the msg dialogs, implemented in + src/generic/msgdlgg.cpp and src/gtk/app.cpp. */ + virtual wxIcon GetStdIcon(int which) const; + inline void SetPrintMode(int mode) { m_printMode = mode; } inline int GetPrintMode() const { return m_printMode; } diff --git a/src/generic/msgdlgg.cpp b/src/generic/msgdlgg.cpp index 54882a1293..3bb87d73d4 100644 --- a/src/generic/msgdlgg.cpp +++ b/src/generic/msgdlgg.cpp @@ -29,6 +29,7 @@ #include "wx/layout.h" #include "wx/intl.h" #include "wx/icon.h" +# include "wx/app.h" #endif #include @@ -44,13 +45,6 @@ // icons // ---------------------------------------------------------------------------- -// MSW icons are in the ressources, for all other platforms - in XPM files -#ifndef __WXMSW__ - #include "wx/generic/info.xpm" - #include "wx/generic/question.xpm" - #include "wx/generic/warning.xpm" - #include "wx/generic/error.xpm" -#endif // __WXMSW__ #if !USE_SHARED_LIBRARY @@ -63,6 +57,46 @@ END_EVENT_TABLE() IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog) #endif +#ifdef _WXGTK__ +# include "wx/gtk/info.xpm" +# include "wx/gtk/error.xpm" +# include "wx/gtk/question.xpm" +# include "wx/gtk/warning.xpm" +#else + // MSW icons are in the ressources, for all other platforms - in XPM files +# ifndef __WXMSW__ +# include "wx/generic/info.xpm" +# include "wx/generic/question.xpm" +# include "wx/generic/warning.xpm" +# include "wx/generic/error.xpm" +# endif // __WXMSW__ +#endif + +wxIcon +wxApp::GetStdIcon(int which) const +{ + switch(which) + { + case wxICON_INFORMATION: + return wxIcon(info_xpm); + break; + case wxICON_HAND: + return wxIcon(error_xpm); + break; + case wxICON_QUESTION: + return wxIcon(question_xpm); + break; + case wxICON_EXCLAMATION: + return wxIcon(warning_xpm); + break; + default: + wxFAIL_MSG("requested non existent standard icon"); + return wxIcon(error_xpm); + break; + } +} + + wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent, const wxString& message, const wxString& caption, @@ -77,43 +111,8 @@ wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent, wxLayoutConstraints *c; SetAutoLayout(TRUE); - // create an icon - enum - { - Icon_Information, - Icon_Question, - Icon_Warning, - Icon_Error - } which; - -#ifdef __WXMSW__ - static char *icons[] = - { - "wxICON_INFO", - "wxICON_QUESTION", - "wxICON_WARNING", - "wxICON_ERROR", - }; -#else // XPM icons - static char **icons[] = - { - info, - question, - warning, - error, - }; -#endif // !XPM/XPM - - if ( style & wxICON_EXCLAMATION ) - which = Icon_Warning; - else if ( style & wxICON_HAND ) - which = Icon_Error; - else if ( style & wxICON_QUESTION ) - which = Icon_Question; - else - which = Icon_Information; - - wxStaticBitmap *icon = new wxStaticBitmap(this, -1, wxIcon(icons[which])); + wxStaticBitmap *icon = new wxStaticBitmap(this, -1, + wxTheApp->GetStdIcon(style & wxICON_MASK)); const int iconSize = icon->GetBitmap().GetWidth(); // split the message in lines diff --git a/src/generic/progdlgg.cpp b/src/generic/progdlgg.cpp index f987808944..0bd46a5ca9 100644 --- a/src/generic/progdlgg.cpp +++ b/src/generic/progdlgg.cpp @@ -81,8 +81,8 @@ wxProgressDialog::wxProgressDialog(wxString const &title, m_msg = new wxStaticText(this, -1, message); c = new wxLayoutConstraints; - c->left.SameAs(this, wxLeft, 10); - c->top.SameAs(this, wxTop, 10); + c->left.SameAs(this, wxLeft, 2*LAYOUT_X_MARGIN); + c->top.SameAs(this, wxTop, 2*LAYOUT_Y_MARGIN); c->width.AsIs(); c->height.AsIs(); m_msg->SetConstraints(c); @@ -254,12 +254,16 @@ wxProgressDialog::Update(int value, const wxString& newmsg) m_btnAbort->SetLabel(_("Close")); } - if ( !newmsg ) +/*I think the default should be the other way round. If the + application wants to set a "Done." message at the end, it should + supply it. Any serious objections to this change? Makes the + application programmers' work a little easier. + if ( !newmsg ) { // also provide the finishing message if the application didn't m_msg->SetLabel(_("Done.")); } - +*/ m_state = Finished; // so that we return TRUE below diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index e7ef187268..0aee0d7761 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -779,3 +779,31 @@ int wxEntry( int argc, char *argv[] ) return retValue; } +# include "wx/gtk/info.xpm" +# include "wx/gtk/error.xpm" +# include "wx/gtk/question.xpm" +# include "wx/gtk/warning.xpm" + +wxIcon +wxApp::GetStdIcon(int which) const +{ + switch(which) + { + case wxICON_INFORMATION: + return wxIcon(info_xpm); + break; + case wxICON_HAND: + return wxIcon(error_xpm); + break; + case wxICON_QUESTION: + return wxIcon(question_xpm); + break; + case wxICON_EXCLAMATION: + return wxIcon(warning_xpm); + break; + default: + wxFAIL_MSG("requested non existent standard icon"); + return wxIcon(error_xpm); + break; + } +} diff --git a/src/gtk/button.cpp b/src/gtk/button.cpp index cca8c9ebd3..ad9b36f8da 100644 --- a/src/gtk/button.cpp +++ b/src/gtk/button.cpp @@ -120,7 +120,8 @@ void wxButton::SetDefault(void) SetSize( m_x, m_y, m_width, m_height ); } -static wxSize wxButton::GetDefaultSize() +/* static */ +wxSize wxButton::GetDefaultSize() { return wxSize(80,26); } diff --git a/src/gtk/msgdlg.cpp b/src/gtk/msgdlg.cpp index 5e57beef40..c1d4f486e9 100644 --- a/src/gtk/msgdlg.cpp +++ b/src/gtk/msgdlg.cpp @@ -30,6 +30,7 @@ #include "wx/layout.h" #include "wx/intl.h" #include "wx/bitmap.h" +#include "wx/app.h" #endif #include @@ -38,11 +39,6 @@ #include "wx/gtk/msgdlg.h" #include "wx/statline.h" -#include "wx/gtk/info.xpm" -#include "wx/gtk/error.xpm" -#include "wx/gtk/question.xpm" -#include "wx/gtk/warning.xpm" - /////////////////////////////////////////////////////////////////// // New dialog box implementations @@ -107,19 +103,13 @@ wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent, const wxString wxSize message_size( wxSplitMessage2( message, this, text_pos_x ) ); if (m_dialogStyle & wxICON_MASK) - if (message_size.y < 50) message_size.y = 50; - - if (m_dialogStyle & wxICON_INFORMATION) - (void) new wxStaticBitmap( this, -1, wxBitmap( info_xpm ), wxPoint(15,message_size.y/2-16) ); - else - if (m_dialogStyle & wxICON_HAND) - (void) new wxStaticBitmap( this, -1, wxBitmap( error_xpm ), wxPoint(15,message_size.y/2-16) ); - else - if (m_dialogStyle & wxICON_QUESTION) - (void) new wxStaticBitmap( this, -1, wxBitmap( question_xpm ), wxPoint(15,message_size.y/2-16) ); - else - if (m_dialogStyle & wxICON_EXCLAMATION) - (void) new wxStaticBitmap( this, -1, wxBitmap( warning_xpm ), wxPoint(15,message_size.y/2-16) ); + { + if (message_size.y < 50) message_size.y = 50; + (void) new wxStaticBitmap( this, -1, + wxTheApp->GetStdIcon(m_dialogStyle + & wxICON_MASK), + wxPoint(15,message_size.y/2-16) ); + } wxButton *ok = (wxButton *) NULL; wxButton *cancel = (wxButton *) NULL; diff --git a/src/gtk1/app.cpp b/src/gtk1/app.cpp index e7ef187268..0aee0d7761 100644 --- a/src/gtk1/app.cpp +++ b/src/gtk1/app.cpp @@ -779,3 +779,31 @@ int wxEntry( int argc, char *argv[] ) return retValue; } +# include "wx/gtk/info.xpm" +# include "wx/gtk/error.xpm" +# include "wx/gtk/question.xpm" +# include "wx/gtk/warning.xpm" + +wxIcon +wxApp::GetStdIcon(int which) const +{ + switch(which) + { + case wxICON_INFORMATION: + return wxIcon(info_xpm); + break; + case wxICON_HAND: + return wxIcon(error_xpm); + break; + case wxICON_QUESTION: + return wxIcon(question_xpm); + break; + case wxICON_EXCLAMATION: + return wxIcon(warning_xpm); + break; + default: + wxFAIL_MSG("requested non existent standard icon"); + return wxIcon(error_xpm); + break; + } +} diff --git a/src/gtk1/button.cpp b/src/gtk1/button.cpp index cca8c9ebd3..ad9b36f8da 100644 --- a/src/gtk1/button.cpp +++ b/src/gtk1/button.cpp @@ -120,7 +120,8 @@ void wxButton::SetDefault(void) SetSize( m_x, m_y, m_width, m_height ); } -static wxSize wxButton::GetDefaultSize() +/* static */ +wxSize wxButton::GetDefaultSize() { return wxSize(80,26); } diff --git a/src/gtk1/msgdlg.cpp b/src/gtk1/msgdlg.cpp index 5e57beef40..c1d4f486e9 100644 --- a/src/gtk1/msgdlg.cpp +++ b/src/gtk1/msgdlg.cpp @@ -30,6 +30,7 @@ #include "wx/layout.h" #include "wx/intl.h" #include "wx/bitmap.h" +#include "wx/app.h" #endif #include @@ -38,11 +39,6 @@ #include "wx/gtk/msgdlg.h" #include "wx/statline.h" -#include "wx/gtk/info.xpm" -#include "wx/gtk/error.xpm" -#include "wx/gtk/question.xpm" -#include "wx/gtk/warning.xpm" - /////////////////////////////////////////////////////////////////// // New dialog box implementations @@ -107,19 +103,13 @@ wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent, const wxString wxSize message_size( wxSplitMessage2( message, this, text_pos_x ) ); if (m_dialogStyle & wxICON_MASK) - if (message_size.y < 50) message_size.y = 50; - - if (m_dialogStyle & wxICON_INFORMATION) - (void) new wxStaticBitmap( this, -1, wxBitmap( info_xpm ), wxPoint(15,message_size.y/2-16) ); - else - if (m_dialogStyle & wxICON_HAND) - (void) new wxStaticBitmap( this, -1, wxBitmap( error_xpm ), wxPoint(15,message_size.y/2-16) ); - else - if (m_dialogStyle & wxICON_QUESTION) - (void) new wxStaticBitmap( this, -1, wxBitmap( question_xpm ), wxPoint(15,message_size.y/2-16) ); - else - if (m_dialogStyle & wxICON_EXCLAMATION) - (void) new wxStaticBitmap( this, -1, wxBitmap( warning_xpm ), wxPoint(15,message_size.y/2-16) ); + { + if (message_size.y < 50) message_size.y = 50; + (void) new wxStaticBitmap( this, -1, + wxTheApp->GetStdIcon(m_dialogStyle + & wxICON_MASK), + wxPoint(15,message_size.y/2-16) ); + } wxButton *ok = (wxButton *) NULL; wxButton *cancel = (wxButton *) NULL; diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 13b1806806..8b1b21727f 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -43,7 +43,8 @@ #include "wx/msgdlg.h" #include "wx/intl.h" #include "wx/dynarray.h" - #include "wx/wxchar.h" +# include "wx/wxchar.h" +# include "wx/icon.h" #endif #include "wx/log.h" @@ -1148,6 +1149,30 @@ bool wxYield() return TRUE; } +wxIcon +wxApp::GetStdIcon(int which) const +{ + switch(which) + { + case wxICON_INFORMATION: + return wxIcon("wxICON_INFO"); + break; + case wxICON_HAND: + return wxIcon("wxICON_ERROR"); + break; + case wxICON_QUESTION: + return wxIcon("wxICON_QUESTION"); + break; + case wxICON_EXCLAMATION: + return wxIcon("wxICON_WARNING"); + break; + default: + wxFAIL_MSG("requested non existent standard icon"); + return wxIcon("wxICON_ERROR"); + break; + } +} + HINSTANCE wxGetInstance() { -- 2.45.2