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