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
This commit is contained in:
Vadim Zeitlin
1999-05-27 12:49:40 +00:00
parent 082b27986b
commit 9726da4fd3
9 changed files with 119 additions and 46 deletions

View File

@@ -109,7 +109,7 @@ public:
wxString GetId() const { return m_format.GetId(); } wxString GetId() const { return m_format.GetId(); }
// implement the base class pure virtuals // implement the base class pure virtuals
virtual wxDataFormat GetPreferredFormat() const virtual wxDataFormatId GetPreferredFormat() const
{ return m_format; } { return m_format; }
virtual bool IsSupportedFormat(wxDataFormat format) const virtual bool IsSupportedFormat(wxDataFormat format) const
{ return m_format == format; } { return m_format == format; }

View File

@@ -646,7 +646,12 @@ typedef void (*wxFunction) (wxObject&, wxEvent&);
#define wxLI_HORIZONTAL wxHORIZONTAL #define wxLI_HORIZONTAL wxHORIZONTAL
#define wxLI_VERTICAL wxVERTICAL #define wxLI_VERTICAL wxVERTICAL
/*
* wxProgressDialog flags
*/
#define wxPD_CAN_ABORT 0x0001
#define wxPD_APP_MODAL 0x0002
#define wxPD_AUTO_HIDE 0x0004
/* /*
* GDI descriptions * GDI descriptions

View File

@@ -32,17 +32,14 @@ public:
frames or parent frame to avoid recursion problems. frames or parent frame to avoid recursion problems.
@param title title for window @param title title for window
@param message message to display in 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 parent window or NULL
@param disableParentOnly if true, only disable parent window's @param style is the bit mask of wxPD_XXX constants from wx/defs.h
event handling
@param abortButton if true, dialog will show an abort button
*/ */
wxProgressDialog(const wxString &title, wxString const &message, wxProgressDialog(const wxString &title, wxString const &message,
int maximum = 100, int maximum = 100,
wxWindow *parent = NULL, wxWindow *parent = NULL,
bool disableParentOnly = FALSE, int style = wxPD_APP_MODAL | wxPD_AUTO_HIDE);
bool abortButton = FALSE);
/** Destructor. /** Destructor.
Re-enables event handling for other windows. Re-enables event handling for other windows.
*/ */

View File

@@ -44,7 +44,7 @@ public:
wxDataFormat( wxDataFormatId type ); wxDataFormat( wxDataFormatId type );
wxDataFormat( const wxString &id ); wxDataFormat( const wxString &id );
wxDataFormat( const wxChar *id ); wxDataFormat( const wxChar *id );
wxDataFormat( wxDataFormat &format ); wxDataFormat( const wxDataFormat &format );
wxDataFormat( const GdkAtom atom ); wxDataFormat( const GdkAtom atom );
void SetType( wxDataFormatId type ); void SetType( wxDataFormatId type );
@@ -62,6 +62,12 @@ public:
GdkAtom GetAtom(); GdkAtom GetAtom();
void SetAtom(GdkAtom atom) { m_hasAtom = TRUE; m_atom = atom; } 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: private:
wxDataFormatId m_type; wxDataFormatId m_type;
wxString m_id; wxString m_id;
@@ -96,7 +102,7 @@ private:
virtual wxDataFormat &GetNthFormat( size_t nth ) const; virtual wxDataFormat &GetNthFormat( size_t nth ) const;
/* return preferrd/best supported format */ /* return preferrd/best supported format */
virtual wxDataFormat &GetPreferredFormat() const; virtual wxDataFormatId GetPreferredFormat() const;
/* search through m_dataObjects, return TRUE if found */ /* search through m_dataObjects, return TRUE if found */
virtual bool IsSupportedFormat( wxDataFormat &format ) const; virtual bool IsSupportedFormat( wxDataFormat &format ) const;

View File

