Commit 00d865c1 authored by Dick Hollenbeck's avatar Dick Hollenbeck

Enhance DIALOG_SHIM to optionally call SetFocus() after the derived class's...

Enhance DIALOG_SHIM to optionally call SetFocus() after the derived class's constructor has been called, for wx 2.8 and wxGTK
parent 24f73eb8
...@@ -18,13 +18,16 @@ Capitalization: ...@@ -18,13 +18,16 @@ Capitalization:
Dialogs: Dialogs:
Follow the recommendations here: Follow the recommendations here:
http://library.gnome.org/devel/hig-book/2.20/windows-dialog.html.en http://library.gnome.org/devel/hig-book/2.20/windows-dialog.html.en
paying particular attention to "initial focus", "sensible default values", paying particular attention to "initial focus", "sensible default values",
"default buttons", ESC key termination. Please note that the escape key "default buttons", ESC key termination. Please note that the escape key
termination only works properly if there is a dialog button defined with termination only works properly if there is a dialog button defined with
an ID of wxID_CANCEL or SetEscapeID( MY_ESCAPE_BUTTON_ID ) is called during an ID of wxID_CANCEL or SetEscapeID( MY_ESCAPE_BUTTON_ID ) is called during
dialog initialization. The former is the preferred method for handling dialog initialization. The former is the preferred method for handling
escape key dialog termination. escape key dialog termination. There is a checkbox in wxformbuilder for
the "default" control, and this is the one fired when the "enter" key
is pressed.
Use wxWidgets "sizers" in all dialogs, no matter how simple they are: Use wxWidgets "sizers" in all dialogs, no matter how simple they are:
http://zetcode.com/tutorials/wxwidgetstutorial/layoutmanagement http://zetcode.com/tutorials/wxwidgetstutorial/layoutmanagement
......
...@@ -30,8 +30,9 @@ DIALOG_SHIM::DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& titl ...@@ -30,8 +30,9 @@ DIALOG_SHIM::DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& titl
const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : const wxPoint& pos, const wxSize& size, long style, const wxString& name ) :
wxDialog( aParent, id, title, pos, size, style, name ) wxDialog( aParent, id, title, pos, size, style, name )
{ {
// linux wxGTK needed this at one time to allow the ESCAPE key to close a wxDialog window. #if DLGSHIM_USE_SETFOCUS
SetFocus(); Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_SHIM::onInit ) );
#endif
} }
...@@ -70,17 +71,54 @@ bool DIALOG_SHIM::Show( bool show ) ...@@ -70,17 +71,54 @@ bool DIALOG_SHIM::Show( bool show )
return ret; return ret;
} }
/*
const wxSize& DIALOG_SHIM::GetLastSize() #if DLGSHIM_USE_SETFOCUS
static bool findWindowRecursively( const wxWindowList& children, const wxWindow* wanted )
{ {
const char* classname = typeid(*this).name(); for( wxWindowList::const_iterator it = children.begin(); it != children.end(); ++it )
return class_map[ classname ].GetSize(); {
const wxWindow* child = *it;
if( wanted == child )
return true;
else
{
if( findWindowRecursively( child->GetChildren(), wanted ) )
return true;
}
}
return false;
} }
const wxPoint& DIALOG_SHIM::GetLastPosition() static bool findWindowRecursively( const wxWindow* topmost, const wxWindow* wanted )
{ {
const char* classname = typeid(*this).name(); // wanted may be NULL and that is ok.
return class_map[ classname ].GetPosition();
if( wanted == topmost )
return true;
return findWindowRecursively( topmost->GetChildren(), wanted );
}
/// Set the focus if it is not already set in a derived constructor to a specific control.
void DIALOG_SHIM::onInit( wxInitDialogEvent& aEvent )
{
wxWindow* focusWnd = wxWindow::FindFocus();
// If focusWnd is not already this window or a child of it, then SetFocus().
// Otherwise the derived class's constructor SetFocus() already to a specific
// child control.
if( !findWindowRecursively( this, focusWnd ) )
{
// Linux wxGTK needs this to allow the ESCAPE key to close a wxDialog window.
SetFocus();
}
aEvent.Skip(); // derived class's handler should be called too
} }
*/ #endif
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Feb 9 2012) // C++ code generated with wxFormBuilder (version Oct 8 2012)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
#include "dialog_exit_base.h" #include "dialog_exit_base.h"
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
DIALOG_EXIT_BASE::DIALOG_EXIT_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style ) DIALOG_EXIT_BASE::DIALOG_EXIT_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style )
{ {
this->SetSizeHints( wxDefaultSize, wxDefaultSize ); this->SetSizeHints( wxDefaultSize, wxDefaultSize );
wxBoxSizer* bSizerMain; wxBoxSizer* bSizerMain;
bSizerMain = new wxBoxSizer( wxVERTICAL ); bSizerMain = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* bSizerUpper; wxBoxSizer* bSizerUpper;
bSizerUpper = new wxBoxSizer( wxHORIZONTAL ); bSizerUpper = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* bSizerBitmap; wxBoxSizer* bSizerBitmap;
bSizerBitmap = new wxBoxSizer( wxVERTICAL ); bSizerBitmap = new wxBoxSizer( wxVERTICAL );
m_bitmap = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); m_bitmap = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
bSizerBitmap->Add( m_bitmap, 0, wxALL, 5 ); bSizerBitmap->Add( m_bitmap, 0, wxALL, 5 );
bSizerUpper->Add( bSizerBitmap, 0, 0, 5 ); bSizerUpper->Add( bSizerBitmap, 0, 0, 5 );
wxBoxSizer* bSizerMessages; wxBoxSizer* bSizerMessages;
bSizerMessages = new wxBoxSizer( wxVERTICAL ); bSizerMessages = new wxBoxSizer( wxVERTICAL );
m_TextInfo = new wxStaticText( this, wxID_ANY, _("Save the changes before closing?"), wxDefaultPosition, wxDefaultSize, 0 ); m_TextInfo = new wxStaticText( this, wxID_ANY, _("Save the changes before closing?"), wxDefaultPosition, wxDefaultSize, 0 );
m_TextInfo->Wrap( -1 ); m_TextInfo->Wrap( -1 );
m_TextInfo->SetFont( wxFont( 8, 74, 90, 92, false, wxT("MS Shell Dlg 2") ) ); m_TextInfo->SetFont( wxFont( 8, 74, 90, 92, false, wxT("MS Shell Dlg 2") ) );
bSizerMessages->Add( m_TextInfo, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 ); bSizerMessages->Add( m_TextInfo, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
bSizerMessages->Add( 10, 10, 0, 0, 5 ); bSizerMessages->Add( 10, 10, 0, 0, 5 );
m_staticText2 = new wxStaticText( this, wxID_ANY, _("If you don't save, all your changes will be permanently lost."), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText2 = new wxStaticText( this, wxID_ANY, _("If you don't save, all your changes will be permanently lost."), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText2->Wrap( -1 ); m_staticText2->Wrap( -1 );
bSizerMessages->Add( m_staticText2, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 ); bSizerMessages->Add( m_staticText2, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
bSizerUpper->Add( bSizerMessages, 1, wxEXPAND, 5 ); bSizerUpper->Add( bSizerMessages, 1, wxEXPAND, 5 );
bSizerMain->Add( bSizerUpper, 1, wxEXPAND, 5 ); bSizerMain->Add( bSizerUpper, 1, wxEXPAND, 5 );
wxBoxSizer* bSizerLower; wxBoxSizer* bSizerLower;
bSizerLower = new wxBoxSizer( wxVERTICAL ); bSizerLower = new wxBoxSizer( wxVERTICAL );
m_staticline = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); m_staticline = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bSizerLower->Add( m_staticline, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 ); bSizerLower->Add( m_staticline, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 );
wxBoxSizer* bSizerButtons; wxBoxSizer* bSizerButtons;
bSizerButtons = new wxBoxSizer( wxHORIZONTAL ); bSizerButtons = new wxBoxSizer( wxHORIZONTAL );
m_buttonSaveAndExit = new wxButton( this, wxID_ANY, _("Save and Exit"), wxDefaultPosition, wxDefaultSize, 0 ); m_buttonSaveAndExit = new wxButton( this, wxID_ANY, _("Save and Exit"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerButtons->Add( m_buttonSaveAndExit, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); m_buttonSaveAndExit->SetDefault();
bSizerButtons->Add( m_buttonSaveAndExit, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
m_buttonExitNoSave = new wxButton( this, wxID_ANY, _("Exit without Save"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerButtons->Add( m_buttonExitNoSave, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); m_buttonExitNoSave = new wxButton( this, wxID_ANY, _("Exit without Save"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerButtons->Add( m_buttonExitNoSave, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
m_buttonCancel = new wxButton( this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerButtons->Add( m_buttonCancel, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); m_buttonCancel = new wxButton( this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerButtons->Add( m_buttonCancel, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
bSizerLower->Add( bSizerButtons, 0, wxALIGN_RIGHT, 5 );
bSizerLower->Add( bSizerButtons, 0, wxALIGN_RIGHT, 5 );
bSizerMain->Add( bSizerLower, 0, wxEXPAND, 5 );
bSizerMain->Add( bSizerLower, 0, wxEXPAND, 5 );
this->SetSizer( bSizerMain );
this->Layout(); this->SetSizer( bSizerMain );
this->Layout();
this->Centre( wxBOTH ); bSizerMain->Fit( this );
// Connect Events this->Centre( wxBOTH );
m_buttonSaveAndExit->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXIT_BASE::OnSaveAndExit ), NULL, this );
m_buttonExitNoSave->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXIT_BASE::OnExitNoSave ), NULL, this ); // Connect Events
m_buttonCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXIT_BASE::OnCancel ), NULL, this ); m_buttonSaveAndExit->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXIT_BASE::OnSaveAndExit ), NULL, this );
} m_buttonExitNoSave->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXIT_BASE::OnExitNoSave ), NULL, this );
m_buttonCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXIT_BASE::OnCancel ), NULL, this );
DIALOG_EXIT_BASE::~DIALOG_EXIT_BASE() }
{
// Disconnect Events DIALOG_EXIT_BASE::~DIALOG_EXIT_BASE()
m_buttonSaveAndExit->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXIT_BASE::OnSaveAndExit ), NULL, this ); {
m_buttonExitNoSave->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXIT_BASE::OnExitNoSave ), NULL, this ); // Disconnect Events
m_buttonCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXIT_BASE::OnCancel ), NULL, this ); m_buttonSaveAndExit->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXIT_BASE::OnSaveAndExit ), NULL, this );
m_buttonExitNoSave->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXIT_BASE::OnExitNoSave ), NULL, this );
} m_buttonCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_EXIT_BASE::OnCancel ), NULL, this );
}
This source diff could not be displayed because it is too large. You can view the blob instead.
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Feb 9 2012) // C++ code generated with wxFormBuilder (version Oct 8 2012)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
#ifndef __DIALOG_EXIT_BASE_H__ #ifndef __DIALOG_EXIT_BASE_H__
#define __DIALOG_EXIT_BASE_H__ #define __DIALOG_EXIT_BASE_H__
#include <wx/artprov.h> #include <wx/artprov.h>
#include <wx/xrc/xmlres.h> #include <wx/xrc/xmlres.h>
#include <wx/intl.h> #include <wx/intl.h>
#include <wx/bitmap.h> class DIALOG_SHIM;
#include <wx/image.h>
#include <wx/icon.h> #include "dialog_shim.h"
#include <wx/statbmp.h> #include <wx/bitmap.h>
#include <wx/string.h> #include <wx/image.h>
#include <wx/gdicmn.h> #include <wx/icon.h>
#include <wx/font.h> #include <wx/statbmp.h>
#include <wx/colour.h> #include <wx/gdicmn.h>
#include <wx/settings.h> #include <wx/font.h>
#include <wx/sizer.h> #include <wx/colour.h>
#include <wx/stattext.h> #include <wx/settings.h>
#include <wx/statline.h> #include <wx/string.h>
#include <wx/button.h> #include <wx/sizer.h>
#include <wx/dialog.h> #include <wx/stattext.h>
#include <wx/statline.h>
/////////////////////////////////////////////////////////////////////////// #include <wx/button.h>
#include <wx/dialog.h>
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/// Class DIALOG_EXIT_BASE
///////////////////////////////////////////////////////////////////////////////
class DIALOG_EXIT_BASE : public wxDialog ///////////////////////////////////////////////////////////////////////////////
{ /// Class DIALOG_EXIT_BASE
private: ///////////////////////////////////////////////////////////////////////////////
class DIALOG_EXIT_BASE : public DIALOG_SHIM
protected: {
wxStaticBitmap* m_bitmap; private:
wxStaticText* m_TextInfo;
wxStaticText* m_staticText2; protected:
wxStaticLine* m_staticline; wxStaticBitmap* m_bitmap;
wxButton* m_buttonSaveAndExit; wxStaticText* m_TextInfo;
wxButton* m_buttonExitNoSave; wxStaticText* m_staticText2;
wxButton* m_buttonCancel; wxStaticLine* m_staticline;
wxButton* m_buttonSaveAndExit;
// Virtual event handlers, overide them in your derived class wxButton* m_buttonExitNoSave;
virtual void OnSaveAndExit( wxCommandEvent& event ) { event.Skip(); } wxButton* m_buttonCancel;
virtual void OnExitNoSave( wxCommandEvent& event ) { event.Skip(); }
virtual void OnCancel( wxCommandEvent& event ) { event.Skip(); } // Virtual event handlers, overide them in your derived class
virtual void OnSaveAndExit( wxCommandEvent& event ) { event.Skip(); }
virtual void OnExitNoSave( wxCommandEvent& event ) { event.Skip(); }
public: virtual void OnCancel( wxCommandEvent& event ) { event.Skip(); }
DIALOG_EXIT_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 345,155 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_EXIT_BASE(); public:
}; DIALOG_EXIT_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_EXIT_BASE();
#endif //__DIALOG_EXIT_BASE_H__
};
#endif //__DIALOG_EXIT_BASE_H__
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <dialog_page_settings.h> #include <dialog_page_settings.h>
// List of page formats. // List of page formats.
// should be statically initialized, because we need both // should be statically initialized, because we need both
// the translated and the not translated version. // the translated and the not translated version.
...@@ -109,8 +110,6 @@ void DIALOG_PAGES_SETTINGS::initDialog() ...@@ -109,8 +110,6 @@ void DIALOG_PAGES_SETTINGS::initDialog()
double customSizeX; double customSizeX;
double customSizeY; double customSizeY;
SetFocus();
// initalize page format choice box and page format list. // initalize page format choice box and page format list.
// The first shows translated strings, the second contains not tralated strings // The first shows translated strings, the second contains not tralated strings
m_paperSizeComboBox->Clear(); m_paperSizeComboBox->Clear();
......
...@@ -28,6 +28,12 @@ ...@@ -28,6 +28,12 @@
#include <wx/dialog.h> #include <wx/dialog.h>
#include <hashtables.h> #include <hashtables.h>
#if wxMINOR_VERSION == 9 && defined(__WXGTK__)
#define DLGSHIM_USE_SETFOCUS 0
#else
#define DLGSHIM_USE_SETFOCUS 1
#endif
/** /**
* Class DIALOG_SHIM * Class DIALOG_SHIM
...@@ -50,10 +56,11 @@ public: ...@@ -50,10 +56,11 @@ public:
bool Show( bool show ); // overload wxDialog::Show bool Show( bool show ); // overload wxDialog::Show
/*
const wxSize& GetLastSize(); #if DLGSHIM_USE_SETFOCUS
const wxPoint& GetLastPosition(); private:
*/ void onInit( wxInitDialogEvent& aEvent );
#endif
}; };
#endif // DIALOG_SHIM_ #endif // DIALOG_SHIM_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment