Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <vcl/fixed.hxx>
30 : : #include <vcl/tabctrl.hxx>
31 : : #include <vcl/tabdlg.hxx>
32 : : #include <tools/rc.h>
33 : :
34 : :
35 : :
36 : : // =======================================================================
37 : :
38 : 0 : void TabDialog::ImplInitTabDialogData()
39 : : {
40 : 0 : mpFixedLine = NULL;
41 : 0 : mpViewWindow = NULL;
42 : 0 : meViewAlign = WINDOWALIGN_LEFT;
43 : 0 : mbPosControls = sal_True;
44 : 0 : }
45 : :
46 : : // -----------------------------------------------------------------------
47 : :
48 : 0 : void TabDialog::ImplPosControls()
49 : : {
50 : 0 : Size aCtrlSize( IMPL_MINSIZE_BUTTON_WIDTH, IMPL_MINSIZE_BUTTON_HEIGHT );
51 : 0 : long nDownCtrl = 0;
52 : 0 : long nOffY = 0;
53 : 0 : TabControl* pTabControl = NULL;
54 : :
55 [ # # ]: 0 : Window* pChild = GetWindow( WINDOW_FIRSTCHILD );
56 [ # # ]: 0 : while ( pChild )
57 : : {
58 [ # # ][ # # ]: 0 : if ( pChild->IsVisible() && (pChild != mpViewWindow) )
[ # # ][ # # ]
59 : : {
60 [ # # ][ # # ]: 0 : if ( pChild->GetType() == WINDOW_TABCONTROL )
61 : 0 : pTabControl = (TabControl*)pChild;
62 [ # # ]: 0 : else if ( pTabControl )
63 : : {
64 [ # # ]: 0 : Size aOptimalSize( pChild->GetOptimalSize( WINDOWSIZE_PREFERRED ) );
65 : 0 : long nTxtWidth = aOptimalSize.Width();
66 [ # # ]: 0 : if ( nTxtWidth > aCtrlSize.Width() )
67 : 0 : aCtrlSize.Width() = nTxtWidth;
68 : 0 : long nTxtHeight = aOptimalSize.Height();
69 [ # # ]: 0 : if ( nTxtHeight > aCtrlSize.Height() )
70 : 0 : aCtrlSize.Height() = nTxtHeight;
71 : 0 : nDownCtrl++;
72 : : }
73 : : else
74 : : {
75 [ # # ]: 0 : long nHeight = pChild->GetSizePixel().Height();
76 [ # # ]: 0 : if ( nHeight > nOffY )
77 : 0 : nOffY = nHeight;
78 : : }
79 : : }
80 : :
81 [ # # ]: 0 : pChild = pChild->GetWindow( WINDOW_NEXT );
82 : : }
83 : :
84 : : // Haben wir ueberhaupt ein TabControl
85 [ # # ]: 0 : if ( pTabControl )
86 : : {
87 : : // Offset bei weiteren Controls um einen weiteren Abstand anpassen
88 [ # # ]: 0 : if ( nOffY )
89 : 0 : nOffY += IMPL_DIALOG_BAR_OFFSET*2 + 2;
90 : :
91 : 0 : Point aTabOffset( IMPL_DIALOG_OFFSET, IMPL_DIALOG_OFFSET+nOffY );
92 [ # # ]: 0 : Size aTabSize = pTabControl->GetSizePixel();
93 : 0 : Size aDlgSize( aTabSize.Width() + IMPL_DIALOG_OFFSET*2,
94 : 0 : aTabSize.Height() + IMPL_DIALOG_OFFSET*2 + nOffY );
95 : 0 : long nBtnEx = 0;
96 : :
97 : : // Preview-Fenster beruecksichtigen und die Groessen/Offsets anpassen
98 [ # # ][ # # ]: 0 : if ( mpViewWindow && mpViewWindow->IsVisible() )
[ # # ][ # # ]
99 : : {
100 : 0 : long nViewOffX = 0;
101 : 0 : long nViewOffY = 0;
102 : 0 : long nViewWidth = 0;
103 : 0 : long nViewHeight = 0;
104 : 0 : sal_uInt16 nViewPosFlags = WINDOW_POSSIZE_POS;
105 [ # # ]: 0 : Size aViewSize = mpViewWindow->GetSizePixel();
106 [ # # ]: 0 : if ( meViewAlign == WINDOWALIGN_TOP )
107 : : {
108 : 0 : nViewOffX = aTabOffset.X();
109 : 0 : nViewOffY = nOffY+IMPL_DIALOG_OFFSET;
110 : 0 : nViewWidth = aTabSize.Width();
111 : 0 : nViewPosFlags |= WINDOW_POSSIZE_WIDTH;
112 : 0 : aTabOffset.Y() += aViewSize.Height()+IMPL_DIALOG_OFFSET;
113 : 0 : aDlgSize.Height() += aViewSize.Height()+IMPL_DIALOG_OFFSET;
114 : : }
115 [ # # ]: 0 : else if ( meViewAlign == WINDOWALIGN_BOTTOM )
116 : : {
117 : 0 : nViewOffX = aTabOffset.X();
118 : 0 : nViewOffY = aTabOffset.Y()+aTabSize.Height()+IMPL_DIALOG_OFFSET;
119 : 0 : nViewWidth = aTabSize.Width();
120 : 0 : nViewPosFlags |= WINDOW_POSSIZE_WIDTH;
121 : 0 : aDlgSize.Height() += aViewSize.Height()+IMPL_DIALOG_OFFSET;
122 : : }
123 [ # # ]: 0 : else if ( meViewAlign == WINDOWALIGN_RIGHT )
124 : : {
125 : 0 : nViewOffX = aTabOffset.X()+aTabSize.Width()+IMPL_DIALOG_OFFSET;
126 : 0 : nViewOffY = aTabOffset.Y();
127 : 0 : nViewHeight = aTabSize.Height();
128 : 0 : nViewPosFlags |= WINDOW_POSSIZE_HEIGHT;
129 : 0 : aDlgSize.Width() += aViewSize.Width()+IMPL_DIALOG_OFFSET;
130 : 0 : nBtnEx = aViewSize.Width()+IMPL_DIALOG_OFFSET;
131 : : }
132 : : else // meViewAlign == WINDOWALIGN_LEFT
133 : : {
134 : 0 : nViewOffX = IMPL_DIALOG_OFFSET;
135 : 0 : nViewOffY = aTabOffset.Y();
136 : 0 : nViewHeight = aTabSize.Height();
137 : 0 : nViewPosFlags |= WINDOW_POSSIZE_HEIGHT;
138 : 0 : aTabOffset.X() += aViewSize.Width()+IMPL_DIALOG_OFFSET;
139 : 0 : aDlgSize.Width() += aViewSize.Width()+IMPL_DIALOG_OFFSET;
140 : 0 : nBtnEx = aViewSize.Width()+IMPL_DIALOG_OFFSET;
141 : : }
142 : :
143 : : mpViewWindow->SetPosSizePixel( nViewOffX, nViewOffY,
144 : : nViewWidth, nViewHeight,
145 [ # # ]: 0 : nViewPosFlags );
146 : : }
147 : :
148 : : // Positionierung vornehmen
149 [ # # ]: 0 : pTabControl->SetPosPixel( aTabOffset );
150 : :
151 : : // Alle anderen Children positionieren
152 : 0 : sal_Bool bTabCtrl = sal_False;
153 : 0 : int nLines = 0;
154 : : long nX;
155 : 0 : long nY = aDlgSize.Height();
156 : 0 : long nTopX = IMPL_DIALOG_OFFSET;
157 : :
158 : : // Unter Windows 95 werden die Buttons rechtsbuendig angeordnet
159 : 0 : nX = IMPL_DIALOG_OFFSET;
160 : 0 : long nCtrlBarWidth = ((aCtrlSize.Width()+IMPL_DIALOG_OFFSET)*nDownCtrl)-IMPL_DIALOG_OFFSET;
161 [ # # ]: 0 : if ( nCtrlBarWidth <= (aTabSize.Width()+nBtnEx) )
162 : 0 : nX = (aTabSize.Width()+nBtnEx) - nCtrlBarWidth + IMPL_DIALOG_OFFSET;
163 : :
164 [ # # ]: 0 : Window* pChild2 = GetWindow( WINDOW_FIRSTCHILD );
165 [ # # ]: 0 : while ( pChild2 )
166 : : {
167 [ # # ][ # # ]: 0 : if ( pChild2->IsVisible() && (pChild2 != mpViewWindow) )
[ # # ][ # # ]
168 : : {
169 [ # # ]: 0 : if ( pChild2 == pTabControl )
170 : 0 : bTabCtrl = sal_True;
171 [ # # ]: 0 : else if ( bTabCtrl )
172 : : {
173 [ # # ]: 0 : if ( !nLines )
174 : 0 : nLines = 1;
175 : :
176 [ # # ]: 0 : if ( nX+aCtrlSize.Width()-IMPL_DIALOG_OFFSET > (aTabSize.Width()+nBtnEx) )
177 : : {
178 : 0 : nY += aCtrlSize.Height()+IMPL_DIALOG_OFFSET;
179 : 0 : nX = IMPL_DIALOG_OFFSET;
180 : 0 : nLines++;
181 : : }
182 : :
183 [ # # ]: 0 : pChild2->SetPosSizePixel( Point( nX, nY ), aCtrlSize );
184 : 0 : nX += aCtrlSize.Width()+IMPL_DIALOG_OFFSET;
185 : : }
186 : : else
187 : : {
188 [ # # ]: 0 : Size aChildSize = pChild2->GetSizePixel();
189 [ # # ]: 0 : pChild2->SetPosPixel( Point( nTopX, (nOffY-aChildSize.Height())/2 ) );
190 : 0 : nTopX += aChildSize.Width()+2;
191 : : }
192 : : }
193 : :
194 [ # # ]: 0 : pChild2 = pChild2->GetWindow( WINDOW_NEXT );
195 : : }
196 : :
197 : 0 : aDlgSize.Height() += nLines * (aCtrlSize.Height()+IMPL_DIALOG_OFFSET);
198 [ # # ]: 0 : SetOutputSizePixel( aDlgSize );
199 : : }
200 : :
201 : : // Offset merken
202 [ # # ]: 0 : if ( nOffY )
203 : : {
204 : 0 : Size aDlgSize = GetOutputSizePixel();
205 [ # # ]: 0 : if ( !mpFixedLine )
206 [ # # ][ # # ]: 0 : mpFixedLine = new FixedLine( this );
207 : : mpFixedLine->SetPosSizePixel( Point( 0, nOffY ),
208 [ # # ]: 0 : Size( aDlgSize.Width(), 2 ) );
209 [ # # ]: 0 : mpFixedLine->Show();
210 : : }
211 : :
212 : 0 : mbPosControls = sal_False;
213 : 0 : }
214 : :
215 : : // -----------------------------------------------------------------------
216 : :
217 : 0 : TabDialog::TabDialog( Window* pParent, WinBits nStyle ) :
218 : 0 : Dialog( WINDOW_TABDIALOG )
219 : : {
220 : 0 : ImplInitTabDialogData();
221 [ # # ]: 0 : ImplInit( pParent, nStyle );
222 : 0 : }
223 : :
224 : : // -----------------------------------------------------------------------
225 : :
226 : 0 : TabDialog::TabDialog( Window* pParent, const ResId& rResId ) :
227 : 0 : Dialog( WINDOW_TABDIALOG )
228 : : {
229 : 0 : ImplInitTabDialogData();
230 : 0 : rResId.SetRT( RSC_TABDIALOG );
231 [ # # ][ # # ]: 0 : ImplInit( pParent, ImplInitRes( rResId ) );
232 [ # # ]: 0 : ImplLoadRes( rResId );
233 : 0 : }
234 : :
235 : : // -----------------------------------------------------------------------
236 : :
237 : 0 : TabDialog::~TabDialog()
238 : : {
239 [ # # ][ # # ]: 0 : delete mpFixedLine;
240 [ # # ]: 0 : }
241 : :
242 : : // -----------------------------------------------------------------------
243 : :
244 : 0 : void TabDialog::Resize()
245 : : {
246 : : // !!! In the future the controls should be automaticly rearrange
247 : : // !!! if the window is resized
248 : : // !!! if ( !IsRollUp() )
249 : : // !!! ImplPosControls();
250 : 0 : }
251 : :
252 : : // -----------------------------------------------------------------------
253 : :
254 : 0 : void TabDialog::StateChanged( StateChangedType nType )
255 : : {
256 [ # # ]: 0 : if ( nType == STATE_CHANGE_INITSHOW )
257 : : {
258 : : // Calculate the Layout only for the initialized state
259 [ # # ]: 0 : if ( mbPosControls )
260 : 0 : ImplPosControls();
261 : : }
262 : 0 : Dialog::StateChanged( nType );
263 : 0 : }
264 : :
265 : : // -----------------------------------------------------------------------
266 : :
267 : 0 : void TabDialog::AdjustLayout()
268 : : {
269 : 0 : ImplPosControls();
270 : 0 : }
271 : :
272 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|