Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / sidebar / TabItem.cxx
blobd053f323dc35ba29bb5373024b04ce3a2b71a56f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "TabItem.hxx"
22 #include "DrawHelper.hxx"
23 #include "Paint.hxx"
24 #include <sfx2/sidebar/Tools.hxx>
26 #include <sfx2/sidebar/Theme.hxx>
28 using namespace css;
29 using namespace css::uno;
31 namespace sfx2 { namespace sidebar {
33 TabItem::TabItem (vcl::Window* pParentWindow)
34 : ImageRadioButton(pParentWindow),
35 mbIsLeftButtonDown(false),
36 mePaintType(PT_Theme)
38 SetStyle(GetStyle() | WB_TABSTOP | WB_DIALOGCONTROL | WB_NOPOINTERFOCUS);
39 SetBackground(Theme::GetPaint(Theme::Paint_TabBarBackground).GetWallpaper());
40 #ifdef DEBUG
41 SetText(OUString("TabItem"));
42 #endif
45 void TabItem::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rUpdateArea)
47 switch (mePaintType)
49 case PT_Theme:
50 default:
52 const bool bIsSelected (IsChecked());
53 const bool bIsHighlighted (IsMouseOver() || HasFocus());
54 DrawHelper::DrawRoundedRectangle(
55 rRenderContext,
56 Rectangle(Point(0,0), GetSizePixel()),
57 Theme::GetInteger(Theme::Int_ButtonCornerRadius),
58 bIsHighlighted||bIsSelected
59 ? Theme::GetColor(Theme::Color_TabItemBorder)
60 : Color(0xffffffff),
61 bIsHighlighted
62 ? Theme::GetPaint(Theme::Paint_TabItemBackgroundHighlight)
63 : Theme::GetPaint(Theme::Paint_TabItemBackgroundNormal));
65 const Image aIcon(Button::GetModeImage());
66 const Size aIconSize (aIcon.GetSizePixel());
67 const Point aIconLocation((GetSizePixel().Width() - aIconSize.Width()) / 2,
68 (GetSizePixel().Height() - aIconSize.Height()) / 2);
69 rRenderContext.DrawImage(aIconLocation, aIcon, IsEnabled() ? DrawImageFlags::NONE : DrawImageFlags::Disable);
70 break;
72 case PT_Native:
73 Button::Paint(rRenderContext, rUpdateArea);
74 break;
78 void TabItem::MouseMove(const MouseEvent& rEvent)
80 if (rEvent.IsEnterWindow() || rEvent.IsLeaveWindow())
81 Invalidate();
82 ImageRadioButton::MouseMove(rEvent);
85 void TabItem::MouseButtonDown(const MouseEvent& rMouseEvent)
87 if (rMouseEvent.IsLeft())
89 mbIsLeftButtonDown = true;
90 CaptureMouse();
91 Invalidate();
95 void TabItem::MouseButtonUp(const MouseEvent& rMouseEvent)
97 if (IsMouseCaptured())
98 ReleaseMouse();
100 if (rMouseEvent.IsLeft())
102 if (mbIsLeftButtonDown)
104 Check();
105 Click();
106 GetParent()->Invalidate();
109 if (mbIsLeftButtonDown)
111 mbIsLeftButtonDown = false;
112 Invalidate();
116 } } // end of namespace sfx2::sidebar
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */