Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / formula / source / ui / dlg / structpg.cxx
blob6f1ffe37e03bd80b86bf34d4f7280b300e2e273f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svl/zforlist.hxx>
21 #include <svl/stritem.hxx>
22 #include "svtools/treelistentry.hxx"
24 #include "structpg.hxx"
25 #include "formdlgs.hrc"
26 #include "formula/formdata.hxx"
27 #include "formula/formula.hxx"
28 #include "ModuleHelper.hxx"
29 #include "formula/IFunctionDescription.hxx"
30 #include "ForResId.hrc"
32 //----------------------------------------------------------------------------
33 namespace formula
35 StructListBox::StructListBox(Window* pParent, const ResId& rResId ):
36 SvTreeListBox(pParent,rResId )
38 bActiveFlag=sal_False;
40 Font aFont( GetFont() );
41 Size aSize = aFont.GetSize();
42 aSize.Height() -= 2;
43 aFont.SetSize( aSize );
44 SetFont( aFont );
47 SvTreeListEntry* StructListBox::InsertStaticEntry(
48 const XubString& rText,
49 const Image& rEntryImg,
50 SvTreeListEntry* pParent, sal_uLong nPos, IFormulaToken* pToken )
52 SvTreeListEntry* pEntry = InsertEntry( rText, rEntryImg, rEntryImg, pParent, sal_False, nPos, pToken );
53 return pEntry;
56 void StructListBox::SetActiveFlag(sal_Bool bFlag)
58 bActiveFlag=bFlag;
61 sal_Bool StructListBox::GetActiveFlag()
63 return bActiveFlag;
66 void StructListBox::MouseButtonDown( const MouseEvent& rMEvt )
68 bActiveFlag=sal_True;
69 SvTreeListBox::MouseButtonDown(rMEvt);
72 void StructListBox::GetFocus()
74 bActiveFlag=sal_True;
75 SvTreeListBox::GetFocus();
78 void StructListBox::LoseFocus()
80 bActiveFlag=sal_False;
81 SvTreeListBox::LoseFocus();
84 //==============================================================================
86 StructPage::StructPage(Window* pParent):
87 TabPage(pParent,ModuleRes(RID_FORMULATAB_STRUCT)),
88 aFtStruct ( this, ModuleRes( FT_STRUCT ) ),
89 aTlbStruct ( this, ModuleRes( TLB_STRUCT ) ),
90 maImgEnd ( ModuleRes( BMP_STR_END ) ),
91 maImgError ( ModuleRes( BMP_STR_ERROR ) ),
92 pSelectedToken ( NULL )
94 aTlbStruct.SetStyle(aTlbStruct.GetStyle()|WB_HASLINES|WB_CLIPCHILDREN|
95 WB_HASBUTTONS|WB_HSCROLL|WB_NOINITIALSELECTION);
97 aTlbStruct.SetNodeDefaultImages();
98 aTlbStruct.SetDefaultExpandedEntryBmp( Image( ModuleRes( BMP_STR_OPEN ) ) );
99 aTlbStruct.SetDefaultCollapsedEntryBmp( Image( ModuleRes( BMP_STR_CLOSE ) ) );
101 FreeResource();
103 aTlbStruct.SetSelectHdl(LINK( this, StructPage, SelectHdl ) );
106 void StructPage::ClearStruct()
108 aTlbStruct.SetActiveFlag(sal_False);
109 aTlbStruct.Clear();
112 SvTreeListEntry* StructPage::InsertEntry( const XubString& rText, SvTreeListEntry* pParent,
113 sal_uInt16 nFlag,sal_uLong nPos,IFormulaToken* pIFormulaToken)
115 aTlbStruct.SetActiveFlag( sal_False );
117 SvTreeListEntry* pEntry = NULL;
118 switch( nFlag )
120 case STRUCT_FOLDER:
121 pEntry = aTlbStruct.InsertEntry( rText, pParent, sal_False, nPos, pIFormulaToken );
122 break;
123 case STRUCT_END:
124 pEntry = aTlbStruct.InsertStaticEntry( rText, maImgEnd, pParent, nPos, pIFormulaToken );
125 break;
126 case STRUCT_ERROR:
127 pEntry = aTlbStruct.InsertStaticEntry( rText, maImgError, pParent, nPos, pIFormulaToken );
128 break;
131 if( pEntry && pParent )
132 aTlbStruct.Expand( pParent );
133 return pEntry;
136 String StructPage::GetEntryText(SvTreeListEntry* pEntry) const
138 String aString;
139 if(pEntry!=NULL)
140 aString=aTlbStruct.GetEntryText(pEntry);
141 return aString;
144 SvTreeListEntry* StructPage::GetParent(SvTreeListEntry* pEntry) const
146 return aTlbStruct.GetParent(pEntry);
148 IFormulaToken* StructPage::GetFunctionEntry(SvTreeListEntry* pEntry)
150 if(pEntry!=NULL)
152 IFormulaToken * pToken=(IFormulaToken *)pEntry->GetUserData();
153 if(pToken!=NULL)
155 if ( !(pToken->isFunction() || pToken->getArgumentCount() > 1 ) )
157 return GetFunctionEntry(aTlbStruct.GetParent(pEntry));
159 else
161 return pToken;
165 return NULL;
168 IMPL_LINK( StructPage, SelectHdl, SvTreeListBox*, pTlb )
170 if(aTlbStruct.GetActiveFlag())
172 if(pTlb==&aTlbStruct)
174 SvTreeListEntry* pCurEntry=aTlbStruct.GetCurEntry();
175 if(pCurEntry!=NULL)
177 pSelectedToken=(IFormulaToken *)pCurEntry->GetUserData();
178 if(pSelectedToken!=NULL)
180 if ( !(pSelectedToken->isFunction() || pSelectedToken->getArgumentCount() > 1) )
182 pSelectedToken = GetFunctionEntry(pCurEntry);
188 aSelLink.Call(this);
190 return 0;
193 } // formula
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */