changeset 986:87dc0f5f96d0

Fix return type of dw_listbox_selected() to be "int" instead of "unsigned int" to allow -1 return. Changed return values of a number of functions to be consistent across platforms and use the defines.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 07 May 2011 05:14:06 +0000
parents cfc0777aceb5
children 297f2e790e57
files dw.h gtk/dw.c gtk3/dw.c mac/dw.m os2/dw.c template/dw.c win/dw.c
diffstat 7 files changed, 76 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Sat May 07 02:15:50 2011 +0000
+++ b/dw.h	Sat May 07 05:14:06 2011 +0000
@@ -1484,7 +1484,7 @@
 void API dw_listbox_delete(HWND handle, int index);
 void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length);
 void API dw_listbox_set_text(HWND handle, unsigned int index, char *buffer);
-unsigned int API dw_listbox_selected(HWND handle);
+int API dw_listbox_selected(HWND handle);
 int API dw_listbox_selected_multi(HWND handle, int where);
 void API dw_percent_set_pos(HWND handle, unsigned int position);
 unsigned int API dw_slider_get_pos(HWND handle);
--- a/gtk/dw.c	Sat May 07 02:15:50 2011 +0000
+++ b/gtk/dw.c	Sat May 07 05:14:06 2011 +0000
@@ -6292,7 +6292,7 @@
    if(!clist)
    {
       DW_MUTEX_UNLOCK;
-      return FALSE;
+      return DW_ERROR_GENERAL;
    }
    multi = (int)gtk_object_get_data(GTK_OBJECT(handle), "_dw_multi");
    gtk_object_set_data(GTK_OBJECT(handle), "_dw_multi", GINT_TO_POINTER(multi));
@@ -6326,7 +6326,7 @@
    }
 
    DW_MUTEX_UNLOCK;
-   return TRUE;
+   return DW_ERROR_NONE;
 }
 
 /*
@@ -6356,6 +6356,7 @@
 {
    char **newtitles = malloc(sizeof(char *) * (count + 1));
    unsigned long *newflags = malloc(sizeof(unsigned long) * (count + 1));
+   int res;
 
    newtitles[0] = "Filename";
 
@@ -6364,11 +6365,11 @@
    memcpy(&newtitles[1], titles, sizeof(char *) * count);
    memcpy(&newflags[1], flags, sizeof(unsigned long) * count);
 
-   _dw_container_setup(handle, newflags, newtitles, count + 1, 1, 1);
+   res = _dw_container_setup(handle, newflags, newtitles, count + 1, 1, 1);
 
    if ( newtitles) free(newtitles);
    if ( newflags ) free(newflags);
-   return TRUE;
+   return res;
 }
 
 /*
@@ -8370,14 +8371,14 @@
 int dw_event_reset (HEV eve)
 {
    if(!eve)
-      return FALSE;
+      return DW_ERROR_NON_INIT;
 
    pthread_mutex_lock (&(eve->mutex));
    pthread_cond_broadcast (&(eve->event));
    pthread_cond_init (&(eve->event), NULL);
    eve->posted = 0;
    pthread_mutex_unlock (&(eve->mutex));
-   return 0;
+   return DW_ERROR_NONE;
 }
 
 /*
@@ -8389,13 +8390,13 @@
 int dw_event_post (HEV eve)
 {
    if(!eve)
-      return FALSE;
+      return DW_ERROR_NON_INIT;
 
    pthread_mutex_lock (&(eve->mutex));
    pthread_cond_broadcast (&(eve->event));
    eve->posted = 1;
    pthread_mutex_unlock (&(eve->mutex));
-   return 0;
+   return DW_ERROR_NONE;
 }
 
 /*
@@ -8411,10 +8412,10 @@
    struct timespec timeo;
 
    if(!eve)
-      return FALSE;
+      return DW_ERROR_NON_INIT;
 
    if(eve->posted)
-      return 0;
+      return DW_ERROR_GENERAL;
 
    pthread_mutex_lock (&(eve->mutex));
    gettimeofday(&now, 0);
@@ -8423,10 +8424,10 @@
    rc = pthread_cond_timedwait (&(eve->event), &(eve->mutex), &timeo);
    pthread_mutex_unlock (&(eve->mutex));
    if(!rc)
-      return 1;
+      return DW_ERROR_NONE;
    if(rc == ETIMEDOUT)
-      return -1;
-   return 0;
+      return DW_ERROR_TIMEOUT;
+   return DW_ERROR_GENERAL;
 }
 
 /*
@@ -8437,7 +8438,7 @@
 int dw_event_close(HEV *eve)
 {
    if(!eve || !(*eve))
-      return FALSE;
+      return DW_ERROR_NON_INIT;
 
    pthread_mutex_lock (&((*eve)->mutex));
    pthread_cond_destroy (&((*eve)->event));
@@ -8446,7 +8447,7 @@
    free(*eve);
    *eve = NULL;
 
-   return TRUE;
+   return DW_ERROR_NONE;
 }
 
 struct _seminfo {
@@ -10112,7 +10113,7 @@
  * Parameters:
  *          handle: Handle to the listbox to be queried.
  */
