Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / sidebar / MenuButton.cxx
blob47e5971e64e617c0be7d0803243dcd17d730a8fd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "MenuButton.hxx"
22 #include "DrawHelper.hxx"
23 #include "Paint.hxx"
24 #include <sfx2/sidebar/Tools.hxx>
25 #include <sfx2/sidebar/Theme.hxx>
27 using namespace css;
28 using namespace css::uno;
30 namespace sfx2 { namespace sidebar {
32 MenuButton::MenuButton (vcl::Window* pParentWindow)
33 : CheckBox(pParentWindow),
34 mbIsLeftButtonDown(false),
35 mePaintType(PT_Theme)
37 #ifdef DEBUG
38 SetText(OUString("MenuButton"));
39 #endif
42 void MenuButton::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rUpdateArea)
44 switch (mePaintType)
46 case PT_Theme:
47 default:
49 const bool bIsSelected (IsChecked());
50 const bool bIsHighlighted (IsMouseOver() || HasFocus());
51 DrawHelper::DrawRoundedRectangle(
52 rRenderContext,
53 Rectangle(Point(0,0), GetSizePixel()),
55 (bIsHighlighted || bIsSelected
56 ? Theme::GetColor(Theme::Color_TabItemBorder)
57 : Color(0xffffffff)),
58 (bIsHighlighted
59 ? Theme::GetPaint(Theme::Paint_TabItemBackgroundHighlight)
60 : Theme::GetPaint(Theme::Paint_TabItemBackgroundNormal)));
62 const Image aIcon(Button::GetModeImage());
63 const Size aIconSize(aIcon.GetSizePixel());
64 const Point aIconLocation((GetSizePixel().Width() - aIconSize.Width()) / 2,
65 (GetSizePixel().Height() - aIconSize.Height()) / 2);
66 rRenderContext.DrawImage(aIconLocation, aIcon);
67 break;
69 case PT_Native:
70 Button::Paint(rRenderContext, rUpdateArea);
71 break;
75 void MenuButton::MouseMove (const MouseEvent& rEvent)
77 if (rEvent.IsEnterWindow() || rEvent.IsLeaveWindow())
78 Invalidate();
79 CheckBox::MouseMove(rEvent);
82 void MenuButton::MouseButtonDown (const MouseEvent& rMouseEvent)
84 if (rMouseEvent.IsLeft())
86 mbIsLeftButtonDown = true;
87 CaptureMouse();
88 Invalidate();
92 void MenuButton::MouseButtonUp (const MouseEvent& rMouseEvent)
94 if (IsMouseCaptured())
95 ReleaseMouse();
97 if (rMouseEvent.IsLeft())
99 if (mbIsLeftButtonDown)
101 Check();
102 Click();
103 GetParent()->Invalidate();
106 if (mbIsLeftButtonDown)
108 mbIsLeftButtonDown = false;
109 Invalidate();
113 } } // end of namespace sfx2::sidebar
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */