Mercurial > dwindows
changeset 2114:251d050d306b
Change dw_notification_new() to take an image path instead of an in-memory HPIXMAP.
After examining all the platforms, several require the image to be on disk.
It is easier to specify the path and load it on platforms requiring it in memory
than to save it to disk on platforms that require it on disk. Currently it does
not automatically pick an extension like some other functions, may need to add
that feature here too soon. Only tested on Windows in this commit.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 23 Jun 2020 07:48:29 +0000 |
parents | aaea278c2356 |
children | 79e5842fb609 |
files | dw.h dwtest.c gtk/dw.c gtk3/dw.c mac/dw.m os2/dw.c win/dw.c win/wintoast.cpp |
diffstat | 8 files changed, 45 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/dw.h Mon Jun 22 04:44:47 2020 +0000 +++ b/dw.h Tue Jun 23 07:48:29 2020 +0000 @@ -1857,7 +1857,7 @@ HPRINT API dw_print_new(const char *jobname, unsigned long flags, unsigned int pages, void *drawfunc, void *drawdata); int API dw_print_run(HPRINT print, unsigned long flags); void API dw_print_cancel(HPRINT print); -HWND API dw_notification_new(const char *title, HPIXMAP pixmap, const char *description, ...); +HWND API dw_notification_new(const char *title, const char *imagepath, const char *description, ...); int API dw_notification_send(HWND notification); wchar_t * API dw_utf8_to_wchar(const char *utf8string); char * API dw_wchar_to_utf8(const wchar_t *wstring);
--- a/dwtest.c Mon Jun 22 04:44:47 2020 +0000 +++ b/dwtest.c Tue Jun 23 07:48:29 2020 +0000 @@ -599,7 +599,7 @@ tmp = dw_file_browse("Pick a file", "dwtest.c", "c", DW_FILE_OPEN ); if ( tmp ) { - HWND notification = dw_notification_new("New file loaded", NULL, "dwtest loaded \"%s\" into the file browser on the Render tab, with \"File Display\" selected from the drop down list.", tmp); + HWND notification = dw_notification_new("New file loaded", "image\\test.png", "dwtest loaded \"%s\" into the file browser on the Render tab, with \"File Display\" selected from the drop down list.", tmp); if ( current_file ) {
--- a/gtk/dw.c Mon Jun 22 04:44:47 2020 +0000 +++ b/gtk/dw.c Tue Jun 23 07:48:29 2020 +0000 @@ -12357,7 +12357,7 @@ * Creates a new system notification if possible. * Parameters: * title: The short title of the notification. - * pixmap: Handle to an image to display or NULL if none. + * imagepath: Path to an image to display or NULL if none. * description: A longer description of the notification, * or NULL if none is necessary. * Returns: @@ -12385,11 +12385,18 @@ g_notification_set_body(notification, outbuf); } -#if GTK_MAJOR_VERSION > 1 - /* GTK 1.x is not implemented as pixbuf, so only allow icons on 2.x */ - if(pixmap && pixmap->pixbuf) - g_notification_set_icon(notification, G_ICON(pixmap->pixbuf)); -#endif + if(imagepath) + { + GFile *file = g_file_new_for_path(imagepath); + + if(file) + { + GFileIcon *icon = g_file_icon_new(file); + + if(icon) + g_notification_set_icon(notification, G_ICON(icon)); + } + } g_notification_set_default_action_and_target(notification, "app.notification", "t", (guint64)notification); } return (HWND)notification;
--- a/gtk3/dw.c Mon Jun 22 04:44:47 2020 +0000 +++ b/gtk3/dw.c Tue Jun 23 07:48:29 2020 +0000 @@ -11062,7 +11062,7 @@ * Creates a new system notification if possible. * Parameters: * title: The short title of the notification. - * pixmap: Handle to an image to display or NULL if none. + * imagepath: Path to an image to display or NULL if none. * description: A longer description of the notification, * or NULL if none is necessary. * Returns: @@ -11072,7 +11072,7 @@ * This will create a system notification that will show in the notifaction panel * on supported systems, which may be clicked to perform another task. */ -HWND dw_notification_new(const char *title, HPIXMAP pixmap, const char *description, ...) +HWND dw_notification_new(const char *title, const char *imagepath, const char *description, ...) { #if GLIB_CHECK_VERSION(2,40,0) GNotification *notification = g_notification_new(title); @@ -11090,8 +11090,18 @@ g_notification_set_body(notification, outbuf); } - if(pixmap && pixmap->pixbuf) - g_notification_set_icon(notification, G_ICON(pixmap->pixbuf)); + if(imagepath) + { + GFile *file = g_file_new_for_path(imagepath); + + if(file) + { + GFileIcon *icon = g_file_icon_new(file); + + if(icon) + g_notification_set_icon(notification, G_ICON(icon)); + } + } g_notification_set_default_action_and_target(notification, "app.notification", "t", (guint64)notification); } return (HWND)notification;
--- a/mac/dw.m Mon Jun 22 04:44:47 2020 +0000 +++ b/mac/dw.m Tue Jun 23 07:48:29 2020 +0000 @@ -10809,7 +10809,7 @@ * Creates a new system notification if possible. * Parameters: * title: The short title of the notification. - * pixmap: Handle to an image to display or NULL if none. + * imagepath: Path to an image to display or NULL if none. * description: A longer description of the notification, * or NULL if none is necessary. * Returns: @@ -10819,7 +10819,7 @@ * This will create a system notification that will show in the notifaction panel * on supported systems, which may be clicked to perform another task. */ -HWND dw_notification_new(const char *title, HPIXMAP pixmap, const char *description, ...) +HWND dw_notification_new(const char *title, const char *imagepath, const char *description, ...) { #ifdef BUILDING_FOR_MOUNTAIN_LION char outbuf[1025] = {0}; @@ -10861,8 +10861,8 @@ { notification.title = [NSString stringWithUTF8String:title]; notification.informativeText = [NSString stringWithUTF8String:outbuf]; - if(pixmap && pixmap->image) - notification.contentImage = pixmap->image; + if(imagepath) + notification.contentImage = [NSImage initByReferencingFile:[NSString stringWithUTF8String:imagepath]]; retval = notification; } }
--- a/os2/dw.c Mon Jun 22 04:44:47 2020 +0000 +++ b/os2/dw.c Tue Jun 23 07:48:29 2020 +0000 @@ -12396,7 +12396,7 @@ * Creates a new system notification if possible. * Parameters: * title: The short title of the notification. - * pixmap: Handle to an image to display or NULL if none. + * imagepath: Path to an image to display or NULL if none. * description: A longer description of the notification, * or NULL if none is necessary. * Returns: @@ -12406,7 +12406,7 @@ * This will create a system notification that will show in the notifaction panel * on supported systems, which may be clicked to perform another task. */ -HWND API dw_notification_new(const char *title, HPIXMAP pixmap, const char *description, ...) +HWND API dw_notification_new(const char *title, const char *imagepath, const char *description, ...) { return 0; }
--- a/win/dw.c Mon Jun 22 04:44:47 2020 +0000 +++ b/win/dw.c Tue Jun 23 07:48:29 2020 +0000 @@ -9642,7 +9642,7 @@ /* check if we can read from this file (it exists and read permission) */ if(access(file, 04) != 0) { - /* Try with .bmp extention */ + /* Try with .ico extention */ strcat(file, ".ico"); if(access(file, 04) != 0) { @@ -12404,7 +12404,7 @@ * Creates a new system notification if possible. * Parameters: * title: The short title of the notification. - * pixmap: Handle to an image to display or NULL if none. + * imagepath: Path to an image to display or NULL if none. * description: A longer description of the notification, * or NULL if none is necessary. * Returns: @@ -12414,7 +12414,7 @@ * This will create a system notification that will show in the notifaction panel * on supported systems, which may be clicked to perform another task. */ -HWND API dw_notification_new(const char *title, HPIXMAP pixmap, const char *description, ...) +HWND API dw_notification_new(const char *title, const char *imagepath, const char *description, ...) { #ifdef BUILD_TOAST char outbuf[1025] = {0}; @@ -12427,7 +12427,7 @@ vsnprintf(outbuf, 1024, description, args); va_end(args); } - return (HWND)_dw_notification_new(UTF8toWide(title), NULL, UTF8toWide(outbuf)); + return (HWND)_dw_notification_new(UTF8toWide(title), imagepath ? UTF8toWide(imagepath) : NULL, UTF8toWide(outbuf)); #else return NULL; #endif
--- a/win/wintoast.cpp Mon Jun 22 04:44:47 2020 +0000 +++ b/win/wintoast.cpp Tue Jun 23 07:48:29 2020 +0000 @@ -98,7 +98,12 @@ templ->setTextField(title, WinToastTemplate::FirstLine); templ->setAttributionText(description); if(image) - templ->setImagePath(image); + { + WCHAR fullpath[MAX_PATH+1] = {0}; + + GetFullPathNameW(image, MAX_PATH, fullpath, NULL); + templ->setImagePath(fullpath); + } return (void *)templ; } return NULL;