-unsigned int dw_listbox_selected(HWND handle)
+int dw_listbox_selected(HWND handle)
 {
    GtkWidget *handle2 = handle;
    int retval = DW_LIT_NONE;
--- a/gtk3/dw.c	Sat May 07 02:15:50 2011 +0000
+++ b/gtk3/dw.c	Sat May 07 05:14:06 2011 +0000
@@ -5374,7 +5374,7 @@
    gtk_widget_show(tree);
    free(array);
    DW_MUTEX_UNLOCK;
-   return TRUE;
+   return DW_ERROR_NONE;
 }
 
 /*
@@ -5415,7 +5415,7 @@
 
    if ( newtitles) free(newtitles);
    if ( newflags ) free(newflags);
-   return TRUE;
+   return DW_ERROR_NONE;
 }
 
 /*
@@ -7266,14 +7266,14 @@
 int dw_event_reset (HEV eve)
 {
    if(!eve)
-      return FALSE;
+      return DW_ERROR_NON_INIT;
 
    pthread_mutex_lock (&(eve->mutex));
    pthread_cond_broadcast (&(eve->event));
    pthread_cond_init (&(eve->event), NULL);
    eve->posted = 0;
    pthread_mutex_unlock (&(eve->mutex));
-   return 0;
+   return DW_ERROR_NONE;
 }
 
 /*
@@ -7285,13 +7285,13 @@
 int dw_event_post (HEV eve)
 {
    if(!eve)
-      return FALSE;
+      return DW_ERROR_NON_INIT;
 
    pthread_mutex_lock (&(eve->mutex));
    pthread_cond_broadcast (&(eve->event));
    eve->posted = 1;
    pthread_mutex_unlock (&(eve->mutex));
-   return 0;
+   return DW_ERROR_NONE;
 }
 
 /*
@@ -7307,10 +7307,10 @@
    struct timespec timeo;
 
    if(!eve)
-      return FALSE;
+      return DW_ERROR_NON_INIT;
 
    if(eve->posted)
-      return 0;
+      return DW_ERROR_GENERAL;
 
    pthread_mutex_lock (&(eve->mutex));
    gettimeofday(&now, 0);
@@ -7319,10 +7319,10 @@
    rc = pthread_cond_timedwait (&(eve->event), &(eve->mutex), &timeo);
    pthread_mutex_unlock (&(eve->mutex));
    if(!rc)
-      return 1;
+      return DW_ERROR_NONE;
    if(rc == ETIMEDOUT)
-      return -1;
-   return 0;
+      return DW_ERROR_TIMEOUT;
+   return DW_ERROR_GENERAL;
 }
 
 /*
@@ -7333,7 +7333,7 @@
 int dw_event_close(HEV *eve)
 {
    if(!eve || !(*eve))
-      return FALSE;
+      return DW_ERROR_NON_INIT;
 
    pthread_mutex_lock (&((*eve)->mutex));
    pthread_cond_destroy (&((*eve)->event));
@@ -7342,7 +7342,7 @@
    free(*eve);
    *eve = NULL;
 
-   return TRUE;
+   return DW_ERROR_NONE;
 }
 
 struct _seminfo {
@@ -8887,7 +8887,7 @@
  * Parameters:
  *          handle: Handle to the listbox to be queried.
  */
