merge the formfield patch from ooo-build
[ooovba.git] / vcl / source / window / tabdlg.cxx
blobba2fc6a9c5c876c420ea9d3c5448d74835f80111
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabdlg.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <vcl/fixed.hxx>
34 #include <vcl/tabctrl.hxx>
35 #include <vcl/tabdlg.hxx>
36 #ifndef _SV_RC_H
37 #include <tools/rc.h>
38 #endif
42 // =======================================================================
44 void TabDialog::ImplInitTabDialogData()
46 mpFixedLine = NULL;
47 mpViewWindow = NULL;
48 meViewAlign = WINDOWALIGN_LEFT;
49 mbPosControls = TRUE;
52 // -----------------------------------------------------------------------
54 void TabDialog::ImplPosControls()
56 Size aCtrlSize( IMPL_MINSIZE_BUTTON_WIDTH, IMPL_MINSIZE_BUTTON_HEIGHT );
57 long nDownCtrl = 0;
58 long nOffY = 0;
59 TabControl* pTabControl = NULL;
61 Window* pChild = GetWindow( WINDOW_FIRSTCHILD );
62 while ( pChild )
64 if ( pChild->IsVisible() && (pChild != mpViewWindow) )
66 if ( pChild->GetType() == WINDOW_TABCONTROL )
67 pTabControl = (TabControl*)pChild;
68 else if ( pTabControl )
70 long nTxtWidth = pChild->GetCtrlTextWidth( pChild->GetText() );
71 nTxtWidth += IMPL_EXTRA_BUTTON_WIDTH;
72 if ( nTxtWidth > aCtrlSize.Width() )
73 aCtrlSize.Width() = nTxtWidth;
74 long nTxtHeight = pChild->GetTextHeight();
75 nTxtHeight += IMPL_EXTRA_BUTTON_HEIGHT;
76 if ( nTxtHeight > aCtrlSize.Height() )
77 aCtrlSize.Height() = nTxtHeight;
78 nDownCtrl++;
80 else
82 long nHeight = pChild->GetSizePixel().Height();
83 if ( nHeight > nOffY )
84 nOffY = nHeight;
88 pChild = pChild->GetWindow( WINDOW_NEXT );
91 // Haben wir ueberhaupt ein TabControl
92 if ( pTabControl )
94 // Offset bei weiteren Controls um einen weiteren Abstand anpassen
95 if ( nOffY )
96 nOffY += IMPL_DIALOG_BAR_OFFSET*2 + 2;
98 Point aTabOffset( IMPL_DIALOG_OFFSET, IMPL_DIALOG_OFFSET+nOffY );
99 Size aTabSize = pTabControl->GetSizePixel();
100 Size aDlgSize( aTabSize.Width() + IMPL_DIALOG_OFFSET*2,
101 aTabSize.Height() + IMPL_DIALOG_OFFSET*2 + nOffY );
102 long nBtnEx = 0;
104 // Preview-Fenster beruecksichtigen und die Groessen/Offsets anpassen
105 if ( mpViewWindow && mpViewWindow->IsVisible() )
107 long nViewOffX = 0;
108 long nViewOffY = 0;
109 long nViewWidth = 0;
110 long nViewHeight = 0;
111 USHORT nViewPosFlags = WINDOW_POSSIZE_POS;
112 Size aViewSize = mpViewWindow->GetSizePixel();
113 if ( meViewAlign == WINDOWALIGN_TOP )
115 nViewOffX = aTabOffset.X();
116 nViewOffY = nOffY+IMPL_DIALOG_OFFSET;
117 nViewWidth = aTabSize.Width();
118 nViewPosFlags |= WINDOW_POSSIZE_WIDTH;
119 aTabOffset.Y() += aViewSize.Height()+IMPL_DIALOG_OFFSET;
120 aDlgSize.Height() += aViewSize.Height()+IMPL_DIALOG_OFFSET;
122 else if ( meViewAlign == WINDOWALIGN_BOTTOM )
124 nViewOffX = aTabOffset.X();
125 nViewOffY = aTabOffset.Y()+aTabSize.Height()+IMPL_DIALOG_OFFSET;
126 nViewWidth = aTabSize.Width();
127 nViewPosFlags |= WINDOW_POSSIZE_WIDTH;
128 aDlgSize.Height() += aViewSize.Height()+IMPL_DIALOG_OFFSET;
130 else if ( meViewAlign == WINDOWALIGN_RIGHT )
132 nViewOffX = aTabOffset.X()+aTabSize.Width()+IMPL_DIALOG_OFFSET;
133 nViewOffY = aTabOffset.Y();
134 nViewHeight = aTabSize.Height();
135 nViewPosFlags |= WINDOW_POSSIZE_HEIGHT;
136 aDlgSize.Width() += aViewSize.Width()+IMPL_DIALOG_OFFSET;
137 nBtnEx = aViewSize.Width()+IMPL_DIALOG_OFFSET;
139 else // meViewAlign == WINDOWALIGN_LEFT
141 nViewOffX = IMPL_DIALOG_OFFSET;
142 nViewOffY = aTabOffset.Y();
143 nViewHeight = aTabSize.Height();
144 nViewPosFlags |= WINDOW_POSSIZE_HEIGHT;
145 aTabOffset.X() += aViewSize.Width()+IMPL_DIALOG_OFFSET;
146 aDlgSize.Width() += aViewSize.Width()+IMPL_DIALOG_OFFSET;
147 nBtnEx = aViewSize.Width()+IMPL_DIALOG_OFFSET;
150 mpViewWindow->SetPosSizePixel( nViewOffX, nViewOffY,
151 nViewWidth, nViewHeight,
152 nViewPosFlags );
155 // Positionierung vornehmen
156 pTabControl->SetPosPixel( aTabOffset );
158 // Alle anderen Childs positionieren
159 BOOL bTabCtrl = FALSE;
160 int nLines = 0;
161 long nX;
162 long nY = aDlgSize.Height();
163 long nTopX = IMPL_DIALOG_OFFSET;
165 // Unter Windows 95 werden die Buttons rechtsbuendig angeordnet
166 nX = IMPL_DIALOG_OFFSET;
167 long nCtrlBarWidth = ((aCtrlSize.Width()+IMPL_DIALOG_OFFSET)*nDownCtrl)-IMPL_DIALOG_OFFSET;
168 if ( nCtrlBarWidth <= (aTabSize.Width()+nBtnEx) )
169 nX = (aTabSize.Width()+nBtnEx) - nCtrlBarWidth + IMPL_DIALOG_OFFSET;
171 Window* pChild2 = GetWindow( WINDOW_FIRSTCHILD );
172 while ( pChild2 )
174 if ( pChild2->IsVisible() && (pChild2 != mpViewWindow) )
176 if ( pChild2 == pTabControl )
177 bTabCtrl = TRUE;
178 else if ( bTabCtrl )
180 if ( !nLines )
181 nLines = 1;
183 if ( nX+aCtrlSize.Width()-IMPL_DIALOG_OFFSET > (aTabSize.Width()+nBtnEx) )
185 nY += aCtrlSize.Height()+IMPL_DIALOG_OFFSET;
186 nX = IMPL_DIALOG_OFFSET;
187 nLines++;
190 pChild2->SetPosSizePixel( Point( nX, nY ), aCtrlSize );
191 nX += aCtrlSize.Width()+IMPL_DIALOG_OFFSET;
193 else
195 Size aChildSize = pChild2->GetSizePixel();
196 pChild2->SetPosPixel( Point( nTopX, (nOffY-aChildSize.Height())/2 ) );
197 nTopX += aChildSize.Width()+2;
201 pChild2 = pChild2->GetWindow( WINDOW_NEXT );
204 aDlgSize.Height() += nLines * (aCtrlSize.Height()+IMPL_DIALOG_OFFSET);
205 SetOutputSizePixel( aDlgSize );
208 // Offset merken
209 if ( nOffY )
211 Size aDlgSize = GetOutputSizePixel();
212 if ( !mpFixedLine )
213 mpFixedLine = new FixedLine( this );
214 mpFixedLine->SetPosSizePixel( Point( 0, nOffY ),
215 Size( aDlgSize.Width(), 2 ) );
216 mpFixedLine->Show();
219 mbPosControls = FALSE;
222 // -----------------------------------------------------------------------
224 TabDialog::TabDialog( Window* pParent, WinBits nStyle ) :
225 Dialog( WINDOW_TABDIALOG )
227 ImplInitTabDialogData();
228 ImplInit( pParent, nStyle );
231 // -----------------------------------------------------------------------
233 TabDialog::TabDialog( Window* pParent, const ResId& rResId ) :
234 Dialog( WINDOW_TABDIALOG )
236 ImplInitTabDialogData();
237 rResId.SetRT( RSC_TABDIALOG );
238 ImplInit( pParent, ImplInitRes( rResId ) );
239 ImplLoadRes( rResId );
242 // -----------------------------------------------------------------------
244 TabDialog::~TabDialog()
246 if ( mpFixedLine )
247 delete mpFixedLine;
250 // -----------------------------------------------------------------------
252 void TabDialog::Resize()
254 // !!! In the future the controls should be automaticly rearrange
255 // !!! if the window is resized
256 // !!! if ( !IsRollUp() )
257 // !!! ImplPosControls();
260 // -----------------------------------------------------------------------
262 void TabDialog::StateChanged( StateChangedType nType )
264 if ( nType == STATE_CHANGE_INITSHOW )
266 // Calculate the Layout only for the initialized state
267 if ( mbPosControls )
268 ImplPosControls();
270 Dialog::StateChanged( nType );
273 // -----------------------------------------------------------------------
275 void TabDialog::AdjustLayout()
277 ImplPosControls();