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