xref: /aoo41x/main/sfx2/source/sidebar/MenuButton.cxx (revision 95a18594)
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/Theme.hxx"
29 
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::uno;
32 
33 
34 namespace sfx2 { namespace sidebar {
35 
36 
37 MenuButton::MenuButton (Window* pParentWindow)
38     : CheckBox(pParentWindow),
39       mbIsLeftButtonDown(false),
40       mePaintType(PT_Theme)
41 {
42 }
43 
44 
45 
46 
47 MenuButton::~MenuButton (void)
48 {
49 }
50 
51 
52 
53 
54 void MenuButton::Paint (const Rectangle& rUpdateArea)
55 {
56     switch(mePaintType)
57     {
58         case PT_Theme:
59         default:
60         {
61             const bool bIsSelected (IsChecked());
62             const bool bIsMouseOver (IsMouseOver());
63             DrawHelper::DrawRoundedRectangle(
64                 *this,
65                 Rectangle(Point(0,0), GetSizePixel()),
66                 2,
67                 bIsMouseOver||bIsSelected ? Theme::GetColor(Theme::Color_TabItemBorder) : Color(0xffffffff),
68                 bIsMouseOver
69                     ? Theme::GetPaint(Theme::Paint_TabItemBackgroundHighlight)
70                     : Theme::GetPaint(Theme::Paint_TabItemBackgroundNormal));
71 
72             const Image aIcon (Button::GetModeImage(Theme::IsHighContrastMode()
73                     ? BMP_COLOR_HIGHCONTRAST
74                     : BMP_COLOR_NORMAL));
75             const Size aIconSize (aIcon.GetSizePixel());
76             const Point aIconLocation(
77                 (GetSizePixel().Width() - aIconSize.Width())/2,
78                 (GetSizePixel().Height() - aIconSize.Height())/2);
79             DrawImage(
80                 aIconLocation,
81                 aIcon);
82             break;
83         }
84         case PT_Native:
85             Button::Paint(rUpdateArea);
86             //            DrawImage(maIconPosition, maIcon);
87             break;
88     }
89 }
90 
91 
92 
93 
94 void MenuButton::MouseMove (const MouseEvent& rEvent)
95 {
96     if (rEvent.IsEnterWindow() || rEvent.IsLeaveWindow())
97         Invalidate();
98     CheckBox::MouseMove(rEvent);
99 }
100 
101 
102 
103 
104 void MenuButton::MouseButtonDown (const MouseEvent& rMouseEvent)
105 {
106 #if 0
107     Hide();
108     CheckBox::MouseButtonDown(rMouseEvent);
109     Show();
110 #else
111     if (rMouseEvent.IsLeft())
112     {
113         mbIsLeftButtonDown = true;
114         CaptureMouse();
115         Invalidate();
116     }
117 #endif
118 }
119 
120 
121 
122 
123 void MenuButton::MouseButtonUp (const MouseEvent& rMouseEvent)
124 {
125 #if 0
126     Hide();
127     CheckBox::MouseButtonUp(rMouseEvent);
128     Show();
129 #else
130     if (IsMouseCaptured())
131         ReleaseMouse();
132 
133     if (rMouseEvent.IsLeft())
134     {
135         if (mbIsLeftButtonDown)
136         {
137             Check();
138             Click();
139             GetParent()->Invalidate();
140         }
141     }
142     if (mbIsLeftButtonDown)
143     {
144         mbIsLeftButtonDown = false;
145         Invalidate();
146     }
147 #endif
148 }
149 
150 
151 } } // end of namespace sfx2::sidebar
152