]> Creatis software - bbtk.git/blob - samples/SampleInsertWxBlackBoxInOwnFrame/bbtkSampleInsertWxBlackBoxInOwnFrame.cxx
17482f1b90b8129005834b83768671bf99a079f3
[bbtk.git] / samples / SampleInsertWxBlackBoxInOwnFrame / bbtkSampleInsertWxBlackBoxInOwnFrame.cxx
1 #include <bbwxSlider.h>
2 #include <bbwxLayoutLine.h>
3 #include <creaWx.h>
4 //=========================================================================
5 // Illustrates how to insert a WxBlackBox into his own wxFrame
6 //=========================================================================
7
8 //==========================================================================
9 // A custom wxFrame which own a bbwx::Slider widget
10 class Frame : public wxFrame
11 {
12 public:
13   Frame();
14   // Slider callback
15   void OnSlider( bbtk::BlackBox::Pointer p, const std::string& o,
16                  bbtk::IOStatus s);
17 private:
18   bbwx::Slider::Pointer mSlider;
19   wxStaticText* mText;
20 };
21 //==========================================================================
22
23 //==========================================================================
24 Frame::Frame() :
25   wxFrame((wxFrame *)0, -1, _T("A frame which contains a bbwx::Slider"), 
26           wxDefaultPosition, wxDefaultSize)
27 {
28   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
29
30   //========================================  
31   // 1) Create the WxBlackBox
32   mSlider = bbwx::Slider::New("slider");
33   // 2) Create the widget giving it the parent
34   mSlider->bbUserCreateWidget(this);
35   // 3) Add an observer to process output modifications
36   mSlider->bbAddOutputObserver ( "Out", 
37                                  BBTK_MAKE_OUTPUT_OBSERVER ( this,
38                                                              &Frame::OnSlider ) );
39   // 4) Add the created widget in the sizer
40   sizer->Add(mSlider->bbGetOutputWidget(),1,wxGROW);
41   //=========================================
42   
43   //=========================================
44   // Create the static text as usual
45   mText = new wxStaticText ( this, -1 , _T("") );
46   sizer->Add(mText,1,wxGROW);
47   //=========================================
48
49   SetSizer(sizer);
50   SetAutoLayout(true);
51   Layout();
52 }
53 //==========================================================================
54
55 //==========================================================================
56 void Frame::OnSlider( bbtk::BlackBox::Pointer p, const std::string& o,
57                       bbtk::IOStatus s)
58 {
59   std::cout << "New slider value = " << mSlider->bbGetOutputOut() << std::endl;
60   std::ostringstream val;
61   val << mSlider->bbGetOutputOut();
62   mText->SetLabel( bbtk::std2wx ( val.str() ) );
63 }
64 //==========================================================================
65
66 //==========================================================================
67 class App : public wxApp
68 {
69 public:
70   bool OnInit( );
71   int  OnExit() { return true; }
72 };
73 //==========================================================================
74
75 //==========================================================================
76 // The `main program' equivalent, creating the windows and returning the
77 // main frame
78 bool App::OnInit( )
79 {
80   wxApp::OnInit();
81 #ifdef __WXGTK__
82   //See http://www.wxwindows.org/faqgtk.htm#locale
83   setlocale(LC_NUMERIC, "C");
84 #endif
85   Frame* I = new Frame();
86   I->Show(true);
87   return true;
88 }
89 //=========================================================================
90
91 //=========================================================================
92 IMPLEMENT_APP(App);
93 CREA_WXMAIN_WITH_CONSOLE;
94 //=========================================================================