backingwindow.cxx (9807c9de) backingwindow.cxx (f7882915)
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

--- 32 unchanged lines hidden (view full) ---

41#include "unotools/historyoptions.hxx"
42#include "svtools/imagemgr.hxx"
43#include "svtools/svtools.hrc"
44
45#include "comphelper/processfactory.hxx"
46#include "comphelper/sequenceashashmap.hxx"
47#include "comphelper/configurationhelper.hxx"
48
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

--- 32 unchanged lines hidden (view full) ---

41#include "unotools/historyoptions.hxx"
42#include "svtools/imagemgr.hxx"
43#include "svtools/svtools.hrc"
44
45#include "comphelper/processfactory.hxx"
46#include "comphelper/sequenceashashmap.hxx"
47#include "comphelper/configurationhelper.hxx"
48
49#include <toolkit/awt/vclxmenu.hxx>
50
49#include "cppuhelper/implbase1.hxx"
50
51#include "rtl/strbuf.hxx"
52#include "rtl/ustrbuf.hxx"
53#include "osl/file.h"
54
55#include "com/sun/star/lang/XMultiServiceFactory.hpp"
56#include "com/sun/star/container/XNameAccess.hpp"
57#include "com/sun/star/system/SystemShellExecute.hpp"
58#include "com/sun/star/system/SystemShellExecuteFlags.hpp"
59#include "com/sun/star/task/XJobExecutor.hpp"
60#include "com/sun/star/util/XStringWidth.hpp"
51#include "cppuhelper/implbase1.hxx"
52
53#include "rtl/strbuf.hxx"
54#include "rtl/ustrbuf.hxx"
55#include "osl/file.h"
56
57#include "com/sun/star/lang/XMultiServiceFactory.hpp"
58#include "com/sun/star/container/XNameAccess.hpp"
59#include "com/sun/star/system/SystemShellExecute.hpp"
60#include "com/sun/star/system/SystemShellExecuteFlags.hpp"
61#include "com/sun/star/task/XJobExecutor.hpp"
62#include "com/sun/star/util/XStringWidth.hpp"
63#include <com/sun/star/frame/PopupMenuControllerFactory.hpp>
61
64
62
63using namespace ::com::sun::star::beans;
64using namespace ::com::sun::star::frame;
65using namespace ::com::sun::star::uno;
66using namespace ::com::sun::star;
67using namespace framework;
68
65using namespace ::com::sun::star::beans;
66using namespace ::com::sun::star::frame;
67using namespace ::com::sun::star::uno;
68using namespace ::com::sun::star;
69using namespace framework;
70
71#define RECENT_FILE_LIST ".uno:RecentFileList"
72
69#define WRITER_URL "private:factory/swriter"
70#define CALC_URL "private:factory/scalc"
71#define IMPRESS_WIZARD_URL "private:factory/simpress?slot=6686"
72#define DRAW_URL "private:factory/sdraw"
73#define BASE_URL "private:factory/sdatabase?Interactive"
74#define MATH_URL "private:factory/smath"
75#define TEMPLATE_URL "slot:5500"
76#define OPEN_URL ".uno:Open"

--- 68 unchanged lines hidden (view full) ---

145 maProductString( FwkResId( STR_BACKING_WELCOMEPRODUCT ) ),
146 maOpenString( FwkResId( STR_BACKING_FILE ) ),
147 maTemplateString( FwkResId( STR_BACKING_TEMPLATE ) ),
148 maButtonImageSize( 10, 10 ),
149 mbInitControls( false ),
150 mnLayoutStyle( 0 ),
151 mpAccExec( NULL ),
152 mnBtnPos( 120 ),
73#define WRITER_URL "private:factory/swriter"
74#define CALC_URL "private:factory/scalc"
75#define IMPRESS_WIZARD_URL "private:factory/simpress?slot=6686"
76#define DRAW_URL "private:factory/sdraw"
77#define BASE_URL "private:factory/sdatabase?Interactive"
78#define MATH_URL "private:factory/smath"
79#define TEMPLATE_URL "slot:5500"
80#define OPEN_URL ".uno:Open"

--- 68 unchanged lines hidden (view full) ---

149 maProductString( FwkResId( STR_BACKING_WELCOMEPRODUCT ) ),
150 maOpenString( FwkResId( STR_BACKING_FILE ) ),
151 maTemplateString( FwkResId( STR_BACKING_TEMPLATE ) ),
152 maButtonImageSize( 10, 10 ),
153 mbInitControls( false ),
154 mnLayoutStyle( 0 ),
155 mpAccExec( NULL ),
156 mnBtnPos( 120 ),
153 mnBtnTop( 150 ),
154 mpRecentMenu( NULL )
157 mnBtnTop( 150 )
155{
156 mnColumnWidth[0] = mnColumnWidth[1] = 0;
157 mnTextColumnWidth[0] = mnTextColumnWidth[1] = 0;
158
159 try
160 {
158{
159 mnColumnWidth[0] = mnColumnWidth[1] = 0;
160 mnTextColumnWidth[0] = mnTextColumnWidth[1] = 0;
161
162 try
163 {
161 Reference<lang::XMultiServiceFactory> xConfig( comphelper::getProcessServiceFactory()->createInstance(SERVICENAME_CFGPROVIDER),UNO_QUERY);
164 mxContext.set( ::comphelper::getProcessComponentContext(), uno::UNO_SET_THROW );
165
166 Reference<lang::XMultiServiceFactory> xConfig(
167 mxContext->getServiceManager()->createInstanceWithContext(
168 SERVICENAME_CFGPROVIDER, mxContext), UNO_QUERY);
162 if( xConfig.is() )
163 {
164 Sequence<Any> args(1);
165 PropertyValue val(
166 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("nodepath") ),
167 0,
168 Any(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Office.Common/Help/StartCenter"))),
169 PropertyState_DIRECT_VALUE);
170 args.getArray()[0] <<= val;
171 Reference<container::XNameAccess> xNameAccess(xConfig->createInstanceWithArguments(SERVICENAME_CFGREADACCESS,args), UNO_QUERY);
172 if( xNameAccess.is() )
173 {
174 //throws css::container::NoSuchElementException, css::lang::WrappedTargetException
175 Any value( xNameAccess->getByName(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StartCenterLayoutStyle"))) );
176 mnLayoutStyle = value.get<sal_Int32>();
177 }
178 }
169 if( xConfig.is() )
170 {
171 Sequence<Any> args(1);
172 PropertyValue val(
173 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("nodepath") ),
174 0,
175 Any(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Office.Common/Help/StartCenter"))),
176 PropertyState_DIRECT_VALUE);
177 args.getArray()[0] <<= val;
178 Reference<container::XNameAccess> xNameAccess(xConfig->createInstanceWithArguments(SERVICENAME_CFGREADACCESS,args), UNO_QUERY);
179 if( xNameAccess.is() )
180 {
181 //throws css::container::NoSuchElementException, css::lang::WrappedTargetException
182 Any value( xNameAccess->getByName(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StartCenterLayoutStyle"))) );
183 mnLayoutStyle = value.get<sal_Int32>();
184 }
185 }
186
187 mxPopupMenuFactory.set(
188 frame::PopupMenuControllerFactory::create( mxContext ) );
189 // TODO If there is no PopupMenuController, the button should be a nomral one not a MenuButton
190 if ( mxPopupMenuFactory->hasController(
191 DECLARE_ASCII( RECENT_FILE_LIST ) , SERVICENAME_STARTMODULE ) )
192 {
193 mxPopupMenu.set( mxContext->getServiceManager()->createInstanceWithContext(
194 DECLARE_ASCII( "com.sun.star.awt.PopupMenu" ), mxContext ), uno::UNO_QUERY_THROW );
195 }
179 }
196 }
180 catch (Exception& )
197 catch (const Exception& e)
181 {
198 {
199 OSL_TRACE( "BackingWindow - caught an exception! %s",
200 rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
201 (void) e;
182 }
183
184 String aExtHelpText( FwkResId( STR_BACKING_EXTHELP ) );
185 String aRegHelpText( FwkResId( STR_BACKING_REGHELP ) );
186 String aInfoHelpText( FwkResId( STR_BACKING_INFOHELP ) );
187 String aTplRepHelpText( FwkResId( STR_BACKING_TPLREP ) );
188
189 // clean up resource stack

--- 49 unchanged lines hidden (view full) ---

239 maButtonImageSize.Width() += 12;
240 maButtonImageSize.Height() += 12;
241
242}
243
244
245BackingWindow::~BackingWindow()
246{
202 }
203
204 String aExtHelpText( FwkResId( STR_BACKING_EXTHELP ) );
205 String aRegHelpText( FwkResId( STR_BACKING_REGHELP ) );
206 String aInfoHelpText( FwkResId( STR_BACKING_INFOHELP ) );
207 String aTplRepHelpText( FwkResId( STR_BACKING_TPLREP ) );
208
209 // clean up resource stack

--- 49 unchanged lines hidden (view full) ---

259 maButtonImageSize.Width() += 12;
260 maButtonImageSize.Height() += 12;
261
262}
263
264
265BackingWindow::~BackingWindow()
266{
247 delete mpRecentMenu;
248 delete mpAccExec;
267 delete mpAccExec;
268
269 if( mxPopupMenuController.is() )
270 {
271 Reference< lang::XComponent > xComponent( mxPopupMenuController, UNO_QUERY );
272 if( xComponent.is() )
273 {
274 try
275 {
276 xComponent->dispose();
277 }
278 catch (...)
279 {}
280 }
281 mxPopupMenuController.clear();
282 }
283 mxPopupMenuFactory.clear();
284 mxPopupMenu.clear();
249}
250
251void BackingWindow::GetFocus()
252{
253 if( IsVisible() )
254 maWriterButton.GrabFocus();
255 Window::GetFocus();
256}

--- 13 unchanged lines hidden (view full) ---

270 {
271 initBackground();
272 Invalidate();
273 }
274}
275
276void BackingWindow::prepareRecentFileMenu()
277{
285}
286
287void BackingWindow::GetFocus()
288{
289 if( IsVisible() )
290 maWriterButton.GrabFocus();
291 Window::GetFocus();
292}

--- 13 unchanged lines hidden (view full) ---

306 {
307 initBackground();
308 Invalidate();
309 }
310}
311
312void BackingWindow::prepareRecentFileMenu()
313{
278 if( ! mpRecentMenu )
279 mpRecentMenu = new PopupMenu();
280 mpRecentMenu->Clear();
281 maRecentFiles.clear();
282
283 // get recent file list and dispatch arguments
284 Sequence< Sequence< PropertyValue > > aHistoryList( SvtHistoryOptions().GetList( ePICKLIST ) );
314 if( ! mxPopupMenu.is() )
315 return;
285
316
286 sal_Int32 nPickListMenuItems = ( aHistoryList.getLength() > 99 ) ? 99 : aHistoryList.getLength();
287
288 if( ( nPickListMenuItems > 0 ) )
317 if ( !mxPopupMenuController.is() )
289 {
318 {
290 maRecentFiles.reserve( nPickListMenuItems );
291 for ( sal_Int32 i = 0; i < nPickListMenuItems; i++ )
292 {
293 Sequence< PropertyValue >& rPickListEntry = aHistoryList[i];
294 rtl::OUString aURL, aFilter, aFilterOpt, aTitle;
295
296 for ( sal_Int32 j = 0; j < rPickListEntry.getLength(); j++ )
297 {
298 const Any& a = rPickListEntry[j].Value;
299
300 if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_URL )
301 a >>= aURL;
302 else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_FILTER )
303 {
304 a >>= aFilter;
305 sal_Int32 nPos = aFilter.indexOf( '|' );
306 if ( nPos >= 0 )
307 {
308 if ( nPos < ( aFilter.getLength() - 1 ) )
309 aFilterOpt = aFilter.copy( nPos+1 );
310 aFilter = aFilter.copy( 0, nPos-1 );
311 }
312 }
313 else if ( rPickListEntry[j].Name == HISTORY_PROPERTYNAME_TITLE )
314 a >>= aTitle;
315 }
316 maRecentFiles.push_back( LoadRecentFile() );
317 maRecentFiles.back().aTargetURL = aURL;
319 uno::Sequence< uno::Any > aArgs( 2 );
320 beans::PropertyValue aProp;
318
321
319 sal_Int32 nArgs = aFilterOpt.getLength() ? 4 : 3;
320 Sequence< PropertyValue >& rArgsList( maRecentFiles.back().aArgSeq );
321 rArgsList.realloc( nArgs );
322 aProp.Name = DECLARE_ASCII( "Frame" );
323 aProp.Value <<= mxFrame;
324 aArgs[0] <<= aProp;
322
325
323 nArgs--;
324 rArgsList[nArgs].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ));
325 rArgsList[nArgs].Value = makeAny( aFilter );
326
327 if( aFilterOpt.getLength() )
328 {
329 nArgs--;
330 rArgsList[nArgs].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterOptions" ));
331 rArgsList[nArgs].Value = makeAny( aFilterOpt );
332 }
333
334 // documents in the picklist will never be opened as templates
335 nArgs--;
336 rArgsList[nArgs].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AsTemplate" ));
337 rArgsList[nArgs].Value = makeAny( (sal_Bool) sal_False );
338
339 nArgs--;
340 rArgsList[nArgs].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Referer" ));
341 rArgsList[nArgs].Value = makeAny( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:user" ) ) );
342
343 // and finally create an entry in the popupmenu
344 rtl::OUString aMenuTitle;
345 INetURLObject aURLObj( aURL );
346
347 if ( aURLObj.GetProtocol() == INET_PROT_FILE )
348 {
349 // Do handle file URL differently => convert it to a system
350 // path and abbreviate it with a special function:
351 String aFileSystemPath( aURLObj.getFSysPath( INetURLObject::FSYS_DETECT ) );
352
353 rtl::OUString aSystemPath( aFileSystemPath );
354 rtl::OUString aCompactedSystemPath;
355
356 oslFileError nError = osl_abbreviateSystemPath( aSystemPath.pData, &aCompactedSystemPath.pData, 46, NULL );
357 if ( !nError )
358 aMenuTitle = String( aCompactedSystemPath );
359 else
360 aMenuTitle = aSystemPath;
361 }
362 else
363 {
364 // Use INetURLObject to abbreviate all other URLs
365 Reference< util::XStringWidth > xStringLength( new RecentFilesStringLength() );
366 aMenuTitle = aURLObj.getAbbreviated( xStringLength, 46, INetURLObject::DECODE_UNAMBIGUOUS );
367 }
368 rtl::OUStringBuffer aBuf( aMenuTitle.getLength() + 5 );
369 if( i < 9 )
370 {
371 aBuf.append( sal_Unicode( '~' ) );
372 aBuf.append( i+1 );
373 }
374 else if( i == 9 )
375 aBuf.appendAscii( "1~0" );
376 else
377 aBuf.append( i+1 );
378 aBuf.appendAscii( ": " );
379 aBuf.append( aMenuTitle );
380 mpRecentMenu->InsertItem( static_cast<sal_uInt16>(i+1), aBuf.makeStringAndClear() );
326 aProp.Name = DECLARE_ASCII( "ModuleIdentifier" );
327 aProp.Value <<= SERVICENAME_STARTMODULE;
328 aArgs[1] <<= aProp;
329 try
330 {
331 mxPopupMenuController.set(
332 mxPopupMenuFactory->createInstanceWithArgumentsAndContext(
333 DECLARE_ASCII( RECENT_FILE_LIST ), aArgs, mxContext),
334 uno::UNO_QUERY_THROW );
335 mxPopupMenuController->setPopupMenu( mxPopupMenu );
381 }
336 }
337 catch ( const Exception &e )
338 {
339 OSL_TRACE( "BackingWindow - caught an exception! %s",
340 rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
341 (void) e;
342 }
343
344 PopupMenu *pRecentMenu = NULL;
345 VCLXMenu* pTKMenu = VCLXMenu::GetImplementation( mxPopupMenu );
346 if ( pTKMenu )
347 pRecentMenu = dynamic_cast< PopupMenu * >( pTKMenu->GetMenu() );
348 maOpenButton.SetPopupMenu( pRecentMenu );
382 }
349 }
383 else
384 {
385 String aNoDoc( FwkResId( STR_NODOCUMENT ) );
386 mpRecentMenu->InsertItem( 0xffff, aNoDoc );
387 }
388 maOpenButton.SetPopupMenu( mpRecentMenu );
389}
390
391void BackingWindow::initBackground()
392{
393 SetBackground();
394
395 bool bDark = GetSettings().GetStyleSettings().GetHighContrastMode();
396 if( bDark )

--- 53 unchanged lines hidden (view full) ---

450 loadImage( FwkResId( BMP_BACKING_IMPRESS ), maImpressButton );
451 loadImage( FwkResId( BMP_BACKING_DRAW ), maDrawButton );
452 loadImage( FwkResId( BMP_BACKING_DATABASE ), maDBButton );
453 loadImage( FwkResId( BMP_BACKING_FORMULA ), maMathButton );
454 loadImage( FwkResId( BMP_BACKING_OPENFILE ), maOpenButton );
455 loadImage( FwkResId( BMP_BACKING_OPENTEMPLATE ), maTemplateButton );
456
457 maOpenButton.SetMenuMode( MENUBUTTON_MENUMODE_TIMED );
350}
351
352void BackingWindow::initBackground()
353{
354 SetBackground();
355
356 bool bDark = GetSettings().GetStyleSettings().GetHighContrastMode();
357 if( bDark )

--- 53 unchanged lines hidden (view full) ---

411 loadImage( FwkResId( BMP_BACKING_IMPRESS ), maImpressButton );
412 loadImage( FwkResId( BMP_BACKING_DRAW ), maDrawButton );
413 loadImage( FwkResId( BMP_BACKING_DATABASE ), maDBButton );
414 loadImage( FwkResId( BMP_BACKING_FORMULA ), maMathButton );
415 loadImage( FwkResId( BMP_BACKING_OPENFILE ), maOpenButton );
416 loadImage( FwkResId( BMP_BACKING_OPENTEMPLATE ), maTemplateButton );
417
418 maOpenButton.SetMenuMode( MENUBUTTON_MENUMODE_TIMED );
458 maOpenButton.SetSelectHdl( LINK( this, BackingWindow, SelectHdl ) );
459 maOpenButton.SetActivateHdl( LINK( this, BackingWindow, ActivateHdl ) );
460}
461
462void BackingWindow::initControls()
463{
464 if( mbInitControls )
465 return;
466

--- 554 unchanged lines hidden (view full) ---

1021 pArg[0].Name = rtl::OUString::createFromAscii("Referer");
1022 pArg[0].Value <<= rtl::OUString::createFromAscii("private:user");
1023
1024 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(TEMPLATE_URL) ), rtl::OUString(), xFrame, aArgs );
1025 }
1026 return 0;
1027}
1028
419 maOpenButton.SetActivateHdl( LINK( this, BackingWindow, ActivateHdl ) );
420}
421
422void BackingWindow::initControls()
423{
424 if( mbInitControls )
425 return;
426

--- 554 unchanged lines hidden (view full) ---

981 pArg[0].Name = rtl::OUString::createFromAscii("Referer");
982 pArg[0].Value <<= rtl::OUString::createFromAscii("private:user");
983
984 dispatchURL( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(TEMPLATE_URL) ), rtl::OUString(), xFrame, aArgs );
985 }
986 return 0;
987}
988
1029IMPL_LINK( BackingWindow, SelectHdl, Button*, pButton )
1030{
1031 if( pButton == &maOpenButton )
1032 {
1033 sal_Int32 nItem = sal_Int32(maOpenButton.GetCurItemId())-1;
1034 if( nItem >= 0 && nItem < sal_Int32(maRecentFiles.size()) )
1035 {
1036 Reference< XDispatchProvider > xFrame( mxFrame, UNO_QUERY );
1037 dispatchURL( maRecentFiles[nItem].aTargetURL, rtl::OUString(), xFrame, maRecentFiles[nItem].aArgSeq );
1038 }
1039 }
1040 return 0;
1041}
1042
1043IMPL_LINK( BackingWindow, ActivateHdl, Button*, pButton )
1044{
1045 if( pButton == &maOpenButton )
1046 prepareRecentFileMenu();
1047 return 0;
1048}
1049

--- 82 unchanged lines hidden ---
989
990IMPL_LINK( BackingWindow, ActivateHdl, Button*, pButton )
991{
992 if( pButton == &maOpenButton )
993 prepareRecentFileMenu();
994 return 0;
995}
996

--- 82 unchanged lines hidden ---