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>
26 void TabDialog::ImplInitTabDialogData()
30 meViewAlign
= WINDOWALIGN_LEFT
;
34 void TabDialog::ImplPosControls()
36 if (isLayoutEnabled())
39 Size
aCtrlSize( IMPL_MINSIZE_BUTTON_WIDTH
, IMPL_MINSIZE_BUTTON_HEIGHT
);
42 vcl::Window
* pTabControl
= NULL
;
44 vcl::Window
* pChild
= GetWindow( GetWindowType::FirstChild
);
47 if ( pChild
->IsVisible() && (pChild
!= mpViewWindow
) )
49 if (pChild
->GetType() == WINDOW_TABCONTROL
|| isContainerWindow(*pChild
))
51 else if ( pTabControl
)
53 Size
aOptimalSize(pChild
->get_preferred_size());
54 long nTxtWidth
= aOptimalSize
.Width();
55 if ( nTxtWidth
> aCtrlSize
.Width() )
56 aCtrlSize
.Width() = nTxtWidth
;
57 long nTxtHeight
= aOptimalSize
.Height();
58 if ( nTxtHeight
> aCtrlSize
.Height() )
59 aCtrlSize
.Height() = nTxtHeight
;
64 long nHeight
= pChild
->GetSizePixel().Height();
65 if ( nHeight
> nOffY
)
70 pChild
= pChild
->GetWindow( GetWindowType::Next
);
73 // do we have a TabControl ?
76 // adapt offset for other controls by an extra distance
78 nOffY
+= IMPL_DIALOG_BAR_OFFSET
*2 + 2;
80 Point
aTabOffset( IMPL_DIALOG_OFFSET
, IMPL_DIALOG_OFFSET
+nOffY
);
82 if (isContainerWindow(*pTabControl
))
83 pTabControl
->SetSizePixel(pTabControl
->get_preferred_size());
85 Size aTabSize
= pTabControl
->GetSizePixel();
87 Size
aDlgSize( aTabSize
.Width() + IMPL_DIALOG_OFFSET
*2,
88 aTabSize
.Height() + IMPL_DIALOG_OFFSET
*2 + nOffY
);
91 // consider Preview-Fenster and adapt the sizes/offsets
92 if ( mpViewWindow
&& mpViewWindow
->IsVisible() )
98 PosSizeFlags nViewPosFlags
= PosSizeFlags::Pos
;
99 Size aViewSize
= mpViewWindow
->GetSizePixel();
100 if ( meViewAlign
== WINDOWALIGN_TOP
)
102 nViewOffX
= aTabOffset
.X();
103 nViewOffY
= nOffY
+IMPL_DIALOG_OFFSET
;
104 nViewWidth
= aTabSize
.Width();
105 nViewPosFlags
|= PosSizeFlags::Width
;
106 aTabOffset
.Y() += aViewSize
.Height()+IMPL_DIALOG_OFFSET
;
107 aDlgSize
.Height() += aViewSize
.Height()+IMPL_DIALOG_OFFSET
;
109 else if ( meViewAlign
== WINDOWALIGN_BOTTOM
)
111 nViewOffX
= aTabOffset
.X();
112 nViewOffY
= aTabOffset
.Y()+aTabSize
.Height()+IMPL_DIALOG_OFFSET
;
113 nViewWidth
= aTabSize
.Width();
114 nViewPosFlags
|= PosSizeFlags::Width
;
115 aDlgSize
.Height() += aViewSize
.Height()+IMPL_DIALOG_OFFSET
;
117 else if ( meViewAlign
== WINDOWALIGN_RIGHT
)
119 nViewOffX
= aTabOffset
.X()+aTabSize
.Width()+IMPL_DIALOG_OFFSET
;
120 nViewOffY
= aTabOffset
.Y();
121 nViewHeight
= aTabSize
.Height();
122 nViewPosFlags
|= PosSizeFlags::Height
;
123 aDlgSize
.Width() += aViewSize
.Width()+IMPL_DIALOG_OFFSET
;
124 nBtnEx
= aViewSize
.Width()+IMPL_DIALOG_OFFSET
;
126 else // meViewAlign == WINDOWALIGN_LEFT
128 nViewOffX
= IMPL_DIALOG_OFFSET
;
129 nViewOffY
= aTabOffset
.Y();
130 nViewHeight
= aTabSize
.Height();
131 nViewPosFlags
|= PosSizeFlags::Height
;
132 aTabOffset
.X() += aViewSize
.Width()+IMPL_DIALOG_OFFSET
;
133 aDlgSize
.Width() += aViewSize
.Width()+IMPL_DIALOG_OFFSET
;
134 nBtnEx
= aViewSize
.Width()+IMPL_DIALOG_OFFSET
;
137 mpViewWindow
->setPosSizePixel( nViewOffX
, nViewOffY
,
138 nViewWidth
, nViewHeight
,
143 pTabControl
->SetPosPixel( aTabOffset
);
145 // position all other Children
146 bool bTabCtrl
= false;
149 long nY
= aDlgSize
.Height();
150 long nTopX
= IMPL_DIALOG_OFFSET
;
152 // all buttons are right aligned under Windows 95
153 nX
= IMPL_DIALOG_OFFSET
;
154 long nCtrlBarWidth
= ((aCtrlSize
.Width()+IMPL_DIALOG_OFFSET
)*nDownCtrl
)-IMPL_DIALOG_OFFSET
;
155 if ( nCtrlBarWidth
<= (aTabSize
.Width()+nBtnEx
) )
156 nX
= (aTabSize
.Width()+nBtnEx
) - nCtrlBarWidth
+ IMPL_DIALOG_OFFSET
;
158 vcl::Window
* pChild2
= GetWindow( GetWindowType::FirstChild
);
161 if ( pChild2
->IsVisible() && (pChild2
!= mpViewWindow
) )
163 if ( pChild2
== pTabControl
)
170 if ( nX
+aCtrlSize
.Width()-IMPL_DIALOG_OFFSET
> (aTabSize
.Width()+nBtnEx
) )
172 nY
+= aCtrlSize
.Height()+IMPL_DIALOG_OFFSET
;
173 nX
= IMPL_DIALOG_OFFSET
;
177 pChild2
->SetPosSizePixel( Point( nX
, nY
), aCtrlSize
);
178 nX
+= aCtrlSize
.Width()+IMPL_DIALOG_OFFSET
;
182 Size aChildSize
= pChild2
->GetSizePixel();
183 pChild2
->SetPosPixel( Point( nTopX
, (nOffY
-aChildSize
.Height())/2 ) );
184 nTopX
+= aChildSize
.Width()+2;
188 pChild2
= pChild2
->GetWindow( GetWindowType::Next
);
191 aDlgSize
.Height() += nLines
* (aCtrlSize
.Height()+IMPL_DIALOG_OFFSET
);
192 SetOutputSizePixel( aDlgSize
);
198 Size aDlgSize
= GetOutputSizePixel();
200 mpFixedLine
= VclPtr
<FixedLine
>::Create( this );
201 mpFixedLine
->SetPosSizePixel( Point( 0, nOffY
),
202 Size( aDlgSize
.Width(), 2 ) );
206 mbPosControls
= false;
209 TabDialog::TabDialog( vcl::Window
* pParent
, WinBits nStyle
) :
210 Dialog( WINDOW_TABDIALOG
)
212 ImplInitTabDialogData();
213 ImplInit( pParent
, nStyle
);
216 TabDialog::TabDialog( vcl::Window
* pParent
, const OUString
& rID
, const OUString
& rUIXMLDescription
) :
217 Dialog(pParent
, rID
, rUIXMLDescription
, WINDOW_TABDIALOG
)
219 ImplInitTabDialogData();
222 TabDialog::~TabDialog()
227 void TabDialog::dispose()
229 mpFixedLine
.disposeAndClear();
230 mpViewWindow
.clear();
234 void TabDialog::StateChanged( StateChangedType nType
)
236 if ( nType
== StateChangedType::InitShow
)
238 // Calculate the Layout only for the initialized state
242 Dialog::StateChanged( nType
);
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */