From 00d7d3333299da2569a1d87fd1bd5f96d09ca1d6 Mon Sep 17 00:00:00 2001 From: guigues Date: Wed, 10 Dec 2008 10:37:29 +0000 Subject: [PATCH] *** empty log message *** --- samples/CMakeLists.txt | 1 + .../CMakeLists.txt | 19 ++++ .../bbtkSampleInsertWxBlackBoxInOwnFrame.cxx | 94 +++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 samples/SampleInsertWxBlackBoxInOwnFrame/CMakeLists.txt create mode 100644 samples/SampleInsertWxBlackBoxInOwnFrame/bbtkSampleInsertWxBlackBoxInOwnFrame.cxx diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 3f409c0..c6abdf6 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -16,3 +16,4 @@ SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}) SUBDIRS(SampleWidgetsBase) SUBDIRS(SampleOutputObserver) +SUBDIRS(SampleInsertWxBlackBoxInOwnFrame) diff --git a/samples/SampleInsertWxBlackBoxInOwnFrame/CMakeLists.txt b/samples/SampleInsertWxBlackBoxInOwnFrame/CMakeLists.txt new file mode 100644 index 0000000..4cd80c9 --- /dev/null +++ b/samples/SampleInsertWxBlackBoxInOwnFrame/CMakeLists.txt @@ -0,0 +1,19 @@ +# Find the bbtk package wx +# The package is called 'bbwx' +# It itself finds bbtk and automatically exports its dependency on it + +# Set 'FIND_PACKAGE_VERBOSE' to have information on the packages found +SET(FIND_PACKAGE_VERBOSE 1) +# Find +FIND_PACKAGE(bbwx) +# Use if found +IF(bbwx_FOUND) +INCLUDE(${bbwx_USE_FILE}) +ENDIF(bbwx_FOUND) + +SET(SAMPLE bbtkSampleInsertWxBlackBoxInOwnFrame) + +# main +ADD_EXECUTABLE(${SAMPLE} ${SAMPLE}) +# Link against bbwx +TARGET_LINK_LIBRARIES(${SAMPLE} ${bbwx_LIBRARIES}) diff --git a/samples/SampleInsertWxBlackBoxInOwnFrame/bbtkSampleInsertWxBlackBoxInOwnFrame.cxx b/samples/SampleInsertWxBlackBoxInOwnFrame/bbtkSampleInsertWxBlackBoxInOwnFrame.cxx new file mode 100644 index 0000000..9efe1bd --- /dev/null +++ b/samples/SampleInsertWxBlackBoxInOwnFrame/bbtkSampleInsertWxBlackBoxInOwnFrame.cxx @@ -0,0 +1,94 @@ +#include +#include + +//========================================================================= +// Illustrates how to insert a WxBlackBox into his own wxFrame +//========================================================================= + +//========================================================================== +// A custom wxFrame which own a bbwx::Slider widget +class Frame : public wxFrame +{ +public: + Frame(); + // Slider callback + void OnSlider( bbtk::BlackBox::Pointer p, const std::string& o, + bbtk::IOStatus s); +private: + bbwx::Slider::Pointer mSlider; + wxStaticText* mText; +}; +//========================================================================== + +//========================================================================== +Frame::Frame() : + wxFrame((wxFrame *)0, -1, _T("A frame which contains a bbwx::Slider"), + wxDefaultPosition, wxDefaultSize) +{ + wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL); + + //======================================== + // 1) Create the WxBlackBox + mSlider = bbwx::Slider::New("slider"); + // 2) Create the widget giving it the parent + mSlider->bbUserCreateWidget(this); + // 3) Add an observer to process output modifications + mSlider->bbAddOutputObserver ( "Out", + BBTK_MAKE_OUTPUT_OBSERVER ( this, + &Frame::OnSlider ) ); + // 4) Add the created widget in the sizer + sizer->Add(mSlider->bbGetOutputWidget(),1,wxGROW); + //========================================= + + //========================================= + // Create the static text as usual + mText = new wxStaticText ( this, -1 , _T("") ); + sizer->Add(mText,1,wxGROW); + //========================================= + + SetSizer(sizer); + SetAutoLayout(true); + Layout(); +} +//========================================================================== + +//========================================================================== +void Frame::OnSlider( bbtk::BlackBox::Pointer p, const std::string& o, + bbtk::IOStatus s) +{ + std::cout << "New slider value = " << mSlider->bbGetOutputOut() << std::endl; + std::ostringstream val; + val << mSlider->bbGetOutputOut(); + mText->SetLabel( bbtk::std2wx ( val.str() ) ); +} +//========================================================================== + +//========================================================================== +class App : public wxApp +{ +public: + bool OnInit( ); + int OnExit() { return true; } +}; +//========================================================================== + +//========================================================================== +// The `main program' equivalent, creating the windows and returning the +// main frame +bool App::OnInit( ) +{ + wxApp::OnInit(); +#ifdef __WXGTK__ + //See http://www.wxwindows.org/faqgtk.htm#locale + setlocale(LC_NUMERIC, "C"); +#endif + Frame* I = new Frame(); + I->Show(true); + return true; +} +//========================================================================= + +//========================================================================= +IMPLEMENT_APP(App); +//========================================================================= + -- 2.45.0