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