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" 32*88f32a2cSAndre 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 387a32b0c8SAndre Fischer 398a1a651aSAndre Fischer using namespace css; 408a1a651aSAndre Fischer using namespace cssu; 41ff12d537SAndre Fischer 42ff12d537SAndre Fischer namespace sfx2 { namespace sidebar { 43ff12d537SAndre Fischer 44ff12d537SAndre Fischer 45ff12d537SAndre Fischer static const sal_Int32 gaLeftIconPadding (5); 46ff12d537SAndre Fischer static const sal_Int32 gaRightIconPadding (5); 47ff12d537SAndre Fischer 48ff12d537SAndre Fischer 49ff12d537SAndre Fischer PanelTitleBar::PanelTitleBar ( 50ff12d537SAndre Fischer const ::rtl::OUString& rsTitle, 51ff12d537SAndre Fischer Window* pParentWindow, 52c545150fSOliver-Rainer Wittmann Panel* pPanel) 537a32b0c8SAndre Fischer : TitleBar(rsTitle, pParentWindow, GetBackgroundPaint()), 54ff12d537SAndre Fischer mbIsLeftButtonDown(false), 557a32b0c8SAndre Fischer mpPanel(pPanel), 567a32b0c8SAndre Fischer mnMenuItemIndex(1), 578a1a651aSAndre Fischer mxFrame(), 588a1a651aSAndre Fischer msMoreOptionsCommand() 59ff12d537SAndre Fischer { 60ff12d537SAndre Fischer OSL_ASSERT(mpPanel != NULL); 61a5516503SAndre Fischer 62a5516503SAndre Fischer const ::rtl::OUString sAccessibleName( 63a5516503SAndre Fischer String(SfxResId(SFX_STR_SIDEBAR_ACCESSIBILITY_PANEL_PREFIX)) 64a5516503SAndre Fischer + rsTitle); 65a5516503SAndre Fischer SetAccessibleName(sAccessibleName); 66a5516503SAndre Fischer SetAccessibleDescription(sAccessibleName); 677a32b0c8SAndre Fischer 687a32b0c8SAndre Fischer #ifdef DEBUG 697a32b0c8SAndre Fischer SetText(A2S("PanelTitleBar")); 707a32b0c8SAndre Fischer #endif 71ff12d537SAndre Fischer } 72ff12d537SAndre Fischer 73ff12d537SAndre Fischer 74ff12d537SAndre Fischer 75ff12d537SAndre Fischer 76ff12d537SAndre Fischer PanelTitleBar::~PanelTitleBar (void) 77ff12d537SAndre Fischer { 78ff12d537SAndre Fischer } 79ff12d537SAndre Fischer 80ff12d537SAndre Fischer 81ff12d537SAndre Fischer 82ff12d537SAndre Fischer 838a1a651aSAndre Fischer void PanelTitleBar::SetMoreOptionsCommand ( 848a1a651aSAndre Fischer const ::rtl::OUString& rsCommandName, 858a1a651aSAndre Fischer const ::cssu::Reference<css::frame::XFrame>& rxFrame) 86c545150fSOliver-Rainer Wittmann { 878a1a651aSAndre Fischer if ( ! rsCommandName.equals(msMoreOptionsCommand)) 888a1a651aSAndre Fischer { 898a1a651aSAndre Fischer if (msMoreOptionsCommand.getLength() > 0) 908a1a651aSAndre Fischer maToolBox.RemoveItem(maToolBox.GetItemPos(mnMenuItemIndex)); 918a1a651aSAndre Fischer 928a1a651aSAndre Fischer msMoreOptionsCommand = rsCommandName; 938a1a651aSAndre Fischer mxFrame = rxFrame; 948a1a651aSAndre Fischer 958a1a651aSAndre Fischer if (msMoreOptionsCommand.getLength() > 0) 96c545150fSOliver-Rainer Wittmann { 97c545150fSOliver-Rainer Wittmann maToolBox.InsertItem( 98c545150fSOliver-Rainer Wittmann mnMenuItemIndex, 99c545150fSOliver-Rainer Wittmann Theme::GetImage(Theme::Image_PanelMenu)); 1008a1a651aSAndre Fischer Reference<frame::XToolbarController> xController ( 1018a1a651aSAndre Fischer ControllerFactory::CreateToolBoxController( 1028a1a651aSAndre Fischer &maToolBox, 1038a1a651aSAndre Fischer mnMenuItemIndex, 1048a1a651aSAndre Fischer msMoreOptionsCommand, 1058a1a651aSAndre Fischer rxFrame, 1068a1a651aSAndre Fischer VCLUnoHelper::GetInterface(&maToolBox), 1078a1a651aSAndre Fischer 0)); 1088a1a651aSAndre Fischer maToolBox.SetController(mnMenuItemIndex, xController, msMoreOptionsCommand); 109c545150fSOliver-Rainer Wittmann maToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT); 110abdd804dSAndre Fischer maToolBox.SetQuickHelpText( 111abdd804dSAndre Fischer mnMenuItemIndex, 112abdd804dSAndre Fischer String(SfxResId(SFX_STR_SIDEBAR_MORE_OPTIONS))); 113c545150fSOliver-Rainer Wittmann } 114c545150fSOliver-Rainer Wittmann } 115c545150fSOliver-Rainer Wittmann } 116c545150fSOliver-Rainer Wittmann 117c545150fSOliver-Rainer Wittmann 118c545150fSOliver-Rainer Wittmann 119c545150fSOliver-Rainer Wittmann 120ff12d537SAndre Fischer Rectangle PanelTitleBar::GetTitleArea (const Rectangle& rTitleBarBox) 121ff12d537SAndre Fischer { 122ff12d537SAndre Fischer if (mpPanel != NULL) 123ff12d537SAndre Fischer { 124ff12d537SAndre Fischer Image aImage (mpPanel->IsExpanded() 125b9e67834SAndre Fischer ? Theme::GetImage(Theme::Image_Expand) 126b9e67834SAndre Fischer : Theme::GetImage(Theme::Image_Collapse)); 127ff12d537SAndre Fischer return Rectangle( 128ff12d537SAndre Fischer aImage.GetSizePixel().Width() + gaLeftIconPadding + gaRightIconPadding, 129ff12d537SAndre Fischer rTitleBarBox.Top(), 130ff12d537SAndre Fischer rTitleBarBox.Right(), 131ff12d537SAndre Fischer rTitleBarBox.Bottom()); 132ff12d537SAndre Fischer } 133ff12d537SAndre Fischer else 134ff12d537SAndre Fischer return rTitleBarBox; 135ff12d537SAndre Fischer } 136ff12d537SAndre Fischer 137ff12d537SAndre Fischer 138ff12d537SAndre Fischer 139ff12d537SAndre Fischer 140ff12d537SAndre Fischer void PanelTitleBar::PaintDecoration (const Rectangle& rTitleBarBox) 141ff12d537SAndre Fischer { 14202c50d82SAndre Fischer (void)rTitleBarBox; 14302c50d82SAndre Fischer 144ff12d537SAndre Fischer if (mpPanel != NULL) 145ff12d537SAndre Fischer { 146ff12d537SAndre Fischer Image aImage (mpPanel->IsExpanded() 14795a18594SAndre Fischer ? Theme::GetImage(Theme::Image_Collapse) 14895a18594SAndre Fischer : Theme::GetImage(Theme::Image_Expand)); 149ff12d537SAndre Fischer const Point aTopLeft ( 150ff12d537SAndre Fischer gaLeftIconPadding, 151ff12d537SAndre Fischer (GetSizePixel().Height()-aImage.GetSizePixel().Height())/2); 152ff12d537SAndre Fischer DrawImage(aTopLeft, aImage); 153ff12d537SAndre Fischer } 154ff12d537SAndre Fischer } 155ff12d537SAndre Fischer 156ff12d537SAndre Fischer 157ff12d537SAndre Fischer 158ff12d537SAndre Fischer 159ff12d537SAndre Fischer Paint PanelTitleBar::GetBackgroundPaint (void) 160ff12d537SAndre Fischer { 161b9e67834SAndre Fischer return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground); 162ff12d537SAndre Fischer } 163ff12d537SAndre Fischer 164ff12d537SAndre Fischer 165ff12d537SAndre Fischer 166ff12d537SAndre Fischer 167ff12d537SAndre Fischer Color PanelTitleBar::GetTextColor (void) 168ff12d537SAndre Fischer { 169b9e67834SAndre Fischer return Theme::GetColor(Theme::Color_PanelTitleFont); 170ff12d537SAndre Fischer } 171ff12d537SAndre Fischer 172ff12d537SAndre Fischer 173ff12d537SAndre Fischer 174ff12d537SAndre Fischer 1757a32b0c8SAndre Fischer void PanelTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex) 1767a32b0c8SAndre Fischer { 1777a32b0c8SAndre Fischer if (nItemIndex == mnMenuItemIndex) 1788a1a651aSAndre Fischer if (msMoreOptionsCommand.getLength() > 0) 1798a1a651aSAndre Fischer { 1808a1a651aSAndre Fischer try 1818a1a651aSAndre Fischer { 1828a1a651aSAndre Fischer const util::URL aURL (Tools::GetURL(msMoreOptionsCommand)); 1838a1a651aSAndre Fischer Reference<frame::XDispatch> xDispatch (Tools::GetDispatch(mxFrame, aURL)); 1848a1a651aSAndre Fischer if (xDispatch.is()) 1858a1a651aSAndre Fischer xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>()); 1868a1a651aSAndre Fischer } 1878a1a651aSAndre Fischer catch(Exception& rException) 1888a1a651aSAndre Fischer { 1898a1a651aSAndre Fischer OSL_TRACE("caught exception: %s", 1908a1a651aSAndre Fischer OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr()); 1918a1a651aSAndre Fischer } 1928a1a651aSAndre Fischer } 1937a32b0c8SAndre Fischer } 1947a32b0c8SAndre Fischer 1957a32b0c8SAndre Fischer 1967a32b0c8SAndre Fischer 1977a32b0c8SAndre Fischer 198ff12d537SAndre Fischer void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent) 199ff12d537SAndre Fischer { 200ff12d537SAndre Fischer if (rMouseEvent.IsLeft()) 201ff12d537SAndre Fischer { 202ff12d537SAndre Fischer mbIsLeftButtonDown = true; 203ff12d537SAndre Fischer CaptureMouse(); 204ff12d537SAndre Fischer } 205ff12d537SAndre Fischer } 206ff12d537SAndre Fischer 207ff12d537SAndre Fischer 208ff12d537SAndre Fischer 209ff12d537SAndre Fischer 210ff12d537SAndre Fischer void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent) 211ff12d537SAndre Fischer { 212ff12d537SAndre Fischer if (IsMouseCaptured()) 213ff12d537SAndre Fischer ReleaseMouse(); 214ff12d537SAndre Fischer 215ff12d537SAndre Fischer if (rMouseEvent.IsLeft()) 216ff12d537SAndre Fischer { 217ff12d537SAndre Fischer if (mbIsLeftButtonDown) 218ff12d537SAndre Fischer { 219ff12d537SAndre Fischer if (mpPanel != NULL) 220ff12d537SAndre Fischer { 221ff12d537SAndre Fischer mpPanel->SetExpanded( ! mpPanel->IsExpanded()); 222ff12d537SAndre Fischer Invalidate(); 223ff12d537SAndre Fischer } 224ff12d537SAndre Fischer } 225ff12d537SAndre Fischer } 226ff12d537SAndre Fischer if (mbIsLeftButtonDown) 227ff12d537SAndre Fischer mbIsLeftButtonDown = false; 228ff12d537SAndre Fischer } 229ff12d537SAndre Fischer 230ff12d537SAndre Fischer 231ff12d537SAndre Fischer 2327a32b0c8SAndre Fischer 2337a32b0c8SAndre Fischer void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent) 2347a32b0c8SAndre Fischer { 2357a32b0c8SAndre Fischer maToolBox.SetItemImage( 2367a32b0c8SAndre Fischer mnMenuItemIndex, 2377a32b0c8SAndre Fischer Theme::GetImage(Theme::Image_PanelMenu)); 238580828edSAndre Fischer TitleBar::DataChanged(rEvent); 2397a32b0c8SAndre Fischer } 2407a32b0c8SAndre Fischer 241ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar 242