xref: /aoo41x/main/cui/source/inc/scriptdlg.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SCRIPTDLG_HXX
29 #define _SCRIPTDLG_HXX
30 
31 #include <memory>
32 
33 #include "tools/solar.h"
34 
35 #include <svtools/svtreebx.hxx>
36 #include <vcl/dialog.hxx>
37 #include <vcl/button.hxx>
38 #include <vcl/fixed.hxx>
39 #include <vcl/abstdlg.hxx>
40 #include <sfx2/basedlgs.hxx>
41 
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/script/browse/XBrowseNode.hpp>
44 #include <com/sun/star/frame/XModel.hpp>
45 
46 #include <hash_map>
47 
48 #define OBJTYPE_BASICMANAGER	1L
49 //#define OBJTYPE_LIB				2L
50 //#define OBJTYPE_MODULE			3L
51 #define OBJTYPE_METHOD			2L
52 //#define OBJTYPE_METHODINOBJ		5L
53 //#define OBJTYPE_OBJECT			6L
54 //#define OBJTYPE_SUBOBJ			7L
55 //#define OBJTYPE_PROPERTY		8L
56 #define OBJTYPE_SCRIPTCONTAINER		3L
57 #define OBJTYPE_SFROOT		4L
58 
59 #define BROWSEMODE_MODULES		0x01
60 #define BROWSEMODE_SUBS			0x02
61 #define BROWSEMODE_OBJS			0x04
62 #define BROWSEMODE_PROPS		0x08
63 #define BROWSEMODE_SUBOBJS		0x10
64 
65 #define INPUTMODE_NEWLIB		1
66 #define INPUTMODE_NEWMACRO		2
67 #define INPUTMODE_RENAME		3
68 
69 typedef ::std::hash_map < ::rtl::OUString, ::rtl::OUString ,
70     ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > Selection_hash;
71 
72 class SFEntry;
73 
74 class SFTreeListBox : public SvTreeListBox
75 {
76    friend class SvxScriptOrgDialog;
77 private:
78 	sal_uInt16			nMode;
79     Image m_hdImage;
80     Image m_hdImage_hc;
81     Image m_libImage;
82     Image m_libImage_hc;
83     Image m_macImage;
84     Image m_macImage_hc;
85     Image m_docImage;
86     Image m_docImage_hc;
87     ::rtl::OUString m_sMyMacros;
88     ::rtl::OUString m_sProdMacros;
89 
90     ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode >
91         getLangNodeFromRootNode( ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode >& root, ::rtl::OUString& language );
92     void delUserData( SvLBoxEntry* pEntry );
93 
94     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface  > getDocumentModel( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xCtx, ::rtl::OUString& docName );
95 
96 protected:
97 	void 					ExpandTree( SvLBoxEntry* pRootEntry );
98 	virtual void			RequestingChilds( SvLBoxEntry* pParent );
99 	virtual void 			ExpandedHdl();
100 	virtual long			ExpandingHdl();
101 public:
102 	void 					Init( const ::rtl::OUString& language );
103 	void  RequestSubEntries(  SvLBoxEntry* pRootEntry, ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode >& node,
104 							  ::com::sun::star::uno::Reference< com::sun::star::frame::XModel>& model  );
105 					SFTreeListBox( Window* pParent, const ResId& rRes );
106 					~SFTreeListBox();
107 
108 	void			ExpandAllTrees();
109 
110 
111 
112 	SvLBoxEntry * insertEntry(String const & rText, sal_uInt16 nBitmap,
113                               SvLBoxEntry * pParent,
114                               bool bChildrenOnDemand,
115                               std::auto_ptr< SFEntry > aUserData,
116                               ::rtl::OUString factoryURL );
117 	SvLBoxEntry * insertEntry(String const & rText, sal_uInt16 nBitmap,
118                               SvLBoxEntry * pParent,
119                               bool bChildrenOnDemand,
120                               std::auto_ptr< SFEntry > aUserData );
121 	void deleteTree( SvLBoxEntry * pEntry );
122 	void deleteAllTree( );
123 };
124 
125 class InputDialog : public ModalDialog
126 {
127 private:
128 	FixedText		aText;
129 	Edit			aEdit;
130 	OKButton		aOKButton;
131 	CancelButton	aCancelButton;
132 
133 public:
134     InputDialog( Window * pParent, sal_uInt16 nMode );
135 				~InputDialog();
136 
137 	String		GetObjectName() const { return aEdit.GetText(); }
138 	void		SetObjectName( const String& rName ) { aEdit.SetText( rName ); aEdit.SetSelection( Selection( 0, rName.Len() ) );}
139 };
140 
141 class SFEntry
142 {
143 private:
144 	sal_uInt8			nType;
145     bool            loaded;
146         ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode > nodes;
147         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > model;
148 	SFEntry(){}
149 public:
150 					SFEntry( sal_uInt8 nT )				{ nType = nT; loaded=false; }
151 					SFEntry( sal_uInt8 nT,
152 							const ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode >& entryNodes ,
153 							const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& entryModel) { nType = nT; nodes = entryNodes; loaded=false; model = entryModel; }
154 					SFEntry( const SFEntry& r ) { nType = r.nType; nodes = r.nodes; loaded = r.loaded; }
155 	virtual 		~SFEntry() {}
156 	::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode > GetNode() { return nodes ;}
157 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > GetModel() { return model ;};
158 	sal_uInt8			GetType() const 					{ return nType; }
159 	bool			isLoaded() const 					{ return loaded; }
160 	void			setLoaded()                         { loaded=true; }
161 };
162 
163 class SvxScriptOrgDialog : public SfxModalDialog
164 {
165 protected:
166 	FixedText 				aScriptsTxt;
167 	SFTreeListBox		    aScriptsBox;
168 
169 	PushButton				aRunButton;
170 	CancelButton 			aCloseButton;
171 	PushButton 				aCreateButton;
172 	PushButton				aEditButton;
173 	PushButton				aRenameButton;
174 	PushButton				aDelButton;
175 	HelpButton				aHelpButton;
176 
177     ::rtl::OUString         m_sLanguage;
178     static Selection_hash   m_lastSelection;
179     const String m_delErrStr;
180     const String m_delErrTitleStr;
181     const String m_delQueryStr;
182     const String m_delQueryTitleStr;
183     const String m_createErrStr;
184     const String m_createDupStr;
185     const String m_createErrTitleStr;
186     const String m_renameErrStr;
187     const String m_renameDupStr;
188     const String m_renameErrTitleStr;
189 
190 	DECL_LINK( MacroSelectHdl, SvTreeListBox * );
191 	DECL_LINK( MacroDoubleClickHdl, SvTreeListBox * );
192 	DECL_LINK( ScriptSelectHdl, SvTreeListBox * );
193 	DECL_LINK( ButtonHdl, Button * );
194 	sal_Bool 	            getBoolProperty( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xProps, ::rtl::OUString& propName );
195 	void				CheckButtons(  ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode >& node );
196 
197 	void        createEntry( SvLBoxEntry* pEntry );
198 	void        renameEntry( SvLBoxEntry* pEntry );
199 	void        deleteEntry( SvLBoxEntry* pEntry );
200 	::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode >
201 		        getBrowseNode( SvLBoxEntry* pEntry );
202 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > getModel( SvLBoxEntry* pEntry );
203     String      getListOfChildren( ::com::sun::star::uno::Reference< com::sun::star::script::browse::XBrowseNode > node, int depth );
204     void        StoreCurrentSelection();
205     void        RestorePreviousSelection();
206 	//String				GetInfo( SbxVariable* pVar );
207 
208 public:
209                     // prob need another arg in the ctor
210                     // to specify the language or provider
211 					SvxScriptOrgDialog( Window* pParent, ::rtl::OUString language );
212 					~SvxScriptOrgDialog();
213 
214 	virtual short	Execute();
215 
216 	//DECL_LINK( ActivatePageHdl, TabControl * );
217 };
218 
219 class SvxScriptErrorDialog : public VclAbstractDialog
220 {
221 private:
222 
223 	::rtl::OUString m_sMessage;
224 
225 	DECL_LINK( ShowDialog, ::rtl::OUString* );
226 
227 public:
228 
229 	SvxScriptErrorDialog(
230 		Window* parent, ::com::sun::star::uno::Any aException );
231 
232 	~SvxScriptErrorDialog();
233 
234 	short			Execute();
235 };
236 
237 #endif // _SCRIPTDLG_HXX
238