update dev300-m58
[ooovba.git] / automation / source / miniapp / testapp.cxx
blob6ab135dc1acb39d8c81d71ba8bf4280cb2b67217
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testapp.cxx,v $
10 * $Revision: 1.9.24.1 $
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_automation.hxx"
33 #include <svtools/filedlg.hxx>
34 #include <stdio.h>
35 #ifndef _MSGBOX_HXX //autogen
36 #include <vcl/msgbox.hxx>
37 #endif
38 #include <tools/debug.hxx>
39 #include <svtools/testtool.hxx>
40 #include <svtools/ttprops.hxx>
41 #include <rtl/ustring.hxx>
42 #include <rtl/ustrbuf.hxx>
43 #include <osl/process.h>
44 #include <ucbhelper/contentbroker.hxx>
45 #include <ucbhelper/configurationkeys.hxx>
46 #include <comphelper/regpathhelper.hxx>
47 #include <comphelper/processfactory.hxx>
48 #include <cppuhelper/servicefactory.hxx>
49 #include <com/sun/star/registry/XImplementationRegistration.hpp>
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 #include <com/sun/star/ucb/XContentProviderManager.hpp>
53 #include "servres.hrc"
54 #include "servres.hxx"
55 #include "testapp.hxx"
57 using namespace comphelper;
58 using namespace cppu;
59 using namespace rtl;
60 using namespace com::sun::star::uno;
61 using namespace com::sun::star::lang;
62 using namespace com::sun::star::registry;
63 using namespace com::sun::star::ucb;
65 static ResMgr* pAppMgr = NULL;
67 MainWindow::MainWindow(MyApp *pAppl)
68 : WorkWindow(NULL, WB_STDWORK)
69 , pApp(pAppl)
72 IMPL_LINK(MainWindow,MenuSelectHdl,MenuBar*,aMenu)
75 return pApp->GetDispatcher()->ExecuteFunction(aMenu->GetCurItemId());
79 void MainWindow::FileOpen()
81 FileDialog Dlg(this,WB_OPEN );
83 Dlg.AddFilter(CUniString("Alle Dateien"), CUniString("*.*"));
84 Dlg.SetCurFilter (CUniString("*.*"));
86 if (Dlg.Execute() == RET_OK)
88 new EditFileWindow(this,Dlg.GetPath());
93 void MainWindow::TestGross()
95 ModalDialogGROSSER_TEST_DLG Dlg(this,ResId(GROSSER_TEST_DLG, *pAppMgr));
97 if (Dlg.Execute() == RET_OK)
103 BOOL MainWindow::Close()
105 WorkWindow::Close();
106 FileExit();
107 return TRUE;
110 void MainWindow::FileExit()
112 /* WriteSTBProfile();*/
114 // if (pApp->CloseAll())
115 pApp->Quit();
119 void MainWindow::Tree(GHEditWindow *aEditWin, Window *pBase, USHORT Indent)
121 String sIndent,aText;
122 sIndent.Expand(5*Indent);
124 aText = pBase->GetText();
125 aText.SearchAndReplaceAllAscii("\n",CUniString("\\n"));
127 aEditWin->AddText(String(sIndent).AppendAscii("Text: ").Append(aText).AppendAscii("\n"));
128 aEditWin->AddText(String(sIndent).AppendAscii("Help: ").Append(String::CreateFromInt64(pBase->GetHelpId())).AppendAscii(":").Append(pBase->GetQuickHelpText()).AppendAscii(":").Append(pBase->GetHelpText()).AppendAscii("\n"));
130 USHORT i;
131 for (i = 0 ; i < pBase->GetChildCount() ; i++)
133 Tree(aEditWin,pBase->GetChild(i),Indent+1);
137 void MainWindow::WinTree()
140 GHEditWindow * aEditWin = new GHEditWindow(this,CUniString("Window Tree"));
141 Tree(aEditWin,this,0);
145 void MainWindow::SysDlg()
147 switch (QueryBox(this,WB_YES_NO_CANCEL | WB_DEF_YES, CUniString("Want to open another Dialog?")).Execute())
149 case RET_YES:
150 while ( WarningBox(this,WB_OK_CANCEL | WB_DEF_OK,CUniString("Well this is the last box now!")).Execute() == RET_OK ) ;
151 break;
152 case RET_NO:
153 break;
154 case RET_CANCEL:InfoBox(this,CUniString("Oh well..")).Execute();
155 break;
160 #define WB_OK ((WinBits)0x0010)
161 #define WB_OK_CANCEL ((WinBits)0x0020)
162 #define WB_YES_NO ((WinBits)0x0040)
163 #define WB_YES_NO_CANCEL ((WinBits)0x0080)
164 #define WB_RETRY_CANCEL ((WinBits)0x0100)
166 #define WB_DEF_OK ((WinBits)0x0200)
167 #define WB_DEF_CANCEL ((WinBits)0x0400)
168 #define WB_DEF_RETRY ((WinBits)0x0800)
169 #define WB_DEF_YES ((WinBits)0x1000)
170 #define WB_DEF_NO ((WinBits)0x2000)
172 #define RET_OK TRUE
173 #define RET_CANCEL FALSE
174 #define RET_YES 2
175 #define RET_NO 3
176 #define RET_RETRY 4
180 MyApp aApp;
182 MyApp::MyApp()
184 pMainWin = NULL;
187 void MyApp::Property( ApplicationProperty& rProp )
189 TTProperties* pTTProperties = PTR_CAST( TTProperties, &rProp );
190 if ( pTTProperties )
192 pTTProperties->nPropertyVersion = TT_PROPERTIES_VERSION;
193 switch ( pTTProperties->nActualPR )
195 /* case TT_PR_SLOTS:
197 pTTProperties->nSidOpenUrl = SID_OPENURL;
198 pTTProperties->nSidFileName = SID_FILE_NAME;
199 pTTProperties->nSidNewDocDirect = SID_NEWDOCDIRECT;
200 pTTProperties->nSidCopy = SID_COPY;
201 pTTProperties->nSidPaste = SID_PASTE;
202 pTTProperties->nSidSourceView = SID_SOURCEVIEW;
203 pTTProperties->nSidSelectAll = SID_SELECTALL;
204 pTTProperties->nSidReferer = SID_REFERER;
205 pTTProperties->nActualPR = 0;
207 break;*/
208 case TT_PR_DISPATCHER:
210 PlugInDispatcher* pDispatcher = GetDispatcher();
211 if ( !pDispatcher )
212 pTTProperties->nActualPR = TT_PR_ERR_NODISPATCHER;
213 else
215 pDispatcher->SetExecuteMode(EXECUTEMODE_DIALOGASYNCHRON);
216 if ( pDispatcher->ExecuteFunction(
217 pTTProperties->mnSID, pTTProperties->mppArgs, pTTProperties->mnMode )
218 == EXECUTE_NO )
219 pTTProperties->nActualPR = TT_PR_ERR_NOEXECUTE;
220 else
221 pTTProperties->nActualPR = 0;
224 break;
225 /* case TT_PR_IMG:
227 SvDataMemberObjectRef aDataObject = new SvDataMemberObject();
228 SvData* pDataBmp = new SvData( FORMAT_BITMAP );
229 pDataBmp->SetData( pTTProperties->mpBmp );
230 aDataObject->Append( pDataBmp );
231 aDataObject->CopyClipboard();
232 pTTProperties->nActualPR = 0;
234 break;*/
235 default:
237 pTTProperties->nPropertyVersion = 0;
240 return;
245 USHORT MyDispatcher::ExecuteFunction( USHORT nSID, SfxPoolItem** ppArgs, USHORT nMode)
247 (void) ppArgs; /* avoid warning about unused parameter */
248 (void) nMode; /* avoid warning about unused parameter */
250 switch (nSID)
252 case IDM_FILE_EXIT: pMainWin->FileExit(); break;
253 case IDM_FILE_OPEN_TEST: pMainWin->FileOpen(); break;
254 case IDM_TEST_GROSS: pMainWin->TestGross(); break;
255 case IDM_TEST_WINTREE: pMainWin->WinTree(); break;
256 case IDM_SYS_DLG: pMainWin->SysDlg(); break;
257 default:
259 DBG_ERROR1("Dispatcher kennt Funktion nicht %s",ByteString::CreateFromInt64(nSID).GetBuffer());
260 return EXECUTE_NO;
264 return EXECUTE_YES;
267 PlugInDispatcher* MyApp::GetDispatcher()
269 return pMyDispatcher;
272 Reference< XContentProviderManager > InitializeUCB( void )
274 OUString path;
275 if( osl_Process_E_None != osl_getExecutableFile( (rtl_uString**)&path ) )
277 InfoBox( NULL, String::CreateFromAscii( "Couldn't retrieve directory of executable" ) ).Execute();
278 exit( 1 );
280 OSL_ASSERT( path.lastIndexOf( '/' ) >= 0 );
283 ::rtl::OUStringBuffer bufServices( path.copy( 0, path.lastIndexOf( '/' )+1 ) );
284 bufServices.appendAscii("services.rdb");
285 OUString services = bufServices.makeStringAndClear();
287 ::rtl::OUStringBuffer bufTypes( path.copy( 0, path.lastIndexOf( '/' )+1 ) );
288 bufTypes.appendAscii("types.rdb");
289 OUString types = bufTypes.makeStringAndClear();
292 Reference< XMultiServiceFactory > xSMgr;
295 xSMgr = createRegistryServiceFactory( types, services, sal_True );
297 catch( com::sun::star::uno::Exception & exc )
299 fprintf( stderr, "Couldn't bootstrap uno servicemanager for reason : %s\n" ,
300 OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
301 InfoBox( NULL, String( exc.Message ) ).Execute();
302 throw ;
306 //////////////////////////////////////////////////////////////////////
307 // set global factory
308 setProcessServiceFactory( xSMgr );
310 // Create unconfigured Ucb:
311 Sequence< Any > aArgs;
312 ucbhelper::ContentBroker::initialize( xSMgr, aArgs );
313 Reference< XContentProviderManager > xUcb =
314 ucbhelper::ContentBroker::get()->getContentProviderManagerInterface();
316 Reference< XContentProvider > xFileProvider
317 ( xSMgr->createInstance( OUString::createFromAscii( "com.sun.star.ucb.FileContentProvider" ) ), UNO_QUERY );
318 xUcb->registerContentProvider( xFileProvider, OUString::createFromAscii( "file" ), sal_True );
320 return xUcb;
323 void MyApp::Main()
325 Reference< XContentProviderManager > xUcb = InitializeUCB();
326 LanguageType aRequestedLanguage;
327 aRequestedLanguage = LanguageType( LANGUAGE_GERMAN );
329 AllSettings aSettings = GetSettings();
330 aSettings.SetUILanguage( aRequestedLanguage );
331 aSettings.SetLanguage( aRequestedLanguage );
332 SetSettings( aSettings );
333 pAppMgr = CREATEVERSIONRESMGR( tma );
335 MainWindow MainWin(this);
336 pMainWin = &MainWin;
338 MenuBar aMenu(ResId(MENU_CLIENT,*pAppMgr));
339 MainWin.SetMenuBar( &aMenu );
340 aMenu.GetPopupMenu( IDM_FILE )->SetSelectHdl(LINK(&MainWin, MainWindow, MenuSelectHdl));
341 aMenu.GetPopupMenu( IDM_TEST )->SetSelectHdl(LINK(&MainWin, MainWindow, MenuSelectHdl));
343 MyDispatcher MyDsp(pMainWin);
344 pMyDispatcher = &MyDsp;
346 MainWin.SetText(CUniString("Star Division Test Tool Client Window"));
347 MainWin.Show();
349 RemoteControl aRC;
351 Execute();