LCOV - code coverage report
Current view: top level - libreoffice/framework/source/uielement - toolbarmerger.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 32 135 23.7 %
Date: 2012-12-27 Functions: 2 11 18.2 %
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             : 
      21             : #include <uielement/toolbarmerger.hxx>
      22             : #include <uielement/generictoolbarcontroller.hxx>
      23             : #include <framework/imageproducer.hxx>
      24             : 
      25             : #include <svtools/miscopt.hxx>
      26             : 
      27             : namespace framework
      28             : {
      29             : 
      30             : static const char MERGE_TOOLBAR_URL[]              = "URL";
      31             : static const sal_uInt32 MERGE_TOOLBAR_URL_LEN      = 3;
      32             : static const char MERGE_TOOLBAR_TITLE[]            = "Title";
      33             : static const sal_uInt32 MERGE_TOOLBAR_TITLE_LEN    = 5;
      34             : static const char MERGE_TOOLBAR_IMAGEID[]          = "ImageIdentifier";
      35             : static const sal_uInt32 MERGE_TOOLBAR_IMAGEID_LEN  = 15;
      36             : static const char MERGE_TOOLBAR_CONTEXT[]          = "Context";
      37             : static const sal_uInt32 MERGE_TOOLBAR_CONTEXT_LEN  = 7;
      38             : static const char MERGE_TOOLBAR_TARGET[]           = "Target";
      39             : static const sal_uInt32 MERGE_TOOLBAR_TARGET_LEN   = 6;
      40             : static const char MERGE_TOOLBAR_CONTROLTYPE[]      = "ControlType";
      41             : static const char MERGE_TOOLBAR_CONTROLTYPE_LEN    = 11;
      42             : static const char MERGE_TOOLBAR_WIDTH[]            = "Width";
      43             : static const char MERGE_TOOLBAR_WIDTH_LEN          = 5;
      44             : 
      45             : static const char MERGECOMMAND_ADDAFTER[]          = "AddAfter";
      46             : static const sal_uInt32 MERGECOMMAND_ADDAFTER_LEN  = 8;
      47             : static const char MERGECOMMAND_ADDBEFORE[]         = "AddBefore";
      48             : static const sal_uInt32 MERGECOMMAND_ADDBEFORE_LEN = 9;
      49             : static const char MERGECOMMAND_REPLACE[]           = "Replace";
      50             : static const sal_uInt32 MERGECOMMAND_REPLACE_LEN   = 7;
      51             : static const char MERGECOMMAND_REMOVE[]            = "Remove";
      52             : static const sal_uInt32 MERGECOMMAND_REMOVE_LEN    = 6;
      53             : 
      54             : static const char MERGEFALLBACK_ADDLAST[]          = "AddLast";
      55             : static const char MERGEFALLBACK_ADDLAST_LEN        = 7;
      56             : static const char MERGEFALLBACK_ADDFIRST[]         = "AddFirst";
      57             : static const char MERGEFALLBACK_ADDFIRST_LEN       = 8;
      58             : static const char MERGEFALLBACK_IGNORE[]           = "Ignore";
      59             : static const char MERGEFALLBACK_IGNORE_LEN         = 6;
      60             : 
      61             : static const char TOOLBARCONTROLLER_BUTTON[]              = "Button";
      62             : static const sal_uInt32 TOOLBARCONTROLLER_BUTTON_LEN      = 6;
      63             : static const char TOOLBARCONTROLLER_COMBOBOX[]            = "Combobox";
      64             : static const sal_uInt32 TOOLBARCONTROLLER_COMBOBOX_LEN    = 8;
      65             : static const char TOOLBARCONTROLLER_EDIT[]                = "Editfield";
      66             : static const sal_uInt32 TOOLBARCONTROLLER_EDIT_LEN        = 9;
      67             : static const char TOOLBARCONTROLLER_SPINFIELD[]           = "Spinfield";
      68             : static const sal_uInt32 TOOLBARCONTROLLER_SPINFIELD_LEN   = 9;
      69             : static const char TOOLBARCONTROLLER_IMGBUTTON[]           = "ImageButton";
      70             : static const sal_uInt32 TOOLBARCONTROLLER_IMGBUTTON_LEN   = 11;
      71             : static const char TOOLBARCONTROLLER_DROPDOWNBOX[]         = "Dropdownbox";
      72             : static const sal_uInt32 TOOLBARCONTROLLER_DROPDOWNBOX_LEN = 11;
      73             : static const char TOOLBARCONTROLLER_DROPDOWNBTN[]         = "DropdownButton";
      74             : static const sal_uInt32 TOOLBARCONTROLLER_DROPDOWNBTN_LEN = 14;
      75             : static const char TOOLBARCONTROLLER_TOGGLEDDBTN[]         = "ToggleDropdownButton";
      76             : static const sal_uInt32 TOOLBARCONTROLLER_TOGGLEDDBTN_LEN = 20;
      77             : 
      78             : static const char   TOOLBOXITEM_SEPARATOR_STR[]   = "private:separator";
      79             : static const sal_uInt16 TOOLBOXITEM_SEPARATOR_STR_LEN = sizeof( TOOLBOXITEM_SEPARATOR_STR )-1;
      80             : 
      81             : using namespace ::com::sun::star;
      82             : 
      83             : /**
      84             :  Check whether a module identifier is part of a context
      85             :  defined by a colon separated list of module identifier.
      86             : 
      87             :  @param
      88             :      rContext
      89             : 
      90             :      Describes a context string list where all contexts
      91             :      are delimited by a colon. For more information about
      92             :      the module identifier used as context strings see the
      93             :      IDL description of com::sun::star::frame::XModuleManager
      94             : 
      95             :  @param
      96             :      rModuleIdentifier
      97             : 
      98             :      A string describing a module identifier. See IDL
      99             :      description of com::sun::star::frame::XModuleManager.
     100             : 
     101             :  @result
     102             :      The result is true if the rContext is an empty string
     103             :      or rModuleIdentifier is part of the context string.
     104             : 
     105             : */
     106           0 : bool ToolBarMerger::IsCorrectContext(
     107             :     const ::rtl::OUString& rContext,
     108             :     const ::rtl::OUString& rModuleIdentifier )
     109             : {
     110           0 :     return ( rContext.isEmpty() || ( rContext.indexOf( rModuleIdentifier ) >= 0 ));
     111             : }
     112             : 
     113             : /**
     114             :  Converts a sequence, sequence of property values to
     115             :  a vector of structs.
     116             : 
     117             :  @param
     118             :      rSequence
     119             : 
     120             :      Provides a sequence, sequence of property values.
     121             : 
     122             :  @param
     123             :      rContainer
     124             : 
     125             :      A vector of AddonToolbarItems which will hold the
     126             :      conversion from the rSequence argument.
     127             : 
     128             :  @result
     129             :      The result is true if the sequence, sequence of property
     130             :      values could be converted to a vector of structs.
     131             : 
     132             : */
     133           0 : bool ToolBarMerger::ConvertSeqSeqToVector(
     134             :     const uno::Sequence< uno::Sequence< beans::PropertyValue > > rSequence,
     135             :     AddonToolbarItemContainer& rContainer )
     136             : {
     137           0 :     sal_Int32 nLen( rSequence.getLength() );
     138           0 :     for ( sal_Int32 i = 0; i < nLen; i++ )
     139             :     {
     140           0 :         AddonToolbarItem aAddonToolbarItem;
     141           0 :         ConvertSequenceToValues( rSequence[i],
     142             :                                  aAddonToolbarItem.aCommandURL,
     143             :                                  aAddonToolbarItem.aLabel,
     144             :                                  aAddonToolbarItem.aImageIdentifier,
     145             :                                  aAddonToolbarItem.aTarget,
     146             :                                  aAddonToolbarItem.aContext,
     147             :                                  aAddonToolbarItem.aControlType,
     148           0 :                                  aAddonToolbarItem.nWidth );
     149           0 :         rContainer.push_back( aAddonToolbarItem );
     150           0 :     }
     151             : 
     152           0 :     return true;
     153             : }
     154             : 
     155             : /**
     156             :  Converts a sequence of property values to single
     157             :  values.
     158             : 
     159             :  @param
     160             :      rSequence
     161             : 
     162             :      Provides a sequence of property values.
     163             : 
     164             :  @param
     165             :      rCommandURL
     166             : 
     167             :      Contains the value of the property with
     168             :      Name="CommandURL".
     169             : 
     170             :  @param
     171             :      rLabel
     172             : 
     173             :      Contains the value of the property with
     174             :      Name="Title"
     175             : 
     176             :  @param
     177             :      rImageIdentifier
     178             : 
     179             :      Contains the value of the property with
     180             :      Name="ImageIdentifier"
     181             : 
     182             :  @param
     183             :      rTarget
     184             : 
     185             :      Contains the value of the property with
     186             :      Name="Target"
     187             : 
     188             :  @param
     189             :      rContext
     190             : 
     191             :      Contains the value of the property with
     192             :      Name="Context"
     193             : 
     194             :  @param
     195             :      rControlType
     196             : 
     197             :      Contains the value of the property with
     198             :      Name="ControlType"
     199             : 
     200             :  @result
     201             :      All possible mapping between sequence of property
     202             :      values and the single values are done.
     203             : 
     204             : */
     205        2360 : void ToolBarMerger::ConvertSequenceToValues(
     206             :     const uno::Sequence< beans::PropertyValue > rSequence,
     207             :     ::rtl::OUString& rCommandURL,
     208             :     ::rtl::OUString& rLabel,
     209             :     ::rtl::OUString& rImageIdentifier,
     210             :     ::rtl::OUString& rTarget,
     211             :     ::rtl::OUString& rContext,
     212             :     ::rtl::OUString& rControlType,
     213             :     sal_uInt16&      rWidth )
     214             : {
     215       18880 :     for ( sal_Int32 i = 0; i < rSequence.getLength(); i++ )
     216             :     {
     217       16520 :         if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_URL, MERGE_TOOLBAR_URL_LEN ))
     218        2360 :             rSequence[i].Value >>= rCommandURL;
     219       14160 :         else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_TITLE, MERGE_TOOLBAR_TITLE_LEN ))
     220        2360 :             rSequence[i].Value >>= rLabel;
     221       11800 :         else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_IMAGEID, MERGE_TOOLBAR_IMAGEID_LEN ))
     222        2360 :             rSequence[i].Value >>= rImageIdentifier;
     223        9440 :         else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_CONTEXT, MERGE_TOOLBAR_CONTEXT_LEN ))
     224        2360 :             rSequence[i].Value >>= rContext;
     225        7080 :         else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_TARGET, MERGE_TOOLBAR_TARGET_LEN ))
     226        2360 :             rSequence[i].Value >>= rTarget;
     227        4720 :         else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_CONTROLTYPE, MERGE_TOOLBAR_CONTROLTYPE_LEN ))
     228        2360 :             rSequence[i].Value >>= rControlType;
     229        2360 :         else if ( rSequence[i].Name.equalsAsciiL( MERGE_TOOLBAR_WIDTH, MERGE_TOOLBAR_WIDTH_LEN ))
     230             :         {
     231        2360 :             sal_Int32 aValue = 0;
     232        2360 :             rSequence[i].Value >>= aValue;
     233        2360 :             rWidth = sal_uInt16( aValue );
     234             :         }
     235             :     }
     236        2360 : }
     237             : 
     238             : /**
     239             :  Tries to find the reference point provided and delivers
     240             :  position and result of the search process.
     241             : 
     242             :  @param
     243             :      pToolbar
     244             : 
     245             :      Must be a valid pointer to a toolbar with items which
     246             :      should be searched.
     247             : 
     248             :  @param
     249             :      rReferencePoint
     250             : 
     251             :      A command URL which should be the reference point for
     252             :      the coming merge operation.
     253             : 
     254             :  @result
     255             :      Provides information about the search result, the
     256             :      position of the reference point and the toolbar used.
     257             : */
     258           0 : ReferenceToolbarPathInfo ToolBarMerger::FindReferencePoint(
     259             :     ToolBox*               pToolbar,
     260             :     const ::rtl::OUString& rReferencePoint )
     261             : {
     262             :     ReferenceToolbarPathInfo aResult;
     263           0 :     aResult.bResult  = false;
     264           0 :     aResult.pToolbar = pToolbar;
     265           0 :     aResult.nPos     = TOOLBOX_ITEM_NOTFOUND;
     266             : 
     267           0 :     const sal_uInt16 nSize( pToolbar->GetItemCount() );
     268             : 
     269           0 :     for ( sal_uInt16 i = 0; i < nSize; i++ )
     270             :     {
     271           0 :         const sal_uInt16 nItemId = pToolbar->GetItemId( i );
     272           0 :         if ( nItemId > 0 )
     273             :         {
     274           0 :             const ::rtl::OUString rCmd = pToolbar->GetItemCommand( nItemId );
     275           0 :             if ( rCmd == rReferencePoint )
     276             :             {
     277           0 :                 aResult.bResult = true;
     278           0 :                 aResult.nPos    = i;
     279             :                 return aResult;
     280           0 :             }
     281             :         }
     282             :     }
     283             : 
     284           0 :     return aResult;
     285             : }
     286             : 
     287             : /**
     288             :  Processes a merge operation.
     289             : 
     290             :  @param
     291             :      xFrame
     292             : 
     293             :      Must be a valid reference to a frame.
     294             : 
     295             :  @param
     296             :      pToolbar
     297             : 
     298             :      A valid pointer to the toolbar where the merge
     299             :      operation is applied to.
     300             : 
     301             :  @param
     302             :      nPos
     303             : 
     304             :      The reference position of the toolbar item for
     305             :      the merge operation. Value must be between
     306             :      0 and number of toolbar items - 1.
     307             : 
     308             :  @param
     309             :      rItemId
     310             : 
     311             :      A unique item ID.
     312             : 
     313             :  @param
     314             :      rModuleIdentifier
     315             : 
     316             :      The current application module context.
     317             : 
     318             :  @param
     319             :      rMergeCommand
     320             : 
     321             :      A merge command.
     322             : 
     323             :  @param
     324             :      rMergeCommandParameter.
     325             : 
     326             :      An optional argument for the merge command.
     327             : 
     328             :  @param
     329             :      rItems
     330             : 
     331             :      Toolbar items which are associated to the merge
     332             :      command.
     333             : 
     334             :  @result
     335             :      Returns true for a successful operation otherwise
     336             :      false.
     337             : */
     338           0 : bool ToolBarMerger::ProcessMergeOperation(
     339             :     const uno::Reference< frame::XFrame >& xFrame,
     340             :     ToolBox*                               pToolbar,
     341             :     sal_uInt16                             nPos,
     342             :     sal_uInt16&                            rItemId,
     343             :     CommandToInfoMap&                      rCommandMap,
     344             :     const ::rtl::OUString&                 rModuleIdentifier,
     345             :     const ::rtl::OUString&                 rMergeCommand,
     346             :     const ::rtl::OUString&                 rMergeCommandParameter,
     347             :     const AddonToolbarItemContainer&       rItems )
     348             : {
     349           0 :     if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_ADDAFTER, MERGECOMMAND_ADDAFTER_LEN ))
     350           0 :         return MergeItems( xFrame, pToolbar, nPos, 1, rItemId, rCommandMap, rModuleIdentifier, rItems );
     351           0 :     else if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_ADDBEFORE, MERGECOMMAND_ADDBEFORE_LEN ))
     352           0 :         return MergeItems( xFrame, pToolbar, nPos, 0, rItemId, rCommandMap, rModuleIdentifier, rItems );
     353           0 :     else if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_REPLACE, MERGECOMMAND_REPLACE_LEN ))
     354           0 :         return ReplaceItem( xFrame, pToolbar, nPos, rItemId, rCommandMap, rModuleIdentifier, rItems );
     355           0 :     else if ( rMergeCommand.equalsAsciiL( MERGECOMMAND_REMOVE, MERGECOMMAND_REMOVE_LEN ))
     356           0 :         return RemoveItems( pToolbar, nPos, rMergeCommandParameter );
     357             : 
     358           0 :     return false;
     359             : }
     360             : 
     361             : /**
     362             :  Processes a merge fallback operation.
     363             : 
     364             :  @param
     365             :      xFrame
     366             : 
     367             :      Must be a valid reference to a frame.
     368             : 
     369             :  @param
     370             :      pToolbar
     371             : 
     372             :      A valid pointer to the toolbar where the merge
     373             :      fall back operation is applied to.
     374             : 
     375             :  @param
     376             :      nPos
     377             : 
     378             :      The reference position of the toolbar item for
     379             :      the merge operation. Value must be between
     380             :      0 and number of toolbar items - 1.
     381             : 
     382             :  @param
     383             :      rItemId
     384             : 
     385             :      A unique item ID.
     386             : 
     387             :  @param
     388             :      rModuleIdentifier
     389             : 
     390             :      The current application module context.
     391             : 
     392             :  @param
     393             :      rMergeCommand
     394             : 
     395             :      A merge command.
     396             : 
     397             :  @param
     398             :      rItems
     399             : 
     400             :      Toolbar items which are associated to the merge
     401             :      command.
     402             : 
     403             :  @result
     404             :      Returns true for a successful operation otherwise
     405             :      false.
     406             : */
     407           0 : bool ToolBarMerger::ProcessMergeFallback(
     408             :     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame,
     409             :     ToolBox*                         pToolbar,
     410             :     sal_uInt16                       /*nPos*/,
     411             :     sal_uInt16&                      rItemId,
     412             :     CommandToInfoMap&                rCommandMap,
     413             :     const ::rtl::OUString&           rModuleIdentifier,
     414             :     const ::rtl::OUString&           rMergeCommand,
     415             :     const ::rtl::OUString&           rMergeFallback,
     416             :     const AddonToolbarItemContainer& rItems )
     417             : {
     418           0 :     if (( rMergeFallback.equalsAsciiL( MERGEFALLBACK_IGNORE, MERGEFALLBACK_IGNORE_LEN )) ||
     419           0 :         ( rMergeCommand.equalsAsciiL(  MERGECOMMAND_REPLACE, MERGECOMMAND_REPLACE_LEN )) ||
     420           0 :         ( rMergeCommand.equalsAsciiL(  MERGECOMMAND_REMOVE, MERGECOMMAND_REMOVE_LEN   )) )
     421             :     {
     422           0 :         return true;
     423             :     }
     424           0 :     else if (( rMergeCommand.equalsAsciiL( MERGECOMMAND_ADDBEFORE, MERGECOMMAND_ADDBEFORE_LEN )) ||
     425           0 :              ( rMergeCommand.equalsAsciiL( MERGECOMMAND_ADDAFTER, MERGECOMMAND_ADDAFTER_LEN   )) )
     426             :     {
     427           0 :         if ( rMergeFallback.equalsAsciiL( MERGEFALLBACK_ADDFIRST, MERGEFALLBACK_ADDFIRST_LEN ))
     428           0 :             return MergeItems( xFrame, pToolbar, 0, 0, rItemId, rCommandMap, rModuleIdentifier, rItems );
     429           0 :         else if ( rMergeFallback.equalsAsciiL( MERGEFALLBACK_ADDLAST, MERGEFALLBACK_ADDLAST_LEN ))
     430           0 :             return MergeItems( xFrame, pToolbar, TOOLBOX_APPEND, 0, rItemId, rCommandMap, rModuleIdentifier, rItems );
     431             :     }
     432             : 
     433           0 :     return false;
     434             : }
     435             : 
     436             : /**
     437             :  Merges (adds) toolbar items into an existing toolbar.
     438             : 
     439             :  @param
     440             :      xFrame
     441             : 
     442             :      Must be a valid reference to a frame.
     443             : 
     444             :  @param
     445             :      pToolbar
     446             : 
     447             :      A valid pointer to the toolbar where the merge
     448             :      fall back operation is applied to.
     449             : 
     450             :  @param
     451             :      nPos
     452             : 
     453             :      The reference position of the toolbar item for
     454             :      the merge operation. Value must be between
     455             :      0 and number of toolbar items - 1.
     456             : 
     457             :  @param
     458             :      rItemId
     459             : 
     460             :      A unique item ID.
     461             : 
     462             :  @param
     463             :      rModuleIdentifier
     464             : 
     465             :      The current application module context.
     466             : 
     467             :  @param
     468             :      rItems
     469             : 
     470             :      Toolbar items which are associated to the merge
     471             :      command.
     472             : 
     473             :  @result
     474             :      Returns true for a successful operation otherwise
     475             :      false.
     476             : */
     477           0 : bool ToolBarMerger::MergeItems(
     478             :     const uno::Reference< frame::XFrame >& rFrame,
     479             :     ToolBox*                               pToolbar,
     480             :     sal_uInt16                             nPos,
     481             :     sal_uInt16                             nModIndex,
     482             :     sal_uInt16&                            rItemId,
     483             :     CommandToInfoMap&                      rCommandMap,
     484             :     const ::rtl::OUString&                 rModuleIdentifier,
     485             :     const AddonToolbarItemContainer&       rAddonToolbarItems )
     486             : {
     487           0 :     const sal_Int32 nSize( rAddonToolbarItems.size() );
     488             : 
     489           0 :     uno::Reference< frame::XFrame > xFrame( rFrame );
     490             : 
     491           0 :     sal_uInt16 nIndex( 0 );
     492           0 :     for ( sal_Int32 i = 0; i < nSize; i++ )
     493             :     {
     494           0 :         const AddonToolbarItem& rItem = rAddonToolbarItems[i];
     495           0 :         if ( IsCorrectContext( rItem.aContext, rModuleIdentifier ))
     496             :         {
     497           0 :             sal_Int32 nInsPos = nPos+nModIndex+i;
     498           0 :             if ( nInsPos > sal_Int32( pToolbar->GetItemCount() ))
     499           0 :                 nInsPos = TOOLBOX_APPEND;
     500             : 
     501           0 :             if ( rItem.aCommandURL.equalsAsciiL( TOOLBOXITEM_SEPARATOR_STR, TOOLBOXITEM_SEPARATOR_STR_LEN ))
     502           0 :                 pToolbar->InsertSeparator( sal_uInt16( nInsPos ));
     503             :             else
     504             :             {
     505           0 :                 CommandToInfoMap::iterator pIter = rCommandMap.find( rItem.aCommandURL );
     506           0 :                 if ( pIter == rCommandMap.end())
     507             :                 {
     508           0 :                     CommandInfo aCmdInfo;
     509           0 :                     aCmdInfo.nId = rItemId;
     510           0 :                     const CommandToInfoMap::value_type aValue( rItem.aCommandURL, aCmdInfo );
     511           0 :                     rCommandMap.insert( aValue );
     512             :                 }
     513             :                 else
     514             :                 {
     515           0 :                     pIter->second.aIds.push_back( rItemId );
     516             :                 }
     517             : 
     518           0 :                 ToolBarMerger::CreateToolbarItem( pToolbar, rCommandMap, sal_uInt16( nInsPos ), rItemId, rItem );
     519             :             }
     520             : 
     521           0 :             ++nIndex;
     522           0 :             ++rItemId;
     523             :         }
     524             :     }
     525             : 
     526           0 :     return true;
     527             : }
     528             : 
     529             : /**
     530             :  Replaces a toolbar item with new items for an
     531             :  existing toolbar.
     532             : 
     533             :  @param
     534             :      xFrame
     535             : 
     536             :      Must be a valid reference to a frame.
     537             : 
     538             :  @param
     539             :      pToolbar
     540             : 
     541             :      A valid pointer to the toolbar where the merge
     542             :      fall back operation is applied to.
     543             : 
     544             :  @param
     545             :      nPos
     546             : 
     547             :      The reference position of the toolbar item for
     548             :      the merge operation. Value must be between
     549             :      0 and number of toolbar items - 1.
     550             : 
     551             :  @param
     552             :      rItemId
     553             : 
     554             :      A unique item ID.
     555             : 
     556             :  @param
     557             :      rModuleIdentifier
     558             : 
     559             :      The current application module context.
     560             : 
     561             :  @param
     562             :      rItems
     563             : 
     564             :      Toolbar items which are associated to the merge
     565             :      command.
     566             : 
     567             :  @result
     568             :      Returns true for a successful operation otherwise
     569             :      false.
     570             : */
     571           0 : bool ToolBarMerger::ReplaceItem(
     572             :     const uno::Reference< frame::XFrame >& xFrame,
     573             :     ToolBox*                               pToolbar,
     574             :     sal_uInt16                             nPos,
     575             :     sal_uInt16&                            rItemId,
     576             :     CommandToInfoMap&                      rCommandMap,
     577             :     const ::rtl::OUString&                 rModuleIdentifier,
     578             :     const AddonToolbarItemContainer&       rAddonToolbarItems )
     579             : {
     580           0 :     pToolbar->RemoveItem( nPos );
     581           0 :     return MergeItems( xFrame, pToolbar, nPos, 0, rItemId, rCommandMap, rModuleIdentifier, rAddonToolbarItems );
     582             : }
     583             : 
     584             : /**
     585             :  Removes toolbar items from an existing toolbar.
     586             : 
     587             :  @param
     588             :      pToolbar
     589             : 
     590             :      A valid pointer to the toolbar where the merge
     591             :      fall back operation is applied to.
     592             : 
     593             :  @param
     594             :      nPos
     595             : 
     596             :      The reference position of the toolbar item for
     597             :      the merge operation. Value must be between
     598             :      0 and number of toolbar items - 1.
     599             : 
     600             :  @param
     601             :      rMergeCommandParameter.
     602             : 
     603             :      An optional argument for the merge command.
     604             : 
     605             :  @result
     606             :      Returns true for a successful operation otherwise
     607             :      false.
     608             : */
     609           0 : bool ToolBarMerger::RemoveItems(
     610             :     ToolBox*                  pToolbar,
     611             :     sal_uInt16                nPos,
     612             :     const ::rtl::OUString&    rMergeCommandParameter )
     613             : {
     614           0 :     sal_Int32 nCount = rMergeCommandParameter.toInt32();
     615           0 :     if ( nCount > 0 )
     616             :     {
     617           0 :         for ( sal_Int32 i = 0; i < nCount; i++ )
     618             :         {
     619           0 :             if ( nPos < pToolbar->GetItemCount() )
     620           0 :                 pToolbar->RemoveItem( nPos );
     621             :         }
     622             :     }
     623           0 :     return true;
     624             : }
     625             : 
     626             : /**
     627             :  Removes toolbar items from an existing toolbar.
     628             : 
     629             :  @param
     630             :      pToolbar
     631             : 
     632             :      A valid pointer to the toolbar where the merge
     633             :      fall back operation is applied to.
     634             : 
     635             :  @param
     636             :      nPos
     637             : 
     638             :      The reference position of the toolbar item for
     639             :      the merge operation. Value must be between
     640             :      0 and number of toolbar items - 1.
     641             : 
     642             :  @param
     643             :      rMergeCommandParameter.
     644             : 
     645             :      An optional argument for the merge command.
     646             : 
     647             :  @result
     648             :      Returns true for a successful operation otherwise
     649             :      false.
     650             : */
     651        2360 : ::cppu::OWeakObject* ToolBarMerger::CreateController(
     652             :     uno::Reference< lang::XMultiServiceFactory > xSMGR,
     653             :     uno::Reference< frame::XFrame > xFrame,
     654             :     ToolBox*               pToolbar,
     655             :     const ::rtl::OUString& rCommandURL,
     656             :     sal_uInt16             nId,
     657             :     sal_uInt16             nWidth,
     658             :     const ::rtl::OUString& rControlType )
     659             : {
     660        2360 :     ::cppu::OWeakObject* pResult( 0 );
     661             : 
     662        2360 :     if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_BUTTON, TOOLBARCONTROLLER_BUTTON_LEN ))
     663           0 :         pResult = new ButtonToolbarController( xSMGR, pToolbar, rCommandURL );
     664        2360 :     else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_COMBOBOX, TOOLBARCONTROLLER_COMBOBOX_LEN ))
     665           0 :         pResult = new ComboboxToolbarController( xSMGR, xFrame, pToolbar, nId, nWidth, rCommandURL );
     666        2360 :     else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_EDIT, TOOLBARCONTROLLER_EDIT_LEN ))
     667         236 :         pResult = new EditToolbarController( xSMGR, xFrame, pToolbar, nId, nWidth, rCommandURL );
     668        2124 :     else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_SPINFIELD, TOOLBARCONTROLLER_SPINFIELD_LEN ))
     669           0 :         pResult = new SpinfieldToolbarController( xSMGR, xFrame, pToolbar, nId, nWidth, rCommandURL );
     670        2124 :     else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_IMGBUTTON, TOOLBARCONTROLLER_IMGBUTTON_LEN ))
     671           0 :         pResult = new ImageButtonToolbarController( xSMGR, xFrame, pToolbar, nId, rCommandURL );
     672        2124 :     else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_DROPDOWNBOX, TOOLBARCONTROLLER_DROPDOWNBOX_LEN ))
     673           0 :         pResult = new DropdownToolbarController( xSMGR, xFrame, pToolbar, nId, nWidth, rCommandURL );
     674        2124 :     else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_DROPDOWNBTN, TOOLBARCONTROLLER_DROPDOWNBTN_LEN ))
     675             :         pResult = new ToggleButtonToolbarController( xSMGR, xFrame, pToolbar, nId,
     676           0 :                                                      ToggleButtonToolbarController::STYLE_DROPDOWNBUTTON, rCommandURL );
     677        2124 :     else if ( rControlType.equalsAsciiL( TOOLBARCONTROLLER_TOGGLEDDBTN, TOOLBARCONTROLLER_TOGGLEDDBTN_LEN ))
     678             :         pResult = new ToggleButtonToolbarController( xSMGR, xFrame, pToolbar, nId,
     679           0 :                                                      ToggleButtonToolbarController::STYLE_TOGGLE_DROPDOWNBUTTON, rCommandURL );
     680             :     else
     681        2124 :         pResult = new GenericToolbarController( xSMGR, xFrame, pToolbar, nId, rCommandURL );
     682             : 
     683        2360 :     return pResult;
     684             : }
     685             : 
     686           0 : void ToolBarMerger::CreateToolbarItem( ToolBox* pToolbar, CommandToInfoMap& rCommandMap, sal_uInt16 nPos, sal_uInt16 nItemId, const AddonToolbarItem& rItem )
     687             : {
     688           0 :     pToolbar->InsertItem( nItemId, rItem.aLabel, 0, nPos );
     689           0 :     pToolbar->SetItemCommand( nItemId, rItem.aCommandURL );
     690           0 :     pToolbar->SetQuickHelpText( nItemId, rItem.aLabel );
     691           0 :     pToolbar->SetItemText( nItemId, rItem.aLabel );
     692           0 :     pToolbar->EnableItem( nItemId, sal_True );
     693           0 :     pToolbar->SetItemState( nItemId, STATE_NOCHECK );
     694             : 
     695           0 :     CommandToInfoMap::iterator pIter = rCommandMap.find( rItem.aCommandURL );
     696           0 :     if ( pIter != rCommandMap.end() )
     697           0 :         pIter->second.nWidth = rItem.nWidth;
     698             : 
     699             :     // Use the user data to store add-on specific data with the toolbar item
     700           0 :     AddonsParams* pAddonParams = new AddonsParams;
     701           0 :     pAddonParams->aImageId     = rItem.aImageIdentifier;
     702           0 :     pAddonParams->aTarget      = rItem.aTarget;
     703           0 :     pAddonParams->aControlType = rItem.aControlType;
     704           0 :     pToolbar->SetItemData( nItemId, pAddonParams );
     705           0 : }
     706             : 
     707             : } // namespace framework
     708             : 
     709             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10