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 "MenuButton.hxx" 25 26 #include "DrawHelper.hxx" 27 #include "Paint.hxx" 28 #include "sfx2/sidebar/Tools.hxx" 29 #include "sfx2/sidebar/Theme.hxx" 30 31 using namespace ::com::sun::star; 32 using namespace ::com::sun::star::uno; 33 34 35 namespace sfx2 { namespace sidebar { 36 37 38 MenuButton::MenuButton (Window* pParentWindow) 39 : CheckBox(pParentWindow), 40 mbIsLeftButtonDown(false), 41 mePaintType(PT_Theme) 42 { 43 #ifdef DEBUG 44 SetText(A2S("MenuButton")); 45 #endif 46 } 47 48 49 50 51 MenuButton::~MenuButton (void) 52 { 53 } 54 55 56 57 58 void MenuButton::Paint (const Rectangle& rUpdateArea) 59 { 60 switch(mePaintType) 61 { 62 case PT_Theme: 63 default: 64 { 65 const bool bIsSelected (IsChecked()); 66 const bool bIsHighlighted (IsMouseOver() || HasFocus()); 67 DrawHelper::DrawRoundedRectangle( 68 *this, 69 Rectangle(Point(0,0), GetSizePixel()), 70 3, 71 bIsHighlighted||bIsSelected 72 ? Theme::GetColor(Theme::Color_TabItemBorder) 73 : Color(0xffffffff), 74 bIsHighlighted 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 MenuButton::MouseMove (const MouseEvent& rEvent) 101 { 102 if (rEvent.IsEnterWindow() || rEvent.IsLeaveWindow()) 103 Invalidate(); 104 CheckBox::MouseMove(rEvent); 105 } 106 107 108 109 110 void MenuButton::MouseButtonDown (const MouseEvent& rMouseEvent) 111 { 112 #if 0 113 Hide(); 114 CheckBox::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 MenuButton::MouseButtonUp (const MouseEvent& rMouseEvent) 130 { 131 #if 0 132 Hide(); 133 CheckBox::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 } } // end of namespace sfx2::sidebar 158