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"
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),
39 SetText(A2S("MenuButton"));
46 MenuButton::~MenuButton (void)
53 void MenuButton::Paint (const Rectangle
& rUpdateArea
)
60 const bool bIsSelected (IsChecked());
61 const bool bIsHighlighted (IsMouseOver() || HasFocus());
62 DrawHelper::DrawRoundedRectangle(
64 Rectangle(Point(0,0), GetSizePixel()),
66 bIsHighlighted
||bIsSelected
67 ? Theme::GetColor(Theme::Color_TabItemBorder
)
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);
84 Button::Paint(rUpdateArea
);
85 // DrawImage(maIconPosition, maIcon);
93 void MenuButton::MouseMove (const MouseEvent
& rEvent
)
95 if (rEvent
.IsEnterWindow() || rEvent
.IsLeaveWindow())
97 CheckBox::MouseMove(rEvent
);
103 void MenuButton::MouseButtonDown (const MouseEvent
& rMouseEvent
)
105 if (rMouseEvent
.IsLeft())
107 mbIsLeftButtonDown
= true;
116 void MenuButton::MouseButtonUp (const MouseEvent
& rMouseEvent
)
118 if (IsMouseCaptured())
121 if (rMouseEvent
.IsLeft())
123 if (mbIsLeftButtonDown
)
127 GetParent()->Invalidate();
130 if (mbIsLeftButtonDown
)
132 mbIsLeftButtonDown
= false;
138 } } // end of namespace sfx2::sidebar