comparison os2/dw.c @ 475:1547e8c327d9

Remove some compiler warnings under EMX. dw_main_sleep() crashed with SIGFPE under EMX. Changed timing to use Unix-like timing checks. Support creating window minimized or maximized. EMX does not support TABBEDDIALOG. Fixed crash with bitmap buttons when bitmap does not exist.
author mhessling@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 10 Oct 2003 22:37:16 +0000
parents 6ccac112f1e5
children a84ee39e7aea
comparison
equal deleted inserted replaced
474:053211e0698b 475:1547e8c327d9
24 #include <time.h> 24 #include <time.h>
25 #include <io.h> 25 #include <io.h>
26 #ifndef __EMX__ 26 #ifndef __EMX__
27 #include <direct.h> 27 #include <direct.h>
28 #endif 28 #endif
29 #include <sys/time.h>
29 #include "dw.h" 30 #include "dw.h"
30 31
31 #define QWP_USER 0 32 #define QWP_USER 0
32 33
33 MRESULT EXPENTRY _run_event(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); 34 MRESULT EXPENTRY _run_event(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
179 } CNRITEM, *PCNRITEM; 180 } CNRITEM, *PCNRITEM;
180 181
181 182
182 int _null_key(HWND window, int key, void *data) 183 int _null_key(HWND window, int key, void *data)
183 { 184 {
185 window = window; /* keep compiler happy */
186 key = key; /* keep compiler happy */
187 data = data; /* keep compiler happy */
184 return TRUE; 188 return TRUE;
185 } 189 }
186 190
187 /* Find the desktop window handle */ 191 /* Find the desktop window handle */
188 HWND _toplevel_window(HWND handle) 192 HWND _toplevel_window(HWND handle)
3249 */ 3253 */
3250 int API dw_init(int newthread, int argc, char *argv[]) 3254 int API dw_init(int newthread, int argc, char *argv[])
3251 { 3255 {
3252 APIRET rc; 3256 APIRET rc;
3253 3257
3258 argc = argc; /* keep compiler happy */
3259 argv = argv; /* keep compiler happy */
3254 if(newthread) 3260 if(newthread)
3255 { 3261 {
3256 dwhab = WinInitialize(0); 3262 dwhab = WinInitialize(0);
3257 dwhmq = WinCreateMsgQueue(dwhab, 0); 3263 dwhmq = WinCreateMsgQueue(dwhab, 0);
3258 } 3264 }
3302 * milliseconds: Number of milliseconds to run the loop for. 3308 * milliseconds: Number of milliseconds to run the loop for.
3303 */ 3309 */
3304 void API dw_main_sleep(int milliseconds) 3310 void API dw_main_sleep(int milliseconds)
3305 { 3311 {
3306 QMSG qmsg; 3312 QMSG qmsg;
3313 #ifdef __EMX__
3307 double start = (double)clock(); 3314 double start = (double)clock();
3308 3315
3309 while(((clock() - start) / (CLOCKS_PER_SEC/1000)) <= milliseconds) 3316 while(((clock() - start) / (CLOCKS_PER_SEC/1000)) <= milliseconds)
3310 { 3317 {
3311 if(WinPeekMsg(dwhab, &qmsg, 0, 0, 0, PM_NOREMOVE)) 3318 if(WinPeekMsg(dwhab, &qmsg, 0, 0, 0, PM_NOREMOVE))
3316 WinDispatchMsg(dwhab, &qmsg); 3323 WinDispatchMsg(dwhab, &qmsg);
3317 } 3324 }
3318 else 3325 else
3319 DosSleep(1); 3326 DosSleep(1);
3320 } 3327 }
3328 #else
3329 struct timeval tv, start;
3330
3331 gettimeofday(&start, NULL);
3332 gettimeofday(&tv, NULL);
3333
3334 while(((tv.tv_sec - start.tv_sec)*1000) + ((tv.tv_usec - start.tv_usec)/1000) <= milliseconds)
3335 {
3336 if(WinPeekMsg(dwhab, &qmsg, 0, 0, 0, PM_NOREMOVE))
3337 {
3338 WinGetMsg(dwhab, &qmsg, 0, 0, 0);
3339 if(qmsg.msg == WM_TIMER && qmsg.hwnd == NULLHANDLE)
3340 _run_event(qmsg.hwnd, qmsg.msg, qmsg.mp1, qmsg.mp2);
3341 WinDispatchMsg(dwhab, &qmsg);
3342 }
3343 else
3344 DosSleep(1);
3345 gettimeofday(&tv, NULL);
3346 }
3347 #endif
3321 } 3348 }
3322 3349
3323 /* 3350 /*
3324 * Processes a single message iteration and returns. 3351 * Processes a single message iteration and returns.
3325 */ 3352 */
3778 HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) 3805 HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle)
3779 { 3806 {
3780 HWND hwndclient = 0, hwndframe; 3807 HWND hwndclient = 0, hwndframe;
3781 Box *newbox = calloc(1, sizeof(Box)); 3808 Box *newbox = calloc(1, sizeof(Box));
3782 WindowData *blah = calloc(1, sizeof(WindowData)); 3809 WindowData *blah = calloc(1, sizeof(WindowData));
3810 ULONG winStyle = 0L;
3783 3811
3784 newbox->pad = 0; 3812 newbox->pad = 0;
3785 newbox->type = DW_VERT; 3813 newbox->type = DW_VERT;
3786 newbox->count = 0; 3814 newbox->count = 0;
3787 3815
3793 flStyle |= FCF_TITLEBAR; 3821 flStyle |= FCF_TITLEBAR;
3794 3822
3795 if(!(flStyle & FCF_SHELLPOSITION)) 3823 if(!(flStyle & FCF_SHELLPOSITION))
3796 blah->flags |= DW_OS2_NEW_WINDOW; 3824 blah->flags |= DW_OS2_NEW_WINDOW;
3797 3825
3798 hwndframe = WinCreateStdWindow(hwndOwner, 0L, &flStyle, ClassName, title, 0L, NULLHANDLE, 0L, &hwndclient); 3826 if(flStyle & WS_MAXIMIZED)
3827 {
3828 winStyle |= WS_MAXIMIZED;
3829 flStyle &= ~WS_MAXIMIZED;
3830 }
3831 if(flStyle & WS_MINIMIZED)
3832 {
3833 winStyle |= WS_MINIMIZED;
3834 flStyle &= ~WS_MINIMIZED;
3835 }
3836
3837 hwndframe = WinCreateStdWindow(hwndOwner, winStyle, &flStyle, ClassName, title, 0L, NULLHANDLE, 0L, &hwndclient);
3799 newbox->hwndtitle = WinWindowFromID(hwndframe, FID_TITLEBAR); 3838 newbox->hwndtitle = WinWindowFromID(hwndframe, FID_TITLEBAR);
3800 if(!newbox->titlebar && newbox->hwndtitle) 3839 if(!newbox->titlebar && newbox->hwndtitle)
3801 WinSetParent(newbox->hwndtitle, HWND_OBJECT, FALSE); 3840 WinSetParent(newbox->hwndtitle, HWND_OBJECT, FALSE);
3802 blah->oldproc = WinSubclassWindow(hwndframe, _sizeproc); 3841 blah->oldproc = WinSubclassWindow(hwndframe, _sizeproc);
3803 WinSetWindowPtr(hwndframe, QWP_USER, blah); 3842 WinSetWindowPtr(hwndframe, QWP_USER, blah);
3894 */ 3933 */
3895 HWND API dw_mdi_new(unsigned long id) 3934 HWND API dw_mdi_new(unsigned long id)
3896 { 3935 {
3897 HWND hwndframe; 3936 HWND hwndframe;
3898 3937
3938 id = id; /* keep compiler happy */
3899 hwndframe = WinCreateWindow(HWND_OBJECT, 3939 hwndframe = WinCreateWindow(HWND_OBJECT,
3900 WC_FRAME, 3940 WC_FRAME,
3901 NULL, 3941 NULL,
3902 WS_VISIBLE | WS_CLIPCHILDREN | 3942 WS_VISIBLE | WS_CLIPCHILDREN |
3903 FS_NOBYTEALIGN, 3943 FS_NOBYTEALIGN,
3947 3987
3948 tmp = WinCreateWindow(HWND_OBJECT, 3988 tmp = WinCreateWindow(HWND_OBJECT,
3949 WC_NOTEBOOK, 3989 WC_NOTEBOOK,
3950 NULL, 3990 NULL,
3951 WS_VISIBLE | 3991 WS_VISIBLE |
3992 #ifdef BKS_TABBEDDIALOG
3952 BKS_TABBEDDIALOG | 3993 BKS_TABBEDDIALOG |
3994 #endif
3953 flags, 3995 flags,
3954 0,0,2000,1000, 3996 0,0,2000,1000,
3955 NULLHANDLE, 3997 NULLHANDLE,
3956 HWND_TOP, 3998 HWND_TOP,
3957 id, 3999 id,
4037 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG id, ULONG flags, int end, int check, HMENUI submenu) 4079 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG id, ULONG flags, int end, int check, HMENUI submenu)
4038 { 4080 {
4039 MENUITEM miSubMenu; 4081 MENUITEM miSubMenu;
4040 char buffer[15]; 4082 char buffer[15];
4041 4083
4084 check = check; /* keep compiler happy */
4042 if(!menux || id > 65536) 4085 if(!menux || id > 65536)
4043 return NULLHANDLE; 4086 return NULLHANDLE;
4044 4087
4045 if(end) 4088 if(end)
4046 miSubMenu.iPosition=MIT_END; 4089 miSubMenu.iPosition=MIT_END;
4514 { 4557 {
4515 /* Try with .bmp extention */ 4558 /* Try with .bmp extention */
4516 strcat(file, ".bmp"); 4559 strcat(file, ".bmp");
4517 if(access(file, 04) != 0) 4560 if(access(file, 04) != 0)
4518 { 4561 {
4562 #if 0 /* don't free pixmap if bitmap doesn't exist; causes crash several lines below */
4519 free(pixmap); 4563 free(pixmap);
4520 pixmap = NULL; 4564 pixmap = NULL;
4565 #endif
4521 } 4566 }
4522 } 4567 }
4523 4568
4524 /* Try to load the bitmap from file */ 4569 /* Try to load the bitmap from file */
4525 if(pixmap) 4570 if(pixmap)
4653 * increments: Number of increments available. 4698 * increments: Number of increments available.
4654 * id: An ID to be used with dw_window_from_id() or 0L. 4699 * id: An ID to be used with dw_window_from_id() or 0L.
4655 */ 4700 */
4656 HWND API dw_scrollbar_new(int vertical, int increments, ULONG id) 4701 HWND API dw_scrollbar_new(int vertical, int increments, ULONG id)
4657 { 4702 {
4703 increments = increments; /* keep compiler happy */
4658 return WinCreateWindow(HWND_OBJECT, 4704 return WinCreateWindow(HWND_OBJECT,
4659 WC_SCROLLBAR, 4705 WC_SCROLLBAR,
4660 "", 4706 "",
4661 WS_VISIBLE | SBS_AUTOTRACK | 4707 WS_VISIBLE | SBS_AUTOTRACK |
4662 (vertical ? SBS_VERT : SBS_HORZ), 4708 (vertical ? SBS_VERT : SBS_HORZ),
5987 */ 6033 */
5988 void API dw_tree_set_data(HWND handle, HTREEITEM item, void *itemdata) 6034 void API dw_tree_set_data(HWND handle, HTREEITEM item, void *itemdata)
5989 { 6035 {
5990 PCNRITEM pci = (PCNRITEM)item; 6036 PCNRITEM pci = (PCNRITEM)item;
5991 6037
6038 handle = handle; /* keep compiler happy */
5992 if(!pci) 6039 if(!pci)
5993 return; 6040 return;
5994 6041
5995 pci->user = itemdata; 6042 pci->user = itemdata;
5996 } 6043 }
6003 */ 6050 */
6004 void * API dw_tree_get_data(HWND handle, HTREEITEM item) 6051 void * API dw_tree_get_data(HWND handle, HTREEITEM item)
6005 { 6052 {
6006 PCNRITEM pci = (PCNRITEM)item; 6053 PCNRITEM pci = (PCNRITEM)item;
6007 6054
6055 handle = handle; /* keep compiler happy */
6008 if(!pci) 6056 if(!pci)
6009 return NULL; 6057 return NULL;
6010 return pci->user; 6058 return pci->user;
6011 } 6059 }
6012 6060
6534 * column: Zero based column of width being set. 6582 * column: Zero based column of width being set.
6535 * width: Width of column in pixels. 6583 * width: Width of column in pixels.
6536 */ 6584 */
6537 void API dw_container_set_column_width(HWND handle, int column, int width) 6585 void API dw_container_set_column_width(HWND handle, int column, int width)
6538 { 6586 {
6587 handle = handle; /* keep compiler happy */
6588 column = column; /* keep compiler happy */
6589 width = width; /* keep compiler happy */
6539 } 6590 }
6540 6591
6541 /* 6592 /*
6542 * Sets the title of a row in the container. 6593 * Sets the title of a row in the container.
6543 * Parameters: 6594 * Parameters:
6666 * DW_SCROLL_BOTTOM. (rows is ignored for last two) 6717 * DW_SCROLL_BOTTOM. (rows is ignored for last two)
6667 * rows: The number of rows to be scrolled. 6718 * rows: The number of rows to be scrolled.
6668 */ 6719 */
6669 void API dw_container_scroll(HWND handle, int direction, long rows) 6720 void API dw_container_scroll(HWND handle, int direction, long rows)
6670 { 6721 {
6722 rows = rows; /* keep compiler happy */
6671 switch(direction) 6723 switch(direction)
6672 { 6724 {
6673 case DW_SCROLL_TOP: 6725 case DW_SCROLL_TOP:
6674 WinSendMsg(handle, CM_SCROLLWINDOW, MPFROMSHORT(CMA_VERTICAL), MPFROMLONG(-10000000)); 6726 WinSendMsg(handle, CM_SCROLLWINDOW, MPFROMSHORT(CMA_VERTICAL), MPFROMLONG(-10000000));
6675 break; 6727 break;
8059 * Returns: 8111 * Returns:
8060 * -1 on error. 8112 * -1 on error.
8061 */ 8113 */
8062 int API dw_exec(char *program, int type, char **params) 8114 int API dw_exec(char *program, int type, char **params)
8063 { 8115 {
8116 type = type; /* keep compiler happy */
8064 return spawnvp(P_NOWAIT, program, (const char **)params); 8117 return spawnvp(P_NOWAIT, program, (const char **)params);
8065 } 8118 }
8066 8119
8067 /* 8120 /*
8068 * Loads a web browser pointed at the given URL. 8121 * Loads a web browser pointed at the given URL.
8069 * Parameters: 8122 * Parameters:
8070 * url: Uniform resource locator. 8123 * url: Uniform resource locator.
8071 */ 8124 */
8072 int API dw_browse(char *url) 8125 int API dw_browse(char *url)
8073 { 8126 {
8074 /* Is there a way to find the webbrowser in Unix? */
8075 char *execargs[3], browser[1024], *olddir, *newurl = NULL; 8127 char *execargs[3], browser[1024], *olddir, *newurl = NULL;
8076 int len, ret; 8128 int len, ret;
8077 8129
8078 olddir = _getcwd(NULL, 1024); 8130 olddir = _getcwd(NULL, 1024);
8079 8131