Add wxActivityIndicator control.

This is a simple animated control indicating some program activity.

Provide native GTK+ (for > 2.20) and OS X implementations as well as a generic
one used under MSW.

Update the sample and the documentation.
This commit is contained in:
Vadim Zeitlin
2015-03-06 17:43:29 +01:00
parent 00748bbaef
commit 3f84cb17ca
50 changed files with 1800 additions and 70 deletions

View File

@@ -50,6 +50,7 @@ WIDGETS_CXXFLAGS = -D__WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) \
-I$(srcdir) $(__DLLFLAG_p) -I$(srcdir)/../../samples $(CXXWARNINGS) \
$(SAMPLES_CXXFLAGS) $(CPPFLAGS) $(CXXFLAGS)
WIDGETS_OBJECTS = \
widgets_activityindicator.o \
widgets_bmpcombobox.o \
widgets_button.o \
widgets_checkbox.o \
@@ -210,6 +211,9 @@ widgets$(EXEEXT): $(WIDGETS_OBJECTS) $(__widgets___win32rc)
@COND_PLATFORM_MACOSX_1@widgets_bundle: $(____widgets_BUNDLE_TGT_REF_DEP)
widgets_activityindicator.o: $(srcdir)/activityindicator.cpp
$(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/activityindicator.cpp
widgets_bmpcombobox.o: $(srcdir)/bmpcombobox.cpp
$(CXXC) -c -o $@ $(WIDGETS_CXXFLAGS) $(srcdir)/bmpcombobox.cpp

View File

@@ -0,0 +1,151 @@
/////////////////////////////////////////////////////////////////////////////
// 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"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// 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 wxControl *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,
wxT("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();
}

View File

@@ -0,0 +1,278 @@
/* XPM */
static const char *const activityindicator_xpm[] = {
/* columns rows colors chars-per-pixel */
"16 16 256 2 ",
" c None",
". c gray93",
"X c gray93",
"o c gray93",
"O c gray93",
"+ c gray93",
"@ c #D5D6D6",
"# c #828587",
"$ c #828587",
"% c #D6D6D7",
"& c gray93",
"* c gray93",
"= c gray93",
"- c gray93",
"; c gray93",
": c gray93",
"> c gray93",
", c gray93",
"< c #E9E9E9",
"1 c #DDDDDD",
"2 c #ECECEC",
"3 c gray93",
"4 c #ABACAE",
"5 c #747779",
"6 c #747779",
"7 c #ABACAE",
"8 c gray93",
"9 c #ECECEC",
"0 c #D4D5D6",
"q c #E7E7E8",
"w c gray93",
"e c gray93",
"r c gray93",
"t c #E9E9E9",
"y c #9A9C9D",
"u c #8C8F90",
"i c #ABADAE",
"p c gray93",
"a c #CACACB",
"s c #76797B",
"d c #76797B",
"f c #CACACB",
"g c gray93",
"h c #8A8D8E",
"j c #5C6162",
"k c #717676",
"l c gray91",
"z c gray93",
"x c gray93",
"c c gray87",
"v c #8C8F90",
"b c #8C8F90",
"n c #929596",
"m c gray93",
"M c gray93",
"N c #E1E1E2",
"B c #E1E1E2",
"V c gray93",
"C c gray93",
"Z c #646869",
"A c #5C6162",
"S c #5C6162",
"D c #D7D8D8",
"F c gray93",
"G c gray93",
"H c #ECECEC",
"J c #ACAEAF",
"K c #929596",
"L c #BFC0C1",
"P c gray93",
"I c gray93",
"U c gray93",
"Y c gray93",
"T c gray93",
"R c gray93",
"E c #A7A9AA",
"W c #64696A",
"Q c #8C8F90",
"! c #ECECEC",
"~ c gray93",
"^ c gray93",
"/ c gray93",
"( c gray93",
") c gray93",
"_ c gray93",
"` c gray93",
"' c gray93",
"] c gray93",
"[ c gray93",
"{ c gray93",
"} c gray93",
"| c gray93",
" . c gray93",
".. c gray93",
"X. c gray93",
"o. c gray93",
"O. c #DFDFDF",
"+. c #C4C5C6",
"@. c #D8D8D9",
"#. c gray93",
"$. c gray93",
"%. c gray93",
"&. c gray93",
"*. c gray93",
"=. c gray93",
"-. c gray93",
";. c gray93",
":. c gray93",
">. c gray93",
",. c #BCBDBE",
"<. c #8E9192",
"1. c #CCCDCD",
"2. c #ACAEAF",
"3. c #A4A6A7",
"4. c #A5A7A8",
"5. c #E6E7E7",
"6. c gray93",
"7. c gray93",
"8. c gray93",
"9. c gray93",
"0. c gray93",
"q. c gray93",
"w. c gray93",
"e. c gray93",
"r. c #DDDEDE",
"t. c #464B4D",
"y. c #44494B",
"u. c #585D5F",
"i. c #ADAFAF",
"p. c #A4A6A7",
"a. c #A5A7A8",
"s. c #E6E7E7",
"d. c gray93",
"f. c gray93",
"g. c gray93",
"h. c gray93",
"j. c gray93",
"k. c gray93",
"l. c gray93",
"z. c gray93",
"x. c #DDDEDE",
"c. c #474B4D",
"v. c #44494B",
"b. c #585D5F",
"n. c #DFDFE0",
"m. c #C5C6C6",
"M. c #D8D8D9",
"N. c gray93",
"B. c gray93",
"V. c gray93",
"C. c gray93",
"Z. c gray93",
"A. c gray93",
"S. c gray93",
"D. c gray93",
"F. c gray93",
"G. c gray93",
"H. c #BCBDBE",
"J. c #8F9293",
"K. c #CFD0D0",
"L. c gray93",
"P. c gray93",
"I. c gray93",
"U. c gray93",
"Y. c gray93",
"T. c gray93",
"R. c gray93",
"E. c gray93",
"W. c gray93",
"Q. c gray93",
"!. c gray93",
"~. c gray93",
"^. c gray93",
"/. c gray93",
"(. c gray93",
"). c gray93",
"_. c gray93",
"`. c gray93",
"'. c #CBCDCD",
"]. c #BEC0C0",
"[. c #D5D6D6",
"{. c gray93",
"}. c gray93",
"|. c gray93",
" X c gray93",
".X c gray93",
"XX c gray93",
"oX c #929596",
"OX c #3F4445",
"+X c #717576",
"@X c #ECECEC",
"#X c gray93",
"$X c gray93",
"%X c #E5E6E6",
"&X c #BCBEBE",
"*X c #BCBEBE",
"=X c #BEC0C0",
"-X c gray93",
";X c gray93",
":X c #EAEAEB",
">X c #EAEAEB",
",X c gray93",
"<X c gray93",
"1X c #3F4546",
"2X c #353B3C",
"3X c #353B3C",
"4X c #D1D2D2",
"5X c gray93",
"6X c gray93",
"7X c #EBECEC",
"8X c #C3C5C5",
"9X c #BCBEBE",
"0X c #CCCDCD",
"qX c gray93",
"wX c #E6E6E6",
"eX c #D5D5D6",
"rX c #D5D5D6",
"tX c #E6E6E6",
"yX c gray93",
"uX c #707475",
"iX c #353B3C",
"pX c #515657",
"aX c #E7E7E7",
"sX c gray93",
"dX c gray93",
"fX c gray93",
"gX c gray92",
"hX c gray90",
"jX c gray93",
"kX c gray93",
"lX c #DFDFE0",
"zX c #D4D4D5",
"xX c #D4D4D5",
"cX c #DFDFE0",
"vX c gray93",
"bX c #ECECEC",
"nX c #CFD0D0",
"mX c #E7E7E7",
"MX c gray93",
"NX c gray93",
"BX c gray93",
"VX c gray93",
"CX c gray93",
"ZX c gray93",
"AX c gray93",
"SX c gray93",
"DX c gray91",
"FX c #D7D7D8",
"GX c #D7D7D8",
"HX c #E8E8E9",
"JX c gray93",
"KX c gray93",
"LX c gray93",
"PX c gray93",
"IX c gray93",
"UX c gray93",
/* pixels */
" @ # $ % ",
" < 1 4 5 6 7 0 ",
" t y u i a s d f h j k ",
" c v b n N B Z A S D ",
" J K L E W Q ",
" ",
"O.+.@. ,.<.1.",
"2.3.4.5. r.t.y.u.",
"i.p.a.s. x.c.v.b.",
"n.m.M. G.H.J.K.",
" ",
" .'.].[. oXOX+X@X ",
" %X&X*X=X 1X2X3X4X ",
" X8X9X0X XeXrXtX uXiXpXaX ",
" XhXjX lXzXxXcX bXnXmX ",
" XFXGXHX "
};

View File

@@ -36,6 +36,7 @@ WIDGETS_CXXFLAGS = $(__RUNTIME_LIBS_7) -I$(BCCDIR)\include $(__DEBUGINFO) \
-I$(SETUPHDIR) -I.\..\..\include $(____CAIRO_INCLUDEDIR_FILENAMES_p) -I. \
$(__DLLFLAG_p) -I.\..\..\samples -DNOPCH $(CPPFLAGS) $(CXXFLAGS)
WIDGETS_OBJECTS = \
$(OBJS)\widgets_activityindicator.obj \
$(OBJS)\widgets_bmpcombobox.obj \
$(OBJS)\widgets_button.obj \
$(OBJS)\widgets_checkbox.obj \
@@ -263,6 +264,9 @@ $(OBJS)\widgets.exe: $(WIDGETS_OBJECTS) $(OBJS)\widgets_sample.res
c0w32.obj $(WIDGETS_OBJECTS),$@,, $(__WXLIB_ADV_p) $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_SCINTILLA_IF_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) wxzlib$(WXDEBUGFLAG).lib wxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG).lib wxexpat$(WXDEBUGFLAG).lib $(EXTRALIBS_FOR_BASE) $(__CAIRO_LIB_p) ole2w32.lib oleacc.lib import32.lib cw32$(__THREADSFLAG_5)$(__RUNTIME_LIBS_8).lib,, $(OBJS)\widgets_sample.res
|
$(OBJS)\widgets_activityindicator.obj: .\activityindicator.cpp
$(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) .\activityindicator.cpp
$(OBJS)\widgets_bmpcombobox.obj: .\bmpcombobox.cpp
$(CXX) -q -c -P -o$@ $(WIDGETS_CXXFLAGS) .\bmpcombobox.cpp

