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