@@ -44,7 +44,7 @@ public:
wxDataFormat( wxDataFormatId type ); wxDataFormat( wxDataFormatId type );
wxDataFormat( const wxString &id ); wxDataFormat( const wxString &id );
wxDataFormat( const wxChar *id ); wxDataFormat( const wxChar *id );
wxDataFormat( wxDataFormat &format ); wxDataFormat( const wxDataFormat &format );
wxDataFormat( const GdkAtom atom ); wxDataFormat( const GdkAtom atom );
void SetType( wxDataFormatId type ); void SetType( wxDataFormatId type );
@@ -62,6 +62,12 @@ public:
GdkAtom GetAtom(); GdkAtom GetAtom();
void SetAtom(GdkAtom atom) { m_hasAtom = TRUE; m_atom = atom; } 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: private:
wxDataFormatId m_type; wxDataFormatId m_type;
wxString m_id; wxString m_id;
@@ -96,7 +102,7 @@ private:
virtual wxDataFormat &GetNthFormat( size_t nth ) const; virtual wxDataFormat &GetNthFormat( size_t nth ) const;
/* return preferrd/best supported format */ /* return preferrd/best supported format */
virtual wxDataFormat &GetPreferredFormat() const; virtual wxDataFormatId GetPreferredFormat() const;
/* search through m_dataObjects, return TRUE if found */ /* search through m_dataObjects, return TRUE if found */
virtual bool IsSupportedFormat( wxDataFormat &format ) const; virtual bool IsSupportedFormat( wxDataFormat &format ) const;

View File