View File

@@ -29,6 +29,7 @@ WIDGETS_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG_2) $(__THREADSFLAG) \
-Wall -I. $(__DLLFLAG_p) -I.\..\..\samples -DNOPCH $(__RTTIFLAG_5) \
$(__EXCEPTIONSFLAG_6) -Wno-ctor-dtor-privacy $(CPPFLAGS) $(CXXFLAGS)
WIDGETS_OBJECTS = \
$(OBJS)\widgets_activityindicator.o \
$(OBJS)\widgets_bmpcombobox.o \
$(OBJS)\widgets_button.o \
$(OBJS)\widgets_checkbox.o \
@@ -252,6 +253,9 @@ clean:
$(OBJS)\widgets.exe: $(WIDGETS_OBJECTS) $(OBJS)\widgets_sample_rc.o
$(CXX) -o $@ $(WIDGETS_OBJECTS) $(__DEBUGINFO) $(__THREADSFLAG) -L$(LIBDIRNAME) -Wl,--subsystem,windows -mwindows $(____CAIRO_LIBDIR_FILENAMES_p) $(LDFLAGS) $(__WXLIB_ADV_p) $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_SCINTILLA_IF_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) -lwxzlib$(WXDEBUGFLAG) -lwxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG) -lwxexpat$(WXDEBUGFLAG) $(EXTRALIBS_FOR_BASE) $(__CAIRO_LIB_p) -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lwininet
$(OBJS)\widgets_activityindicator.o: ./activityindicator.cpp
$(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\widgets_bmpcombobox.o: ./bmpcombobox.cpp
$(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $<

View File

@@ -53,6 +53,7 @@ WX_CONFIG_FLAGS = $(WX_CONFIG_UNICODE_FLAG) $(WX_CONFIG_SHARED_FLAG) \
WIDGETS_CXXFLAGS = -I. `$(WX_CONFIG) --cxxflags $(WX_CONFIG_FLAGS)` $(CPPFLAGS) \
$(CXXFLAGS)
WIDGETS_OBJECTS = \
widgets_activityindicator.o \
widgets_bmpcombobox.o \
widgets_button.o \
widgets_checkbox.o \
@@ -118,6 +119,9 @@ test_for_selected_wxbuild:
widgets: $(WIDGETS_OBJECTS)
$(CXX) -o $@ $(WIDGETS_OBJECTS) $(LDFLAGS) `$(WX_CONFIG) $(WX_CONFIG_FLAGS) --libs adv,core,base`
widgets_activityindicator.o: ./activityindicator.cpp
$(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $<
widgets_bmpcombobox.o: ./bmpcombobox.cpp
$(CXX) -c -o $@ $(WIDGETS_CXXFLAGS) $(CPPDEPS) $<

View File

@@ -31,6 +31,7 @@ WIDGETS_CXXFLAGS = /M$(__RUNTIME_LIBS_10)$(__DEBUGRUNTIME_4) /DWIN32 \
/I.\..\..\samples /DNOPCH $(__RTTIFLAG_11) $(__EXCEPTIONSFLAG_12) \
$(CPPFLAGS) $(CXXFLAGS)
WIDGETS_OBJECTS = \
$(OBJS)\widgets_activityindicator.obj \
$(OBJS)\widgets_bmpcombobox.obj \
$(OBJS)\widgets_button.obj \
$(OBJS)\widgets_checkbox.obj \
@@ -386,6 +387,9 @@ $(OBJS)\widgets.exe: $(WIDGETS_OBJECTS) $(OBJS)\widgets_sample.res
$(WIDGETS_OBJECTS) $(WIDGETS_RESOURCES) $(__WXLIB_ADV_p) $(__WXLIB_CORE_p) $(__WXLIB_BASE_p) $(__WXLIB_MONO_p) $(__LIB_SCINTILLA_IF_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) wxzlib$(WXDEBUGFLAG).lib wxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG).lib wxexpat$(WXDEBUGFLAG).lib $(EXTRALIBS_FOR_BASE) $(__CAIRO_LIB_p) kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib winmm.lib shell32.lib comctl32.lib ole32.lib oleaut32.lib uuid.lib rpcrt4.lib advapi32.lib wsock32.lib wininet.lib
<<
$(OBJS)\widgets_activityindicator.obj: .\activityindicator.cpp
$(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) .\activityindicator.cpp
$(OBJS)\widgets_bmpcombobox.obj: .\bmpcombobox.cpp
$(CXX) /c /nologo /TP /Fo$@ $(WIDGETS_CXXFLAGS) .\bmpcombobox.cpp

View File

@@ -5,6 +5,7 @@
<exe id="widgets" template="wx_sample" template_append="wx_append">
<sources>
activityindicator.cpp
bmpcombobox.cpp
button.cpp
checkbox.cpp

View File

@@ -283,6 +283,9 @@
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\activityindicator.cpp">
</File>
<File
RelativePath=".\bmpcombobox.cpp">
</File>

View File

@@ -806,6 +806,10 @@
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\activityindicator.cpp"
>
</File>
<File
RelativePath=".\bmpcombobox.cpp"
>

View File

@@ -778,6 +778,10 @@
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\activityindicator.cpp"
>
</File>
<File
RelativePath=".\bmpcombobox.cpp"
>