xref: /AOO41X/main/toolkit/source/layout/core/dialogbuttonhbox.cxx (revision b0724fc6948542b2496e16ea247f985ee5987cfe)
1*b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b0724fc6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b0724fc6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b0724fc6SAndrew Rist  * distributed with this work for additional information
6*b0724fc6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b0724fc6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b0724fc6SAndrew Rist  * "License"); you may not use this file except in compliance
9*b0724fc6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*b0724fc6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*b0724fc6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b0724fc6SAndrew Rist  * software distributed under the License is distributed on an
15*b0724fc6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b0724fc6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b0724fc6SAndrew Rist  * specific language governing permissions and limitations
18*b0724fc6SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*b0724fc6SAndrew Rist  *************************************************************/
21*b0724fc6SAndrew Rist 
22*b0724fc6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <awt/vclxbutton.hxx>
25cdf0e10cSrcweir #include <tools/debug.hxx>
26cdf0e10cSrcweir #include <toolkit/awt/vclxwindows.hxx>
27cdf0e10cSrcweir #include <vcl/button.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "dialogbuttonhbox.hxx"
30cdf0e10cSrcweir #include "flow.hxx"
31cdf0e10cSrcweir #include "proplist.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #if TEST_LAYOUT && !defined( DBG_UTIL )
34cdf0e10cSrcweir #undef DBG_ERROR
35cdf0e10cSrcweir #define DBG_ERROR OSL_TRACE
36cdf0e10cSrcweir #undef DBG_ERROR1
37cdf0e10cSrcweir #define DBG_ERROR1 OSL_TRACE
38cdf0e10cSrcweir #undef DBG_ERROR2
39cdf0e10cSrcweir #define DBG_ERROR2 OSL_TRACE
40cdf0e10cSrcweir #endif /* TEST_LAYOUT && !DBG_UTIL */
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace layoutimpl
43cdf0e10cSrcweir {
44cdf0e10cSrcweir 
45cdf0e10cSrcweir using namespace css;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir //FIXME: how to set platform-dependant variables?
48cdf0e10cSrcweir DialogButtonHBox::Ordering const DialogButtonHBox::DEFAULT_ORDERING =
49cdf0e10cSrcweir #if defined( MACOSX )
50cdf0e10cSrcweir     DialogButtonHBox::MACOS;
51cdf0e10cSrcweir #elif defined( SAL_W32 )
52cdf0e10cSrcweir DialogButtonHBox::WINDOWS;
53cdf0e10cSrcweir #elif defined( ENABLE_KDE )
54cdf0e10cSrcweir DialogButtonHBox::KDE;
55cdf0e10cSrcweir #else /* !MACOSX && !SAL_W32 && !ENABLE_KDE */
56cdf0e10cSrcweir DialogButtonHBox::GNOME;
57cdf0e10cSrcweir #endif /* !MACOSX && !SAL_W32 && !ENABLE_KDE */
58cdf0e10cSrcweir 
DialogButtonHBox()59cdf0e10cSrcweir DialogButtonHBox::DialogButtonHBox()
60cdf0e10cSrcweir     : HBox()
61cdf0e10cSrcweir     , mnOrdering( DEFAULT_ORDERING )
62cdf0e10cSrcweir     , mFlow()
63cdf0e10cSrcweir     , mpAction( 0 )
64cdf0e10cSrcweir     , mpAffirmative( 0 )
65cdf0e10cSrcweir     , mpAlternate( 0 )
66cdf0e10cSrcweir     , mpApply( 0 )
67cdf0e10cSrcweir     , mpCancel( 0 )
68cdf0e10cSrcweir     , mpFlow( createChild( uno::Reference< awt::XLayoutConstrains > ( &mFlow ) ) )
69cdf0e10cSrcweir     , mpHelp( 0 )
70cdf0e10cSrcweir     , mpReset( 0 )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     mbHomogeneous = true;
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir void
setOrdering(rtl::OUString const & ordering)76cdf0e10cSrcweir DialogButtonHBox::setOrdering( rtl::OUString const& ordering )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir     if ( ordering.equalsIgnoreAsciiCaseAscii( "GNOME" ) )
79cdf0e10cSrcweir         mnOrdering = GNOME;
80cdf0e10cSrcweir     else if ( ordering.equalsIgnoreAsciiCaseAscii( "KDE" ) )
81cdf0e10cSrcweir         mnOrdering = KDE;
82cdf0e10cSrcweir     else if ( ordering.equalsIgnoreAsciiCaseAscii( "MacOS" ) )
83cdf0e10cSrcweir         mnOrdering = MACOS;
84cdf0e10cSrcweir     else if ( ordering.equalsIgnoreAsciiCaseAscii( "Windows" ) )
85cdf0e10cSrcweir         mnOrdering = WINDOWS;
86cdf0e10cSrcweir     else
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         DBG_ERROR1( "DialogButtonHBox: no such ordering: %s", OUSTRING_CSTR( ordering ) );
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir void
addChild(uno::Reference<awt::XLayoutConstrains> const & xChild)93cdf0e10cSrcweir DialogButtonHBox::addChild( uno::Reference< awt::XLayoutConstrains > const& xChild )
94cdf0e10cSrcweir     throw ( uno::RuntimeException, awt::MaxChildrenException )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir     if ( !xChild.is() )
97cdf0e10cSrcweir         return;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     ChildData *p = createChild( xChild );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir #define IS_BUTTON(t) dynamic_cast<VCLX##t##Button *>( xChild.get () )
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     /* Sort Retry as Action */
104cdf0e10cSrcweir     if ( !mpAction && IS_BUTTON( Retry ) )
105cdf0e10cSrcweir         mpAction = p;
106cdf0e10cSrcweir     else if ( !mpAffirmative && IS_BUTTON( OK ) )
107cdf0e10cSrcweir         mpAffirmative = p;
108cdf0e10cSrcweir     else if ( !mpAffirmative && IS_BUTTON( Yes ) )
109cdf0e10cSrcweir         mpAffirmative = p;
110cdf0e10cSrcweir     else if ( !mpAlternate && IS_BUTTON( No ) )
111cdf0e10cSrcweir         mpAlternate = p;
112cdf0e10cSrcweir     /* Sort Ignore as Alternate */
113cdf0e10cSrcweir     else if ( !mpAlternate && IS_BUTTON( Ignore ) )
114cdf0e10cSrcweir         mpAlternate = p;
115cdf0e10cSrcweir     else if ( !mpApply && IS_BUTTON( Apply ) )
116cdf0e10cSrcweir         mpApply = p;
117cdf0e10cSrcweir     else if ( !mpCancel && IS_BUTTON( Cancel ) )
118cdf0e10cSrcweir         mpCancel = p;
119cdf0e10cSrcweir     /* Let the user overwrite Flow */
120cdf0e10cSrcweir     else if ( /* !mpFlow && */ dynamic_cast<Flow *>( xChild.get () ) )
121cdf0e10cSrcweir         mpFlow = p;
122cdf0e10cSrcweir     else if ( !mpHelp && IS_BUTTON( Help ) )
123cdf0e10cSrcweir         mpHelp = p;
124cdf0e10cSrcweir     else if ( !mpReset && IS_BUTTON( Reset ) )
125cdf0e10cSrcweir         mpReset = p;
126cdf0e10cSrcweir     else
127cdf0e10cSrcweir         maOther.push_back( p );
128cdf0e10cSrcweir     orderChildren();
129cdf0e10cSrcweir     setChildParent( xChild );
130cdf0e10cSrcweir     queueResize();
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir void
orderChildren()134cdf0e10cSrcweir DialogButtonHBox::orderChildren()
135cdf0e10cSrcweir {
136cdf0e10cSrcweir     if ( mnOrdering == WINDOWS )
137cdf0e10cSrcweir         windowsOrdering();
138cdf0e10cSrcweir     else if ( mnOrdering == MACOS )
139cdf0e10cSrcweir         macosOrdering();
140cdf0e10cSrcweir     else if ( mnOrdering == KDE )
141cdf0e10cSrcweir         kdeOrdering();
142cdf0e10cSrcweir     else if ( 1 || mnOrdering == GNOME )
143cdf0e10cSrcweir         gnomeOrdering();
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir void SAL_CALL
removeChild(uno::Reference<awt::XLayoutConstrains> const & xChild)147cdf0e10cSrcweir DialogButtonHBox::removeChild( uno::Reference< awt::XLayoutConstrains > const& xChild )
148cdf0e10cSrcweir     throw ( uno::RuntimeException)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir     if ( !xChild.is ())
151cdf0e10cSrcweir         return;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     Box_Base::ChildData *p = 0;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     if ( mpAction && mpAction->mxChild == xChild )
156cdf0e10cSrcweir         p = mpAction;
157cdf0e10cSrcweir     else if ( mpAffirmative && mpAffirmative->mxChild == xChild )
158cdf0e10cSrcweir         p = mpAffirmative;
159cdf0e10cSrcweir     else if ( mpAlternate && mpAlternate->mxChild == xChild )
160cdf0e10cSrcweir         p = mpAlternate;
161cdf0e10cSrcweir     else if ( mpApply && mpApply->mxChild == xChild )
162cdf0e10cSrcweir         p = mpApply;
163cdf0e10cSrcweir     else if ( mpCancel && mpCancel->mxChild == xChild )
164cdf0e10cSrcweir         p = mpCancel;
165cdf0e10cSrcweir     else if ( mpFlow && mpFlow->mxChild == xChild )
166cdf0e10cSrcweir         p = mpFlow;
167cdf0e10cSrcweir     else if ( mpReset && mpReset->mxChild == xChild )
168cdf0e10cSrcweir         p = mpReset;
169cdf0e10cSrcweir     else if ( mpHelp && mpHelp->mxChild == xChild )
170cdf0e10cSrcweir         p = mpHelp;
171cdf0e10cSrcweir     else
172cdf0e10cSrcweir         p = removeChildData( maOther, xChild );
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     if ( p )
175cdf0e10cSrcweir     {
176cdf0e10cSrcweir         delete p;
177cdf0e10cSrcweir         unsetChildParent( xChild );
178cdf0e10cSrcweir         orderChildren();
179cdf0e10cSrcweir         queueResize();
180cdf0e10cSrcweir     }
181cdf0e10cSrcweir     else
182cdf0e10cSrcweir     {
183cdf0e10cSrcweir         DBG_ERROR( "DialogButtonHBox: removeChild: no such child" );
184cdf0e10cSrcweir     }
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir void
gnomeOrdering()188cdf0e10cSrcweir DialogButtonHBox::gnomeOrdering()
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     std::list< Box_Base::ChildData * > ordered;
191cdf0e10cSrcweir     if ( mpHelp )
192cdf0e10cSrcweir         ordered.push_back( mpHelp );
193cdf0e10cSrcweir     if ( mpReset )
194cdf0e10cSrcweir         ordered.push_back( mpReset );
195cdf0e10cSrcweir     if ( mpFlow && ( mpHelp || mpReset ) )
196cdf0e10cSrcweir         ordered.push_back( mpFlow );
197cdf0e10cSrcweir     ordered.insert( ordered.end(), maOther.begin(), maOther.end() );
198cdf0e10cSrcweir     if ( mpAction )
199cdf0e10cSrcweir         ordered.push_back( mpAction );
200cdf0e10cSrcweir     if ( mpApply )
201cdf0e10cSrcweir         ordered.push_back( mpApply );
202cdf0e10cSrcweir     if ( mpAlternate )
203cdf0e10cSrcweir         ordered.push_back( mpAlternate );
204cdf0e10cSrcweir     if ( mpCancel )
205cdf0e10cSrcweir         ordered.push_back( mpCancel );
206cdf0e10cSrcweir     if ( mpAffirmative )
207cdf0e10cSrcweir         ordered.push_back( mpAffirmative );
208cdf0e10cSrcweir     maChildren = ordered;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir void
kdeOrdering()212cdf0e10cSrcweir DialogButtonHBox::kdeOrdering()
213cdf0e10cSrcweir {
214cdf0e10cSrcweir     std::list< Box_Base::ChildData * > ordered;
215cdf0e10cSrcweir     if ( mpHelp )
216cdf0e10cSrcweir         ordered.push_back( mpHelp );
217cdf0e10cSrcweir     if ( mpReset )
218cdf0e10cSrcweir         ordered.push_back( mpReset );
219cdf0e10cSrcweir     if ( mpFlow && ( mpHelp || mpReset ) )
220cdf0e10cSrcweir         ordered.push_back( mpFlow );
221cdf0e10cSrcweir     ordered.insert( ordered.end(), maOther.begin(), maOther.end() );
222cdf0e10cSrcweir     if ( mpAction )
223cdf0e10cSrcweir         ordered.push_back( mpAction );
224cdf0e10cSrcweir     if ( mpAffirmative )
225cdf0e10cSrcweir         ordered.push_back( mpAffirmative );
226cdf0e10cSrcweir     if ( mpApply )
227cdf0e10cSrcweir         ordered.push_back( mpApply );
228cdf0e10cSrcweir     if ( mpAlternate )
229cdf0e10cSrcweir         ordered.push_back( mpAlternate );
230cdf0e10cSrcweir     if ( mpCancel )
231cdf0e10cSrcweir         ordered.push_back( mpCancel );
232cdf0e10cSrcweir     maChildren = ordered;
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir void
macosOrdering()236cdf0e10cSrcweir DialogButtonHBox::macosOrdering()
237cdf0e10cSrcweir {
238cdf0e10cSrcweir     std::list< Box_Base::ChildData * > ordered;
239cdf0e10cSrcweir     if ( mpHelp )
240cdf0e10cSrcweir         ordered.push_back( mpHelp );
241cdf0e10cSrcweir     if ( mpReset )
242cdf0e10cSrcweir         ordered.push_back( mpReset );
243cdf0e10cSrcweir     if ( mpApply )
244cdf0e10cSrcweir         ordered.push_back( mpApply );
245cdf0e10cSrcweir     if ( mpAction )
246cdf0e10cSrcweir         ordered.push_back( mpAction );
247cdf0e10cSrcweir     ordered.insert( ordered.end(), maOther.begin(), maOther.end() );
248cdf0e10cSrcweir     if ( mpFlow ) // Always flow? && ( maOther.size () || mpHelp || mpReset || mpAction ) )
249cdf0e10cSrcweir         ordered.push_back( mpFlow );
250cdf0e10cSrcweir     if ( mpAlternate )
251cdf0e10cSrcweir         ordered.push_back( mpAlternate );
252cdf0e10cSrcweir     if ( mpFlow && mpAlternate )
253cdf0e10cSrcweir         ordered.push_back( mpFlow );
254cdf0e10cSrcweir     if ( mpCancel )
255cdf0e10cSrcweir         ordered.push_back( mpCancel );
256cdf0e10cSrcweir     if ( mpAffirmative )
257cdf0e10cSrcweir         ordered.push_back( mpAffirmative );
258cdf0e10cSrcweir     maChildren = ordered;
259cdf0e10cSrcweir }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir void
windowsOrdering()262cdf0e10cSrcweir DialogButtonHBox::windowsOrdering()
263cdf0e10cSrcweir {
264cdf0e10cSrcweir     std::list< Box_Base::ChildData * > ordered;
265cdf0e10cSrcweir     if ( mpReset )
266cdf0e10cSrcweir         ordered.push_back( mpReset );
267cdf0e10cSrcweir     if ( mpReset && mpFlow )
268cdf0e10cSrcweir         ordered.push_back( mpFlow );
269cdf0e10cSrcweir     if ( mpAffirmative )
270cdf0e10cSrcweir         ordered.push_back( mpAffirmative );
271cdf0e10cSrcweir     if ( mpAlternate )
272cdf0e10cSrcweir         ordered.push_back( mpAlternate );
273cdf0e10cSrcweir     if ( mpAction )
274cdf0e10cSrcweir         ordered.push_back( mpAction );
275cdf0e10cSrcweir     if ( mpCancel )
276cdf0e10cSrcweir         ordered.push_back( mpCancel );
277cdf0e10cSrcweir     if ( mpApply )
278cdf0e10cSrcweir         ordered.push_back( mpApply );
279cdf0e10cSrcweir     ordered.insert( ordered.end(), maOther.begin(), maOther.end() );
280cdf0e10cSrcweir     if ( mpHelp )
281cdf0e10cSrcweir         ordered.push_back( mpHelp );
282cdf0e10cSrcweir     maChildren = ordered;
283cdf0e10cSrcweir }
284cdf0e10cSrcweir 
285cdf0e10cSrcweir } // namespace layoutimpl
286