CWS-TOOLING: integrate CWS os150
[LibreOffice.git] / sd / source / ui / toolpanel / ScrollPanel.cxx
blob276703999808bcea642d2d5c294ae714e39f3570
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
31 #include "taskpane/ScrollPanel.hxx"
33 #include "taskpane/ControlContainer.hxx"
34 #include "TaskPaneFocusManager.hxx"
35 #include "taskpane/TitledControl.hxx"
36 #include "AccessibleScrollPanel.hxx"
38 #include <vcl/svapp.hxx>
39 #include <svtools/valueset.hxx>
41 namespace sd { namespace toolpanel {
43 ScrollPanel::ScrollPanel (
44 ::Window& i_rParentWindow)
45 : Control (&i_rParentWindow, WB_DIALOGCONTROL),
46 TreeNode(NULL),
47 maScrollWindow(this, WB_DIALOGCONTROL),
48 maVerticalScrollBar(this, WB_VERT),
49 maHorizontalScrollBar(this, WB_HORZ),
50 maScrollBarFiller(this),
51 maScrollWindowFiller(&maScrollWindow),
52 mbIsRearrangePending(true),
53 mbIsLayoutPending(true),
54 mnChildrenWidth(0),
55 mnVerticalBorder(2),
56 mnVerticalGap(3),
57 mnHorizontalBorder(2)
59 Construct();
62 void ScrollPanel::Construct()
64 SetAccessibleName (
65 ::rtl::OUString::createFromAscii("Sub Task Panel"));
66 mpControlContainer->SetMultiSelection (true);
68 SetBorderStyle (WINDOW_BORDER_NORMAL);
69 SetMapMode (MapMode(MAP_PIXEL));
71 // To reduce flickering during repaints make the container windows
72 // transparent and rely on their children to paint the whole area.
73 SetBackground(Wallpaper());
74 maScrollWindow.SetBackground(Wallpaper());
75 maScrollWindowFiller.SetBackground(
76 Application::GetSettings().GetStyleSettings().GetWindowColor());
78 maScrollWindow.Show();
80 // Initialize the scroll bars.
81 maVerticalScrollBar.SetScrollHdl (
82 LINK(this, ScrollPanel, ScrollBarHandler));
83 maVerticalScrollBar.EnableDrag (sal_True);
84 maHorizontalScrollBar.SetScrollHdl (
85 LINK(this, ScrollPanel, ScrollBarHandler));
86 maHorizontalScrollBar.EnableDrag (sal_True);
92 ScrollPanel::~ScrollPanel (void)
94 sal_uInt32 nCount = mpControlContainer->GetControlCount();
95 for (sal_uInt32 nIndex=0; nIndex<nCount; nIndex++)
97 TreeNode* pNode = mpControlContainer->GetControl(nIndex);
98 TreeNode* pControl = pNode;
99 // When the node has been created as TitledControl then use its
100 // control instead of pNode directly.
101 TitledControl* pTitledControl = static_cast<TitledControl*>(pNode);
102 if (pTitledControl != NULL)
103 pControl = pTitledControl->GetControl();
105 // Remove this object as listener from the control.
106 if (pControl != NULL && pControl->GetWindow()!=NULL)
108 pControl->GetWindow()->RemoveEventListener(
109 LINK(this,ScrollPanel,WindowEventListener));
112 mpControlContainer->DeleteChildren();
118 TitledControl* ScrollPanel::AddControl (
119 ::std::auto_ptr<TreeNode> pControl,
120 const String& rTitle,
121 const rtl::OString& rHelpId)
123 // We are interested only in the title. The control itself is
124 // managed by the content object.
125 TitledControl* pTitledControl = new TitledControl(
126 this,
127 pControl,
128 rTitle,
129 TitledControlStandardClickHandler(GetControlContainer(), ControlContainer::ES_TOGGLE),
130 TitleBar::TBT_SUB_CONTROL_HEADLINE);
131 pTitledControl->GetTitleBar()->SetHelpId(rHelpId);
133 AddControl(::std::auto_ptr<TreeNode>(pTitledControl));
135 return pTitledControl;
141 void ScrollPanel::AddControl (::std::auto_ptr<TreeNode> pControl)
143 if (pControl.get() != NULL)
145 // Add a window event listener which does two things:
146 // 1. Listen for controls being shown or hidden so that the layout
147 // can be adapted.
148 // 2. Track selection changes in order to make the selected elements
149 // visible.
150 const Link aWindowListener(LINK(this,ScrollPanel,WindowEventListener));
151 OSL_ASSERT(pControl->GetWindow()!=NULL);
152 pControl->GetWindow()->AddEventListener(aWindowListener);
154 TitledControl* pTitledControl = dynamic_cast<TitledControl*>(pControl.get());
155 if (pTitledControl != NULL)
157 OSL_ASSERT(pTitledControl->GetControl()!=NULL);
158 OSL_ASSERT(pTitledControl->GetControl()->GetWindow()!=NULL);
159 pTitledControl->GetControl()->GetWindow()->AddEventListener(aWindowListener);
162 FocusManager& rFocusManager (FocusManager::Instance());
163 int nControlCount (mpControlContainer->GetControlCount());
164 // Replace the old links for cycling between first and last child by
165 // current ones.
166 if (nControlCount > 0)
168 ::Window* pFirst = mpControlContainer->GetControl(0)->GetWindow();
169 ::Window* pLast = mpControlContainer->GetControl(nControlCount-1)->GetWindow();
170 rFocusManager.RemoveLinks(pFirst,pLast);
171 rFocusManager.RemoveLinks(pLast,pFirst);
173 rFocusManager.RegisterLink(pFirst,pControl->GetWindow(), KEY_UP);
174 rFocusManager.RegisterLink(pControl->GetWindow(),pFirst, KEY_DOWN);
178 // Add a down link only for the first control so that when entering
179 // the sub tool panel the focus is set to the first control.
180 if (nControlCount == 0)
181 rFocusManager.RegisterDownLink(GetParent(), pControl->GetWindow());
182 rFocusManager.RegisterUpLink(pControl->GetWindow(), GetParent());
184 pControl->GetWindow()->SetParent(&maScrollWindow);
185 mpControlContainer->AddControl (pControl);
186 mpControlContainer->SetExpansionState(
187 mpControlContainer->GetControlCount()-1,
188 ControlContainer::ES_EXPAND);
195 void ScrollPanel::Paint (const Rectangle& rRect)
197 if (mbIsRearrangePending)
198 Rearrange();
199 if (mbIsLayoutPending)
200 LayoutChildren();
201 ::Window::Paint (rRect);
203 // Paint the outer border and the space between every two children.
204 Color aOriginalLineColor (maScrollWindow.GetLineColor());
205 Color aOriginalFillColor (maScrollWindow.GetFillColor());
207 maScrollWindow.SetLineColor ();
208 maScrollWindow.SetFillColor (
209 GetSettings().GetStyleSettings().GetWindowColor());
211 Size aSize (maScrollWindow.GetOutputSizePixel());
212 // Paint left and right vertical border.
213 Rectangle aVerticalArea (
214 Point(0,0),
215 Size(mnHorizontalBorder,aSize.Height()));
216 maScrollWindow.DrawRect (aVerticalArea);
217 aVerticalArea.Right() += mnHorizontalBorder + mnChildrenWidth - 1;
218 aVerticalArea.Left() = aVerticalArea.Right() + mnHorizontalBorder;
219 maScrollWindow.DrawRect (aVerticalArea);
221 // Paint horizontal stripes.
222 Rectangle aStripeArea (
223 Point (mnHorizontalBorder,0),
224 Size(mnChildrenWidth,0));
225 StripeList::const_iterator iStripe;
226 for (iStripe=maStripeList.begin(); iStripe!=maStripeList.end(); iStripe++)
228 aStripeArea.Top() = iStripe->first;
229 aStripeArea.Bottom() = iStripe->second;
230 if (aStripeArea.Bottom() < 0)
231 continue;
232 if (aStripeArea.Top() >= aSize.Height())
233 break;
234 maScrollWindow.DrawRect (aStripeArea);
237 maScrollWindow.SetLineColor (aOriginalLineColor);
238 maScrollWindow.SetFillColor (aOriginalFillColor);
244 void ScrollPanel::Resize (void)
246 ::Window::Resize();
247 mbIsRearrangePending = true;
248 mbIsLayoutPending = true;
254 void ScrollPanel::RequestResize (void)
256 mbIsRearrangePending = true;
257 mbIsLayoutPending = true;
258 Invalidate();
264 Size ScrollPanel::GetPreferredSize (void)
266 return GetRequiredSize();
272 sal_Int32 ScrollPanel::GetPreferredWidth (sal_Int32 )
274 return GetPreferredSize().Width();
280 sal_Int32 ScrollPanel::GetPreferredHeight (sal_Int32 )
282 return GetPreferredSize().Height();
288 bool ScrollPanel::IsResizable (void)
290 return true;
296 ::Window* ScrollPanel::GetWindow (void)
298 return this;
304 sal_Int32 ScrollPanel::GetMinimumWidth (void)
306 return TreeNode::GetMinimumWidth();
312 void ScrollPanel::ExpandControl (
313 TreeNode* pControl,
314 bool bExpansionState)
316 // Toggle expand status.
317 pControl->Expand (bExpansionState);
319 Rearrange ();
320 Invalidate ();
326 bool ScrollPanel::IsVerticalScrollBarVisible (void) const
328 return maVerticalScrollBar.IsReallyVisible();
334 bool ScrollPanel::IsHorizontalScrollBarVisible (void) const
336 return maHorizontalScrollBar.IsReallyVisible();
342 ScrollBar& ScrollPanel::GetVerticalScrollBar (void)
344 return maVerticalScrollBar;
350 ScrollBar& ScrollPanel::GetHorizontalScrollBar (void)
352 return maHorizontalScrollBar;
358 /** This control shows an expansion bar for every control and in a
359 separate area below that expansion area it shows all controls each
360 with its title bar. When there is not enough space then show a
361 scroll bar in the control area.
363 void ScrollPanel::Rearrange (void)
365 Size aRequiredSize (GetRequiredSize());
366 if (aRequiredSize.Width()>0 && aRequiredSize.Height()>0)
368 Size aAvailableSize (SetupScrollBars (aRequiredSize));
369 maScrollWindow.SetPosSizePixel(
370 Point(0,0),
371 aAvailableSize);
373 // Make the children at least as wide as the sub tool panel.
374 if (aRequiredSize.Width() < aAvailableSize.Width())
375 aRequiredSize.Width() = aAvailableSize.Width();
376 mnChildrenWidth = -2*mnHorizontalBorder;
377 if (maHorizontalScrollBar.IsVisible())
378 mnChildrenWidth += aRequiredSize.Width();
379 else
380 mnChildrenWidth += aAvailableSize.Width();
382 sal_Int32 nChildrenHeight (LayoutChildren());
383 maVerticalScrollBar.SetRangeMax (
384 nChildrenHeight + mnVerticalBorder);
386 mbIsRearrangePending = false;
393 Size ScrollPanel::GetRequiredSize (void)
395 // First determine the width of the children. This is the maximum of
396 // the current window width and the individual minimum widths of the
397 // children.
398 int nChildrenWidth (GetSizePixel().Width());
399 unsigned int nCount = mpControlContainer->GetControlCount();
400 unsigned int nIndex;
401 for (nIndex=0; nIndex<nCount; nIndex++)
403 TreeNode* pChild = mpControlContainer->GetControl (nIndex);
404 int nMinimumWidth (pChild->GetMinimumWidth());
405 if (nMinimumWidth > nChildrenWidth)
406 nChildrenWidth = nMinimumWidth;
409 // Determine the accumulated width of all children when scaled to the
410 // minimum width.
411 nChildrenWidth -= 2*mnHorizontalBorder;
412 Size aTotalSize (nChildrenWidth,
413 2*mnVerticalBorder + (nCount-1) * mnVerticalGap);
414 for (nIndex=0; nIndex<nCount; nIndex++)
416 TreeNode* pChild = mpControlContainer->GetControl (nIndex);
417 sal_Int32 nHeight = pChild->GetPreferredHeight(nChildrenWidth);
418 aTotalSize.Height() += nHeight;
421 return aTotalSize;
427 sal_Int32 ScrollPanel::LayoutChildren (void)
429 maStripeList.clear();
431 Point aPosition (maScrollOffset);
432 aPosition.X() += mnHorizontalBorder;
433 maStripeList.push_back( ::std::pair<int,int>(
434 aPosition.Y(),
435 aPosition.Y() + mnVerticalBorder - 1));
436 aPosition.Y() += mnVerticalBorder;
438 // Place the controls one over the other.
439 unsigned int nCount (mpControlContainer->GetControlCount());
440 for (unsigned int nIndex=0; nIndex<nCount; nIndex++)
442 if (nIndex > 0)
444 maStripeList.push_back( ::std::pair<int,int>(
445 aPosition.Y(),
446 aPosition.Y() + mnVerticalGap - 1));
447 aPosition.Y() += mnVerticalGap;
449 TreeNode* pChild = mpControlContainer->GetControl (nIndex);
450 int nControlHeight = pChild->GetPreferredHeight(mnChildrenWidth);
451 pChild->GetWindow()->SetPosSizePixel(
452 aPosition,
453 Size(mnChildrenWidth, nControlHeight));
454 aPosition.Y() += nControlHeight;
457 // If the children do not cover their parent window completely
458 // (regarding the height) we put a filler below that is responsible for
459 // painting the remaining space.
460 int nWindowHeight = maScrollWindow.GetSizePixel().Height();
461 if (aPosition.Y() < nWindowHeight)
463 maScrollWindowFiller.SetPosSizePixel (
464 aPosition,
465 Size(mnChildrenWidth, nWindowHeight-aPosition.Y()));
466 maStripeList.push_back( ::std::pair<int,int>(
467 aPosition.Y(),
468 nWindowHeight-1));
469 // maScrollWindowFiller.Show();
470 aPosition.Y() = nWindowHeight;
472 else
473 maScrollWindowFiller.Hide();
475 aPosition.Y() += mnVerticalBorder;
476 mbIsLayoutPending = false;
478 return aPosition.Y()-maScrollOffset.Y();
484 Size ScrollPanel::SetupScrollBars (const Size& rRequiredSize)
486 Size aWindowSize (GetSizePixel());
487 Size aScrollBarSize (
488 maVerticalScrollBar.GetSizePixel().Width(),
489 maHorizontalScrollBar.GetSizePixel().Height());
490 Size aRemainingSize (aWindowSize);
492 // Determine which scroll bars have to be shown.
493 bool bShowHorizontal = false;
494 if (rRequiredSize.Width() > aWindowSize.Width())
495 bShowHorizontal = true;
496 bool bShowVertical = false;
497 if (rRequiredSize.Height() > aWindowSize.Height())
498 bShowVertical = true;
499 // Showing one scroll bar may reduce the available size so that the
500 // other one has to be shown as well.
501 if (bShowHorizontal && ! bShowVertical)
503 if ((rRequiredSize.Height() + aScrollBarSize.Height())
504 > aWindowSize.Height())
505 bShowVertical = true;
507 else if (bShowVertical && ! bShowHorizontal)
509 if (GetMinimumWidth() + aScrollBarSize.Width() > aWindowSize.Width())
510 bShowHorizontal = true;
513 // Setup the scroll bars.
514 aRemainingSize.Width()
515 = SetupVerticalScrollBar (bShowVertical, rRequiredSize.Height());
516 aRemainingSize.Height()
517 = SetupHorizontalScrollBar (bShowHorizontal, rRequiredSize.Width());
519 // Place the filler.
520 if (bShowHorizontal && bShowVertical)
522 maScrollBarFiller.SetPosSizePixel (
523 Point(aWindowSize.Width(), aWindowSize.Height()),
524 aScrollBarSize);
525 maScrollBarFiller.Show();
527 else
528 maScrollBarFiller.Hide();
531 return aRemainingSize;
537 sal_Int32 ScrollPanel::SetupVerticalScrollBar (bool bShow, sal_Int32 nRange)
539 Size aScrollBarSize (
540 maVerticalScrollBar.GetSizePixel().Width(),
541 maHorizontalScrollBar.GetSizePixel().Height());
542 Size aWindowSize (GetOutputSizePixel());
543 sal_Int32 nRemainingWidth (aWindowSize.Width());
545 // Setup the verical scroll bar.
546 if (bShow)
548 int nWidth = aScrollBarSize.Width();
549 int nHeight = aWindowSize.Height();
550 maVerticalScrollBar.SetPosSizePixel(
551 Point(aWindowSize.Width()-nWidth,0),
552 Size(nWidth, nHeight));
553 maVerticalScrollBar.Show();
555 // Set the scroll bar range and thumb size.
556 maVerticalScrollBar.SetRangeMin (0);
557 maVerticalScrollBar.SetRangeMax (
558 nRange + 2*mnVerticalBorder);
559 maVerticalScrollBar.SetVisibleSize (aWindowSize.Height());
560 // Make page size approx. 10% of visible area.
561 maVerticalScrollBar.SetLineSize (aWindowSize.Height()/10);
562 // Make page size approx. 100% of visible area.
563 maVerticalScrollBar.SetPageSize (aWindowSize.Height());
564 // Make sure that thumb is inside the valid range.
565 maVerticalScrollBar.SetThumbPos(-maScrollOffset.Y());
566 long nMinPos = maVerticalScrollBar.GetRangeMin();
567 if (maVerticalScrollBar.GetThumbPos() < nMinPos)
568 maVerticalScrollBar.SetThumbPos(nMinPos);
569 long nMaxPos = maVerticalScrollBar.GetRangeMax()
570 - maVerticalScrollBar.GetVisibleSize();
571 if (maVerticalScrollBar.GetThumbPos() >= nMaxPos)
572 maVerticalScrollBar.SetThumbPos(nMaxPos);
573 // Set offset to match thumb pos.
574 maScrollOffset.Y() = -maVerticalScrollBar.GetThumbPos();
576 nRemainingWidth -= aScrollBarSize.Width();
578 else
580 maVerticalScrollBar.Hide();
581 maScrollOffset.Y() = 0;
584 return nRemainingWidth;
590 sal_Int32 ScrollPanel::SetupHorizontalScrollBar (bool bShow, sal_Int32 nRange)
592 Size aScrollBarSize (
593 maVerticalScrollBar.GetSizePixel().Width(),
594 maHorizontalScrollBar.GetSizePixel().Height());
595 Size aWindowSize (GetOutputSizePixel());
596 sal_Int32 nRemainingHeight (aWindowSize.Height());
598 // Setup the horizontal scroll bar.
599 if (bShow)
601 int nHeight = aScrollBarSize.Height();
602 int nWidth = GetOutputSizePixel().Width();
603 maHorizontalScrollBar.SetPosSizePixel(
604 Point(0, aWindowSize.Height()-nHeight),
605 Size(nWidth,nHeight));
606 maHorizontalScrollBar.Show();
608 // Set the scroll bar range and thumb size.
609 maHorizontalScrollBar.SetRangeMin (0);
610 maHorizontalScrollBar.SetRangeMax (
611 nRange + 2*mnHorizontalBorder);
612 maHorizontalScrollBar.SetVisibleSize (aWindowSize.Width());
613 // Make page size approx. 5% of visible area.
614 maHorizontalScrollBar.SetLineSize (aWindowSize.Width()/20+1);
615 // Make page size approx. 50% of visible area.
616 maHorizontalScrollBar.SetPageSize (aWindowSize.Width()/2+1);
617 // Make sure that thumb is inside the valid range.
618 maHorizontalScrollBar.SetThumbPos(-maScrollOffset.X());
619 long nMinPos = maHorizontalScrollBar.GetRangeMin();
620 if (maHorizontalScrollBar.GetThumbPos() < nMinPos)
621 maHorizontalScrollBar.SetThumbPos(nMinPos);
622 long nMaxPos = maHorizontalScrollBar.GetRangeMax()
623 - maHorizontalScrollBar.GetVisibleSize();
624 if (maHorizontalScrollBar.GetThumbPos() >= nMaxPos)
625 maHorizontalScrollBar.SetThumbPos(nMaxPos);
626 // Set offset to match thumb pos.
627 maScrollOffset.X() = -maHorizontalScrollBar.GetThumbPos();
629 nRemainingHeight -= aScrollBarSize.Height();
631 else
633 maHorizontalScrollBar.Hide();
634 maScrollOffset.X() = 0;
637 return nRemainingHeight;
641 IMPL_LINK(ScrollPanel, ScrollBarHandler, ScrollBar*, EMPTYARG)
643 maScrollOffset.X() -= maHorizontalScrollBar.GetDelta();
644 maScrollOffset.Y() -= maVerticalScrollBar.GetDelta();
646 // Scrolling is done by moving the child windows up or down.
647 mbIsLayoutPending = true;
648 Invalidate();
649 // LayoutChildren();
651 return 0;
657 long ScrollPanel::Notify( NotifyEvent& rNEvt )
659 long nRet = sal_False;
660 if( rNEvt.GetType() == EVENT_COMMAND )
662 // note: dynamic_cast is not possible as GetData() returns a void*
663 CommandEvent* pCmdEvent = reinterpret_cast< CommandEvent* >(rNEvt.GetData());
664 DBG_ASSERT( pCmdEvent!=0 &&
665 ( pCmdEvent->IsMouseEvent() == sal_True ||
666 pCmdEvent->IsMouseEvent() == sal_False ),
667 "Invalid CommandEvent" );
668 if (pCmdEvent)
669 switch (pCmdEvent->GetCommand())
671 case COMMAND_WHEEL:
672 case COMMAND_STARTAUTOSCROLL:
673 case COMMAND_AUTOSCROLL:
675 nRet = HandleScrollCommand (*pCmdEvent, &maHorizontalScrollBar, &maVerticalScrollBar);
676 break;
681 if( ! nRet )
682 nRet = ::Window::Notify( rNEvt );
684 return nRet;
690 ::com::sun::star::uno::Reference<
691 ::com::sun::star::accessibility::XAccessible> ScrollPanel::CreateAccessibleObject (
692 const ::com::sun::star::uno::Reference<
693 ::com::sun::star::accessibility::XAccessible>& )
695 return new ::accessibility::AccessibleScrollPanel (
696 *this,
697 ::rtl::OUString::createFromAscii("Scroll Panel"),
698 ::rtl::OUString::createFromAscii("Scroll Panel"));
704 void ScrollPanel::MakeRectangleVisible (
705 Rectangle& aRectangle,
706 ::Window* pWindow)
708 if (maVerticalScrollBar.IsVisible() && aRectangle.GetWidth()>0 && aRectangle.GetHeight()>0)
710 const Rectangle aRelativeBox (pWindow->GetWindowExtentsRelative(&maScrollWindow));
712 aRectangle.Move(
713 -maScrollOffset.X() + aRelativeBox.Left(),
714 -maScrollOffset.Y() + aRelativeBox.Top());
716 const int nVisibleHeight (maVerticalScrollBar.GetVisibleSize());
717 const int nVisibleTop (maVerticalScrollBar.GetThumbPos());
718 if (aRectangle.Bottom() >= nVisibleTop+nVisibleHeight)
719 maVerticalScrollBar.DoScroll(aRectangle.Bottom() - nVisibleHeight);
720 else if (aRectangle.Top() < nVisibleTop)
721 maVerticalScrollBar.DoScroll(aRectangle.Top());
728 IMPL_LINK(ScrollPanel,WindowEventListener,VclSimpleEvent*,pEvent)
730 VclWindowEvent* pWindowEvent = dynamic_cast<VclWindowEvent*>(pEvent);
731 if (pWindowEvent != NULL)
733 switch (pWindowEvent->GetId())
735 case VCLEVENT_WINDOW_KEYUP:
736 case VCLEVENT_WINDOW_MOUSEBUTTONUP:
738 // Make the currently selected item visible.
739 ValueSet* pControl = dynamic_cast<ValueSet*>(pWindowEvent->GetWindow());
740 if (pControl != NULL)
742 // Get the bounding box of the currently selected item
743 // and enlarge this so that the selection frame is
744 // inside as well.
745 Rectangle aBox (pControl->GetItemRect(pControl->GetSelectItemId()));
746 aBox.Top()-=4;
747 aBox.Bottom()+=4;
749 MakeRectangleVisible(aBox, pControl);
752 break;
754 case VCLEVENT_WINDOW_MOUSEBUTTONDOWN:
756 // Make the item under the mouse visible. We need this case
757 // for right clicks that open context menus. For these we
758 // only get the mouse down event. The following mouse up
759 // event is sent to the context menu.
760 ValueSet* pControl = dynamic_cast<ValueSet*>(pWindowEvent->GetWindow());
761 if (pControl != NULL)
763 // Get the bounding box of the item at the mouse
764 // position and enlarge this so that the selection frame
765 // is inside as well.
766 MouseEvent* pMouseEvent
767 = reinterpret_cast<MouseEvent*>(pWindowEvent->GetData());
768 if (pMouseEvent != NULL)
770 Point aPosition (pMouseEvent->GetPosPixel());
771 Rectangle aBox (pControl->GetItemRect(pControl->GetItemId(aPosition)));
772 aBox.Top()-=4;
773 aBox.Bottom()+=4;
775 MakeRectangleVisible(aBox, pControl);
779 break;
782 case VCLEVENT_WINDOW_GETFOCUS:
784 // Move title bars into the visible area when they get the
785 // focus (::Window wise their enclosing TitledControl gets
786 // the focus.)
787 TitledControl* pTitledControl = dynamic_cast<TitledControl*>(pWindowEvent->GetWindow());
788 if (pTitledControl!=NULL && pTitledControl->GetTitleBar()!=NULL)
790 ::Window* pTitleBarWindow = pTitledControl->GetTitleBar()->GetWindow();
791 Rectangle aBox(pTitleBarWindow->GetPosPixel(),pTitleBarWindow->GetSizePixel());
792 MakeRectangleVisible(
793 aBox,
794 pTitleBarWindow);
797 break;
799 case VCLEVENT_WINDOW_SHOW:
800 case VCLEVENT_WINDOW_HIDE:
801 case VCLEVENT_WINDOW_ACTIVATE:
802 case VCLEVENT_WINDOW_RESIZE:
803 // Rearrange the children of the scroll panel when one of
804 // the children changes its size or visibility.
805 RequestResize();
806 break;
809 return 0;
815 } } // end of namespace ::sd::toolpanel