The Battle for Wesnoth  1.19.24+dev
Static Public Member Functions | Private Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
windows_tray_notification Class Reference

#include <windows_tray_notification.hpp>

Static Public Member Functions

static bool show (std::string title, std::string message)
 Displays a tray notification. More...
 
static bool message_hook (const MSG &msg)
 Frees resources when a notification disappears, switches user to the wesnoth window if the notification popup was clicked by user. More...
 

Private Member Functions

 windows_tray_notification ()
 
 windows_tray_notification (const windows_tray_notification &w)
 
windows_tray_notificationoperator= (const windows_tray_notification &w)
 

Static Private Member Functions

static bool create_tray_icon ()
 
static void destroy_tray_icon ()
 
static bool set_tray_message (const std::string &title, const std::string &message)
 
static void adjust_length (std::string &title, std::string &message)
 
static HWND get_window_handle ()
 
static void switch_to_wesnoth_window ()
 
static std::wstring string_to_wstring (const std::string &string, std::size_t maxlength)
 

Static Private Attributes

static NOTIFYICONDATA * nid = nullptr
 
static bool message_reset = false
 
static const int ICON_ID = 1007
 
static const unsigned int WM_TRAYNOTIFY = 32868
 
static const std::size_t MAX_TITLE_LENGTH = 63
 
static const std::size_t MAX_MESSAGE_LENGTH = 255
 

Detailed Description

Definition at line 27 of file windows_tray_notification.hpp.

Constructor & Destructor Documentation

◆ windows_tray_notification() [1/2]

windows_tray_notification::windows_tray_notification ( )
explicitprivate

◆ windows_tray_notification() [2/2]

windows_tray_notification::windows_tray_notification ( const windows_tray_notification w)
private

Member Function Documentation

◆ adjust_length()

void windows_tray_notification::adjust_length ( std::string &  title,
std::string &  message 
)
staticprivate

Definition at line 165 of file windows_tray_notification.cpp.

References utils::ellipsis_truncate(), MAX_MESSAGE_LENGTH, and MAX_TITLE_LENGTH.

Referenced by show().

◆ create_tray_icon()

bool windows_tray_notification::create_tray_icon ( )
staticprivate

◆ destroy_tray_icon()

void windows_tray_notification::destroy_tray_icon ( )
staticprivate

Definition at line 27 of file windows_tray_notification.cpp.

References message_reset, and nid.

Referenced by message_hook(), and show().

◆ get_window_handle()

HWND windows_tray_notification::get_window_handle ( )
staticprivate

Definition at line 178 of file windows_tray_notification.cpp.

References video::get_window().

Referenced by create_tray_icon(), and switch_to_wesnoth_window().

◆ message_hook()

bool windows_tray_notification::message_hook ( const MSG &  msg)
static

Frees resources when a notification disappears, switches user to the wesnoth window if the notification popup was clicked by user.

Parameters
msgWindows message payload.
Returns
True if the message was handled.

Definition at line 42 of file windows_tray_notification.cpp.

References destroy_tray_icon(), message_reset, wfl::msg(), and switch_to_wesnoth_window().

◆ operator=()

windows_tray_notification& windows_tray_notification::operator= ( const windows_tray_notification w)
private

◆ set_tray_message()

bool windows_tray_notification::set_tray_message ( const std::string &  title,
const std::string &  message 
)
staticprivate

Definition at line 152 of file windows_tray_notification.cpp.

References MAX_MESSAGE_LENGTH, MAX_TITLE_LENGTH, message_reset, nid, and string_to_wstring().

Referenced by show().

◆ show()

bool windows_tray_notification::show ( std::string  title,
std::string  message 
)
static

Displays a tray notification.

When user clicks on the notification popup, the user switches to the wesnoth window.

Parameters
titleTitle of a notification. Gets truncated if longer than 64 characters, including the terminating null character.
messageMessage of a notification. Gets truncated if longer than 256 characters, including the terminating null character.
Returns
True if message was shown successfully, False otherwise.

Definition at line 209 of file windows_tray_notification.cpp.

References adjust_length(), create_tray_icon(), destroy_tray_icon(), nid, and set_tray_message().

◆ string_to_wstring()

std::wstring windows_tray_notification::string_to_wstring ( const std::string &  string,
std::size_t  maxlength 
)
staticprivate

Definition at line 197 of file windows_tray_notification.cpp.

Referenced by create_tray_icon(), and set_tray_message().

◆ switch_to_wesnoth_window()

void windows_tray_notification::switch_to_wesnoth_window ( )
staticprivate

Definition at line 184 of file windows_tray_notification.cpp.

References get_window_handle().

Referenced by message_hook().

Member Data Documentation

◆ ICON_ID

const int windows_tray_notification::ICON_ID = 1007
staticprivate

Definition at line 55 of file windows_tray_notification.hpp.

Referenced by create_tray_icon().

◆ MAX_MESSAGE_LENGTH

const std::size_t windows_tray_notification::MAX_MESSAGE_LENGTH = 255
staticprivate

Definition at line 58 of file windows_tray_notification.hpp.

Referenced by adjust_length(), and set_tray_message().

◆ MAX_TITLE_LENGTH

const std::size_t windows_tray_notification::MAX_TITLE_LENGTH = 63
staticprivate

Definition at line 57 of file windows_tray_notification.hpp.

Referenced by adjust_length(), create_tray_icon(), and set_tray_message().

◆ message_reset

bool windows_tray_notification::message_reset = false
staticprivate

Definition at line 54 of file windows_tray_notification.hpp.

Referenced by destroy_tray_icon(), message_hook(), and set_tray_message().

◆ nid

NOTIFYICONDATA * windows_tray_notification::nid = nullptr
staticprivate

◆ WM_TRAYNOTIFY

const unsigned int windows_tray_notification::WM_TRAYNOTIFY = 32868
staticprivate

Definition at line 56 of file windows_tray_notification.hpp.

Referenced by create_tray_icon().


The documentation for this class was generated from the following files: