122de8995SAndre Fischer /************************************************************** 222de8995SAndre Fischer * 322de8995SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 422de8995SAndre Fischer * or more contributor license agreements. See the NOTICE file 522de8995SAndre Fischer * distributed with this work for additional information 622de8995SAndre Fischer * regarding copyright ownership. The ASF licenses this file 722de8995SAndre Fischer * to you under the Apache License, Version 2.0 (the 822de8995SAndre Fischer * "License"); you may not use this file except in compliance 922de8995SAndre Fischer * with the License. You may obtain a copy of the License at 1022de8995SAndre Fischer * 1122de8995SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 1222de8995SAndre Fischer * 1322de8995SAndre Fischer * Unless required by applicable law or agreed to in writing, 1422de8995SAndre Fischer * software distributed under the License is distributed on an 1522de8995SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1622de8995SAndre Fischer * KIND, either express or implied. See the License for the 1722de8995SAndre Fischer * specific language governing permissions and limitations 1822de8995SAndre Fischer * under the License. 1922de8995SAndre Fischer * 2022de8995SAndre Fischer *************************************************************/ 2122de8995SAndre Fischer 2222de8995SAndre Fischer #include "precompiled_sfx2.hxx" 2322de8995SAndre Fischer 2422de8995SAndre Fischer #include "TabBar.hxx" 25ff12d537SAndre Fischer #include "TabItem.hxx" 2695a18594SAndre Fischer #include "sidebar/ControlFactory.hxx" 27ff12d537SAndre Fischer #include "DeckDescriptor.hxx" 28ff12d537SAndre Fischer #include "Paint.hxx" 29b9e67834SAndre Fischer #include "sfx2/sidebar/Theme.hxx" 30b9e67834SAndre Fischer #include "Tools.hxx" 31ff12d537SAndre Fischer 3222de8995SAndre Fischer #include <vcl/gradient.hxx> 33ff12d537SAndre Fischer #include <vcl/image.hxx> 34*7a32b0c8SAndre Fischer #include <vcl/wrkwin.hxx> 35ff12d537SAndre Fischer #include <comphelper/processfactory.hxx> 36ff12d537SAndre Fischer #include <comphelper/componentcontext.hxx> 3795a18594SAndre Fischer #include <tools/svborder.hxx> 38ff12d537SAndre Fischer 39ff12d537SAndre Fischer #include <com/sun/star/graphic/XGraphicProvider.hpp> 40ff12d537SAndre Fischer 41ff12d537SAndre Fischer 42ff12d537SAndre Fischer using namespace ::com::sun::star; 43ff12d537SAndre Fischer using namespace ::com::sun::star::uno; 44ff12d537SAndre Fischer 45ff12d537SAndre Fischer 46ff12d537SAndre Fischer 4722de8995SAndre Fischer 48ff12d537SAndre Fischer namespace sfx2 { namespace sidebar { 4922de8995SAndre Fischer 50ff12d537SAndre Fischer TabBar::TabBar ( 51ff12d537SAndre Fischer Window* pParentWindow, 52ff12d537SAndre Fischer const Reference<frame::XFrame>& rxFrame, 5395a18594SAndre Fischer const ::boost::function<void(const ::rtl::OUString&)>& rDeckActivationFunctor, 5495a18594SAndre Fischer const PopupMenuProvider& rPopupMenuProvider) 55ff12d537SAndre Fischer : Window(pParentWindow), 56ff12d537SAndre Fischer mxFrame(rxFrame), 57ff12d537SAndre Fischer mpMenuButton(ControlFactory::CreateMenuButton(this)), 58ff12d537SAndre Fischer maItems(), 59ff12d537SAndre Fischer maDeckActivationFunctor(rDeckActivationFunctor), 60ff12d537SAndre Fischer maPopupMenuProvider(rPopupMenuProvider) 6122de8995SAndre Fischer { 62b9e67834SAndre Fischer SetBackground(Theme::GetPaint(Theme::Paint_TabBarBackground).GetWallpaper()); 63ff12d537SAndre Fischer 64ff12d537SAndre Fischer mpMenuButton->SetModeImage( 65*7a32b0c8SAndre Fischer Theme::GetImage(Theme::Image_TabBarMenu), 66ff12d537SAndre Fischer Theme::IsHighContrastMode() 67ff12d537SAndre Fischer ? BMP_COLOR_HIGHCONTRAST 68ff12d537SAndre Fischer : BMP_COLOR_NORMAL); 69ff12d537SAndre Fischer mpMenuButton->SetClickHdl(LINK(this, TabBar, OnToolboxClicked)); 7095a18594SAndre Fischer Layout(); 71*7a32b0c8SAndre Fischer 72*7a32b0c8SAndre Fischer #ifdef DEBUG 73*7a32b0c8SAndre Fischer SetText(A2S("TabBar")); 74*7a32b0c8SAndre Fischer #endif 7522de8995SAndre Fischer } 7622de8995SAndre Fischer 7722de8995SAndre Fischer 7822de8995SAndre Fischer 7922de8995SAndre Fischer 8022de8995SAndre Fischer TabBar::~TabBar (void) 8122de8995SAndre Fischer { 8222de8995SAndre Fischer } 8322de8995SAndre Fischer 8422de8995SAndre Fischer 8522de8995SAndre Fischer 8622de8995SAndre Fischer 8722de8995SAndre Fischer void TabBar::Paint (const Rectangle& rUpdateArea) 8822de8995SAndre Fischer { 89ff12d537SAndre Fischer Window::Paint(rUpdateArea); 90ff12d537SAndre Fischer 91b9e67834SAndre Fischer const sal_Int32 nHorizontalPadding (Theme::GetInteger(Theme::Int_TabMenuSeparatorPadding)); 92b9e67834SAndre Fischer SetLineColor(Theme::GetColor(Theme::Color_TabMenuSeparator)); 93ff12d537SAndre Fischer DrawLine( 94ff12d537SAndre Fischer Point(nHorizontalPadding, mnMenuSeparatorY), 95ff12d537SAndre Fischer Point(GetSizePixel().Width()-nHorizontalPadding, mnMenuSeparatorY)); 9622de8995SAndre Fischer } 9722de8995SAndre Fischer 9822de8995SAndre Fischer 9922de8995SAndre Fischer 10022de8995SAndre Fischer 10122de8995SAndre Fischer sal_Int32 TabBar::GetDefaultWidth (void) 10222de8995SAndre Fischer { 103b9e67834SAndre Fischer return Theme::GetInteger(Theme::Int_TabItemWidth) 104b9e67834SAndre Fischer + Theme::GetInteger(Theme::Int_TabBarLeftPadding) 105b9e67834SAndre Fischer + Theme::GetInteger(Theme::Int_TabBarRightPadding); 106ff12d537SAndre Fischer } 107ff12d537SAndre Fischer 108ff12d537SAndre Fischer 109ff12d537SAndre Fischer 110ff12d537SAndre Fischer 111ff12d537SAndre Fischer void TabBar::SetDecks ( 11295a18594SAndre Fischer const ResourceManager::IdContainer& rDeckIds) 113ff12d537SAndre Fischer { 114ff12d537SAndre Fischer // Remove the current buttons. 115ff12d537SAndre Fischer { 116*7a32b0c8SAndre Fischer for(ItemContainer::iterator 117ff12d537SAndre Fischer iItem(maItems.begin()), iEnd(maItems.end()); 118ff12d537SAndre Fischer iItem!=iEnd; 119ff12d537SAndre Fischer ++iItem) 120ff12d537SAndre Fischer { 121*7a32b0c8SAndre Fischer iItem->mpButton.reset(); 122ff12d537SAndre Fischer } 123ff12d537SAndre Fischer maItems.clear(); 124ff12d537SAndre Fischer } 125ff12d537SAndre Fischer 12695a18594SAndre Fischer maItems.resize(rDeckIds.size()); 127ff12d537SAndre Fischer sal_Int32 nIndex (0); 12895a18594SAndre Fischer for (ResourceManager::IdContainer::const_iterator 12995a18594SAndre Fischer iDeckId(rDeckIds.begin()), 13095a18594SAndre Fischer iEnd(rDeckIds.end()); 13195a18594SAndre Fischer iDeckId!=iEnd; 13295a18594SAndre Fischer ++iDeckId) 133ff12d537SAndre Fischer { 13495a18594SAndre Fischer const DeckDescriptor* pDescriptor = ResourceManager::Instance().GetDeckDescriptor(*iDeckId); 13595a18594SAndre Fischer if (pDescriptor == NULL) 13695a18594SAndre Fischer { 13795a18594SAndre Fischer OSL_ASSERT(pDescriptor!=NULL); 13895a18594SAndre Fischer continue; 13995a18594SAndre Fischer } 14095a18594SAndre Fischer 141ff12d537SAndre Fischer Item& rItem (maItems[nIndex++]); 14295a18594SAndre Fischer rItem.msDeckId = pDescriptor->msId; 143*7a32b0c8SAndre Fischer rItem.mpButton.reset(CreateTabItem(*pDescriptor)); 144ff12d537SAndre Fischer rItem.mpButton->SetClickHdl(LINK(&rItem, TabBar::Item, HandleClick)); 145ff12d537SAndre Fischer rItem.maDeckActivationFunctor = maDeckActivationFunctor; 146ff12d537SAndre Fischer rItem.mbIsHiddenByDefault = false; 14795a18594SAndre Fischer rItem.mbIsHidden = ! pDescriptor->mbIsEnabled; 148ff12d537SAndre Fischer } 149ff12d537SAndre Fischer 150ff12d537SAndre Fischer UpdateButtonIcons(); 151ff12d537SAndre Fischer Layout(); 152ff12d537SAndre Fischer } 153ff12d537SAndre Fischer 154ff12d537SAndre Fischer 155ff12d537SAndre Fischer 156ff12d537SAndre Fischer 157ff12d537SAndre Fischer void TabBar::UpdateButtonIcons (void) 158ff12d537SAndre Fischer { 159ff12d537SAndre Fischer const BmpColorMode eColorMode ( 160ff12d537SAndre Fischer Theme::IsHighContrastMode() 161ff12d537SAndre Fischer ? BMP_COLOR_HIGHCONTRAST 162ff12d537SAndre Fischer : BMP_COLOR_NORMAL); 163ff12d537SAndre Fischer 164*7a32b0c8SAndre Fischer mpMenuButton->SetModeImage(Theme::GetImage(Theme::Image_TabBarMenu), eColorMode); 165ff12d537SAndre Fischer 166ff12d537SAndre Fischer for(ItemContainer::const_iterator 167ff12d537SAndre Fischer iItem(maItems.begin()), iEnd(maItems.end()); 168ff12d537SAndre Fischer iItem!=iEnd; 169ff12d537SAndre Fischer ++iItem) 170ff12d537SAndre Fischer { 17195a18594SAndre Fischer const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(iItem->msDeckId); 17295a18594SAndre Fischer if (pDeckDescriptor != NULL) 17395a18594SAndre Fischer iItem->mpButton->SetModeImage( 17495a18594SAndre Fischer GetItemImage(*pDeckDescriptor), 17595a18594SAndre Fischer eColorMode); 176ff12d537SAndre Fischer } 17795a18594SAndre Fischer 17895a18594SAndre Fischer Invalidate(); 179ff12d537SAndre Fischer } 180ff12d537SAndre Fischer 181ff12d537SAndre Fischer 182ff12d537SAndre Fischer 183ff12d537SAndre Fischer 184ff12d537SAndre Fischer void TabBar::Layout (void) 185ff12d537SAndre Fischer { 186b9e67834SAndre Fischer const SvBorder aPadding ( 187b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_TabBarLeftPadding), 188b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_TabBarTopPadding), 189b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_TabBarRightPadding), 190b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_TabBarBottomPadding)); 191ff12d537SAndre Fischer sal_Int32 nX (aPadding.Top()); 192ff12d537SAndre Fischer sal_Int32 nY (aPadding.Left()); 193b9e67834SAndre Fischer const Size aTabItemSize ( 194b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_TabItemWidth), 195b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_TabItemHeight)); 196ff12d537SAndre Fischer 19795a18594SAndre Fischer // Place the menu button and the separator. 198ff12d537SAndre Fischer if (mpMenuButton != NULL) 199ff12d537SAndre Fischer { 200ff12d537SAndre Fischer mpMenuButton->SetPosSizePixel( 201ff12d537SAndre Fischer Point(nX,nY), 202b9e67834SAndre Fischer aTabItemSize); 203ff12d537SAndre Fischer mpMenuButton->Show(); 204b9e67834SAndre Fischer nY += mpMenuButton->GetSizePixel().Height() + 1 + Theme::GetInteger(Theme::Int_TabMenuPadding); 205b9e67834SAndre Fischer mnMenuSeparatorY = nY - Theme::GetInteger(Theme::Int_TabMenuPadding)/2 - 1; 206ff12d537SAndre Fischer } 20795a18594SAndre Fischer 20895a18594SAndre Fischer // Place the deck selection buttons. 209ff12d537SAndre Fischer for(ItemContainer::const_iterator 210ff12d537SAndre Fischer iItem(maItems.begin()), iEnd(maItems.end()); 211ff12d537SAndre Fischer iItem!=iEnd; 212ff12d537SAndre Fischer ++iItem) 213ff12d537SAndre Fischer { 21495a18594SAndre Fischer Button& rButton (*iItem->mpButton); 21595a18594SAndre Fischer rButton.Show( ! iItem->mbIsHidden); 21695a18594SAndre Fischer 217ff12d537SAndre Fischer if (iItem->mbIsHidden) 218ff12d537SAndre Fischer continue; 219ff12d537SAndre Fischer 220ff12d537SAndre Fischer // Place and size the icon. 221ff12d537SAndre Fischer rButton.SetPosSizePixel( 222ff12d537SAndre Fischer Point(nX,nY), 223b9e67834SAndre Fischer aTabItemSize); 224ff12d537SAndre Fischer rButton.Show(); 225ff12d537SAndre Fischer 226ff12d537SAndre Fischer nY += rButton.GetSizePixel().Height() + 1 + aPadding.Bottom(); 227ff12d537SAndre Fischer } 228ff12d537SAndre Fischer Invalidate(); 229ff12d537SAndre Fischer } 230ff12d537SAndre Fischer 231ff12d537SAndre Fischer 232ff12d537SAndre Fischer 233ff12d537SAndre Fischer 234ff12d537SAndre Fischer void TabBar::HighlightDeck (const ::rtl::OUString& rsDeckId) 235ff12d537SAndre Fischer { 236ff12d537SAndre Fischer for (ItemContainer::const_iterator iItem(maItems.begin()),iEnd(maItems.end()); 237ff12d537SAndre Fischer iItem!=iEnd; 238ff12d537SAndre Fischer ++iItem) 239ff12d537SAndre Fischer { 24095a18594SAndre Fischer if (iItem->msDeckId.equals(rsDeckId)) 241ff12d537SAndre Fischer { 242ff12d537SAndre Fischer iItem->mpButton->Check(); 243ff12d537SAndre Fischer break; 244ff12d537SAndre Fischer } 245ff12d537SAndre Fischer } 246ff12d537SAndre Fischer } 247ff12d537SAndre Fischer 248ff12d537SAndre Fischer 249ff12d537SAndre Fischer 250ff12d537SAndre Fischer 251ff12d537SAndre Fischer void TabBar::DataChanged (const DataChangedEvent& rDataChangedEvent) 252ff12d537SAndre Fischer { 25395a18594SAndre Fischer SetBackground(Theme::GetPaint(Theme::Paint_TabBarBackground).GetWallpaper()); 25495a18594SAndre Fischer UpdateButtonIcons(); 25595a18594SAndre Fischer 25695a18594SAndre Fischer Window::DataChanged(rDataChangedEvent); 257ff12d537SAndre Fischer } 258ff12d537SAndre Fischer 259ff12d537SAndre Fischer 260ff12d537SAndre Fischer 261ff12d537SAndre Fischer 262ff12d537SAndre Fischer RadioButton* TabBar::CreateTabItem (const DeckDescriptor& rDeckDescriptor) 263ff12d537SAndre Fischer { 264ff12d537SAndre Fischer RadioButton* pItem = ControlFactory::CreateTabItem(this); 265ff12d537SAndre Fischer pItem->SetHelpText(rDeckDescriptor.msHelpText); 266ff12d537SAndre Fischer pItem->SetQuickHelpText(rDeckDescriptor.msHelpText); 267ff12d537SAndre Fischer 268ff12d537SAndre Fischer return pItem; 26922de8995SAndre Fischer } 27022de8995SAndre Fischer 27122de8995SAndre Fischer 272ff12d537SAndre Fischer 273ff12d537SAndre Fischer Image TabBar::GetItemImage (const DeckDescriptor& rDeckDescriptor) const 274ff12d537SAndre Fischer { 275b9e67834SAndre Fischer return Tools::GetImage( 276b9e67834SAndre Fischer rDeckDescriptor.msIconURL, 277b9e67834SAndre Fischer rDeckDescriptor.msHighContrastIconURL, 278b9e67834SAndre Fischer mxFrame); 279ff12d537SAndre Fischer } 280ff12d537SAndre Fischer 281ff12d537SAndre Fischer 282ff12d537SAndre Fischer 283ff12d537SAndre Fischer 284ff12d537SAndre Fischer 28595a18594SAndre Fischer IMPL_LINK(TabBar::Item, HandleClick, Button*, EMPTYARG) 286ff12d537SAndre Fischer { 28795a18594SAndre Fischer maDeckActivationFunctor(msDeckId); 28895a18594SAndre Fischer return 1; 289ff12d537SAndre Fischer } 290ff12d537SAndre Fischer 291ff12d537SAndre Fischer 292ff12d537SAndre Fischer 293ff12d537SAndre Fischer 29495a18594SAndre Fischer const ::rtl::OUString TabBar::GetDeckIdForIndex (const sal_Int32 nIndex) const 295ff12d537SAndre Fischer { 29695a18594SAndre Fischer if (nIndex<0 || static_cast<size_t>(nIndex)>=maItems.size()) 297ff12d537SAndre Fischer throw RuntimeException(); 298ff12d537SAndre Fischer else 29995a18594SAndre Fischer return maItems[nIndex].msDeckId; 300ff12d537SAndre Fischer } 301ff12d537SAndre Fischer 302ff12d537SAndre Fischer 303ff12d537SAndre Fischer 304ff12d537SAndre Fischer 305ff12d537SAndre Fischer void TabBar::ToggleHideFlag (const sal_Int32 nIndex) 306ff12d537SAndre Fischer { 30795a18594SAndre Fischer if (nIndex<0 || static_cast<size_t>(nIndex)>=maItems.size()) 308ff12d537SAndre Fischer throw RuntimeException(); 309ff12d537SAndre Fischer else 310ff12d537SAndre Fischer { 311ff12d537SAndre Fischer maItems[nIndex].mbIsHidden = ! maItems[nIndex].mbIsHidden; 31295a18594SAndre Fischer ResourceManager::Instance().SetIsDeckEnabled( 31395a18594SAndre Fischer maItems[nIndex].msDeckId, 31495a18594SAndre Fischer maItems[nIndex].mbIsHidden); 315ff12d537SAndre Fischer Layout(); 316ff12d537SAndre Fischer } 317ff12d537SAndre Fischer } 318ff12d537SAndre Fischer 319ff12d537SAndre Fischer 320ff12d537SAndre Fischer 321ff12d537SAndre Fischer 322ff12d537SAndre Fischer void TabBar::RestoreHideFlags (void) 323ff12d537SAndre Fischer { 324ff12d537SAndre Fischer bool bNeedsLayout (false); 325ff12d537SAndre Fischer for(ItemContainer::iterator iItem(maItems.begin()),iEnd(maItems.end()); 326ff12d537SAndre Fischer iItem!=iEnd; 327ff12d537SAndre Fischer ++iItem) 328ff12d537SAndre Fischer { 329ff12d537SAndre Fischer if (iItem->mbIsHidden != iItem->mbIsHiddenByDefault) 330ff12d537SAndre Fischer { 331ff12d537SAndre Fischer iItem->mbIsHidden = iItem->mbIsHiddenByDefault; 332ff12d537SAndre Fischer bNeedsLayout = true; 333ff12d537SAndre Fischer } 334ff12d537SAndre Fischer } 335ff12d537SAndre Fischer if (bNeedsLayout) 336ff12d537SAndre Fischer Layout(); 337ff12d537SAndre Fischer } 338ff12d537SAndre Fischer 339ff12d537SAndre Fischer 340ff12d537SAndre Fischer 341ff12d537SAndre Fischer 34295a18594SAndre Fischer IMPL_LINK(TabBar, OnToolboxClicked, void*, EMPTYARG) 343ff12d537SAndre Fischer { 34495a18594SAndre Fischer ::std::vector<DeckMenuData> aSelectionData; 34595a18594SAndre Fischer ::std::vector<DeckMenuData> aShowData; 34695a18594SAndre Fischer 34795a18594SAndre Fischer for(ItemContainer::const_iterator iItem(maItems.begin()),iEnd(maItems.end()); 34895a18594SAndre Fischer iItem!=iEnd; 34995a18594SAndre Fischer ++iItem) 35095a18594SAndre Fischer { 35195a18594SAndre Fischer const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(iItem->msDeckId); 35295a18594SAndre Fischer if (pDeckDescriptor != NULL) 35395a18594SAndre Fischer { 35495a18594SAndre Fischer if ( ! iItem->mbIsHidden) 35595a18594SAndre Fischer aSelectionData.push_back( 35695a18594SAndre Fischer DeckMenuData( 35795a18594SAndre Fischer pDeckDescriptor->msTitle, 35895a18594SAndre Fischer pDeckDescriptor->msId, 35995a18594SAndre Fischer iItem->mpButton->IsChecked())); 36095a18594SAndre Fischer 36195a18594SAndre Fischer aShowData.push_back( 36295a18594SAndre Fischer DeckMenuData( 36395a18594SAndre Fischer pDeckDescriptor->msTitle, 36495a18594SAndre Fischer pDeckDescriptor->msId, 36595a18594SAndre Fischer !iItem->mbIsHidden)); 36695a18594SAndre Fischer } 36795a18594SAndre Fischer } 36895a18594SAndre Fischer 369ff12d537SAndre Fischer maPopupMenuProvider( 370ff12d537SAndre Fischer Rectangle( 371ff12d537SAndre Fischer mpMenuButton->GetPosPixel(), 37295a18594SAndre Fischer mpMenuButton->GetSizePixel()), 37395a18594SAndre Fischer aSelectionData, 37495a18594SAndre Fischer aShowData); 375ff12d537SAndre Fischer 376ff12d537SAndre Fischer return 0; 377ff12d537SAndre Fischer } 378ff12d537SAndre Fischer 379ff12d537SAndre Fischer 380ff12d537SAndre Fischer 381ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar 382