]> Creatis software - bbtk.git/commitdiff
*** empty log message ***
authorguigues <guigues>
Wed, 10 Dec 2008 10:37:29 +0000 (10:37 +0000)
committerguigues <guigues>
Wed, 10 Dec 2008 10:37:29 +0000 (10:37 +0000)
samples/CMakeLists.txt
samples/SampleInsertWxBlackBoxInOwnFrame/CMakeLists.txt [new file with mode: 0644]
samples/SampleInsertWxBlackBoxInOwnFrame/bbtkSampleInsertWxBlackBoxInOwnFrame.cxx [new file with mode: 0644]

index 3f409c0946a1f5f587e6beda770a49311077d672..c6abdf67165c7111e41f0c3bd51b75b3c764c57d 100644 (file)
@@ -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 (file)
index 0000000..4cd80c9
--- /dev/null
@@ -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 (file)
index 0000000..9efe1bd
--- /dev/null
@@ -0,0 +1,94 @@
+#include <bbwxSlider.h>
+#include <bbwxLayoutLine.h>
+
+//=========================================================================
+// 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);
+//=========================================================================
+