]> Creatis software - bbtk.git/blob - packages/kw/src/bbkwLayoutSplit.cxx
10a2097d1e41e0a058598805eb16c679e5ac69b4
[bbtk.git] / packages / kw / src / bbkwLayoutSplit.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbkwLayoutSplit.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/12/02 13:37:56 $
6   Version:   $Revision: 1.3 $
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_KWWIDGETS
38
39 #include "bbkwLayoutSplit.h"
40 #include "bbkwPackage.h"
41 #include "bbtkUtilities.h"
42
43 #include <vtkKWSplitFrame.h>
44
45 namespace bbkw
46 {
47   BBTK_ADD_BLACK_BOX_TO_PACKAGE(kw,LayoutSplit);
48   BBTK_BLACK_BOX_IMPLEMENTATION(LayoutSplit,bbtk::KWBlackBox);
49
50   void LayoutSplit::bbUserConstructor()
51   {
52     bbSetInputOrientation("VERTICAL");
53     bbSetInputProportion(50);
54     bbSetInputWidget1(NULL);
55     bbSetInputWidget2(NULL);
56   }
57
58   void LayoutSplit::Process()
59   {
60   }
61
62
63   void LayoutSplit::CreateWidget(vtkKWFrame* parent) 
64   {
65     vtkKWSplitFrame *splitframe = vtkKWSplitFrame::New();
66     bbSetOutputWidget(splitframe);
67     splitframe->SetParent(parent);
68     splitframe->Create();
69     splitframe->SetFrame1MinimumSize(5);
70     splitframe->SetFrame2MinimumSize(5);
71     splitframe->SetExpandableFrameToBothFrames();
72
73  
74     int width = parent->GetWidth();
75     int height = parent->GetHeight();
76     int orientation = 0;
77     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"0|H|HORIZONTAL")==true)  
78       { 
79         orientation = 0; 
80      }
81     else if (bbtk::Utilities::loosematch(bbGetInputOrientation(),"1|V|VERTICAL")==true)           
82       {
83         orientation = 1; 
84       }
85     else 
86       {
87         bbtkWarning("Unrecognized value '"<<bbGetInputOrientation()<<"' for input 'Orientation' of LayoutSplit "<<bbGetName()<<std::endl);
88       }
89
90     if (orientation==0)
91       {
92         splitframe->SetOrientationToHorizontal ();
93         width = width / 2;
94       }
95     else 
96       {
97         splitframe->SetOrientationToVertical ();
98         height = height / 2 ;   
99       }  
100
101    width = width - 5;
102    height = height - 5 ;
103     
104     bbGetOutputWidget()->GetApplication()->Script("place %s -x 0 -y 0 -width %d -height %d",
105                                                   bbGetOutputWidget()->GetWidgetName(),
106                                                   parent->GetWidth(),
107                                                   parent->GetHeight() );
108
109     splitframe->SetReliefToGroove();
110     splitframe->SetBorderWidth(2);
111
112
113     vtkKWWidget* w1 =  bbCreateWidgetOfInput("Widget1",splitframe->GetFrame1());
114     
115     vtkKWWidget* w2 = bbCreateWidgetOfInput("Widget2",splitframe->GetFrame2());
116  
117
118    splitframe->GetApplication()->Script("place %s -x 0 -y 0 -width %d -height %d",
119                                         w1->GetWidgetName(),
120                                         width,
121                                         height);
122
123   splitframe->GetApplication()->Script("place %s -x 0 -y 0 -width %d -height %d",
124                                        w2->GetWidgetName(),
125                                        width,
126                                        height);
127   
128
129
130   }
131
132
133   // This callback is necessary to get actual processing of the view 
134   // when window is shown
135   /*
136   void  LayoutSplit::OnShowWidget()
137   {
138     if (bbGetOutputWidget()==0)
139       {
140         return;
141         //bbtkError("LayoutSplit::OnShowWidget() : Output Widget == 0 !");
142       }
143     kwSplitterWindow* win = (kwSplitterWindow*)bbGetOutputWidget();
144     int w,h;
145     if (win==0)
146       {
147         return;
148         //      bbtkError("LayoutSplit::OnShowWidget() : win == 0 !");
149       }
150     win->GetClientSize(&w,&h);
151     int pos = 100;
152     if (bbtk::Utilities::loosematch(bbGetInputOrientation(),
153                                     "0|H|HORIZONTAL")==true)  
154       { 
155         pos = (int)(w * bbGetInputProportion() * 0.01);
156       }
157     else 
158       {
159         pos = (int)(h * bbGetInputProportion() * 0.01);
160       } 
161     //    std::cout << "pos = "<<pos<<std::endl;
162   
163     win->SetSashPosition(pos,true);
164     bbUserOnShowWidget("Widget1");
165     bbUserOnShowWidget("Widget2");
166   }
167   */
168
169
170
171 }//namespace bbkw
172
173 #endif // _USE_KWWIDGETS_
174