LCOV - code coverage report
Current view: top level - starmath/source - toolbox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 120 176 68.2 %
Date: 2012-08-25 Functions: 19 26 73.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 97 216 44.9 %

           Branch data     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 <rtl/logfile.hxx>
      21                 :            : #include <svl/eitem.hxx>
      22                 :            : #include <sfx2/app.hxx>
      23                 :            : #include <svl/intitem.hxx>
      24                 :            : #include <svtools/imgdef.hxx>
      25                 :            : #include <sfx2/dispatch.hxx>
      26                 :            : #include <sfx2/imgmgr.hxx>
      27                 :            : #include <vcl/wrkwin.hxx>
      28                 :            : #include "toolbox.hxx"
      29                 :            : #include "starmath.hrc"
      30                 :            : #include "toolbox.hrc"
      31                 :            : #include "view.hxx"
      32                 :            : 
      33                 :            : 
      34                 :            : ////////////////////////////////////////////////////////////
      35                 :            : 
      36                 :         34 : static sal_uInt16  GetImageListRID( sal_uInt16 nCategoryRID )
      37                 :            : {
      38                 :         34 :     sal_uInt16 nRes = 0xFFFF;
      39   [ +  -  -  -  :         34 :     switch (nCategoryRID)
          -  -  -  -  -  
                      - ]
      40                 :            :     {
      41                 :         34 :         case RID_UNBINOPS_CAT       : nRes = RID_IL_UNBINOPS; break;
      42                 :          0 :         case RID_RELATIONS_CAT      : nRes = RID_IL_RELATIONS; break;
      43                 :          0 :         case RID_SETOPERATIONS_CAT  : nRes = RID_IL_SETOPERATIONS; break;
      44                 :          0 :         case RID_FUNCTIONS_CAT      : nRes = RID_IL_FUNCTIONS; break;
      45                 :          0 :         case RID_OPERATORS_CAT      : nRes = RID_IL_OPERATORS; break;
      46                 :          0 :         case RID_ATTRIBUTES_CAT     : nRes = RID_IL_ATTRIBUTES; break;
      47                 :          0 :         case RID_BRACKETS_CAT       : nRes = RID_IL_BRACKETS; break;
      48                 :          0 :         case RID_FORMAT_CAT         : nRes = RID_IL_FORMAT; break;
      49                 :          0 :         case RID_MISC_CAT           : nRes = RID_IL_MISC; break;
      50                 :            :         default :
      51                 :            :             OSL_FAIL( "unkown category" );
      52                 :            :     }
      53                 :         34 :     return nRes;
      54                 :            : }
      55                 :            : 
      56                 :            : 
      57                 :        170 : static sal_Int16  GetToolBoxCategoriesIndex( sal_uInt16 nCategoryRID )
      58                 :            : {
      59                 :        170 :     sal_Int16 nIdx = -1;
      60   [ +  -  -  -  :        170 :     switch (nCategoryRID)
          -  -  -  -  -  
                      + ]
      61                 :            :     {
      62                 :        136 :         case RID_UNBINOPS_CAT       : nIdx = 0; break;
      63                 :          0 :         case RID_RELATIONS_CAT      : nIdx = 1; break;
      64                 :          0 :         case RID_SETOPERATIONS_CAT  : nIdx = 2; break;
      65                 :          0 :         case RID_FUNCTIONS_CAT      : nIdx = 3; break;
      66                 :          0 :         case RID_OPERATORS_CAT      : nIdx = 4; break;
      67                 :          0 :         case RID_ATTRIBUTES_CAT     : nIdx = 5; break;
      68                 :          0 :         case RID_BRACKETS_CAT       : nIdx = 6; break;
      69                 :          0 :         case RID_FORMAT_CAT         : nIdx = 7; break;
      70                 :          0 :         case RID_MISC_CAT           : nIdx = 8; break;
      71                 :            :         default:
      72                 :            :             ;
      73                 :            :     }
      74                 :        170 :     return nIdx;
      75                 :            : }
      76                 :            : 
      77                 :            : 
      78                 :         68 : static sal_uInt16  GetCategoryRID( sal_uInt16 nResId )
      79                 :            : {
      80                 :         68 :     sal_uInt16 nRes = 0xFFFF;
      81   [ +  -  -  -  :         68 :     switch (nResId)
          -  -  -  -  -  
                      + ]
      82                 :            :     {
      83                 :         34 :         case RID_IL_UNBINOPS       : nRes = RID_UNBINOPS_CAT; break;
      84                 :          0 :         case RID_IL_RELATIONS      : nRes = RID_RELATIONS_CAT; break;
      85                 :          0 :         case RID_IL_SETOPERATIONS  : nRes = RID_SETOPERATIONS_CAT; break;
      86                 :          0 :         case RID_IL_FUNCTIONS      : nRes = RID_FUNCTIONS_CAT; break;
      87                 :          0 :         case RID_IL_OPERATORS      : nRes = RID_OPERATORS_CAT; break;
      88                 :          0 :         case RID_IL_ATTRIBUTES     : nRes = RID_ATTRIBUTES_CAT; break;
      89                 :          0 :         case RID_IL_BRACKETS       : nRes = RID_BRACKETS_CAT; break;
      90                 :          0 :         case RID_IL_FORMAT         : nRes = RID_FORMAT_CAT; break;
      91                 :          0 :         case RID_IL_MISC           : nRes = RID_MISC_CAT; break;
      92                 :            :         default :
      93                 :            :             if (nResId != RID_IL_CATALOG)
      94                 :            :             {
      95                 :            : #if OSL_DEBUG_LEVEL > 1
      96                 :            :                 OSL_FAIL( "unkown category" );
      97                 :            : #endif
      98                 :            :             }
      99                 :            :     }
     100                 :         68 :     return nRes;
     101                 :            : }
     102                 :            : 
     103                 :            : 
     104                 :            : ////////////////////////////////////////////////////////////
     105                 :            : 
     106                 :            : 
     107                 :         34 : SmToolBoxWindow::SmToolBoxWindow(SfxBindings *pTmpBindings,
     108                 :            :                                  SfxChildWindow *pChildWindow,
     109                 :            :                                  Window *pParent) :
     110                 :            :     SfxFloatingWindow(pTmpBindings, pChildWindow, pParent, SmResId(RID_TOOLBOXWINDOW)),
     111                 :            :     aToolBoxCat(this, SmResId(TOOLBOX_CATALOG)),
     112 [ +  - ][ +  - ]:         34 :     aToolBoxCat_Delim(this, SmResId( FL_TOOLBOX_CAT_DELIM ))
         [ +  - ][ +  - ]
                 [ +  - ]
     113                 :            : {
     114                 :            :     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmToolBoxWindow::SmToolBoxWindow" );
     115                 :            : 
     116                 :            :     // allow for cursor travelling between toolbox and sub-categories
     117 [ +  - ][ +  - ]:         34 :     SetStyle( GetStyle() | WB_DIALOGCONTROL );
     118                 :            : 
     119                 :         34 :     nActiveCategoryRID = USHRT_MAX;
     120                 :            : 
     121         [ +  - ]:         34 :     aToolBoxCat.SetClickHdl(LINK(this, SmToolBoxWindow, CategoryClickHdl));
     122                 :            : 
     123                 :            :     sal_uInt16 i;
     124         [ +  + ]:        340 :     for (i = 0;  i < NUM_TBX_CATEGORIES;  ++i)
     125                 :            :     {
     126 [ +  - ][ +  - ]:        306 :         ToolBox *pBox = new ToolBox(this, SmResId( TOOLBOX_CAT_A + i ));
                 [ +  - ]
     127                 :        306 :         vToolBoxCategories[i] = pBox;
     128         [ +  - ]:        306 :         pBox->SetSelectHdl(LINK(this, SmToolBoxWindow, CmdSelectHdl));
     129                 :            :     }
     130                 :         34 :     pToolBoxCmd = vToolBoxCategories[0];
     131                 :            : 
     132         [ +  + ]:        374 :     for (i = 0;  i <= NUM_TBX_CATEGORIES; ++i)
     133                 :        340 :         aImageLists [i] = 0;
     134                 :            : 
     135         [ +  - ]:         34 :     FreeResource();
     136                 :         34 : }
     137                 :            : 
     138 [ +  - ][ +  - ]:         34 : SmToolBoxWindow::~SmToolBoxWindow()
     139                 :            : {
     140                 :            :     int i;
     141         [ +  + ]:        340 :     for (i = 0;  i < NUM_TBX_CATEGORIES;  ++i)
     142                 :            :     {
     143                 :        306 :         ToolBox *pBox = vToolBoxCategories[i];
     144 [ +  - ][ +  - ]:        306 :         delete pBox;
     145                 :            :     }
     146         [ +  + ]:        374 :     for (i = 0;  i < NUM_TBX_CATEGORIES + 1;  ++i)
     147 [ +  + ][ +  - ]:        340 :         delete aImageLists[i];
     148         [ -  + ]:         68 : }
     149                 :            : 
     150                 :            : 
     151                 :          4 : SmViewShell * SmToolBoxWindow::GetView()
     152                 :            : {
     153                 :          4 :     SfxViewShell *pView = GetBindings().GetDispatcher()->GetFrame()->GetViewShell();
     154 [ +  - ][ +  - ]:          4 :     return PTR_CAST(SmViewShell, pView);
     155                 :            : }
     156                 :            : 
     157                 :            : 
     158                 :         68 : const ImageList * SmToolBoxWindow::GetImageList( sal_uInt16 nResId )
     159                 :            : {
     160                 :            :     // creates the image list via its resource id and stores that
     161                 :            :     // list for later use in the respective array.
     162                 :            : 
     163                 :         68 :     const ImageList *pIL = 0;
     164                 :            : 
     165                 :            :     // get index to use
     166                 :         68 :     sal_uInt16 nCategoryRID = GetCategoryRID( nResId );
     167                 :         68 :     sal_Int16 nIndex = GetToolBoxCategoriesIndex( nCategoryRID );
     168 [ +  - ][ +  + ]:         68 :     if (nIndex == -1 && (nResId == RID_IL_CATALOG))
     169                 :         34 :         nIndex = NUM_TBX_CATEGORIES;
     170                 :            : 
     171         [ +  - ]:         68 :     if (nIndex >= 0)
     172                 :            :     {
     173                 :         68 :         ImageList **pImgList = aImageLists;
     174         [ +  - ]:         68 :         if (!pImgList[ nIndex ])
     175 [ +  - ][ +  - ]:         68 :             pImgList[ nIndex ] = new ImageList( SmResId(nResId) );
     176                 :         68 :         pIL = pImgList[ nIndex ];
     177                 :            :     }
     178                 :            : 
     179                 :            :     OSL_ENSURE( pIL, "image list not found!" );
     180                 :         68 :     return pIL;
     181                 :            : }
     182                 :            : 
     183                 :            : 
     184                 :         34 : void SmToolBoxWindow::ApplyImageLists( sal_uInt16 nCategoryRID )
     185                 :            : {
     186                 :            :     // set image list for toolbox 'catalog'
     187                 :         34 :     const ImageList *pImageList = GetImageList( RID_IL_CATALOG );
     188                 :            :     OSL_ENSURE( pImageList, "image list missing" );
     189         [ +  - ]:         34 :     if (pImageList)
     190                 :         34 :         aToolBoxCat.SetImageList( *pImageList );
     191                 :            : 
     192                 :            :     // set image list for active (visible) category of 'catalog'
     193                 :         34 :     sal_Int16 nIdx = GetToolBoxCategoriesIndex( nCategoryRID );
     194                 :         34 :     sal_uInt16 nResId = GetImageListRID( nCategoryRID );
     195                 :         34 :     pImageList = GetImageList( nResId );
     196                 :            :     OSL_ENSURE( pImageList && nIdx >= 0, "image list or index missing" );
     197 [ +  - ][ +  - ]:         34 :     if (pImageList && nIdx >= 0)
     198                 :         34 :         vToolBoxCategories[ nIdx ]->SetImageList( *pImageList );
     199                 :         34 : }
     200                 :            : 
     201                 :          0 : void SmToolBoxWindow::DataChanged( const DataChangedEvent &rEvt )
     202                 :            : {
     203 [ #  # ][ #  # ]:          0 :     if ( (rEvt.GetType() == DATACHANGED_SETTINGS) && (rEvt.GetFlags() & SETTINGS_STYLE) )
                 [ #  # ]
     204                 :          0 :         ApplyImageLists( nActiveCategoryRID );
     205                 :            : 
     206                 :          0 :     SfxFloatingWindow::DataChanged( rEvt );
     207                 :          0 : }
     208                 :            : 
     209                 :        204 : void SmToolBoxWindow::StateChanged( StateChangedType nStateChange )
     210                 :            : {
     211                 :            :     static bool bSetPosition = true;
     212         [ +  + ]:        204 :     if (STATE_CHANGE_INITSHOW == nStateChange)
     213                 :            :     {
     214         [ +  + ]:         68 :         SetCategory( nActiveCategoryRID == USHRT_MAX ? RID_UNBINOPS_CAT : nActiveCategoryRID );
     215                 :            : 
     216                 :            :         // calculate initial position to be used after creation of the window...
     217                 :         68 :         AdjustPosSize( bSetPosition );
     218                 :         68 :         bSetPosition = false;
     219                 :            :     }
     220                 :            :     //... otherwise the base class will remember the last position of the window
     221                 :        204 :     SfxFloatingWindow::StateChanged( nStateChange );
     222                 :        204 : }
     223                 :            : 
     224                 :            : 
     225                 :         68 : void SmToolBoxWindow::AdjustPosSize( bool bSetPos )
     226                 :            : {
     227         [ +  - ]:         68 :     Size aCatSize( aToolBoxCat.CalcWindowSizePixel( 2 ) );
     228         [ +  - ]:         68 :     Size aCmdSize( pToolBoxCmd->CalcWindowSizePixel( 7 /* see nLines in SetCategory*/ ) );
     229                 :            :     OSL_ENSURE( aCatSize.Width() == aCmdSize.Width(), "width mismatch" );
     230                 :            : 
     231                 :            :     // catalog settings
     232         [ +  - ]:         68 :     aToolBoxCat.SetPosPixel( Point(0, 3) );
     233         [ +  - ]:         68 :     aToolBoxCat.SetSizePixel( aCatSize );
     234                 :            :     // settings for catalog / category delimiter
     235         [ +  - ]:         68 :     Point aP( aToolBoxCat_Delim.GetPosPixel() );
     236                 :         68 :     aP.X() = 0;
     237         [ +  - ]:         68 :     aToolBoxCat_Delim.SetPosPixel( aP );
     238 [ +  - ][ +  - ]:         68 :     aToolBoxCat_Delim.SetSizePixel( Size( aCatSize.Width(), aToolBoxCat_Delim.GetSizePixel().Height() ) );
     239                 :            :     // category settings
     240         [ +  - ]:         68 :     aP.Y() += aToolBoxCat_Delim.GetSizePixel().Height();
     241         [ +  + ]:        680 :     for (int i = 0;  i < NUM_TBX_CATEGORIES;  ++i)
     242                 :            :     {
     243         [ +  - ]:        612 :         vToolBoxCategories[i]->SetPosPixel( aP );
     244         [ +  - ]:        612 :         vToolBoxCategories[i]->SetSizePixel( aCmdSize );
     245                 :            :     }
     246                 :            :     // main window settings
     247 [ +  - ][ +  - ]:         68 :     Size    aWndSize ( aCatSize.Width(), pToolBoxCmd->GetPosPixel().Y() + pToolBoxCmd->GetSizePixel().Height() + 3);
     248         [ +  - ]:         68 :     SetOutputSizePixel( aWndSize );
     249                 :            : 
     250         [ +  + ]:         68 :     if (bSetPos)
     251                 :            :     {
     252         [ +  - ]:          4 :         SmViewShell *pView = GetView();
     253                 :            :         OSL_ENSURE( pView, "view shell missing" );
     254                 :          4 :         Point aPos( 50, 75 );
     255         [ +  - ]:          4 :         if (pView)
     256                 :            :         {
     257                 :          4 :             SmGraphicWindow &rWin = pView->GetGraphicWindow();
     258                 :            :             aPos = Point( rWin.OutputToScreenPixel(
     259 [ +  - ][ +  - ]:          4 :                             Point( rWin.GetSizePixel().Width() - aWndSize.Width(), 0) ) );
     260                 :            :         }
     261         [ +  - ]:          4 :         if (aPos.X() < 0)
     262                 :          4 :             aPos.X() = 0;
     263         [ -  + ]:          4 :         if (aPos.Y() < 0)
     264                 :          0 :             aPos.Y() = 0;
     265         [ +  - ]:          4 :         SetPosPixel( aPos );
     266                 :            :     }
     267                 :         68 : }
     268                 :            : 
     269                 :            : 
     270                 :          0 : sal_Bool SmToolBoxWindow::Close()
     271                 :            : {
     272                 :          0 :     SmViewShell *pViewSh = GetView();
     273         [ #  # ]:          0 :     if (pViewSh)
     274                 :            :         pViewSh->GetViewFrame()->GetDispatcher()->Execute(
     275                 :            :                 SID_TOOLBOX, SFX_CALLMODE_STANDARD,
     276         [ #  # ]:          0 :                 new SfxBoolItem(SID_TOOLBOX, false), 0L);
     277                 :          0 :     return true;
     278                 :            : }
     279                 :            : 
     280                 :          0 : void SmToolBoxWindow::GetFocus()
     281                 :            : {
     282                 :            :     // give focus to category toolbox
     283                 :            :     // (allow for cursor travelling when a category is selected with the mouse)
     284                 :          0 :     aToolBoxCat.GrabFocus();
     285                 :          0 : }
     286                 :            : 
     287                 :         68 : void SmToolBoxWindow::SetCategory(sal_uInt16 nCategoryRID)
     288                 :            : {
     289         [ +  + ]:         68 :     if (nCategoryRID != nActiveCategoryRID)
     290         [ +  - ]:         34 :         ApplyImageLists( nCategoryRID );
     291                 :            : 
     292                 :            :     sal_uInt16 nLines;
     293                 :            :     // check for valid resource id
     294   [ +  -  -  -  :         68 :     switch (nCategoryRID)
          -  -  -  -  -  
                      - ]
     295                 :            :     {
     296                 :         68 :         case RID_UNBINOPS_CAT :     nLines = 4; break;
     297                 :          0 :         case RID_RELATIONS_CAT:     nLines = 7; break;
     298                 :          0 :         case RID_SETOPERATIONS_CAT: nLines = 5; break;
     299                 :          0 :         case RID_FUNCTIONS_CAT:     nLines = 5; break;
     300                 :          0 :         case RID_OPERATORS_CAT:     nLines = 3; break;
     301                 :          0 :         case RID_ATTRIBUTES_CAT:    nLines = 5; break;
     302                 :          0 :         case RID_MISC_CAT:          nLines = 4; break;
     303                 :          0 :         case RID_BRACKETS_CAT:      nLines = 5; break;
     304                 :          0 :         case RID_FORMAT_CAT:        nLines = 3; break;
     305                 :            :         default:
     306                 :            :             // nothing to be done
     307                 :         68 :             return;
     308                 :            :     }
     309                 :            : 
     310         [ +  - ]:         68 :     pToolBoxCmd->Hide();
     311                 :            : 
     312                 :         68 :     sal_Int16 nIdx = GetToolBoxCategoriesIndex( nCategoryRID );
     313                 :            :         OSL_ENSURE( nIdx >= 0, "unkown category" );
     314         [ +  - ]:         68 :     if (nIdx >= 0)
     315                 :         68 :         pToolBoxCmd = vToolBoxCategories[nIdx];
     316                 :            : 
     317                 :            :     // calculate actual size of window to use
     318         [ +  - ]:         68 :     Size aCatSize( aToolBoxCat.CalcWindowSizePixel( 2 ) );
     319         [ +  - ]:         68 :     Size aCmdSize( pToolBoxCmd->CalcWindowSizePixel( nLines ) );
     320                 :            :         OSL_ENSURE( aCatSize.Width() == aCmdSize.Width(), "width mismatch" );
     321                 :            :     // main window settings
     322         [ +  - ]:         68 :     Size  aWndSize ( aCatSize.Width(), pToolBoxCmd->GetPosPixel().Y() + aCmdSize.Height() + 3);
     323         [ +  - ]:         68 :     SetOutputSizePixel( aWndSize );
     324                 :            : 
     325         [ +  - ]:         68 :     if (nActiveCategoryRID)
     326         [ +  - ]:         68 :             aToolBoxCat.CheckItem(nActiveCategoryRID, false);
     327                 :         68 :     nActiveCategoryRID = nCategoryRID;
     328         [ +  - ]:         68 :         aToolBoxCat.CheckItem(nActiveCategoryRID, true);
     329                 :            : 
     330         [ +  - ]:         68 :     pToolBoxCmd->Show();
     331                 :            : }
     332                 :            : 
     333                 :            : 
     334                 :          0 : IMPL_LINK( SmToolBoxWindow, CategoryClickHdl, ToolBox*, pToolBox)
     335                 :            : {
     336                 :          0 :     int nItemId = pToolBox->GetCurItemId();
     337         [ #  # ]:          0 :     if (nItemId != 0)
     338                 :          0 :         SetCategory( sal::static_int_cast< sal_uInt16 >(nItemId) );
     339                 :          0 :     return 0;
     340                 :            : }
     341                 :            : 
     342                 :            : 
     343                 :          0 : IMPL_LINK( SmToolBoxWindow, CmdSelectHdl, ToolBox*, pToolBox)
     344                 :            : {
     345                 :          0 :     SmViewShell *pViewSh = GetView();
     346         [ #  # ]:          0 :     if (pViewSh)
     347                 :            :         pViewSh->GetViewFrame()->GetDispatcher()->Execute(
     348                 :            :                 SID_INSERTCOMMAND, SFX_CALLMODE_STANDARD,
     349         [ #  # ]:          0 :                 new SfxInt16Item(SID_INSERTCOMMAND, pToolBox->GetCurItemId()), 0L);
     350                 :          0 :     return 0;
     351                 :            : }
     352                 :            : 
     353                 :            : 
     354                 :            : /**************************************************************************/
     355                 :            : 
     356 [ +  - ][ +  - ]:        108 : SFX_IMPL_FLOATINGWINDOW_WITHID(SmToolBoxWrapper, SID_TOOLBOXWINDOW);
                 [ +  - ]
     357                 :            : 
     358                 :         34 : SmToolBoxWrapper::SmToolBoxWrapper(Window *pParentWindow,
     359                 :            :                                    sal_uInt16 nId, SfxBindings* pBindings,
     360                 :            :                                    SfxChildWinInfo *pInfo) :
     361                 :         34 :     SfxChildWindow(pParentWindow, nId)
     362                 :            : {
     363                 :         34 :     eChildAlignment = SFX_ALIGN_NOALIGNMENT;
     364                 :            : 
     365 [ +  - ][ +  - ]:         34 :     pWindow = new SmToolBoxWindow(pBindings, this, pParentWindow);
     366         [ +  - ]:         34 :     ((SfxFloatingWindow *)pWindow)->Initialize(pInfo);
     367 [ +  - ][ +  - ]:         64 : }
     368                 :            : 
     369                 :            : 
     370                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10