changeset 1075:3d117071a50b

Renamed Mac _dw_default_font() to dw_font_set_default() and added it on OS/2 and Windows. Function added to the public export list... GTK2/3 support will be added shortly.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 26 Jun 2011 02:07:49 +0000
parents 53fc692279fc
children dbaf1b11c301
files dw.def dw.h dww.def mac/dw.m os2/dw.c win/dw.c
diffstat 6 files changed, 56 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/dw.def	Sat Jun 25 03:16:40 2011 +0000
+++ b/dw.def	Sun Jun 26 02:07:49 2011 +0000
@@ -237,6 +237,7 @@
 
   dw_font_text_extents_get               @385
   dw_font_choose                         @386
+  dw_font_set_default                    @387
 
   dw_slider_new                          @390
   dw_slider_get_pos                      @391
--- a/dw.h	Sat Jun 25 03:16:40 2011 +0000
+++ b/dw.h	Sun Jun 26 02:07:49 2011 +0000
@@ -311,8 +311,6 @@
 } *HPIXMAP;
 
 void _dw_pool_drain(void);
-void _dw_default_font(char *fontname);
-
 
 #define DW_DT_LEFT               0 /* NSLeftTextAlignment */
 #define DW_DT_QUERYEXTENT        0
@@ -1624,6 +1622,7 @@
 void API dw_draw_polygon(HWND handle, HPIXMAP pixmap, int fill, int npoints, int *x, int *y);
 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text);
 void API dw_font_text_extents_get(HWND handle, HPIXMAP pixmap, char *text, int *width, int *height);
+void API dw_font_set_default(char *fontname);
 void API dw_flush(void);
 void API dw_pixmap_bitblt(HWND dest, HPIXMAP destp, int xdest, int ydest, int width, int height, HWND src, HPIXMAP srcp, int xsrc, int ysrc);
 HPIXMAP API dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth);
--- a/dww.def	Sat Jun 25 03:16:40 2011 +0000
+++ b/dww.def	Sun Jun 26 02:07:49 2011 +0000
@@ -234,6 +234,7 @@
 
   dw_font_text_extents_get               @385
   dw_font_choose                         @386
+  dw_font_set_default                    @387
 
   dw_slider_new                          @390
   dw_slider_get_pos                      @391
--- a/mac/dw.m	Sat Jun 25 03:16:40 2011 +0000
+++ b/mac/dw.m	Sun Jun 26 02:07:49 2011 +0000
@@ -8929,7 +8929,12 @@
     free(tmp);
 }
 
-void _dw_default_font(char *fontname)
+/*
+ * Sets the default font used on text based widgets.
+ * Parameters:
+ *           fontname: Font name in Dynamic Windows format.
+ */
+void API dw_font_set_default(char *fontname)
 {
     if(DWDefaultFont)
     {
--- a/os2/dw.c	Sat Jun 25 03:16:40 2011 +0000
+++ b/os2/dw.c	Sun Jun 26 02:07:49 2011 +0000
@@ -3669,7 +3669,9 @@
    desktop = WinQueryDesktopWindow(dwhab, NULLHANDLE);
 
    if(!IS_WARP4())
-      DefaultFont = "8.Helv";
+      DefaultFont = strdup("8.Helv");
+   else
+      DefaultFont = strdup(DefaultFont);
 
    /* This is a window that hangs around as long as the
     * application does and handles menu messages.
@@ -4131,6 +4133,19 @@
 }
 
 /*
+ * Sets the default font used on text based widgets.
+ * Parameters:
+ *           fontname: Font name in Dynamic Windows format.
+ */
+void API dw_font_set_default(char *fontname)
+{
+    char *oldfont = DefaultFont;
+    
+    DefaultFont = strdup(fontname);
+    free(oldfont);
+}
+
+/*
  * Sets the font used by a specified window (widget) handle.
  * Parameters:
  *          handle: The window (widget) handle.
--- a/win/dw.c	Sat Jun 25 03:16:40 2011 +0000
+++ b/win/dw.c	Sun Jun 26 02:07:49 2011 +0000
@@ -73,6 +73,7 @@
 HBRUSH _colors[18];
 
 static int screenx, screeny;
+HFONT _DefaultFont = NULL;
 
 LRESULT CALLBACK _browserWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 void _resize_notebook_page(HWND handle, int pageid);
@@ -4038,6 +4039,18 @@
    return lf;
 }
 
+/* Create a duplicate of an existing font handle
+ * that is safe to call DeleteObject() on.
+ */
+HFONT _DupFontHandle(HFONT hfont)
+{
+    LOGFONT lf = {0};
+    return GetObject(hfont, sizeof(lf), &lf) ? CreateFontIndirect(&lf) : NULL;
+}
+
+/* Create a font handle from specified font name..
+ * or return a handle to the default font.
+ */
 HFONT _acquire_font(HWND handle, char *fontname)
 {
    HFONT hfont = 0;
@@ -4047,12 +4060,30 @@
       LOGFONT lf = _get_logfont(handle, fontname);
       hfont = CreateFontIndirect(&lf);
    }
+   if(!hfont && _DefaultFont)
+      hfont = _DupFontHandle(_DefaultFont);
    if(!hfont)
       hfont = GetStockObject(DEFAULT_GUI_FONT);
    return hfont;
 }
 
 /*
+ * Sets the default font used on text based widgets.
+ * Parameters:
+ *           fontname: Font name in Dynamic Windows format.
+ */
+void API dw_font_set_default(char *fontname)
+{
+    HFONT oldfont = _DefaultFont;
+    
+    _DefaultFont = _acquire_font(HWND_DESKTOP, fontname);
+    if(oldfont)
+    {
+        DeleteObject(oldfont);
+    }
+}
+
+/*
  * Sets the font used by a specified window (widget) handle.
  * Parameters:
  *          handle: The window (widget) handle.