1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/fixed.hxx>
21 #include <vcl/layout.hxx>
22 #include <vcl/tabctrl.hxx>
23 #include <vcl/tabdlg.hxx>
28 // =======================================================================
30 void TabDialog::ImplInitTabDialogData()
34 meViewAlign
= WINDOWALIGN_LEFT
;
35 mbPosControls
= sal_True
;
38 // -----------------------------------------------------------------------
40 void TabDialog::ImplPosControls()
42 if (isLayoutEnabled())
45 Size
aCtrlSize( IMPL_MINSIZE_BUTTON_WIDTH
, IMPL_MINSIZE_BUTTON_HEIGHT
);
48 Window
* pTabControl
= NULL
;
50 Window
* pChild
= GetWindow( WINDOW_FIRSTCHILD
);
53 if ( pChild
->IsVisible() && (pChild
!= mpViewWindow
) )
55 if (pChild
->GetType() == WINDOW_TABCONTROL
|| isContainerWindow(*pChild
))
57 else if ( pTabControl
)
59 Size
aOptimalSize(pChild
->GetOptimalSize());
60 long nTxtWidth
= aOptimalSize
.Width();
61 if ( nTxtWidth
> aCtrlSize
.Width() )
62 aCtrlSize
.Width() = nTxtWidth
;
63 long nTxtHeight
= aOptimalSize
.Height();
64 if ( nTxtHeight
> aCtrlSize
.Height() )
65 aCtrlSize
.Height() = nTxtHeight
;
70 long nHeight
= pChild
->GetSizePixel().Height();
71 if ( nHeight
> nOffY
)
76 pChild
= pChild
->GetWindow( WINDOW_NEXT
);
79 // Haben wir ueberhaupt ein TabControl
82 // Offset bei weiteren Controls um einen weiteren Abstand anpassen
84 nOffY
+= IMPL_DIALOG_BAR_OFFSET
*2 + 2;
86 Point
aTabOffset( IMPL_DIALOG_OFFSET
, IMPL_DIALOG_OFFSET
+nOffY
);
88 if (isContainerWindow(*pTabControl
))
89 pTabControl
->SetSizePixel(pTabControl
->GetOptimalSize());
91 Size aTabSize
= pTabControl
->GetSizePixel();
93 Size
aDlgSize( aTabSize
.Width() + IMPL_DIALOG_OFFSET
*2,
94 aTabSize
.Height() + IMPL_DIALOG_OFFSET
*2 + nOffY
);
97 // Preview-Fenster beruecksichtigen und die Groessen/Offsets anpassen
98 if ( mpViewWindow
&& mpViewWindow
->IsVisible() )
103 long nViewHeight
= 0;
104 sal_uInt16 nViewPosFlags
= WINDOW_POSSIZE_POS
;
105 Size aViewSize
= mpViewWindow
->GetSizePixel();
106 if ( meViewAlign
== WINDOWALIGN_TOP
)
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
;
115 else if ( meViewAlign
== WINDOWALIGN_BOTTOM
)
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
;
123 else if ( meViewAlign
== WINDOWALIGN_RIGHT
)
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
;
132 else // meViewAlign == WINDOWALIGN_LEFT
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
;
143 mpViewWindow
->setPosSizePixel( nViewOffX
, nViewOffY
,
144 nViewWidth
, nViewHeight
,
148 // Positionierung vornehmen
149 pTabControl
->SetPosPixel( aTabOffset
);
151 // Alle anderen Children positionieren
152 sal_Bool bTabCtrl
= sal_False
;
155 long nY
= aDlgSize
.Height();
156 long nTopX
= IMPL_DIALOG_OFFSET
;
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
;
164 Window
* pChild2
= GetWindow( WINDOW_FIRSTCHILD
);
167 if ( pChild2
->IsVisible() && (pChild2
!= mpViewWindow
) )
169 if ( pChild2
== pTabControl
)
176 if ( nX
+aCtrlSize
.Width()-IMPL_DIALOG_OFFSET
> (aTabSize
.Width()+nBtnEx
) )
178 nY
+= aCtrlSize
.Height()+IMPL_DIALOG_OFFSET
;
179 nX
= IMPL_DIALOG_OFFSET
;
183 pChild2
->SetPosSizePixel( Point( nX
, nY
), aCtrlSize
);
184 nX
+= aCtrlSize
.Width()+IMPL_DIALOG_OFFSET
;
188 Size aChildSize
= pChild2
->GetSizePixel();
189 pChild2
->SetPosPixel( Point( nTopX
, (nOffY
-aChildSize
.Height())/2 ) );
190 nTopX
+= aChildSize
.Width()+2;
194 pChild2
= pChild2
->GetWindow( WINDOW_NEXT
);
197 aDlgSize
.Height() += nLines
* (aCtrlSize
.Height()+IMPL_DIALOG_OFFSET
);
198 SetOutputSizePixel( aDlgSize
);
204 Size aDlgSize
= GetOutputSizePixel();
206 mpFixedLine
= new FixedLine( this );
207 mpFixedLine
->SetPosSizePixel( Point( 0, nOffY
),
208 Size( aDlgSize
.Width(), 2 ) );
212 mbPosControls
= sal_False
;
215 // -----------------------------------------------------------------------
217 TabDialog::TabDialog( Window
* pParent
, WinBits nStyle
) :
218 Dialog( WINDOW_TABDIALOG
)
220 ImplInitTabDialogData();
221 ImplInit( pParent
, nStyle
);
224 // -----------------------------------------------------------------------
226 TabDialog::TabDialog( Window
* pParent
, const ResId
& rResId
) :
227 Dialog( WINDOW_TABDIALOG
)
229 ImplInitTabDialogData();
230 rResId
.SetRT( RSC_TABDIALOG
);
231 init(pParent
, rResId
);
234 TabDialog::TabDialog( Window
* pParent
, const OString
& rID
, const OUString
& rUIXMLDescription
) :
235 Dialog(pParent
, rID
, rUIXMLDescription
, WINDOW_TABDIALOG
)
237 ImplInitTabDialogData();
240 // -----------------------------------------------------------------------
242 TabDialog::~TabDialog()
247 // -----------------------------------------------------------------------
249 void TabDialog::StateChanged( StateChangedType nType
)
251 if ( nType
== STATE_CHANGE_INITSHOW
)
253 // Calculate the Layout only for the initialized state
257 Dialog::StateChanged( nType
);
260 // -----------------------------------------------------------------------
262 void TabDialog::AdjustLayout()
264 SAL_WARN_IF(isLayoutEnabled(), "vcl.layout", "unnecessary to call TabDialog::AdjustLayout when layout enabled");
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */