]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxLayoutSplit.cxx
Another ugly bug fixed in pipeline executing (bad transfer to parent in some cases...
[bbtk.git] / packages / wx / src / bbwxLayoutSplit.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbwxLayoutSplit.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/11/13 14:46:46 $
6   Version:   $Revision: 1.7 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *  \file
33  *  \brief
34  */
35
36
37 #ifdef _USE_WXWIDGETS_
38
39 #include "bbwxLayoutSplit.h"
40 #include "bbwxPackage.h"
41 #include "bbtkUtilities.h"
42
43
44 namespace bbwx
45 {
46   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,LayoutSplit);
47   BBTK_BLACK_BOX_IMPLEMENTATION(LayoutSplit,bbtk::WxBlackBox);
48
49   void LayoutSplit::bbUserConstructor()
50   {
51     bbSetInputOrientation("VERTICAL");
52     bbSetInputProportion(50);
53     bbSetInputWidget1(NULL);
54     bbSetInputWidget2(NULL);
55   }
56
57   void LayoutSplit::Process()
58   {
59   }
60
61   void LayoutSplit::CreateWidget()
62   {
63     wxSplitterWindow* w = new wxSplitterWindow(bbGetWxParent(),
64                                                -1,
65                                                wxDefaultPosition,
66                                                wxDefaultSize,
67                                                //wxSize(400,200),
68                                                wxSP_3D |
69                                                wxSP_LIVE_UPDATE );
70     w->SetName( bbtk::std2wx( bbGetInputWinTitle() ) );
71     wxWindow* w1 = bbGetInputWidget1();
72     wxWindow* w2 = bbGetInputWidget2();
73
74     if (w1==NULL) { w1=new wxPanel(bbGetWxParent()); }
75     if (w2==NULL) { w2=new wxPanel(bbGetWxParent()); }
76     w1->Reparent(w);
77     w2->Reparent(w);
78     int orientation=0;
79     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"0|H|HORIZONTAL")==true)  { orientation=0; }
80     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"1|V|VERTICAL")==true)        { orientation=1; }
81     
82     if (orientation==1) { w->SplitHorizontally( w1, w2, 100); }
83     else                { w->SplitVertically( w1, w2, 100);   }
84     
85     bbSetOutputWidget( w );
86   }
87
88
89   // This callback is necessary to get actual processing of the view 
90   // when window is shown
91   void  LayoutSplit::OnShowWidget()
92   {
93     if (bbGetOutputWidget()==0)
94       {
95         return;
96         //bbtkError("LayoutSplit::OnShowWidget() : Output Widget == 0 !");
97       }
98     wxSplitterWindow* win = (wxSplitterWindow*)bbGetOutputWidget();
99     int w,h;
100     if (win==0)
101       {
102         return;
103         //      bbtkError("LayoutSplit::OnShowWidget() : win == 0 !");
104       }
105     win->GetClientSize(&w,&h);
106     int pos = 100;
107     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),
108                                     "0|H|HORIZONTAL")==true)  
109       { 
110         pos = (int)(w * bbGetInputProportion() * 0.01);
111       }
112     else 
113       {
114         pos = (int)(h * bbGetInputProportion() * 0.01);
115       } 
116     //    std::cout << "pos = "<<pos<<std::endl;
117   
118     win->SetSashPosition(pos,true);
119     bbUserOnShowWidget("Widget1");
120     bbUserOnShowWidget("Widget2");
121   }
122
123
124
125 }//namespace bbwx
126
127 #endif // _USE_WXWIDGETS_
128