1*c25918c1SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*c25918c1SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*c25918c1SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*c25918c1SAndrew Rist * distributed with this work for additional information
6*c25918c1SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*c25918c1SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*c25918c1SAndrew Rist * "License"); you may not use this file except in compliance
9*c25918c1SAndrew Rist * with the License. You may obtain a copy of the License at
10*c25918c1SAndrew Rist *
11*c25918c1SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*c25918c1SAndrew Rist *
13*c25918c1SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*c25918c1SAndrew Rist * software distributed under the License is distributed on an
15*c25918c1SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c25918c1SAndrew Rist * KIND, either express or implied. See the License for the
17*c25918c1SAndrew Rist * specific language governing permissions and limitations
18*c25918c1SAndrew Rist * under the License.
19*c25918c1SAndrew Rist *
20*c25918c1SAndrew Rist *************************************************************/
21*c25918c1SAndrew Rist
22*c25918c1SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_formula.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir //----------------------------------------------------------------------------
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <svl/zforlist.hxx>
32cdf0e10cSrcweir #include <svl/stritem.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include "structpg.hxx"
35cdf0e10cSrcweir #include "formdlgs.hrc"
36cdf0e10cSrcweir #include "formula/formdata.hxx"
37cdf0e10cSrcweir #include "formula/formula.hxx"
38cdf0e10cSrcweir #include "ModuleHelper.hxx"
39cdf0e10cSrcweir #include "formula/IFunctionDescription.hxx"
40cdf0e10cSrcweir #include "ForResId.hrc"
41cdf0e10cSrcweir
42cdf0e10cSrcweir //----------------------------------------------------------------------------
43cdf0e10cSrcweir namespace formula
44cdf0e10cSrcweir {
StructListBox(Window * pParent,const ResId & rResId)45cdf0e10cSrcweir StructListBox::StructListBox(Window* pParent, const ResId& rResId ):
46cdf0e10cSrcweir SvTreeListBox(pParent,rResId )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir bActiveFlag=sal_False;
49cdf0e10cSrcweir
50cdf0e10cSrcweir Font aFont( GetFont() );
51cdf0e10cSrcweir Size aSize = aFont.GetSize();
52cdf0e10cSrcweir aSize.Height() -= 2;
53cdf0e10cSrcweir aFont.SetSize( aSize );
54cdf0e10cSrcweir SetFont( aFont );
55cdf0e10cSrcweir }
56cdf0e10cSrcweir
InsertStaticEntry(const XubString & rText,const Image & rEntryImg,const Image & rEntryImgHC,SvLBoxEntry * pParent,sal_uLong nPos,IFormulaToken * pToken)57cdf0e10cSrcweir SvLBoxEntry* StructListBox::InsertStaticEntry(
58cdf0e10cSrcweir const XubString& rText,
59cdf0e10cSrcweir const Image& rEntryImg, const Image& rEntryImgHC,
60cdf0e10cSrcweir SvLBoxEntry* pParent, sal_uLong nPos, IFormulaToken* pToken )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir SvLBoxEntry* pEntry = InsertEntry( rText, rEntryImg, rEntryImg, pParent, sal_False, nPos, pToken );
63cdf0e10cSrcweir SvLBoxContextBmp* pBmpItem = static_cast< SvLBoxContextBmp* >( pEntry->GetFirstItem( SV_ITEM_ID_LBOXCONTEXTBMP ) );
64cdf0e10cSrcweir DBG_ASSERT( pBmpItem, "StructListBox::InsertStaticEntry - missing item" );
65cdf0e10cSrcweir pBmpItem->SetBitmap1( rEntryImgHC, BMP_COLOR_HIGHCONTRAST );
66cdf0e10cSrcweir pBmpItem->SetBitmap2( rEntryImgHC, BMP_COLOR_HIGHCONTRAST );
67cdf0e10cSrcweir return pEntry;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir
SetActiveFlag(sal_Bool bFlag)70cdf0e10cSrcweir void StructListBox::SetActiveFlag(sal_Bool bFlag)
71cdf0e10cSrcweir {
72cdf0e10cSrcweir bActiveFlag=bFlag;
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
GetActiveFlag()75cdf0e10cSrcweir sal_Bool StructListBox::GetActiveFlag()
76cdf0e10cSrcweir {
77cdf0e10cSrcweir return bActiveFlag;
78cdf0e10cSrcweir }
79cdf0e10cSrcweir
MouseButtonDown(const MouseEvent & rMEvt)80cdf0e10cSrcweir void StructListBox::MouseButtonDown( const MouseEvent& rMEvt )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir bActiveFlag=sal_True;
83cdf0e10cSrcweir SvTreeListBox::MouseButtonDown(rMEvt);
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
GetFocus()86cdf0e10cSrcweir void StructListBox::GetFocus()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir bActiveFlag=sal_True;
89cdf0e10cSrcweir SvTreeListBox::GetFocus();
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
LoseFocus()92cdf0e10cSrcweir void StructListBox::LoseFocus()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir bActiveFlag=sal_False;
95cdf0e10cSrcweir SvTreeListBox::LoseFocus();
96cdf0e10cSrcweir }
97cdf0e10cSrcweir
98cdf0e10cSrcweir //==============================================================================
99cdf0e10cSrcweir
StructPage(Window * pParent)100cdf0e10cSrcweir StructPage::StructPage(Window* pParent):
101cdf0e10cSrcweir TabPage(pParent,ModuleRes(RID_FORMULATAB_STRUCT)),
102cdf0e10cSrcweir //
103cdf0e10cSrcweir aFtStruct ( this, ModuleRes( FT_STRUCT ) ),
104cdf0e10cSrcweir aTlbStruct ( this, ModuleRes( TLB_STRUCT ) ),
105cdf0e10cSrcweir maImgEnd ( ModuleRes( BMP_STR_END ) ),
106cdf0e10cSrcweir maImgError ( ModuleRes( BMP_STR_ERROR ) ),
107cdf0e10cSrcweir maImgEndHC ( ModuleRes( BMP_STR_END_H ) ),
108cdf0e10cSrcweir maImgErrorHC ( ModuleRes( BMP_STR_ERROR_H ) ),
109cdf0e10cSrcweir pSelectedToken ( NULL )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir aTlbStruct.SetStyle(aTlbStruct.GetStyle()|WB_HASLINES|WB_CLIPCHILDREN|
112cdf0e10cSrcweir WB_HASBUTTONS|WB_HSCROLL|WB_NOINITIALSELECTION);
113cdf0e10cSrcweir
114cdf0e10cSrcweir aTlbStruct.SetNodeDefaultImages();
115cdf0e10cSrcweir aTlbStruct.SetDefaultExpandedEntryBmp( Image( ModuleRes( BMP_STR_OPEN ) ) );
116cdf0e10cSrcweir aTlbStruct.SetDefaultCollapsedEntryBmp( Image( ModuleRes( BMP_STR_CLOSE ) ) );
117cdf0e10cSrcweir aTlbStruct.SetDefaultExpandedEntryBmp( Image( ModuleRes( BMP_STR_OPEN_H ) ), BMP_COLOR_HIGHCONTRAST );
118cdf0e10cSrcweir aTlbStruct.SetDefaultCollapsedEntryBmp( Image( ModuleRes( BMP_STR_CLOSE_H ) ), BMP_COLOR_HIGHCONTRAST );
119cdf0e10cSrcweir
120cdf0e10cSrcweir FreeResource();
121cdf0e10cSrcweir
122cdf0e10cSrcweir aTlbStruct.SetSelectHdl(LINK( this, StructPage, SelectHdl ) );
123cdf0e10cSrcweir }
124cdf0e10cSrcweir
ClearStruct()125cdf0e10cSrcweir void StructPage::ClearStruct()
126cdf0e10cSrcweir {
127cdf0e10cSrcweir aTlbStruct.SetActiveFlag(sal_False);
128cdf0e10cSrcweir aTlbStruct.Clear();
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
InsertEntry(const XubString & rText,SvLBoxEntry * pParent,sal_uInt16 nFlag,sal_uLong nPos,IFormulaToken * pIFormulaToken)131cdf0e10cSrcweir SvLBoxEntry* StructPage::InsertEntry( const XubString& rText, SvLBoxEntry* pParent,
132cdf0e10cSrcweir sal_uInt16 nFlag,sal_uLong nPos,IFormulaToken* pIFormulaToken)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir aTlbStruct.SetActiveFlag( sal_False );
135cdf0e10cSrcweir
136cdf0e10cSrcweir SvLBoxEntry* pEntry = NULL;
137cdf0e10cSrcweir switch( nFlag )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir case STRUCT_FOLDER:
140cdf0e10cSrcweir pEntry = aTlbStruct.InsertEntry( rText, pParent, sal_False, nPos, pIFormulaToken );
141cdf0e10cSrcweir break;
142cdf0e10cSrcweir case STRUCT_END:
143cdf0e10cSrcweir pEntry = aTlbStruct.InsertStaticEntry( rText, maImgEnd, maImgEndHC, pParent, nPos, pIFormulaToken );
144cdf0e10cSrcweir break;
145cdf0e10cSrcweir case STRUCT_ERROR:
146cdf0e10cSrcweir pEntry = aTlbStruct.InsertStaticEntry( rText, maImgError, maImgErrorHC, pParent, nPos, pIFormulaToken );
147cdf0e10cSrcweir break;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
150cdf0e10cSrcweir if( pEntry && pParent )
151cdf0e10cSrcweir aTlbStruct.Expand( pParent );
152cdf0e10cSrcweir return pEntry;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir
GetEntryText(SvLBoxEntry * pEntry) const155cdf0e10cSrcweir String StructPage::GetEntryText(SvLBoxEntry* pEntry) const
156cdf0e10cSrcweir {
157cdf0e10cSrcweir String aString;
158cdf0e10cSrcweir if(pEntry!=NULL)
159cdf0e10cSrcweir aString=aTlbStruct.GetEntryText(pEntry);
160cdf0e10cSrcweir return aString;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir
GetParent(SvLBoxEntry * pEntry) const163cdf0e10cSrcweir SvLBoxEntry* StructPage::GetParent(SvLBoxEntry* pEntry) const
164cdf0e10cSrcweir {
165cdf0e10cSrcweir return aTlbStruct.GetParent(pEntry);
166cdf0e10cSrcweir }
GetFunctionEntry(SvLBoxEntry * pEntry)167cdf0e10cSrcweir IFormulaToken* StructPage::GetFunctionEntry(SvLBoxEntry* pEntry)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir if(pEntry!=NULL)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir IFormulaToken * pToken=(IFormulaToken *)pEntry->GetUserData();
172cdf0e10cSrcweir if(pToken!=NULL)
173cdf0e10cSrcweir {
174cdf0e10cSrcweir if ( !(pToken->isFunction() || pToken->getArgumentCount() > 1 ) )
175cdf0e10cSrcweir {
176cdf0e10cSrcweir return GetFunctionEntry(aTlbStruct.GetParent(pEntry));
177cdf0e10cSrcweir }
178cdf0e10cSrcweir else
179cdf0e10cSrcweir {
180cdf0e10cSrcweir return pToken;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir }
183cdf0e10cSrcweir }
184cdf0e10cSrcweir return NULL;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir
IMPL_LINK(StructPage,SelectHdl,SvTreeListBox *,pTlb)187cdf0e10cSrcweir IMPL_LINK( StructPage, SelectHdl, SvTreeListBox*, pTlb )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir if(aTlbStruct.GetActiveFlag())
190cdf0e10cSrcweir {
191cdf0e10cSrcweir if(pTlb==&aTlbStruct)
192cdf0e10cSrcweir {
193cdf0e10cSrcweir SvLBoxEntry* pCurEntry=aTlbStruct.GetCurEntry();
194cdf0e10cSrcweir if(pCurEntry!=NULL)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir pSelectedToken=(IFormulaToken *)pCurEntry->GetUserData();
197cdf0e10cSrcweir if(pSelectedToken!=NULL)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir if ( !(pSelectedToken->isFunction() || pSelectedToken->getArgumentCount() > 1) )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir pSelectedToken = GetFunctionEntry(pCurEntry);
202cdf0e10cSrcweir }
203cdf0e10cSrcweir }
204cdf0e10cSrcweir }
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
207cdf0e10cSrcweir aSelLink.Call(this);
208cdf0e10cSrcweir }
209cdf0e10cSrcweir return 0;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
GetSelectedToken()212cdf0e10cSrcweir IFormulaToken* StructPage::GetSelectedToken()
213cdf0e10cSrcweir {
214cdf0e10cSrcweir return pSelectedToken;
215cdf0e10cSrcweir }
216cdf0e10cSrcweir
GetSelectedEntryText()217cdf0e10cSrcweir String StructPage::GetSelectedEntryText()
218cdf0e10cSrcweir {
219cdf0e10cSrcweir return aTlbStruct.GetEntryText(aTlbStruct.GetCurEntry());
220cdf0e10cSrcweir }
221cdf0e10cSrcweir
222cdf0e10cSrcweir } // formula
223cdf0e10cSrcweir
224