This is a combination of running clang-tidy with modernize-use-nullptr check for some ports (GTK, X11, OSX) and manual changes to the ports for which it couldn't be used easily (MSW, DFB) and also manually updating the docs. Also replace NULL with null or nullptr in the comments as this is more consistent with the use of nullptr in the code and makes it simpler to grep for the remaining occurrences of NULL itself. And also use null in the assert messages. Only a few occurrences of "NULL" are still left in non-C files, mostly corresponding to unclear comments or string output which it might not be safe to change.
152 lines
5 KiB
C++
152 lines
5 KiB
C++
/////////////////////////////////////////////////////////////////////////////
|
|
// 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 = nullptr;
|
|
m_sizerIndicator = nullptr;
|
|
}
|
|
|
|
virtual wxWindow *GetWidget() const override { return m_indicator; }
|
|
virtual void RecreateWidget() override;
|
|
|
|
// lazy creation of the content
|
|
virtual void CreateContent() override;
|
|
|
|
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
|