1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sfx2/sidebar/MenuButton.hxx>
22 #include <sfx2/sidebar/DrawHelper.hxx>
23 #include <sfx2/sidebar/Theme.hxx>
24 #include <vcl/event.hxx>
27 using namespace css::uno
;
29 namespace sfx2
{ namespace sidebar
{
31 MenuButton::MenuButton (vcl::Window
* pParentWindow
)
32 : CheckBox(pParentWindow
),
33 mbIsLeftButtonDown(false)
36 SetText(OUString("MenuButton"));
40 void MenuButton::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& /*rUpdateArea*/)
42 const bool bIsSelected (IsChecked());
43 const bool bIsHighlighted (IsMouseOver() || HasFocus());
44 DrawHelper::DrawRoundedRectangle(
46 tools::Rectangle(Point(0,0), GetSizePixel()),
48 (bIsHighlighted
|| bIsSelected
49 ? Theme::GetColor(Theme::Color_TabItemBorder
)
52 ? Theme::GetPaint(Theme::Paint_TabItemBackgroundHighlight
)
53 : Theme::GetPaint(Theme::Paint_TabItemBackgroundNormal
)));
55 const Image
aIcon(Button::GetModeImage());
56 const Size
aIconSize(aIcon
.GetSizePixel());
57 const Point
aIconLocation((GetSizePixel().Width() - aIconSize
.Width()) / 2,
58 (GetSizePixel().Height() - aIconSize
.Height()) / 2);
59 rRenderContext
.DrawImage(aIconLocation
, aIcon
);
62 void MenuButton::MouseMove (const MouseEvent
& rEvent
)
64 if (rEvent
.IsEnterWindow() || rEvent
.IsLeaveWindow())
66 CheckBox::MouseMove(rEvent
);
69 void MenuButton::MouseButtonDown (const MouseEvent
& rMouseEvent
)
71 if (rMouseEvent
.IsLeft())
73 mbIsLeftButtonDown
= true;
79 void MenuButton::MouseButtonUp (const MouseEvent
& rMouseEvent
)
81 if (IsMouseCaptured())
84 if (rMouseEvent
.IsLeft())
86 if (mbIsLeftButtonDown
)
90 GetParent()->Invalidate();
93 if (mbIsLeftButtonDown
)
95 mbIsLeftButtonDown
= false;
100 } } // end of namespace sfx2::sidebar
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */