| shutdowniconunx.cxx (cdf0e10c) | shutdowniconunx.cxx (2ad018be) |
|---|---|
| 1 2#ifdef ENABLE_QUICKSTART_APPLET 3 4#include <unotools/moduleoptions.hxx> | 1 2#ifdef ENABLE_QUICKSTART_APPLET 3 4#include <unotools/moduleoptions.hxx> |
| 5 | |
| 6#include <unotools/dynamicmenuoptions.hxx> 7 8#include <gtk/gtk.h> 9#include <glib.h> | 5#include <unotools/dynamicmenuoptions.hxx> 6 7#include <gtk/gtk.h> 8#include <glib.h> |
| 10#include <eggtray/eggtrayicon.h> | |
| 11#include <vos/mutex.hxx> 12#include <vcl/bitmapex.hxx> 13#include <vcl/bmpacc.hxx> 14#include <sfx2/app.hxx> 15#ifndef _SFX_APP_HRC 16#include "app.hrc" 17#endif 18#ifndef __SHUTDOWNICON_HXX__ 19#define USE_APP_SHORTCUTS 20#include "shutdownicon.hxx" 21#endif 22 23// Cut/paste from vcl/inc/svids.hrc | 9#include <vos/mutex.hxx> 10#include <vcl/bitmapex.hxx> 11#include <vcl/bmpacc.hxx> 12#include <sfx2/app.hxx> 13#ifndef _SFX_APP_HRC 14#include "app.hrc" 15#endif 16#ifndef __SHUTDOWNICON_HXX__ 17#define USE_APP_SHORTCUTS 18#include "shutdownicon.hxx" 19#endif 20 21// Cut/paste from vcl/inc/svids.hrc |
| 22#define SV_ICON_LARGE_START 24000 |
|
| 24#define SV_ICON_SMALL_START 25000 25 26#define SV_ICON_ID_OFFICE 1 27#define SV_ICON_ID_TEXT 2 28#define SV_ICON_ID_SPREADSHEET 4 29#define SV_ICON_ID_DRAWING 6 30#define SV_ICON_ID_PRESENTATION 8 31#define SV_ICON_ID_DATABASE 14 32#define SV_ICON_ID_FORMULA 15 33#define SV_ICON_ID_TEMPLATE 16 34 35using namespace ::rtl; 36using namespace ::osl; 37 38static ResMgr *pVCLResMgr; | 23#define SV_ICON_SMALL_START 25000 24 25#define SV_ICON_ID_OFFICE 1 26#define SV_ICON_ID_TEXT 2 27#define SV_ICON_ID_SPREADSHEET 4 28#define SV_ICON_ID_DRAWING 6 29#define SV_ICON_ID_PRESENTATION 8 30#define SV_ICON_ID_DATABASE 14 31#define SV_ICON_ID_FORMULA 15 32#define SV_ICON_ID_TEMPLATE 16 33 34using namespace ::rtl; 35using namespace ::osl; 36 37static ResMgr *pVCLResMgr; |
| 39static EggTrayIcon *pTrayIcon; | 38static GtkStatusIcon *pTrayIcon; |
| 40static GtkWidget *pExitMenuItem = NULL; 41static GtkWidget *pOpenMenuItem = NULL; | 39static GtkWidget *pExitMenuItem = NULL; 40static GtkWidget *pOpenMenuItem = NULL; |
| 41static GtkWidget *pDisableMenuItem = NULL; |
|
| 42 43static void open_url_cb( GtkWidget *, gpointer data ) 44{ 45 ShutdownIcon::OpenURL( *(OUString *)data, 46 OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) ); 47} 48 49static void open_file_cb( GtkWidget * ) --- 11 unchanged lines hidden (view full) --- 61static void systray_disable_cb() 62{ 63 ShutdownIcon::SetAutostart( false ); 64 ShutdownIcon::terminateDesktop(); 65} 66 67static void exit_quickstarter_cb( GtkWidget * ) 68{ | 42 43static void open_url_cb( GtkWidget *, gpointer data ) 44{ 45 ShutdownIcon::OpenURL( *(OUString *)data, 46 OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ) ); 47} 48 49static void open_file_cb( GtkWidget * ) --- 11 unchanged lines hidden (view full) --- 61static void systray_disable_cb() 62{ 63 ShutdownIcon::SetAutostart( false ); 64 ShutdownIcon::terminateDesktop(); 65} 66 67static void exit_quickstarter_cb( GtkWidget * ) 68{ |
| 69 egg_tray_icon_cancel_message (pTrayIcon, 1 ); | |
| 70 ShutdownIcon::getInstance()->terminateDesktop(); 71 plugin_shutdown_sys_tray(); 72} 73 74static void menu_deactivate_cb( GtkWidget *pMenu ) 75{ 76 gtk_menu_popdown( GTK_MENU( pMenu ) ); 77} 78 79static GdkPixbuf * ResIdToPixbuf( sal_uInt16 nResId ) 80{ | 69 ShutdownIcon::getInstance()->terminateDesktop(); 70 plugin_shutdown_sys_tray(); 71} 72 73static void menu_deactivate_cb( GtkWidget *pMenu ) 74{ 75 gtk_menu_popdown( GTK_MENU( pMenu ) ); 76} 77 78static GdkPixbuf * ResIdToPixbuf( sal_uInt16 nResId ) 79{ |
| 81 ResId aResId( SV_ICON_SMALL_START + nResId, *pVCLResMgr ); | 80 ResId aResId( nResId, *pVCLResMgr ); |
| 82 BitmapEx aIcon( aResId ); 83 Bitmap pInSalBitmap = aIcon.GetBitmap(); 84 AlphaMask pInSalAlpha = aIcon.GetAlpha(); 85 86 BitmapReadAccess* pSalBitmap = pInSalBitmap.AcquireReadAccess(); 87 BitmapReadAccess* pSalAlpha = pInSalAlpha.AcquireReadAccess(); 88 89 g_return_val_if_fail( pSalBitmap != NULL, NULL ); --- 57 unchanged lines hidden (view full) --- 147 aLabel = OUStringToOString (*pOverrideLabel, RTL_TEXTENCODING_UTF8); 148 else 149 { 150 ShutdownIcon *pShutdownIcon = ShutdownIcon::getInstance(); 151 aLabel = OUStringToOString (pShutdownIcon->GetUrlDescription( *pURL ), 152 RTL_TEXTENCODING_UTF8); 153 } 154 | 81 BitmapEx aIcon( aResId ); 82 Bitmap pInSalBitmap = aIcon.GetBitmap(); 83 AlphaMask pInSalAlpha = aIcon.GetAlpha(); 84 85 BitmapReadAccess* pSalBitmap = pInSalBitmap.AcquireReadAccess(); 86 BitmapReadAccess* pSalAlpha = pInSalAlpha.AcquireReadAccess(); 87 88 g_return_val_if_fail( pSalBitmap != NULL, NULL ); --- 57 unchanged lines hidden (view full) --- 146 aLabel = OUStringToOString (*pOverrideLabel, RTL_TEXTENCODING_UTF8); 147 else 148 { 149 ShutdownIcon *pShutdownIcon = ShutdownIcon::getInstance(); 150 aLabel = OUStringToOString (pShutdownIcon->GetUrlDescription( *pURL ), 151 RTL_TEXTENCODING_UTF8); 152 } 153 |
| 155 GdkPixbuf *pPixbuf= ResIdToPixbuf( nResId ); 156 GtkWidget *pImage = gtk_image_new_from_pixbuf( pPixbuf ); 157 g_object_unref( G_OBJECT( pPixbuf ) ); | 154 GdkPixbuf *pPixbuf= ResIdToPixbuf( SV_ICON_SMALL_START + nResId ); 155 GtkWidget *pImage = gtk_image_new_from_pixbuf( pPixbuf ); 156 g_object_unref( G_OBJECT( pPixbuf ) ); |
| 158 159 GtkWidget *pMenuItem = gtk_image_menu_item_new_with_label( aLabel ); 160 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM( pMenuItem ), pImage ); 161 g_signal_connect_data( pMenuItem, "activate", pFnCallback, pURL, 162 oustring_delete, GConnectFlags(0)); 163 164 gtk_menu_shell_append( pMenuShell, pMenuItem ); 165} --- 91 unchanged lines hidden (view full) --- 257 pMenuItem = gtk_separator_menu_item_new(); 258 gtk_menu_shell_append( pMenuShell, pMenuItem ); 259 260 pOpenMenuItem = add_image_menu_item 261 (pMenuShell, GTK_STOCK_OPEN, 262 pShutdownIcon->GetResString( STR_QUICKSTART_FILEOPEN ), 263 G_CALLBACK( open_file_cb )); 264 | 157 158 GtkWidget *pMenuItem = gtk_image_menu_item_new_with_label( aLabel ); 159 gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM( pMenuItem ), pImage ); 160 g_signal_connect_data( pMenuItem, "activate", pFnCallback, pURL, 161 oustring_delete, GConnectFlags(0)); 162 163 gtk_menu_shell_append( pMenuShell, pMenuItem ); 164} --- 91 unchanged lines hidden (view full) --- 256 pMenuItem = gtk_separator_menu_item_new(); 257 gtk_menu_shell_append( pMenuShell, pMenuItem ); 258 259 pOpenMenuItem = add_image_menu_item 260 (pMenuShell, GTK_STOCK_OPEN, 261 pShutdownIcon->GetResString( STR_QUICKSTART_FILEOPEN ), 262 G_CALLBACK( open_file_cb )); 263 |
| 264 |
|
| 265 pMenuItem = gtk_separator_menu_item_new(); 266 gtk_menu_shell_append( pMenuShell, pMenuItem ); 267 | 265 pMenuItem = gtk_separator_menu_item_new(); 266 gtk_menu_shell_append( pMenuShell, pMenuItem ); 267 |
| 268 (void) add_image_menu_item | 268 pDisableMenuItem = add_image_menu_item |
| 269 ( pMenuShell, GTK_STOCK_CLOSE, 270 pShutdownIcon->GetResString( STR_QUICKSTART_PRELAUNCH_UNX ), 271 G_CALLBACK( systray_disable_cb ) ); 272 273 pMenuItem = gtk_separator_menu_item_new(); 274 gtk_menu_shell_append( pMenuShell, pMenuItem ); 275 276 pExitMenuItem = add_image_menu_item --- 7 unchanged lines hidden (view full) --- 284static void refresh_menu( GtkWidget *pMenu ) 285{ 286 if (!pExitMenuItem) 287 populate_menu( pMenu ); 288 289 bool bModal = ShutdownIcon::bModalMode; 290 gtk_widget_set_sensitive( pExitMenuItem, !bModal); 291 gtk_widget_set_sensitive( pOpenMenuItem, !bModal); | 269 ( pMenuShell, GTK_STOCK_CLOSE, 270 pShutdownIcon->GetResString( STR_QUICKSTART_PRELAUNCH_UNX ), 271 G_CALLBACK( systray_disable_cb ) ); 272 273 pMenuItem = gtk_separator_menu_item_new(); 274 gtk_menu_shell_append( pMenuShell, pMenuItem ); 275 276 pExitMenuItem = add_image_menu_item --- 7 unchanged lines hidden (view full) --- 284static void refresh_menu( GtkWidget *pMenu ) 285{ 286 if (!pExitMenuItem) 287 populate_menu( pMenu ); 288 289 bool bModal = ShutdownIcon::bModalMode; 290 gtk_widget_set_sensitive( pExitMenuItem, !bModal); 291 gtk_widget_set_sensitive( pOpenMenuItem, !bModal); |
| 292 gtk_widget_set_sensitive( pDisableMenuItem, !bModal); |
|
| 292} 293 | 293} 294 |
| 294extern "C" { 295static void 296layout_menu( GtkMenu *menu, 297 gint *x, gint *y, gboolean *push_in, 298 gpointer ) 299{ 300 GtkRequisition req; 301 GtkWidget *ebox = GTK_BIN( pTrayIcon )->child; | |
| 302 | 295 |
| 303 gtk_widget_size_request( GTK_WIDGET( menu ), &req ); 304 gdk_window_get_origin( ebox->window, x, y ); 305 306 (*x) += ebox->allocation.x; 307 (*y) += ebox->allocation.y; 308 309 if (*y >= gdk_screen_get_height (gtk_widget_get_screen (ebox)) / 2) 310 (*y) -= req.height; 311 else 312 (*y) += ebox->allocation.height; 313 314 *push_in = sal_True; 315} 316} 317 | |
| 318static gboolean display_menu_cb( GtkWidget *, 319 GdkEventButton *event, GtkWidget *pMenu ) 320{ 321 if (event->button == 2) 322 return sal_False; 323 | 296static gboolean display_menu_cb( GtkWidget *, 297 GdkEventButton *event, GtkWidget *pMenu ) 298{ 299 if (event->button == 2) 300 return sal_False; 301 |
| 324#ifdef TEMPLATE_DIALOG_MORE_POLISHED 325 if (event->button == 1 && 326 event->type == GDK_2BUTTON_PRESS) 327 { 328 open_template_cb( NULL ); 329 return sal_True; 330 } 331 if (event->button == 3) 332 { 333 ... as below ... 334#endif 335 | |
| 336 refresh_menu( pMenu ); 337 338 gtk_menu_popup( GTK_MENU( pMenu ), NULL, NULL, | 302 refresh_menu( pMenu ); 303 304 gtk_menu_popup( GTK_MENU( pMenu ), NULL, NULL, |
| 339 layout_menu, NULL, 0, event->time ); | 305 gtk_status_icon_position_menu, 306 pTrayIcon, 0, event->time ); |
| 340 341 return sal_True; 342} 343 | 307 308 return sal_True; 309} 310 |
| 344extern "C" { 345 static gboolean 346 show_at_idle( gpointer ) 347 { 348 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 349 gtk_widget_show_all( GTK_WIDGET( pTrayIcon ) ); 350 return sal_False; 351 } 352} 353 | |
| 354void SAL_DLLPUBLIC_EXPORT plugin_init_sys_tray() 355{ 356 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 357 358 if( !g_type_from_name( "GdkDisplay" ) ) 359 return; 360 | 311void SAL_DLLPUBLIC_EXPORT plugin_init_sys_tray() 312{ 313 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 314 315 if( !g_type_from_name( "GdkDisplay" ) ) 316 return; 317 |
| 318 ShutdownIcon *pShutdownIcon = ShutdownIcon::getInstance(); 319 if ( !pShutdownIcon ) 320 return; 321 322 pTrayIcon = gtk_status_icon_new(); 323 pVCLResMgr = CREATEVERSIONRESMGR( vcl ); 324 325 if ( !pTrayIcon || !pVCLResMgr ) 326 return; 327 328 // disable shutdown 329 pShutdownIcon->SetVeto( true ); 330 pShutdownIcon->addTerminateListener(); 331 |
|
| 361 OString aLabel; | 332 OString aLabel; |
| 362 ShutdownIcon *pShutdownIcon = ShutdownIcon::getInstance(); | |
| 363 364 aLabel = rtl::OUStringToOString ( 365 pShutdownIcon->GetResString( STR_QUICKSTART_TIP ), 366 RTL_TEXTENCODING_UTF8 ); 367 | 333 334 aLabel = rtl::OUStringToOString ( 335 pShutdownIcon->GetResString( STR_QUICKSTART_TIP ), 336 RTL_TEXTENCODING_UTF8 ); 337 |
| 368 pTrayIcon = egg_tray_icon_new( aLabel ); 369 370 GtkWidget *pParent = gtk_event_box_new(); 371 GtkTooltips *pTooltips = gtk_tooltips_new(); 372 gtk_tooltips_set_tip( GTK_TOOLTIPS( pTooltips ), pParent, aLabel, NULL ); 373 374 GtkWidget *pIconImage = gtk_image_new(); 375 gtk_container_add( GTK_CONTAINER( pParent ), pIconImage ); 376 377 pVCLResMgr = CREATEVERSIONRESMGR( vcl ); 378 379 GdkPixbuf *pPixbuf = ResIdToPixbuf( SV_ICON_ID_OFFICE ); 380 gtk_image_set_from_pixbuf( GTK_IMAGE( pIconImage ), pPixbuf ); | 338 GdkPixbuf *pPixbuf = ResIdToPixbuf( SV_ICON_LARGE_START + SV_ICON_ID_OFFICE ); 339 g_object_set( G_OBJECT( pTrayIcon ), 340 "pixbuf", pPixbuf, 341 "title", aLabel.getStr(), 342 NULL ); |
| 381 g_object_unref( pPixbuf ); 382 | 343 g_object_unref( pPixbuf ); 344 |
| 345 gtk_status_icon_set_tooltip_text( pTrayIcon, aLabel.getStr() ); 346 |
|
| 383 GtkWidget *pMenu = gtk_menu_new(); | 347 GtkWidget *pMenu = gtk_menu_new(); |
| 384 g_signal_connect (pMenu, "deactivate", 385 G_CALLBACK (menu_deactivate_cb), NULL); 386 g_signal_connect( pParent, "button_press_event", 387 G_CALLBACK( display_menu_cb ), pMenu ); 388 gtk_container_add( GTK_CONTAINER( pTrayIcon ), pParent ); | |
| 389 | 348 |
| 390 // Show at idle to avoid artefacts at startup 391 g_idle_add (show_at_idle, (gpointer) pTrayIcon); | 349 g_signal_connect( pTrayIcon, "button-press-event", 350 G_CALLBACK( display_menu_cb ), pMenu ); |
| 392 | 351 |
| 393 // disable shutdown 394 pShutdownIcon->SetVeto( true ); 395 pShutdownIcon->addTerminateListener(); | 352 g_signal_connect( pMenu, "deactivate", 353 G_CALLBACK (menu_deactivate_cb), NULL); |
| 396} 397 398void SAL_DLLPUBLIC_EXPORT plugin_shutdown_sys_tray() 399{ 400 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 401 if( !pTrayIcon ) 402 return; | 354} 355 356void SAL_DLLPUBLIC_EXPORT plugin_shutdown_sys_tray() 357{ 358 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 359 if( !pTrayIcon ) 360 return; |
| 403 gtk_widget_destroy( GTK_WIDGET( pTrayIcon ) ); | 361 g_object_unref( pTrayIcon ); |
| 404 pTrayIcon = NULL; 405 pExitMenuItem = NULL; 406 pOpenMenuItem = NULL; | 362 pTrayIcon = NULL; 363 pExitMenuItem = NULL; 364 pOpenMenuItem = NULL; |
| 365 pDisableMenuItem = NULL; |
|
| 407} 408 409#endif // ENABLE_QUICKSTART_APPLET | 366} 367 368#endif // ENABLE_QUICKSTART_APPLET |