17 #include <SDL_syswm.h>
35 Shell_NotifyIcon(NIM_DELETE,
nid);
67 else if (event.syswm.msg->msg.win.lParam == 0x0200 && !
message_reset) {
75 const HMODULE wesnoth_exe = GetModuleHandle(
nullptr);
76 if (wesnoth_exe ==
nullptr) {
80 const HRSRC group_icon_info = FindResource(wesnoth_exe, TEXT(
"WESNOTH_ICON"), RT_GROUP_ICON);
81 if (group_icon_info ==
nullptr) {
85 HGLOBAL hGlobal = LoadResource(wesnoth_exe, group_icon_info);
86 if (hGlobal ==
nullptr) {
90 const PBYTE group_icon_res =
static_cast<PBYTE
>(LockResource(hGlobal));
91 if (group_icon_res ==
nullptr) {
95 const int nID = LookupIconIdFromDirectoryEx(group_icon_res, TRUE, 32, 32, LR_DEFAULTCOLOR);
100 const HRSRC icon_info = FindResource(wesnoth_exe, MAKEINTRESOURCE(nID), MAKEINTRESOURCE(3));
101 if (icon_info ==
nullptr) {
105 hGlobal = LoadResource(wesnoth_exe, icon_info);
106 if (hGlobal ==
nullptr) {
110 const PBYTE icon_res =
static_cast<PBYTE
>(LockResource(hGlobal));
111 if (icon_res ==
nullptr) {
115 const HICON icon = CreateIconFromResource(icon_res, SizeofResource(wesnoth_exe, icon_info), TRUE, 0x00030000);
116 if (icon ==
nullptr) {
121 if (window ==
nullptr) {
128 nid =
new NOTIFYICONDATA;
129 memset(
nid, 0,
sizeof(*
nid));
130 nid->cbSize = NOTIFYICONDATA_V2_SIZE;
132 nid->uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
134 nid->uVersion = NOTIFYICON_VERSION;
138 #if _WIN32_WINNT >= 0x600
139 nid->hBalloonIcon = icon;
141 lstrcpyW(
nid->szTip, wtip.c_str());
144 return Shell_NotifyIcon(NIM_ADD,
nid) != FALSE;
152 nid->uFlags |= NIF_INFO;
157 return Shell_NotifyIcon(NIM_MODIFY,
nid) != FALSE;
162 static const int ELIPSIS_LENGTH = 3;
175 SDL_SysWMinfo wmInfo;
176 SDL_VERSION(&wmInfo.version);
179 if (!window || SDL_GetWindowWMInfo (static_cast<SDL_Window *> (*window), &wmInfo) != SDL_TRUE) {
183 return wmInfo.info.win.window;
189 if (window ==
nullptr) {
193 if (IsIconic(window)) {
194 ShowWindow(window, SW_RESTORE);
196 SetForegroundWindow(window);
202 if(u16_string.size() > maxlength) {
203 if((u16_string[maxlength-1] & 0xDC00) == 0xD800)
204 u16_string.resize(maxlength - 1);
206 u16_string.resize(maxlength);
208 return std::wstring(u16_string.begin(), u16_string.end());
215 const bool tray_icon_exist =
nid !=
nullptr;
216 if (!tray_icon_exist) {
218 if (!tray_icon_created) {
219 const bool memory_allocated =
nid !=
nullptr;
220 if (memory_allocated) {
static void destroy_tray_icon()
static const unsigned int WM_TRAYNOTIFY
std::vector< char_t > string
static HWND get_window_handle()
#define NIN_BALLOONTIMEOUT
ucs4_convert_impl::enableif< TD, typename TS::value_type >::type unicode_cast(const TS &source)
static void switch_to_wesnoth_window()
static CVideo & get_singleton()
static bool set_tray_message(const std::string &title, const std::string &message)
sdl::twindow * get_window()
static bool create_tray_icon()
static const size_t MAX_TITLE_LENGTH
void ellipsis_truncate(std::string &str, const size_t size)
Truncates a string to a given utf-8 character count and then appends an ellipsis. ...
static UNUSEDNOWARN std::string _(const char *str)
The wrapper class for the SDL_Window class.
static bool message_reset
#define NIN_BALLOONUSERCLICK
static const size_t MAX_MESSAGE_LENGTH
GLsizei GLenum GLuint GLuint GLsizei char * message
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 NOTIFYICONDATA * nid
GLsizei const GLcharARB ** string
static std::wstring string_to_wstring(const std::string &string, size_t maxlength)