comparison win/dw.c @ 1614:702de58e9ef8

Initial UTF8 support for Windows. Window/widget creation and dw_window_set/get_text() now support UTF8. MLE and other internal functionality still need to be updated.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 26 Mar 2012 21:51:02 +0000
parents fd3b7784ab53
children f8d1da63fb77
comparison
equal deleted inserted replaced
1613:fd3b7784ab53 1614:702de58e9ef8
431 argv = _convertargs(&argc, lpCmdLine); 431 argv = _convertargs(&argc, lpCmdLine);
432 432
433 return main(argc, argv); 433 return main(argc, argv);
434 } 434 }
435 #endif 435 #endif
436
437 /* Macro and internal function to convert UTF8 to Unicode wide characters */
438 #define UTF8toWide(a) _myUTF8toWide(a, a ? _alloca(MultiByteToWideChar(CP_UTF8, 0, a, -1, NULL, 0) * sizeof(WCHAR)) : NULL)
439 LPWSTR _myUTF8toWide(char *utf8string, void *outbuf)
440 {
441 LPWSTR retbuf = outbuf;
442
443 if(retbuf)
444 MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, retbuf, MultiByteToWideChar(CP_UTF8, 0, utf8string, -1, NULL, 0) * sizeof(WCHAR));
445 return retbuf;
446 }
436 447
437 DWORD GetDllVersion(LPCTSTR lpszDllName) 448 DWORD GetDllVersion(LPCTSTR lpszDllName)
438 { 449 {
439 450
440 HINSTANCE hinstDll; 451 HINSTANCE hinstDll;
3899 * temporary window that isn't visible and really does nothing 3910 * temporary window that isn't visible and really does nothing
3900 * except temporarily hold the child windows before they are 3911 * except temporarily hold the child windows before they are
3901 * packed into their correct parent. 3912 * packed into their correct parent.
3902 */ 3913 */
3903 3914
3904 DW_HWND_OBJECT = CreateWindow(ObjectClassName, "", 0, 0, 0, 3915 DW_HWND_OBJECT = CreateWindow(ObjectClassName, NULL, 0, 0, 0,
3905 0, 0, HWND_DESKTOP, NULL, DWInstance, NULL); 3916 0, 0, HWND_DESKTOP, NULL, DWInstance, NULL);
3906 3917
3907 if(!DW_HWND_OBJECT) 3918 if(!DW_HWND_OBJECT)
3908 { 3919 {
3909 dw_messagebox("Dynamic Windows", DW_MB_OK|DW_MB_ERROR, "Could not initialize the object window. error code %d", GetLastError()); 3920 dw_messagebox("Dynamic Windows", DW_MB_OK|DW_MB_ERROR, "Could not initialize the object window. error code %d", GetLastError());
5024 flStyle |= WS_POPUPWINDOW; 5035 flStyle |= WS_POPUPWINDOW;
5025 5036
5026 if(flStyle & DW_FCF_TASKLIST || 5037 if(flStyle & DW_FCF_TASKLIST ||
5027 flStyle & WS_VSCROLL /* This is deprecated and should go away in version 3? */) 5038 flStyle & WS_VSCROLL /* This is deprecated and should go away in version 3? */)
5028 { 5039 {
5029 hwndframe = CreateWindowEx(flStyleEx, ClassName, title, (flStyle | WS_CLIPCHILDREN) & 0xffdf0000, CW_USEDEFAULT, CW_USEDEFAULT, 5040 hwndframe = CreateWindowExW(flStyleEx, UTF8toWide(ClassName), UTF8toWide(title), (flStyle | WS_CLIPCHILDREN) & 0xffdf0000, CW_USEDEFAULT, CW_USEDEFAULT,
5030 0, 0, hwndOwner, NULL, DWInstance, NULL); 5041 0, 0, hwndOwner, NULL, DWInstance, NULL);
5031 } 5042 }
5032 else 5043 else
5033 { 5044 {
5034 flStyleEx |= WS_EX_TOOLWINDOW; 5045 flStyleEx |= WS_EX_TOOLWINDOW;
5035 5046
5036 hwndframe = CreateWindowEx(flStyleEx, ClassName, title, (flStyle | WS_CLIPCHILDREN) & 0xffff0000, CW_USEDEFAULT, CW_USEDEFAULT, 5047 hwndframe = CreateWindowExW(flStyleEx, UTF8toWide(ClassName), UTF8toWide(title), (flStyle | WS_CLIPCHILDREN) & 0xffff0000, CW_USEDEFAULT, CW_USEDEFAULT,
5037 0, 0, hwndOwner, NULL, DWInstance, NULL); 5048 0, 0, hwndOwner, NULL, DWInstance, NULL);
5038 } 5049 }
5039 SetWindowLongPtr(hwndframe, GWLP_USERDATA, (LONG_PTR)newbox); 5050 SetWindowLongPtr(hwndframe, GWLP_USERDATA, (LONG_PTR)newbox);
5040 5051
5041 if(hwndOwner) 5052 if(hwndOwner)
5069 newbox->count = 0; 5080 newbox->count = 0;
5070 newbox->grouphwnd = (HWND)NULL; 5081 newbox->grouphwnd = (HWND)NULL;
5071 newbox->cinfo.fore = newbox->cinfo.back = -1; 5082 newbox->cinfo.fore = newbox->cinfo.back = -1;
5072 5083
5073 hwndframe = CreateWindow(FRAMECLASSNAME, 5084 hwndframe = CreateWindow(FRAMECLASSNAME,
5074 "", 5085 NULL,
5075 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, 5086 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN,
5076 0,0,0,0, 5087 0,0,0,0,
5077 DW_HWND_OBJECT, 5088 DW_HWND_OBJECT,
5078 NULL, 5089 NULL,
5079 DWInstance, 5090 DWInstance,
5100 dw_box_pack_start(tmpbox, box, 1, 1, TRUE, TRUE, 0); 5111 dw_box_pack_start(tmpbox, box, 1, 1, TRUE, TRUE, 0);
5101 5112
5102 cinfo->fore = cinfo->back = -1; 5113 cinfo->fore = cinfo->back = -1;
5103 5114
5104 hwndframe = CreateWindow(ScrollClassName, 5115 hwndframe = CreateWindow(ScrollClassName,
5105 "", 5116 NULL,
5106 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL, 5117 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL | WS_HSCROLL,
5107 0,0,0,0, 5118 0,0,0,0,
5108 DW_HWND_OBJECT, 5119 DW_HWND_OBJECT,
5109 NULL, 5120 NULL,
5110 DWInstance, 5121 DWInstance,
5186 newbox->type = type; 5197 newbox->type = type;
5187 newbox->count = 0; 5198 newbox->count = 0;
5188 newbox->cinfo.fore = newbox->cinfo.back = -1; 5199 newbox->cinfo.fore = newbox->cinfo.back = -1;
5189 5200
5190 hwndframe = CreateWindow(FRAMECLASSNAME, 5201 hwndframe = CreateWindow(FRAMECLASSNAME,
5191 "", 5202 NULL,
5192 WS_VISIBLE | WS_CHILD, 5203 WS_VISIBLE | WS_CHILD,
5193 0,0,0,0, 5204 0,0,0,0,
5194 DW_HWND_OBJECT, 5205 DW_HWND_OBJECT,
5195 NULL, 5206 NULL,
5196 DWInstance, 5207 DWInstance,
5197 NULL); 5208 NULL);
5198 5209
5199 newbox->grouphwnd = CreateWindow(BUTTONCLASSNAME, 5210 newbox->grouphwnd = CreateWindowW(UTF8toWide(BUTTONCLASSNAME),
5200 title, 5211 UTF8toWide(title),
5201 WS_CHILD | BS_GROUPBOX | 5212 WS_CHILD | BS_GROUPBOX |
5202 WS_VISIBLE | WS_CLIPCHILDREN, 5213 WS_VISIBLE | WS_CLIPCHILDREN,
5203 0,0,0,0, 5214 0,0,0,0,
5204 hwndframe, 5215 hwndframe,
5205 NULL, 5216 NULL,
5223 5234
5224 ccs.hWindowMenu = NULL; 5235 ccs.hWindowMenu = NULL;
5225 ccs.idFirstChild = 0; 5236 ccs.idFirstChild = 0;
5226 5237
5227 hwndframe = CreateWindow("MDICLIENT", 5238 hwndframe = CreateWindow("MDICLIENT",
5228 "", 5239 NULL,
5229 WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, 5240 WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS,
5230 0,0,0,0, 5241 0,0,0,0,
5231 DW_HWND_OBJECT, 5242 DW_HWND_OBJECT,
5232 (HMENU)id, 5243 (HMENU)id,
5233 DWInstance, 5244 DWInstance,
5242 */ 5253 */
5243 HWND API dw_html_new(unsigned long id) 5254 HWND API dw_html_new(unsigned long id)
5244 { 5255 {
5245 #if (defined(BUILD_DLL) || defined(BUILD_HTML)) && !defined(__MINGW32__) 5256 #if (defined(BUILD_DLL) || defined(BUILD_HTML)) && !defined(__MINGW32__)
5246 return CreateWindow(BrowserClassName, 5257 return CreateWindow(BrowserClassName,
5247 "", 5258 NULL,
5248 WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, 5259 WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS,
5249 0,0,0,0, 5260 0,0,0,0,
5250 DW_HWND_OBJECT, 5261 DW_HWND_OBJECT,
5251 (HMENU)id, 5262 (HMENU)id,
5252 DWInstance, 5263 DWInstance,
5318 * id: An ID to be used with dw_window_from_id or 0L. 5329 * id: An ID to be used with dw_window_from_id or 0L.
5319 */ 5330 */
5320 HWND API dw_bitmap_new(ULONG id) 5331 HWND API dw_bitmap_new(ULONG id)
5321 { 5332 {
5322 return CreateWindow(STATICCLASSNAME, 5333 return CreateWindow(STATICCLASSNAME,
5323 "", 5334 NULL,
5324 SS_BITMAP | SS_CENTERIMAGE | WS_VISIBLE | 5335 SS_BITMAP | SS_CENTERIMAGE | WS_VISIBLE |
5325 WS_CHILD | WS_CLIPCHILDREN, 5336 WS_CHILD | WS_CLIPCHILDREN,
5326 0,0,0,0, 5337 0,0,0,0,
5327 DW_HWND_OBJECT, 5338 DW_HWND_OBJECT,
5328 (HMENU)id, 5339 (HMENU)id,
5344 5355
5345 if(!top) 5356 if(!top)
5346 flags = TCS_BOTTOM; 5357 flags = TCS_BOTTOM;
5347 5358
5348 tmp = CreateWindow(WC_TABCONTROL, 5359 tmp = CreateWindow(WC_TABCONTROL,
5349 "", 5360 NULL,
5350 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | flags, 5361 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | flags,
5351 0,0,0,0, 5362 0,0,0,0,
5352 DW_HWND_OBJECT, 5363 DW_HWND_OBJECT,
5353 (HMENU)id, 5364 (HMENU)id,
5354 DWInstance, 5365 DWInstance,
5742 * resource file. 5753 * resource file.
5743 */ 5754 */
5744 HWND API dw_container_new(ULONG id, int multi) 5755 HWND API dw_container_new(ULONG id, int multi)
5745 { 5756 {
5746 HWND tmp = CreateWindow(WC_LISTVIEW, 5757 HWND tmp = CreateWindow(WC_LISTVIEW,
5747 "", 5758 NULL,
5748 WS_VISIBLE | WS_CHILD | 5759 WS_VISIBLE | WS_CHILD |
5749 (multi ? 0 : LVS_SINGLESEL) | 5760 (multi ? 0 : LVS_SINGLESEL) |
5750 LVS_REPORT | LVS_SHOWSELALWAYS | 5761 LVS_REPORT | LVS_SHOWSELALWAYS |
5751 LVS_SHAREIMAGELISTS | WS_BORDER | 5762 LVS_SHAREIMAGELISTS | WS_BORDER |
5752 WS_CLIPCHILDREN, 5763 WS_CLIPCHILDREN,
5785 * resource file. 5796 * resource file.
5786 */ 5797 */
5787 HWND API dw_tree_new(ULONG id) 5798 HWND API dw_tree_new(ULONG id)
5788 { 5799 {
5789 HWND tmp = CreateWindow(WC_TREEVIEW, 5800 HWND tmp = CreateWindow(WC_TREEVIEW,
5790 "", 5801 NULL,
5791 WS_VISIBLE | WS_CHILD | 5802 WS_VISIBLE | WS_CHILD |
5792 TVS_HASLINES | TVS_SHOWSELALWAYS | 5803 TVS_HASLINES | TVS_SHOWSELALWAYS |
5793 TVS_HASBUTTONS | TVS_LINESATROOT | 5804 TVS_HASBUTTONS | TVS_LINESATROOT |
5794 WS_BORDER | WS_CLIPCHILDREN, 5805 WS_BORDER | WS_CLIPCHILDREN,
5795 0,0,0,0, 5806 0,0,0,0,
5850 * text: The text to be display by the static text widget. 5861 * text: The text to be display by the static text widget.
5851 * id: An ID to be used with dw_window_from_id() or 0L. 5862 * id: An ID to be used with dw_window_from_id() or 0L.
5852 */ 5863 */
5853 HWND API dw_text_new(char *text, ULONG id) 5864 HWND API dw_text_new(char *text, ULONG id)
5854 { 5865 {
5855 HWND tmp = CreateWindow(STATICCLASSNAME, 5866 HWND tmp = CreateWindowW(UTF8toWide(STATICCLASSNAME),
5856 text, 5867 UTF8toWide(text),
5857 SS_NOPREFIX | SS_NOTIFY | WS_VISIBLE | 5868 SS_NOPREFIX | SS_NOTIFY | WS_VISIBLE |
5858 WS_CHILD | WS_CLIPCHILDREN, 5869 WS_CHILD | WS_CLIPCHILDREN,
5859 0,0,0,0, 5870 0,0,0,0,
5860 DW_HWND_OBJECT, 5871 DW_HWND_OBJECT,
5861 (HMENU)id, 5872 (HMENU)id,
5880 * text: The text to be display by the static text widget. 5891 * text: The text to be display by the static text widget.
5881 * id: An ID to be used with dw_window_from_id() or 0L. 5892 * id: An ID to be used with dw_window_from_id() or 0L.
5882 */ 5893 */
5883 HWND API dw_status_text_new(char *text, ULONG id) 5894 HWND API dw_status_text_new(char *text, ULONG id)
5884 { 5895 {
5885 HWND tmp = CreateWindow(StatusbarClassName, 5896 HWND tmp = CreateWindowW(UTF8toWide(StatusbarClassName),
5886 text, 5897 UTF8toWide(text),
5887 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, 5898 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN,
5888 0,0,0,0, 5899 0,0,0,0,
5889 DW_HWND_OBJECT, 5900 DW_HWND_OBJECT,
5890 (HMENU)id, 5901 (HMENU)id,
5891 DWInstance, 5902 DWInstance,
5902 HWND API dw_mle_new(ULONG id) 5913 HWND API dw_mle_new(ULONG id)
5903 { 5914 {
5904 5915
5905 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, 5916 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE,
5906 hrichedit ? RICHEDIT_CLASS : EDITCLASSNAME, 5917 hrichedit ? RICHEDIT_CLASS : EDITCLASSNAME,
5907 "", 5918 NULL,
5908 WS_VISIBLE | WS_BORDER | 5919 WS_VISIBLE | WS_BORDER |
5909 WS_VSCROLL | ES_MULTILINE | 5920 WS_VSCROLL | ES_MULTILINE |
5910 ES_WANTRETURN | WS_CHILD | 5921 ES_WANTRETURN | WS_CHILD |
5911 WS_CLIPCHILDREN, 5922 WS_CLIPCHILDREN,
5912 0,0,0,0, 5923 0,0,0,0,
5937 * text: The default text to be in the entryfield widget. 5948 * text: The default text to be in the entryfield widget.
5938 * id: An ID to be used with dw_window_from_id() or 0L. 5949 * id: An ID to be used with dw_window_from_id() or 0L.
5939 */ 5950 */
5940 HWND API dw_entryfield_new(char *text, ULONG id) 5951 HWND API dw_entryfield_new(char *text, ULONG id)
5941 { 5952 {
5942 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, 5953 HWND tmp = CreateWindowExW(WS_EX_CLIENTEDGE,
5943 EDITCLASSNAME, 5954 UTF8toWide(EDITCLASSNAME),
5944 text, 5955 UTF8toWide(text),
5945 ES_WANTRETURN | WS_CHILD | 5956 ES_WANTRETURN | WS_CHILD |
5946 WS_BORDER | ES_AUTOHSCROLL | 5957 WS_BORDER | ES_AUTOHSCROLL |
5947 WS_VISIBLE | WS_CLIPCHILDREN, 5958 WS_VISIBLE | WS_CLIPCHILDREN,
5948 0,0,0,0, 5959 0,0,0,0,
5949 DW_HWND_OBJECT, 5960 DW_HWND_OBJECT,
5966 * text: The default text to be in the entryfield widget. 5977 * text: The default text to be in the entryfield widget.
5967 * id: An ID to be used with dw_window_from_id() or 0L. 5978 * id: An ID to be used with dw_window_from_id() or 0L.
5968 */ 5979 */
5969 HWND API dw_entryfield_password_new(char *text, ULONG id) 5980 HWND API dw_entryfield_password_new(char *text, ULONG id)
5970 { 5981 {
5971 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, 5982 HWND tmp = CreateWindowExW(WS_EX_CLIENTEDGE,
5972 EDITCLASSNAME, 5983 UTF8toWide(EDITCLASSNAME),
5973 text, 5984 UTF8toWide(text),
5974 ES_WANTRETURN | WS_CHILD | 5985 ES_WANTRETURN | WS_CHILD |
5975 ES_PASSWORD | WS_BORDER | WS_VISIBLE | 5986 ES_PASSWORD | WS_BORDER | WS_VISIBLE |
5976 ES_AUTOHSCROLL | WS_CLIPCHILDREN, 5987 ES_AUTOHSCROLL | WS_CLIPCHILDREN,
5977 0,0,0,0, 5988 0,0,0,0,
5978 DW_HWND_OBJECT, 5989 DW_HWND_OBJECT,
6008 * text: The default text to be in the combpbox widget. 6019 * text: The default text to be in the combpbox widget.
6009 * id: An ID to be used with dw_window_from_id() or 0L. 6020 * id: An ID to be used with dw_window_from_id() or 0L.
6010 */ 6021 */
6011 HWND API dw_combobox_new(char *text, ULONG id) 6022 HWND API dw_combobox_new(char *text, ULONG id)
6012 { 6023 {
6013 HWND tmp = CreateWindow(COMBOBOXCLASSNAME, 6024 HWND tmp = CreateWindowW(UTF8toWide(COMBOBOXCLASSNAME),
6014 text, 6025 UTF8toWide(text),
6015 WS_CHILD | CBS_DROPDOWN | WS_VSCROLL | 6026 WS_CHILD | CBS_DROPDOWN | WS_VSCROLL |
6016 WS_CLIPCHILDREN | CBS_AUTOHSCROLL | WS_VISIBLE, 6027 WS_CLIPCHILDREN | CBS_AUTOHSCROLL | WS_VISIBLE,
6017 0,0,0,0, 6028 0,0,0,0,
6018 DW_HWND_OBJECT, 6029 DW_HWND_OBJECT,
6019 (HMENU)id, 6030 (HMENU)id,
6038 EnumChildWindows(tmp, _subclass_child, (LPARAM)cinfo2); 6049 EnumChildWindows(tmp, _subclass_child, (LPARAM)cinfo2);
6039 cinfo->buddy = cinfo2->buddy; 6050 cinfo->buddy = cinfo2->buddy;
6040 6051
6041 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo); 6052 SetWindowLongPtr(tmp, GWLP_USERDATA, (LONG_PTR)cinfo);
6042 dw_window_set_font(tmp, DefaultFont); 6053 dw_window_set_font(tmp, DefaultFont);
6043 SetWindowText(tmp, text); 6054 SetWindowTextW(tmp, UTF8toWide(text));
6044 return tmp; 6055 return tmp;
6045 } 6056 }
6046 6057
6047 /* 6058 /*
6048 * Create a new button window (widget) to be packed. 6059 * Create a new button window (widget) to be packed.
6052 */ 6063 */
6053 HWND API dw_button_new(char *text, ULONG id) 6064 HWND API dw_button_new(char *text, ULONG id)
6054 { 6065 {
6055 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); 6066 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo));
6056 6067
6057 HWND tmp = CreateWindow(BUTTONCLASSNAME, 6068 HWND tmp = CreateWindowW(UTF8toWide(BUTTONCLASSNAME),
6058 text, 6069 UTF8toWide(text),
6059 WS_CHILD | BS_PUSHBUTTON | 6070 WS_CHILD | BS_PUSHBUTTON |
6060 WS_VISIBLE | WS_CLIPCHILDREN, 6071 WS_VISIBLE | WS_CLIPCHILDREN,
6061 0,0,0,0, 6072 0,0,0,0,
6062 DW_HWND_OBJECT, 6073 DW_HWND_OBJECT,
6063 (HMENU)id, 6074 (HMENU)id,
6083 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); 6094 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo));
6084 HBITMAP hbitmap = LoadBitmap(DWInstance, MAKEINTRESOURCE(id)); 6095 HBITMAP hbitmap = LoadBitmap(DWInstance, MAKEINTRESOURCE(id));
6085 HICON icon = LoadImage(DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_SHARED); 6096 HICON icon = LoadImage(DWInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 0, 0, LR_SHARED);
6086 6097
6087 tmp = CreateWindow(BUTTONCLASSNAME, 6098 tmp = CreateWindow(BUTTONCLASSNAME,
6088 "", 6099 NULL,
6089 WS_CHILD | BS_PUSHBUTTON | 6100 WS_CHILD | BS_PUSHBUTTON |
6090 WS_VISIBLE | WS_CLIPCHILDREN | 6101 WS_VISIBLE | WS_CLIPCHILDREN |
6091 (icon ? BS_ICON : BS_BITMAP), 6102 (icon ? BS_ICON : BS_BITMAP),
6092 0,0,0,0, 6103 0,0,0,0,
6093 DW_HWND_OBJECT, 6104 DW_HWND_OBJECT,
6144 #else 6155 #else
6145 windowtype = _dw_get_image_handle(filename, &hicon, &hbitmap); 6156 windowtype = _dw_get_image_handle(filename, &hicon, &hbitmap);
6146 #endif 6157 #endif
6147 6158
6148 tmp = CreateWindow( BUTTONCLASSNAME, 6159 tmp = CreateWindow( BUTTONCLASSNAME,
6149 "", 6160 NULL,
6150 windowtype | WS_CHILD | BS_PUSHBUTTON | WS_CLIPCHILDREN | WS_VISIBLE, 6161 windowtype | WS_CHILD | BS_PUSHBUTTON | WS_CLIPCHILDREN | WS_VISIBLE,
6151 0,0,0,0, 6162 0,0,0,0,
6152 DW_HWND_OBJECT, 6163 DW_HWND_OBJECT,
6153 (HMENU)id, 6164 (HMENU)id,
6154 DWInstance, 6165 DWInstance,
6226 _unlink( file ); 6237 _unlink( file );
6227 free( file ); 6238 free( file );
6228 } 6239 }
6229 6240
6230 tmp = CreateWindow( BUTTONCLASSNAME, 6241 tmp = CreateWindow( BUTTONCLASSNAME,
6231 "", 6242 NULL,
6232 WS_CHILD | BS_PUSHBUTTON | 6243 WS_CHILD | BS_PUSHBUTTON |
6233 windowtype | WS_CLIPCHILDREN | 6244 windowtype | WS_CLIPCHILDREN |
6234 WS_VISIBLE, 6245 WS_VISIBLE,
6235 0,0,0,0, 6246 0,0,0,0,
6236 DW_HWND_OBJECT, 6247 DW_HWND_OBJECT,
6262 * text: The text to be display by the static text widget. 6273 * text: The text to be display by the static text widget.
6263 * id: An ID to be used with dw_window_from_id() or 0L. 6274 * id: An ID to be used with dw_window_from_id() or 0L.
6264 */ 6275 */
6265 HWND API dw_spinbutton_new(char *text, ULONG id) 6276 HWND API dw_spinbutton_new(char *text, ULONG id)
6266 { 6277 {
6267 HWND buddy = CreateWindowEx(WS_EX_CLIENTEDGE, 6278 HWND buddy = CreateWindowExW(WS_EX_CLIENTEDGE,
6268 EDITCLASSNAME, 6279 UTF8toWide(EDITCLASSNAME),
6269 text, 6280 UTF8toWide(text),
6270 WS_CHILD | WS_BORDER | WS_VISIBLE | 6281 WS_CHILD | WS_BORDER | WS_VISIBLE |
6271 ES_NUMBER | WS_CLIPCHILDREN, 6282 ES_NUMBER | WS_CLIPCHILDREN,
6272 0,0,0,0, 6283 0,0,0,0,
6273 DW_HWND_OBJECT, 6284 DW_HWND_OBJECT,
6274 NULL, 6285 NULL,
6317 * text: The text to be display by the static text widget. 6328 * text: The text to be display by the static text widget.
6318 * id: An ID to be used with dw_window_from_id() or 0L. 6329 * id: An ID to be used with dw_window_from_id() or 0L.
6319 */ 6330 */
6320 HWND API dw_radiobutton_new(char *text, ULONG id) 6331 HWND API dw_radiobutton_new(char *text, ULONG id)
6321 { 6332 {
6322 HWND tmp = CreateWindow(BUTTONCLASSNAME, 6333 HWND tmp = CreateWindowW(UTF8toWide(BUTTONCLASSNAME),
6323 text, 6334 UTF8toWide(text),
6324 WS_CHILD | BS_AUTORADIOBUTTON | 6335 WS_CHILD | BS_AUTORADIOBUTTON |
6325 WS_CLIPCHILDREN | WS_VISIBLE, 6336 WS_CLIPCHILDREN | WS_VISIBLE,
6326 0,0,0,0, 6337 0,0,0,0,
6327 DW_HWND_OBJECT, 6338 DW_HWND_OBJECT,
6328 (HMENU)id, 6339 (HMENU)id,
6346 * id: An ID to be used with dw_window_from_id() or 0L. 6357 * id: An ID to be used with dw_window_from_id() or 0L.
6347 */ 6358 */
6348 HWND API dw_slider_new(int vertical, int increments, ULONG id) 6359 HWND API dw_slider_new(int vertical, int increments, ULONG id)
6349 { 6360 {
6350 HWND tmp = CreateWindow(TRACKBAR_CLASS, 6361 HWND tmp = CreateWindow(TRACKBAR_CLASS,
6351 "", 6362 NULL,
6352 WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | 6363 WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE |
6353 (vertical ? TBS_VERT : TBS_HORZ), 6364 (vertical ? TBS_VERT : TBS_HORZ),
6354 0,0,0,0, 6365 0,0,0,0,
6355 DW_HWND_OBJECT, 6366 DW_HWND_OBJECT,
6356 (HMENU)id, 6367 (HMENU)id,
6374 * id: An ID to be used with dw_window_from_id() or 0L. 6385 * id: An ID to be used with dw_window_from_id() or 0L.
6375 */ 6386 */
6376 HWND API dw_scrollbar_new(int vertical, ULONG id) 6387 HWND API dw_scrollbar_new(int vertical, ULONG id)
6377 { 6388 {
6378 HWND tmp = CreateWindow(SCROLLBARCLASSNAME, 6389 HWND tmp = CreateWindow(SCROLLBARCLASSNAME,
6379 "", 6390 NULL,
6380 WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | 6391 WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE |
6381 (vertical ? SBS_VERT : SBS_HORZ), 6392 (vertical ? SBS_VERT : SBS_HORZ),
6382 0,0,0,0, 6393 0,0,0,0,
6383 DW_HWND_OBJECT, 6394 DW_HWND_OBJECT,
6384 (HMENU)id, 6395 (HMENU)id,
6400 * id: An ID to be used with dw_window_from_id() or 0L. 6411 * id: An ID to be used with dw_window_from_id() or 0L.
6401 */ 6412 */
6402 HWND API dw_percent_new(ULONG id) 6413 HWND API dw_percent_new(ULONG id)
6403 { 6414 {
6404 return CreateWindow(PROGRESS_CLASS, 6415 return CreateWindow(PROGRESS_CLASS,
6405 "", 6416 NULL,
6406 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, 6417 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN,
6407 0,0,0,0, 6418 0,0,0,0,
6408 DW_HWND_OBJECT, 6419 DW_HWND_OBJECT,
6409 (HMENU)id, 6420 (HMENU)id,
6410 DWInstance, 6421 DWInstance,
6418 * id: An ID to be used with dw_window_from_id() or 0L. 6429 * id: An ID to be used with dw_window_from_id() or 0L.
6419 */ 6430 */
6420 HWND API dw_checkbox_new(char *text, ULONG id) 6431 HWND API dw_checkbox_new(char *text, ULONG id)
6421 { 6432 {
6422 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo)); 6433 ColorInfo *cinfo = calloc(1, sizeof(ColorInfo));
6423 HWND tmp = CreateWindow(BUTTONCLASSNAME, 6434 HWND tmp = CreateWindowW(UTF8toWide(BUTTONCLASSNAME),
6424 text, 6435 UTF8toWide(text),
6425 WS_CHILD | BS_AUTOCHECKBOX | 6436 WS_CHILD | BS_AUTOCHECKBOX |
6426 BS_TEXT | WS_CLIPCHILDREN | WS_VISIBLE, 6437 BS_TEXT | WS_CLIPCHILDREN | WS_VISIBLE,
6427 0,0,0,0, 6438 0,0,0,0,
6428 DW_HWND_OBJECT, 6439 DW_HWND_OBJECT,
6429 (HMENU)id, 6440 (HMENU)id,
6445 */ 6456 */
6446 HWND API dw_listbox_new(ULONG id, int multi) 6457 HWND API dw_listbox_new(ULONG id, int multi)
6447 { 6458 {
6448 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, 6459 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE,
6449 LISTBOXCLASSNAME, 6460 LISTBOXCLASSNAME,
6450 "", 6461 NULL,
6451 WS_VISIBLE | LBS_NOINTEGRALHEIGHT | 6462 WS_VISIBLE | LBS_NOINTEGRALHEIGHT |
6452 WS_CHILD | LBS_HASSTRINGS | 6463 WS_CHILD | LBS_HASSTRINGS |
6453 LBS_NOTIFY | WS_BORDER | WS_CLIPCHILDREN | 6464 LBS_NOTIFY | WS_BORDER | WS_CLIPCHILDREN |
6454 WS_VSCROLL | (multi ? LBS_MULTIPLESEL : 0) , 6465 WS_VSCROLL | (multi ? LBS_MULTIPLESEL : 0) ,
6455 0,0,0,0, 6466 0,0,0,0,
6652 */ 6663 */
6653 void API dw_window_set_text(HWND handle, char *text) 6664 void API dw_window_set_text(HWND handle, char *text)
6654 { 6665 {
6655 Box *thisbox; 6666 Box *thisbox;
6656 char tmpbuf[100] = {0}; 6667 char tmpbuf[100] = {0};
6668 LPWSTR wtext = UTF8toWide(text);
6657 6669
6658 GetClassName(handle, tmpbuf, 99); 6670 GetClassName(handle, tmpbuf, 99);
6659 6671
6660 SetWindowText(handle, text); 6672 SetWindowTextW(handle, wtext);
6661 6673
6662 /* Combobox */ 6674 /* Combobox */
6663 if ( _strnicmp( tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1) == 0 ) 6675 if ( _strnicmp( tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1) == 0 )
6664 SendMessage(handle, CB_SETEDITSEL, 0, MAKELPARAM(-1, 0)); 6676 SendMessage(handle, CB_SETEDITSEL, 0, MAKELPARAM(-1, 0));
6665 else if ( _strnicmp( tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1) == 0 ) 6677 else if ( _strnicmp( tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1) == 0 )
6666 { 6678 {
6667 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 6679 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA);
6668 if( cinfo && cinfo->buddy ) 6680 if( cinfo && cinfo->buddy )
6669 SetWindowText( cinfo->buddy, text ); 6681 SetWindowTextW( cinfo->buddy, wtext );
6670 } 6682 }
6671 else if ( _strnicmp( tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1) == 0 ) 6683 else if ( _strnicmp( tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1) == 0 )
6672 { 6684 {
6673 /* groupbox */ 6685 /* groupbox */
6674 thisbox = (Box *)GetWindowLongPtr( handle, GWLP_USERDATA ); 6686 thisbox = (Box *)GetWindowLongPtr( handle, GWLP_USERDATA );
6675 if ( thisbox && thisbox->grouphwnd != (HWND)NULL ) 6687 if ( thisbox && thisbox->grouphwnd != (HWND)NULL )
6676 SetWindowText( thisbox->grouphwnd, text ); 6688 SetWindowTextW( thisbox->grouphwnd, wtext );
6677 } 6689 }
6678 /* If we changed the text... */ 6690 /* If we changed the text... */
6679 { 6691 {
6680 Item *item = _box_item(handle); 6692 Item *item = _box_item(handle);
6681 6693
6711 * Returns: 6723 * Returns:
6712 * text: The text associsated with a given window. 6724 * text: The text associsated with a given window.
6713 */ 6725 */
6714 char * API dw_window_get_text(HWND handle) 6726 char * API dw_window_get_text(HWND handle)
6715 { 6727 {
6716 char tmpbuf[100] = {0}, *tempbuf; 6728 char tmpbuf[100] = {0}, *retbuf;
6717 int len; 6729 LPWSTR tempbuf;
6730 int wlen, len;
6718 6731
6719 GetClassName(handle, tmpbuf, 99); 6732 GetClassName(handle, tmpbuf, 99);
6720 6733
6721 if ( _strnicmp( tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1) == 0 ) 6734 if ( _strnicmp( tmpbuf, UPDOWN_CLASS, strlen(UPDOWN_CLASS)+1) == 0 )
6722 { 6735 {
6726 handle = cinfo->buddy; 6739 handle = cinfo->buddy;
6727 else 6740 else
6728 return NULL; 6741 return NULL;
6729 } 6742 }
6730 6743
6731 len = GetWindowTextLength(handle); 6744 /* Figure out the wide length, allocate a temp buffer
6732 tempbuf = calloc(1, len + 2); 6745 * and fill it with the current text.
6733 6746 */
6734 GetWindowText(handle, tempbuf, len + 1); 6747 wlen = GetWindowTextLengthW(handle);
6735 6748 tempbuf = _alloca(wlen * sizeof(WCHAR));
6736 return tempbuf; 6749 GetWindowTextW(handle, tempbuf, wlen);
6750
6751 /* Figure out the UTF8 length, allocate a return buffer
6752 * and fill it with the UTF8 text and return it.
6753 */
6754 len = WideCharToMultiByte(CP_UTF8, 0, tempbuf, -1, NULL, 0, NULL, NULL);
6755 retbuf = (char *)calloc(1, len);
6756 WideCharToMultiByte(CP_UTF8, 0, tempbuf, -1, retbuf, len, NULL, NULL);
6757
6758 return retbuf;
6737 } 6759 }
6738 6760
6739 /* 6761 /*
6740 * Disables given window (widget). 6762 * Disables given window (widget).
6741 * Parameters: 6763 * Parameters:
9501 */ 9523 */
9502 HWND API dw_render_new(unsigned long id) 9524 HWND API dw_render_new(unsigned long id)
9503 { 9525 {
9504 Box *newbox = calloc(sizeof(Box), 1); 9526 Box *newbox = calloc(sizeof(Box), 1);
9505 HWND tmp = CreateWindow(ObjectClassName, 9527 HWND tmp = CreateWindow(ObjectClassName,
9506 "", 9528 NULL,
9507 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, 9529 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN,
9508 0,0,0,0, 9530 0,0,0,0,
9509 DW_HWND_OBJECT, 9531 DW_HWND_OBJECT,
9510 (HMENU)id, 9532 (HMENU)id,
9511 DWInstance, 9533 DWInstance,
10805 * A handle to a splitbar window or NULL on failure. 10827 * A handle to a splitbar window or NULL on failure.
10806 */ 10828 */
10807 HWND API dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long id) 10829 HWND API dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long id)
10808 { 10830 {
10809 HWND tmp = CreateWindow(SplitbarClassName, 10831 HWND tmp = CreateWindow(SplitbarClassName,
10810 "", 10832 NULL,
10811 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, 10833 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN,
10812 0,0,0,0, 10834 0,0,0,0,
10813 DW_HWND_OBJECT, 10835 DW_HWND_OBJECT,
10814 (HMENU)id, 10836 (HMENU)id,
10815 DWInstance, 10837 DWInstance,
10883 { 10905 {
10884 RECT rc; 10906 RECT rc;
10885 MONTHDAYSTATE mds[3]; 10907 MONTHDAYSTATE mds[3];
10886 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE, 10908 HWND tmp = CreateWindowEx(WS_EX_CLIENTEDGE,
10887 MONTHCAL_CLASS, 10909 MONTHCAL_CLASS,
10888 "", 10910 NULL,
10889 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | MCS_DAYSTATE, 10911 WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | MCS_DAYSTATE,
10890 0,0,0,0, 10912 0,0,0,0,
10891 DW_HWND_OBJECT, 10913 DW_HWND_OBJECT,
10892 (HMENU)id, 10914 (HMENU)id,
10893 DWInstance, 10915 DWInstance,