Mercurial > dwindows
comparison win/dw.c @ 571:828e6a66c5c5
Add dw_listbox_list_append()
author | mhessling@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 20 Jul 2004 07:36:11 +0000 |
parents | f6de197ecbe9 |
children | 314abd650968 |
comparison
equal
deleted
inserted
replaced
570:052e9e4a59bd | 571:828e6a66c5c5 |
---|---|
1 /* | |
2 /* | 1 /* |
3 * Dynamic Windows: | 2 * Dynamic Windows: |
4 * A GTK like implementation of the Win32 GUI | 3 * A GTK like implementation of the Win32 GUI |
5 * | 4 * |
6 * (C) 2000-2004 Brian Smith <dbsoft@technologist.com> | 5 * (C) 2000-2004 Brian Smith <dbsoft@technologist.com> |
18 #include <string.h> | 17 #include <string.h> |
19 #include <stdio.h> | 18 #include <stdio.h> |
20 #include <process.h> | 19 #include <process.h> |
21 #include <time.h> | 20 #include <time.h> |
22 #include "dw.h" | 21 #include "dw.h" |
22 | |
23 /* | |
24 * MinGW (as at 3.2.3) doesn't have MIM_MENUDATA | |
25 * so #define it here | |
26 */ | |
27 | |
28 #if !defined( MIM_MENUDATA ) | |
29 # define MIM_MENUDATA 0x00000008 | |
30 #endif | |
23 | 31 |
24 HWND popup = (HWND)NULL, hwndBubble = (HWND)NULL, DW_HWND_OBJECT = (HWND)NULL; | 32 HWND popup = (HWND)NULL, hwndBubble = (HWND)NULL, DW_HWND_OBJECT = (HWND)NULL; |
25 | 33 |
26 HINSTANCE DWInstance = NULL; | 34 HINSTANCE DWInstance = NULL; |
27 | 35 |
381 { | 389 { |
382 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); | 390 NotebookPage **array = (NotebookPage **)dw_window_get_data(handle, "_dw_array"); |
383 | 391 |
384 if(array) | 392 if(array) |
385 { | 393 { |
386 int z, refid = -1; | 394 int z; |
387 | 395 |
388 for(z=0;z<256;z++) | 396 for(z=0;z<256;z++) |
389 { | 397 { |
390 if(array[z]) | 398 if(array[z]) |
391 { | 399 { |
1471 { | 1479 { |
1472 int (*buttonfunc)(HWND, int, int, int, void *) = (int (*)(HWND, int, int, int, void *))tmp->signalfunction; | 1480 int (*buttonfunc)(HWND, int, int, int, void *) = (int (*)(HWND, int, int, int, void *))tmp->signalfunction; |
1473 | 1481 |
1474 if(hWnd == tmp->window) | 1482 if(hWnd == tmp->window) |
1475 { | 1483 { |
1476 int button; | 1484 int button=0; |
1477 | 1485 |
1478 switch(origmsg) | 1486 switch(origmsg) |
1479 { | 1487 { |
1480 case WM_LBUTTONDOWN: | 1488 case WM_LBUTTONDOWN: |
1481 button = 1; | 1489 button = 1; |
1506 { | 1514 { |
1507 int (*buttonfunc)(HWND, int, int, int, void *) = (int (*)(HWND, int, int, int, void *))tmp->signalfunction; | 1515 int (*buttonfunc)(HWND, int, int, int, void *) = (int (*)(HWND, int, int, int, void *))tmp->signalfunction; |
1508 | 1516 |
1509 if(hWnd == tmp->window) | 1517 if(hWnd == tmp->window) |
1510 { | 1518 { |
1511 int button; | 1519 int button=0; |
1512 | 1520 |
1513 switch(origmsg) | 1521 switch(origmsg) |
1514 { | 1522 { |
1515 case WM_LBUTTONUP: | 1523 case WM_LBUTTONUP: |
1516 button = 1; | 1524 button = 1; |
2431 if(IS_IE5PLUS) | 2439 if(IS_IE5PLUS) |
2432 val = (long)SendMessage(cinfo->buddy, UDM_GETPOS32, 0, 0); | 2440 val = (long)SendMessage(cinfo->buddy, UDM_GETPOS32, 0, 0); |
2433 else | 2441 else |
2434 val = (long)SendMessage(cinfo->buddy, UDM_GETPOS, 0, 0); | 2442 val = (long)SendMessage(cinfo->buddy, UDM_GETPOS, 0, 0); |
2435 | 2443 |
2436 sprintf(tmpbuf, "%d", val); | 2444 sprintf(tmpbuf, "%ld", val); |
2437 SetWindowText(hWnd, tmpbuf); | 2445 SetWindowText(hWnd, tmpbuf); |
2438 } | 2446 } |
2439 } | 2447 } |
2440 break; | 2448 break; |
2441 case WM_CTLCOLORSTATIC: | 2449 case WM_CTLCOLORSTATIC: |
2770 | 2778 |
2771 BeginPaint(hwnd, &ps); | 2779 BeginPaint(hwnd, &ps); |
2772 | 2780 |
2773 if((hdcPaint = GetDC(hwnd)) != NULL) | 2781 if((hdcPaint = GetDC(hwnd)) != NULL) |
2774 { | 2782 { |
2775 int cx, cy; | 2783 unsigned long cx, cy; |
2776 HBRUSH oldBrush = SelectObject(hdcPaint, GetSysColorBrush(COLOR_3DFACE)); | 2784 HBRUSH oldBrush = SelectObject(hdcPaint, GetSysColorBrush(COLOR_3DFACE)); |
2777 HPEN oldPen = SelectObject(hdcPaint, CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DFACE))); | 2785 HPEN oldPen = SelectObject(hdcPaint, CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DFACE))); |
2778 | 2786 |
2779 dw_window_get_pos_size(hwnd, NULL, NULL, &cx, &cy); | 2787 dw_window_get_pos_size(hwnd, NULL, NULL, &cx, &cy); |
2780 | 2788 |
2871 { | 2879 { |
2872 HDC hdcPaint; | 2880 HDC hdcPaint; |
2873 PAINTSTRUCT ps; | 2881 PAINTSTRUCT ps; |
2874 RECT rc; | 2882 RECT rc; |
2875 unsigned long cx, cy; | 2883 unsigned long cx, cy; |
2876 int threadid = dw_thread_id(); | |
2877 char tempbuf[1024] = ""; | 2884 char tempbuf[1024] = ""; |
2878 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA); | 2885 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA); |
2879 HFONT hfont = _acquire_font(hwnd, cinfo ? cinfo->fontname : NULL); | 2886 HFONT hfont = _acquire_font(hwnd, cinfo ? cinfo->fontname : NULL); |
2880 HFONT oldfont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0); | 2887 HFONT oldfont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0); |
2881 | 2888 |
3034 } | 3041 } |
3035 | 3042 |
3036 if(!hwndBubble) | 3043 if(!hwndBubble) |
3037 { | 3044 { |
3038 POINTL ptlWork = {0,0}; | 3045 POINTL ptlWork = {0,0}; |
3039 ULONG ulColor = DW_CLR_YELLOW; | |
3040 SIZE size; | 3046 SIZE size; |
3041 HFONT hFont, oldFont = (HFONT)0; | 3047 HFONT hFont, oldFont = (HFONT)0; |
3042 HDC hdc; | 3048 HDC hdc; |
3043 RECT rect; | 3049 RECT rect; |
3044 void *oldproc; | |
3045 | 3050 |
3046 /* Use the WS_EX_TOOLWINDOW extended style | 3051 /* Use the WS_EX_TOOLWINDOW extended style |
3047 * so the window doesn't get listed in the | 3052 * so the window doesn't get listed in the |
3048 * taskbar. | 3053 * taskbar. |
3049 */ | 3054 */ |
4103 | 4108 |
4104 InsertMenuItem(mymenu, 65535, TRUE, &mii); | 4109 InsertMenuItem(mymenu, 65535, TRUE, &mii); |
4105 | 4110 |
4106 if(!IS_WINNTOR95) | 4111 if(!IS_WINNTOR95) |
4107 { | 4112 { |
4108 sprintf(buffer, "_dw_id%d", id); | 4113 sprintf(buffer, "_dw_id%ld", id); |
4109 dw_window_set_data(DW_HWND_OBJECT, buffer, (void *)mymenu); | 4114 dw_window_set_data(DW_HWND_OBJECT, buffer, (void *)mymenu); |
4110 | 4115 |
4111 /* According to the docs this will only work on Win2k/98 and above */ | 4116 /* According to the docs this will only work on Win2k/98 and above */ |
4112 if(submenu) | 4117 if(submenu) |
4113 { | 4118 { |
4649 * text: The text to be display by the static text widget. | 4654 * text: The text to be display by the static text widget. |
4650 * id: An ID to be used with dw_window_from_id() or 0L. | 4655 * id: An ID to be used with dw_window_from_id() or 0L. |
4651 */ | 4656 */ |
4652 HWND API dw_spinbutton_new(char *text, ULONG id) | 4657 HWND API dw_spinbutton_new(char *text, ULONG id) |
4653 { | 4658 { |
4654 ULONG *data = malloc(sizeof(ULONG)); | |
4655 HWND buddy = CreateWindowEx(WS_EX_CLIENTEDGE, | 4659 HWND buddy = CreateWindowEx(WS_EX_CLIENTEDGE, |
4656 EDITCLASSNAME, | 4660 EDITCLASSNAME, |
4657 text, | 4661 text, |
4658 WS_CHILD | WS_BORDER | WS_VISIBLE | | 4662 WS_CHILD | WS_BORDER | WS_VISIBLE | |
4659 ES_NUMBER | WS_CLIPCHILDREN, | 4663 ES_NUMBER | WS_CLIPCHILDREN, |
5497 LB_ADDSTRING, | 5501 LB_ADDSTRING, |
5498 0, (LPARAM)text); | 5502 0, (LPARAM)text); |
5499 } | 5503 } |
5500 | 5504 |
5501 /* | 5505 /* |
5506 * Appends the specified text items to the listbox's (or combobox) entry list. | |
5507 * Parameters: | |
5508 * handle: Handle to the listbox to be appended to. | |
5509 * text: Text strings to append into listbox. | |
5510 * count: Number of text strings to append | |
5511 */ | |
5512 void API dw_listbox_list_append(HWND handle, char **text, int count) | |
5513 { | |
5514 char tmpbuf[100]; | |
5515 int listbox_type; | |
5516 int i; | |
5517 | |
5518 GetClassName(handle, tmpbuf, 99); | |
5519 | |
5520 if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0) | |
5521 listbox_type = CB_ADDSTRING; | |
5522 else | |
5523 listbox_type = LB_ADDSTRING; | |
5524 | |
5525 for(i=0;i<count;i++) | |
5526 SendMessage(handle,(WPARAM)listbox_type,0,(LPARAM)text[i]); | |
5527 } | |
5528 | |
5529 /* | |
5502 * Clears the listbox's (or combobox) list of all entries. | 5530 * Clears the listbox's (or combobox) list of all entries. |
5503 * Parameters: | 5531 * Parameters: |
5504 * handle: Handle to the listbox to be cleared. | 5532 * handle: Handle to the listbox to be cleared. |
5505 */ | 5533 */ |
5506 void API dw_listbox_clear(HWND handle) | 5534 void API dw_listbox_clear(HWND handle) |
6064 void API dw_spinbutton_set_pos(HWND handle, long position) | 6092 void API dw_spinbutton_set_pos(HWND handle, long position) |
6065 { | 6093 { |
6066 char tmpbuf[100]; | 6094 char tmpbuf[100]; |
6067 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 6095 ColorInfo *cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
6068 | 6096 |
6069 sprintf(tmpbuf, "%d", position); | 6097 sprintf(tmpbuf, "%ld", position); |
6070 | 6098 |
6071 if(cinfo && cinfo->buddy) | 6099 if(cinfo && cinfo->buddy) |
6072 SetWindowText(cinfo->buddy, tmpbuf); | 6100 SetWindowText(cinfo->buddy, tmpbuf); |
6073 | 6101 |
6074 if(IS_IE5PLUS) | 6102 if(IS_IE5PLUS) |
6418 * item: Handle to node to be deleted. | 6446 * item: Handle to node to be deleted. |
6419 */ | 6447 */ |
6420 void API dw_tree_item_delete(HWND handle, HTREEITEM item) | 6448 void API dw_tree_item_delete(HWND handle, HTREEITEM item) |
6421 { | 6449 { |
6422 TVITEM tvi; | 6450 TVITEM tvi; |
6423 void **ptrs; | 6451 void **ptrs=NULL; |
6424 | 6452 |
6425 if(item == TVI_ROOT || !item) | 6453 if(item == TVI_ROOT || !item) |
6426 return; | 6454 return; |
6427 | 6455 |
6428 tvi.mask = TVIF_HANDLE; | 6456 tvi.mask = TVIF_HANDLE; |
7031 | 7059 |
7032 ListView_GetItem(handle, &lvi); | 7060 ListView_GetItem(handle, &lvi); |
7033 | 7061 |
7034 if((char *)lvi.lParam == text) | 7062 if((char *)lvi.lParam == text) |
7035 { | 7063 { |
7036 RECT viewport, item; | |
7037 | 7064 |
7038 ListView_SetItemState(handle, index, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); | 7065 ListView_SetItemState(handle, index, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); |
7039 ListView_EnsureVisible(handle, index, TRUE); | 7066 ListView_EnsureVisible(handle, index, TRUE); |
7040 return; | 7067 return; |
7041 } | 7068 } |
7086 * handle: Handle to the window (widget) to be optimized. | 7113 * handle: Handle to the window (widget) to be optimized. |
7087 */ | 7114 */ |
7088 void API dw_container_optimize(HWND handle) | 7115 void API dw_container_optimize(HWND handle) |
7089 { | 7116 { |
7090 ContainerInfo *cinfo = (ContainerInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); | 7117 ContainerInfo *cinfo = (ContainerInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); |
7091 ULONG *flags; | |
7092 LV_ITEM lvi; | |
7093 | 7118 |
7094 if(cinfo && cinfo->columns == 1) | 7119 if(cinfo && cinfo->columns == 1) |
7095 { | 7120 { |
7096 ListView_SetColumnWidth(handle, 0, LVSCW_AUTOSIZE); | 7121 ListView_SetColumnWidth(handle, 0, LVSCW_AUTOSIZE); |
7097 } | 7122 } |
7380 * height: Height of rectangle. | 7405 * height: Height of rectangle. |
7381 */ | 7406 */ |
7382 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height) | 7407 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int fill, int x, int y, int width, int height) |
7383 { | 7408 { |
7384 HDC hdcPaint; | 7409 HDC hdcPaint; |
7385 HPEN oldPen; | |
7386 HBRUSH oldBrush; | |
7387 RECT Rect; | 7410 RECT Rect; |
7388 int threadid = dw_thread_id(); | 7411 int threadid = dw_thread_id(); |
7389 | 7412 |
7390 if(threadid < 0 || threadid >= THREAD_LIMIT) | 7413 if(threadid < 0 || threadid >= THREAD_LIMIT) |
7391 threadid = 0; | 7414 threadid = 0; |
7415 * text: Text to be displayed. | 7438 * text: Text to be displayed. |
7416 */ | 7439 */ |
7417 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text) | 7440 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text) |
7418 { | 7441 { |
7419 HDC hdc; | 7442 HDC hdc; |
7420 int size = 9, z, mustdelete = 0; | 7443 int mustdelete = 0; |
7421 HFONT hFont = 0, oldFont = 0; | 7444 HFONT hFont = 0, oldFont = 0; |
7422 int threadid = dw_thread_id(); | 7445 int threadid = dw_thread_id(); |
7423 ColorInfo *cinfo; | 7446 ColorInfo *cinfo; |
7424 | 7447 |
7425 if(threadid < 0 || threadid >= THREAD_LIMIT) | 7448 if(threadid < 0 || threadid >= THREAD_LIMIT) |
7533 * A handle to a pixmap or NULL on failure. | 7556 * A handle to a pixmap or NULL on failure. |
7534 */ | 7557 */ |
7535 HPIXMAP API dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth) | 7558 HPIXMAP API dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth) |
7536 { | 7559 { |
7537 HPIXMAP pixmap; | 7560 HPIXMAP pixmap; |
7538 BITMAP bm; | |
7539 HDC hdc; | 7561 HDC hdc; |
7540 | 7562 |
7541 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 7563 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
7542 return NULL; | 7564 return NULL; |
7543 | 7565 |