Update ooo320-m1
[ooovba.git] / toolkit / source / layout / core / dialogbuttonhbox.cxx
blob047572335154d15954a2f8078bf0ffcbac21beb2
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$
11 * $Revision$
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include <awt/vclxbutton.hxx>
33 #include <tools/debug.hxx>
34 #include <toolkit/awt/vclxwindows.hxx>
35 #include <vcl/button.hxx>
37 #include "dialogbuttonhbox.hxx"
38 #include "flow.hxx"
39 #include "proplist.hxx"
41 #if TEST_LAYOUT && !defined( DBG_UTIL )
42 #undef DBG_ERROR
43 #define DBG_ERROR OSL_TRACE
44 #undef DBG_ERROR1
45 #define DBG_ERROR1 OSL_TRACE
46 #undef DBG_ERROR2
47 #define DBG_ERROR2 OSL_TRACE
48 #endif /* TEST_LAYOUT && !DBG_UTIL */
50 namespace layoutimpl
53 using namespace css;
55 //FIXME: how to set platform-dependant variables?
56 DialogButtonHBox::Ordering const DialogButtonHBox::DEFAULT_ORDERING =
57 #if defined( MACOSX )
58 DialogButtonHBox::MACOS;
59 #elif defined( SAL_W32 )
60 DialogButtonHBox::WINDOWS;
61 #elif defined( ENABLE_KDE )
62 DialogButtonHBox::KDE;
63 #else /* !MACOSX && !SAL_W32 && !ENABLE_KDE */
64 DialogButtonHBox::GNOME;
65 #endif /* !MACOSX && !SAL_W32 && !ENABLE_KDE */
67 DialogButtonHBox::DialogButtonHBox()
68 : HBox()
69 , mnOrdering( DEFAULT_ORDERING )
70 , mFlow()
71 , mpAction( 0 )
72 , mpAffirmative( 0 )
73 , mpAlternate( 0 )
74 , mpApply( 0 )
75 , mpCancel( 0 )
76 , mpFlow( createChild( uno::Reference< awt::XLayoutConstrains > ( &mFlow ) ) )
77 , mpHelp( 0 )
78 , mpReset( 0 )
80 mbHomogeneous = true;
83 void
84 DialogButtonHBox::setOrdering( rtl::OUString const& ordering )
86 if ( ordering.equalsIgnoreAsciiCaseAscii( "GNOME" ) )
87 mnOrdering = GNOME;
88 else if ( ordering.equalsIgnoreAsciiCaseAscii( "KDE" ) )
89 mnOrdering = KDE;
90 else if ( ordering.equalsIgnoreAsciiCaseAscii( "MacOS" ) )
91 mnOrdering = MACOS;
92 else if ( ordering.equalsIgnoreAsciiCaseAscii( "Windows" ) )
93 mnOrdering = WINDOWS;
94 else
96 DBG_ERROR1( "DialogButtonHBox: no such ordering: %s", OUSTRING_CSTR( ordering ) );
100 void
101 DialogButtonHBox::addChild( uno::Reference< awt::XLayoutConstrains > const& xChild )
102 throw ( uno::RuntimeException, awt::MaxChildrenException )
104 if ( !xChild.is() )
105 return;
107 ChildData *p = createChild( xChild );
109 #define IS_BUTTON(t) dynamic_cast<VCLX##t##Button *>( xChild.get () )
111 /* Sort Retry as Action */
112 if ( !mpAction && IS_BUTTON( Retry ) )
113 mpAction = p;
114 else if ( !mpAffirmative && IS_BUTTON( OK ) )
115 mpAffirmative = p;
116 else if ( !mpAffirmative && IS_BUTTON( Yes ) )
117 mpAffirmative = p;
118 else if ( !mpAlternate && IS_BUTTON( No ) )
119 mpAlternate = p;
120 /* Sort Ignore as Alternate */
121 else if ( !mpAlternate && IS_BUTTON( Ignore ) )
122 mpAlternate = p;
123 else if ( !mpApply && IS_BUTTON( Apply ) )
124 mpApply = p;
125 else if ( !mpCancel && IS_BUTTON( Cancel ) )
126 mpCancel = p;
127 /* Let the user overwrite Flow */
128 else if ( /* !mpFlow && */ dynamic_cast<Flow *>( xChild.get () ) )
129 mpFlow = p;
130 else if ( !mpHelp && IS_BUTTON( Help ) )
131 mpHelp = p;
132 else if ( !mpReset && IS_BUTTON( Reset ) )
133 mpReset = p;
134 else
135 maOther.push_back( p );
136 orderChildren();
137 setChildParent( xChild );
138 queueResize();
141 void
142 DialogButtonHBox::orderChildren()
144 if ( mnOrdering == WINDOWS )
145 windowsOrdering();
146 else if ( mnOrdering == MACOS )
147 macosOrdering();
148 else if ( mnOrdering == KDE )
149 kdeOrdering();
150 else if ( 1 || mnOrdering == GNOME )
151 gnomeOrdering();
154 void SAL_CALL
155 DialogButtonHBox::removeChild( uno::Reference< awt::XLayoutConstrains > const& xChild )
156 throw ( uno::RuntimeException)
158 if ( !xChild.is ())
159 return;
161 Box_Base::ChildData *p = 0;
163 if ( mpAction && mpAction->mxChild == xChild )
164 p = mpAction;
165 else if ( mpAffirmative && mpAffirmative->mxChild == xChild )
166 p = mpAffirmative;
167 else if ( mpAlternate && mpAlternate->mxChild == xChild )
168 p = mpAlternate;
169 else if ( mpApply && mpApply->mxChild == xChild )
170 p = mpApply;
171 else if ( mpCancel && mpCancel->mxChild == xChild )
172 p = mpCancel;
173 else if ( mpFlow && mpFlow->mxChild == xChild )
174 p = mpFlow;
175 else if ( mpReset && mpReset->mxChild == xChild )
176 p = mpReset;
177 else if ( mpHelp && mpHelp->mxChild == xChild )
178 p = mpHelp;
179 else
180 p = removeChildData( maOther, xChild );
182 if ( p )
184 delete p;
185 unsetChildParent( xChild );
186 orderChildren();
187 queueResize();
189 else
191 DBG_ERROR( "DialogButtonHBox: removeChild: no such child" );
195 void
196 DialogButtonHBox::gnomeOrdering()
198 std::list< Box_Base::ChildData * > ordered;
199 if ( mpHelp )
200 ordered.push_back( mpHelp );
201 if ( mpReset )
202 ordered.push_back( mpReset );
203 if ( mpFlow && ( mpHelp || mpReset ) )
204 ordered.push_back( mpFlow );
205 ordered.insert( ordered.end(), maOther.begin(), maOther.end() );
206 if ( mpAction )
207 ordered.push_back( mpAction );
208 if ( mpApply )
209 ordered.push_back( mpApply );
210 if ( mpAlternate )
211 ordered.push_back( mpAlternate );
212 if ( mpCancel )
213 ordered.push_back( mpCancel );
214 if ( mpAffirmative )
215 ordered.push_back( mpAffirmative );
216 maChildren = ordered;
219 void
220 DialogButtonHBox::kdeOrdering()
222 std::list< Box_Base::ChildData * > ordered;
223 if ( mpHelp )
224 ordered.push_back( mpHelp );
225 if ( mpReset )
226 ordered.push_back( mpReset );
227 if ( mpFlow && ( mpHelp || mpReset ) )
228 ordered.push_back( mpFlow );
229 ordered.insert( ordered.end(), maOther.begin(), maOther.end() );
230 if ( mpAction )
231 ordered.push_back( mpAction );
232 if ( mpAffirmative )
233 ordered.push_back( mpAffirmative );
234 if ( mpApply )
235 ordered.push_back( mpApply );
236 if ( mpAlternate )
237 ordered.push_back( mpAlternate );
238 if ( mpCancel )
239 ordered.push_back( mpCancel );
240 maChildren = ordered;
243 void
244 DialogButtonHBox::macosOrdering()
246 std::list< Box_Base::ChildData * > ordered;
247 if ( mpHelp )
248 ordered.push_back( mpHelp );
249 if ( mpReset )
250 ordered.push_back( mpReset );
251 if ( mpApply )
252 ordered.push_back( mpApply );
253 if ( mpAction )
254 ordered.push_back( mpAction );
255 ordered.insert( ordered.end(), maOther.begin(), maOther.end() );
256 if ( mpFlow ) // Always flow? && ( maOther.size () || mpHelp || mpReset || mpAction ) )
257 ordered.push_back( mpFlow );
258 if ( mpAlternate )
259 ordered.push_back( mpAlternate );
260 if ( mpFlow && mpAlternate )
261 ordered.push_back( mpFlow );
262 if ( mpCancel )
263 ordered.push_back( mpCancel );
264 if ( mpAffirmative )
265 ordered.push_back( mpAffirmative );
266 maChildren = ordered;
269 void
270 DialogButtonHBox::windowsOrdering()
272 std::list< Box_Base::ChildData * > ordered;
273 if ( mpReset )
274 ordered.push_back( mpReset );
275 if ( mpReset && mpFlow )
276 ordered.push_back( mpFlow );
277 if ( mpAffirmative )
278 ordered.push_back( mpAffirmative );
279 if ( mpAlternate )
280 ordered.push_back( mpAlternate );
281 if ( mpAction )
282 ordered.push_back( mpAction );
283 if ( mpCancel )
284 ordered.push_back( mpCancel );
285 if ( mpApply )
286 ordered.push_back( mpApply );
287 ordered.insert( ordered.end(), maOther.begin(), maOther.end() );
288 if ( mpHelp )
289 ordered.push_back( mpHelp );
290 maChildren = ordered;
293 } // namespace layoutimpl