1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
/////////////////////////////////////////////////////////////////////////////
// Program: wxWidgets Widgets Sample
// Name: activityindicator.cpp
// Purpose: Part of the widgets sample showing wxActivityIndicator
// Author: Vadim Zeitlin
// Created: 2015-03-06
// Copyright: (c) 2015 wxWindows team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#if wxUSE_ACTIVITYINDICATOR
// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/button.h"
#include "wx/sizer.h"
#include "wx/stattext.h"
#endif
#include "wx/activityindicator.h"
#include "widgets.h"
#include "icons/activityindicator.xpm"
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
// Control IDs
enum
{
ActivityIndicator_Start = wxID_HIGHEST,
ActivityIndicator_Stop,
ActivityIndicator_IsRunning
};
// ----------------------------------------------------------------------------
// ActivityIndicatorWidgetsPage
// ----------------------------------------------------------------------------
class ActivityIndicatorWidgetsPage : public WidgetsPage
{
public:
ActivityIndicatorWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist)
: WidgetsPage(book, imaglist, activityindicator_xpm)
{
m_indicator = NULL;
m_sizerIndicator = NULL;
}
virtual wxWindow *GetWidget() const wxOVERRIDE { return m_indicator; }
virtual void RecreateWidget() wxOVERRIDE;
// lazy creation of the content
virtual void CreateContent() wxOVERRIDE;
protected:
void OnButtonStart(wxCommandEvent&) { m_indicator->Start(); }
void OnButtonStop(wxCommandEvent&) { m_indicator->Stop(); }
void OnUpdateIsRunning(wxUpdateUIEvent& event)
{
event.SetText(m_indicator && m_indicator->IsRunning()
? "Indicator is running"
: "Indicator is stopped");
}
// the indicator itself and the sizer it is in
wxActivityIndicator *m_indicator;
wxSizer *m_sizerIndicator;
private:
wxDECLARE_EVENT_TABLE();
DECLARE_WIDGETS_PAGE(ActivityIndicatorWidgetsPage)
};
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
wxBEGIN_EVENT_TABLE(ActivityIndicatorWidgetsPage, WidgetsPage)
EVT_BUTTON(ActivityIndicator_Start,
ActivityIndicatorWidgetsPage::OnButtonStart)
EVT_BUTTON(ActivityIndicator_Stop,
ActivityIndicatorWidgetsPage::OnButtonStop)
EVT_UPDATE_UI(ActivityIndicator_IsRunning,
ActivityIndicatorWidgetsPage::OnUpdateIsRunning)
wxEND_EVENT_TABLE()
// ============================================================================
// implementation
// ============================================================================
IMPLEMENT_WIDGETS_PAGE(ActivityIndicatorWidgetsPage,
"ActivityIndicator", NATIVE_CTRLS);
void ActivityIndicatorWidgetsPage::CreateContent()
{
wxSizer* const sizerOper = new wxStaticBoxSizer(wxVERTICAL, this,
"&Operations");
sizerOper->Add(new wxButton(this, ActivityIndicator_Start, "&Start"),
wxSizerFlags().Expand().Border());
sizerOper->Add(new wxButton(this, ActivityIndicator_Stop, "&Stop"),
wxSizerFlags().Expand().Border());
sizerOper->Add(new wxStaticText(this, ActivityIndicator_IsRunning,
"Indicator is initializing..."),
wxSizerFlags().Expand().Border());
m_sizerIndicator = new wxStaticBoxSizer(wxHORIZONTAL, this,
"Activity Indicator");
RecreateWidget();
wxSizer* const sizerTop = new wxBoxSizer(wxHORIZONTAL);
sizerTop->Add(sizerOper, wxSizerFlags().Expand().DoubleBorder());
sizerTop->Add(m_sizerIndicator, wxSizerFlags(1).Expand().DoubleBorder());
SetSizer(sizerTop);
}
void ActivityIndicatorWidgetsPage::RecreateWidget()
{
m_sizerIndicator->Clear(true /* delete windows */);
m_indicator = new wxActivityIndicator(this, wxID_ANY,
wxDefaultPosition, wxDefaultSize,
GetAttrs().m_defaultFlags);
m_sizerIndicator->AddStretchSpacer();
m_sizerIndicator->Add(m_indicator, wxSizerFlags().Centre());
m_sizerIndicator->AddStretchSpacer();
m_sizerIndicator->Layout();
}
#endif // wxUSE_ACTIVITYINDICATOR
|