xref: /aoo41x/main/cui/source/inc/scriptdlg.hxx (revision c4eee24d)
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 #ifndef _SCRIPTDLG_HXX
25 #define _SCRIPTDLG_HXX
26 
27 #include <memory>
28 
29 #include "tools/solar.h"
30 
31 #include <svtools/svtreebx.hxx>
32 #include <vcl/dialog.hxx>
33 #include <vcl/button.hxx>
34 #include <vcl/fixed.hxx>
35 #include <vcl/abstdlg.hxx>
36 #include <sfx2/basedlgs.hxx>
37 
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/script/browse/XBrowseNode.hpp>
40 #include <com/sun/star/frame/XModel.hpp>
41 
42 #include <hash_map>
43 
44 #define OBJTYPE_BASICMANAGER	1L
45 //#define OBJTYPE_LIB				2L
46 //#define OBJTYPE_MODULE			3L
47 #define OBJTYPE_METHOD			2L
48 //#define OBJTYPE_METHODINOBJ		5L
49 //#define OBJTYPE_OBJECT			6L
50 //#define OBJTYPE_SUBOBJ			7L
51 //#define OBJTYPE_PROPERTY		8L
52 #define OBJTYPE_SCRIPTCONTAINER		3L
53 #define OBJTYPE_SFROOT		4L
54 
55 #define BROWSEMODE_MODULES		0x01
56 #define BROWSEMODE_SUBS			0x02
57 #define BROWSEMODE_OBJS			0x04
58 #define BROWSEMODE_PROPS		0x08
59 #define BROWSEMODE_SUBOBJS		0x10
60 
61 #define INPUTMODE_NEWLIB		1
62 #define INPUTMODE_NEWMACRO		2
63 #define INPUTMODE_RENAME		3
64 
65 typedef ::std::hash_map < ::rtl::OUString, ::rtl::OUString ,
66     ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > Selection_hash;
67 
68 class SFEntry;
69 
70 class SFTreeListBox : public SvTreeListBox
71 {
72    friend class SvxScriptOrgDialog;
73 private:
74 	sal_uInt16			nMode;
75     Image m_hdImage;
76     Image m_hdImage_hc;
77     Image m_libImage;
78     Image m_libImage_hc;
79     Image m_macImage;
80     Image m_macImage_hc;
81     Image m_docImage;
82     Image m_docImage_hc;
83     ::rtl::OUString m_sMyMacros;
84     ::rtl::OUString m_sProdMacros;
85 
86     ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode >
87         getLangNodeFromRootNode( ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode >& root, ::rtl::OUString& language );
88     void delUserData( SvLBoxEntry* pEntry );
89 
90     ::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 );
91 
92 protected:
93 	void 					ExpandTree( SvLBoxEntry* pRootEntry );
94 	virtual void			RequestingChilds( SvLBoxEntry* pParent );
95 	virtual void 			ExpandedHdl();
96 	virtual long			ExpandingHdl();
97 public:
98 	void 					Init( const ::rtl::OUString& language );
99 	void  RequestSubEntries(  SvLBoxEntry* pRootEntry, ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode >& node,
100 							  ::com::sun::star::uno::Reference< com::sun::star::frame::XModel>& model  );
101 					SFTreeListBox( Window* pParent, const ResId& rRes );
102 					~SFTreeListBox();
103 
104 	void			ExpandAllTrees();
105 
106 
107 
108 	SvLBoxEntry * insertEntry(String const & rText, sal_uInt16 nBitmap,
109                               SvLBoxEntry * pParent,
110                               bool bChildrenOnDemand,
111                               std::auto_ptr< SFEntry > aUserData,
112                               ::rtl::OUString factoryURL );
113 	SvLBoxEntry * insertEntry(String const & rText, sal_uInt16 nBitmap,
114                               SvLBoxEntry * pParent,
115                               bool bChildrenOnDemand,
116                               std::auto_ptr< SFEntry > aUserData );
117 	void deleteTree( SvLBoxEntry * pEntry );
118 	void deleteAllTree( );
119 };
120 
121 class InputDialog : public ModalDialog
122 {
123 private:
124 	FixedText		aText;
125 	Edit			aEdit;
126 	OKButton		aOKButton;
127 	CancelButton	aCancelButton;
128 
129 public:
130     InputDialog( Window * pParent, sal_uInt16 nMode );
131 				~InputDialog();
132 
GetObjectName() const133 	String		GetObjectName() const { return aEdit.GetText(); }
SetObjectName(const String & rName)134 	void		SetObjectName( const String& rName ) { aEdit.SetText( rName ); aEdit.SetSelection( Selection( 0, rName.Len() ) );}
135 };
136 
137 class SFEntry
138 {
139 private:
140 	sal_uInt8			nType;
141     bool            loaded;
142         ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode > nodes;
143         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > model;
SFEntry()144 	SFEntry(){}
145 public:
SFEntry(sal_uInt8 nT)146 					SFEntry( sal_uInt8 nT )				{ nType = nT; loaded=false; }
SFEntry(sal_uInt8 nT,const::com::sun::star::uno::Reference<::com::sun::star::script::browse::XBrowseNode> & entryNodes,const::com::sun::star::uno::Reference<::com::sun::star::frame::XModel> & entryModel)147 					SFEntry( sal_uInt8 nT,
148 							const ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode >& entryNodes ,
149 							const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& entryModel) { nType = nT; nodes = entryNodes; loaded=false; model = entryModel; }
SFEntry(const SFEntry & r)150 					SFEntry( const SFEntry& r ) { nType = r.nType; nodes = r.nodes; loaded = r.loaded; }
~SFEntry()151 	virtual 		~SFEntry() {}
GetNode()152 	::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode > GetNode() { return nodes ;}
GetModel()153 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > GetModel() { return model ;};
GetType() const154 	sal_uInt8			GetType() const 					{ return nType; }
isLoaded() const155 	bool			isLoaded() const 					{ return loaded; }
setLoaded()156 	void			setLoaded()                         { loaded=true; }
157 };
158 
159 class SvxScriptOrgDialog : public SfxModalDialog
160 {
161 protected:
162 	FixedText 				aScriptsTxt;
163 	SFTreeListBox		    aScriptsBox;
164 
165 	PushButton				aRunButton;
166 	CancelButton 			aCloseButton;
167 	PushButton 				aCreateButton;
168 	PushButton				aEditButton;
169 	PushButton				aRenameButton;
170 	PushButton				aDelButton;
171 	HelpButton				aHelpButton;
172 
173     ::rtl::OUString         m_sLanguage;
174     static Selection_hash   m_lastSelection;
175     const String m_delErrStr;
176     const String m_delErrTitleStr;
177     const String m_delQueryStr;
178     const String m_delQueryTitleStr;
179     const String m_createErrStr;
180     const String m_createDupStr;
181     const String m_createErrTitleStr;
182     const String m_renameErrStr;
183     const String m_renameDupStr;
184     const String m_renameErrTitleStr;
185 
186 	DECL_LINK( MacroSelectHdl, SvTreeListBox * );
187 	DECL_LINK( MacroDoubleClickHdl, SvTreeListBox * );
188 	DECL_LINK( ScriptSelectHdl, SvTreeListBox * );
189 	DECL_LINK( ButtonHdl, Button * );
190 	sal_Bool 	            getBoolProperty( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xProps, ::rtl::OUString& propName );
191 	void				CheckButtons(  ::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode >& node );
192 
193 	void        createEntry( SvLBoxEntry* pEntry );
194 	void        renameEntry( SvLBoxEntry* pEntry );
195 	void        deleteEntry( SvLBoxEntry* pEntry );
196 	::com::sun::star::uno::Reference< ::com::sun::star::script::browse::XBrowseNode >
197 		        getBrowseNode( SvLBoxEntry* pEntry );
198 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > getModel( SvLBoxEntry* pEntry );
199     String      getListOfChildren( ::com::sun::star::uno::Reference< com::sun::star::script::browse::XBrowseNode > node, int depth );
200     void        StoreCurrentSelection();
201     void        RestorePreviousSelection();
202 	//String				GetInfo( SbxVariable* pVar );
203 
204 public:
205                     // prob need another arg in the ctor
206                     // to specify the language or provider
207 					SvxScriptOrgDialog( Window* pParent, ::rtl::OUString language );
208 					~SvxScriptOrgDialog();
209 
210 	virtual short	Execute();
211 
212 	//DECL_LINK( ActivatePageHdl, TabControl * );
213 };
214 
215 class SvxScriptErrorDialog : public VclAbstractDialog
216 {
217 private:
218 
219 	::rtl::OUString m_sMessage;
220 
221 	DECL_LINK( ShowDialog, ::rtl::OUString* );
222 
223 public:
224 
225 	SvxScriptErrorDialog(
226 		Window* parent, ::com::sun::star::uno::Any aException );
227 
228 	~SvxScriptErrorDialog();
229 
230 	short			Execute();
231 };
232 
233 #endif // _SCRIPTDLG_HXX
234