1d119d52dSAndrew Rist /**************************************************************
2d119d52dSAndrew Rist  *
3d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5d119d52dSAndrew Rist  * distributed with this work for additional information
6d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10d119d52dSAndrew Rist  *
11d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12d119d52dSAndrew Rist  *
13d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17d119d52dSAndrew Rist  * specific language governing permissions and limitations
18d119d52dSAndrew Rist  * under the License.
19d119d52dSAndrew Rist  *
20d119d52dSAndrew Rist  *************************************************************/
21d119d52dSAndrew Rist 
22cdf0e10cSrcweir 
23cdf0e10cSrcweir #ifdef ENABLE_QUICKSTART_APPLET
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
26cdf0e10cSrcweir #include <unotools/dynamicmenuoptions.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <gtk/gtk.h>
29cdf0e10cSrcweir #include <glib.h>
30cdf0e10cSrcweir #include <vos/mutex.hxx>
31cdf0e10cSrcweir #include <vcl/bitmapex.hxx>
32cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
33cdf0e10cSrcweir #include <sfx2/app.hxx>
34cdf0e10cSrcweir #ifndef _SFX_APP_HRC
35cdf0e10cSrcweir #include "app.hrc"
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir #ifndef __SHUTDOWNICON_HXX__
38cdf0e10cSrcweir #define USE_APP_SHORTCUTS
39cdf0e10cSrcweir #include "shutdownicon.hxx"
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir 
42cdf0e10cSrcweir // Cut/paste from vcl/inc/svids.hrc
432ad018beSPedro Giffuni #define SV_ICON_LARGE_START                 24000
44cdf0e10cSrcweir #define SV_ICON_SMALL_START                 25000
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #define SV_ICON_ID_OFFICE                       1
47cdf0e10cSrcweir #define SV_ICON_ID_TEXT                         2
48cdf0e10cSrcweir #define SV_ICON_ID_SPREADSHEET                  4
49cdf0e10cSrcweir #define SV_ICON_ID_DRAWING                      6
50cdf0e10cSrcweir #define SV_ICON_ID_PRESENTATION                 8
51cdf0e10cSrcweir #define SV_ICON_ID_DATABASE                    14
52cdf0e10cSrcweir #define SV_ICON_ID_FORMULA                     15
53cdf0e10cSrcweir #define SV_ICON_ID_TEMPLATE                    16
54cdf0e10cSrcweir 
55cdf0e10cSrcweir using namespace ::rtl;
56cdf0e10cSrcweir using namespace ::osl;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir static ResMgr *pVCLResMgr;
592ad018beSPedro Giffuni static GtkStatusIcon *pTrayIcon;
60cdf0e10cSrcweir static GtkWidget *pExitMenuItem = NULL;
61cdf0e10cSrcweir static GtkWidget *pOpenMenuItem = NULL;
622ad018beSPedro Giffuni static GtkWidget *pDisableMenuItem = NULL;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir static void open_url_cb( GtkWidget *, gpointer data )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	ShutdownIcon::OpenURL( *(OUString *)data,
67cdf0e10cSrcweir 						   OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) );
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir static void open_file_cb( GtkWidget * )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	if ( !ShutdownIcon::bModalMode )
73cdf0e10cSrcweir 		ShutdownIcon::FileOpen();
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir static void open_template_cb( GtkWidget * )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	if ( !ShutdownIcon::bModalMode )
79cdf0e10cSrcweir 		ShutdownIcon::FromTemplate();
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir static void systray_disable_cb()
83cdf0e10cSrcweir {
84cdf0e10cSrcweir 	ShutdownIcon::SetAutostart( false );
85cdf0e10cSrcweir 	ShutdownIcon::terminateDesktop();
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir static void exit_quickstarter_cb( GtkWidget * )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir 	plugin_shutdown_sys_tray();
91*143238c7SAriel Constenla-Haile     ShutdownIcon::getInstance()->terminateDesktop();
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir static void menu_deactivate_cb( GtkWidget *pMenu )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	gtk_menu_popdown( GTK_MENU( pMenu ) );
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir static GdkPixbuf * ResIdToPixbuf( sal_uInt16 nResId )
100cdf0e10cSrcweir {
1012ad018beSPedro Giffuni 	ResId aResId( nResId, *pVCLResMgr );
102cdf0e10cSrcweir 	BitmapEx aIcon( aResId );
103cdf0e10cSrcweir 	Bitmap pInSalBitmap = aIcon.GetBitmap();
104cdf0e10cSrcweir 	AlphaMask pInSalAlpha = aIcon.GetAlpha();
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	BitmapReadAccess* pSalBitmap = pInSalBitmap.AcquireReadAccess();
107cdf0e10cSrcweir 	BitmapReadAccess* pSalAlpha = pInSalAlpha.AcquireReadAccess();
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	g_return_val_if_fail( pSalBitmap != NULL, NULL );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	Size aSize( pSalBitmap->Width(), pSalBitmap->Height() );
112cdf0e10cSrcweir 	g_return_val_if_fail( Size( pSalAlpha->Width(), pSalAlpha->Height() ) == aSize, NULL );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 	int nX, nY;
115cdf0e10cSrcweir 	guchar *pPixbufData = ( guchar * )g_malloc( 4 * aSize.Width() * aSize.Height() );
116cdf0e10cSrcweir 	guchar *pDestData = pPixbufData;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	for( nY = 0; nY < pSalBitmap->Height(); nY++ )
119cdf0e10cSrcweir 	{
120cdf0e10cSrcweir 		for( nX = 0; nX < pSalBitmap->Width(); nX++ )
121cdf0e10cSrcweir 		{
122cdf0e10cSrcweir 			BitmapColor aPix;
123cdf0e10cSrcweir 			aPix = pSalBitmap->GetPixel( nY, nX );
124cdf0e10cSrcweir 			pDestData[0] = aPix.GetRed();
125cdf0e10cSrcweir 			pDestData[1] = aPix.GetGreen();
126cdf0e10cSrcweir 			pDestData[2] = aPix.GetBlue();
127cdf0e10cSrcweir 			if (pSalAlpha)
128cdf0e10cSrcweir 			{
129cdf0e10cSrcweir 				aPix = pSalAlpha->GetPixel( nY, nX );
130cdf0e10cSrcweir 				pDestData[3] = 255 - aPix.GetIndex();
131cdf0e10cSrcweir 			}
132cdf0e10cSrcweir 			else
133cdf0e10cSrcweir 				pDestData[3] = 255;
134cdf0e10cSrcweir 			pDestData += 4;
135cdf0e10cSrcweir 		}
136cdf0e10cSrcweir 	}
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 	pInSalBitmap.ReleaseAccess( pSalBitmap );
139cdf0e10cSrcweir 	if( pSalAlpha )
140cdf0e10cSrcweir 		pInSalAlpha.ReleaseAccess( pSalAlpha );
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	return gdk_pixbuf_new_from_data( pPixbufData,
143cdf0e10cSrcweir 		GDK_COLORSPACE_RGB, sal_True, 8,
144cdf0e10cSrcweir 		aSize.Width(), aSize.Height(),
145cdf0e10cSrcweir 		aSize.Width() * 4,
146cdf0e10cSrcweir 		(GdkPixbufDestroyNotify) g_free,
147cdf0e10cSrcweir 		NULL );
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir extern "C" {
151cdf0e10cSrcweir static void oustring_delete (gpointer  data,
152cdf0e10cSrcweir 							 GClosure * /* closure */)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir 	OUString *pURL = (OUString *) data;
155cdf0e10cSrcweir 	delete pURL;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir static void add_item( GtkMenuShell *pMenuShell, const char *pAsciiURL,
160cdf0e10cSrcweir 					  OUString *pOverrideLabel,
161cdf0e10cSrcweir 					  sal_uInt16 nResId, GCallback pFnCallback )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir 	OUString *pURL = new OUString (OStringToOUString( pAsciiURL,
164cdf0e10cSrcweir 													  RTL_TEXTENCODING_UTF8 ));
165cdf0e10cSrcweir 	OString aLabel;
166cdf0e10cSrcweir 	if (pOverrideLabel)
167cdf0e10cSrcweir 		aLabel = OUStringToOString (*pOverrideLabel, RTL_TEXTENCODING_UTF8);
168cdf0e10cSrcweir 	else
169cdf0e10cSrcweir 	{
170cdf0e10cSrcweir 		ShutdownIcon *pShutdownIcon = ShutdownIcon::getInstance();
171cdf0e10cSrcweir 		aLabel = OUStringToOString (pShutdownIcon->GetUrlDescription( *pURL ),
172cdf0e10cSrcweir 									RTL_TEXTENCODING_UTF8);
173cdf0e10cSrcweir 	}
174cdf0e10cSrcweir 
1752ad018beSPedro Giffuni     GdkPixbuf *pPixbuf= ResIdToPixbuf( SV_ICON_SMALL_START + nResId );
1762ad018beSPedro Giffuni     GtkWidget *pImage = gtk_image_new_from_pixbuf( pPixbuf );
1772ad018beSPedro Giffuni     g_object_unref( G_OBJECT( pPixbuf ) );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 	GtkWidget *pMenuItem = gtk_image_menu_item_new_with_label( aLabel );
180cdf0e10cSrcweir 	gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM( pMenuItem ), pImage );
181cdf0e10cSrcweir 	g_signal_connect_data( pMenuItem, "activate", pFnCallback, pURL,
182cdf0e10cSrcweir 						   oustring_delete, GConnectFlags(0));
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	gtk_menu_shell_append( pMenuShell, pMenuItem );
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir // Unbelievably nasty
188cdf0e10cSrcweir using namespace ::com::sun::star::uno;
189cdf0e10cSrcweir using namespace ::com::sun::star::task;
190cdf0e10cSrcweir using namespace ::com::sun::star::lang;
191cdf0e10cSrcweir using namespace ::com::sun::star::beans;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir static void add_ugly_db_item( GtkMenuShell *pMenuShell, const char *pAsciiURL,
194cdf0e10cSrcweir 							  sal_uInt16 nResId, GCallback pFnCallback )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir     SvtDynamicMenuOptions aOpt;
197cdf0e10cSrcweir 	Sequence < Sequence < PropertyValue > > aMenu = aOpt.GetMenu( E_NEWMENU );
198cdf0e10cSrcweir 	for ( sal_Int32 n=0; n<aMenu.getLength(); n++ )
199cdf0e10cSrcweir     {
200cdf0e10cSrcweir         ::rtl::OUString aURL;
201cdf0e10cSrcweir 		::rtl::OUString aDescription;
202cdf0e10cSrcweir 		Sequence < PropertyValue >& aEntry = aMenu[n];
203cdf0e10cSrcweir 		for ( sal_Int32 m=0; m<aEntry.getLength(); m++ )
204cdf0e10cSrcweir 		{
205cdf0e10cSrcweir             if ( aEntry[m].Name.equalsAsciiL( "URL", 3 ) )
206cdf0e10cSrcweir                 aEntry[m].Value >>= aURL;
207cdf0e10cSrcweir             if ( aEntry[m].Name.equalsAsciiL( "Title", 5 ) )
208cdf0e10cSrcweir                 aEntry[m].Value >>= aDescription;
209cdf0e10cSrcweir 		}
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 		if ( aURL.equalsAscii( BASE_URL ) && aDescription.getLength() )
212cdf0e10cSrcweir 		{
213cdf0e10cSrcweir 			add_item (pMenuShell, pAsciiURL, &aDescription, nResId, pFnCallback);
214cdf0e10cSrcweir             break;
215cdf0e10cSrcweir 		}
216cdf0e10cSrcweir 	}
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir static GtkWidget *
220cdf0e10cSrcweir add_image_menu_item( GtkMenuShell *pMenuShell,
221cdf0e10cSrcweir 					 const gchar *stock_id,
222cdf0e10cSrcweir 					 rtl::OUString aLabel,
223cdf0e10cSrcweir 					 GCallback     activate_cb )
224cdf0e10cSrcweir {
225cdf0e10cSrcweir 	OString aUtfLabel = rtl::OUStringToOString (aLabel, RTL_TEXTENCODING_UTF8 );
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 	GtkWidget *pImage;
228cdf0e10cSrcweir 	pImage = gtk_image_new_from_stock( stock_id, GTK_ICON_SIZE_MENU );
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 	GtkWidget *pMenuItem;
231cdf0e10cSrcweir 	pMenuItem = gtk_image_menu_item_new_with_label( aUtfLabel );
232cdf0e10cSrcweir 	gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM( pMenuItem ), pImage );
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 	gtk_menu_shell_append( pMenuShell, pMenuItem );
235cdf0e10cSrcweir 	g_signal_connect( pMenuItem, "activate", activate_cb, NULL);
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 	return pMenuItem;
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir static void populate_menu( GtkWidget *pMenu )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir 	ShutdownIcon *pShutdownIcon = ShutdownIcon::getInstance();
243cdf0e10cSrcweir 	GtkMenuShell *pMenuShell = GTK_MENU_SHELL( pMenu );
244cdf0e10cSrcweir 	SvtModuleOptions aModuleOptions;
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 	if ( aModuleOptions.IsWriter() )
247cdf0e10cSrcweir 		add_item (pMenuShell, WRITER_URL, NULL,
248cdf0e10cSrcweir 				  SV_ICON_ID_TEXT, G_CALLBACK( open_url_cb ));
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 	if ( aModuleOptions.IsCalc() )
251cdf0e10cSrcweir 		add_item (pMenuShell, CALC_URL, NULL,
252cdf0e10cSrcweir 				  SV_ICON_ID_SPREADSHEET, G_CALLBACK( open_url_cb ));
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 	if ( aModuleOptions.IsImpress() )
255cdf0e10cSrcweir 		add_item (pMenuShell, IMPRESS_URL, NULL,
256cdf0e10cSrcweir 				  SV_ICON_ID_PRESENTATION, G_CALLBACK( open_url_cb ));
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 	if ( aModuleOptions.IsDraw() )
259cdf0e10cSrcweir 		add_item (pMenuShell, DRAW_URL, NULL,
260cdf0e10cSrcweir 				  SV_ICON_ID_DRAWING, G_CALLBACK( open_url_cb ));
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     if ( aModuleOptions.IsDataBase() )
263cdf0e10cSrcweir 		add_ugly_db_item (pMenuShell, BASE_URL,
264cdf0e10cSrcweir 						  SV_ICON_ID_DATABASE, G_CALLBACK( open_url_cb ));
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 	if ( aModuleOptions.IsMath() )
267cdf0e10cSrcweir 		add_item (pMenuShell, MATH_URL, NULL,
268cdf0e10cSrcweir 				  SV_ICON_ID_FORMULA, G_CALLBACK( open_url_cb ));
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 	OUString aULabel = pShutdownIcon->GetResString( STR_QUICKSTART_FROMTEMPLATE );
271cdf0e10cSrcweir 	add_item (pMenuShell, "dummy", &aULabel,
272cdf0e10cSrcweir 			  SV_ICON_ID_TEMPLATE, G_CALLBACK( open_template_cb ));
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 	OString aLabel;
275cdf0e10cSrcweir 	GtkWidget *pMenuItem;
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 	pMenuItem = gtk_separator_menu_item_new();
278cdf0e10cSrcweir 	gtk_menu_shell_append( pMenuShell, pMenuItem );
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 	pOpenMenuItem = add_image_menu_item
281cdf0e10cSrcweir         (pMenuShell, GTK_STOCK_OPEN,
282cdf0e10cSrcweir 		 pShutdownIcon->GetResString( STR_QUICKSTART_FILEOPEN ),
283cdf0e10cSrcweir 		 G_CALLBACK( open_file_cb ));
284cdf0e10cSrcweir 
2852ad018beSPedro Giffuni 
286cdf0e10cSrcweir 	pMenuItem = gtk_separator_menu_item_new();
287cdf0e10cSrcweir 	gtk_menu_shell_append( pMenuShell, pMenuItem );
288cdf0e10cSrcweir 
2892ad018beSPedro Giffuni 	pDisableMenuItem = add_image_menu_item
290cdf0e10cSrcweir         ( pMenuShell, GTK_STOCK_CLOSE,
291cdf0e10cSrcweir 		  pShutdownIcon->GetResString( STR_QUICKSTART_PRELAUNCH_UNX ),
292cdf0e10cSrcweir 		  G_CALLBACK( systray_disable_cb ) );
293cdf0e10cSrcweir 
294cdf0e10cSrcweir 	pMenuItem = gtk_separator_menu_item_new();
295cdf0e10cSrcweir 	gtk_menu_shell_append( pMenuShell, pMenuItem );
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 	pExitMenuItem = add_image_menu_item
298cdf0e10cSrcweir         ( pMenuShell, GTK_STOCK_QUIT,
299cdf0e10cSrcweir 		  pShutdownIcon->GetResString( STR_QUICKSTART_EXIT ),
300cdf0e10cSrcweir 		  G_CALLBACK( exit_quickstarter_cb ) );
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 	gtk_widget_show_all( pMenu );
303cdf0e10cSrcweir }
304cdf0e10cSrcweir 
305cdf0e10cSrcweir static void refresh_menu( GtkWidget *pMenu )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir 	if (!pExitMenuItem)
308cdf0e10cSrcweir 		populate_menu( pMenu );
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 	bool bModal = ShutdownIcon::bModalMode;
311cdf0e10cSrcweir 	gtk_widget_set_sensitive( pExitMenuItem, !bModal);
312cdf0e10cSrcweir 	gtk_widget_set_sensitive( pOpenMenuItem, !bModal);
3132ad018beSPedro Giffuni     gtk_widget_set_sensitive( pDisableMenuItem, !bModal);
314cdf0e10cSrcweir }
315cdf0e10cSrcweir 
316595ead2bSAriel Constenla-Haile static void activate_cb( GtkStatusIcon *status_icon,
317595ead2bSAriel Constenla-Haile                          gpointer pMenu )
318595ead2bSAriel Constenla-Haile {
319595ead2bSAriel Constenla-Haile     refresh_menu( GTK_WIDGET( pMenu ) );
320595ead2bSAriel Constenla-Haile 
321595ead2bSAriel Constenla-Haile     gtk_menu_popup( GTK_MENU( pMenu ), NULL, NULL,
322595ead2bSAriel Constenla-Haile                     gtk_status_icon_position_menu,
323595ead2bSAriel Constenla-Haile                     status_icon, 0, gtk_get_current_event_time() );
324595ead2bSAriel Constenla-Haile }
325cdf0e10cSrcweir 
326595ead2bSAriel Constenla-Haile static void popup_menu_cb(GtkStatusIcon *status_icon,
327595ead2bSAriel Constenla-Haile                           guint button,
328595ead2bSAriel Constenla-Haile                           guint activate_time,
329595ead2bSAriel Constenla-Haile                           gpointer pMenu)
330cdf0e10cSrcweir {
331595ead2bSAriel Constenla-Haile 	if (button == 2)
332595ead2bSAriel Constenla-Haile 		return;
333cdf0e10cSrcweir 
334595ead2bSAriel Constenla-Haile 	refresh_menu( GTK_WIDGET( pMenu ) );
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 	gtk_menu_popup( GTK_MENU( pMenu ), NULL, NULL,
3372ad018beSPedro Giffuni                     gtk_status_icon_position_menu,
338595ead2bSAriel Constenla-Haile                     status_icon, button, activate_time );
339cdf0e10cSrcweir }
340cdf0e10cSrcweir 
341cdf0e10cSrcweir void SAL_DLLPUBLIC_EXPORT plugin_init_sys_tray()
342cdf0e10cSrcweir {
343cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 	if( !g_type_from_name( "GdkDisplay" ) )
346cdf0e10cSrcweir 		return;
347cdf0e10cSrcweir 
3482ad018beSPedro Giffuni     ShutdownIcon *pShutdownIcon = ShutdownIcon::getInstance();
3492ad018beSPedro Giffuni     if ( !pShutdownIcon )
3502ad018beSPedro Giffuni         return;
3512ad018beSPedro Giffuni 
3522ad018beSPedro Giffuni     pTrayIcon = gtk_status_icon_new();
3532ad018beSPedro Giffuni     pVCLResMgr = CREATEVERSIONRESMGR( vcl );
3542ad018beSPedro Giffuni 
3552ad018beSPedro Giffuni     if ( !pTrayIcon || !pVCLResMgr )
3562ad018beSPedro Giffuni         return;
3572ad018beSPedro Giffuni 
3582ad018beSPedro Giffuni     // disable shutdown
3592ad018beSPedro Giffuni     pShutdownIcon->SetVeto( true );
3602ad018beSPedro Giffuni     pShutdownIcon->addTerminateListener();
3612ad018beSPedro Giffuni 
362cdf0e10cSrcweir 	OString aLabel;
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 	aLabel = rtl::OUStringToOString (
365cdf0e10cSrcweir 			pShutdownIcon->GetResString( STR_QUICKSTART_TIP ),
366cdf0e10cSrcweir 			RTL_TEXTENCODING_UTF8 );
367cdf0e10cSrcweir 
3682ad018beSPedro Giffuni 	GdkPixbuf *pPixbuf = ResIdToPixbuf( SV_ICON_LARGE_START + SV_ICON_ID_OFFICE );
3692ad018beSPedro Giffuni     g_object_set( G_OBJECT( pTrayIcon ),
3702ad018beSPedro Giffuni                   "pixbuf", pPixbuf,
371595ead2bSAriel Constenla-Haile                   "title", aLabel.getStr(),/* Since 2.18 */
372595ead2bSAriel Constenla-Haile                   "tooltip-text", aLabel.getStr(), /* Since 2.16 */
3732ad018beSPedro Giffuni                   NULL );
3742ad018beSPedro Giffuni 	g_object_unref( pPixbuf );
375cdf0e10cSrcweir 
376595ead2bSAriel Constenla-Haile 	// gtk_status_icon_set_tooltip_text is available since 2.16
377595ead2bSAriel Constenla-Haile     // so use instead deprecated gtk_status_icon_set_tooltip
378595ead2bSAriel Constenla-Haile    gtk_status_icon_set_tooltip( pTrayIcon, aLabel.getStr() );
379cdf0e10cSrcweir 
3802ad018beSPedro Giffuni 	GtkWidget *pMenu = gtk_menu_new();
381cdf0e10cSrcweir 
382595ead2bSAriel Constenla-Haile 	// Signal "button-press-event" is available since 2.14
383595ead2bSAriel Constenla-Haile     // Use "activate" and "popup-menu" instead
384595ead2bSAriel Constenla-Haile     g_signal_connect( pTrayIcon, "activate",
385595ead2bSAriel Constenla-Haile                       G_CALLBACK( activate_cb ), pMenu );
386595ead2bSAriel Constenla-Haile     g_signal_connect( pTrayIcon, "popup-menu",
387595ead2bSAriel Constenla-Haile                       G_CALLBACK( popup_menu_cb ), pMenu );
388cdf0e10cSrcweir 
3892ad018beSPedro Giffuni     g_signal_connect( pMenu, "deactivate",
3902ad018beSPedro Giffuni                       G_CALLBACK (menu_deactivate_cb), NULL);
391cdf0e10cSrcweir }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir void SAL_DLLPUBLIC_EXPORT plugin_shutdown_sys_tray()
394cdf0e10cSrcweir {
395cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
396cdf0e10cSrcweir 	if( !pTrayIcon )
397cdf0e10cSrcweir 		return;
3982ad018beSPedro Giffuni 	g_object_unref( pTrayIcon );
399cdf0e10cSrcweir 	pTrayIcon = NULL;
400cdf0e10cSrcweir 	pExitMenuItem = NULL;
401cdf0e10cSrcweir 	pOpenMenuItem = NULL;
4022ad018beSPedro Giffuni     pDisableMenuItem = NULL;
403cdf0e10cSrcweir }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir #endif // ENABLE_QUICKSTART_APPLET
406