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: 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>
35 #ifndef _MSGBOX_HXX //autogen
36 #include <vcl/msgbox.hxx>
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
;
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
)
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()
110 void MainWindow::FileExit()
112 /* WriteSTBProfile();*/
114 // if (pApp->CloseAll())
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"));
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())
150 while ( WarningBox(this,WB_OK_CANCEL
| WB_DEF_OK
,CUniString("Well this is the last box now!")).Execute() == RET_OK
) ;
154 case RET_CANCEL
:InfoBox(this,CUniString("Oh well..")).Execute();
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)
173 #define RET_CANCEL FALSE
187 void MyApp::Property( ApplicationProperty
& rProp
)
189 TTProperties
* pTTProperties
= PTR_CAST( TTProperties
, &rProp
);
192 pTTProperties
->nPropertyVersion
= TT_PROPERTIES_VERSION
;
193 switch ( pTTProperties
->nActualPR
)
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;
208 case TT_PR_DISPATCHER
:
210 PlugInDispatcher
* pDispatcher
= GetDispatcher();
212 pTTProperties
->nActualPR
= TT_PR_ERR_NODISPATCHER
;
215 pDispatcher
->SetExecuteMode(EXECUTEMODE_DIALOGASYNCHRON
);
216 if ( pDispatcher
->ExecuteFunction(
217 pTTProperties
->mnSID
, pTTProperties
->mppArgs
, pTTProperties
->mnMode
)
219 pTTProperties
->nActualPR
= TT_PR_ERR_NOEXECUTE
;
221 pTTProperties
->nActualPR
= 0;
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;
237 pTTProperties
->nPropertyVersion
= 0;
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 */
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;
259 DBG_ERROR1("Dispatcher kennt Funktion nicht %s",ByteString::CreateFromInt64(nSID
).GetBuffer());
267 PlugInDispatcher
* MyApp::GetDispatcher()
269 return pMyDispatcher
;
272 Reference
< XContentProviderManager
> InitializeUCB( void )
275 if( osl_Process_E_None
!= osl_getExecutableFile( (rtl_uString
**)&path
) )
277 InfoBox( NULL
, String::CreateFromAscii( "Couldn't retrieve directory of executable" ) ).Execute();
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();
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
);
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);
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"));