2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include <sal/macros.h>
20 #include <sal/log.hxx>
22 #include <unotools/moduleoptions.hxx>
23 #include <unotools/dynamicmenuoptions.hxx>
28 #include "shutdownicon.hxx"
29 #include <sfx2/sfxresid.hxx>
30 #include <sfx2/strings.hrc>
33 #include <osl/thread.h>
34 #include <systools/win32/qswin32.h>
35 #include <comphelper/sequenceashashmap.hxx>
36 #include <comphelper/windowserrorstring.hxx>
37 #include <o3tl/char16_t2wchar_t.hxx>
41 using namespace ::osl
;
43 using ::com::sun::star::uno::Sequence
;
44 using ::com::sun::star::beans::PropertyValue
;
47 #define EXECUTER_WINDOWCLASS L"SO Executer Class"
48 #define EXECUTER_WINDOWNAME L"SO Executer Window"
51 #define ID_QUICKSTART 1
59 #define IDM_TEMPLATE 9
61 #define IDM_INSTALL 10
62 #define IDM_STARTCENTER 14
65 #define ICON_LO_DEFAULT 1
66 #define ICON_TEXT_DOCUMENT 2
67 #define ICON_SPREADSHEET_DOCUMENT 4
68 #define ICON_DRAWING_DOCUMENT 6
69 #define ICON_PRESENTATION_DOCUMENT 8
70 #define ICON_TEMPLATE 11
71 #define ICON_DATABASE_DOCUMENT 12
72 #define ICON_MATH_DOCUMENT 13
73 #define ICON_OPEN 5 // See index of open folder icon in shell32.dll
75 #define SFX_TASKBAR_NOTIFICATION WM_USER+1
77 static HWND aListenerWindow
= nullptr;
78 static HWND aExecuterWindow
= nullptr;
79 static HMENU popupMenu
= nullptr;
81 static void OnMeasureItem(HWND hwnd
, LPMEASUREITEMSTRUCT lpmis
);
82 static void OnDrawItem(HWND hwnd
, LPDRAWITEMSTRUCT lpdis
);
86 typedef struct tagMYITEM
95 static void addMenuItem( HMENU hMenu
, UINT id
, UINT iconId
, const OUString
& text
, int& pos
, bool bOwnerdraw
, const OUString
& module
)
97 MENUITEMINFOW mi
= {};
99 mi
.cbSize
= sizeof( mi
);
100 if( id
== static_cast<UINT
>( -1 ) )
103 mi
.fType
=MFT_SEPARATOR
;
109 mi
.fMask
=MIIM_TYPE
| MIIM_STATE
| MIIM_ID
| MIIM_DATA
;
110 mi
.fType
=MFT_OWNERDRAW
;
111 mi
.fState
=MFS_ENABLED
;
114 MYITEM
*pMyItem
= new MYITEM
;
115 pMyItem
->text
= text
;
116 pMyItem
->iconId
= iconId
;
117 pMyItem
->module
= module
;
118 mi
.dwItemData
= reinterpret_cast<DWORD_PTR
>(pMyItem
);
122 mi
.fMask
=MIIM_TYPE
| MIIM_STATE
| MIIM_ID
| MIIM_DATA
;
124 mi
.fState
=MFS_ENABLED
;
126 mi
.dwTypeData
= o3tl::toW(
127 const_cast<sal_Unicode
*>(text
.getStr()));
128 mi
.cch
= text
.getLength();
131 if ( IDM_TEMPLATE
== id
)
132 mi
.fState
|= MFS_DEFAULT
;
135 InsertMenuItemW( hMenu
, pos
++, TRUE
, &mi
);
139 static HMENU
createSystrayMenu( )
141 SvtModuleOptions aModuleOptions
;
143 HMENU hMenu
= CreatePopupMenu();
146 ShutdownIcon
*pShutdownIcon
= ShutdownIcon::getInstance();
147 OSL_ENSURE( pShutdownIcon
, "ShutdownIcon instance empty!");
152 // collect the URLs of the entries in the File/New menu
153 ::std::set
< OUString
> aFileNewAppsAvailable
;
154 std::vector
< SvtDynMenuEntry
> const aNewMenu
= SvtDynamicMenuOptions::GetMenu( EDynamicMenuType::NewMenu
);
155 for ( SvtDynMenuEntry
const & newMenuProp
: aNewMenu
)
157 if ( !newMenuProp
.sURL
.isEmpty() )
158 aFileNewAppsAvailable
.insert( newMenuProp
.sURL
);
161 // describe the menu entries for launching the applications
162 struct MenuEntryDescriptor
164 SvtModuleOptions::EModule eModuleIdentifier
;
167 const char* pAsciiURLDescription
;
170 { SvtModuleOptions::EModule::WRITER
, IDM_WRITER
, ICON_TEXT_DOCUMENT
, WRITER_URL
},
171 { SvtModuleOptions::EModule::CALC
, IDM_CALC
, ICON_SPREADSHEET_DOCUMENT
, CALC_URL
},
172 { SvtModuleOptions::EModule::IMPRESS
, IDM_IMPRESS
,ICON_PRESENTATION_DOCUMENT
, IMPRESS_WIZARD_URL
},
173 { SvtModuleOptions::EModule::DRAW
, IDM_DRAW
, ICON_DRAWING_DOCUMENT
, DRAW_URL
},
174 { SvtModuleOptions::EModule::DATABASE
, IDM_BASE
, ICON_DATABASE_DOCUMENT
, BASE_URL
},
175 { SvtModuleOptions::EModule::MATH
, IDM_MATH
, ICON_MATH_DOCUMENT
, MATH_URL
},
178 // insert the menu entries for launching the applications
179 for ( size_t i
= 0; i
< SAL_N_ELEMENTS(aMenuItems
); ++i
)
181 if ( !aModuleOptions
.IsModuleInstalled( aMenuItems
[i
].eModuleIdentifier
) )
182 // the complete application is not even installed
185 OUString
sURL( OUString::createFromAscii( aMenuItems
[i
].pAsciiURLDescription
) );
187 if ( aFileNewAppsAvailable
.find( sURL
) == aFileNewAppsAvailable
.end() )
188 // the application is installed, but the entry has been configured to *not* appear in the File/New
189 // menu => also let not appear it in the quickstarter
192 addMenuItem( hMenu
, aMenuItems
[i
].nMenuItemID
, aMenuItems
[i
].nMenuIconID
,
193 ShutdownIcon::GetUrlDescription( sURL
), pos
, true, "" );
197 // insert the remaining menu entries
198 addMenuItem( hMenu
, IDM_TEMPLATE
, ICON_TEMPLATE
,
199 SfxResId( STR_QUICKSTART_FROMTEMPLATE
), pos
, true, "");
200 addMenuItem( hMenu
, static_cast< UINT
>( -1 ), 0, OUString(), pos
, false, "" );
201 addMenuItem( hMenu
, IDM_OPEN
, ICON_OPEN
, SfxResId(STR_QUICKSTART_FILEOPEN
), pos
, true, "SHELL32");
202 addMenuItem( hMenu
, static_cast< UINT
>( -1 ), 0, OUString(), pos
, false, "" );
203 addMenuItem( hMenu
, IDM_INSTALL
,0, SfxResId(STR_QUICKSTART_PRELAUNCH
), pos
, false, "" );
204 addMenuItem( hMenu
, static_cast< UINT
>( -1 ), 0, OUString(), pos
, false, "" );
205 addMenuItem( hMenu
, IDM_EXIT
, 0, SfxResId(STR_QUICKSTART_EXIT
), pos
, false, "" );
207 // indicate status of autostart folder
208 CheckMenuItem( hMenu
, IDM_INSTALL
, MF_BYCOMMAND
| (ShutdownIcon::GetAutostart() ? MF_CHECKED
: MF_UNCHECKED
) );
214 static void deleteSystrayMenu( HMENU hMenu
)
216 if( !hMenu
|| !IsMenu( hMenu
))
219 MENUITEMINFOW mi
= {};
221 mi
.cbSize
= sizeof( mi
);
222 mi
.fMask
= MIIM_DATA
;
224 while( GetMenuItemInfoW( hMenu
, pos
++, true, &mi
) )
226 MYITEM
*pMyItem
= reinterpret_cast<MYITEM
*>(mi
.dwItemData
);
229 pMyItem
->text
.clear();
232 mi
.fMask
= MIIM_DATA
;
237 static void addTaskbarIcon( HWND hWnd
)
239 OUString strTip
= SfxResId(STR_QUICKSTART_TIP
);
243 nid
.hIcon
= static_cast<HICON
>(LoadImageW( GetModuleHandleW( nullptr ), MAKEINTRESOURCEW( ICON_LO_DEFAULT
),
244 IMAGE_ICON
, GetSystemMetrics( SM_CXSMICON
), GetSystemMetrics( SM_CYSMICON
),
245 LR_DEFAULTCOLOR
| LR_SHARED
));
247 wcsncpy( nid
.szTip
, o3tl::toW(strTip
.getStr()), 64 );
249 nid
.cbSize
= sizeof(nid
);
251 nid
.uID
= ID_QUICKSTART
;
252 nid
.uCallbackMessage
= SFX_TASKBAR_NOTIFICATION
;
253 nid
.uFlags
= NIF_MESSAGE
|NIF_TIP
|NIF_ICON
;
255 Shell_NotifyIconW(NIM_ADD
, &nid
);
259 static LRESULT CALLBACK
listenerWndProc( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
261 static UINT s_uTaskbarRestart
= 0;
262 static UINT s_uMsgKillTray
= 0;
270 // request notification when taskbar is recreated
271 // we then have to add our icon again
272 s_uTaskbarRestart
= RegisterWindowMessageW(L
"TaskbarCreated");
273 s_uMsgKillTray
= RegisterWindowMessageW( SHUTDOWN_QUICKSTART_MESSAGE
);
277 if( (popupMenu
= createSystrayMenu( )) == nullptr )
281 addTaskbarIcon( hWnd
);
284 ShutdownIcon::getInstance()->SetVeto( true );
285 ShutdownIcon::addTerminateListener();
290 OnMeasureItem(hWnd
, reinterpret_cast<LPMEASUREITEMSTRUCT
>(lParam
));
294 OnDrawItem(hWnd
, reinterpret_cast<LPDRAWITEMSTRUCT
>(lParam
));
297 case SFX_TASKBAR_NOTIFICATION
:
302 bool const ret
= PostMessageW(aExecuterWindow
, WM_COMMAND
, IDM_STARTCENTER
, reinterpret_cast<LPARAM
>(hWnd
));
303 SAL_WARN_IF(!ret
, "sfx.appl", "ERROR: PostMessage() failed!");
311 SetForegroundWindow( hWnd
);
313 // update status before showing menu, could have been changed from option page
314 CheckMenuItem( popupMenu
, IDM_INSTALL
, MF_BYCOMMAND
| (ShutdownIcon::GetAutostart() ? MF_CHECKED
: MF_UNCHECKED
) );
316 EnableMenuItem( popupMenu
, IDM_EXIT
, MF_BYCOMMAND
| (ShutdownIcon::bModalMode
? MF_GRAYED
: MF_ENABLED
) );
317 EnableMenuItem( popupMenu
, IDM_OPEN
, MF_BYCOMMAND
| (ShutdownIcon::bModalMode
? MF_GRAYED
: MF_ENABLED
) );
318 EnableMenuItem( popupMenu
, IDM_TEMPLATE
, MF_BYCOMMAND
| (ShutdownIcon::bModalMode
? MF_GRAYED
: MF_ENABLED
) );
319 int m
= TrackPopupMenuEx( popupMenu
, TPM_RETURNCMD
|TPM_LEFTALIGN
|TPM_RIGHTBUTTON
,
320 pt
.x
, pt
.y
, hWnd
, nullptr );
321 bool const ret
= PostMessageW( hWnd
, 0, 0, 0 );
322 SAL_WARN_IF(!ret
, "sfx.appl", "ERROR: PostMessage() failed!");
335 CheckMenuItem( popupMenu
, IDM_INSTALL
, MF_BYCOMMAND
| (ShutdownIcon::GetAutostart() ? MF_CHECKED
: MF_UNCHECKED
) );
338 // delete taskbar icon
340 nid
.cbSize
=sizeof(nid
);
342 nid
.uID
= ID_QUICKSTART
;
343 Shell_NotifyIconW(NIM_DELETE
, &nid
);
347 bool const ret2
= PostMessageW(aExecuterWindow
, WM_COMMAND
, m
, reinterpret_cast<LPARAM
>(hWnd
));
348 SAL_WARN_IF(!ret2
, "sfx.appl", "ERROR: PostMessage() failed!");
354 deleteSystrayMenu( popupMenu
);
355 // We don't need the Systray Thread anymore
356 PostQuitMessage( 0 );
357 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
359 if( uMsg
== s_uTaskbarRestart
)
361 // re-create taskbar icon
362 addTaskbarIcon( hWnd
);
364 else if ( uMsg
== s_uMsgKillTray
)
366 // delete taskbar icon
368 nid
.cbSize
=sizeof(nid
);
370 nid
.uID
= ID_QUICKSTART
;
371 Shell_NotifyIconW(NIM_DELETE
, &nid
);
373 bool const ret
= PostMessageW(aExecuterWindow
, WM_COMMAND
, IDM_EXIT
, reinterpret_cast<LPARAM
>(hWnd
));
374 SAL_WARN_IF(!ret
, "sfx.appl", "ERROR: PostMessage() failed!");
377 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
383 static LRESULT CALLBACK
executerWndProc( HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
393 switch( LOWORD(wParam
) )
396 if ( !ShutdownIcon::bModalMode
)
397 ShutdownIcon::FileOpen();
400 ShutdownIcon::OpenURL( WRITER_URL
, "_default" );
403 ShutdownIcon::OpenURL( CALC_URL
, "_default" );
406 ShutdownIcon::OpenURL( IMPRESS_WIZARD_URL
, "_default" );
409 ShutdownIcon::OpenURL( DRAW_URL
, "_default" );
412 ShutdownIcon::OpenURL( BASE_URL
, "_default" );
415 ShutdownIcon::OpenURL( MATH_URL
, "_default" );
417 case IDM_STARTCENTER
:
418 ShutdownIcon::OpenURL( STARTMODULE_URL
, "_default" );
421 if ( !ShutdownIcon::bModalMode
)
422 ShutdownIcon::FromTemplate();
425 ShutdownIcon::SetAutostart( !ShutdownIcon::GetAutostart() );
428 // remove listener and
429 // terminate office if running in background
430 if ( !ShutdownIcon::bModalMode
)
431 ShutdownIcon::terminateDesktop();
437 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
443 static DWORD WINAPI
SystrayThread( LPVOID
/*lpParam*/ )
445 osl_setThreadName("SystrayThread");
447 aListenerWindow
= CreateWindowExW(0,
448 QUICKSTART_CLASSNAME
, // registered class name
449 QUICKSTART_WINDOWNAME
, // window name
451 CW_USEDEFAULT
, // horizontal position of window
452 CW_USEDEFAULT
, // vertical position of window
453 CW_USEDEFAULT
, // window width
454 CW_USEDEFAULT
, // window height
455 nullptr, // handle to parent or owner window
456 nullptr, // menu handle or child identifier
457 GetModuleHandleW( nullptr ), // handle to application instance
458 nullptr // window-creation data
465 auto const bRet
= GetMessageW(&msg
, nullptr, 0, 0);
472 SAL_WARN("sfx.appl", "GetMessageW failed: " << WindowsErrorString(GetLastError()));
475 TranslateMessage( &msg
);
476 DispatchMessageW( &msg
);
479 return msg
.wParam
; // Exit code of WM_QUIT
483 void win32_init_sys_tray()
485 if ( ShutdownIcon::IsQuickstarterInstalled() )
487 WNDCLASSEXW listenerClass
;
488 listenerClass
.cbSize
= sizeof(listenerClass
);
489 listenerClass
.style
= 0;
490 listenerClass
.lpfnWndProc
= listenerWndProc
;
491 listenerClass
.cbClsExtra
= 0;
492 listenerClass
.cbWndExtra
= 0;
493 listenerClass
.hInstance
= GetModuleHandleW( nullptr );
494 listenerClass
.hIcon
= nullptr;
495 listenerClass
.hCursor
= nullptr;
496 listenerClass
.hbrBackground
= nullptr;
497 listenerClass
.lpszMenuName
= nullptr;
498 listenerClass
.lpszClassName
= QUICKSTART_CLASSNAME
;
499 listenerClass
.hIconSm
= nullptr;
501 RegisterClassExW(&listenerClass
);
503 WNDCLASSEXW executerClass
;
504 executerClass
.cbSize
= sizeof(executerClass
);
505 executerClass
.style
= 0;
506 executerClass
.lpfnWndProc
= executerWndProc
;
507 executerClass
.cbClsExtra
= 0;
508 executerClass
.cbWndExtra
= 0;
509 executerClass
.hInstance
= GetModuleHandleW( nullptr );
510 executerClass
.hIcon
= nullptr;
511 executerClass
.hCursor
= nullptr;
512 executerClass
.hbrBackground
= nullptr;
513 executerClass
.lpszMenuName
= nullptr;
514 executerClass
.lpszClassName
= EXECUTER_WINDOWCLASS
;
515 executerClass
.hIconSm
= nullptr;
517 RegisterClassExW( &executerClass
);
519 aExecuterWindow
= CreateWindowExW(0,
520 EXECUTER_WINDOWCLASS
, // registered class name
521 EXECUTER_WINDOWNAME
, // window name
523 CW_USEDEFAULT
, // horizontal position of window
524 CW_USEDEFAULT
, // vertical position of window
525 CW_USEDEFAULT
, // window width
526 CW_USEDEFAULT
, // window height
527 nullptr, // handle to parent or owner window
528 nullptr, // menu handle or child identifier
529 GetModuleHandleW( nullptr ), // handle to application instance
530 nullptr // window-creation data
534 CloseHandle(CreateThread(nullptr, 0, SystrayThread
, nullptr, 0, &dwThreadId
));
539 void win32_shutdown_sys_tray()
541 if ( ShutdownIcon::IsQuickstarterInstalled() )
543 if( IsWindow( aListenerWindow
) )
545 DestroyWindow( aListenerWindow
);
546 aListenerWindow
= nullptr;
547 DestroyWindow( aExecuterWindow
);
548 aExecuterWindow
= nullptr;
550 UnregisterClassW( QUICKSTART_CLASSNAME
, GetModuleHandleW( nullptr ) );
551 UnregisterClassW( EXECUTER_WINDOWCLASS
, GetModuleHandleW( nullptr ) );
556 void OnMeasureItem(HWND hwnd
, LPMEASUREITEMSTRUCT lpmis
)
558 MYITEM
*pMyItem
= reinterpret_cast<MYITEM
*>(lpmis
->itemData
);
559 HDC hdc
= GetDC(hwnd
);
562 NONCLIENTMETRICSW ncm
= {};
563 ncm
.cbSize
= sizeof(ncm
);
565 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0);
567 // Assume every menu item can be default and printed bold
568 ncm
.lfMenuFont
.lfWeight
= FW_BOLD
;
570 HFONT hfntOld
= static_cast<HFONT
>(SelectObject(hdc
, CreateFontIndirectW( &ncm
.lfMenuFont
)));
572 GetTextExtentPoint32W(hdc
, o3tl::toW(pMyItem
->text
.getStr()),
573 pMyItem
->text
.getLength(), &size
);
575 lpmis
->itemWidth
= size
.cx
+ 4 + GetSystemMetrics( SM_CXSMICON
);
576 lpmis
->itemHeight
= std::max
<int>(size
.cy
, GetSystemMetrics( SM_CYSMICON
));
577 lpmis
->itemHeight
+= 4;
579 DeleteObject( SelectObject(hdc
, hfntOld
) );
580 ReleaseDC(hwnd
, hdc
);
583 void OnDrawItem(HWND
/*hwnd*/, LPDRAWITEMSTRUCT lpdis
)
585 MYITEM
*pMyItem
= reinterpret_cast<MYITEM
*>(lpdis
->itemData
);
586 COLORREF clrPrevText
, clrPrevBkgnd
;
590 bool fSelected
= lpdis
->itemState
& ODS_SELECTED
;
591 bool fDisabled
= lpdis
->itemState
& (ODS_DISABLED
| ODS_GRAYED
);
593 // Set the appropriate foreground and background colors.
595 RECT aRect
= lpdis
->rcItem
;
597 clrPrevBkgnd
= SetBkColor( lpdis
->hDC
, GetSysColor(COLOR_MENU
) );
600 clrPrevText
= SetTextColor( lpdis
->hDC
, GetSysColor( COLOR_GRAYTEXT
) );
602 clrPrevText
= SetTextColor( lpdis
->hDC
, GetSysColor( fSelected
? COLOR_HIGHLIGHTTEXT
: COLOR_MENUTEXT
) );
605 clrPrevBkgnd
= SetBkColor( lpdis
->hDC
, GetSysColor(COLOR_HIGHLIGHT
) );
607 clrPrevBkgnd
= SetBkColor( lpdis
->hDC
, GetSysColor(COLOR_MENU
) );
609 hbrOld
= static_cast<HBRUSH
>(SelectObject( lpdis
->hDC
, CreateSolidBrush( GetBkColor( lpdis
->hDC
) ) ));
612 PatBlt(lpdis
->hDC
, aRect
.left
, aRect
.top
, aRect
.right
-aRect
.left
, aRect
.bottom
-aRect
.top
, PATCOPY
);
614 int height
= aRect
.bottom
-aRect
.top
;
619 int cx
= GetSystemMetrics( SM_CXSMICON
);
620 int cy
= GetSystemMetrics( SM_CYSMICON
);
621 HICON
hIcon( nullptr );
622 HMODULE
hModule( GetModuleHandleW( nullptr ) );
624 if ( pMyItem
->module
.getLength() > 0 )
626 LPCWSTR pModuleName
= o3tl::toW( pMyItem
->module
.getStr() );
627 hModule
= GetModuleHandleW( pModuleName
);
628 if ( hModule
== nullptr )
630 hModule
= LoadLibraryW(pModuleName
);
634 hIcon
= static_cast<HICON
>(LoadImageW( hModule
, MAKEINTRESOURCEW( pMyItem
->iconId
),
636 LR_DEFAULTCOLOR
| LR_SHARED
));
639 HBRUSH hbrIcon
= CreateSolidBrush( GetSysColor( COLOR_GRAYTEXT
) );
641 DrawStateW( lpdis
->hDC
, hbrIcon
, nullptr, reinterpret_cast<LPARAM
>(hIcon
), WPARAM(0), x
, y
+(height
-cy
)/2, 0, 0, DST_ICON
| (fDisabled
? (fSelected
? DSS_MONO
: DSS_DISABLED
) : DSS_NORMAL
) );
643 DeleteObject( hbrIcon
);
645 x
+= cx
+ 4; // space for icon
648 NONCLIENTMETRICSW ncm
= {};
649 ncm
.cbSize
= sizeof(ncm
);
651 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
, 0, &ncm
, 0);
653 // Print default menu entry with bold font
654 if ( lpdis
->itemState
& ODS_DEFAULT
)
655 ncm
.lfMenuFont
.lfWeight
= FW_BOLD
;
657 hfntOld
= static_cast<HFONT
>(SelectObject(lpdis
->hDC
, CreateFontIndirectW( &ncm
.lfMenuFont
)));
661 GetTextExtentPointW( lpdis
->hDC
, o3tl::toW(pMyItem
->text
.getStr()), pMyItem
->text
.getLength(), &size
);
663 DrawStateW( lpdis
->hDC
, nullptr, nullptr, reinterpret_cast<LPARAM
>(pMyItem
->text
.getStr()), WPARAM(0), aRect
.left
, aRect
.top
+ (height
- size
.cy
)/2, 0, 0, DST_TEXT
| (fDisabled
&& !fSelected
? DSS_DISABLED
: DSS_NORMAL
) );
665 // Restore the original font and colors.
666 DeleteObject( SelectObject( lpdis
->hDC
, hbrOld
) );
667 DeleteObject( SelectObject( lpdis
->hDC
, hfntOld
) );
668 SetTextColor(lpdis
->hDC
, clrPrevText
);
669 SetBkColor(lpdis
->hDC
, clrPrevBkgnd
);
673 // code from setup2 project
676 static void SHFree_( void *pv
)
679 if( NOERROR
== SHGetMalloc(&pMalloc
) )
686 #define ALLOC(type, n) static_cast<type *>(HeapAlloc(GetProcessHeap(), 0, sizeof(type) * n ))
687 #define FREE(p) HeapFree(GetProcessHeap(), 0, p)
689 static OUString
SHGetSpecialFolder( int nFolderID
)
693 HRESULT hHdl
= SHGetSpecialFolderLocation( nullptr, nFolderID
, &pidl
);
696 if( hHdl
== NOERROR
)
699 lpFolderA
= ALLOC( WCHAR
, 16000 );
701 SHGetPathFromIDListW( pidl
, lpFolderA
);
702 aFolder
= o3tl::toU( lpFolderA
);
710 OUString
ShutdownIcon::GetAutostartFolderNameW32()
712 return SHGetSpecialFolder(CSIDL_STARTUP
);
715 static HRESULT WINAPI
SHCoCreateInstance( LPVOID lpszReserved
, REFCLSID clsid
, LPUNKNOWN pUnkUnknown
, REFIID iid
, LPVOID
*ppv
)
717 HRESULT hResult
= E_NOTIMPL
;
718 HMODULE hModShell
= GetModuleHandleW( L
"SHELL32" );
720 if ( hModShell
!= nullptr )
722 typedef HRESULT (WINAPI
*SHCoCreateInstance_PROC
)( LPVOID lpszReserved
, REFCLSID clsid
, LPUNKNOWN pUnkUnknown
, REFIID iid
, LPVOID
*ppv
);
724 SHCoCreateInstance_PROC lpfnSHCoCreateInstance
= reinterpret_cast<SHCoCreateInstance_PROC
>(GetProcAddress( hModShell
, MAKEINTRESOURCEA(102) ));
726 if ( lpfnSHCoCreateInstance
)
727 hResult
= lpfnSHCoCreateInstance( lpszReserved
, clsid
, pUnkUnknown
, iid
, ppv
);
732 static bool CreateShortcut( const OUString
& rAbsObject
, const OUString
& rAbsObjectPath
,
733 const OUString
& rAbsShortcut
, const OUString
& rDescription
, const OUString
& rParameter
)
737 CLSID clsid_ShellLink
= CLSID_ShellLink
;
738 CLSID clsid_IShellLink
= IID_IShellLinkW
;
740 hres
= CoCreateInstance( clsid_ShellLink
, nullptr, CLSCTX_INPROC_SERVER
,
741 clsid_IShellLink
, reinterpret_cast<void**>(&psl
) );
743 hres
= SHCoCreateInstance( nullptr, clsid_ShellLink
, nullptr, clsid_IShellLink
, reinterpret_cast<void**>(&psl
) );
745 if( SUCCEEDED(hres
) )
748 psl
->SetPath( o3tl::toW(rAbsObject
.getStr()) );
749 psl
->SetWorkingDirectory( o3tl::toW(rAbsObjectPath
.getStr()) );
750 psl
->SetDescription( o3tl::toW(rDescription
.getStr()) );
751 if( rParameter
.getLength() )
752 psl
->SetArguments( o3tl::toW(rParameter
.getStr()) );
754 CLSID clsid_IPersistFile
= IID_IPersistFile
;
755 hres
= psl
->QueryInterface( clsid_IPersistFile
, reinterpret_cast<void**>(&ppf
) );
757 if( SUCCEEDED(hres
) )
759 hres
= ppf
->Save( o3tl::toW(rAbsShortcut
.getStr()), TRUE
);
770 static bool FileExistsW( LPCWSTR lpPath
)
772 bool bExists
= false;
773 WIN32_FIND_DATAW aFindData
;
775 HANDLE hFind
= FindFirstFileW( lpPath
, &aFindData
);
777 if ( INVALID_HANDLE_VALUE
!= hFind
)
786 bool ShutdownIcon::IsQuickstarterInstalled()
788 wchar_t aPath
[_MAX_PATH
];
789 GetModuleFileNameW( nullptr, aPath
, _MAX_PATH
-1);
791 OUString
aOfficepath( o3tl::toU(aPath
) );
792 int i
= aOfficepath
.lastIndexOf('\\');
794 aOfficepath
= aOfficepath
.copy(0, i
);
796 OUString
quickstartExe(aOfficepath
+ "\\quickstart.exe");
798 return FileExistsW( o3tl::toW(quickstartExe
.getStr()) );
801 void ShutdownIcon::EnableAutostartW32( const OUString
&aShortcut
)
803 wchar_t aPath
[_MAX_PATH
];
804 GetModuleFileNameW( nullptr, aPath
, _MAX_PATH
-1);
806 OUString
aOfficepath( o3tl::toU(aPath
) );
807 int i
= aOfficepath
.lastIndexOf('\\');
809 aOfficepath
= aOfficepath
.copy(0, i
);
811 OUString
quickstartExe(aOfficepath
+ "\\quickstart.exe");
813 CreateShortcut( quickstartExe
, aOfficepath
, aShortcut
, OUString(), OUString() );
817 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */