Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "MenuButton.hxx"
21 :
22 : #include "DrawHelper.hxx"
23 : #include "Paint.hxx"
24 : #include <sfx2/sidebar/Tools.hxx>
25 : #include <sfx2/sidebar/Theme.hxx>
26 :
27 : using namespace css;
28 : using namespace css::uno;
29 :
30 :
31 : namespace sfx2 { namespace sidebar {
32 :
33 :
34 4700 : MenuButton::MenuButton (vcl::Window* pParentWindow)
35 : : CheckBox(pParentWindow),
36 : mbIsLeftButtonDown(false),
37 4700 : mePaintType(PT_Theme)
38 : {
39 : #ifdef DEBUG
40 : SetText(OUString("MenuButton"));
41 : #endif
42 4700 : }
43 :
44 :
45 :
46 :
47 9400 : MenuButton::~MenuButton (void)
48 : {
49 9400 : }
50 :
51 :
52 :
53 :
54 10300 : void MenuButton::Paint (const Rectangle& rUpdateArea)
55 : {
56 10300 : switch(mePaintType)
57 : {
58 : case PT_Theme:
59 : default:
60 : {
61 10300 : const bool bIsSelected (IsChecked());
62 10300 : const bool bIsHighlighted (IsMouseOver() || HasFocus());
63 : DrawHelper::DrawRoundedRectangle(
64 : *this,
65 10300 : Rectangle(Point(0,0), GetSizePixel()),
66 : 3,
67 10300 : bIsHighlighted||bIsSelected
68 : ? Theme::GetColor(Theme::Color_TabItemBorder)
69 : : Color(0xffffffff),
70 : bIsHighlighted
71 : ? Theme::GetPaint(Theme::Paint_TabItemBackgroundHighlight)
72 20600 : : Theme::GetPaint(Theme::Paint_TabItemBackgroundNormal));
73 :
74 10300 : const Image aIcon(Button::GetModeImage());
75 10300 : const Size aIconSize (aIcon.GetSizePixel());
76 : const Point aIconLocation(
77 20600 : (GetSizePixel().Width() - aIconSize.Width())/2,
78 30900 : (GetSizePixel().Height() - aIconSize.Height())/2);
79 : DrawImage(
80 : aIconLocation,
81 10300 : aIcon);
82 10300 : break;
83 : }
84 : case PT_Native:
85 0 : Button::Paint(rUpdateArea);
86 : // DrawImage(maIconPosition, maIcon);
87 0 : break;
88 : }
89 10300 : }
90 :
91 :
92 :
93 :
94 0 : void MenuButton::MouseMove (const MouseEvent& rEvent)
95 : {
96 0 : if (rEvent.IsEnterWindow() || rEvent.IsLeaveWindow())
97 0 : Invalidate();
98 0 : CheckBox::MouseMove(rEvent);
99 0 : }
100 :
101 :
102 :
103 :
104 0 : void MenuButton::MouseButtonDown (const MouseEvent& rMouseEvent)
105 : {
106 0 : if (rMouseEvent.IsLeft())
107 : {
108 0 : mbIsLeftButtonDown = true;
109 0 : CaptureMouse();
110 0 : Invalidate();
111 : }
112 0 : }
113 :
114 :
115 :
116 :
117 0 : void MenuButton::MouseButtonUp (const MouseEvent& rMouseEvent)
118 : {
119 0 : if (IsMouseCaptured())
120 0 : ReleaseMouse();
121 :
122 0 : if (rMouseEvent.IsLeft())
123 : {
124 0 : if (mbIsLeftButtonDown)
125 : {
126 0 : Check();
127 0 : Click();
128 0 : GetParent()->Invalidate();
129 : }
130 : }
131 0 : if (mbIsLeftButtonDown)
132 : {
133 0 : mbIsLeftButtonDown = false;
134 0 : Invalidate();
135 : }
136 0 : }
137 :
138 :
139 951 : } } // end of namespace sfx2::sidebar
140 :
141 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|