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