The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
windows_tray_notification.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2016 by Maxim Biro <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef WINDOWS_TRAY_NOTIFICATION_HPP_INCLUDED
16 #define WINDOWS_TRAY_NOTIFICATION_HPP_INCLUDED
17 
18 #include <SDL.h>
19 #include <string>
20 //forces to call Unicode winapi functions instead of ASCII (default)
21 #ifndef UNICODE
22 #define UNICODE
23 #endif
24 //defines that mingw misses
25 #ifndef _WIN32_IE
26  #define _WIN32_IE 0x0600 //specifying target platform to be Windows XP and higher
27 #endif
28 #ifndef NIIF_USER
29  #define NIIF_USER 0x00000004
30 #endif
31 #ifndef NIN_BALLOONTIMEOUT
32  #define NIN_BALLOONTIMEOUT (WM_USER + 4)
33 #endif
34 #ifndef NIN_BALLOONUSERCLICK
35  #define NIN_BALLOONUSERCLICK (WM_USER + 5)
36 #endif
37 // ShellAPI.h should be included after Windows.h only!
38 #include <windows.h>
39 #include <shellapi.h>
40 
42 public:
43  /**
44  * Displays a tray notification.
45  * When user clicks on the notification popup, the user switches to the wesnoth window.
46  *
47  * @param title Title of a notification. Gets truncated if longer than 64 characters, including
48  * the terminating null character.
49  * @param message Message of a notification. Gets truncated if longer than 256 characters, including
50  * the terminating null character.
51  *
52  * @return True if message was shown successfully, False otherwise.
53  */
54  static bool show(std::string title, std::string message);
55 
56  /**
57  * Frees resources when a notification disappears, switches user to the wesnoth
58  * window if the notification popup was clicked by user.
59  *
60  * @param event System event.
61  */
62  static void handle_system_event(const SDL_Event& event);
63 
64 private:
65  static NOTIFYICONDATA* nid;
66  static bool message_reset;
67  static const int ICON_ID = 1007; // just a random number
68  static const unsigned int WM_TRAYNOTIFY = 32868; // WM_APP+100
69  static const size_t MAX_TITLE_LENGTH = 63; // 64 including the terminating null character
70  static const size_t MAX_MESSAGE_LENGTH = 255; // 256 including the terminating null character
71 
72  static bool create_tray_icon();
73  static void destroy_tray_icon();
74  static bool set_tray_message(const std::string& title, const std::string& message);
75  static void adjust_length(std::string& title, std::string& message);
76  static HWND get_window_handle();
77  static void switch_to_wesnoth_window();
78  static std::wstring string_to_wstring(const std::string& string, size_t maxlength);
79 
80  explicit windows_tray_notification();
83 };
84 
85 #endif // WINDOWS_TRAY_NOTIFICATION_HPP_INCLUDED
static const unsigned int WM_TRAYNOTIFY
windows_tray_notification & operator=(const windows_tray_notification &w)
static bool set_tray_message(const std::string &title, const std::string &message)
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1858
cl_event event
Definition: glew.h:3070
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
static bool show(std::string title, std::string message)
Displays a tray notification.
static void adjust_length(std::string &title, std::string &message)
static void handle_system_event(const SDL_Event &event)
Frees resources when a notification disappears, switches user to the wesnoth window if the notificati...
GLsizei const GLcharARB ** string
Definition: glew.h:4503
static std::wstring string_to_wstring(const std::string &string, size_t maxlength)