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