1ff12d537SAndre Fischer /************************************************************** 2ff12d537SAndre Fischer * 3ff12d537SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 4ff12d537SAndre Fischer * or more contributor license agreements. See the NOTICE file 5ff12d537SAndre Fischer * distributed with this work for additional information 6ff12d537SAndre Fischer * regarding copyright ownership. The ASF licenses this file 7ff12d537SAndre Fischer * to you under the Apache License, Version 2.0 (the 8ff12d537SAndre Fischer * "License"); you may not use this file except in compliance 9ff12d537SAndre Fischer * with the License. You may obtain a copy of the License at 10ff12d537SAndre Fischer * 11ff12d537SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 12ff12d537SAndre Fischer * 13ff12d537SAndre Fischer * Unless required by applicable law or agreed to in writing, 14ff12d537SAndre Fischer * software distributed under the License is distributed on an 15ff12d537SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ff12d537SAndre Fischer * KIND, either express or implied. See the License for the 17ff12d537SAndre Fischer * specific language governing permissions and limitations 18ff12d537SAndre Fischer * under the License. 19ff12d537SAndre Fischer * 20ff12d537SAndre Fischer *************************************************************/ 21ff12d537SAndre Fischer 22ff12d537SAndre Fischer #include "precompiled_sfx2.hxx" 23ff12d537SAndre Fischer 24ff12d537SAndre Fischer #include "PanelTitleBar.hxx" 25abdd804dSAndre Fischer #include "sfx2/sfxresid.hxx" 26abdd804dSAndre Fischer #include "Sidebar.hrc" 27ff12d537SAndre Fischer 28ff12d537SAndre Fischer #include "Paint.hxx" 29ff12d537SAndre Fischer #include "Panel.hxx" 30b9e67834SAndre Fischer #include "sfx2/sidebar/Theme.hxx" 31ff12d537SAndre Fischer 32ff12d537SAndre Fischer #include <tools/svborder.hxx> 33ff12d537SAndre Fischer #include <vcl/gradient.hxx> 3495a18594SAndre Fischer #include <vcl/image.hxx> 3595a18594SAndre Fischer 367a32b0c8SAndre Fischer #ifdef DEBUG 37f35c6d02SAndre Fischer #include "sfx2/sidebar/Tools.hxx" 387a32b0c8SAndre Fischer #endif 397a32b0c8SAndre Fischer 40ff12d537SAndre Fischer 41ff12d537SAndre Fischer namespace sfx2 { namespace sidebar { 42ff12d537SAndre Fischer 43ff12d537SAndre Fischer 44ff12d537SAndre Fischer static const sal_Int32 gaLeftIconPadding (5); 45ff12d537SAndre Fischer static const sal_Int32 gaRightIconPadding (5); 46ff12d537SAndre Fischer 47ff12d537SAndre Fischer 48ff12d537SAndre Fischer PanelTitleBar::PanelTitleBar ( 49ff12d537SAndre Fischer const ::rtl::OUString& rsTitle, 50ff12d537SAndre Fischer Window* pParentWindow, 51c545150fSOliver-Rainer Wittmann Panel* pPanel) 527a32b0c8SAndre Fischer : TitleBar(rsTitle, pParentWindow, GetBackgroundPaint()), 53ff12d537SAndre Fischer mbIsLeftButtonDown(false), 547a32b0c8SAndre Fischer mpPanel(pPanel), 557a32b0c8SAndre Fischer mnMenuItemIndex(1), 56c545150fSOliver-Rainer Wittmann maMenuAction() 57ff12d537SAndre Fischer { 58ff12d537SAndre Fischer OSL_ASSERT(mpPanel != NULL); 59*a5516503SAndre Fischer 60*a5516503SAndre Fischer const ::rtl::OUString sAccessibleName( 61*a5516503SAndre Fischer String(SfxResId(SFX_STR_SIDEBAR_ACCESSIBILITY_PANEL_PREFIX)) 62*a5516503SAndre Fischer + rsTitle); 63*a5516503SAndre Fischer SetAccessibleName(sAccessibleName); 64*a5516503SAndre Fischer SetAccessibleDescription(sAccessibleName); 657a32b0c8SAndre Fischer 667a32b0c8SAndre Fischer #ifdef DEBUG 677a32b0c8SAndre Fischer SetText(A2S("PanelTitleBar")); 687a32b0c8SAndre Fischer #endif 69ff12d537SAndre Fischer } 70ff12d537SAndre Fischer 71ff12d537SAndre Fischer 72ff12d537SAndre Fischer 73ff12d537SAndre Fischer 74ff12d537SAndre Fischer PanelTitleBar::~PanelTitleBar (void) 75ff12d537SAndre Fischer { 76ff12d537SAndre Fischer } 77ff12d537SAndre Fischer 78ff12d537SAndre Fischer 79ff12d537SAndre Fischer 80ff12d537SAndre Fischer 81c545150fSOliver-Rainer Wittmann void PanelTitleBar::SetMenuAction ( const ::boost::function<void(void)>& rMenuAction ) 82c545150fSOliver-Rainer Wittmann { 83c545150fSOliver-Rainer Wittmann if ( !maMenuAction && rMenuAction ) 84c545150fSOliver-Rainer Wittmann { 85c545150fSOliver-Rainer Wittmann maToolBox.InsertItem( 86c545150fSOliver-Rainer Wittmann mnMenuItemIndex, 87c545150fSOliver-Rainer Wittmann Theme::GetImage(Theme::Image_PanelMenu)); 88c545150fSOliver-Rainer Wittmann maToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT); 89abdd804dSAndre Fischer maToolBox.SetQuickHelpText( 90abdd804dSAndre Fischer mnMenuItemIndex, 91abdd804dSAndre Fischer String(SfxResId(SFX_STR_SIDEBAR_MORE_OPTIONS))); 92c545150fSOliver-Rainer Wittmann } 93c545150fSOliver-Rainer Wittmann else if ( maMenuAction && !rMenuAction ) 94c545150fSOliver-Rainer Wittmann { 95c545150fSOliver-Rainer Wittmann maToolBox.RemoveItem( maToolBox.GetItemPos( mnMenuItemIndex ) ); 96c545150fSOliver-Rainer Wittmann } 97c545150fSOliver-Rainer Wittmann maMenuAction = rMenuAction; 98c545150fSOliver-Rainer Wittmann } 99c545150fSOliver-Rainer Wittmann 100c545150fSOliver-Rainer Wittmann 101c545150fSOliver-Rainer Wittmann 102c545150fSOliver-Rainer Wittmann 103ff12d537SAndre Fischer Rectangle PanelTitleBar::GetTitleArea (const Rectangle& rTitleBarBox) 104ff12d537SAndre Fischer { 105ff12d537SAndre Fischer if (mpPanel != NULL) 106ff12d537SAndre Fischer { 107ff12d537SAndre Fischer Image aImage (mpPanel->IsExpanded() 108b9e67834SAndre Fischer ? Theme::GetImage(Theme::Image_Expand) 109b9e67834SAndre Fischer : Theme::GetImage(Theme::Image_Collapse)); 110ff12d537SAndre Fischer return Rectangle( 111ff12d537SAndre Fischer aImage.GetSizePixel().Width() + gaLeftIconPadding + gaRightIconPadding, 112ff12d537SAndre Fischer rTitleBarBox.Top(), 113ff12d537SAndre Fischer rTitleBarBox.Right(), 114ff12d537SAndre Fischer rTitleBarBox.Bottom()); 115ff12d537SAndre Fischer } 116ff12d537SAndre Fischer else 117ff12d537SAndre Fischer return rTitleBarBox; 118ff12d537SAndre Fischer } 119ff12d537SAndre Fischer 120ff12d537SAndre Fischer 121ff12d537SAndre Fischer 122ff12d537SAndre Fischer 123ff12d537SAndre Fischer void PanelTitleBar::PaintDecoration (const Rectangle& rTitleBarBox) 124ff12d537SAndre Fischer { 12502c50d82SAndre Fischer (void)rTitleBarBox; 12602c50d82SAndre Fischer 127ff12d537SAndre Fischer if (mpPanel != NULL) 128ff12d537SAndre Fischer { 129ff12d537SAndre Fischer Image aImage (mpPanel->IsExpanded() 13095a18594SAndre Fischer ? Theme::GetImage(Theme::Image_Collapse) 13195a18594SAndre Fischer : Theme::GetImage(Theme::Image_Expand)); 132ff12d537SAndre Fischer const Point aTopLeft ( 133ff12d537SAndre Fischer gaLeftIconPadding, 134ff12d537SAndre Fischer (GetSizePixel().Height()-aImage.GetSizePixel().Height())/2); 135ff12d537SAndre Fischer DrawImage(aTopLeft, aImage); 136ff12d537SAndre Fischer } 137ff12d537SAndre Fischer } 138ff12d537SAndre Fischer 139ff12d537SAndre Fischer 140ff12d537SAndre Fischer 141ff12d537SAndre Fischer 142ff12d537SAndre Fischer Paint PanelTitleBar::GetBackgroundPaint (void) 143ff12d537SAndre Fischer { 144b9e67834SAndre Fischer return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground); 145ff12d537SAndre Fischer } 146ff12d537SAndre Fischer 147ff12d537SAndre Fischer 148ff12d537SAndre Fischer 149ff12d537SAndre Fischer 150ff12d537SAndre Fischer Color PanelTitleBar::GetTextColor (void) 151ff12d537SAndre Fischer { 152b9e67834SAndre Fischer return Theme::GetColor(Theme::Color_PanelTitleFont); 153ff12d537SAndre Fischer } 154ff12d537SAndre Fischer 155ff12d537SAndre Fischer 156ff12d537SAndre Fischer 157ff12d537SAndre Fischer 1587a32b0c8SAndre Fischer void PanelTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex) 1597a32b0c8SAndre Fischer { 1607a32b0c8SAndre Fischer if (nItemIndex == mnMenuItemIndex) 1617a32b0c8SAndre Fischer if (maMenuAction) 1627a32b0c8SAndre Fischer maMenuAction(); 1637a32b0c8SAndre Fischer } 1647a32b0c8SAndre Fischer 1657a32b0c8SAndre Fischer 1667a32b0c8SAndre Fischer 1677a32b0c8SAndre Fischer 168ff12d537SAndre Fischer void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent) 169ff12d537SAndre Fischer { 170ff12d537SAndre Fischer if (rMouseEvent.IsLeft()) 171ff12d537SAndre Fischer { 172ff12d537SAndre Fischer mbIsLeftButtonDown = true; 173ff12d537SAndre Fischer CaptureMouse(); 174ff12d537SAndre Fischer } 175ff12d537SAndre Fischer } 176ff12d537SAndre Fischer 177ff12d537SAndre Fischer 178ff12d537SAndre Fischer 179ff12d537SAndre Fischer 180ff12d537SAndre Fischer void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent) 181ff12d537SAndre Fischer { 182ff12d537SAndre Fischer if (IsMouseCaptured()) 183ff12d537SAndre Fischer ReleaseMouse(); 184ff12d537SAndre Fischer 185ff12d537SAndre Fischer if (rMouseEvent.IsLeft()) 186ff12d537SAndre Fischer { 187ff12d537SAndre Fischer if (mbIsLeftButtonDown) 188ff12d537SAndre Fischer { 189ff12d537SAndre Fischer if (mpPanel != NULL) 190ff12d537SAndre Fischer { 191ff12d537SAndre Fischer mpPanel->SetExpanded( ! mpPanel->IsExpanded()); 192ff12d537SAndre Fischer Invalidate(); 193ff12d537SAndre Fischer } 194ff12d537SAndre Fischer } 195ff12d537SAndre Fischer } 196ff12d537SAndre Fischer if (mbIsLeftButtonDown) 197ff12d537SAndre Fischer mbIsLeftButtonDown = false; 198ff12d537SAndre Fischer } 199ff12d537SAndre Fischer 200ff12d537SAndre Fischer 201ff12d537SAndre Fischer 2027a32b0c8SAndre Fischer 2037a32b0c8SAndre Fischer void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent) 2047a32b0c8SAndre Fischer { 2057a32b0c8SAndre Fischer maToolBox.SetItemImage( 2067a32b0c8SAndre Fischer mnMenuItemIndex, 2077a32b0c8SAndre Fischer Theme::GetImage(Theme::Image_PanelMenu)); 208580828edSAndre Fischer TitleBar::DataChanged(rEvent); 2097a32b0c8SAndre Fischer } 2107a32b0c8SAndre Fischer 211ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar 212