1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include "precompiled_sfx2.hxx"
23 
24 #include "MenuButton.hxx"
25 
26 #include "DrawHelper.hxx"
27 #include "Paint.hxx"
28 #include "sfx2/sidebar/Tools.hxx"
29 #include "sfx2/sidebar/Theme.hxx"
30 
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::uno;
33 
34 
35 namespace sfx2 { namespace sidebar {
36 
37 
MenuButton(Window * pParentWindow)38 MenuButton::MenuButton (Window* pParentWindow)
39     : CheckBox(pParentWindow),
40       mbIsLeftButtonDown(false),
41       mePaintType(PT_Theme)
42 {
43 #ifdef DEBUG
44     SetText(A2S("MenuButton"));
45 #endif
46 }
47 
48 
49 
50 
~MenuButton(void)51 MenuButton::~MenuButton (void)
52 {
53 }
54 
55 
56 
57 
Paint(const Rectangle & rUpdateArea)58 void MenuButton::Paint (const Rectangle& rUpdateArea)
59 {
60     switch(mePaintType)
61     {
62         case PT_Theme:
63         default:
64         {
65             const bool bIsSelected (IsChecked());
66             const bool bIsHighlighted (IsMouseOver() || HasFocus());
67             DrawHelper::DrawRoundedRectangle(
68                 *this,
69                 Rectangle(Point(0,0), GetSizePixel()),
70                 3,
71                 bIsHighlighted||bIsSelected
72                     ? Theme::GetColor(Theme::Color_TabItemBorder)
73                     : Color(0xffffffff),
74                 bIsHighlighted
75                     ? Theme::GetPaint(Theme::Paint_TabItemBackgroundHighlight)
76                     : Theme::GetPaint(Theme::Paint_TabItemBackgroundNormal));
77 
78             const Image aIcon (Button::GetModeImage(Theme::IsHighContrastMode()
79                     ? BMP_COLOR_HIGHCONTRAST
80                     : BMP_COLOR_NORMAL));
81             const Size aIconSize (aIcon.GetSizePixel());
82             const Point aIconLocation(
83                 (GetSizePixel().Width() - aIconSize.Width())/2,
84                 (GetSizePixel().Height() - aIconSize.Height())/2);
85             DrawImage(
86                 aIconLocation,
87                 aIcon);
88             break;
89         }
90         case PT_Native:
91             Button::Paint(rUpdateArea);
92             //            DrawImage(maIconPosition, maIcon);
93             break;
94     }
95 }
96 
97 
98 
99 
MouseMove(const MouseEvent & rEvent)100 void MenuButton::MouseMove (const MouseEvent& rEvent)
101 {
102     if (rEvent.IsEnterWindow() || rEvent.IsLeaveWindow())
103         Invalidate();
104     CheckBox::MouseMove(rEvent);
105 }
106 
107 
108 
109 
MouseButtonDown(const MouseEvent & rMouseEvent)110 void MenuButton::MouseButtonDown (const MouseEvent& rMouseEvent)
111 {
112     if (rMouseEvent.IsLeft())
113     {
114         mbIsLeftButtonDown = true;
115         CaptureMouse();
116         Invalidate();
117     }
118 }
119 
120 
121 
122 
MouseButtonUp(const MouseEvent & rMouseEvent)123 void MenuButton::MouseButtonUp (const MouseEvent& rMouseEvent)
124 {
125     if (IsMouseCaptured())
126         ReleaseMouse();
127 
128     if (rMouseEvent.IsLeft())
129     {
130         if (mbIsLeftButtonDown)
131         {
132             Check();
133             Click();
134             GetParent()->Invalidate();
135         }
136     }
137     if (mbIsLeftButtonDown)
138     {
139         mbIsLeftButtonDown = false;
140         Invalidate();
141     }
142 }
143 
144 
145 } } // end of namespace sfx2::sidebar
146