Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #include "taskpane/TitledControl.hxx"
22 : :
23 : : #include "AccessibleTreeNode.hxx"
24 : : #include "taskpane/ControlContainer.hxx"
25 : : #include "TaskPaneFocusManager.hxx"
26 : : #include "taskpane/TaskPaneControlFactory.hxx"
27 : : #include <vcl/ctrl.hxx>
28 : : #include <vcl/svapp.hxx>
29 : :
30 : :
31 : : namespace sd { namespace toolpanel {
32 : :
33 : :
34 : 0 : TitledControl::TitledControl (
35 : : TreeNode* pParent,
36 : : ::std::auto_ptr<TreeNode> pControl,
37 : : const String& rTitle,
38 : : const ClickHandler& rClickHandler,
39 : : TitleBar::TitleBarType eType)
40 : 0 : : ::Window (pParent->GetWindow(), WB_TABSTOP),
41 : : TreeNode(pParent),
42 : : msTitle(rTitle),
43 : : mbVisible(true),
44 : : mpUserData(NULL),
45 [ # # ][ # # ]: 0 : mpClickHandler(new ClickHandler(rClickHandler))
[ # # ][ # # ]
46 : : {
47 : : mpControlContainer->AddControl (::std::auto_ptr<TreeNode> (
48 [ # # ][ # # ]: 0 : new TitleBar (this, rTitle, eType, pControl->IsExpandable())));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
49 [ # # ]: 0 : pControl->SetParentNode (this);
50 [ # # ][ # # ]: 0 : mpControlContainer->AddControl (pControl);
51 : :
52 [ # # ][ # # ]: 0 : FocusManager::Instance().RegisterDownLink( GetTitleBar()->GetWindow(), GetControl()->GetWindow() );
[ # # ][ # # ]
[ # # ][ # # ]
53 [ # # ][ # # ]: 0 : FocusManager::Instance().RegisterUpLink( GetControl()->GetWindow(), GetTitleBar()->GetWindow() );
[ # # ][ # # ]
[ # # ][ # # ]
54 : :
55 [ # # ][ # # ]: 0 : SetBackground (Wallpaper());
[ # # ]
56 : :
57 [ # # ][ # # ]: 0 : GetTitleBar()->GetWindow()->Show ();
[ # # ]
58 [ # # ]: 0 : GetTitleBar()->GetWindow()->AddEventListener (
59 [ # # ][ # # ]: 0 : LINK(this,TitledControl,WindowEventListener));
[ # # ]
60 : :
61 [ # # ]: 0 : UpdateStates ();
62 : 0 : }
63 : :
64 : :
65 : :
66 : :
67 [ # # ][ # # ]: 0 : TitledControl::~TitledControl (void)
[ # # ]
68 : : {
69 [ # # ]: 0 : GetTitleBar()->GetWindow()->RemoveEventListener (
70 [ # # ][ # # ]: 0 : LINK(this,TitledControl,WindowEventListener));
[ # # ]
71 [ # # ]: 0 : }
72 : :
73 : :
74 : :
75 : :
76 : 0 : Size TitledControl::GetPreferredSize (void)
77 : : {
78 : 0 : Size aPreferredSize;
79 [ # # ]: 0 : if (GetControl() != NULL)
80 : : {
81 : 0 : aPreferredSize = GetControl()->GetPreferredSize();
82 [ # # ]: 0 : if ( ! IsExpanded())
83 : 0 : aPreferredSize.Height() = 0;
84 : : }
85 : : else
86 : 0 : aPreferredSize = Size (GetSizePixel().Width(), 0);
87 [ # # ]: 0 : if (aPreferredSize.Width() == 0)
88 : 0 : aPreferredSize.Width() = 300;
89 : 0 : aPreferredSize.Height() += GetTitleBar()->GetPreferredHeight(
90 : 0 : aPreferredSize.Width());
91 : :
92 : 0 : return aPreferredSize;
93 : : }
94 : :
95 : :
96 : :
97 : :
98 : 0 : sal_Int32 TitledControl::GetPreferredWidth (sal_Int32 nHeight)
99 : : {
100 : 0 : int nPreferredWidth = 0;
101 [ # # ]: 0 : if (GetControl() != NULL)
102 : 0 : nPreferredWidth = GetControl()->GetPreferredWidth(
103 [ # # ]: 0 : nHeight - GetTitleBar()->GetWindow()->GetSizePixel().Height());
104 : : else
105 : 0 : nPreferredWidth = GetSizePixel().Width();
106 [ # # ]: 0 : if (nPreferredWidth == 0)
107 : 0 : nPreferredWidth = 300;
108 : :
109 : 0 : return nPreferredWidth;
110 : : }
111 : :
112 : :
113 : :
114 : :
115 : 0 : sal_Int32 TitledControl::GetPreferredHeight (sal_Int32 nWidth)
116 : : {
117 : 0 : int nPreferredHeight = 0;
118 [ # # ][ # # ]: 0 : if (IsExpanded() && GetControl()!=NULL)
[ # # ]
119 : 0 : nPreferredHeight = GetControl()->GetPreferredHeight(nWidth);
120 : 0 : nPreferredHeight += GetTitleBar()->GetPreferredHeight(nWidth);
121 : :
122 : 0 : return nPreferredHeight;
123 : : }
124 : :
125 : :
126 : :
127 : :
128 : 0 : bool TitledControl::IsResizable (void)
129 : : {
130 : 0 : return IsExpanded()
131 [ # # ][ # # ]: 0 : && GetControl()->IsResizable();
132 : : }
133 : :
134 : :
135 : :
136 : :
137 : 0 : ::Window* TitledControl::GetWindow (void)
138 : : {
139 : 0 : return this;
140 : : }
141 : :
142 : :
143 : :
144 : :
145 : 0 : void TitledControl::Resize (void)
146 : : {
147 : 0 : Size aWindowSize (GetOutputSizePixel());
148 : :
149 : : int nTitleBarHeight
150 [ # # ][ # # ]: 0 : = GetTitleBar()->GetPreferredHeight(aWindowSize.Width());
151 [ # # ][ # # ]: 0 : GetTitleBar()->GetWindow()->SetPosSizePixel (
152 : : Point (0,0),
153 [ # # ]: 0 : Size (aWindowSize.Width(), nTitleBarHeight));
154 : :
155 : :
156 [ # # ]: 0 : TreeNode* pControl = GetControl();
157 [ # # ][ # # ]: 0 : if (pControl != NULL
[ # # ][ # # ]
158 [ # # ]: 0 : && pControl->GetWindow() != NULL
159 [ # # ][ # # ]: 0 : && pControl->GetWindow()->IsVisible())
160 : : {
161 [ # # ]: 0 : pControl->GetWindow()->SetPosSizePixel (
162 : : Point (0,nTitleBarHeight),
163 [ # # ]: 0 : Size (aWindowSize.Width(), aWindowSize.Height()-nTitleBarHeight));
164 : : }
165 : 0 : }
166 : :
167 : :
168 : :
169 : :
170 : 0 : void TitledControl::GetFocus (void)
171 : : {
172 : 0 : ::Window::GetFocus();
173 [ # # ]: 0 : if (GetTitleBar() != NULL)
174 : 0 : GetTitleBar()->GrabFocus();
175 : 0 : }
176 : :
177 : :
178 : :
179 : :
180 : 0 : void TitledControl::KeyInput (const KeyEvent& rEvent)
181 : : {
182 : 0 : KeyCode nCode = rEvent.GetKeyCode();
183 [ # # ][ # # ]: 0 : if (nCode == KEY_SPACE)
184 : : {
185 : : // Toggle the expansion state of the control (when toggling is
186 : : // supported.) The focus remains on this control.
187 [ # # ][ # # ]: 0 : GetParentNode()->GetControlContainer().SetExpansionState (
188 : : this,
189 [ # # ]: 0 : ControlContainer::ES_TOGGLE);
190 : : }
191 [ # # ][ # # ]: 0 : else if (nCode == KEY_RETURN)
192 : : {
193 : : // Return, also called enter, enters the control and puts the
194 : : // focus to the first child. If the control is not yet
195 : : // expanded then do that first.
196 [ # # ][ # # ]: 0 : GetParentNode()->GetControlContainer().SetExpansionState (
197 : : this,
198 [ # # ]: 0 : ControlContainer::ES_EXPAND);
199 : :
200 [ # # ][ # # ]: 0 : if ( ! FocusManager::Instance().TransferFocus(this,nCode))
[ # # ]
201 : : {
202 : : // When already expanded then put focus on first child.
203 [ # # ]: 0 : TreeNode* pControl = GetControl();
204 [ # # ][ # # ]: 0 : if (pControl!=NULL && IsExpanded())
[ # # ][ # # ]
205 [ # # ][ # # ]: 0 : if (pControl->GetWindow() != NULL)
206 [ # # ][ # # ]: 0 : pControl->GetWindow()->GrabFocus();
207 : : }
208 : : }
209 [ # # ][ # # ]: 0 : else if (nCode == KEY_ESCAPE)
210 : : {
211 [ # # ][ # # ]: 0 : if ( ! FocusManager::Instance().TransferFocus(this,nCode))
[ # # ]
212 : : // Put focus to parent.
213 [ # # ][ # # ]: 0 : GetParent()->GrabFocus();
214 : : }
215 : : else
216 [ # # ]: 0 : Window::KeyInput (rEvent);
217 : 0 : }
218 : :
219 : :
220 : :
221 : :
222 : 0 : const String& TitledControl::GetTitle (void) const
223 : : {
224 : 0 : return msTitle;
225 : : }
226 : :
227 : :
228 : :
229 : :
230 : 0 : bool TitledControl::Expand (bool bExpanded)
231 : : {
232 : 0 : bool bExpansionStateChanged (false);
233 : :
234 [ # # ][ # # ]: 0 : if (IsExpandable() && IsEnabled())
[ # # ]
235 : : {
236 [ # # ]: 0 : if (GetTitleBar()->IsExpanded() != bExpanded)
237 : 0 : bExpansionStateChanged |= GetTitleBar()->Expand (bExpanded);
238 : : // Get the control. Use the bExpanded parameter as argument to
239 : : // indicate that a control is created via its factory only when it
240 : : // is to be expanded. When it is collapsed this is not necessary.
241 : 0 : TreeNode* pControl = GetControl();
242 [ # # ]: 0 : if (pControl != NULL
[ # # # # ]
243 : 0 : && GetControl()->IsExpanded() != bExpanded)
244 : : {
245 : 0 : bExpansionStateChanged |= pControl->Expand (bExpanded);
246 : : }
247 [ # # ]: 0 : if (bExpansionStateChanged)
248 : 0 : UpdateStates();
249 : : }
250 : :
251 : 0 : return bExpansionStateChanged;
252 : : }
253 : :
254 : :
255 : :
256 : :
257 : 0 : bool TitledControl::IsExpandable (void) const
258 : : {
259 : 0 : const TreeNode* pControl = GetConstControl();
260 [ # # ]: 0 : if (pControl != NULL)
261 : 0 : return pControl->IsExpandable();
262 : : else
263 : : // When a control factory is given but the control has not yet been
264 : : // created we assume that the control is expandable.
265 : 0 : return true;
266 : : }
267 : :
268 : :
269 : :
270 : :
271 : 0 : bool TitledControl::IsExpanded (void) const
272 : : {
273 : 0 : const TreeNode* pControl = GetConstControl();
274 [ # # ]: 0 : if (pControl != NULL)
275 : 0 : return pControl->IsExpanded();
276 : : else
277 : 0 : return false;
278 : : }
279 : :
280 : 0 : void TitledControl::SetEnabledState(bool bFlag)
281 : : {
282 [ # # ]: 0 : if (!bFlag)
283 : : {
284 : 0 : GetParentNode()->GetControlContainer().SetExpansionState (
285 : : this,
286 : 0 : ControlContainer::ES_COLLAPSE);
287 : 0 : Disable();
288 : : }
289 : : else
290 : : {
291 : 0 : Enable();
292 : : }
293 : :
294 : 0 : GetTitleBar()->SetEnabledState(bFlag);
295 : 0 : }
296 : :
297 : :
298 : :
299 : 0 : bool TitledControl::IsShowing (void) const
300 : : {
301 : 0 : return mbVisible;
302 : : }
303 : :
304 : :
305 : :
306 : :
307 : 0 : void TitledControl::Show (bool bVisible)
308 : : {
309 [ # # ]: 0 : if (mbVisible != bVisible)
310 : : {
311 : 0 : mbVisible = bVisible;
312 : 0 : UpdateStates ();
313 : : }
314 : 0 : }
315 : :
316 : :
317 : :
318 : :
319 : 0 : void TitledControl::UpdateStates (void)
320 : : {
321 [ # # ]: 0 : if (mbVisible)
322 : 0 : GetWindow()->Show();
323 : : else
324 : 0 : GetWindow()->Hide();
325 : :
326 : 0 : TreeNode* pControl = GetControl();
327 [ # # ][ # # ]: 0 : if (pControl!=NULL && pControl->GetWindow() != NULL)
[ # # ]
328 : : {
329 [ # # ][ # # ]: 0 : if (IsVisible() && IsExpanded())
[ # # ]
330 : 0 : pControl->GetWindow()->Show();
331 : : else
332 : 0 : pControl->GetWindow()->Hide();
333 : : }
334 : 0 : }
335 : :
336 : :
337 : :
338 : :
339 : 0 : IMPL_LINK(TitledControl, WindowEventListener,
340 : : VclSimpleEvent*, pEvent)
341 : : {
342 [ # # ][ # # ]: 0 : if (pEvent!=NULL && pEvent->ISA(VclWindowEvent))
[ # # ]
343 : : {
344 : 0 : VclWindowEvent* pWindowEvent = static_cast<VclWindowEvent*>(pEvent);
345 [ # # ]: 0 : switch (pWindowEvent->GetId())
346 : : {
347 : : case VCLEVENT_WINDOW_MOUSEBUTTONUP:
348 [ # # ]: 0 : if (IsEnabled())
349 : 0 : (*mpClickHandler)(*this);
350 : 0 : break;
351 : : }
352 : : }
353 : 0 : return 0;
354 : : }
355 : :
356 : :
357 : :
358 : :
359 : 0 : TreeNode* TitledControl::GetControl (void)
360 : : {
361 : 0 : return mpControlContainer->GetControl(1);
362 : : }
363 : :
364 : :
365 : :
366 : :
367 : 0 : const TreeNode* TitledControl::GetConstControl () const
368 : : {
369 : 0 : return const_cast<TitledControl*>(this)->GetControl();
370 : : }
371 : :
372 : :
373 : :
374 : :
375 : 0 : TitleBar* TitledControl::GetTitleBar (void)
376 : : {
377 [ # # ]: 0 : return static_cast<TitleBar*>(mpControlContainer->GetControl(0));
378 : : }
379 : :
380 : :
381 : :
382 : :
383 : : ::com::sun::star::uno::Reference<
384 : 0 : ::com::sun::star::accessibility::XAccessible> TitledControl::CreateAccessibleObject (
385 : : const ::com::sun::star::uno::Reference<
386 : : ::com::sun::star::accessibility::XAccessible>& )
387 : : {
388 : : return new ::accessibility::AccessibleTreeNode(
389 : : *this,
390 : 0 : GetTitle(),
391 : 0 : GetTitle(),
392 [ # # ][ # # ]: 0 : ::com::sun::star::accessibility::AccessibleRole::LIST_ITEM);
[ # # ][ # # ]
393 : : }
394 : :
395 : :
396 : :
397 : :
398 : : //===== TitledControlStandardClickHandler =====================================
399 : :
400 : 0 : TitledControlStandardClickHandler::TitledControlStandardClickHandler (
401 : : ControlContainer& rControlContainer,
402 : : ControlContainer::ExpansionState eExpansionState)
403 : : : mrControlContainer(rControlContainer),
404 : 0 : meExpansionState(eExpansionState)
405 : : {
406 : 0 : }
407 : :
408 : :
409 : :
410 : :
411 : 0 : void TitledControlStandardClickHandler::operator () (TitledControl& rTitledControl)
412 : : {
413 : : // Toggle expansion.
414 : 0 : mrControlContainer.SetExpansionState (&rTitledControl, meExpansionState);
415 : 0 : }
416 : :
417 : : } } // end of namespace ::sd::toolpanel
418 : :
419 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|