LCOV - code coverage report
Current view: top level - libreoffice/starmath/source - toolbox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 176 1.1 %
Date: 2012-12-27 Functions: 4 26 15.4 %
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 <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           0 : static sal_uInt16  GetImageListRID( sal_uInt16 nCategoryRID )
      37             : {
      38           0 :     sal_uInt16 nRes = 0xFFFF;
      39           0 :     switch (nCategoryRID)
      40             :     {
      41           0 :         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           0 :     return nRes;
      54             : }
      55             : 
      56             : 
      57           0 : static sal_Int16  GetToolBoxCategoriesIndex( sal_uInt16 nCategoryRID )
      58             : {
      59           0 :     sal_Int16 nIdx = -1;
      60           0 :     switch (nCategoryRID)
      61             :     {
      62           0 :         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           0 :     return nIdx;
      75             : }
      76             : 
      77             : 
      78           0 : static sal_uInt16  GetCategoryRID( sal_uInt16 nResId )
      79             : {
      80           0 :     sal_uInt16 nRes = 0xFFFF;
      81           0 :     switch (nResId)
      82             :     {
      83           0 :         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           0 :     return nRes;
     101             : }
     102             : 
     103             : 
     104             : ////////////////////////////////////////////////////////////
     105             : 
     106             : 
     107           0 : 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           0 :     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           0 :     SetStyle( GetStyle() | WB_DIALOGCONTROL );
     118             : 
     119           0 :     nActiveCategoryRID = USHRT_MAX;
     120             : 
     121           0 :     aToolBoxCat.SetClickHdl(LINK(this, SmToolBoxWindow, CategoryClickHdl));
     122             : 
     123             :     sal_uInt16 i;
     124           0 :     for (i = 0;  i < NUM_TBX_CATEGORIES;  ++i)
     125             :     {
     126           0 :         ToolBox *pBox = new ToolBox(this, SmResId( TOOLBOX_CAT_A + i ));
     127           0 :         vToolBoxCategories[i] = pBox;
     128           0 :         pBox->SetSelectHdl(LINK(this, SmToolBoxWindow, CmdSelectHdl));
     129             :     }
     130           0 :     pToolBoxCmd = vToolBoxCategories[0];
     131             : 
     132           0 :     for (i = 0;  i <= NUM_TBX_CATEGORIES; ++i)
     133           0 :         aImageLists [i] = 0;
     134             : 
     135           0 :     FreeResource();
     136           0 : }
     137             : 
     138           0 : SmToolBoxWindow::~SmToolBoxWindow()
     139             : {
     140             :     int i;
     141           0 :     for (i = 0;  i < NUM_TBX_CATEGORIES;  ++i)
     142             :     {
     143           0 :         ToolBox *pBox = vToolBoxCategories[i];
     144           0 :         delete pBox;
     145             :     }
     146           0 :     for (i = 0;  i < NUM_TBX_CATEGORIES + 1;  ++i)
     147           0 :         delete aImageLists[i];
     148           0 : }
     149             : 
     150             : 
     151           0 : SmViewShell * SmToolBoxWindow::GetView()
     152             : {
     153           0 :     SfxViewShell *pView = GetBindings().GetDispatcher()->GetFrame()->GetViewShell();
     154           0 :     return PTR_CAST(SmViewShell, pView);
     155             : }
     156             : 
     157             : 
     158           0 : 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           0 :     const ImageList *pIL = 0;
     164             : 
     165             :     // get index to use
     166           0 :     sal_uInt16 nCategoryRID = GetCategoryRID( nResId );
     167           0 :     sal_Int16 nIndex = GetToolBoxCategoriesIndex( nCategoryRID );
     168           0 :     if (nIndex == -1 && (nResId == RID_IL_CATALOG))
     169           0 :         nIndex = NUM_TBX_CATEGORIES;
     170             : 
     171           0 :     if (nIndex >= 0)
     172             :     {
     173           0 :         ImageList **pImgList = aImageLists;
     174           0 :         if (!pImgList[ nIndex ])
     175           0 :             pImgList[ nIndex ] = new ImageList( SmResId(nResId) );
     176           0 :         pIL = pImgList[ nIndex ];
     177             :     }
     178             : 
     179             :     OSL_ENSURE( pIL, "image list not found!" );
     180           0 :     return pIL;
     181             : }
     182             : 
     183             : 
     184           0 : void SmToolBoxWindow::ApplyImageLists( sal_uInt16 nCategoryRID )
     185             : {
     186             :     // set image list for toolbox 'catalog'
     187           0 :     const ImageList *pImageList = GetImageList( RID_IL_CATALOG );
     188             :     OSL_ENSURE( pImageList, "image list missing" );
     189           0 :     if (pImageList)
     190           0 :         aToolBoxCat.SetImageList( *pImageList );
     191             : 
     192             :     // set image list for active (visible) category of 'catalog'
     193           0 :     sal_Int16 nIdx = GetToolBoxCategoriesIndex( nCategoryRID );
     194           0 :     sal_uInt16 nResId = GetImageListRID( nCategoryRID );
     195           0 :     pImageList = GetImageList( nResId );
     196             :     OSL_ENSURE( pImageList && nIdx >= 0, "image list or index missing" );
     197           0 :     if (pImageList && nIdx >= 0)
     198           0 :         vToolBoxCategories[ nIdx ]->SetImageList( *pImageList );
     199           0 : }
     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           0 : void SmToolBoxWindow::StateChanged( StateChangedType nStateChange )
     210             : {
     211             :     static bool bSetPosition = true;
     212           0 :     if (STATE_CHANGE_INITSHOW == nStateChange)
     213             :     {
     214           0 :         SetCategory( nActiveCategoryRID == USHRT_MAX ? RID_UNBINOPS_CAT : nActiveCategoryRID );
     215             : 
     216             :         // calculate initial position to be used after creation of the window...
     217           0 :         AdjustPosSize( bSetPosition );
     218           0 :         bSetPosition = false;
     219             :     }
     220             :     //... otherwise the base class will remember the last position of the window
     221           0 :     SfxFloatingWindow::StateChanged( nStateChange );
     222           0 : }
     223             : 
     224             : 
     225           0 : void SmToolBoxWindow::AdjustPosSize( bool bSetPos )
     226             : {
     227           0 :     Size aCatSize( aToolBoxCat.CalcWindowSizePixel( 2 ) );
     228           0 :     Size aCmdSize( pToolBoxCmd->CalcWindowSizePixel( 7 /* see nLines in SetCategory*/ ) );
     229             :     OSL_ENSURE( aCatSize.Width() == aCmdSize.Width(), "width mismatch" );
     230             : 
     231             :     // catalog settings
     232           0 :     aToolBoxCat.SetPosPixel( Point(0, 3) );
     233           0 :     aToolBoxCat.SetSizePixel( aCatSize );
     234             :     // settings for catalog / category delimiter
     235           0 :     Point aP( aToolBoxCat_Delim.GetPosPixel() );
     236           0 :     aP.X() = 0;
     237           0 :     aToolBoxCat_Delim.SetPosPixel( aP );
     238           0 :     aToolBoxCat_Delim.SetSizePixel( Size( aCatSize.Width(), aToolBoxCat_Delim.GetSizePixel().Height() ) );
     239             :     // category settings
     240           0 :     aP.Y() += aToolBoxCat_Delim.GetSizePixel().Height();
     241           0 :     for (int i = 0;  i < NUM_TBX_CATEGORIES;  ++i)
     242             :     {
     243           0 :         vToolBoxCategories[i]->SetPosPixel( aP );
     244           0 :         vToolBoxCategories[i]->SetSizePixel( aCmdSize );
     245             :     }
     246             :     // main window settings
     247           0 :     Size    aWndSize ( aCatSize.Width(), pToolBoxCmd->GetPosPixel().Y() + pToolBoxCmd->GetSizePixel().Height() + 3);
     248           0 :     SetOutputSizePixel( aWndSize );
     249             : 
     250           0 :     if (bSetPos)
     251             :     {
     252           0 :         SmViewShell *pView = GetView();
     253             :         OSL_ENSURE( pView, "view shell missing" );
     254           0 :         Point aPos( 50, 75 );
     255           0 :         if (pView)
     256             :         {
     257           0 :             SmGraphicWindow &rWin = pView->GetGraphicWindow();
     258             :             aPos = Point( rWin.OutputToScreenPixel(
     259           0 :                             Point( rWin.GetSizePixel().Width() - aWndSize.Width(), 0) ) );
     260             :         }
     261           0 :         if (aPos.X() < 0)
     262           0 :             aPos.X() = 0;
     263           0 :         if (aPos.Y() < 0)
     264           0 :             aPos.Y() = 0;
     265           0 :         SetPosPixel( aPos );
     266             :     }
     267           0 : }
     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           0 : void SmToolBoxWindow::SetCategory(sal_uInt16 nCategoryRID)
     288             : {
     289           0 :     if (nCategoryRID != nActiveCategoryRID)
     290           0 :         ApplyImageLists( nCategoryRID );
     291             : 
     292             :     sal_uInt16 nLines;
     293             :     // check for valid resource id
     294           0 :     switch (nCategoryRID)
     295             :     {
     296           0 :         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           0 :             return;
     308             :     }
     309             : 
     310           0 :     pToolBoxCmd->Hide();
     311             : 
     312           0 :     sal_Int16 nIdx = GetToolBoxCategoriesIndex( nCategoryRID );
     313             :         OSL_ENSURE( nIdx >= 0, "unkown category" );
     314           0 :     if (nIdx >= 0)
     315           0 :         pToolBoxCmd = vToolBoxCategories[nIdx];
     316             : 
     317             :     // calculate actual size of window to use
     318           0 :     Size aCatSize( aToolBoxCat.CalcWindowSizePixel( 2 ) );
     319           0 :     Size aCmdSize( pToolBoxCmd->CalcWindowSizePixel( nLines ) );
     320             :         OSL_ENSURE( aCatSize.Width() == aCmdSize.Width(), "width mismatch" );
     321             :     // main window settings
     322           0 :     Size  aWndSize ( aCatSize.Width(), pToolBoxCmd->GetPosPixel().Y() + aCmdSize.Height() + 3);
     323           0 :     SetOutputSizePixel( aWndSize );
     324             : 
     325           0 :     if (nActiveCategoryRID)
     326           0 :             aToolBoxCat.CheckItem(nActiveCategoryRID, false);
     327           0 :     nActiveCategoryRID = nCategoryRID;
     328           0 :         aToolBoxCat.CheckItem(nActiveCategoryRID, true);
     329             : 
     330           0 :     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           8 : SFX_IMPL_FLOATINGWINDOW_WITHID(SmToolBoxWrapper, SID_TOOLBOXWINDOW);
     357             : 
     358           0 : SmToolBoxWrapper::SmToolBoxWrapper(Window *pParentWindow,
     359             :                                    sal_uInt16 nId, SfxBindings* pBindings,
     360             :                                    SfxChildWinInfo *pInfo) :
     361           0 :     SfxChildWindow(pParentWindow, nId)
     362             : {
     363           0 :     eChildAlignment = SFX_ALIGN_NOALIGNMENT;
     364             : 
     365           0 :     pWindow = new SmToolBoxWindow(pBindings, this, pParentWindow);
     366           0 :     ((SfxFloatingWindow *)pWindow)->Initialize(pInfo);
     367          12 : }
     368             : 
     369             : 
     370             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10