-unsigned int dw_listbox_selected(HWND handle)
+int dw_listbox_selected(HWND handle)
 {
    GtkWidget *handle2 = handle;
    GtkListStore *store = NULL;
--- a/mac/dw.m	Sat May 07 02:15:50 2011 +0000
+++ b/mac/dw.m	Sat May 07 05:14:06 2011 +0000
@@ -4070,7 +4070,7 @@
  * Parameters:
  *          handle: Handle to the listbox to be queried.
  */
-unsigned int API dw_listbox_selected(HWND handle)
+int API dw_listbox_selected(HWND handle)
 {
     id object = handle;
 
@@ -5225,7 +5225,7 @@
         [column release];
     }
     DW_MUTEX_UNLOCK;
-    return TRUE;
+    return DW_ERROR_NONE;
 }
 
 /*
@@ -5254,7 +5254,7 @@
 
     free(newtitles);
     free(newflags);
-    return TRUE;
+    return DW_ERROR_NONE;
 }
 
 /*
@@ -8283,14 +8283,14 @@
 int dw_event_reset (HEV eve)
 {
    if(!eve)
-      return FALSE;
+      return DW_ERROR_NON_INIT;
 
    pthread_mutex_lock (&(eve->mutex));
    pthread_cond_broadcast (&(eve->event));
    pthread_cond_init (&(eve->event), NULL);
    eve->posted = 0;
    pthread_mutex_unlock (&(eve->mutex));
-   return 0;
+   return DW_ERROR_NONE;
 }
 
 /*
@@ -8324,10 +8324,10 @@
    struct timespec timeo;
 
    if(!eve)
-      return FALSE;
+      return DW_ERROR_NON_INIT;
 
    if(eve->posted)
-      return 0;
+      return DW_ERROR_GENERAL;
 
    pthread_mutex_lock (&(eve->mutex));
    gettimeofday(&now, 0);
@@ -8336,10 +8336,10 @@
    rc = pthread_cond_timedwait (&(eve->event), &(eve->mutex), &timeo);
    pthread_mutex_unlock (&(eve->mutex));
    if(!rc)
-      return 1;
+      return DW_ERROR_NONE;
    if(rc == ETIMEDOUT)
-      return -1;
-   return 0;
+      return DW_ERROR_TIMEOUT;
+   return DW_ERROR_GENERAL;
 }
 
 /*
@@ -8350,7 +8350,7 @@
 int dw_event_close(HEV *eve)
 {
    if(!eve || !(*eve))
-      return FALSE;
+      return DW_ERROR_NON_INIT;
 
    pthread_mutex_lock (&((*eve)->mutex));
    pthread_cond_destroy (&((*eve)->event));
@@ -8359,7 +8359,7 @@
    free(*eve);
    *eve = NULL;
 
-   return TRUE;
+   return DW_ERROR_NONE;
 }
 
 struct _seminfo {
--- a/os2/dw.c	Sat May 07 02:15:50 2011 +0000
+++ b/os2/dw.c	Sat May 07 05:14:06 2011 +0000
@@ -2634,7 +2634,7 @@
                         if(_recursing == 0 && (tmp->window == conthwnd || (!id && tmp->window == (HWND)mp2)))
                         {
                            char buf1[500];
-                           unsigned int index = dw_listbox_selected(tmp->window);
+                           int index = dw_listbox_selected(tmp->window);
 
                            dw_listbox_get_text(tmp->window, index, buf1, 500);
 
@@ -6288,7 +6288,7 @@
  * Parameters:
  *          handle: Handle to the listbox to be queried.
  */
