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

Generated by: LCOV version 1.10