comparison src/glyphs-msw.c @ 384:bbff43aa5eb7 r21-2-7

Import from CVS: tag r21-2-7
author cvs
date Mon, 13 Aug 2007 11:08:24 +0200
parents 064ab7fed2e0
children aabb7f5b1c81
comparison
equal deleted inserted replaced
383:6a50c6a581a5 384:bbff43aa5eb7
1 /* mswindows-specific Lisp objects. 1 /* mswindows-specific glyph objects.
2 Copyright (C) 1998 Andy Piper. 2 Copyright (C) 1998 Andy Piper.
3 3
4 This file is part of XEmacs. 4 This file is part of XEmacs.
5 5
6 XEmacs is free software; you can redistribute it and/or modify it 6 XEmacs is free software; you can redistribute it and/or modify it
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */ 19 Boston, MA 02111-1307, USA. */
20 20
21 /* Synched up with: Not in FSF. */ 21 /* Synched up with: Not in FSF. */
22 22
23 /* written by Andy Piper <andyp@parallax.co.uk> plagerising buts from 23 /* written by Andy Piper <andy@xemacs.org> plagerising bits from
24 glyphs-x.c */ 24 glyphs-x.c */
25 25
26 #include <config.h> 26 #include <config.h>
27 #include "lisp.h" 27 #include "lisp.h"
28 #include "lstream.h" 28 #include "lstream.h"
30 #define OEMRESOURCE /* Define OCR_ and friend constants */ 30 #define OEMRESOURCE /* Define OCR_ and friend constants */
31 #include "console-msw.h" 31 #include "console-msw.h"
32 #include "glyphs-msw.h" 32 #include "glyphs-msw.h"
33 #include "objects-msw.h" 33 #include "objects-msw.h"
34 34
35 #include "window.h"
36 #include "elhash.h"
35 #include "buffer.h" 37 #include "buffer.h"
36 #include "frame.h" 38 #include "frame.h"
37 #include "insdel.h" 39 #include "insdel.h"
38 #include "opaque.h" 40 #include "opaque.h"
39 #include "sysfile.h" 41 #include "sysfile.h"
44 #include "file-coding.h" 46 #include "file-coding.h"
45 #endif 47 #endif
46 #include <stdio.h> 48 #include <stdio.h>
47 #include <ctype.h> 49 #include <ctype.h>
48 50
51 #define WIDGET_GLYPH_SLOT 0
52
53 #ifdef HAVE_XPM
54 DEFINE_DEVICE_IIFORMAT (mswindows, xpm);
55 #endif
56 DEFINE_DEVICE_IIFORMAT (mswindows, xbm);
57 DEFINE_DEVICE_IIFORMAT (mswindows, button);
58 DEFINE_DEVICE_IIFORMAT (mswindows, edit);
59 #if 0
60 DEFINE_DEVICE_IIFORMAT (mswindows, group);
61 #endif
62 DEFINE_DEVICE_IIFORMAT (mswindows, subwindow);
63 DEFINE_DEVICE_IIFORMAT (mswindows, widget);
64 DEFINE_DEVICE_IIFORMAT (mswindows, label);
65 DEFINE_DEVICE_IIFORMAT (mswindows, scrollbar);
66 DEFINE_DEVICE_IIFORMAT (mswindows, combo);
49 67
50 DEFINE_IMAGE_INSTANTIATOR_FORMAT (bmp); 68 DEFINE_IMAGE_INSTANTIATOR_FORMAT (bmp);
51 Lisp_Object Qbmp; 69 Lisp_Object Qbmp;
52 Lisp_Object Vmswindows_bitmap_file_path; 70 Lisp_Object Vmswindows_bitmap_file_path;
53 static COLORREF transparent_color = RGB (1,1,1); 71 static COLORREF transparent_color = RGB (1,1,1);
56 Lisp_Object Q_resource_type, Q_resource_id; 74 Lisp_Object Q_resource_type, Q_resource_id;
57 Lisp_Object Qmswindows_resource; 75 Lisp_Object Qmswindows_resource;
58 76
59 static void 77 static void
60 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii, 78 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
61 enum image_instance_type type); 79 enum image_instance_type type);
62 static void 80 static void
63 mswindows_initialize_image_instance_mask (struct Lisp_Image_Instance* image, 81 mswindows_initialize_image_instance_mask (struct Lisp_Image_Instance* image,
64 struct frame* f); 82 struct frame* f);
65 83
66 COLORREF mswindows_string_to_color (CONST char *name); 84 COLORREF mswindows_string_to_color (CONST char *name);
658 { 676 {
659 Lisp_Object cons = XCAR (results); 677 Lisp_Object cons = XCAR (results);
660 colortbl[j].color = 678 colortbl[j].color =
661 COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (XCDR (cons))); 679 COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
662 680
663 colortbl[j].name = (char *) XSTRING_DATA (XCAR (cons)); 681 GET_C_STRING_OS_DATA_ALLOCA (XCAR (cons), colortbl[j].name);
664 free_cons (XCONS (cons)); 682 free_cons (XCONS (cons));
665 cons = results; 683 cons = results;
666 results = XCDR (results); 684 results = XCDR (results);
667 free_cons (XCONS (cons)); 685 free_cons (XCONS (cons));
668 } 686 }
1091 { 1109 {
1092 signal_simple_error ("invalid resource identifier", name); 1110 signal_simple_error ("invalid resource identifier", name);
1093 } 1111 }
1094 1112
1095 do { 1113 do {
1096 if (!strcasecmp ((char*)res->name, XSTRING_DATA (name))) 1114 Extbyte* nm=0;
1115 GET_C_STRING_OS_DATA_ALLOCA (name, nm);
1116 if (!strcasecmp ((char*)res->name, nm))
1097 return res->resource_id; 1117 return res->resource_id;
1098 } while ((++res)->name); 1118 } while ((++res)->name);
1099 return 0; 1119 return 0;
1100 } 1120 }
1101 1121
1149 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK); 1169 IMAGE_COLOR_PIXMAP_MASK | IMAGE_POINTER_MASK);
1150 1170
1151 /* mess with the keyword info we were provided with */ 1171 /* mess with the keyword info we were provided with */
1152 if (!NILP (file)) 1172 if (!NILP (file))
1153 { 1173 {
1174 Extbyte* f=0;
1175 GET_C_STRING_FILENAME_DATA_ALLOCA (file, f);
1154 #ifdef __CYGWIN32__ 1176 #ifdef __CYGWIN32__
1155 CYGWIN_WIN32_PATH (XSTRING_DATA (file), fname); 1177 CYGWIN_WIN32_PATH (f, fname);
1156 #else 1178 #else
1157 /* #### FIXME someone who knows ... */ 1179 /* #### FIXME someone who knows ... */
1158 fname = XSTRING_DATA (file); 1180 fname = f
1159 #endif 1181 #endif
1160 1182
1161 if (NILP (resource_id)) 1183 if (NILP (resource_id))
1162 resid = (LPCTSTR)fname; 1184 resid = (LPCTSTR)fname;
1163 else 1185 else
1166 LOAD_LIBRARY_AS_DATAFILE); 1188 LOAD_LIBRARY_AS_DATAFILE);
1167 resid = MAKEINTRESOURCE (resource_name_to_resource (resource_id, 1189 resid = MAKEINTRESOURCE (resource_name_to_resource (resource_id,
1168 type)); 1190 type));
1169 1191
1170 if (!resid) 1192 if (!resid)
1171 resid = XSTRING_DATA (resource_id); 1193 GET_C_STRING_OS_DATA_ALLOCA (resource_id, resid);
1172 } 1194 }
1173 } 1195 }
1174 else if (!(resid = MAKEINTRESOURCE (resource_name_to_resource (resource_id, 1196 else if (!(resid = MAKEINTRESOURCE (resource_name_to_resource (resource_id,
1175 type)))) 1197 type))))
1176 signal_simple_error ("Invalid resource identifier", resource_id); 1198 signal_simple_error ("Invalid resource identifier", resource_id);
1837 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_MASK (p)); 1859 (unsigned long) IMAGE_INSTANCE_MSWINDOWS_MASK (p));
1838 write_c_string (buf, printcharfun); 1860 write_c_string (buf, printcharfun);
1839 } 1861 }
1840 write_c_string (")", printcharfun); 1862 write_c_string (")", printcharfun);
1841 break; 1863 break;
1864
1842 default: 1865 default:
1843 break; 1866 break;
1844 } 1867 }
1845 } 1868 }
1846 1869
1847 static void 1870 static void
1848 mswindows_finalize_image_instance (struct Lisp_Image_Instance *p) 1871 mswindows_finalize_image_instance (struct Lisp_Image_Instance *p)
1849 { 1872 {
1850 if (!p->data)
1851 return;
1852
1853 if (DEVICE_LIVE_P (XDEVICE (p->device))) 1873 if (DEVICE_LIVE_P (XDEVICE (p->device)))
1854 { 1874 {
1855 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p)) 1875 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_WIDGET
1856 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p)); 1876 ||
1857 IMAGE_INSTANCE_MSWINDOWS_BITMAP (p) = 0; 1877 IMAGE_INSTANCE_TYPE (p) == IMAGE_SUBWINDOW)
1858 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p)) 1878 {
1859 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (p)); 1879 if (IMAGE_INSTANCE_SUBWINDOW_ID (p))
1860 IMAGE_INSTANCE_MSWINDOWS_MASK (p) = 0; 1880 DestroyWindow (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p));
1861 if (IMAGE_INSTANCE_MSWINDOWS_ICON (p)) 1881 IMAGE_INSTANCE_SUBWINDOW_ID (p) = 0;
1862 DestroyIcon (IMAGE_INSTANCE_MSWINDOWS_ICON (p)); 1882 }
1863 IMAGE_INSTANCE_MSWINDOWS_ICON (p) = 0; 1883 else if (p->data)
1864 } 1884 {
1865 1885 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p))
1866 xfree (p->data); 1886 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p));
1867 p->data = 0; 1887 IMAGE_INSTANCE_MSWINDOWS_BITMAP (p) = 0;
1888 if (IMAGE_INSTANCE_MSWINDOWS_MASK (p))
1889 DeleteObject (IMAGE_INSTANCE_MSWINDOWS_MASK (p));
1890 IMAGE_INSTANCE_MSWINDOWS_MASK (p) = 0;
1891 if (IMAGE_INSTANCE_MSWINDOWS_ICON (p))
1892 DestroyIcon (IMAGE_INSTANCE_MSWINDOWS_ICON (p));
1893 IMAGE_INSTANCE_MSWINDOWS_ICON (p) = 0;
1894 }
1895 }
1896
1897 if (p->data)
1898 {
1899 xfree (p->data);
1900 p->data = 0;
1901 }
1902 }
1903
1904 /************************************************************************/
1905 /* subwindow and widget support */
1906 /************************************************************************/
1907
1908 /* unmap the image if it is a widget. This is used by redisplay via
1909 redisplay_unmap_subwindows */
1910 static void
1911 mswindows_unmap_subwindow (struct Lisp_Image_Instance *p)
1912 {
1913 if (IMAGE_INSTANCE_SUBWINDOW_ID (p))
1914 {
1915 SetWindowPos (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p),
1916 NULL,
1917 0, 0, 0, 0,
1918 SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE
1919 | SWP_NOCOPYBITS | SWP_NOSENDCHANGING);
1920 }
1921 }
1922
1923 /* map the subwindow. This is used by redisplay via
1924 redisplay_output_subwindow */
1925 static void
1926 mswindows_map_subwindow (struct Lisp_Image_Instance *p, int x, int y)
1927 {
1928 /* ShowWindow (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p), SW_SHOW);*/
1929 SetWindowPos (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p),
1930 NULL,
1931 x, y, 0, 0,
1932 SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOSIZE
1933 | SWP_NOCOPYBITS | SWP_NOSENDCHANGING);
1934 }
1935
1936 /* when you click on a widget you may activate another widget this
1937 needs to be checked and all appropriate widgets updated */
1938 static void
1939 mswindows_update_subwindow (struct Lisp_Image_Instance *p)
1940 {
1941 if (IMAGE_INSTANCE_TYPE (p) == IMAGE_WIDGET)
1942 {
1943 /* buttons checked or otherwise */
1944 if ( EQ (IMAGE_INSTANCE_WIDGET_TYPE (p), Qbutton))
1945 {
1946 if (gui_item_selected_p (&IMAGE_INSTANCE_WIDGET_ITEM (p)))
1947 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p),
1948 BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
1949 else
1950 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (p),
1951 BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
1952 }
1953 }
1954 }
1955
1956 /* register widgets into our hastable so that we can cope with the
1957 callbacks. The hashtable is weak so deregistration is handled
1958 automatically */
1959 static int
1960 mswindows_register_widget_instance (Lisp_Object instance, Lisp_Object domain)
1961 {
1962 Lisp_Object frame = FW_FRAME (domain);
1963 struct frame* f = XFRAME (frame);
1964 int id = gui_item_hash (FRAME_MSWINDOWS_WIDGET_HASH_TABLE (f),
1965 &XIMAGE_INSTANCE_WIDGET_ITEM (instance),
1966 WIDGET_GLYPH_SLOT);
1967 Fputhash (make_int (id),
1968 XIMAGE_INSTANCE_WIDGET_CALLBACK (instance),
1969 FRAME_MSWINDOWS_WIDGET_HASH_TABLE (f));
1970 return id;
1971 }
1972
1973 static void
1974 mswindows_subwindow_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
1975 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
1976 int dest_mask, Lisp_Object domain)
1977 {
1978 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
1979 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii);
1980 struct device* d = XDEVICE (device);
1981 Lisp_Object frame = FW_FRAME (domain);
1982 HWND wnd;
1983
1984 if (!DEVICE_MSWINDOWS_P (d))
1985 signal_simple_error ("Not an mswindows device", device);
1986
1987 /* have to set the type this late in case there is no device
1988 instantiation for a widget */
1989 IMAGE_INSTANCE_TYPE (ii) = IMAGE_SUBWINDOW;
1990
1991 wnd = CreateWindow( "STATIC",
1992 "",
1993 WS_CHILD,
1994 0, /* starting x position */
1995 0, /* starting y position */
1996 IMAGE_INSTANCE_WIDGET_WIDTH (ii),
1997 IMAGE_INSTANCE_WIDGET_HEIGHT (ii),
1998 FRAME_MSWINDOWS_HANDLE (XFRAME (frame)), /* parent window */
1999 0,
2000 (HINSTANCE)
2001 GetWindowLong (FRAME_MSWINDOWS_HANDLE (XFRAME (frame)),
2002 GWL_HINSTANCE),
2003 NULL);
2004
2005 SetWindowLong (wnd, GWL_USERDATA, (LONG)LISP_TO_VOID(image_instance));
2006 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = wnd;
1868 } 2007 }
1869 2008
1870 static int 2009 static int
1871 mswindows_image_instance_equal (struct Lisp_Image_Instance *p1, 2010 mswindows_image_instance_equal (struct Lisp_Image_Instance *p1,
1872 struct Lisp_Image_Instance *p2, int depth) 2011 struct Lisp_Image_Instance *p2, int depth)
1878 case IMAGE_POINTER: 2017 case IMAGE_POINTER:
1879 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p1) 2018 if (IMAGE_INSTANCE_MSWINDOWS_BITMAP (p1)
1880 != IMAGE_INSTANCE_MSWINDOWS_BITMAP (p2)) 2019 != IMAGE_INSTANCE_MSWINDOWS_BITMAP (p2))
1881 return 0; 2020 return 0;
1882 break; 2021 break;
2022
1883 default: 2023 default:
1884 break; 2024 break;
1885 } 2025 }
1886 2026
1887 return 1; 2027 return 1;
1894 { 2034 {
1895 case IMAGE_MONO_PIXMAP: 2035 case IMAGE_MONO_PIXMAP:
1896 case IMAGE_COLOR_PIXMAP: 2036 case IMAGE_COLOR_PIXMAP:
1897 case IMAGE_POINTER: 2037 case IMAGE_POINTER:
1898 return (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p); 2038 return (unsigned long) IMAGE_INSTANCE_MSWINDOWS_BITMAP (p);
2039
1899 default: 2040 default:
1900 return 0; 2041 return 0;
1901 } 2042 }
1902 } 2043 }
1903 2044
1907 instance is already set -- this is the case when instantiate 2048 instance is already set -- this is the case when instantiate
1908 methods are called. */ 2049 methods are called. */
1909 2050
1910 static void 2051 static void
1911 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii, 2052 mswindows_initialize_dibitmap_image_instance (struct Lisp_Image_Instance *ii,
1912 enum image_instance_type type) 2053 enum image_instance_type type)
1913 { 2054 {
1914 ii->data = xnew_and_zero (struct mswindows_image_instance_data); 2055 ii->data = xnew_and_zero (struct mswindows_image_instance_data);
1915 IMAGE_INSTANCE_TYPE (ii) = type; 2056 IMAGE_INSTANCE_TYPE (ii) = type;
1916 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil; 2057 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = Qnil;
1917 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil; 2058 IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (ii) = Qnil;
1921 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil; 2062 IMAGE_INSTANCE_PIXMAP_BG (ii) = Qnil;
1922 } 2063 }
1923 2064
1924 2065
1925 /************************************************************************/ 2066 /************************************************************************/
2067 /* widgets */
2068 /************************************************************************/
2069
2070 static void
2071 mswindows_widget_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2072 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2073 int dest_mask, Lisp_Object domain,
2074 CONST char* class, int flags, int exflags)
2075 {
2076 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2077 #if 0
2078 struct Lisp_Image_Instance *groupii = 0;
2079 Lisp_Object group = find_keyword_in_vector (instantiator, Q_group);
2080 #endif
2081 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii), style;
2082 struct device* d = XDEVICE (device);
2083 Lisp_Object frame = FW_FRAME (domain);
2084 Extbyte* nm=0;
2085 HWND wnd;
2086 int id = 0xffff;
2087 struct gui_item* pgui = &IMAGE_INSTANCE_WIDGET_ITEM (ii);
2088
2089 if (!DEVICE_MSWINDOWS_P (d))
2090 signal_simple_error ("Not an mswindows device", device);
2091 #if 0
2092 /* if the user specified another glyph as a group pick up the
2093 instance in our domain. */
2094 if (!NILP (group))
2095 {
2096 if (SYMBOLP (group))
2097 group = XSYMBOL (group)->value;
2098 group = glyph_image_instance (group, domain, ERROR_ME, 1);
2099 groupii = XIMAGE_INSTANCE (group);
2100 }
2101 #endif
2102 if (!gui_item_active_p (pgui))
2103 flags |= WS_DISABLED;
2104
2105 style = pgui->style;
2106
2107 if (!NILP (pgui->callback))
2108 {
2109 id = mswindows_register_widget_instance (image_instance, domain);
2110 }
2111 /* have to set the type this late in case there is no device
2112 instantiation for a widget */
2113 IMAGE_INSTANCE_TYPE (ii) = IMAGE_WIDGET;
2114 if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii)))
2115 GET_C_STRING_OS_DATA_ALLOCA (IMAGE_INSTANCE_WIDGET_TEXT (ii), nm);
2116
2117 wnd = CreateWindowEx(
2118 exflags /* | WS_EX_NOPARENTNOTIFY*/,
2119 class,
2120 nm,
2121 flags | WS_CHILD,
2122 0, /* starting x position */
2123 0, /* starting y position */
2124 IMAGE_INSTANCE_WIDGET_WIDTH (ii),
2125 IMAGE_INSTANCE_WIDGET_HEIGHT (ii),
2126 /* parent window */
2127 FRAME_MSWINDOWS_HANDLE (XFRAME (frame)),
2128 (HMENU)id, /* No menu */
2129 (HINSTANCE)
2130 GetWindowLong (FRAME_MSWINDOWS_HANDLE (XFRAME (frame)),
2131 GWL_HINSTANCE),
2132 NULL);
2133
2134 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = wnd;
2135 SetWindowLong (wnd, GWL_USERDATA, (LONG)LISP_TO_VOID(image_instance));
2136 /* set the widget font from the widget face */
2137 SendMessage (wnd, WM_SETFONT,
2138 (WPARAM)FONT_INSTANCE_MSWINDOWS_HFONT
2139 (XFONT_INSTANCE (widget_face_font_info
2140 (domain,
2141 IMAGE_INSTANCE_WIDGET_FACE (ii),
2142 0, 0))),
2143 MAKELPARAM (TRUE, 0));
2144 }
2145
2146 /* Instantiate a button widget. Unfortunately instantiated widgets are
2147 particular to a frame since they need to have a parent. It's not
2148 like images where you just select the image into the context you
2149 want to display it in and BitBlt it. So images instances can have a
2150 many-to-one relationship with things you see, whereas widgets can
2151 only be one-to-one (i.e. per frame) */
2152 static void
2153 mswindows_button_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2154 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2155 int dest_mask, Lisp_Object domain)
2156 {
2157 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2158 HWND wnd;
2159 int flags = BS_NOTIFY;
2160 Lisp_Object style;
2161 struct gui_item* pgui = &IMAGE_INSTANCE_WIDGET_ITEM (ii);
2162
2163 if (!gui_item_active_p (pgui))
2164 flags |= WS_DISABLED;
2165
2166 style = pgui->style;
2167
2168 if (EQ (style, Qradio))
2169 {
2170 flags |= BS_RADIOBUTTON;
2171 }
2172 else if (EQ (style, Qtoggle))
2173 {
2174 flags |= BS_AUTOCHECKBOX;
2175 }
2176 else
2177 flags |= BS_DEFPUSHBUTTON;
2178
2179 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2180 pointer_bg, dest_mask, domain, "BUTTON", flags,
2181 WS_EX_CONTROLPARENT);
2182
2183 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2184 /* set the checked state */
2185 if (gui_item_selected_p (pgui))
2186 SendMessage (wnd, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
2187 else
2188 SendMessage (wnd, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
2189 }
2190
2191 /* instantiate an edit control */
2192 static void
2193 mswindows_edit_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2194 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2195 int dest_mask, Lisp_Object domain)
2196 {
2197 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2198 pointer_bg, dest_mask, domain, "EDIT",
2199 ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP
2200 | WS_BORDER,
2201 WS_EX_CLIENTEDGE | WS_EX_CONTROLPARENT);
2202 }
2203
2204 /* instantiate a static control possible for putting other things in */
2205 static void
2206 mswindows_label_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2207 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2208 int dest_mask, Lisp_Object domain)
2209 {
2210 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2211 pointer_bg, dest_mask, domain, "STATIC",
2212 0, WS_EX_STATICEDGE);
2213 }
2214
2215 #if 0
2216 /* instantiate a static control possible for putting other things in */
2217 static void
2218 mswindows_group_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2219 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2220 int dest_mask, Lisp_Object domain)
2221 {
2222 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2223 pointer_bg, dest_mask, domain, "BUTTON",
2224 WS_GROUP | BS_GROUPBOX | WS_BORDER,
2225 WS_EX_CLIENTEDGE );
2226 }
2227 #endif
2228
2229 /* instantiate a scrollbar control */
2230 static void
2231 mswindows_scrollbar_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2232 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2233 int dest_mask, Lisp_Object domain)
2234 {
2235 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2236 pointer_bg, dest_mask, domain, "SCROLLBAR",
2237 0,
2238 WS_EX_CLIENTEDGE );
2239 }
2240
2241 /* instantiate a combo control */
2242 static void
2243 mswindows_combo_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
2244 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
2245 int dest_mask, Lisp_Object domain)
2246 {
2247 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2248 HANDLE wnd;
2249 Lisp_Object rest;
2250
2251 /* Maybe ought to generalise this more but it may be very windows
2252 specific. In windows the window height of a combo box is the
2253 height when the combo box is open. Thus we need to set the height
2254 before creating the window and then reset it to a single line
2255 after the window is created so that redisplay does the right
2256 thing. */
2257 mswindows_widget_instantiate (image_instance, instantiator, pointer_fg,
2258 pointer_bg, dest_mask, domain, "COMBOBOX",
2259 WS_BORDER | WS_TABSTOP | CBS_DROPDOWN
2260 | CBS_AUTOHSCROLL
2261 | CBS_HASSTRINGS | WS_VSCROLL,
2262 WS_EX_CLIENTEDGE | WS_EX_CONTROLPARENT);
2263 /* reset the height */
2264 widget_text_to_pixel_conversion (domain,
2265 IMAGE_INSTANCE_WIDGET_FACE (ii), 1, 0,
2266 &IMAGE_INSTANCE_SUBWINDOW_HEIGHT (ii), 0);
2267 wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2268 /* add items to the combo box */
2269 SendMessage (wnd, CB_RESETCONTENT, 0, 0);
2270 LIST_LOOP (rest, Fplist_get (IMAGE_INSTANCE_WIDGET_PROPS (ii), Q_items, Qnil))
2271 {
2272 Extbyte* lparam;
2273 GET_C_STRING_OS_DATA_ALLOCA (XCAR (rest), lparam);
2274 if (SendMessage (wnd, CB_ADDSTRING, 0, (LPARAM)lparam) == CB_ERR)
2275 signal_simple_error ("error adding combo entries", instantiator);
2276 }
2277 }
2278
2279 /* get properties of a control */
2280 static Lisp_Object
2281 mswindows_widget_property (Lisp_Object image_instance, Lisp_Object prop)
2282 {
2283 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2284 HANDLE wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2285 /* get the text from a control */
2286 if (EQ (prop, Qtext))
2287 {
2288 Extcount len = SendMessage (wnd, WM_GETTEXTLENGTH, 0, 0);
2289 Extbyte* buf =alloca (len+1);
2290
2291 SendMessage (wnd, WM_GETTEXT, (WPARAM)len+1, (LPARAM) buf);
2292 return build_ext_string (buf, FORMAT_OS);
2293 }
2294 return Qunbound;
2295 }
2296
2297 /* get properties of a button */
2298 static Lisp_Object
2299 mswindows_button_property (Lisp_Object image_instance, Lisp_Object prop)
2300 {
2301 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2302 HANDLE wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2303 /* check the state of a button */
2304 if (EQ (prop, Qselected))
2305 {
2306 if (SendMessage (wnd, BM_GETSTATE, 0, 0) & BST_CHECKED)
2307 return Qt;
2308 else
2309 return Qnil;
2310 }
2311 return Qunbound;
2312 }
2313
2314 /* get properties of a combo box */
2315 static Lisp_Object
2316 mswindows_combo_property (Lisp_Object image_instance, Lisp_Object prop)
2317 {
2318 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2319 HANDLE wnd = WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii);
2320 /* get the text from a control */
2321 if (EQ (prop, Qtext))
2322 {
2323 long item = SendMessage (wnd, CB_GETCURSEL, 0, 0);
2324 Extcount len = SendMessage (wnd, CB_GETLBTEXTLEN, (WPARAM)item, 0);
2325 Extbyte* buf = alloca (len+1);
2326 SendMessage (wnd, CB_GETLBTEXT, (WPARAM)item, (LPARAM)buf);
2327 return build_ext_string (buf, FORMAT_OS);
2328 }
2329 return Qunbound;
2330 }
2331
2332 /* set the properties of a control */
2333 static Lisp_Object
2334 mswindows_widget_set_property (Lisp_Object image_instance, Lisp_Object prop,
2335 Lisp_Object val)
2336 {
2337 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
2338
2339 if (EQ (prop, Qtext))
2340 {
2341 Extbyte* lparam=0;
2342 CHECK_STRING (val);
2343 GET_C_STRING_OS_DATA_ALLOCA (val, lparam);
2344 SendMessage (WIDGET_INSTANCE_MSWINDOWS_HANDLE (ii),
2345 WM_SETTEXT, 0, (LPARAM)lparam);
2346 return Qt;
2347 }
2348 return Qunbound;
2349 }
2350
2351
2352 /************************************************************************/
1926 /* initialization */ 2353 /* initialization */
1927 /************************************************************************/ 2354 /************************************************************************/
1928 2355
1929 void 2356 void
1930 syms_of_glyphs_mswindows (void) 2357 syms_of_glyphs_mswindows (void)
1938 { 2365 {
1939 /* image methods */ 2366 /* image methods */
1940 2367
1941 CONSOLE_HAS_METHOD (mswindows, print_image_instance); 2368 CONSOLE_HAS_METHOD (mswindows, print_image_instance);
1942 CONSOLE_HAS_METHOD (mswindows, finalize_image_instance); 2369 CONSOLE_HAS_METHOD (mswindows, finalize_image_instance);
2370 CONSOLE_HAS_METHOD (mswindows, unmap_subwindow);
2371 CONSOLE_HAS_METHOD (mswindows, map_subwindow);
2372 CONSOLE_HAS_METHOD (mswindows, update_subwindow);
1943 CONSOLE_HAS_METHOD (mswindows, image_instance_equal); 2373 CONSOLE_HAS_METHOD (mswindows, image_instance_equal);
1944 CONSOLE_HAS_METHOD (mswindows, image_instance_hash); 2374 CONSOLE_HAS_METHOD (mswindows, image_instance_hash);
1945 CONSOLE_HAS_METHOD (mswindows, init_image_instance_from_eimage); 2375 CONSOLE_HAS_METHOD (mswindows, init_image_instance_from_eimage);
1946 CONSOLE_HAS_METHOD (mswindows, locate_pixmap_file); 2376 CONSOLE_HAS_METHOD (mswindows, locate_pixmap_file);
1947 #ifdef HAVE_XPM
1948 CONSOLE_HAS_METHOD (mswindows, xpm_instantiate);
1949 #endif
1950 CONSOLE_HAS_METHOD (mswindows, xbm_instantiate);
1951 } 2377 }
1952 2378
1953 void 2379 void
1954 image_instantiator_format_create_glyphs_mswindows (void) 2380 image_instantiator_format_create_glyphs_mswindows (void)
1955 { 2381 {
1956 /* image-instantiator types */ 2382 /* image-instantiator types */
2383 #ifdef HAVE_XPM
2384 INITIALIZE_DEVICE_IIFORMAT (mswindows, xpm);
2385 IIFORMAT_HAS_DEVMETHOD (mswindows, xpm, instantiate);
2386 #endif
2387 INITIALIZE_DEVICE_IIFORMAT (mswindows, xbm);
2388 IIFORMAT_HAS_DEVMETHOD (mswindows, xbm, instantiate);
2389
2390 INITIALIZE_DEVICE_IIFORMAT (mswindows, button);
2391 IIFORMAT_HAS_DEVMETHOD (mswindows, button, property);
2392 IIFORMAT_HAS_DEVMETHOD (mswindows, button, instantiate);
2393
2394 INITIALIZE_DEVICE_IIFORMAT (mswindows, edit);
2395 IIFORMAT_HAS_DEVMETHOD (mswindows, edit, instantiate);
2396
2397 INITIALIZE_DEVICE_IIFORMAT (mswindows, subwindow);
2398 IIFORMAT_HAS_DEVMETHOD (mswindows, subwindow, instantiate);
2399
2400 INITIALIZE_DEVICE_IIFORMAT (mswindows, widget);
2401 IIFORMAT_HAS_DEVMETHOD (mswindows, widget, property);
2402 IIFORMAT_HAS_DEVMETHOD (mswindows, widget, set_property);
2403 #if 0
2404 INITIALIZE_DEVICE_IIFORMAT (mswindows, group);
2405 IIFORMAT_HAS_DEVMETHOD (mswindows, group, instantiate);
2406 #endif
2407 INITIALIZE_DEVICE_IIFORMAT (mswindows, label);
2408 IIFORMAT_HAS_DEVMETHOD (mswindows, label, instantiate);
2409
2410 INITIALIZE_DEVICE_IIFORMAT (mswindows, combo);
2411 IIFORMAT_HAS_DEVMETHOD (mswindows, combo, property);
2412 IIFORMAT_HAS_DEVMETHOD (mswindows, combo, instantiate);
2413
2414 INITIALIZE_DEVICE_IIFORMAT (mswindows, scrollbar);
2415 IIFORMAT_HAS_DEVMETHOD (mswindows, scrollbar, instantiate);
1957 2416
1958 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (bmp, "bmp"); 2417 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (bmp, "bmp");
1959 2418
1960 IIFORMAT_HAS_METHOD (bmp, validate); 2419 IIFORMAT_HAS_METHOD (bmp, validate);
1961 IIFORMAT_HAS_METHOD (bmp, normalize); 2420 IIFORMAT_HAS_METHOD (bmp, normalize);
1987 DEFVAR_LISP ("mswindows-bitmap-file-path", &Vmswindows_bitmap_file_path /* 2446 DEFVAR_LISP ("mswindows-bitmap-file-path", &Vmswindows_bitmap_file_path /*
1988 A list of the directories in which mswindows bitmap files may be found. 2447 A list of the directories in which mswindows bitmap files may be found.
1989 This is used by the `make-image-instance' function. 2448 This is used by the `make-image-instance' function.
1990 */ ); 2449 */ );
1991 Vmswindows_bitmap_file_path = Qnil; 2450 Vmswindows_bitmap_file_path = Qnil;
2451
2452 Fprovide (Qbutton);
2453 Fprovide (Qedit);
2454 Fprovide (Qcombo);
2455 Fprovide (Qscrollbar);
2456 Fprovide (Qlabel);
1992 } 2457 }
1993 2458
1994 void 2459 void
1995 complex_vars_of_glyphs_mswindows (void) 2460 complex_vars_of_glyphs_mswindows (void)
1996 { 2461 {