1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: structpg.cxx,v $
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 //----------------------------------------------------------------------------
52 StructListBox::StructListBox(Window
* pParent
, const ResId
& rResId
):
53 SvTreeListBox(pParent
,rResId
)
57 Font
aFont( GetFont() );
58 Size aSize
= aFont
.GetSize();
60 aFont
.SetSize( aSize
);
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
);
77 void StructListBox::SetActiveFlag(BOOL bFlag
)
82 BOOL
StructListBox::GetActiveFlag()
87 void StructListBox::MouseButtonDown( const MouseEvent
& rMEvt
)
90 SvTreeListBox::MouseButtonDown(rMEvt
);
93 void StructListBox::GetFocus()
96 SvTreeListBox::GetFocus();
99 void StructListBox::LoseFocus()
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
);
129 aTlbStruct
.SetSelectHdl(LINK( this, StructPage
, SelectHdl
) );
132 void StructPage::ClearStruct()
134 aTlbStruct
.SetActiveFlag(FALSE
);
138 SvLBoxEntry
* StructPage::InsertEntry( const XubString
& rText
, SvLBoxEntry
* pParent
,
139 USHORT nFlag
,ULONG nPos
,IFormulaToken
* pIFormulaToken
)
141 aTlbStruct
.SetActiveFlag( FALSE
);
143 SvLBoxEntry
* pEntry
= NULL
;
147 pEntry
= aTlbStruct
.InsertEntry( rText
, pParent
, FALSE
, nPos
, pIFormulaToken
);
150 pEntry
= aTlbStruct
.InsertStaticEntry( rText
, maImgEnd
, maImgEndHC
, pParent
, nPos
, pIFormulaToken
);
153 pEntry
= aTlbStruct
.InsertStaticEntry( rText
, maImgError
, maImgErrorHC
, pParent
, nPos
, pIFormulaToken
);
157 if( pEntry
&& pParent
)
158 aTlbStruct
.Expand( pParent
);
162 String
StructPage::GetEntryText(SvLBoxEntry
* pEntry
) const
166 aString
=aTlbStruct
.GetEntryText(pEntry
);
170 SvLBoxEntry
* StructPage::GetParent(SvLBoxEntry
* pEntry
) const
172 return aTlbStruct
.GetParent(pEntry
);
174 IFormulaToken
* StructPage::GetFunctionEntry(SvLBoxEntry
* pEntry
)
178 IFormulaToken
* pToken
=(IFormulaToken
*)pEntry
->GetUserData();
181 if ( !(pToken
->isFunction() || pToken
->getArgumentCount() > 1 ) )
183 return GetFunctionEntry(aTlbStruct
.GetParent(pEntry
));
194 IMPL_LINK( StructPage
, SelectHdl
, SvTreeListBox
*, pTlb
)
196 if(aTlbStruct
.GetActiveFlag())
198 if(pTlb
==&aTlbStruct
)
200 SvLBoxEntry
* pCurEntry
=aTlbStruct
.GetCurEntry();
203 pSelectedToken
=(IFormulaToken
*)pCurEntry
->GetUserData();
204 if(pSelectedToken
!=NULL
)
206 if ( !(pSelectedToken
->isFunction() || pSelectedToken
->getArgumentCount() > 1) )
208 pSelectedToken
= GetFunctionEntry(pCurEntry
);
219 IFormulaToken
* StructPage::GetSelectedToken()
221 return pSelectedToken
;
224 String
StructPage::GetSelectedEntryText()
226 return aTlbStruct
.GetEntryText(aTlbStruct
.GetCurEntry());