@@ -51,6 +51,14 @@
#include "icons/gauge.xpm" #include "icons/gauge.xpm"
#endif #endif
#ifdef __WIN16__
// Win16 doesn't have them
#undef wxUSE_SPINBUTTON
#define wxUSE_SPINBUTTON 0
#endif // __WIN16__
#include "wx/progdlg.h"
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class definitions // class definitions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@@ -101,9 +109,11 @@ public:
void OnPageChanged( wxNotebookEvent &event ); void OnPageChanged( wxNotebookEvent &event );
void OnPageChanging( wxNotebookEvent &event ); void OnPageChanging( wxNotebookEvent &event );
void OnSliderUpdate( wxCommandEvent &event ); void OnSliderUpdate( wxCommandEvent &event );
#ifndef __WIN16__ #ifndef wxUSE_SPINBUTTON
void OnSpinUpdate( wxSpinEvent &event ); void OnSpinUpdate( wxSpinEvent &event );
#endif void OnUpdateShowProgress( wxUpdateUIEvent& event );
void OnShowProgress( wxCommandEvent &event );
#endif // wxUSE_SPINBUTTON
void OnPasteFromClipboard( wxCommandEvent &event ); void OnPasteFromClipboard( wxCommandEvent &event );
void OnCopyToClipboard( wxCommandEvent &event ); void OnCopyToClipboard( wxCommandEvent &event );
void OnMoveToEndOfText( wxCommandEvent &event ); void OnMoveToEndOfText( wxCommandEvent &event );
@@ -116,8 +126,9 @@ public:
wxGauge *m_gauge; wxGauge *m_gauge;
wxSlider *m_slider; wxSlider *m_slider;
wxButton *m_fontButton; wxButton *m_fontButton;
#ifndef __WIN16__ #ifndef wxUSE_SPINBUTTON
wxSpinButton *m_spinbutton; wxSpinButton *m_spinbutton;
wxButton *m_btnProgress;
#endif #endif
wxTextCtrl *m_spintext; wxTextCtrl *m_spintext;
MyTextCtrl *m_multitext; MyTextCtrl *m_multitext;
@@ -453,6 +464,7 @@ const int ID_GAUGE = 180;
const int ID_SLIDER = 181; const int ID_SLIDER = 181;
const int ID_SPIN = 182; const int ID_SPIN = 182;
const int ID_BTNPROGRESS = 183;
BEGIN_EVENT_TABLE(MyPanel, wxPanel) BEGIN_EVENT_TABLE(MyPanel, wxPanel)
EVT_SIZE ( MyPanel::OnSize) EVT_SIZE ( MyPanel::OnSize)
@@ -490,8 +502,10 @@ EVT_BUTTON (ID_RADIOBOX_FONT, MyPanel::OnRadioButtons)
EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons) EVT_CHECKBOX (ID_RADIOBOX_ENABLE, MyPanel::OnRadioButtons)
EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont) EVT_BUTTON (ID_SET_FONT, MyPanel::OnSetFont)
EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate) EVT_SLIDER (ID_SLIDER, MyPanel::OnSliderUpdate)
#ifndef __WIN16__ #ifndef wxUSE_SPINBUTTON
EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate) EVT_SPIN (ID_SPIN, MyPanel::OnSpinUpdate)
EVT_UPDATE_UI (ID_BTNPROGRESS, MyPanel::OnUpdateShowProgress)
EVT_BUTTON (ID_BTNPROGRESS, MyPanel::OnShowProgress)
#endif #endif
EVT_BUTTON (ID_PASTE_TEXT, MyPanel::OnPasteFromClipboard) EVT_BUTTON (ID_PASTE_TEXT, MyPanel::OnPasteFromClipboard)
EVT_BUTTON (ID_COPY_TEXT, MyPanel::OnCopyToClipboard) EVT_BUTTON (ID_COPY_TEXT, MyPanel::OnCopyToClipboard)
@@ -701,10 +715,13 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
); );
#endif #endif
m_spintext = new wxTextCtrl( panel, -1, "0", wxPoint(20,160), wxSize(80,-1) ); 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 = new wxSpinButton( panel, ID_SPIN, wxPoint(103,159), wxSize(-1,-1) );
m_spinbutton->SetRange(-10,30); m_spinbutton->SetRange(-10,30);
m_spinbutton->SetValue(-5); m_spinbutton->SetValue(-5);
m_btnProgress = new wxButton( panel, ID_BTNPROGRESS, "Show progress dialog",
wxPoint(208, 159) );
#endif #endif
m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge); m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge);
} }
@@ -1065,7 +1082,7 @@ void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
m_gauge->SetValue( m_slider->GetValue() ); m_gauge->SetValue( m_slider->GetValue() );
} }
#ifndef __WIN16__ #ifndef wxUSE_SPINBUTTON
void MyPanel::OnSpinUpdate( wxSpinEvent &event ) void MyPanel::OnSpinUpdate( wxSpinEvent &event )
{ {
wxString value; wxString value;
@@ -1078,7 +1095,47 @@ void MyPanel::OnSpinUpdate( wxSpinEvent &event )
m_text->AppendText(value); 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() MyPanel::~MyPanel()
{ {

View File

@@ -39,27 +39,27 @@
// wxTextEntryDialog // wxTextEntryDialog
#if !USE_SHARED_LIBRARY #if !USE_SHARED_LIBRARY
BEGIN_EVENT_TABLE(wxProgressDialog, wxFrame) BEGIN_EVENT_TABLE(wxProgressDialog, wxFrame)
EVT_BUTTON(-1, wxProgressDialog::OnCancel) EVT_BUTTON(-1, wxProgressDialog::OnCancel)
EVT_CLOSE(wxProgressDialog::OnClose) EVT_CLOSE(wxProgressDialog::OnClose)
END_EVENT_TABLE() END_EVENT_TABLE()
IMPLEMENT_CLASS(wxProgressDialog, wxFrame) IMPLEMENT_CLASS(wxProgressDialog, wxFrame)
#endif #endif
wxProgressDialog::wxProgressDialog(wxString const &title, wxProgressDialog::wxProgressDialog(wxString const &title,
wxString const &message, wxString const &message,
int maximum, int maximum,
wxWindow *parent, wxWindow *parent,
bool parentOnly, int style)
bool abortButton)
{ {
m_state = abortButton ? Continue : Uncancelable; bool hasAbortButton = (style & wxPD_CAN_ABORT) != 0;
m_disableParentOnly = parentOnly; m_state = hasAbortButton ? Continue : Uncancelable;
m_disableParentOnly = (style & wxPD_APP_MODAL) == 0;
m_parent = parent; m_parent = parent;
int height = 70; // FIXME arbitrary numbers int height = 70; // FIXME arbitrary numbers
if ( abortButton ) if ( hasAbortButton )
height += 35; height += 35;
wxFrame::Create(m_parent, -1, title, wxFrame::Create(m_parent, -1, title,
wxPoint(0, 0), wxSize(220, height), wxPoint(0, 0), wxSize(220, height),
@@ -75,7 +75,7 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
c->height.AsIs(); c->height.AsIs();
m_msg->SetConstraints(c); m_msg->SetConstraints(c);
if(maximum > 0) if ( maximum > 0 )
{ {
m_gauge = new wxGauge(this, -1, maximum); m_gauge = new wxGauge(this, -1, maximum);
c = new wxLayoutConstraints; c = new wxLayoutConstraints;
@@ -89,7 +89,7 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
else else
m_gauge = NULL; m_gauge = NULL;
if ( abortButton ) if ( hasAbortButton )
{ {
wxControl *ctrl = new wxButton(this, -1, _("Cancel")); wxControl *ctrl = new wxButton(this, -1, _("Cancel"));
c = new wxLayoutConstraints; c = new wxLayoutConstraints;
@@ -108,10 +108,10 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
Centre(wxCENTER_FRAME | wxBOTH); Centre(wxCENTER_FRAME | wxBOTH);
if(m_disableParentOnly) if(m_disableParentOnly)
m_parent->Enable(false); m_parent->Enable(FALSE);
else else
wxEnableTopLevelWindows(false); wxEnableTopLevelWindows(FALSE);
Enable(true); // enable this window Enable(TRUE); // enable this window
wxYield(); wxYield();
} }
@@ -119,12 +119,14 @@ wxProgressDialog::wxProgressDialog(wxString const &title,
bool bool
wxProgressDialog::Update(int value, const wxString& newmsg) wxProgressDialog::Update(int value, const wxString& newmsg)
{ {
wxASSERT(value == -1 || m_gauge); wxASSERT_MSG( value == -1 || m_gauge, "can't update non existent dialog" );
if(m_gauge)
if( m_gauge )
m_gauge->SetValue(value); m_gauge->SetValue(value);
if(!newmsg.IsNull()) if( !newmsg.IsNull() )
m_msg->SetLabel(newmsg); m_msg->SetLabel(newmsg);
wxYield(); wxYield();
return m_state != Canceled; return m_state != Canceled;
} }
@@ -139,8 +141,8 @@ void wxProgressDialog::OnClose(wxCloseEvent& event)
wxProgressDialog::~wxProgressDialog() wxProgressDialog::~wxProgressDialog()
{ {
if(m_disableParentOnly) if ( m_disableParentOnly )
m_parent->Enable(true); m_parent->Enable(TRUE);
else else
wxEnableTopLevelWindows(true); wxEnableTopLevelWindows(TRUE);
} }

View File

@@ -56,7 +56,7 @@ wxDataFormat::wxDataFormat( const wxString &id )
SetId( id ); SetId( id );
} }
wxDataFormat::wxDataFormat( wxDataFormat &format ) wxDataFormat::wxDataFormat( const wxDataFormat &format )
{ {
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
m_type = format.GetType(); m_type = format.GetType();
@@ -192,7 +192,7 @@ size_t wxDataBroker::GetFormatCount() const
return m_dataObjects.GetCount(); return m_dataObjects.GetCount();
} }
wxDataFormat &wxDataBroker::GetPreferredFormat() const wxDataFormatId wxDataBroker::GetPreferredFormat() const
{ {
wxNode *node = m_dataObjects.Nth( m_preferred ); wxNode *node = m_dataObjects.Nth( m_preferred );
@@ -200,7 +200,7 @@ wxDataFormat &wxDataBroker::GetPreferredFormat() const
wxDataObject* data_obj = (wxDataObject*)node->Data(); wxDataObject* data_obj = (wxDataObject*)node->Data();
return data_obj->GetFormat(); return data_obj->GetFormat().GetType();
} }
wxDataFormat &wxDataBroker::GetNthFormat( size_t nth ) const wxDataFormat &wxDataBroker::GetNthFormat( size_t nth ) const

View File

@@ -56,7 +56,7 @@ wxDataFormat::wxDataFormat( const wxString &id )
SetId( id ); SetId( id );
} }
wxDataFormat::wxDataFormat( wxDataFormat &format ) wxDataFormat::wxDataFormat( const wxDataFormat &format )
{ {
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
m_type = format.GetType(); m_type = format.GetType();
@@ -192,7 +192,7 @@ size_t wxDataBroker::GetFormatCount() const
return m_dataObjects.GetCount(); return m_dataObjects.GetCount();
} }
wxDataFormat &wxDataBroker::GetPreferredFormat() const wxDataFormatId wxDataBroker::GetPreferredFormat() const
{ {
wxNode *node = m_dataObjects.Nth( m_preferred ); wxNode *node = m_dataObjects.Nth( m_preferred );
@@ -200,7 +200,7 @@ wxDataFormat &wxDataBroker::GetPreferredFormat() const
wxDataObject* data_obj = (wxDataObject*)node->Data(); wxDataObject* data_obj = (wxDataObject*)node->Data();
return data_obj->GetFormat(); return data_obj->GetFormat().GetType();
} }
wxDataFormat &wxDataBroker::GetNthFormat( size_t nth ) const wxDataFormat &wxDataBroker::GetNthFormat( size_t nth ) const