update dev300-m58
[ooovba.git] / formula / source / ui / dlg / structpg.cxx
blob1afb1c0fb458f3448bc3d017e4e5e98cfb201bbd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: structpg.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_formula.hxx"
36 //----------------------------------------------------------------------------
38 #include <svtools/zforlist.hxx>
39 #include <svtools/stritem.hxx>
41 #include "structpg.hxx"
42 #include "formdlgs.hrc"
43 #include "formula/formdata.hxx"
44 #include "formula/formula.hxx"
45 #include "ModuleHelper.hxx"
46 #include "formula/IFunctionDescription.hxx"
47 #include "ForResId.hrc"
49 //----------------------------------------------------------------------------
50 namespace formula
52 StructListBox::StructListBox(Window* pParent, const ResId& rResId ):
53 SvTreeListBox(pParent,rResId )
55 bActiveFlag=FALSE;
57 Font aFont( GetFont() );
58 Size aSize = aFont.GetSize();
59 aSize.Height() -= 2;
60 aFont.SetSize( aSize );
61 SetFont( aFont );
64 SvLBoxEntry* StructListBox::InsertStaticEntry(
65 const XubString& rText,
66 const Image& rEntryImg, const Image& rEntryImgHC,
67 SvLBoxEntry* pParent, ULONG nPos, IFormulaToken* pToken )
69 SvLBoxEntry* pEntry = InsertEntry( rText, rEntryImg, rEntryImg, pParent, FALSE, nPos, pToken );
70 SvLBoxContextBmp* pBmpItem = static_cast< SvLBoxContextBmp* >( pEntry->GetFirstItem( SV_ITEM_ID_LBOXCONTEXTBMP ) );
71 DBG_ASSERT( pBmpItem, "StructListBox::InsertStaticEntry - missing item" );
72 pBmpItem->SetBitmap1( rEntryImgHC, BMP_COLOR_HIGHCONTRAST );
73 pBmpItem->SetBitmap2( rEntryImgHC, BMP_COLOR_HIGHCONTRAST );
74 return pEntry;
77 void StructListBox::SetActiveFlag(BOOL bFlag)
79 bActiveFlag=bFlag;
82 BOOL StructListBox::GetActiveFlag()
84 return bActiveFlag;
87 void StructListBox::MouseButtonDown( const MouseEvent& rMEvt )
89 bActiveFlag=TRUE;
90 SvTreeListBox::MouseButtonDown(rMEvt);
93 void StructListBox::GetFocus()
95 bActiveFlag=TRUE;
96 SvTreeListBox::GetFocus();
99 void StructListBox::LoseFocus()
101 bActiveFlag=FALSE;
102 SvTreeListBox::LoseFocus();
105 //==============================================================================
107 StructPage::StructPage(Window* pParent):
108 TabPage(pParent,ModuleRes(RID_FORMULATAB_STRUCT)),
110 aFtStruct ( this, ModuleRes( FT_STRUCT ) ),
111 aTlbStruct ( this, ModuleRes( TLB_STRUCT ) ),
112 maImgEnd ( ModuleRes( BMP_STR_END ) ),
113 maImgError ( ModuleRes( BMP_STR_ERROR ) ),
114 maImgEndHC ( ModuleRes( BMP_STR_END_H ) ),
115 maImgErrorHC ( ModuleRes( BMP_STR_ERROR_H ) ),
116 pSelectedToken ( NULL )
118 aTlbStruct.SetWindowBits(WB_HASLINES|WB_CLIPCHILDREN|
119 WB_HASBUTTONS|WB_HSCROLL|WB_NOINITIALSELECTION);
121 aTlbStruct.SetNodeDefaultImages();
122 aTlbStruct.SetDefaultExpandedEntryBmp( Image( ModuleRes( BMP_STR_OPEN ) ) );
123 aTlbStruct.SetDefaultCollapsedEntryBmp( Image( ModuleRes( BMP_STR_CLOSE ) ) );
124 aTlbStruct.SetDefaultExpandedEntryBmp( Image( ModuleRes( BMP_STR_OPEN_H ) ), BMP_COLOR_HIGHCONTRAST );
125 aTlbStruct.SetDefaultCollapsedEntryBmp( Image( ModuleRes( BMP_STR_CLOSE_H ) ), BMP_COLOR_HIGHCONTRAST );
127 FreeResource();
129 aTlbStruct.SetSelectHdl(LINK( this, StructPage, SelectHdl ) );
132 void StructPage::ClearStruct()
134 aTlbStruct.SetActiveFlag(FALSE);
135 aTlbStruct.Clear();
138 SvLBoxEntry* StructPage::InsertEntry( const XubString& rText, SvLBoxEntry* pParent,
139 USHORT nFlag,ULONG nPos,IFormulaToken* pIFormulaToken)
141 aTlbStruct.SetActiveFlag( FALSE );
143 SvLBoxEntry* pEntry = NULL;
144 switch( nFlag )
146 case STRUCT_FOLDER:
147 pEntry = aTlbStruct.InsertEntry( rText, pParent, FALSE, nPos, pIFormulaToken );
148 break;
149 case STRUCT_END:
150 pEntry = aTlbStruct.InsertStaticEntry( rText, maImgEnd, maImgEndHC, pParent, nPos, pIFormulaToken );
151 break;
152 case STRUCT_ERROR:
153 pEntry = aTlbStruct.InsertStaticEntry( rText, maImgError, maImgErrorHC, pParent, nPos, pIFormulaToken );
154 break;
157 if( pEntry && pParent )
158 aTlbStruct.Expand( pParent );
159 return pEntry;
162 String StructPage::GetEntryText(SvLBoxEntry* pEntry) const
164 String aString;
165 if(pEntry!=NULL)
166 aString=aTlbStruct.GetEntryText(pEntry);
167 return aString;
170 SvLBoxEntry* StructPage::GetParent(SvLBoxEntry* pEntry) const
172 return aTlbStruct.GetParent(pEntry);
174 IFormulaToken* StructPage::GetFunctionEntry(SvLBoxEntry* pEntry)
176 if(pEntry!=NULL)
178 IFormulaToken * pToken=(IFormulaToken *)pEntry->GetUserData();
179 if(pToken!=NULL)
181 if ( !(pToken->isFunction() || pToken->getArgumentCount() > 1 ) )
183 return GetFunctionEntry(aTlbStruct.GetParent(pEntry));
185 else
187 return pToken;
191 return NULL;
194 IMPL_LINK( StructPage, SelectHdl, SvTreeListBox*, pTlb )
196 if(aTlbStruct.GetActiveFlag())
198 if(pTlb==&aTlbStruct)
200 SvLBoxEntry* pCurEntry=aTlbStruct.GetCurEntry();
201 if(pCurEntry!=NULL)
203 pSelectedToken=(IFormulaToken *)pCurEntry->GetUserData();
204 if(pSelectedToken!=NULL)
206 if ( !(pSelectedToken->isFunction() || pSelectedToken->getArgumentCount() > 1) )
208 pSelectedToken = GetFunctionEntry(pCurEntry);
214 aSelLink.Call(this);
216 return 0;
219 IFormulaToken* StructPage::GetSelectedToken()
221 return pSelectedToken;
224 String StructPage::GetSelectedEntryText()
226 return aTlbStruct.GetEntryText(aTlbStruct.GetCurEntry());
229 } // formula