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