From: Vadim Zeitlin Date: Thu, 27 May 1999 12:49:40 +0000 (+0000) Subject: 1. wxDataObject compilation fixes (can't test if it works right now, sorry) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/9726da4fd35db27e7210488ff431cb7a63f2f1ee?hp=082b27986b4f0f6751c1482992fc0d9eae5a931e 1. wxDataObject compilation fixes (can't test if it works right now, sorry) 2. wxProgressDialog ctor has "style" parameter 3. the controls samples now also demonstrates wxUpdateUI events and wxProgressDialog git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2580 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/dataobj.h b/include/wx/dataobj.h index c1ac807fc3..fad2dc6664 100644 --- a/include/wx/dataobj.h +++ b/include/wx/dataobj.h @@ -109,7 +109,7 @@ public: wxString GetId() const { return m_format.GetId(); } // implement the base class pure virtuals - virtual wxDataFormat GetPreferredFormat() const + virtual wxDataFormatId GetPreferredFormat() const { return m_format; } virtual bool IsSupportedFormat(wxDataFormat format) const { return m_format == format; } diff --git a/include/wx/defs.h b/include/wx/defs.h index 9138b54608..eb9e55b1dc 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -646,7 +646,12 @@ typedef void (*wxFunction) (wxObject&, wxEvent&); #define wxLI_HORIZONTAL wxHORIZONTAL #define wxLI_VERTICAL wxVERTICAL - +/* + * wxProgressDialog flags + */ +#define wxPD_CAN_ABORT 0x0001 +#define wxPD_APP_MODAL 0x0002 +#define wxPD_AUTO_HIDE 0x0004 /* * GDI descriptions diff --git a/include/wx/generic/progdlgg.h b/include/wx/generic/progdlgg.h index 27b5fffe4f..e839b7fe35 100644 --- a/include/wx/generic/progdlgg.h +++ b/include/wx/generic/progdlgg.h @@ -32,17 +32,14 @@ public: frames or parent frame to avoid recursion problems. @param title title for window @param message message to display in window - @param maximum maximum value for status bar, if <= 0, no bar is shown + @param maximum value for status bar, if <= 0, no bar is shown @param parent window or NULL - @param disableParentOnly if true, only disable parent window's - event handling - @param abortButton if true, dialog will show an abort button + @param style is the bit mask of wxPD_XXX constants from wx/defs.h */ wxProgressDialog(const wxString &title, wxString const &message, int maximum = 100, wxWindow *parent = NULL, - bool disableParentOnly = FALSE, - bool abortButton = FALSE); + int style = wxPD_APP_MODAL | wxPD_AUTO_HIDE); /** Destructor. Re-enables event handling for other windows. */ diff --git a/include/wx/gtk/dataobj.h b/include/wx/gtk/dataobj.h index 4949cf9c51..e8d598e3dd 100644 --- a/include/wx/gtk/dataobj.h +++ b/include/wx/gtk/dataobj.h @@ -44,7 +44,7 @@ public: wxDataFormat( wxDataFormatId type ); wxDataFormat( const wxString &id ); wxDataFormat( const wxChar *id ); - wxDataFormat( wxDataFormat &format ); + wxDataFormat( const wxDataFormat &format ); wxDataFormat( const GdkAtom atom ); void SetType( wxDataFormatId type ); @@ -62,6 +62,12 @@ public: GdkAtom GetAtom(); void SetAtom(GdkAtom atom) { m_hasAtom = TRUE; m_atom = atom; } + // implicit conversion to wxDataFormatId + operator wxDataFormatId() const { return m_type; } + + bool operator==(wxDataFormatId type) const { return m_type == type; } + bool operator!=(wxDataFormatId type) const { return m_type != type; } + private: wxDataFormatId m_type; wxString m_id; @@ -96,7 +102,7 @@ private: virtual wxDataFormat &GetNthFormat( size_t nth ) const; /* return preferrd/best supported format */ - virtual wxDataFormat &GetPreferredFormat() const; + virtual wxDataFormatId GetPreferredFormat() const; /* search through m_dataObjects, return TRUE if found */ virtual bool IsSupportedFormat( wxDataFormat &format ) const; diff --git a/include/wx/gtk1/dataobj.h b/include/wx/gtk1/dataobj.h index 4949cf9c51..e8d598e3dd 100644 --- a/include/wx/gtk1/dataobj.h +++ b/include/wx/gtk1/dataobj.h @@ -44,7 +44,7 @@ public: wxDataFormat( wxDataFormatId type ); wxDataFormat( const wxString &id ); wxDataFormat( const wxChar *id ); - wxDataFormat( wxDataFormat &format ); + wxDataFormat( const wxDataFormat &format ); wxDataFormat( const GdkAtom atom ); void SetType( wxDataFormatId type ); @@ -62,6 +62,12 @@ public: GdkAtom GetAtom(); void SetAtom(GdkAtom atom) { m_hasAtom = TRUE; m_atom = atom; } + // implicit conversion to wxDataFormatId + operator wxDataFormatId() const { return m_type; } + + bool operator==(wxDataFormatId type) const { return m_type == type; } + bool operator!=(wxDataFormatId type) const { return m_type != type; } + private: wxDataFormatId m_type; wxString m_id; @@ -96,7 +102,7 @@ private: virtual wxDataFormat &GetNthFormat( size_t nth ) const; /* return preferrd/best supported format */ - virtual wxDataFormat &GetPreferredFormat() const; + virtual wxDataFormatId GetPreferredFormat() const; /* search through m_dataObjects, return TRUE if found */ virtual bool IsSupportedFormat( wxDataFormat &format ) const; diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index 17375966c0..0101824412 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -51,6 +51,14 @@ #include "icons/gauge.xpm" #endif +#ifdef __WIN16__ + // Win16 doesn't have them + #undef wxUSE_SPINBUTTON + #define wxUSE_SPINBUTTON 0 +#endif // __WIN16__ + +#include "wx/progdlg.h" + //---------------------------------------------------------------------- // class definitions //---------------------------------------------------------------------- @@ -101,9 +109,11 @@ public: void OnPageChanged( wxNotebookEvent &event ); void OnPageChanging( wxNotebookEvent &event ); void OnSliderUpdate( wxCommandEvent &event ); -#ifndef __WIN16__ +#ifndef wxUSE_SPINBUTTON void OnSpinUpdate( wxSpinEvent &event ); -#endif + void OnUpdateShowProgress( wxUpdateUIEvent& event ); + void OnShowProgress( wxCommandEvent &event ); +#endif // wxUSE_SPINBUTTON void OnPasteFromClipboard( wxCommandEvent &event ); void OnCopyToClipboard( wxCommandEvent &event ); void OnMoveToEndOfText( wxCommandEvent &event ); @@ -116,8 +126,9 @@ public: wxGauge *m_gauge; wxSlider *m_slider; wxButton *m_fontButton; -#ifndef __WIN16__ +#ifndef wxUSE_SPINBUTTON wxSpinButton *m_spinbutton; + wxButton *m_btnProgress; #endif wxTextCtrl *m_spintext; MyTextCtrl *m_multitext; @@ -453,6 +464,7 @@ const int ID_GAUGE = 180; const int ID_SLIDER = 181; const int ID_SPIN = 182; +const int ID_BTNPROGRESS = 183; BEGIN_EVENT_TABLE(MyPanel, wxPanel) EVT_SIZE ( MyPanel::OnSize) @@ -490,8 +502,10 @@ EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons) EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons) EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont) EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate) -#ifndef __WIN16__ +#ifndef wxUSE_SPINBUTTON EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate) +EVT_UPDATE_UI (ID_BTNPROGRESS, MyPanel::OnUpdateShowProgress) +EVT_BUTTON (ID_BTNPROGRESS, MyPanel::OnShowProgress) #endif EVT_BUTTON (ID_PASTE_TEXT, MyPanel::OnPasteFromClipboard) EVT_BUTTON (ID_COPY_TEXT, MyPanel::OnCopyToClipboard) @@ -701,10 +715,13 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) ); #endif m_spintext = new wxTextCtrl( panel, -1, "0", wxPoint(20,160), wxSize(80,-1) ); -#ifndef __WIN16__ +#ifndef wxUSE_SPINBUTTON m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,159), wxSize(-1,-1) ); m_spinbutton->SetRange(-10,30); m_spinbutton->SetValue(-5); + + m_btnProgress = new wxButton( panel, ID_BTNPROGRESS, "Show progress dialog", + wxPoint(208, 159) ); #endif m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge); } @@ -1065,7 +1082,7 @@ void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) ) m_gauge->SetValue( m_slider->GetValue() ); } -#ifndef __WIN16__ +#ifndef wxUSE_SPINBUTTON void MyPanel::OnSpinUpdate( wxSpinEvent &event ) { wxString value; @@ -1078,7 +1095,47 @@ void MyPanel::OnSpinUpdate( wxSpinEvent &event ) m_text->AppendText(value); } -#endif + +void MyPanel::OnUpdateShowProgress( wxUpdateUIEvent& event ) +{ + event.Enable( m_spinbutton->GetValue() > 0 ); +} + +void MyPanel::OnShowProgress( wxCommandEvent& WXUNUSED(event) ) +{ + int max = m_spinbutton->GetValue(); + wxProgressDialog dialog("Progress dialog example", + "An informative message", + max, // range + this, // parent + FALSE, // modal + TRUE); // has abort button + + bool cont = TRUE; + for ( int i = 0; i < max && cont; i++ ) + { + wxSleep(1); + if ( i == max / 2 ) + { + cont = dialog.Update(i, "Only a half left!"); + } + else + { + cont = dialog.Update(i); + } + } + + if ( !cont ) + { + *m_text << "Progress dialog aborted!\n"; + } + else + { + *m_text << "Countdown from " << max << " finished.\n"; + } +} + +#endif // wxUSE_SPINBUTTON MyPanel::~MyPanel() { diff --git a/src/generic/progdlgg.cpp b/src/generic/progdlgg.cpp index c43494211f..73f15139db 100644 --- a/src/generic/progdlgg.cpp +++ b/src/generic/progdlgg.cpp @@ -39,27 +39,27 @@ // wxTextEntryDialog #if !USE_SHARED_LIBRARY -BEGIN_EVENT_TABLE(wxProgressDialog, wxFrame) - EVT_BUTTON(-1, wxProgressDialog::OnCancel) - EVT_CLOSE(wxProgressDialog::OnClose) -END_EVENT_TABLE() + BEGIN_EVENT_TABLE(wxProgressDialog, wxFrame) + EVT_BUTTON(-1, wxProgressDialog::OnCancel) + EVT_CLOSE(wxProgressDialog::OnClose) + END_EVENT_TABLE() - IMPLEMENT_CLASS(wxProgressDialog, wxFrame) + IMPLEMENT_CLASS(wxProgressDialog, wxFrame) #endif wxProgressDialog::wxProgressDialog(wxString const &title, wxString const &message, int maximum, wxWindow *parent, - bool parentOnly, - bool abortButton) + int style) { - m_state = abortButton ? Continue : Uncancelable; - m_disableParentOnly = parentOnly; + bool hasAbortButton = (style & wxPD_CAN_ABORT) != 0; + m_state = hasAbortButton ? Continue : Uncancelable; + m_disableParentOnly = (style & wxPD_APP_MODAL) == 0; m_parent = parent; int height = 70; // FIXME arbitrary numbers - if ( abortButton ) + if ( hasAbortButton ) height += 35; wxFrame::Create(m_parent, -1, title, wxPoint(0, 0), wxSize(220, height), @@ -75,7 +75,7 @@ wxProgressDialog::wxProgressDialog(wxString const &title, c->height.AsIs(); m_msg->SetConstraints(c); - if(maximum > 0) + if ( maximum > 0 ) { m_gauge = new wxGauge(this, -1, maximum); c = new wxLayoutConstraints; @@ -89,7 +89,7 @@ wxProgressDialog::wxProgressDialog(wxString const &title, else m_gauge = NULL; - if ( abortButton ) + if ( hasAbortButton ) { wxControl *ctrl = new wxButton(this, -1, _("Cancel")); c = new wxLayoutConstraints; @@ -108,10 +108,10 @@ wxProgressDialog::wxProgressDialog(wxString const &title, Centre(wxCENTER_FRAME | wxBOTH); if(m_disableParentOnly) - m_parent->Enable(false); + m_parent->Enable(FALSE); else - wxEnableTopLevelWindows(false); - Enable(true); // enable this window + wxEnableTopLevelWindows(FALSE); + Enable(TRUE); // enable this window wxYield(); } @@ -119,12 +119,14 @@ wxProgressDialog::wxProgressDialog(wxString const &title, bool wxProgressDialog::Update(int value, const wxString& newmsg) { - wxASSERT(value == -1 || m_gauge); - if(m_gauge) + wxASSERT_MSG( value == -1 || m_gauge, "can't update non existent dialog" ); + + if( m_gauge ) m_gauge->SetValue(value); - if(!newmsg.IsNull()) + if( !newmsg.IsNull() ) m_msg->SetLabel(newmsg); wxYield(); + return m_state != Canceled; } @@ -139,8 +141,8 @@ void wxProgressDialog::OnClose(wxCloseEvent& event) wxProgressDialog::~wxProgressDialog() { - if(m_disableParentOnly) - m_parent->Enable(true); + if ( m_disableParentOnly ) + m_parent->Enable(TRUE); else - wxEnableTopLevelWindows(true); + wxEnableTopLevelWindows(TRUE); } diff --git a/src/gtk/dataobj.cpp b/src/gtk/dataobj.cpp index 342d813401..41d6b4faa5 100644 --- a/src/gtk/dataobj.cpp +++ b/src/gtk/dataobj.cpp @@ -56,7 +56,7 @@ wxDataFormat::wxDataFormat( const wxString &id ) SetId( id ); } -wxDataFormat::wxDataFormat( wxDataFormat &format ) +wxDataFormat::wxDataFormat( const wxDataFormat &format ) { if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); m_type = format.GetType(); @@ -192,7 +192,7 @@ size_t wxDataBroker::GetFormatCount() const return m_dataObjects.GetCount(); } -wxDataFormat &wxDataBroker::GetPreferredFormat() const +wxDataFormatId wxDataBroker::GetPreferredFormat() const { wxNode *node = m_dataObjects.Nth( m_preferred ); @@ -200,7 +200,7 @@ wxDataFormat &wxDataBroker::GetPreferredFormat() const wxDataObject* data_obj = (wxDataObject*)node->Data(); - return data_obj->GetFormat(); + return data_obj->GetFormat().GetType(); } wxDataFormat &wxDataBroker::GetNthFormat( size_t nth ) const diff --git a/src/gtk1/dataobj.cpp b/src/gtk1/dataobj.cpp index 342d813401..41d6b4faa5 100644 --- a/src/gtk1/dataobj.cpp +++ b/src/gtk1/dataobj.cpp @@ -56,7 +56,7 @@ wxDataFormat::wxDataFormat( const wxString &id ) SetId( id ); } -wxDataFormat::wxDataFormat( wxDataFormat &format ) +wxDataFormat::wxDataFormat( const wxDataFormat &format ) { if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); m_type = format.GetType(); @@ -192,7 +192,7 @@ size_t wxDataBroker::GetFormatCount() const return m_dataObjects.GetCount(); } -wxDataFormat &wxDataBroker::GetPreferredFormat() const +wxDataFormatId wxDataBroker::GetPreferredFormat() const { wxNode *node = m_dataObjects.Nth( m_preferred ); @@ -200,7 +200,7 @@ wxDataFormat &wxDataBroker::GetPreferredFormat() const wxDataObject* data_obj = (wxDataObject*)node->Data(); - return data_obj->GetFormat(); + return data_obj->GetFormat().GetType(); } wxDataFormat &wxDataBroker::GetNthFormat( size_t nth ) const