The Battle for Wesnoth  1.13.10+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 - 2017 by Maxim Biro <nurupo.contributions@gmail.com>
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 #pragma once
16 
17 #include <SDL.h>
18 #include <string>
19 //forces to call Unicode winapi functions instead of ASCII (default)
20 #ifndef UNICODE
21 #define UNICODE
22 #endif
23 //defines that mingw misses
24 #ifndef _WIN32_IE
25  #define _WIN32_IE 0x0600 //specifying target platform to be Windows XP and higher
26 #endif
27 #ifndef NIIF_USER
28  #define NIIF_USER 0x00000004
29 #endif
30 #ifndef NIN_BALLOONTIMEOUT
31  #define NIN_BALLOONTIMEOUT (WM_USER + 4)
32 #endif
33 #ifndef NIN_BALLOONUSERCLICK
34  #define NIN_BALLOONUSERCLICK (WM_USER + 5)
35 #endif
36 // ShellAPI.h should be included after Windows.h only!
37 #include <windows.h>
38 #include <shellapi.h>
39 
41 public:
42  /**
43  * Displays a tray notification.
44  * When user clicks on the notification popup, the user switches to the wesnoth window.
45  *
46  * @param title Title of a notification. Gets truncated if longer than 64 characters, including
47  * the terminating null character.
48  * @param message Message of a notification. Gets truncated if longer than 256 characters, including
49  * the terminating null character.
50  *
51  * @return True if message was shown successfully, False otherwise.
52  */
53  static bool show(std::string title, std::string message);
54 
55  /**
56  * Frees resources when a notification disappears, switches user to the wesnoth
57  * window if the notification popup was clicked by user.
58  *
59  * @param event System event.
60  */
61  static void handle_system_event(const SDL_Event& event);
62 
63 private:
64  static NOTIFYICONDATA* nid;
65  static bool message_reset;
66  static const int ICON_ID = 1007; // just a random number
67  static const unsigned int WM_TRAYNOTIFY = 32868; // WM_APP+100
68  static const size_t MAX_TITLE_LENGTH = 63; // 64 including the terminating null character
69  static const size_t MAX_MESSAGE_LENGTH = 255; // 256 including the terminating null character
70 
71  static bool create_tray_icon();
72  static void destroy_tray_icon();
73  static bool set_tray_message(const std::string& title, const std::string& message);
74  static void adjust_length(std::string& title, std::string& message);
75  static HWND get_window_handle();
76  static void switch_to_wesnoth_window();
77  static std::wstring string_to_wstring(const std::string& string, size_t maxlength);
78 
79  explicit windows_tray_notification();
82 };
std::vector< char_t > string
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)
int w
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...
static std::wstring string_to_wstring(const std::string &string, size_t maxlength)