/Users/ericb/Desktop/SRC680_m247/starmath/source/toolbox.cxx

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  OpenOffice.org - a multi-platform office productivity suite
00004  *
00005  *  $RCSfile: toolbox.cxx,v $
00006  *
00007  *  $Revision: 1.22 $
00008  *
00009  *  last change: $Author: vg $ $Date: 2007/05/31 11:22:04 $
00010  *
00011  *  The Contents of this file are made available subject to
00012  *  the terms of GNU Lesser General Public License Version 2.1.
00013  *
00014  *
00015  *    GNU Lesser General Public License Version 2.1
00016  *    =============================================
00017  *    Copyright 2005 by Sun Microsystems, Inc.
00018  *    901 San Antonio Road, Palo Alto, CA 94303, USA
00019  *
00020  *    This library is free software; you can redistribute it and/or
00021  *    modify it under the terms of the GNU Lesser General Public
00022  *    License version 2.1, as published by the Free Software Foundation.
00023  *
00024  *    This library is distributed in the hope that it will be useful,
00025  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00026  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027  *    Lesser General Public License for more details.
00028  *
00029  *    You should have received a copy of the GNU Lesser General Public
00030  *    License along with this library; if not, write to the Free Software
00031  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00032  *    MA  02111-1307  USA
00033  *
00034  ************************************************************************/
00035 
00036 // MARKER(update_precomp.py): autogen include statement, do not remove
00037 #include "precompiled_starmath.hxx"
00038 
00039 
00040 #ifndef _RTL_LOGFILE_HXX_
00041 #include <rtl/logfile.hxx>
00042 #endif
00043 
00044 #ifndef _SFXENUMITEM_HXX //autogen
00045 #include <svtools/eitem.hxx>
00046 #endif
00047 #ifndef _SFXAPP_HXX //autogen
00048 #include <sfx2/app.hxx>
00049 #endif
00050 #ifndef _SFXINTITEM_HXX //autogen
00051 #include <svtools/intitem.hxx>
00052 #endif
00053 #ifndef _SVTOOLS_IMGDEF_HXX
00054 #include <svtools/imgdef.hxx>
00055 #endif
00056 #ifndef _SFXDISPATCH_HXX //autogen
00057 #include <sfx2/dispatch.hxx>
00058 #endif
00059 #ifndef _SFXIMGMGR_HXX //autogen
00060 #include <sfx2/imgmgr.hxx>
00061 #endif
00062 #ifndef _SV_WRKWIN_HXX //autogen
00063 #include <vcl/wrkwin.hxx>
00064 #endif
00065 
00066 #ifndef TOOLBOX_HXX
00067 #include "toolbox.hxx"
00068 #endif
00069 #ifndef _STARMATH_HRC
00070 #include "starmath.hrc"
00071 #endif
00072 #ifndef _TOOLBOX_HRC_
00073 #include "toolbox.hrc"
00074 #endif
00075 #include "view.hxx"
00076 
00077 
00079 
00080 static USHORT  GetImageListRID( USHORT nCategoryRID, BOOL bHighContrast )
00081 {
00082     USHORT nRes = 0xFFFF;
00083     switch (nCategoryRID)
00084     {
00085         case RID_UNBINOPS_CAT       : nRes = RID_IL_UNBINOPS; break;
00086         case RID_RELATIONS_CAT      : nRes = RID_IL_RELATIONS; break;
00087         case RID_SETOPERATIONS_CAT  : nRes = RID_IL_SETOPERATIONS; break;
00088         case RID_FUNCTIONS_CAT      : nRes = RID_IL_FUNCTIONS; break;
00089         case RID_OPERATORS_CAT      : nRes = RID_IL_OPERATORS; break;
00090         case RID_ATTRIBUTES_CAT     : nRes = RID_IL_ATTRIBUTES; break;
00091         case RID_BRACKETS_CAT       : nRes = RID_IL_BRACKETS; break;
00092         case RID_FORMAT_CAT         : nRes = RID_IL_FORMAT; break;
00093         case RID_MISC_CAT           : nRes = RID_IL_MISC; break;
00094         default :
00095             DBG_ERROR( "unkown category" );
00096     }
00097     if (nRes != 0xFFFF && bHighContrast)
00098         ++nRes;     
00099     return nRes;
00100 }
00101 
00102 
00103 static sal_Int16  GetToolBoxCategoriesIndex( USHORT nCategoryRID )
00104 {
00105     sal_Int16 nIdx = -1;
00106     switch (nCategoryRID)
00107     {
00108         case RID_UNBINOPS_CAT       : nIdx = 0; break;
00109         case RID_RELATIONS_CAT      : nIdx = 1; break;
00110         case RID_SETOPERATIONS_CAT  : nIdx = 2; break;
00111         case RID_FUNCTIONS_CAT      : nIdx = 3; break;
00112         case RID_OPERATORS_CAT      : nIdx = 4; break;
00113         case RID_ATTRIBUTES_CAT     : nIdx = 5; break;
00114         case RID_BRACKETS_CAT       : nIdx = 6; break;
00115         case RID_FORMAT_CAT         : nIdx = 7; break;
00116         case RID_MISC_CAT           : nIdx = 8; break;
00117         default:
00118                         ;
00119     }
00120     return nIdx;
00121 }
00122 
00123 
00124 static USHORT  GetCategoryRID( USHORT nResId )
00125 {
00126     USHORT nRes = 0xFFFF;
00127     switch (nResId)
00128     {
00129         case RID_IL_UNBINOPS        :
00130         case RID_ILH_UNBINOPS       : nRes = RID_UNBINOPS_CAT; break;
00131         case RID_IL_RELATIONS       :
00132         case RID_ILH_RELATIONS      : nRes = RID_RELATIONS_CAT; break;
00133         case RID_IL_SETOPERATIONS   :
00134         case RID_ILH_SETOPERATIONS  : nRes = RID_SETOPERATIONS_CAT; break;
00135         case RID_IL_FUNCTIONS       :
00136         case RID_ILH_FUNCTIONS      : nRes = RID_FUNCTIONS_CAT; break;
00137         case RID_IL_OPERATORS       :
00138         case RID_ILH_OPERATORS      : nRes = RID_OPERATORS_CAT; break;
00139         case RID_IL_ATTRIBUTES      :
00140         case RID_ILH_ATTRIBUTES     : nRes = RID_ATTRIBUTES_CAT; break;
00141         case RID_IL_BRACKETS        :
00142         case RID_ILH_BRACKETS       : nRes = RID_BRACKETS_CAT; break;
00143         case RID_IL_FORMAT          :
00144         case RID_ILH_FORMAT         : nRes = RID_FORMAT_CAT; break;
00145         case RID_IL_MISC            :
00146         case RID_ILH_MISC           : nRes = RID_MISC_CAT; break;
00147         default :
00148             if (nResId != RID_IL_CATALOG  &&  nResId != RID_ILH_CATALOG)
00149             {
00150 #if OSL_DEBUG_LEVEL > 1
00151                 DBG_ERROR( "unkown category" );
00152 #endif
00153             }
00154     }
00155     return nRes;
00156 }
00157 
00158 
00160 
00161 
00162 SmToolBoxWindow::SmToolBoxWindow(SfxBindings *pTmpBindings,
00163                                                                  SfxChildWindow *pChildWindow,
00164                                                                  Window *pParent) :
00165     SfxFloatingWindow(pTmpBindings, pChildWindow, pParent, SmResId(RID_TOOLBOXWINDOW)),
00166     aToolBoxCat(this, SmResId(NUM_TBX_CATEGORIES + 1)),
00167     aToolBoxCat_Delim(this, SmResId( FL_TOOLBOX_CAT_DELIM ))
00168 {
00169     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmToolBoxWindow::SmToolBoxWindow" );
00170 
00171     // allow for cursor travelling between toolbox and sub-categories
00172     SetStyle( GetStyle() | WB_DIALOGCONTROL );
00173 
00174     nActiveCategoryRID = sal::static_int_cast< USHORT >(-1);
00175     
00176     aToolBoxCat.SetClickHdl(LINK(this, SmToolBoxWindow, CategoryClickHdl));
00177 
00178     USHORT i;
00179     for (i = 0;  i < NUM_TBX_CATEGORIES;  i++)
00180         {
00181                 ToolBox *pBox = new ToolBox(this, SmResId (i+1));
00182                 vToolBoxCategories[i] = pBox;
00183                 pBox->SetSelectHdl(LINK(this, SmToolBoxWindow, CmdSelectHdl));
00184         }
00185     pToolBoxCmd = vToolBoxCategories[0];
00186 
00187     for (i = 0;  i <= NUM_TBX_CATEGORIES; ++i)
00188     {
00189         aImageLists [i] = 0;
00190         aImageListsH[i] = 0;
00191     }
00192 
00193         FreeResource();
00194 
00195     ApplyImageLists( RID_UNBINOPS_CAT );
00196     SetCategory( RID_UNBINOPS_CAT );
00197 }
00198 
00199 SmToolBoxWindow::~SmToolBoxWindow()
00200 {
00201     int i;
00202     for (i = 0;  i < NUM_TBX_CATEGORIES;  i++)
00203         {
00204                 ToolBox *pBox = vToolBoxCategories[i];
00205                 delete pBox;
00206         }
00207     for (i = 0;  i < NUM_TBX_CATEGORIES + 1;  ++i)
00208         {
00209         delete aImageLists[i];
00210         delete aImageListsH[i];
00211         }
00212 }
00213 
00214 
00215 SmViewShell * SmToolBoxWindow::GetView()
00216 {
00217     SfxViewShell *pView = GetBindings().GetDispatcher()->GetFrame()->GetViewShell();
00218     return PTR_CAST(SmViewShell, pView);
00219 }
00220 
00221 
00222 const ImageList * SmToolBoxWindow::GetImageList( USHORT nResId, BOOL bHighContrast )
00223 {
00224     // creates the image list via its resource id and stores that
00225     // list for later use in the respective array.
00226 
00227     const ImageList *pIL = 0;
00228     
00229     // get index to use
00230     USHORT nCategoryRID = GetCategoryRID( nResId );
00231     sal_Int16 nIndex = GetToolBoxCategoriesIndex( nCategoryRID );
00232     if (nIndex == -1 && (nResId == RID_IL_CATALOG || nResId == RID_ILH_CATALOG))
00233         nIndex = NUM_TBX_CATEGORIES;
00234 
00235     if (nIndex >= 0)
00236     {
00237         ImageList **pImgList = bHighContrast ? aImageListsH : aImageLists;
00238         if (!pImgList[ nIndex ])
00239             pImgList[ nIndex ] = new ImageList( SmResId(nResId) );
00240         pIL = pImgList[ nIndex ];
00241     }
00242 
00243     DBG_ASSERT( pIL, "image list not found!" );
00244     return pIL;
00245 }
00246 
00247 
00248 void SmToolBoxWindow::ApplyImageLists( USHORT nCategoryRID )
00249 {
00250     BOOL bHighContrast = GetDisplayBackground().GetColor().IsDark() != 0;
00251         
00252     // set image list for toolbox 'catalog'
00253         const ImageList *pImageList = GetImageList( bHighContrast ? RID_ILH_CATALOG : RID_IL_CATALOG, bHighContrast );
00254     DBG_ASSERT( pImageList, "image list missing" );
00255     if (pImageList)
00256         aToolBoxCat.SetImageList( *pImageList );
00257         
00258     // set image list for active (visible) category of 'catalog'
00259     sal_Int16 nIdx = GetToolBoxCategoriesIndex( nCategoryRID );
00260     USHORT nResId = GetImageListRID( nCategoryRID, bHighContrast );
00261     pImageList = GetImageList( nResId, bHighContrast );
00262     DBG_ASSERT( pImageList && nIdx >= 0, "image list or index missing" );
00263     if (pImageList && nIdx >= 0)
00264         vToolBoxCategories[ nIdx ]->SetImageList( *pImageList );
00265 }
00266 
00267 void SmToolBoxWindow::DataChanged( const DataChangedEvent &rEvt )
00268 {
00269     if ( (rEvt.GetType() == DATACHANGED_SETTINGS) && (rEvt.GetFlags() & SETTINGS_STYLE) )
00270         ApplyImageLists( nActiveCategoryRID );
00271 
00272     SfxFloatingWindow::DataChanged( rEvt );
00273 }
00274 
00275 void SmToolBoxWindow::StateChanged( StateChangedType nStateChange )
00276 {
00277     static BOOL bSetPosition = TRUE;
00278     if (STATE_CHANGE_INITSHOW == nStateChange)
00279     {
00280         // calculate initial position to be used after creation of the window...
00281         AdjustPosSize( bSetPosition );
00282         bSetPosition = FALSE;
00283 
00284         SetCategory(RID_UNBINOPS_CAT);
00285     }
00286     //... otherwise the base class will remember the last position of the window
00287     SfxFloatingWindow::StateChanged( nStateChange );
00288 }
00289 
00290 
00291 void SmToolBoxWindow::AdjustPosSize( BOOL bSetPos )
00292 {
00293     Size aCatSize( aToolBoxCat.CalcWindowSizePixel( 2 ) );
00294     Size aCmdSize( pToolBoxCmd->CalcWindowSizePixel( 5 ) );
00295     DBG_ASSERT( aCatSize.Width() == aCmdSize.Width(), "width mismatch" );
00296 
00297     // catalog settings
00298     aToolBoxCat.SetPosPixel( Point(0, 3) );
00299     aToolBoxCat.SetSizePixel( aCatSize );
00300     // settings for catalog / category delimiter
00301     Point aP( aToolBoxCat_Delim.GetPosPixel() );
00302     aP.X() += 5;
00303     aToolBoxCat_Delim.SetPosPixel( aP );
00304     Size  aS( aCatSize.Width() - 10, 10 );
00305     aToolBoxCat_Delim.SetSizePixel( aS );
00306     // category settings
00307     aP.X() = 0;
00308     aP.Y() += aToolBoxCat_Delim.GetSizePixel().Height();
00309         for (int i = 0;  i < NUM_TBX_CATEGORIES;  i++)
00310     {
00311         vToolBoxCategories[i]->SetPosPixel( aP );
00312         vToolBoxCategories[i]->SetSizePixel( aCmdSize );
00313     }
00314     // main window settings
00315     Size    aWndSize ( aCatSize.Width(), pToolBoxCmd->GetPosPixel().Y() + pToolBoxCmd->GetSizePixel().Height() + 3);
00316     SetOutputSizePixel( aWndSize );
00317 
00318     if (bSetPos)
00319         {
00320         SmViewShell *pView = GetView();
00321         DBG_ASSERT( pView, "view shell missing" );
00322         Point aPos( 50, 75 );
00323         if (pView)
00324         {
00325             SmGraphicWindow &rWin = pView->GetGraphicWindow();
00326             aPos = Point( rWin.OutputToScreenPixel(
00327                             Point( rWin.GetSizePixel().Width() - aWndSize.Width(), 0) ) );
00328         }
00329                 if (aPos.X() < 0)
00330                         aPos.X() = 0;
00331                 if (aPos.Y() < 0)
00332                         aPos.Y() = 0;
00333         SetPosPixel( aPos );
00334         }
00335 }
00336 
00337 
00338 BOOL SmToolBoxWindow::Close()
00339 {
00340     SmViewShell *pViewSh = GetView();
00341         if (pViewSh)
00342                 pViewSh->GetViewFrame()->GetDispatcher()->Execute(
00343                                 SID_TOOLBOX, SFX_CALLMODE_STANDARD,
00344                                 new SfxBoolItem(SID_TOOLBOX, FALSE), 0L);
00345         return TRUE;
00346 }
00347 
00348 void SmToolBoxWindow::GetFocus()
00349 {
00350     // give focus to category toolbox
00351     // (allow for cursor travelling when a category is selected with the mouse)
00352     aToolBoxCat.GrabFocus();
00353 }
00354 
00355 void SmToolBoxWindow::SetCategory(USHORT nCategoryRID)
00356 {
00357     if (nCategoryRID != nActiveCategoryRID)
00358         {
00359         ApplyImageLists( nCategoryRID );
00360 
00361         USHORT nLines;
00362                 // check for valid resource id
00363         switch (nCategoryRID)
00364                 {
00365             case RID_UNBINOPS_CAT :     nLines = 4; break;
00366             case RID_RELATIONS_CAT:     nLines = 5; break;
00367             case RID_SETOPERATIONS_CAT: nLines = 5; break;
00368             case RID_FUNCTIONS_CAT:     nLines = 5; break;
00369             case RID_OPERATORS_CAT:     nLines = 3; break;
00370             case RID_ATTRIBUTES_CAT:    nLines = 5; break;
00371             case RID_MISC_CAT:          nLines = 4; break;
00372             case RID_BRACKETS_CAT:      nLines = 5; break;
00373             case RID_FORMAT_CAT:        nLines = 3; break;
00374                         default:
00375                                 // nothing to be done
00376                                 return;
00377                 }
00378 
00379                 pToolBoxCmd->Hide();
00380 
00381         sal_Int16 nIdx = GetToolBoxCategoriesIndex( nCategoryRID );
00382         DBG_ASSERT( nIdx >= 0, "unkown category" );
00383         if (nIdx >= 0)
00384             pToolBoxCmd = vToolBoxCategories[nIdx];
00385 
00386         // calculate actual size of window to use
00387         Size aCatSize( aToolBoxCat.CalcWindowSizePixel( 2 ) );
00388         Size aCmdSize( pToolBoxCmd->CalcWindowSizePixel( nLines ) );
00389         DBG_ASSERT( aCatSize.Width() == aCmdSize.Width(), "width mismatch" );
00390         // main window settings
00391         Size  aWndSize ( aCatSize.Width(), pToolBoxCmd->GetPosPixel().Y() + aCmdSize.Height() + 3);
00392         SetOutputSizePixel( aWndSize );
00393 
00394         if (nActiveCategoryRID)
00395             aToolBoxCat.CheckItem(nActiveCategoryRID, FALSE);
00396         nActiveCategoryRID = nCategoryRID;
00397         aToolBoxCat.CheckItem(nActiveCategoryRID, TRUE);
00398 
00399                 pToolBoxCmd->Show();
00400         }
00401 }
00402 
00403 
00404 IMPL_LINK_INLINE_START( SmToolBoxWindow, CategoryClickHdl, ToolBox*, pToolBox)
00405 {
00406         int nItemId = pToolBox->GetCurItemId();
00407         if (nItemId != 0)
00408         SetCategory( sal::static_int_cast< USHORT >(nItemId) );
00409         return 0;
00410 }
00411 IMPL_LINK_INLINE_END( SmToolBoxWindow, CategoryClickHdl, ToolBox*, pToolBox)
00412 
00413 
00414 IMPL_LINK_INLINE_START( SmToolBoxWindow, CmdSelectHdl, ToolBox*, pToolBox)
00415 {
00416     SmViewShell *pViewSh = GetView();
00417         if (pViewSh)
00418                 pViewSh->GetViewFrame()->GetDispatcher()->Execute(
00419                                 SID_INSERTCOMMAND, SFX_CALLMODE_STANDARD,
00420                                 new SfxInt16Item(SID_INSERTCOMMAND, pToolBox->GetCurItemId()), 0L);
00421         return 0;
00422 }
00423 IMPL_LINK_INLINE_END( SmToolBoxWindow, CmdSelectHdl, ToolBox*, pToolBox)
00424 
00425 
00426 /**************************************************************************/
00427 
00428 SFX_IMPL_FLOATINGWINDOW(SmToolBoxWrapper, SID_TOOLBOXWINDOW);
00429 
00430 SmToolBoxWrapper::SmToolBoxWrapper(Window *pParentWindow,
00431                                                                    USHORT nId, SfxBindings* pBindings,
00432                                                                    SfxChildWinInfo *pInfo) :
00433         SfxChildWindow(pParentWindow, nId)
00434 {
00435     eChildAlignment = SFX_ALIGN_NOALIGNMENT;
00436 
00437         pWindow = new SmToolBoxWindow(pBindings, this, pParentWindow);
00438     ((SfxFloatingWindow *)pWindow)->Initialize(pInfo);
00439 }
00440 
00441 

Generated on Wed Feb 20 17:21:57 2008 for maths by  doxygen 1.5.1