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