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