1 /* 2 * FXTrayIcon.h 3 * 4 * Copyright (c) 2008, Hendrik Rittich 5 * Copyright (C) 2006-2011 by Sander Jansen 6 * Copyright 2012 David Vachulka <david@konstrukce-cad.com> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 21 * MA 02110-1301, USA. 22 */ 23 24 #ifndef FX_TRAY_ICON_H 25 #define FX_TRAY_ICON_H 26 27 #include "fx.h" 28 #ifdef WIN32 29 #define WIN32_LEAN_AND_MEAN 30 #include <windows.h> 31 #include <shellapi.h> 32 #endif 33 34 namespace FX { 35 36 enum { 37 XEMBED_EMBEDDED_NOTIFY = 0, 38 XEMBED_MODALITY_ON = 10, 39 XEMBED_MODALITY_OFF = 11, 40 XEMBED_REQUEST_FOCUS = 3 41 }; 42 43 enum { 44 TRAY_MENU_ON_LEFT = 0x0001, 45 TRAY_MENU_ON_RIGHT = 0x0002, 46 TRAY_CMD_ON_LEFT = 0x0004, 47 TRAY_CMD_ON_RIGHT = 0x0008 48 }; 49 50 #ifdef WIN32 51 class FXTrayIcon : public FXTopWindow 52 { 53 FXDECLARE(FXTrayIcon) 54 public: 55 enum { 56 ID_POPTIMEOUT = FXTopWindow::ID_LAST, 57 ID_LAST 58 }; 59 FXTrayIcon(FXApp* app, const FXString& text, FXIcon* icon, 60 FXPopup* pup = NULL, FXObject* target = 0, FXSelector sel = 0, 61 FXuint opts = TRAY_MENU_ON_LEFT); 62 ~FXTrayIcon(); 63 64 void create(); 65 66 void mapToManager(); 67 68 long onEvent(FXObject*, FXSelector, void* ptr); 69 long onTimeout(FXObject*, FXSelector, void*); 70 setMenu(FXPopup * pup)71 void setMenu(FXPopup* pup) { m_popup = pup; } getMenu()72 FXPopup* getMenu() const { return m_popup; } 73 74 void setIcon(FXIcon* icon); getIcon()75 inline FXIcon* getIcon() const { return mIcon; } 76 77 void setText(const FXString& text); getText()78 inline const FXString& getText() const { return mTooltip; } 79 80 static HICON createMswIcon(FXIcon* icon); 81 getOpaque()82 FXbool getOpaque() const { return false; } 83 setTrayColor(FXColor)84 void setTrayColor(FXColor) {} 85 private: 86 HICON mWIcon; 87 FXIcon* mIcon; 88 DWORD mTrayID; 89 90 FXPopup* m_popup; 91 FXuint m_opts; 92 FXString mTooltip; 93 94 static DWORD sTrayIconCount; 95 FXTrayIcon()96 FXTrayIcon() 97 {} 98 99 void setupNotifyData(NOTIFYICONDATA* data); 100 }; 101 #else 102 class FXTrayIcon : public FXTopWindow 103 { 104 FXDECLARE(FXTrayIcon) 105 private: 106 FXTrayIcon(const FXTrayIcon*); 107 FXTrayIcon& operator=(const FXTrayIcon&); 108 109 void popup(FXint x, FXint y); 110 protected: 111 FXID m_xtraywindow; 112 FXID m_xtrayopcode; 113 FXID m_xtrayorientation; 114 FXID m_xtrayxfceorientation; 115 FXID m_xtrayvisual; 116 FXID m_socket; 117 FXIcon *m_icon; 118 FXbool m_opaque; 119 FXString m_tip; 120 FXPopup *m_popup; 121 FXuint m_opts; 122 FXColor m_traycolor; 123 124 FXTrayIcon(); 125 126 FXbool findSystemTray(); 127 void requestDock(); 128 FXuint getTrayOrientation(); 129 FXuint getTrayVisual(); 130 virtual bool doesOverrideRedirect() const; 131 public: 132 enum { 133 ID_POPTIMEOUT = FXTopWindow::ID_LAST, 134 ID_LAST 135 }; 136 FXTrayIcon(FXApp* app, const FXString& text, FXIcon* icon, 137 FXPopup* popup = NULL, FXObject* target = 0, FXSelector sel = 0, 138 FXuint opts = TRAY_MENU_ON_RIGHT); 139 virtual ~FXTrayIcon(); 140 141 long onPaint(FXObject*, FXSelector, void*); 142 long onConfigure(FXObject*, FXSelector, void*); 143 long onLeftBtnPress(FXObject*, FXSelector, void*); 144 long onRightBtnRelease(FXObject*, FXSelector, void*); 145 long onQueryTip(FXObject*, FXSelector, void*); 146 long onEmbedded(FXObject*, FXSelector, void*); 147 long onTimeout(FXObject*, FXSelector, void*); 148 149 virtual void create(); 150 FXbool dock(); 151 virtual void setFocus(); 152 /** Change the tool tip text. */ setText(const FXString & t)153 void setText(const FXString & t) { 154 m_tip = t; 155 } 156 /** Set the popup menu. */ setMenu(FXPopup * p)157 void setMenu(FXPopup *p) { 158 m_popup = p; 159 } 160 /** Change the icon in the tray. */ 161 void setIcon(FXIcon *ic); 162 /** Get the icon. */ 163 FXIcon* getIcon() const; 164 /** Is windows opaque? */ getOpaque()165 FXbool getOpaque() const { return m_opaque; } 166 /** Set tray color, usefull for opaque window */ 167 void setTrayColor(FXColor color); 168 }; 169 #endif 170 } 171 172 #endif 173