1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
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"
39 #include "proplist.hxx"
41 #if TEST_LAYOUT && !defined( DBG_UTIL )
43 #define DBG_ERROR OSL_TRACE
45 #define DBG_ERROR1 OSL_TRACE
47 #define DBG_ERROR2 OSL_TRACE
48 #endif /* TEST_LAYOUT && !DBG_UTIL */
55 //FIXME: how to set platform-dependant variables?
56 DialogButtonHBox::Ordering
const DialogButtonHBox::DEFAULT_ORDERING
=
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()
69 , mnOrdering( DEFAULT_ORDERING
)
76 , mpFlow( createChild( uno::Reference
< awt::XLayoutConstrains
> ( &mFlow
) ) )
84 DialogButtonHBox::setOrdering( rtl::OUString
const& ordering
)
86 if ( ordering
.equalsIgnoreAsciiCaseAscii( "GNOME" ) )
88 else if ( ordering
.equalsIgnoreAsciiCaseAscii( "KDE" ) )
90 else if ( ordering
.equalsIgnoreAsciiCaseAscii( "MacOS" ) )
92 else if ( ordering
.equalsIgnoreAsciiCaseAscii( "Windows" ) )
96 DBG_ERROR1( "DialogButtonHBox: no such ordering: %s", OUSTRING_CSTR( ordering
) );
101 DialogButtonHBox::addChild( uno::Reference
< awt::XLayoutConstrains
> const& xChild
)
102 throw ( uno::RuntimeException
, awt::MaxChildrenException
)
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
) )
114 else if ( !mpAffirmative
&& IS_BUTTON( OK
) )
116 else if ( !mpAffirmative
&& IS_BUTTON( Yes
) )
118 else if ( !mpAlternate
&& IS_BUTTON( No
) )
120 /* Sort Ignore as Alternate */
121 else if ( !mpAlternate
&& IS_BUTTON( Ignore
) )
123 else if ( !mpApply
&& IS_BUTTON( Apply
) )
125 else if ( !mpCancel
&& IS_BUTTON( Cancel
) )
127 /* Let the user overwrite Flow */
128 else if ( /* !mpFlow && */ dynamic_cast<Flow
*>( xChild
.get () ) )
130 else if ( !mpHelp
&& IS_BUTTON( Help
) )
132 else if ( !mpReset
&& IS_BUTTON( Reset
) )
135 maOther
.push_back( p
);
137 setChildParent( xChild
);
142 DialogButtonHBox::orderChildren()
144 if ( mnOrdering
== WINDOWS
)
146 else if ( mnOrdering
== MACOS
)
148 else if ( mnOrdering
== KDE
)
150 else if ( 1 || mnOrdering
== GNOME
)
155 DialogButtonHBox::removeChild( uno::Reference
< awt::XLayoutConstrains
> const& xChild
)
156 throw ( uno::RuntimeException
)
161 Box_Base::ChildData
*p
= 0;
163 if ( mpAction
&& mpAction
->mxChild
== xChild
)
165 else if ( mpAffirmative
&& mpAffirmative
->mxChild
== xChild
)
167 else if ( mpAlternate
&& mpAlternate
->mxChild
== xChild
)
169 else if ( mpApply
&& mpApply
->mxChild
== xChild
)
171 else if ( mpCancel
&& mpCancel
->mxChild
== xChild
)
173 else if ( mpFlow
&& mpFlow
->mxChild
== xChild
)
175 else if ( mpReset
&& mpReset
->mxChild
== xChild
)
177 else if ( mpHelp
&& mpHelp
->mxChild
== xChild
)
180 p
= removeChildData( maOther
, xChild
);
185 unsetChildParent( xChild
);
191 DBG_ERROR( "DialogButtonHBox: removeChild: no such child" );
196 DialogButtonHBox::gnomeOrdering()
198 std::list
< Box_Base::ChildData
* > ordered
;
200 ordered
.push_back( mpHelp
);
202 ordered
.push_back( mpReset
);
203 if ( mpFlow
&& ( mpHelp
|| mpReset
) )
204 ordered
.push_back( mpFlow
);
205 ordered
.insert( ordered
.end(), maOther
.begin(), maOther
.end() );
207 ordered
.push_back( mpAction
);
209 ordered
.push_back( mpApply
);
211 ordered
.push_back( mpAlternate
);
213 ordered
.push_back( mpCancel
);
215 ordered
.push_back( mpAffirmative
);
216 maChildren
= ordered
;
220 DialogButtonHBox::kdeOrdering()
222 std::list
< Box_Base::ChildData
* > ordered
;
224 ordered
.push_back( mpHelp
);
226 ordered
.push_back( mpReset
);
227 if ( mpFlow
&& ( mpHelp
|| mpReset
) )
228 ordered
.push_back( mpFlow
);
229 ordered
.insert( ordered
.end(), maOther
.begin(), maOther
.end() );
231 ordered
.push_back( mpAction
);
233 ordered
.push_back( mpAffirmative
);
235 ordered
.push_back( mpApply
);
237 ordered
.push_back( mpAlternate
);
239 ordered
.push_back( mpCancel
);
240 maChildren
= ordered
;
244 DialogButtonHBox::macosOrdering()
246 std::list
< Box_Base::ChildData
* > ordered
;
248 ordered
.push_back( mpHelp
);
250 ordered
.push_back( mpReset
);
252 ordered
.push_back( mpApply
);
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
);
259 ordered
.push_back( mpAlternate
);
260 if ( mpFlow
&& mpAlternate
)
261 ordered
.push_back( mpFlow
);
263 ordered
.push_back( mpCancel
);
265 ordered
.push_back( mpAffirmative
);
266 maChildren
= ordered
;
270 DialogButtonHBox::windowsOrdering()
272 std::list
< Box_Base::ChildData
* > ordered
;
274 ordered
.push_back( mpReset
);
275 if ( mpReset
&& mpFlow
)
276 ordered
.push_back( mpFlow
);
278 ordered
.push_back( mpAffirmative
);
280 ordered
.push_back( mpAlternate
);
282 ordered
.push_back( mpAction
);
284 ordered
.push_back( mpCancel
);
286 ordered
.push_back( mpApply
);
287 ordered
.insert( ordered
.end(), maOther
.begin(), maOther
.end() );
289 ordered
.push_back( mpHelp
);
290 maChildren
= ordered
;
293 } // namespace layoutimpl