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" 318a1a651aSAndre Fischer #include "sfx2/sidebar/ControllerFactory.hxx" 3288f32a2cSAndre Fischer #include "sfx2/sidebar/Tools.hxx" 33ff12d537SAndre Fischer #include <tools/svborder.hxx> 34ff12d537SAndre Fischer #include <vcl/gradient.hxx> 3595a18594SAndre Fischer #include <vcl/image.hxx> 368a1a651aSAndre Fischer #include <toolkit/helper/vclunohelper.hxx> 3795a18594SAndre Fischer 388a1a651aSAndre Fischer using namespace css; 398a1a651aSAndre Fischer using namespace cssu; 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), 568a1a651aSAndre Fischer mxFrame(), 57*3b2c5b9dSAndre Fischer msMoreOptionsCommand(), 58*3b2c5b9dSAndre Fischer msAccessibleNamePrefix(String(SfxResId(SFX_STR_SIDEBAR_ACCESSIBILITY_PANEL_PREFIX))) 59ff12d537SAndre Fischer { 60ff12d537SAndre Fischer OSL_ASSERT(mpPanel != NULL); 61a5516503SAndre Fischer 627a32b0c8SAndre Fischer #ifdef DEBUG 637a32b0c8SAndre Fischer SetText(A2S("PanelTitleBar")); 647a32b0c8SAndre Fischer #endif 65ff12d537SAndre Fischer } 66ff12d537SAndre Fischer 67ff12d537SAndre Fischer 68ff12d537SAndre Fischer 69ff12d537SAndre Fischer 70ff12d537SAndre Fischer PanelTitleBar::~PanelTitleBar (void) 71ff12d537SAndre Fischer { 72ff12d537SAndre Fischer } 73ff12d537SAndre Fischer 74ff12d537SAndre Fischer 75ff12d537SAndre Fischer 76ff12d537SAndre Fischer 778a1a651aSAndre Fischer void PanelTitleBar::SetMoreOptionsCommand ( 788a1a651aSAndre Fischer const ::rtl::OUString& rsCommandName, 798a1a651aSAndre Fischer const ::cssu::Reference<css::frame::XFrame>& rxFrame) 80c545150fSOliver-Rainer Wittmann { 818a1a651aSAndre Fischer if ( ! rsCommandName.equals(msMoreOptionsCommand)) 828a1a651aSAndre Fischer { 838a1a651aSAndre Fischer if (msMoreOptionsCommand.getLength() > 0) 848a1a651aSAndre Fischer maToolBox.RemoveItem(maToolBox.GetItemPos(mnMenuItemIndex)); 858a1a651aSAndre Fischer 868a1a651aSAndre Fischer msMoreOptionsCommand = rsCommandName; 878a1a651aSAndre Fischer mxFrame = rxFrame; 888a1a651aSAndre Fischer 898a1a651aSAndre Fischer if (msMoreOptionsCommand.getLength() > 0) 90c545150fSOliver-Rainer Wittmann { 91c545150fSOliver-Rainer Wittmann maToolBox.InsertItem( 92c545150fSOliver-Rainer Wittmann mnMenuItemIndex, 93c545150fSOliver-Rainer Wittmann Theme::GetImage(Theme::Image_PanelMenu)); 948a1a651aSAndre Fischer Reference<frame::XToolbarController> xController ( 958a1a651aSAndre Fischer ControllerFactory::CreateToolBoxController( 968a1a651aSAndre Fischer &maToolBox, 978a1a651aSAndre Fischer mnMenuItemIndex, 988a1a651aSAndre Fischer msMoreOptionsCommand, 998a1a651aSAndre Fischer rxFrame, 1008a1a651aSAndre Fischer VCLUnoHelper::GetInterface(&maToolBox), 1018a1a651aSAndre Fischer 0)); 1028a1a651aSAndre Fischer maToolBox.SetController(mnMenuItemIndex, xController, msMoreOptionsCommand); 103c545150fSOliver-Rainer Wittmann maToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT); 104abdd804dSAndre Fischer maToolBox.SetQuickHelpText( 105abdd804dSAndre Fischer mnMenuItemIndex, 106abdd804dSAndre Fischer String(SfxResId(SFX_STR_SIDEBAR_MORE_OPTIONS))); 107c545150fSOliver-Rainer Wittmann } 108c545150fSOliver-Rainer Wittmann } 109c545150fSOliver-Rainer Wittmann } 110c545150fSOliver-Rainer Wittmann 111c545150fSOliver-Rainer Wittmann 112c545150fSOliver-Rainer Wittmann 113c545150fSOliver-Rainer Wittmann 114ff12d537SAndre Fischer Rectangle PanelTitleBar::GetTitleArea (const Rectangle& rTitleBarBox) 115ff12d537SAndre Fischer { 116ff12d537SAndre Fischer if (mpPanel != NULL) 117ff12d537SAndre Fischer { 118ff12d537SAndre Fischer Image aImage (mpPanel->IsExpanded() 119b9e67834SAndre Fischer ? Theme::GetImage(Theme::Image_Expand) 120b9e67834SAndre Fischer : Theme::GetImage(Theme::Image_Collapse)); 121ff12d537SAndre Fischer return Rectangle( 122ff12d537SAndre Fischer aImage.GetSizePixel().Width() + gaLeftIconPadding + gaRightIconPadding, 123ff12d537SAndre Fischer rTitleBarBox.Top(), 124ff12d537SAndre Fischer rTitleBarBox.Right(), 125ff12d537SAndre Fischer rTitleBarBox.Bottom()); 126ff12d537SAndre Fischer } 127ff12d537SAndre Fischer else 128ff12d537SAndre Fischer return rTitleBarBox; 129ff12d537SAndre Fischer } 130ff12d537SAndre Fischer 131ff12d537SAndre Fischer 132ff12d537SAndre Fischer 133ff12d537SAndre Fischer 134ff12d537SAndre Fischer void PanelTitleBar::PaintDecoration (const Rectangle& rTitleBarBox) 135ff12d537SAndre Fischer { 13602c50d82SAndre Fischer (void)rTitleBarBox; 13702c50d82SAndre Fischer 138ff12d537SAndre Fischer if (mpPanel != NULL) 139ff12d537SAndre Fischer { 140ff12d537SAndre Fischer Image aImage (mpPanel->IsExpanded() 14195a18594SAndre Fischer ? Theme::GetImage(Theme::Image_Collapse) 14295a18594SAndre Fischer : Theme::GetImage(Theme::Image_Expand)); 143ff12d537SAndre Fischer const Point aTopLeft ( 144ff12d537SAndre Fischer gaLeftIconPadding, 145ff12d537SAndre Fischer (GetSizePixel().Height()-aImage.GetSizePixel().Height())/2); 146ff12d537SAndre Fischer DrawImage(aTopLeft, aImage); 147ff12d537SAndre Fischer } 148ff12d537SAndre Fischer } 149ff12d537SAndre Fischer 150ff12d537SAndre Fischer 151ff12d537SAndre Fischer 152ff12d537SAndre Fischer 153ff12d537SAndre Fischer Paint PanelTitleBar::GetBackgroundPaint (void) 154ff12d537SAndre Fischer { 155b9e67834SAndre Fischer return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground); 156ff12d537SAndre Fischer } 157ff12d537SAndre Fischer 158ff12d537SAndre Fischer 159ff12d537SAndre Fischer 160ff12d537SAndre Fischer 161ff12d537SAndre Fischer Color PanelTitleBar::GetTextColor (void) 162ff12d537SAndre Fischer { 163b9e67834SAndre Fischer return Theme::GetColor(Theme::Color_PanelTitleFont); 164ff12d537SAndre Fischer } 165ff12d537SAndre Fischer 166ff12d537SAndre Fischer 167ff12d537SAndre Fischer 168ff12d537SAndre Fischer 1697a32b0c8SAndre Fischer void PanelTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex) 1707a32b0c8SAndre Fischer { 1717a32b0c8SAndre Fischer if (nItemIndex == mnMenuItemIndex) 1728a1a651aSAndre Fischer if (msMoreOptionsCommand.getLength() > 0) 1738a1a651aSAndre Fischer { 1748a1a651aSAndre Fischer try 1758a1a651aSAndre Fischer { 1768a1a651aSAndre Fischer const util::URL aURL (Tools::GetURL(msMoreOptionsCommand)); 1778a1a651aSAndre Fischer Reference<frame::XDispatch> xDispatch (Tools::GetDispatch(mxFrame, aURL)); 1788a1a651aSAndre Fischer if (xDispatch.is()) 1798a1a651aSAndre Fischer xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>()); 1808a1a651aSAndre Fischer } 1818a1a651aSAndre Fischer catch(Exception& rException) 1828a1a651aSAndre Fischer { 1838a1a651aSAndre Fischer OSL_TRACE("caught exception: %s", 1848a1a651aSAndre Fischer OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr()); 1858a1a651aSAndre Fischer } 1868a1a651aSAndre Fischer } 1877a32b0c8SAndre Fischer } 1887a32b0c8SAndre Fischer 1897a32b0c8SAndre Fischer 1907a32b0c8SAndre Fischer 1917a32b0c8SAndre Fischer 192*3b2c5b9dSAndre Fischer Reference<accessibility::XAccessible> PanelTitleBar::CreateAccessible (void) 193*3b2c5b9dSAndre Fischer { 194*3b2c5b9dSAndre Fischer const ::rtl::OUString sAccessibleName(msAccessibleNamePrefix + msTitle); 195*3b2c5b9dSAndre Fischer SetAccessibleName(sAccessibleName); 196*3b2c5b9dSAndre Fischer SetAccessibleDescription(sAccessibleName); 197*3b2c5b9dSAndre Fischer return TitleBar::CreateAccessible(); 198*3b2c5b9dSAndre Fischer } 199*3b2c5b9dSAndre Fischer 200*3b2c5b9dSAndre Fischer 201*3b2c5b9dSAndre Fischer 202*3b2c5b9dSAndre Fischer 203ff12d537SAndre Fischer void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent) 204ff12d537SAndre Fischer { 205ff12d537SAndre Fischer if (rMouseEvent.IsLeft()) 206ff12d537SAndre Fischer { 207ff12d537SAndre Fischer mbIsLeftButtonDown = true; 208ff12d537SAndre Fischer CaptureMouse(); 209ff12d537SAndre Fischer } 210ff12d537SAndre Fischer } 211ff12d537SAndre Fischer 212ff12d537SAndre Fischer 213ff12d537SAndre Fischer 214ff12d537SAndre Fischer 215ff12d537SAndre Fischer void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent) 216ff12d537SAndre Fischer { 217ff12d537SAndre Fischer if (IsMouseCaptured()) 218ff12d537SAndre Fischer ReleaseMouse(); 219ff12d537SAndre Fischer 220ff12d537SAndre Fischer if (rMouseEvent.IsLeft()) 221ff12d537SAndre Fischer { 222ff12d537SAndre Fischer if (mbIsLeftButtonDown) 223ff12d537SAndre Fischer { 224ff12d537SAndre Fischer if (mpPanel != NULL) 225ff12d537SAndre Fischer { 226ff12d537SAndre Fischer mpPanel->SetExpanded( ! mpPanel->IsExpanded()); 227ff12d537SAndre Fischer Invalidate(); 228ff12d537SAndre Fischer } 229ff12d537SAndre Fischer } 230ff12d537SAndre Fischer } 231ff12d537SAndre Fischer if (mbIsLeftButtonDown) 232ff12d537SAndre Fischer mbIsLeftButtonDown = false; 233ff12d537SAndre Fischer } 234ff12d537SAndre Fischer 235ff12d537SAndre Fischer 236ff12d537SAndre Fischer 2377a32b0c8SAndre Fischer 2387a32b0c8SAndre Fischer void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent) 2397a32b0c8SAndre Fischer { 2407a32b0c8SAndre Fischer maToolBox.SetItemImage( 2417a32b0c8SAndre Fischer mnMenuItemIndex, 2427a32b0c8SAndre Fischer Theme::GetImage(Theme::Image_PanelMenu)); 243580828edSAndre Fischer TitleBar::DataChanged(rEvent); 2447a32b0c8SAndre Fischer } 2457a32b0c8SAndre Fischer 246ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar 247