1 #ifndef SNARL_INTERFACE_V39
2 #define SNARL_INTERFACE_V39
3 
4 #ifdef __WXMSW__
5 
6 #include <tchar.h>
7 #include <windows.h>
8 #include <cstdio>
9 
10 #ifndef SMTO_NOTIMEOUTIFNOTHUNG
11 	#define SMTO_NOTIMEOUTIFNOTHUNG 8
12 #endif
13 
14 
15 namespace Snarl {
16 	namespace V39 {
17 
18 	static const LPCTSTR SNARL_GLOBAL_MSG = _T("SnarlGlobalEvent");
19 	static const LPCTSTR SNARL_APP_MSG    = _T("SnarlAppMessage");
20 
21 	static const LPCTSTR SNARL_WINDOW_CLASS = _T("w>Snarl");
22 	static const LPCTSTR SNARL_WINDOW_TITLE = _T("Snarl");
23 
24 	static const int SNARL_STRING_LENGTH = 1024;
25 	static const int SNARL_UNICODE_LENGTH = SNARL_STRING_LENGTH / 2;
26 
27 	static const LONG32 SNARL_LAUNCHED = 1;                // Snarl has just started running
28 	static const LONG32 SNARL_QUIT = 2;                    // Snarl is about to stop running
29 	static const LONG32 SNARL_ASK_APPLET_VER = 3;          // (R1.5) Reserved for future use
30 	static const LONG32 SNARL_SHOW_APP_UI = 4;             // (R1.6) Application should show its UI
31 
32 	static const LONG32 SNARL_NOTIFICATION_CLICKED = 32;   // notification was right-clicked by user
33 	static const LONG32 SNARL_NOTIFICATION_TIMED_OUT = 33;
34 	static const LONG32 SNARL_NOTIFICATION_ACK = 34;       // notification was left-clicked by user
35 	static const LONG32 SNARL_NOTIFICATION_MENU = 35;           // V39 - menu item selected
36 	static const LONG32 SNARL_NOTIFICATION_MIDDLE_BUTTON = 36;  // V39 - notification middle-clicked by user
37 	static const LONG32 SNARL_NOTIFICATION_CLOSED = 37;         // V39 - user clicked the close gadget
38 
39 	static const LONG32 SNARL_NOTIFICATION_CANCELLED = SNARL_NOTIFICATION_CLICKED;  // Added in R1.6
40 
41 	static const DWORD WM_SNARLTEST = WM_USER + 237;    // note hardcoded WM_USER value!
42 
43 	// --------------------------------------------------------------------
44 
45 	enum M_RESULT {
46 		M_ABORTED         = 0x80000007,
47 		M_ACCESS_DENIED   = 0x80000009,
48 		M_ALREADY_EXISTS  = 0x8000000C,
49 		M_BAD_HANDLE      = 0x80000006,
50 		M_BAD_POINTER     = 0x80000005,
51 		M_FAILED          = 0x80000008,
52 		M_INVALID_ARGS    = 0x80000003,
53 		M_NO_INTERFACE    = 0x80000004,
54 		M_NOT_FOUND       = 0x8000000B,
55 		M_NOT_IMPLEMENTED = 0x80000001,
56 		M_OK              = 0x00000000,
57 		M_OUT_OF_MEMORY   = 0x80000002,
58 		M_TIMED_OUT       = 0x8000000A
59 	};
60 
61 	enum SNARL_COMMANDS {
62 		SNARL_SHOW = 1,
63 		SNARL_HIDE,
64 		SNARL_UPDATE,
65 		SNARL_IS_VISIBLE,
66 		SNARL_GET_VERSION,
67 		SNARL_REGISTER_CONFIG_WINDOW,
68 		SNARL_REVOKE_CONFIG_WINDOW,
69 
70 		/* R1.6 onwards */
71 		SNARL_REGISTER_ALERT,
72 		SNARL_REVOKE_ALERT,   // for future use
73 		SNARL_REGISTER_CONFIG_WINDOW_2,
74 		SNARL_GET_VERSION_EX,
75 		SNARL_SET_TIMEOUT,
76 
77 		/* following introduced in Snarl V39 (R2.1) */
78 		SNARL_SET_CLASS_DEFAULT,
79 		SNARL_CHANGE_ATTR,
80 		SNARL_REGISTER_APP,
81 		SNARL_UNREGISTER_APP,
82 		SNARL_ADD_CLASS,
83 
84 		/* extended commands (all use SNARLSTRUCTEX) */
85 		SNARL_EX_SHOW = 0x20,
86 		SNARL_SHOW_NOTIFICATION                // V39
87 	};
88 
89 	static const SNARL_COMMANDS SNARL_GET_REVISION = SNARL_REVOKE_ALERT;
90 
91 	enum SNARL_APP_FLAGS {
92 		SNARL_APP_HAS_PREFS = 1,
93 		SNARL_APP_HAS_ABOUT = 2
94 	};
95 
96 	static const LONG32 SNARL_APP_PREFS = 1;
97 	static const LONG32 SNARL_APP_ABOUT = 2;
98 
99 
100 	/* --------------- V39 additions --------------- */
101 
102 	/* snAddClass() flags */
103 	enum SNARL_CLASS_FLAGS {
104 		SNARL_CLASS_ENABLED = 0,
105 		SNARL_CLASS_DISABLED = 1,
106 		SNARL_CLASS_NO_DUPLICATES = 2,         // means Snarl will suppress duplicate notifications
107 		SNARL_CLASS_DELAY_DUPLICATES = 4       // means Snarl will suppress duplicate notifications within a pre-set time period
108 	};
109 
110 	/* Class attributes */
111 	enum SNARL_ATTRIBUTES {
112 		SNARL_ATTRIBUTE_TITLE = 1,
113 		SNARL_ATTRIBUTE_TEXT,
114 		SNARL_ATTRIBUTE_ICON,
115 		SNARL_ATTRIBUTE_TIMEOUT,
116 		SNARL_ATTRIBUTE_SOUND,
117 		SNARL_ATTRIBUTE_ACK,               // file to run on ACK
118 		SNARL_ATTRIBUTE_MENU
119 	};
120 
121 	/* ------------------- end of V39 additions ------------------ */
122 
123 	struct SNARLSTRUCT {
124 		SNARL_COMMANDS Cmd;
125 		LONG32 Id;
126 		LONG32 Timeout;
127 		LONG32 LngData2;
128 		char Title[SNARL_STRING_LENGTH];
129 		char Text[SNARL_STRING_LENGTH];
130 		char Icon[SNARL_STRING_LENGTH];
131 	};
132 
133 	struct SNARLSTRUCTEX {
134 		SNARL_COMMANDS Cmd;
135 		LONG32 Id;
136 		LONG32 Timeout;
137 		LONG32 LngData2;
138 		char Title[SNARL_STRING_LENGTH];
139 		char Text[SNARL_STRING_LENGTH];
140 		char Icon[SNARL_STRING_LENGTH];
141 
142 		char Class[SNARL_STRING_LENGTH];
143 		char Extra[SNARL_STRING_LENGTH];
144 		char Extra2[SNARL_STRING_LENGTH];
145 		LONG32 Reserved1;
146 		LONG32 Reserved2;
147 	};
148 
149 
150 
151 	// ------------------------------------------------------------------------
152 	// SnarlInterface class definition
153 	// ------------------------------------------------------------------------
154 
155 	class SnarlInterface {
156 		public:
157 			SnarlInterface();
158 			~SnarlInterface();
159 
160 			static HWND   GetSnarlWindow();
161 			static LONG32 GetGlobalMsg();
162 
163 
AllocateString(size_t n)164 			LPTSTR AllocateString(size_t n)  { return new TCHAR[n]; }
FreeString(LPCTSTR str)165 			void FreeString(LPCTSTR str)     { delete [] str; str = NULL; }
166 
167 
168 			LONG32  ShowMessage(LPCSTR szTitle, LPCSTR szText, LONG32 timeout = 0, LPCSTR szIconPath = "", HWND hWndReply = NULL, WPARAM uReplyMsg = 0);
169 			LONG32  ShowMessage(LPCWSTR szTitle, LPCWSTR szText, LONG32 timeout = 0, LPCWSTR szIconPath = L"", HWND hWndReply = NULL, WPARAM uReplyMsg = 0);
170 			LONG32  ShowMessageEx(LPCSTR szClass, LPCSTR szTitle, LPCSTR szText, LONG32 timeout = 0, LPCSTR szIconPath = "", HWND hWndReply = NULL, WPARAM uReplyMsg = 0, LPCSTR szSoundFile = "");
171 			LONG32  ShowMessageEx(LPCWSTR szClass, LPCWSTR szTitle, LPCWSTR szText, LONG32 timeout = 0, LPCWSTR szIconPath = L"", HWND hWndReply = NULL, WPARAM uReplyMsg = 0, LPCWSTR szSoundFile = L"");
172 
173 			LPCTSTR GetAppPath();    // ** Remember to FreeString when finished with the string !
174 			LPCTSTR GetIconsPath();  // ** Remember to FreeString when finished with the string !
175 
176 			BOOL      GetVersion(WORD* Major, WORD* Minor);
177 			LONG32    GetVersionEx();
178 			BOOL      HideMessage();
179 			BOOL      HideMessage(LONG32 Id);
180 			BOOL      IsMessageVisible();
181 			BOOL      IsMessageVisible(LONG32 Id);
182 			M_RESULT  RegisterAlert(LPCSTR szAppName, LPCSTR szClass);
183 			M_RESULT  RegisterAlert(LPCWSTR szAppName, LPCWSTR szClass);
184 			M_RESULT  RegisterConfig(HWND hWnd, LPCSTR szAppName, LONG32 replyMsg);
185 			M_RESULT  RegisterConfig(HWND hWnd, LPCWSTR szAppName, LONG32 replyMsg);
186 			M_RESULT  RegisterConfig2(HWND hWnd, LPCSTR szAppName, LONG32 replyMsg, LPCSTR szIcon);
187 			M_RESULT  RegisterConfig2(HWND hWnd, LPCWSTR szAppName, LONG32 replyMsg, LPCWSTR szIcon);
188 			M_RESULT  RevokeConfig(HWND hWnd);
189 			M_RESULT  SetTimeout(LONG32 Timeout);
190 			M_RESULT  SetTimeout(LONG32 Id, LONG32 Timeout);
191 			M_RESULT  UpdateMessage(LPCSTR szTitle, LPCSTR szText, LPCSTR szIconPath = "");
192 			M_RESULT  UpdateMessage(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szIconPath = L"");
193 			M_RESULT  UpdateMessage(LONG32 Id, LPCSTR szTitle, LPCSTR szText, LPCSTR szIconPath = "");
194 			M_RESULT  UpdateMessage(LONG32 Id, LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szIconPath = L"");
195 
196 			/* V39 */
197 			M_RESULT  AddClass(LPCSTR Class, LPCSTR Description = NULL, SNARL_CLASS_FLAGS Flags = SNARL_CLASS_ENABLED, LPCSTR DefaultTitle = NULL, LPCSTR DefaultIcon = NULL, LONG32 DefaultTimeout = 0);
198 			M_RESULT  AddClass(LPCWSTR Class, LPCWSTR Description = NULL, SNARL_CLASS_FLAGS Flags = SNARL_CLASS_ENABLED, LPCWSTR DefaultTitle = NULL, LPCWSTR DefaultIcon = NULL, LONG32 DefaultTimeout = 0);
199 			M_RESULT  ChangeAttribute(SNARL_ATTRIBUTES Attr, LPCSTR Value);
200 			M_RESULT  ChangeAttribute(SNARL_ATTRIBUTES Attr, LPCWSTR Value);
201 			M_RESULT  ChangeAttribute(LONG32 Id, SNARL_ATTRIBUTES Attr, LPCSTR Value);
202 			M_RESULT  ChangeAttribute(LONG32 Id, SNARL_ATTRIBUTES Attr, LPCWSTR Value);
203 			LONG32    GetAppMsg();
204 			LONG32    GetRevision();
205 
206 			M_RESULT  RegisterApp(LPCSTR Application, LPCSTR SmallIcon, LPCSTR LargeIcon, HWND hWnd = 0, LONG32 ReplyMsg = 0);
207 			M_RESULT  RegisterApp(LPCWSTR Application, LPCWSTR SmallIcon, LPCWSTR LargeIcon, HWND hWnd = 0, LONG32 ReplyMsg = 0);
208 			void      SetAsSnarlApp(HWND hWndOwner, SNARL_APP_FLAGS Flags = (SNARL_APP_FLAGS)(SNARL_APP_HAS_ABOUT | SNARL_APP_HAS_PREFS));
209 			M_RESULT  SetClassDefault(LPCSTR Class, SNARL_ATTRIBUTES Attr, LPCSTR Value);
210 			M_RESULT  SetClassDefault(LPCWSTR Class, SNARL_ATTRIBUTES Attr, LPCWSTR Value);
211 			LONG32    ShowNotification(LPCSTR Class, LPCSTR Title, LPCSTR Text, LONG32 Timeout = 0, LPCSTR Icon = NULL, HWND hWndReply = NULL, LONG32 uReplyMsg = 0, LPCSTR Sound = NULL);
212 			LONG32    ShowNotification(LPCWSTR Class, LPCWSTR Title, LPCWSTR Text, LONG32 Timeout = 0, LPCWSTR Icon = NULL, HWND hWndReply = NULL, LONG32 uReplyMsg = 0, LPCWSTR Sound = NULL);
213 			M_RESULT  UnregisterApp();
214 
GetLastMessageId()215 			LONG32    GetLastMessageId() { return m_nLastMessageId; }
216 
217 		private:
218 			template <class T> LONG32 Send(T ss);
219 			LPSTR  WideToUTF8(LPCWSTR szWideStr);
220 
221 			HWND   m_hwndFrom; // set during snRegisterConfig() or snRegisterConfig2()
222 			LONG32 m_nLastMessageId;
223 	};
224 
225 	} // namespace V39
226 } // namespace Snarl
227 
228 #endif // __WXMSW__
229 #endif // SNARL_INTERFACE_V39
230