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