tdf#42949 Fix IWYU warnings in sfx2/source/[s-v]*/*cxx and sfx2/qa
[LibreOffice.git] / sfx2 / source / sidebar / TabItem.cxx
blobd2535b583acf2aa4d0c48212468a8a70c4f7e305
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 <sfx2/sidebar/TabItem.hxx>
22 #include <sfx2/sidebar/DrawHelper.hxx>
23 #include <sfx2/sidebar/Paint.hxx>
25 #include <sfx2/sidebar/Theme.hxx>
26 #include <vcl/event.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)
37 SetStyle(GetStyle() | WB_TABSTOP | WB_DIALOGCONTROL | WB_NOPOINTERFOCUS);
38 SetBackground(Theme::GetPaint(Theme::Paint_TabBarBackground).GetWallpaper());
39 #ifdef DEBUG
40 SetText(OUString("TabItem"));
41 #endif
44 void TabItem::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*UpdateArea*/)
46 const bool bIsSelected (IsChecked());
47 const bool bIsHighlighted (IsMouseOver() || HasFocus());
48 DrawHelper::DrawRoundedRectangle(
49 rRenderContext,
50 tools::Rectangle(Point(0,0), GetSizePixel()),
51 Theme::GetInteger(Theme::Int_ButtonCornerRadius),
52 bIsHighlighted||bIsSelected
53 ? Theme::GetColor(Theme::Color_TabItemBorder)
54 : Color(0xffffffff),
55 bIsHighlighted
56 ? Theme::GetPaint(Theme::Paint_TabItemBackgroundHighlight)
57 : Theme::GetPaint(Theme::Paint_TabItemBackgroundNormal));
59 const Image aIcon(Button::GetModeImage());
60 const Size aIconSize (aIcon.GetSizePixel());
61 const Point aIconLocation((GetSizePixel().Width() - aIconSize.Width()) / 2,
62 (GetSizePixel().Height() - aIconSize.Height()) / 2);
63 rRenderContext.DrawImage(aIconLocation, aIcon, IsEnabled() ? DrawImageFlags::NONE : DrawImageFlags::Disable);
66 void TabItem::MouseMove(const MouseEvent& rEvent)
68 if (rEvent.IsEnterWindow() || rEvent.IsLeaveWindow())
69 Invalidate();
70 ImageRadioButton::MouseMove(rEvent);
73 void TabItem::MouseButtonDown(const MouseEvent& rMouseEvent)
75 if (rMouseEvent.IsLeft())
77 mbIsLeftButtonDown = true;
78 CaptureMouse();
79 Invalidate();
83 void TabItem::MouseButtonUp(const MouseEvent& rMouseEvent)
85 if (IsMouseCaptured())
86 ReleaseMouse();
88 if (rMouseEvent.IsLeft())
90 if (mbIsLeftButtonDown)
92 Check();
93 Click();
94 vcl::Window* pParent = GetParent();
95 if (pParent)
96 pParent->Invalidate();
100 if (mbIsLeftButtonDown)
102 mbIsLeftButtonDown = false;
103 Invalidate();
107 } } // end of namespace sfx2::sidebar
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */