]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxLayoutSplit.cxx
#3514 Layout
[bbtk.git] / packages / wx / src / bbwxLayoutSplit.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbwxLayoutSplit.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:52:14 $
33   Version:   $Revision: 1.14 $
34 =========================================================================*/
35
36 /**
37  *  \file
38  *  \brief
39  */
40
41
42 #ifdef _USE_WXWIDGETS_
43
44 #include "bbwxLayoutSplit.h"
45 #include "bbwxPackage.h"
46 #include "bbtkUtilities.h"
47
48
49 namespace bbwx
50 {
51   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,LayoutSplit);
52   BBTK_BLACK_BOX_IMPLEMENTATION(LayoutSplit,bbtk::WxBlackBox);
53
54         //-----------------------------------------------------------------     
55         void LayoutSplit::bbUserSetDefaultValues()
56         {
57                 bbSetInputOrientation("VERTICAL");
58                 bbSetInputProportion(50);
59                 bbSetInputWidget1(NULL);
60                 bbSetInputWidget2(NULL);
61                 w=NULL; 
62         }
63         
64         //-----------------------------------------------------------------     
65         void LayoutSplit::bbUserInitializeProcessing()
66         {
67         }
68         
69         //-----------------------------------------------------------------     
70         void LayoutSplit::bbUserFinalizeProcessing()
71         {
72         }       
73         
74         void LayoutSplit::Process()
75         {
76                 PutWinTitle();
77         }
78
79   void LayoutSplit::CreateWidget(wxWindow* parent)
80   {
81     wxPanel             *splitterWindowPanel    = new wxPanel(parent, -1, wxDefaultPosition, wxSize(40,40) );
82
83  //   wxSplitterWindow  *w
84                         w                       = new wxSplitterWindow( splitterWindowPanel, //bbGetWxParent(),
85                                                                         -1,
86                                                                         wxDefaultPosition,
87                                                                         wxDefaultSize,
88 //                                                                      wxSize(400,200),
89                                                                         wxSP_3DSASH |
90                                                                         wxSP_LIVE_UPDATE );
91         w->SetName( bbtk::std2wx( bbGetInputWinTitle() ) );
92         w->SetMinimumPaneSize(15);
93         //RaC Nov2012 Correctly resize internal panels with the window resize event
94         w->SetSashGravity(0.5);
95 /*
96           wxWindow* w1 = bbGetInputWidget1();
97     wxWindow* w2 = bbGetInputWidget2();
98
99     if (w1==NULL) { w1=new wxPanel(bbGetWxParent()); }
100     if (w2==NULL) { w2=new wxPanel(bbGetWxParent()); }
101     w1->Reparent(w);
102     w2->Reparent(w);
103  */ 
104
105           wxWindow* w1 = bbCreateWidgetOfInput("Widget1",w);
106           wxWindow* w2 = bbCreateWidgetOfInput("Widget2",w);
107           if (w1==NULL) { w1=new wxPanel(splitterWindowPanel); }
108           if (w2==NULL) { w2=new wxPanel(splitterWindowPanel); }
109           
110           int orientation=0;
111     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"0|H|h|horizontal|Horizontal|HORIZONTAL")==true)  { orientation=0; }
112     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"1|V|v|vertical|Vertical|VERTICAL")==true)    { orientation=1; }
113     
114
115     if (orientation==1) { w->SplitHorizontally( w1, w2, 100); }
116     else                { w->SplitVertically( w1, w2, 100);   }
117
118 //EED 2024-03-30  
119     wxBoxSizer *sizer   = new wxBoxSizer(wxVERTICAL);
120     sizer->Add( w , 1, wxGROW, 0 );
121     splitterWindowPanel->SetSizer( sizer );
122     splitterWindowPanel->SetAutoLayout(true);
123     splitterWindowPanel->Layout();
124     bbSetOutputWidget( splitterWindowPanel );
125 //    bbSetOutputWidget( w );
126
127   }
128
129
130   // This callback is necessary to get actual processing of the view 
131   // when window is shown
132   void  LayoutSplit::OnShowWidget()
133   {
134     //    std::cout << "LayoutSplit::OnShowWidget()" << std::endl;
135     if (bbGetOutputWidget()==NULL)
136       {
137         return;
138         //bbtkError("LayoutSplit::OnShowWidget() : Output Widget == 0 !");
139       }
140 //    wxSplitterWindow* win = (wxSplitterWindow*)bbGetOutputWidget();
141     int width,height;
142     if (w==NULL)
143       {
144         return;
145         //      bbtkError("LayoutSplit::OnShowWidget() : win == 0 !");
146       }
147     w->GetParent()->GetParent()->GetClientSize(&width,&height);
148     int    pos = 100;
149     double ww  = width;
150     double hh  = height;
151     double proportion = bbGetInputProportion();
152     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),
153                                     "0|H|h|horizontal|Horizontal|HORIZONTAL")==true)  
154       { 
155         pos = (int)(ww * proportion * 0.01);
156       }    else {
157         pos = (int)(hh * proportion * 0.01);
158       } 
159   
160         printf("EED LayoutSplit::OnShowWidget  width=%d   height=%d  proportion=%d pos=%d box=%s\n", width,height,bbGetInputProportion(),pos, bbGetFullName().c_str() );        
161     w->SetSashPosition(pos,true);
162     //RaC Nov2012 Correctly resize internal panels with the window resize event
163     w->SetSashGravity(0.5);
164
165   }
166
167
168
169 }//namespace bbwx
170
171 #endif // _USE_WXWIDGETS_
172