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" 26*95a18594SAndre 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> 34ff12d537SAndre Fischer #include <comphelper/processfactory.hxx> 35ff12d537SAndre Fischer #include <comphelper/componentcontext.hxx> 36*95a18594SAndre Fischer #include <tools/svborder.hxx> 37ff12d537SAndre Fischer 38ff12d537SAndre Fischer #include <com/sun/star/graphic/XGraphicProvider.hpp> 39ff12d537SAndre Fischer 40ff12d537SAndre Fischer 41ff12d537SAndre Fischer using namespace ::com::sun::star; 42ff12d537SAndre Fischer using namespace ::com::sun::star::uno; 43ff12d537SAndre Fischer 44ff12d537SAndre Fischer 45ff12d537SAndre Fischer 4622de8995SAndre Fischer 47ff12d537SAndre Fischer namespace sfx2 { namespace sidebar { 4822de8995SAndre Fischer 49ff12d537SAndre Fischer TabBar::TabBar ( 50ff12d537SAndre Fischer Window* pParentWindow, 51ff12d537SAndre Fischer const Reference<frame::XFrame>& rxFrame, 52*95a18594SAndre Fischer const ::boost::function<void(const ::rtl::OUString&)>& rDeckActivationFunctor, 53*95a18594SAndre Fischer const PopupMenuProvider& rPopupMenuProvider) 54ff12d537SAndre Fischer : Window(pParentWindow), 55ff12d537SAndre Fischer mxFrame(rxFrame), 56ff12d537SAndre Fischer mpMenuButton(ControlFactory::CreateMenuButton(this)), 57ff12d537SAndre Fischer maItems(), 58ff12d537SAndre Fischer maDeckActivationFunctor(rDeckActivationFunctor), 59ff12d537SAndre Fischer maPopupMenuProvider(rPopupMenuProvider) 6022de8995SAndre Fischer { 61b9e67834SAndre Fischer SetBackground(Theme::GetPaint(Theme::Paint_TabBarBackground).GetWallpaper()); 62ff12d537SAndre Fischer 63ff12d537SAndre Fischer mpMenuButton->SetHelpText(A2S("This is the menu button")); 64ff12d537SAndre Fischer mpMenuButton->SetQuickHelpText(A2S("This is the menu button")); 65ff12d537SAndre Fischer mpMenuButton->SetModeImage( 66b9e67834SAndre Fischer Theme::GetImage(Theme::Image_Menu), 67ff12d537SAndre Fischer Theme::IsHighContrastMode() 68ff12d537SAndre Fischer ? BMP_COLOR_HIGHCONTRAST 69ff12d537SAndre Fischer : BMP_COLOR_NORMAL); 70ff12d537SAndre Fischer mpMenuButton->SetClickHdl(LINK(this, TabBar, OnToolboxClicked)); 71*95a18594SAndre Fischer Layout(); 7222de8995SAndre Fischer } 7322de8995SAndre Fischer 7422de8995SAndre Fischer 7522de8995SAndre Fischer 7622de8995SAndre Fischer 7722de8995SAndre Fischer TabBar::~TabBar (void) 7822de8995SAndre Fischer { 7922de8995SAndre Fischer } 8022de8995SAndre Fischer 8122de8995SAndre Fischer 8222de8995SAndre Fischer 8322de8995SAndre Fischer 8422de8995SAndre Fischer void TabBar::Paint (const Rectangle& rUpdateArea) 8522de8995SAndre Fischer { 86ff12d537SAndre Fischer Window::Paint(rUpdateArea); 87ff12d537SAndre Fischer 88b9e67834SAndre Fischer const sal_Int32 nHorizontalPadding (Theme::GetInteger(Theme::Int_TabMenuSeparatorPadding)); 89b9e67834SAndre Fischer SetLineColor(Theme::GetColor(Theme::Color_TabMenuSeparator)); 90ff12d537SAndre Fischer DrawLine( 91ff12d537SAndre Fischer Point(nHorizontalPadding, mnMenuSeparatorY), 92ff12d537SAndre Fischer Point(GetSizePixel().Width()-nHorizontalPadding, mnMenuSeparatorY)); 9322de8995SAndre Fischer } 9422de8995SAndre Fischer 9522de8995SAndre Fischer 9622de8995SAndre Fischer 9722de8995SAndre Fischer 9822de8995SAndre Fischer sal_Int32 TabBar::GetDefaultWidth (void) 9922de8995SAndre Fischer { 100b9e67834SAndre Fischer return Theme::GetInteger(Theme::Int_TabItemWidth) 101b9e67834SAndre Fischer + Theme::GetInteger(Theme::Int_TabBarLeftPadding) 102b9e67834SAndre Fischer + Theme::GetInteger(Theme::Int_TabBarRightPadding); 103ff12d537SAndre Fischer } 104ff12d537SAndre Fischer 105ff12d537SAndre Fischer 106ff12d537SAndre Fischer 107ff12d537SAndre Fischer 108ff12d537SAndre Fischer void TabBar::SetDecks ( 109*95a18594SAndre Fischer const ResourceManager::IdContainer& rDeckIds) 110ff12d537SAndre Fischer { 111ff12d537SAndre Fischer // Remove the current buttons. 112ff12d537SAndre Fischer { 113ff12d537SAndre Fischer Window aTemporaryParent (NULL,0); 114ff12d537SAndre Fischer for(ItemContainer::const_iterator 115ff12d537SAndre Fischer iItem(maItems.begin()), iEnd(maItems.end()); 116ff12d537SAndre Fischer iItem!=iEnd; 117ff12d537SAndre Fischer ++iItem) 118ff12d537SAndre Fischer { 119ff12d537SAndre Fischer removeWindow(iItem->mpButton, &aTemporaryParent); 120ff12d537SAndre Fischer } 121ff12d537SAndre Fischer maItems.clear(); 122ff12d537SAndre Fischer } 123ff12d537SAndre Fischer 124*95a18594SAndre Fischer maItems.resize(rDeckIds.size()); 125ff12d537SAndre Fischer sal_Int32 nIndex (0); 126*95a18594SAndre Fischer for (ResourceManager::IdContainer::const_iterator 127*95a18594SAndre Fischer iDeckId(rDeckIds.begin()), 128*95a18594SAndre Fischer iEnd(rDeckIds.end()); 129*95a18594SAndre Fischer iDeckId!=iEnd; 130*95a18594SAndre Fischer ++iDeckId) 131ff12d537SAndre Fischer { 132*95a18594SAndre Fischer const DeckDescriptor* pDescriptor = ResourceManager::Instance().GetDeckDescriptor(*iDeckId); 133*95a18594SAndre Fischer if (pDescriptor == NULL) 134*95a18594SAndre Fischer { 135*95a18594SAndre Fischer OSL_ASSERT(pDescriptor!=NULL); 136*95a18594SAndre Fischer continue; 137*95a18594SAndre Fischer } 138*95a18594SAndre Fischer 139ff12d537SAndre Fischer Item& rItem (maItems[nIndex++]); 140*95a18594SAndre Fischer rItem.msDeckId = pDescriptor->msId; 141*95a18594SAndre Fischer rItem.mpButton = CreateTabItem(*pDescriptor); 142ff12d537SAndre Fischer rItem.mpButton->SetClickHdl(LINK(&rItem, TabBar::Item, HandleClick)); 143ff12d537SAndre Fischer rItem.maDeckActivationFunctor = maDeckActivationFunctor; 144ff12d537SAndre Fischer rItem.mbIsHiddenByDefault = false; 145*95a18594SAndre Fischer rItem.mbIsHidden = ! pDescriptor->mbIsEnabled; 146ff12d537SAndre Fischer } 147ff12d537SAndre Fischer 148ff12d537SAndre Fischer UpdateButtonIcons(); 149ff12d537SAndre Fischer Layout(); 150ff12d537SAndre Fischer } 151ff12d537SAndre Fischer 152ff12d537SAndre Fischer 153ff12d537SAndre Fischer 154ff12d537SAndre Fischer 155ff12d537SAndre Fischer void TabBar::UpdateButtonIcons (void) 156ff12d537SAndre Fischer { 157ff12d537SAndre Fischer const BmpColorMode eColorMode ( 158ff12d537SAndre Fischer Theme::IsHighContrastMode() 159ff12d537SAndre Fischer ? BMP_COLOR_HIGHCONTRAST 160ff12d537SAndre Fischer : BMP_COLOR_NORMAL); 161ff12d537SAndre Fischer 162b9e67834SAndre Fischer mpMenuButton->SetModeImage(Theme::GetImage(Theme::Image_Menu), eColorMode); 163ff12d537SAndre Fischer 164ff12d537SAndre Fischer for(ItemContainer::const_iterator 165ff12d537SAndre Fischer iItem(maItems.begin()), iEnd(maItems.end()); 166ff12d537SAndre Fischer iItem!=iEnd; 167ff12d537SAndre Fischer ++iItem) 168ff12d537SAndre Fischer { 169*95a18594SAndre Fischer const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(iItem->msDeckId); 170*95a18594SAndre Fischer if (pDeckDescriptor != NULL) 171*95a18594SAndre Fischer iItem->mpButton->SetModeImage( 172*95a18594SAndre Fischer GetItemImage(*pDeckDescriptor), 173*95a18594SAndre Fischer eColorMode); 174ff12d537SAndre Fischer } 175*95a18594SAndre Fischer 176*95a18594SAndre Fischer Invalidate(); 177ff12d537SAndre Fischer } 178ff12d537SAndre Fischer 179ff12d537SAndre Fischer 180ff12d537SAndre Fischer 181ff12d537SAndre Fischer 182ff12d537SAndre Fischer void TabBar::Layout (void) 183ff12d537SAndre Fischer { 184b9e67834SAndre Fischer const SvBorder aPadding ( 185b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_TabBarLeftPadding), 186b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_TabBarTopPadding), 187b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_TabBarRightPadding), 188b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_TabBarBottomPadding)); 189ff12d537SAndre Fischer sal_Int32 nX (aPadding.Top()); 190ff12d537SAndre Fischer sal_Int32 nY (aPadding.Left()); 191b9e67834SAndre Fischer const Size aTabItemSize ( 192b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_TabItemWidth), 193b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_TabItemHeight)); 194ff12d537SAndre Fischer 195*95a18594SAndre Fischer // Place the menu button and the separator. 196ff12d537SAndre Fischer if (mpMenuButton != NULL) 197ff12d537SAndre Fischer { 198ff12d537SAndre Fischer mpMenuButton->SetPosSizePixel( 199ff12d537SAndre Fischer Point(nX,nY), 200b9e67834SAndre Fischer aTabItemSize); 201ff12d537SAndre Fischer mpMenuButton->Show(); 202b9e67834SAndre Fischer nY += mpMenuButton->GetSizePixel().Height() + 1 + Theme::GetInteger(Theme::Int_TabMenuPadding); 203b9e67834SAndre Fischer mnMenuSeparatorY = nY - Theme::GetInteger(Theme::Int_TabMenuPadding)/2 - 1; 204ff12d537SAndre Fischer } 205*95a18594SAndre Fischer 206*95a18594SAndre Fischer // Place the deck selection buttons. 207ff12d537SAndre Fischer for(ItemContainer::const_iterator 208ff12d537SAndre Fischer iItem(maItems.begin()), iEnd(maItems.end()); 209ff12d537SAndre Fischer iItem!=iEnd; 210ff12d537SAndre Fischer ++iItem) 211ff12d537SAndre Fischer { 212*95a18594SAndre Fischer Button& rButton (*iItem->mpButton); 213*95a18594SAndre Fischer rButton.Show( ! iItem->mbIsHidden); 214*95a18594SAndre Fischer 215ff12d537SAndre Fischer if (iItem->mbIsHidden) 216ff12d537SAndre Fischer continue; 217ff12d537SAndre Fischer 218ff12d537SAndre Fischer // Place and size the icon. 219ff12d537SAndre Fischer rButton.SetPosSizePixel( 220ff12d537SAndre Fischer Point(nX,nY), 221b9e67834SAndre Fischer aTabItemSize); 222ff12d537SAndre Fischer rButton.Show(); 223ff12d537SAndre Fischer 224ff12d537SAndre Fischer nY += rButton.GetSizePixel().Height() + 1 + aPadding.Bottom(); 225ff12d537SAndre Fischer } 226ff12d537SAndre Fischer Invalidate(); 227ff12d537SAndre Fischer } 228ff12d537SAndre Fischer 229ff12d537SAndre Fischer 230ff12d537SAndre Fischer 231ff12d537SAndre Fischer 232ff12d537SAndre Fischer void TabBar::HighlightDeck (const ::rtl::OUString& rsDeckId) 233ff12d537SAndre Fischer { 234ff12d537SAndre Fischer for (ItemContainer::const_iterator iItem(maItems.begin()),iEnd(maItems.end()); 235ff12d537SAndre Fischer iItem!=iEnd; 236ff12d537SAndre Fischer ++iItem) 237ff12d537SAndre Fischer { 238*95a18594SAndre Fischer if (iItem->msDeckId.equals(rsDeckId)) 239ff12d537SAndre Fischer { 240ff12d537SAndre Fischer iItem->mpButton->Check(); 241ff12d537SAndre Fischer break; 242ff12d537SAndre Fischer } 243ff12d537SAndre Fischer } 244ff12d537SAndre Fischer } 245ff12d537SAndre Fischer 246ff12d537SAndre Fischer 247ff12d537SAndre Fischer 248ff12d537SAndre Fischer 249ff12d537SAndre Fischer void TabBar::DataChanged (const DataChangedEvent& rDataChangedEvent) 250ff12d537SAndre Fischer { 251*95a18594SAndre Fischer SetBackground(Theme::GetPaint(Theme::Paint_TabBarBackground).GetWallpaper()); 252*95a18594SAndre Fischer UpdateButtonIcons(); 253*95a18594SAndre Fischer 254*95a18594SAndre Fischer Window::DataChanged(rDataChangedEvent); 255ff12d537SAndre Fischer } 256ff12d537SAndre Fischer 257ff12d537SAndre Fischer 258ff12d537SAndre Fischer 259ff12d537SAndre Fischer 260ff12d537SAndre Fischer RadioButton* TabBar::CreateTabItem (const DeckDescriptor& rDeckDescriptor) 261ff12d537SAndre Fischer { 262ff12d537SAndre Fischer RadioButton* pItem = ControlFactory::CreateTabItem(this); 263ff12d537SAndre Fischer pItem->SetHelpText(rDeckDescriptor.msHelpText); 264ff12d537SAndre Fischer pItem->SetQuickHelpText(rDeckDescriptor.msHelpText); 265ff12d537SAndre Fischer 266ff12d537SAndre Fischer return pItem; 26722de8995SAndre Fischer } 26822de8995SAndre Fischer 26922de8995SAndre Fischer 270ff12d537SAndre Fischer 271ff12d537SAndre Fischer Image TabBar::GetItemImage (const DeckDescriptor& rDeckDescriptor) const 272ff12d537SAndre Fischer { 273b9e67834SAndre Fischer return Tools::GetImage( 274b9e67834SAndre Fischer rDeckDescriptor.msIconURL, 275b9e67834SAndre Fischer rDeckDescriptor.msHighContrastIconURL, 276b9e67834SAndre Fischer mxFrame); 277ff12d537SAndre Fischer } 278ff12d537SAndre Fischer 279ff12d537SAndre Fischer 280ff12d537SAndre Fischer 281ff12d537SAndre Fischer 282ff12d537SAndre Fischer 283*95a18594SAndre Fischer IMPL_LINK(TabBar::Item, HandleClick, Button*, EMPTYARG) 284ff12d537SAndre Fischer { 285*95a18594SAndre Fischer maDeckActivationFunctor(msDeckId); 286*95a18594SAndre Fischer return 1; 287ff12d537SAndre Fischer } 288ff12d537SAndre Fischer 289ff12d537SAndre Fischer 290ff12d537SAndre Fischer 291ff12d537SAndre Fischer 292*95a18594SAndre Fischer const ::rtl::OUString TabBar::GetDeckIdForIndex (const sal_Int32 nIndex) const 293ff12d537SAndre Fischer { 294*95a18594SAndre Fischer if (nIndex<0 || static_cast<size_t>(nIndex)>=maItems.size()) 295ff12d537SAndre Fischer throw RuntimeException(); 296ff12d537SAndre Fischer else 297*95a18594SAndre Fischer return maItems[nIndex].msDeckId; 298ff12d537SAndre Fischer } 299ff12d537SAndre Fischer 300ff12d537SAndre Fischer 301ff12d537SAndre Fischer 302ff12d537SAndre Fischer 303ff12d537SAndre Fischer void TabBar::ToggleHideFlag (const sal_Int32 nIndex) 304ff12d537SAndre Fischer { 305*95a18594SAndre Fischer if (nIndex<0 || static_cast<size_t>(nIndex)>=maItems.size()) 306ff12d537SAndre Fischer throw RuntimeException(); 307ff12d537SAndre Fischer else 308ff12d537SAndre Fischer { 309ff12d537SAndre Fischer maItems[nIndex].mbIsHidden = ! maItems[nIndex].mbIsHidden; 310*95a18594SAndre Fischer ResourceManager::Instance().SetIsDeckEnabled( 311*95a18594SAndre Fischer maItems[nIndex].msDeckId, 312*95a18594SAndre Fischer maItems[nIndex].mbIsHidden); 313ff12d537SAndre Fischer Layout(); 314ff12d537SAndre Fischer } 315ff12d537SAndre Fischer } 316ff12d537SAndre Fischer 317ff12d537SAndre Fischer 318ff12d537SAndre Fischer 319ff12d537SAndre Fischer 320ff12d537SAndre Fischer void TabBar::RestoreHideFlags (void) 321ff12d537SAndre Fischer { 322ff12d537SAndre Fischer bool bNeedsLayout (false); 323ff12d537SAndre Fischer for(ItemContainer::iterator iItem(maItems.begin()),iEnd(maItems.end()); 324ff12d537SAndre Fischer iItem!=iEnd; 325ff12d537SAndre Fischer ++iItem) 326ff12d537SAndre Fischer { 327ff12d537SAndre Fischer if (iItem->mbIsHidden != iItem->mbIsHiddenByDefault) 328ff12d537SAndre Fischer { 329ff12d537SAndre Fischer iItem->mbIsHidden = iItem->mbIsHiddenByDefault; 330ff12d537SAndre Fischer bNeedsLayout = true; 331ff12d537SAndre Fischer } 332ff12d537SAndre Fischer } 333ff12d537SAndre Fischer if (bNeedsLayout) 334ff12d537SAndre Fischer Layout(); 335ff12d537SAndre Fischer } 336ff12d537SAndre Fischer 337ff12d537SAndre Fischer 338ff12d537SAndre Fischer 339ff12d537SAndre Fischer 340*95a18594SAndre Fischer IMPL_LINK(TabBar, OnToolboxClicked, void*, EMPTYARG) 341ff12d537SAndre Fischer { 342*95a18594SAndre Fischer ::std::vector<DeckMenuData> aSelectionData; 343*95a18594SAndre Fischer ::std::vector<DeckMenuData> aShowData; 344*95a18594SAndre Fischer 345*95a18594SAndre Fischer for(ItemContainer::const_iterator iItem(maItems.begin()),iEnd(maItems.end()); 346*95a18594SAndre Fischer iItem!=iEnd; 347*95a18594SAndre Fischer ++iItem) 348*95a18594SAndre Fischer { 349*95a18594SAndre Fischer const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(iItem->msDeckId); 350*95a18594SAndre Fischer if (pDeckDescriptor != NULL) 351*95a18594SAndre Fischer { 352*95a18594SAndre Fischer if ( ! iItem->mbIsHidden) 353*95a18594SAndre Fischer aSelectionData.push_back( 354*95a18594SAndre Fischer DeckMenuData( 355*95a18594SAndre Fischer pDeckDescriptor->msTitle, 356*95a18594SAndre Fischer pDeckDescriptor->msId, 357*95a18594SAndre Fischer iItem->mpButton->IsChecked())); 358*95a18594SAndre Fischer 359*95a18594SAndre Fischer aShowData.push_back( 360*95a18594SAndre Fischer DeckMenuData( 361*95a18594SAndre Fischer pDeckDescriptor->msTitle, 362*95a18594SAndre Fischer pDeckDescriptor->msId, 363*95a18594SAndre Fischer !iItem->mbIsHidden)); 364*95a18594SAndre Fischer } 365*95a18594SAndre Fischer } 366*95a18594SAndre Fischer 367ff12d537SAndre Fischer maPopupMenuProvider( 368ff12d537SAndre Fischer Rectangle( 369ff12d537SAndre Fischer mpMenuButton->GetPosPixel(), 370*95a18594SAndre Fischer mpMenuButton->GetSizePixel()), 371*95a18594SAndre Fischer aSelectionData, 372*95a18594SAndre Fischer aShowData); 373ff12d537SAndre Fischer 374ff12d537SAndre Fischer return 0; 375ff12d537SAndre Fischer } 376ff12d537SAndre Fischer 377ff12d537SAndre Fischer 378ff12d537SAndre Fischer 379ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar 380