1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_formula.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir //---------------------------------------------------------------------------- 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <svl/zforlist.hxx> 36*cdf0e10cSrcweir #include <svl/stritem.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include "structpg.hxx" 39*cdf0e10cSrcweir #include "formdlgs.hrc" 40*cdf0e10cSrcweir #include "formula/formdata.hxx" 41*cdf0e10cSrcweir #include "formula/formula.hxx" 42*cdf0e10cSrcweir #include "ModuleHelper.hxx" 43*cdf0e10cSrcweir #include "formula/IFunctionDescription.hxx" 44*cdf0e10cSrcweir #include "ForResId.hrc" 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir //---------------------------------------------------------------------------- 47*cdf0e10cSrcweir namespace formula 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir StructListBox::StructListBox(Window* pParent, const ResId& rResId ): 50*cdf0e10cSrcweir SvTreeListBox(pParent,rResId ) 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir bActiveFlag=sal_False; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir Font aFont( GetFont() ); 55*cdf0e10cSrcweir Size aSize = aFont.GetSize(); 56*cdf0e10cSrcweir aSize.Height() -= 2; 57*cdf0e10cSrcweir aFont.SetSize( aSize ); 58*cdf0e10cSrcweir SetFont( aFont ); 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir SvLBoxEntry* StructListBox::InsertStaticEntry( 62*cdf0e10cSrcweir const XubString& rText, 63*cdf0e10cSrcweir const Image& rEntryImg, const Image& rEntryImgHC, 64*cdf0e10cSrcweir SvLBoxEntry* pParent, sal_uLong nPos, IFormulaToken* pToken ) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir SvLBoxEntry* pEntry = InsertEntry( rText, rEntryImg, rEntryImg, pParent, sal_False, nPos, pToken ); 67*cdf0e10cSrcweir SvLBoxContextBmp* pBmpItem = static_cast< SvLBoxContextBmp* >( pEntry->GetFirstItem( SV_ITEM_ID_LBOXCONTEXTBMP ) ); 68*cdf0e10cSrcweir DBG_ASSERT( pBmpItem, "StructListBox::InsertStaticEntry - missing item" ); 69*cdf0e10cSrcweir pBmpItem->SetBitmap1( rEntryImgHC, BMP_COLOR_HIGHCONTRAST ); 70*cdf0e10cSrcweir pBmpItem->SetBitmap2( rEntryImgHC, BMP_COLOR_HIGHCONTRAST ); 71*cdf0e10cSrcweir return pEntry; 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir void StructListBox::SetActiveFlag(sal_Bool bFlag) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir bActiveFlag=bFlag; 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir sal_Bool StructListBox::GetActiveFlag() 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir return bActiveFlag; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir void StructListBox::MouseButtonDown( const MouseEvent& rMEvt ) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir bActiveFlag=sal_True; 87*cdf0e10cSrcweir SvTreeListBox::MouseButtonDown(rMEvt); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir void StructListBox::GetFocus() 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir bActiveFlag=sal_True; 93*cdf0e10cSrcweir SvTreeListBox::GetFocus(); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir void StructListBox::LoseFocus() 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir bActiveFlag=sal_False; 99*cdf0e10cSrcweir SvTreeListBox::LoseFocus(); 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir //============================================================================== 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir StructPage::StructPage(Window* pParent): 105*cdf0e10cSrcweir TabPage(pParent,ModuleRes(RID_FORMULATAB_STRUCT)), 106*cdf0e10cSrcweir // 107*cdf0e10cSrcweir aFtStruct ( this, ModuleRes( FT_STRUCT ) ), 108*cdf0e10cSrcweir aTlbStruct ( this, ModuleRes( TLB_STRUCT ) ), 109*cdf0e10cSrcweir maImgEnd ( ModuleRes( BMP_STR_END ) ), 110*cdf0e10cSrcweir maImgError ( ModuleRes( BMP_STR_ERROR ) ), 111*cdf0e10cSrcweir maImgEndHC ( ModuleRes( BMP_STR_END_H ) ), 112*cdf0e10cSrcweir maImgErrorHC ( ModuleRes( BMP_STR_ERROR_H ) ), 113*cdf0e10cSrcweir pSelectedToken ( NULL ) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir aTlbStruct.SetStyle(aTlbStruct.GetStyle()|WB_HASLINES|WB_CLIPCHILDREN| 116*cdf0e10cSrcweir WB_HASBUTTONS|WB_HSCROLL|WB_NOINITIALSELECTION); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir aTlbStruct.SetNodeDefaultImages(); 119*cdf0e10cSrcweir aTlbStruct.SetDefaultExpandedEntryBmp( Image( ModuleRes( BMP_STR_OPEN ) ) ); 120*cdf0e10cSrcweir aTlbStruct.SetDefaultCollapsedEntryBmp( Image( ModuleRes( BMP_STR_CLOSE ) ) ); 121*cdf0e10cSrcweir aTlbStruct.SetDefaultExpandedEntryBmp( Image( ModuleRes( BMP_STR_OPEN_H ) ), BMP_COLOR_HIGHCONTRAST ); 122*cdf0e10cSrcweir aTlbStruct.SetDefaultCollapsedEntryBmp( Image( ModuleRes( BMP_STR_CLOSE_H ) ), BMP_COLOR_HIGHCONTRAST ); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir FreeResource(); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir aTlbStruct.SetSelectHdl(LINK( this, StructPage, SelectHdl ) ); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir void StructPage::ClearStruct() 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir aTlbStruct.SetActiveFlag(sal_False); 132*cdf0e10cSrcweir aTlbStruct.Clear(); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir SvLBoxEntry* StructPage::InsertEntry( const XubString& rText, SvLBoxEntry* pParent, 136*cdf0e10cSrcweir sal_uInt16 nFlag,sal_uLong nPos,IFormulaToken* pIFormulaToken) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir aTlbStruct.SetActiveFlag( sal_False ); 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir SvLBoxEntry* pEntry = NULL; 141*cdf0e10cSrcweir switch( nFlag ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir case STRUCT_FOLDER: 144*cdf0e10cSrcweir pEntry = aTlbStruct.InsertEntry( rText, pParent, sal_False, nPos, pIFormulaToken ); 145*cdf0e10cSrcweir break; 146*cdf0e10cSrcweir case STRUCT_END: 147*cdf0e10cSrcweir pEntry = aTlbStruct.InsertStaticEntry( rText, maImgEnd, maImgEndHC, pParent, nPos, pIFormulaToken ); 148*cdf0e10cSrcweir break; 149*cdf0e10cSrcweir case STRUCT_ERROR: 150*cdf0e10cSrcweir pEntry = aTlbStruct.InsertStaticEntry( rText, maImgError, maImgErrorHC, pParent, nPos, pIFormulaToken ); 151*cdf0e10cSrcweir break; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir if( pEntry && pParent ) 155*cdf0e10cSrcweir aTlbStruct.Expand( pParent ); 156*cdf0e10cSrcweir return pEntry; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir String StructPage::GetEntryText(SvLBoxEntry* pEntry) const 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir String aString; 162*cdf0e10cSrcweir if(pEntry!=NULL) 163*cdf0e10cSrcweir aString=aTlbStruct.GetEntryText(pEntry); 164*cdf0e10cSrcweir return aString; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir SvLBoxEntry* StructPage::GetParent(SvLBoxEntry* pEntry) const 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir return aTlbStruct.GetParent(pEntry); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir IFormulaToken* StructPage::GetFunctionEntry(SvLBoxEntry* pEntry) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir if(pEntry!=NULL) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir IFormulaToken * pToken=(IFormulaToken *)pEntry->GetUserData(); 176*cdf0e10cSrcweir if(pToken!=NULL) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir if ( !(pToken->isFunction() || pToken->getArgumentCount() > 1 ) ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir return GetFunctionEntry(aTlbStruct.GetParent(pEntry)); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir else 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir return pToken; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir return NULL; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir IMPL_LINK( StructPage, SelectHdl, SvTreeListBox*, pTlb ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir if(aTlbStruct.GetActiveFlag()) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir if(pTlb==&aTlbStruct) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir SvLBoxEntry* pCurEntry=aTlbStruct.GetCurEntry(); 198*cdf0e10cSrcweir if(pCurEntry!=NULL) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir pSelectedToken=(IFormulaToken *)pCurEntry->GetUserData(); 201*cdf0e10cSrcweir if(pSelectedToken!=NULL) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir if ( !(pSelectedToken->isFunction() || pSelectedToken->getArgumentCount() > 1) ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir pSelectedToken = GetFunctionEntry(pCurEntry); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir aSelLink.Call(this); 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir return 0; 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir IFormulaToken* StructPage::GetSelectedToken() 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir return pSelectedToken; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir String StructPage::GetSelectedEntryText() 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir return aTlbStruct.GetEntryText(aTlbStruct.GetCurEntry()); 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir } // formula 227*cdf0e10cSrcweir 228