bump product version to 4.1.6.2
[LibreOffice.git] / sfx2 / source / sidebar / MenuButton.cxx
blobfc573cea6f6f7f6e3f9fbaa153abf1a1c8f61ae2
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "MenuButton.hxx"
21 #include "DrawHelper.hxx"
22 #include "Paint.hxx"
23 #include "sfx2/sidebar/Tools.hxx"
24 #include "sfx2/sidebar/Theme.hxx"
26 using namespace ::com::sun::star;
27 using namespace ::com::sun::star::uno;
30 namespace sfx2 { namespace sidebar {
33 MenuButton::MenuButton (Window* pParentWindow)
34 : CheckBox(pParentWindow),
35 mbIsLeftButtonDown(false),
36 mePaintType(PT_Theme)
38 #ifdef DEBUG
39 SetText(A2S("MenuButton"));
40 #endif
46 MenuButton::~MenuButton (void)
53 void MenuButton::Paint (const Rectangle& rUpdateArea)
55 switch(mePaintType)
57 case PT_Theme:
58 default:
60 const bool bIsSelected (IsChecked());
61 const bool bIsHighlighted (IsMouseOver() || HasFocus());
62 DrawHelper::DrawRoundedRectangle(
63 *this,
64 Rectangle(Point(0,0), GetSizePixel()),
66 bIsHighlighted||bIsSelected
67 ? Theme::GetColor(Theme::Color_TabItemBorder)
68 : Color(0xffffffff),
69 bIsHighlighted
70 ? Theme::GetPaint(Theme::Paint_TabItemBackgroundHighlight)
71 : Theme::GetPaint(Theme::Paint_TabItemBackgroundNormal));
73 const Image aIcon(Button::GetModeImage());
74 const Size aIconSize (aIcon.GetSizePixel());
75 const Point aIconLocation(
76 (GetSizePixel().Width() - aIconSize.Width())/2,
77 (GetSizePixel().Height() - aIconSize.Height())/2);
78 DrawImage(
79 aIconLocation,
80 aIcon);
81 break;
83 case PT_Native:
84 Button::Paint(rUpdateArea);
85 // DrawImage(maIconPosition, maIcon);
86 break;
93 void MenuButton::MouseMove (const MouseEvent& rEvent)
95 if (rEvent.IsEnterWindow() || rEvent.IsLeaveWindow())
96 Invalidate();
97 CheckBox::MouseMove(rEvent);
103 void MenuButton::MouseButtonDown (const MouseEvent& rMouseEvent)
105 if (rMouseEvent.IsLeft())
107 mbIsLeftButtonDown = true;
108 CaptureMouse();
109 Invalidate();
116 void MenuButton::MouseButtonUp (const MouseEvent& rMouseEvent)
118 if (IsMouseCaptured())
119 ReleaseMouse();
121 if (rMouseEvent.IsLeft())
123 if (mbIsLeftButtonDown)
125 Check();
126 Click();
127 GetParent()->Invalidate();
130 if (mbIsLeftButtonDown)
132 mbIsLeftButtonDown = false;
133 Invalidate();
138 } } // end of namespace sfx2::sidebar