-unsigned int API dw_listbox_selected(HWND handle)
+int API dw_listbox_selected(HWND handle)
 {
       return (unsigned int)WinSendMsg(handle,
                               LM_QUERYSELECTION,
@@ -7062,7 +7062,7 @@
    WinSendMsg(handle, CM_SETCNRINFO, &cnri, MPFROMLONG(CMA_FLWINDOWATTR | CMA_SLBITMAPORICON));
 
    free(offStruct);
-   return TRUE;
+   return DW_ERROR_NONE;
 }
 
 /*
@@ -7091,7 +7091,7 @@
 
    free(newtitles);
    free(newflags);
-   return TRUE;
+   return DW_ERROR_NONE;
 }
 
 /*
@@ -8849,8 +8849,8 @@
    ULONG count;
 
    if(DosResetEventSem(eve, &count))
-      return FALSE;
-   return TRUE;
+      return DW_ERROR_GENERAL;
+   return DW_ERROR_NONE;
 }
 
 /*
@@ -8862,8 +8862,8 @@
 int API dw_event_post(HEV eve)
 {
    if(DosPostEventSem(eve))
-      return FALSE;
-   return TRUE;
+      return DW_ERROR_GENERAL;
+   return DW_ERROR_NONE;
 }
 
 
@@ -8877,10 +8877,10 @@
 {
    int rc = DosWaitEventSem(eve, timeout);
    if(!rc)
-      return 1;
+      return DW_ERROR_NONE;
    if(rc == ERROR_TIMEOUT)
-      return -1;
-   return 0;
+      return DW_ERROR_TIMEOUT;
+   return DW_ERROR_GENERAL;
 }
 
 /*
@@ -8891,8 +8891,8 @@
 int API dw_event_close(HEV *eve)
 {
    if(!eve || ~DosCloseEventSem(*eve))
-      return FALSE;
-   return TRUE;
+      return DW_ERROR_GENERAL;
+   return DW_ERROR_NONE;
 }
 
 /* Create a named event semaphore which can be
--- a/template/dw.c	Sat May 07 02:15:50 2011 +0000
+++ b/template/dw.c	Sat May 07 05:14:06 2011 +0000
@@ -1208,7 +1208,7 @@
  * Returns:
  *       The selected item index or DW_ERROR_UNKNOWN (-1) on error.
  */
-unsigned int API dw_listbox_selected(HWND handle)
+int API dw_listbox_selected(HWND handle)
 {
     return DW_ERROR_UNKNOWN;
 }
@@ -3165,10 +3165,12 @@
  *       eve: The handle to the event returned by dw_event_new().
  * Returns:
  *       DW_ERROR_NONE (0) on success.
+ *       DW_ERROR_TIMEOUT (2) if the timeout has expired.
+ *       Other values on other error.
  */
 int dw_event_wait(HEV eve, unsigned long timeout)
 {
-   return DW_ERROR_GENERAL;
+   return DW_ERROR_GENERAL
 }
 
 /*
--- a/win/dw.c	Sat May 07 02:15:50 2011 +0000
+++ b/win/dw.c	Sat May 07 05:14:06 2011 +0000
@@ -6664,7 +6664,7 @@
  * Parameters:
  *          handle: Handle to the listbox to be queried.
  */
-unsigned int API dw_listbox_selected(HWND handle)
+int API dw_listbox_selected(HWND handle)
 {
    char tmpbuf[100];
 
@@ -7542,7 +7542,7 @@
       }
    }
    ListView_SetExtendedListViewStyle(handle, LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);
-   return TRUE;
+   return DW_ERROR_NONE;
 }
 
 /*
@@ -7568,7 +7568,7 @@
    lvc.iSubItem = count;
    SendMessage(handle, LVM_INSERTCOLUMN, (WPARAM)0, (LPARAM)&lvc);
    dw_container_setup(handle, flags, titles, count, -1);
-   return TRUE;
+   return DW_ERROR_NONE;
 }
 
 /*
@@ -9080,7 +9080,7 @@
 int API dw_module_load(char *name, HMOD *handle)
 {
    if(!handle)
-      return   -1;
+      return DW_ERROR_UNKNOWN;
 
    *handle = LoadLibrary(name);
    return (NULL == *handle);
@@ -9096,10 +9096,10 @@
 int API dw_module_symbol(HMOD handle, char *name, void**func)
 {
    if(!func || !name)
-      return   -1;
+      return DW_ERROR_UNKNOWN;
 
    if(0 == strlen(name))
-      return   -1;
+      return DW_ERROR_UNKNOWN;
 
    *func = (void*)GetProcAddress(handle, name);
    return   (NULL == *func);
@@ -9189,7 +9189,7 @@
  */
 int API dw_event_post(HEV eve)
 {
-   return SetEvent(eve);
+   return (SetEvent(eve) == 0);
 }
 
 /*
@@ -9204,10 +9204,10 @@
 
    rc = WaitForSingleObject(eve, timeout);
    if(rc == WAIT_OBJECT_0)
-      return 1;
+      return DW_ERROR_NONE;
    if(rc == WAIT_ABANDONED)
-      return -1;
-   return 0;
+      return DW_ERROR_TIMEOUT;
+   return DW_ERROR_GENERAL;
 }
 
 /*
@@ -9218,8 +9218,8 @@
 int API dw_event_close(HEV *eve)
 {
    if(eve)
-      return CloseHandle(*eve);
-   return 0;
+      return (CloseHandle(*eve) == 0);
+   return DW_ERROR_NONE;
 }
 
 /* Create a named event semaphore which can be
@@ -9262,9 +9262,9 @@
 
    rc = ResetEvent(eve);
    if(!rc)
-      return 1;
-
-   return 0;
+      return DW_ERROR_GENERAL;
+
+   return DW_ERROR_NONE;
 }
 
 /* Sets the posted state of an event semaphore, any threads