LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/ribbar - workctrl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 16 370 4.3 %
Date: 2013-07-09 Functions: 7 56 12.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <string>
      21             : #include <comphelper/string.hxx>
      22             : #include <svl/eitem.hxx>
      23             : #include <sfx2/htmlmode.hxx>
      24             : #include <sfx2/dispatch.hxx>
      25             : #include <sfx2/bindings.hxx>
      26             : #include <sfx2/imagemgr.hxx>
      27             : #include <swmodule.hxx>
      28             : #include <view.hxx>
      29             : #include <initui.hxx>
      30             : #include <viewopt.hxx>
      31             : #include <docsh.hxx>
      32             : #include <gloshdl.hxx>
      33             : #include <glosdoc.hxx>
      34             : #include <gloslst.hxx>
      35             : #include <workctrl.hxx>
      36             : #include <workctrl.hrc>
      37             : #include <cmdid.h>
      38             : #include <helpid.h>
      39             : #include <wrtsh.hxx>
      40             : #include <svl/imageitm.hxx>
      41             : #include <vcl/lstbox.hxx>
      42             : #include <rtl/ustring.hxx>
      43             : #include "swabstdlg.hxx"
      44             : #include <misc.hrc>
      45             : 
      46             : #include <vcl/svapp.hxx>
      47             : 
      48             : // Size check
      49             : #define NAVI_ENTRIES 20
      50             : #if NAVI_ENTRIES != NID_COUNT
      51             : #error SwScrollNaviPopup-CTOR static array wrong size. Are new IDs added?
      52             : #endif
      53             : 
      54             : using namespace ::com::sun::star;
      55             : using namespace ::com::sun::star::uno;
      56             : using namespace ::com::sun::star::beans;
      57             : using namespace ::com::sun::star::frame;
      58             : 
      59          66 : SFX_IMPL_TOOLBOX_CONTROL( SwTbxInsertCtrl, SfxImageItem);
      60          66 : SFX_IMPL_TOOLBOX_CONTROL( SwTbxAutoTextCtrl, SfxBoolItem );
      61             : 
      62           0 : SwTbxInsertCtrl::SwTbxInsertCtrl(
      63             :     sal_uInt16 nSlotId,
      64             :     sal_uInt16 nId,
      65             :     ToolBox& rTbx ) :
      66             :         SfxToolBoxControl( nSlotId, nId, rTbx ),
      67           0 :         nLastSlotId(FN_INSERT_CTRL == nSlotId ? FN_INSERT_TABLE : SID_INSERT_DIAGRAM)
      68             : {
      69           0 :     rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
      70           0 : }
      71             : 
      72           0 : SwTbxInsertCtrl::~SwTbxInsertCtrl()
      73             : {
      74           0 : }
      75             : 
      76           0 : void SAL_CALL SwTbxInsertCtrl::update() throw (uno::RuntimeException)
      77             : {
      78           0 :     ToolBox& rTbx = GetToolBox();
      79           0 :     OUString aSlotURL( "slot:" );
      80           0 :     aSlotURL += OUString::valueOf( sal_Int32( nLastSlotId ));
      81           0 :     Image aImage = GetImage( m_xFrame, aSlotURL, hasBigImages() );
      82             : 
      83           0 :     rTbx.SetItemImage(GetId(), aImage);
      84           0 :     rTbx.Invalidate();
      85             : 
      86           0 :     SfxToolBoxControl::update();
      87           0 : }
      88             : 
      89           0 : void SwTbxInsertCtrl::StateChanged( sal_uInt16 /*nSID*/,
      90             :                                       SfxItemState eState,
      91             :                                       const SfxPoolItem* pState )
      92             : {
      93           0 :     sal_uInt16 nId = GetId();
      94           0 :     GetToolBox().EnableItem( nId, (GetItemState(pState) != SFX_ITEM_DISABLED) );
      95             : 
      96           0 :     if( eState == SFX_ITEM_AVAILABLE )
      97             :     {
      98           0 :         const SfxImageItem* pItem = PTR_CAST( SfxImageItem, pState );
      99           0 :         if(pItem)
     100             :         {
     101           0 :             nLastSlotId = pItem->GetValue();
     102           0 :             if( nLastSlotId )
     103           0 :                 nId = nLastSlotId;
     104             : 
     105           0 :             OUString aSlotURL( "slot:" );
     106           0 :             aSlotURL += OUString::valueOf( sal_Int32( nId ));
     107           0 :             ToolBox& rBox = GetToolBox();
     108           0 :             Image aImage = GetImage( m_xFrame, aSlotURL, hasBigImages() );
     109           0 :             rBox.SetItemImage(GetId(), aImage);
     110           0 :             rBox.SetItemImageMirrorMode( GetId(), sal_False );
     111           0 :             rBox.SetItemImageAngle( GetId(), pItem->GetRotation() );
     112           0 :             rBox.SetItemImageMirrorMode( GetId(), pItem->IsMirrored() );
     113             :         }
     114             :     }
     115             : 
     116           0 : }
     117             : 
     118           0 : SfxPopupWindow* SwTbxInsertCtrl::CreatePopupWindow()
     119             : {
     120           0 :     if(GetSlotId() == FN_INSERT_CTRL)
     121             :     {
     122           0 :         OUString aToolBarResStr( "private:resource/toolbar/insertbar" );
     123           0 :         createAndPositionSubToolBar( aToolBarResStr );
     124             :     }
     125             :     else /* FN_INSERT_OBJ_CTRL */
     126             :     {
     127           0 :         OUString aToolBarResStr( "private:resource/toolbar/insertobjectbar" );
     128           0 :         createAndPositionSubToolBar( aToolBarResStr );
     129             :     }
     130           0 :     return NULL;
     131             : }
     132             : 
     133           0 : SfxPopupWindowType  SwTbxInsertCtrl::GetPopupWindowType() const
     134             : {
     135           0 :     return nLastSlotId ? SFX_POPUPWINDOW_ONTIMEOUT : SFX_POPUPWINDOW_ONCLICK;
     136             : }
     137             : 
     138             : 
     139           0 : void SwTbxInsertCtrl::Select( sal_Bool /*bMod1*/ )
     140             : {
     141           0 :     if( nLastSlotId )
     142             :     {
     143           0 :         SfxViewShell*   pCurSh( SfxViewShell::Current() );
     144           0 :         SfxDispatcher*  pDispatch( 0 );
     145             : 
     146           0 :         if ( pCurSh )
     147             :         {
     148           0 :             SfxViewFrame*   pViewFrame = pCurSh->GetViewFrame();
     149           0 :             if ( pViewFrame )
     150           0 :                 pDispatch = pViewFrame->GetDispatcher();
     151             :         }
     152             : 
     153           0 :         if ( pDispatch )
     154           0 :             pDispatch->Execute(nLastSlotId);
     155             :     }
     156           0 : }
     157             : 
     158           0 : SwTbxAutoTextCtrl::SwTbxAutoTextCtrl(
     159             :     sal_uInt16 nSlotId,
     160             :     sal_uInt16 nId,
     161             :     ToolBox& rTbx ) :
     162             :     SfxToolBoxControl( nSlotId, nId, rTbx ),
     163             :     pPopup(0),
     164           0 :     pView(0)
     165             : {
     166           0 :     rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
     167           0 : }
     168             : 
     169           0 : SwTbxAutoTextCtrl::~SwTbxAutoTextCtrl()
     170             : {
     171           0 :     DelPopup();
     172           0 : }
     173             : 
     174           0 : SfxPopupWindow* SwTbxAutoTextCtrl::CreatePopupWindow()
     175             : {
     176           0 :     pView = ::GetActiveView();
     177           0 :     if(pView && !pView->GetDocShell()->IsReadOnly() &&
     178           0 :        !pView->GetWrtShell().HasReadonlySel() )
     179             :     {
     180           0 :         ToolBox& rBox = GetToolBox();
     181             : 
     182           0 :         Rectangle aItemRect( rBox.GetItemRect( GetId() ) );
     183           0 :         Point aPt(rBox.OutputToScreenPixel(aItemRect.TopLeft()));
     184           0 :         aPt.X() += aItemRect.GetWidth()/2;
     185           0 :         aPt.Y() += aItemRect.GetHeight()/2;
     186           0 :         if(pView)
     187             :         {
     188           0 :             Link aLnk = LINK(this, SwTbxAutoTextCtrl, PopupHdl);
     189             : 
     190           0 :             if (GetSlotId() == FN_INSERT_FIELD_CTRL)
     191             :             {
     192           0 :                 pPopup = new PopupMenu(SW_RES(RID_INSERT_FIELD_CTRL));
     193           0 :                 pPopup->SetSelectHdl(aLnk);
     194             : 
     195           0 :                 if (::GetHtmlMode(pView->GetDocShell()) & HTMLMODE_ON)
     196             :                 {
     197           0 :                     pPopup->RemoveItem(pPopup->GetItemPos(FN_INSERT_FLD_PGCOUNT));
     198           0 :                     pPopup->RemoveItem(pPopup->GetItemPos(FN_INSERT_FLD_TOPIC));
     199             :                 }
     200             :             }
     201             :             else
     202             :             {
     203           0 :                 pPopup = new PopupMenu;
     204           0 :                 SwGlossaryList* pGlossaryList = ::GetGlossaryList();
     205           0 :                 sal_uInt16 nGroupCount = pGlossaryList->GetGroupCount();
     206           0 :                 for(sal_uInt16 i = 1; i <= nGroupCount; i++)
     207             :                 {
     208             :                     // Acquire group name with path extension
     209           0 :                     String sTitle;
     210           0 :                     sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i -1);
     211           0 :                     if(nBlockCount)
     212             :                     {
     213           0 :                         sal_uInt16 nIndex = 100 * (i);
     214             :                         // but insert without extension
     215           0 :                         pPopup->InsertItem( i, sTitle);
     216           0 :                         PopupMenu* pSub = new PopupMenu;
     217           0 :                         pSub->SetSelectHdl(aLnk);
     218           0 :                         pPopup->SetPopupMenu(i, pSub);
     219           0 :                         for(sal_uInt16 j = 0; j < nBlockCount; j++)
     220             :                         {
     221           0 :                             String sEntry;
     222           0 :                             String sLongName(pGlossaryList->GetBlockName(i - 1, j, sEntry));
     223           0 :                             sEntry.AppendAscii(" - ");
     224           0 :                             sEntry += sLongName;
     225           0 :                             pSub->InsertItem(++nIndex, sEntry);
     226           0 :                         }
     227             :                     }
     228           0 :                 }
     229             :             }
     230             :         }
     231           0 :         ToolBox* pToolBox = &GetToolBox();
     232           0 :         sal_uInt16 nId = GetId();
     233           0 :         pToolBox->SetItemDown( nId, sal_True );
     234             : 
     235           0 :         pPopup->Execute( pToolBox, pToolBox->GetItemRect( nId ),
     236           0 :             (pToolBox->GetAlign() == WINDOWALIGN_TOP || pToolBox->GetAlign() == WINDOWALIGN_BOTTOM) ?
     237           0 :                 POPUPMENU_EXECUTE_DOWN : POPUPMENU_EXECUTE_RIGHT );
     238             : 
     239           0 :         pToolBox->SetItemDown( nId, sal_False );
     240             :     }
     241           0 :     GetToolBox().EndSelection();
     242           0 :     DelPopup();
     243           0 :     return 0;
     244             : 
     245             : }
     246             : 
     247           0 : SfxPopupWindowType SwTbxAutoTextCtrl::GetPopupWindowType() const
     248             : {
     249           0 :     return SFX_POPUPWINDOW_ONTIMEOUT;
     250             : }
     251             : 
     252           0 : void SwTbxAutoTextCtrl::StateChanged( sal_uInt16 nSID,
     253             :                                               SfxItemState eState,
     254             :                                               const SfxPoolItem* pState )
     255             : {
     256           0 :     GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
     257           0 :     if(FN_INSERT_FIELD_CTRL == nSID && eState >= SFX_ITEM_DEFAULT)
     258             :     {
     259           0 :         GetToolBox().CheckItem( GetId(), ((SfxBoolItem*)pState)->GetValue() );
     260             :     }
     261           0 : }
     262             : 
     263           0 : IMPL_LINK(SwTbxAutoTextCtrl, PopupHdl, PopupMenu*, pMenu)
     264             : {
     265           0 :     sal_uInt16 nId = pMenu->GetCurItemId();
     266             : 
     267           0 :     if ( GetSlotId() == FN_INSERT_FIELD_CTRL)
     268             :     {
     269           0 :         Sequence< PropertyValue > aArgs;
     270           0 :         const char* pChar = 0;
     271           0 :         switch(nId)
     272             :         {
     273             :             case FN_INSERT_FLD_DATE:
     274           0 :                 pChar = ".uno:InsertDateField";
     275           0 :             break;
     276             :             case FN_INSERT_FLD_TIME:
     277           0 :                 pChar = ".uno:InsertTimeField";
     278           0 :             break;
     279             :             case FN_INSERT_FLD_PGNUMBER:
     280           0 :                 pChar = ".uno:InsertPageNumberField";
     281           0 :             break;
     282             :             case FN_INSERT_FLD_PGCOUNT:
     283           0 :                 pChar = ".uno:InsertPageCountField";
     284           0 :             break;
     285             :             case FN_INSERT_FLD_TOPIC:
     286           0 :                 pChar = ".uno:InsertTopicField";
     287           0 :             break;
     288             :             case FN_INSERT_FLD_TITLE:
     289           0 :                 pChar = ".uno:InsertTitleField";
     290           0 :             break;
     291             :             case FN_INSERT_FLD_AUTHOR:
     292           0 :                 pChar = ".uno:InsertAuthorField";
     293           0 :             break;
     294             :             default:
     295           0 :                 pChar = ".uno:InsertFieldCtrl";
     296             :         }
     297           0 :         Dispatch( OUString::createFromAscii( pChar ),aArgs );
     298             :     }
     299             :     else
     300             :     {
     301           0 :         sal_uInt16 nBlock = nId / 100;
     302             : 
     303           0 :         SwGlossaryList* pGlossaryList = ::GetGlossaryList();
     304           0 :         String sShortName;
     305           0 :         String sGroup = pGlossaryList->GetGroupName(nBlock - 1, false);
     306             : 
     307           0 :         SwGlossaryHdl* pGlosHdl = pView->GetGlosHdl();
     308           0 :         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     309             :         OSL_ENSURE(pFact, "Dialogdiet fail!");
     310           0 :         ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc();
     311           0 :         if ( fnSetActGroup )
     312           0 :             (*fnSetActGroup)( sGroup );
     313           0 :         pGlosHdl->SetCurGroup(sGroup, sal_True);
     314           0 :         pGlosHdl->InsertGlossary(sShortName);
     315             :     }
     316           0 :     return 0;
     317             : }
     318             : 
     319           0 : void SwTbxAutoTextCtrl::DelPopup()
     320             : {
     321           0 :     if(pPopup)
     322             :     {
     323           0 :         if (GetSlotId() != FN_INSERT_FIELD_CTRL)
     324             :         {
     325           0 :             for( sal_uInt16 i = 0; i < pPopup->GetItemCount(); i ++ )
     326             :             {
     327           0 :                 PopupMenu* pSubPopup = pPopup->GetPopupMenu(pPopup->GetItemId(i));
     328           0 :                 delete pSubPopup;
     329             :             }
     330             :         }
     331           0 :         delete pPopup;
     332           0 :         pPopup = 0;
     333             :     }
     334           0 : }
     335             : 
     336             : // Navigation-Popup
     337             : // determine the order of the toolbox items
     338             : static sal_uInt16 aNavigationInsertIds[ NAVI_ENTRIES ] =
     339             : {
     340             :     // -- first line
     341             :     NID_TBL,
     342             :     NID_FRM,
     343             :     NID_GRF,
     344             :     NID_OLE,
     345             :     NID_PGE,
     346             :     NID_OUTL,
     347             :     NID_MARK,
     348             :     NID_DRW,
     349             :     NID_CTRL,
     350             :     NID_PREV,
     351             :     // -- second line
     352             :     NID_REG,
     353             :     NID_BKM,
     354             :     NID_SEL,
     355             :     NID_FTN,
     356             :     NID_POSTIT,
     357             :     NID_SRCH_REP,
     358             :     NID_INDEX_ENTRY,
     359             :     NID_TABLE_FORMULA,
     360             :     NID_TABLE_FORMULA_ERROR,
     361             :     NID_NEXT
     362             : };
     363             : static const char* aNavigationHelpIds[ NAVI_ENTRIES ] =
     364             : {
     365             :     // -- first line
     366             :     HID_NID_TBL,
     367             :     HID_NID_FRM,
     368             :     HID_NID_GRF,
     369             :     HID_NID_OLE,
     370             :     HID_NID_PGE,
     371             :     HID_NID_OUTL,
     372             :     HID_NID_MARK,
     373             :     HID_NID_DRW,
     374             :     HID_NID_CTRL,
     375             :     HID_NID_PREV,
     376             :     // -- second line
     377             :     HID_NID_REG,
     378             :     HID_NID_BKM,
     379             :     HID_NID_SEL,
     380             :     HID_NID_FTN,
     381             :     HID_NID_POSTIT,
     382             :     HID_NID_SRCH_REP,
     383             :     HID_NID_INDEX_ENTRY,
     384             :     HID_NID_TABLE_FORMULA,
     385             :     HID_NID_TABLE_FORMULA_ERROR,
     386             :     HID_NID_NEXT
     387             : };
     388             : 
     389           0 : SwScrollNaviPopup::SwScrollNaviPopup( sal_uInt16 nId, const Reference< XFrame >& rFrame )
     390             :     : SfxPopupWindow(nId, rFrame, SW_RES(RID_SCROLL_NAVIGATION_WIN) ),
     391             :     aToolBox(this, 0),
     392             :     aSeparator(this, SW_RES(FL_SEP)),
     393             :     aInfoField(this, SW_RES(FI_INFO)),
     394           0 :     aIList(SW_RES(IL_VALUES))
     395             : {
     396             :     sal_uInt16 i;
     397             : 
     398           0 :     aToolBox.SetHelpId(HID_NAVI_VS);
     399           0 :     aToolBox.SetLineCount( 2 );
     400           0 :     aToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT);
     401           0 :     for( i = 0; i < NID_COUNT; i++)
     402             :     {
     403           0 :         sal_uInt16 nNaviId = aNavigationInsertIds[i];
     404           0 :         String sText;
     405           0 :         ToolBoxItemBits  nTbxBits = 0;
     406           0 :         if((NID_PREV != nNaviId) && (NID_NEXT != nNaviId))
     407             :         {
     408             :             // -2, there's no string for Next/Prev
     409           0 :             sal_uInt16 nResStr = ST_TBL - 2 + nNaviId - NID_START;
     410           0 :             sText = String(SW_RES(nResStr));
     411           0 :             nTbxBits = TIB_CHECKABLE;
     412             :         }
     413           0 :         aToolBox.InsertItem(nNaviId, sText, nTbxBits);
     414           0 :         aToolBox.SetHelpId( nNaviId, aNavigationHelpIds[i] );
     415           0 :     }
     416           0 :     ApplyImageList();
     417           0 :     aToolBox.InsertBreak(NID_COUNT/2);
     418             :     // don't call it before!
     419           0 :     FreeResource();
     420             : 
     421             :     // these are global strings
     422           0 :     for( i = 0; i < 2 * NID_COUNT; i++)
     423             :     {
     424           0 :         sQuickHelp[i] = String(SW_RES(STR_IMGBTN_START + i));
     425             :     }
     426             : 
     427           0 :     Size aImgSize = aIList.GetImageSize();
     428           0 :     aImgSize.Width() += 5;
     429           0 :     aImgSize.Height() += 5;
     430           0 :     Size aSz = aToolBox.CalcWindowSizePixel(2);
     431           0 :     aToolBox.SetPosSizePixel( Point(), aSz );
     432           0 :     sal_uInt16 nItemId = SwView::GetMoveType();
     433           0 :     aInfoField.SetText(aToolBox.GetItemText(nItemId));
     434           0 :     aToolBox.CheckItem( nItemId, sal_True );
     435           0 :     Size aFTSize(aInfoField.GetSizePixel());
     436           0 :     Size aSepSize(aSeparator.GetSizePixel());
     437           0 :     aSepSize.Width() = aSz.Width();
     438             : 
     439           0 :     aSz.Height() += aFTSize.Height() + aSepSize.Height();
     440             :     aInfoField.SetPosSizePixel(
     441           0 :         Point(0, aSz.Height() - aFTSize.Height()), Size(aSz.Width(), aFTSize.Height()));
     442             : 
     443           0 :     aSeparator.SetSizePixel(aSepSize);
     444           0 :     aSeparator.SetPosPixel(Point(0, aSz.Height() - aFTSize.Height() - aSepSize.Height()));
     445             : 
     446           0 :     SetOutputSizePixel(aSz);
     447           0 :     aToolBox.SetSelectHdl(LINK(this, SwScrollNaviPopup, SelectHdl));
     448           0 :     aToolBox.StartSelection();
     449           0 :     aToolBox.Show();
     450           0 : }
     451             : 
     452           0 : SwScrollNaviPopup::~SwScrollNaviPopup()
     453             : {
     454           0 : }
     455             : 
     456           0 : void SwScrollNaviPopup::DataChanged( const DataChangedEvent& rDCEvt )
     457             : {
     458           0 :     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
     459           0 :          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
     460           0 :             ApplyImageList();
     461             : 
     462           0 :     Window::DataChanged( rDCEvt );
     463           0 : }
     464             : 
     465           0 : void SwScrollNaviPopup::ApplyImageList()
     466             : {
     467           0 :     ImageList& rImgLst = aIList;
     468           0 :     for(sal_uInt16 i = 0; i < NID_COUNT; i++)
     469             :     {
     470           0 :         sal_uInt16 nNaviId = aNavigationInsertIds[i];
     471           0 :         aToolBox.SetItemImage(nNaviId, rImgLst.GetImage(nNaviId));
     472             :     }
     473           0 : }
     474             : 
     475           0 : SfxPopupWindow* SwScrollNaviPopup::Clone() const
     476             : {
     477           0 :     return new SwScrollNaviPopup( GetId(), GetFrame() );
     478             : }
     479             : 
     480           0 : IMPL_LINK(SwScrollNaviPopup, SelectHdl, ToolBox*, pSet)
     481             : {
     482           0 :     sal_uInt16 nSet = pSet->GetCurItemId();
     483           0 :     if( nSet != NID_PREV && nSet != NID_NEXT )
     484             :     {
     485           0 :         SwView::SetMoveType(nSet);
     486           0 :         aToolBox.SetItemText(NID_NEXT, sQuickHelp[nSet - NID_START]);
     487           0 :         aToolBox.SetItemText(NID_PREV, sQuickHelp[nSet - NID_START + NID_COUNT]);
     488           0 :         aInfoField.SetText(aToolBox.GetItemText(nSet));
     489             :         // check the current button only
     490           0 :         for(sal_uInt16 i = 0; i < NID_COUNT; i++)
     491             :         {
     492           0 :             sal_uInt16 nItemId = aToolBox.GetItemId( i );
     493           0 :             aToolBox.CheckItem( nItemId, nItemId == nSet );
     494           0 :         }
     495             :     }
     496             :     else
     497             :     {
     498           0 :         SfxBoolItem aNext(FN_SCROLL_NEXT_PREV, NID_NEXT == nSet);
     499           0 :         Any a;
     500           0 :         Sequence< PropertyValue > aArgs( 1 );
     501           0 :         aArgs[0].Name = OUString( "ScrollNextPrev" );
     502           0 :         aNext.QueryValue( a );
     503           0 :         aArgs[0].Value = a;
     504           0 :         SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( GetFrame()->getController(), UNO_QUERY ),
     505             :                                      OUString( ".uno:ScrollNextPrev" ),
     506           0 :                                      aArgs );
     507             :     }
     508           0 :     return 0;
     509             : }
     510             : 
     511           0 : void SwScrollNaviToolBox::MouseButtonUp( const MouseEvent& rMEvt )
     512             : {
     513           0 :     ToolBox::MouseButtonUp(rMEvt);
     514           0 :     if ( ((SwScrollNaviPopup*)GetParent())->IsInPopupMode() )
     515           0 :         ((SwScrollNaviPopup*)GetParent())->EndPopupMode( FLOATWIN_POPUPMODEEND_CLOSEALL );
     516           0 : }
     517             : 
     518           0 : void  SwScrollNaviToolBox::RequestHelp( const HelpEvent& rHEvt )
     519             : {
     520           0 :     SetItemText(NID_NEXT, SwScrollNaviPopup::GetQuickHelpText(sal_True));
     521           0 :     SetItemText(NID_PREV, SwScrollNaviPopup::GetQuickHelpText(sal_False));
     522           0 :     ToolBox::RequestHelp( rHEvt );
     523             : 
     524           0 : }
     525             : 
     526           0 : String  SwScrollNaviPopup::GetQuickHelpText(sal_Bool bNext)
     527             : {
     528           0 :     sal_uInt16 nResId = STR_IMGBTN_START;
     529           0 :     nResId += SwView::GetMoveType() - NID_START;
     530           0 :     if(!bNext)
     531           0 :         nResId += NID_COUNT;
     532           0 :     return String(SW_RES(nResId));
     533             : }
     534             : 
     535           0 : void SwNaviImageButton::Click()
     536             : {
     537             :     pPopup = new
     538             :         SwScrollNaviPopup( FN_SCROLL_NAVIGATION,
     539           0 :                            m_xFrame );
     540           0 :     Point aPos = OutputToScreenPixel(Point(0,0));
     541           0 :     Rectangle aRect(aPos, GetSizePixel());
     542           0 :     SetPopupWindow( pPopup );
     543           0 :     pPopup->StartPopupMode(aRect, FLOATWIN_POPUPMODE_LEFT|FLOATWIN_POPUPMODE_ALLOWTEAROFF);
     544           0 : }
     545             : 
     546           0 : void SwNaviImageButton::SetPopupWindow( SfxPopupWindow* pWindow )
     547             : {
     548           0 :     pPopupWindow = pWindow;
     549           0 :     pPopupWindow->SetPopupModeEndHdl( LINK( this, SwNaviImageButton, PopupModeEndHdl ));
     550           0 :     pPopupWindow->SetDeleteLink_Impl( LINK( this, SwNaviImageButton, ClosePopupWindow ));
     551           0 : }
     552             : 
     553           0 : IMPL_LINK_NOARG(SwNaviImageButton, PopupModeEndHdl)
     554             : {
     555           0 :     if ( pPopupWindow->IsVisible() )
     556             :     {
     557             :         // Replace floating window with popup window and destroy
     558             :         // floating window instance.
     559           0 :         delete pFloatingWindow;
     560           0 :         pFloatingWindow = pPopupWindow;
     561           0 :         pPopupWindow    = 0;
     562             :     }
     563             :     else
     564             :     {
     565             :         // Popup window has been closed by the user. No replacement, instance
     566             :         // will destroy itself.
     567           0 :         pPopupWindow = 0;
     568             :     }
     569             : 
     570           0 :     return 1;
     571             : }
     572             : 
     573           0 : IMPL_LINK( SwNaviImageButton, ClosePopupWindow, SfxPopupWindow *, pWindow )
     574             : {
     575           0 :     if ( pWindow == pFloatingWindow )
     576           0 :         pFloatingWindow = 0;
     577             :     else
     578           0 :         pPopupWindow = 0;
     579             : 
     580           0 :     return 1;
     581             : }
     582             : 
     583           0 : void SwHlpImageButton::RequestHelp( const HelpEvent& rHEvt )
     584             : {
     585             : 
     586           0 :     SetQuickHelpText(SwScrollNaviPopup::GetQuickHelpText(!bUp));
     587             : 
     588           0 :     ImageButton::RequestHelp(rHEvt);
     589           0 : }
     590             : 
     591         793 : SwNaviImageButton::SwNaviImageButton(
     592             :     Window* pParent,
     593             :     const Reference< XFrame >& rFrame ) :
     594             :     ImageButton(pParent, SW_RES(BTN_NAVI)),
     595             :         pPopup(0),
     596             :         aImage(SW_RES(IMG_BTN)),
     597             :         sQuickText(SW_RES(ST_QUICK)),
     598             :         pPopupWindow(0),
     599             :         pFloatingWindow(0),
     600         793 :         m_xFrame( rFrame )
     601             : {
     602         793 :     FreeResource();
     603         793 :     SetStyle(GetStyle()|WB_NOPOINTERFOCUS);
     604         793 :     SetQuickHelpText(sQuickText);
     605         793 :     SetModeImage( aImage );
     606         793 : }
     607             : 
     608           4 : void SwNaviImageButton::DataChanged( const DataChangedEvent& rDCEvt )
     609             : {
     610           8 :     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
     611           4 :          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
     612           0 :             SetModeImage( aImage );
     613             : 
     614           4 :     Window::DataChanged( rDCEvt );
     615           4 : }
     616             : 
     617             : class SwZoomBox_Impl : public ComboBox
     618             : {
     619             :     sal_uInt16          nSlotId;
     620             :     bool            bRelease;
     621             :     uno::Reference< frame::XDispatchProvider > m_xDispatchProvider;
     622             : 
     623             : public:
     624             :     SwZoomBox_Impl(
     625             :         Window* pParent,
     626             :         sal_uInt16 nSlot,
     627             :         const Reference< XDispatchProvider >& rDispatchProvider );
     628             :     ~SwZoomBox_Impl();
     629             : 
     630             : protected:
     631             :     virtual void    Select();
     632             :     virtual long    Notify( NotifyEvent& rNEvt );
     633             : 
     634             :     void ReleaseFocus();
     635             : 
     636             : };
     637             : 
     638           0 : SwZoomBox_Impl::SwZoomBox_Impl(
     639             :     Window* pParent,
     640             :     sal_uInt16 nSlot,
     641             :     const Reference< XDispatchProvider >& rDispatchProvider ):
     642             :     ComboBox( pParent, SW_RES(RID_PVIEW_ZOOM_LB)),
     643             :     nSlotId(nSlot),
     644             :     bRelease(true),
     645           0 :     m_xDispatchProvider( rDispatchProvider )
     646             : {
     647           0 :     EnableAutocomplete( sal_False );
     648             :     sal_uInt16 aZoomValues[] =
     649           0 :     {   25, 50, 75, 100, 150, 200 };
     650           0 :     for(sal_uInt16 i = 0; i < sizeof(aZoomValues)/sizeof(sal_uInt16); i++)
     651             :     {
     652           0 :         String sEntry = OUString::number(aZoomValues[i]);
     653           0 :         sEntry += '%';
     654           0 :         InsertEntry(sEntry);
     655           0 :     }
     656           0 : }
     657             : 
     658           0 : SwZoomBox_Impl::~SwZoomBox_Impl()
     659           0 : {}
     660             : 
     661           0 : void    SwZoomBox_Impl::Select()
     662             : {
     663           0 :     if ( !IsTravelSelect() )
     664             :     {
     665           0 :         String sEntry(comphelper::string::remove(GetText(), '%'));
     666           0 :         sal_uInt16 nZoom = (sal_uInt16)sEntry.ToInt32();
     667           0 :         if(nZoom < MINZOOM)
     668           0 :             nZoom = MINZOOM;
     669           0 :         if(nZoom > MAXZOOM)
     670           0 :             nZoom = MAXZOOM;
     671             : 
     672           0 :         SfxUInt16Item aItem( nSlotId, nZoom );
     673           0 :         if ( FN_PREVIEW_ZOOM == nSlotId )
     674             :         {
     675           0 :             Any a;
     676           0 :             Sequence< PropertyValue > aArgs( 1 );
     677           0 :             aArgs[0].Name = OUString( "PreviewZoom" );
     678           0 :             aItem.QueryValue( a );
     679           0 :             aArgs[0].Value = a;
     680             :             SfxToolBoxControl::Dispatch(
     681             :                 m_xDispatchProvider,
     682             :                 OUString( ".uno:PreviewZoom" ),
     683           0 :                 aArgs );
     684             :         }
     685             : 
     686           0 :         ReleaseFocus();
     687             :     }
     688           0 : }
     689             : 
     690           0 : long SwZoomBox_Impl::Notify( NotifyEvent& rNEvt )
     691             : {
     692           0 :     long nHandled = 0;
     693             : 
     694           0 :     if ( rNEvt.GetType() == EVENT_KEYINPUT )
     695             :     {
     696           0 :         sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
     697             : 
     698           0 :         switch ( nCode )
     699             :         {
     700             :             case KEY_RETURN:
     701             :             case KEY_TAB:
     702             :             {
     703           0 :                 if ( KEY_TAB == nCode )
     704           0 :                     bRelease = false;
     705             :                 else
     706           0 :                     nHandled = 1;
     707           0 :                 Select();
     708           0 :                 break;
     709             :             }
     710             : 
     711             :             case KEY_ESCAPE:
     712           0 :                 SetText( GetSavedValue() );
     713           0 :                 ReleaseFocus();
     714           0 :                 break;
     715             :         }
     716             :     }
     717           0 :     else if ( EVENT_LOSEFOCUS == rNEvt.GetType() )
     718             :     {
     719           0 :         Window* pFocusWin = Application::GetFocusWindow();
     720           0 :         if ( !HasFocus() && GetSubEdit() != pFocusWin )
     721           0 :             SetText( GetSavedValue() );
     722             :     }
     723             : 
     724           0 :     return nHandled ? nHandled : ComboBox::Notify( rNEvt );
     725             : }
     726             : 
     727           0 : void SwZoomBox_Impl::ReleaseFocus()
     728             : {
     729           0 :     if ( !bRelease )
     730             :     {
     731           0 :         bRelease = true;
     732           0 :         return;
     733             :     }
     734           0 :     SfxViewShell* pCurSh = SfxViewShell::Current();
     735             : 
     736           0 :     if ( pCurSh )
     737             :     {
     738           0 :         Window* pShellWnd = pCurSh->GetWindow();
     739             : 
     740           0 :         if ( pShellWnd )
     741           0 :             pShellWnd->GrabFocus();
     742             :     }
     743             : }
     744             : 
     745          33 : SFX_IMPL_TOOLBOX_CONTROL( SwPreviewZoomControl, SfxUInt16Item);
     746             : 
     747           0 : SwPreviewZoomControl::SwPreviewZoomControl(
     748             :     sal_uInt16 nSlotId,
     749             :     sal_uInt16 nId,
     750             :     ToolBox& rTbx) :
     751           0 :     SfxToolBoxControl( nSlotId, nId, rTbx )
     752             : {
     753           0 : }
     754             : 
     755           0 : SwPreviewZoomControl::~SwPreviewZoomControl()
     756             : {
     757           0 : }
     758             : 
     759           0 : void SwPreviewZoomControl::StateChanged( sal_uInt16 /*nSID*/,
     760             :                                          SfxItemState eState,
     761             :                                          const SfxPoolItem* pState )
     762             : {
     763           0 :     sal_uInt16 nId = GetId();
     764           0 :     GetToolBox().EnableItem( nId, (GetItemState(pState) != SFX_ITEM_DISABLED) );
     765           0 :     SwZoomBox_Impl* pBox = (SwZoomBox_Impl*)GetToolBox().GetItemWindow( GetId() );
     766           0 :     if(SFX_ITEM_AVAILABLE <= eState)
     767             :     {
     768           0 :         String sZoom(OUString::number(((const SfxUInt16Item*)pState)->GetValue()));
     769           0 :         sZoom += '%';
     770           0 :         pBox->SetText(sZoom);
     771           0 :         pBox->SaveValue();
     772             :     }
     773           0 : }
     774             : 
     775           0 : Window* SwPreviewZoomControl::CreateItemWindow( Window *pParent )
     776             : {
     777           0 :     SwZoomBox_Impl* pRet = new SwZoomBox_Impl( pParent, GetSlotId(), Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ));
     778           0 :     return pRet;
     779          99 : }
     780             : 
     781             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10