Mercurial > dwindows
comparison gtk/dw.c @ 1875:fb137f7f91e4
Initial commit of GTK2 code changes (untested) ...
Cleanups of some other platform code.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 09 Aug 2013 02:11:06 +0000 |
parents | a3e356948426 |
children | 4ca16d418039 |
comparison
equal
deleted
inserted
replaced
1874:71c8a45b2a35 | 1875:fb137f7f91e4 |
---|---|
7650 if(clist && GTK_IS_CLIST(clist)) | 7650 if(clist && GTK_IS_CLIST(clist)) |
7651 gtk_clist_set_column_width(GTK_CLIST(clist), column, width); | 7651 gtk_clist_set_column_width(GTK_CLIST(clist), column, width); |
7652 DW_MUTEX_UNLOCK; | 7652 DW_MUTEX_UNLOCK; |
7653 } | 7653 } |
7654 | 7654 |
7655 void _dw_container_row_data_destroy(gpointer data) | |
7656 { | |
7657 void **params = (void **)data; | |
7658 | |
7659 if(params) | |
7660 { | |
7661 if(params[0]) | |
7662 free(params[0]); | |
7663 free(params); | |
7664 } | |
7665 } | |
7666 | |
7655 /* Internal version for both */ | 7667 /* Internal version for both */ |
7656 void _dw_container_set_row_title(HWND handle, void *pointer, int row, char *title) | 7668 #define _DW_DATA_TYPE_STRING 0 |
7669 #define _DW_DATA_TYPE_POINTER 1 | |
7670 | |
7671 void _dw_container_set_row_data(HWND handle, void *pointer, int row, int type, void *data) | |
7657 { | 7672 { |
7658 GtkWidget *clist; | 7673 GtkWidget *clist; |
7659 int _locked_by_me = FALSE; | 7674 int _locked_by_me = FALSE; |
7660 | 7675 |
7661 DW_MUTEX_LOCK; | 7676 DW_MUTEX_LOCK; |
7664 { | 7679 { |
7665 row += GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(clist), "_dw_insertpos")); | 7680 row += GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(clist), "_dw_insertpos")); |
7666 } | 7681 } |
7667 | 7682 |
7668 if(clist) | 7683 if(clist) |
7669 gtk_clist_set_row_data(GTK_CLIST(clist), row, (gpointer)title); | 7684 { |
7685 void **params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), row); | |
7686 | |
7687 if(!params) | |
7688 { | |
7689 params = (void **)calloc(2, sizeof(void *)); | |
7690 gtk_clist_set_row_data_full(GTK_CLIST(clist), row, (gpointer)params, _dw_container_row_data_destroy); | |
7691 } | |
7692 if(type == _DW_DATA_TYPE_STRING) | |
7693 { | |
7694 void *oldtitle = params[0]; | |
7695 params[0] = data ? (void *)strdup((char *)data) : NULL; | |
7696 if(oldtitle) | |
7697 free(oldtitle); | |
7698 } | |
7699 else | |
7700 params[type] = data; | |
7701 } | |
7670 DW_MUTEX_UNLOCK; | 7702 DW_MUTEX_UNLOCK; |
7671 } | 7703 } |
7672 | 7704 |
7673 /* | 7705 /* |
7674 * Sets the title of a row in the container. | 7706 * Sets the title of a row in the container. |
7677 * row: Zero based row of data being set. | 7709 * row: Zero based row of data being set. |
7678 * title: String title of the item. | 7710 * title: String title of the item. |
7679 */ | 7711 */ |
7680 void dw_container_set_row_title(void *pointer, int row, char *title) | 7712 void dw_container_set_row_title(void *pointer, int row, char *title) |
7681 { | 7713 { |
7682 _dw_container_set_row_title(pointer, pointer, row, title); | 7714 _dw_container_set_row_data(pointer, pointer, row, _DW_DATA_TYPE_STRING, title); |
7683 } | 7715 } |
7684 | 7716 |
7685 /* | 7717 /* |
7686 * Changes the title of a row already inserted in the container. | 7718 * Changes the title of a row already inserted in the container. |
7687 * Parameters: | 7719 * Parameters: |
7689 * row: Zero based row of data being set. | 7721 * row: Zero based row of data being set. |
7690 * title: String title of the item. | 7722 * title: String title of the item. |
7691 */ | 7723 */ |
7692 void dw_container_change_row_title(HWND handle, int row, char *title) | 7724 void dw_container_change_row_title(HWND handle, int row, char *title) |
7693 { | 7725 { |
7694 _dw_container_set_row_title(handle, NULL, row, title); | 7726 _dw_container_set_row_data(handle, NULL, row, _DW_DATA_TYPE_STRING, title); |
7727 } | |
7728 | |
7729 /* | |
7730 * Sets the data of a row in the container. | |
7731 * Parameters: | |
7732 * pointer: Pointer to the allocated memory in dw_container_alloc(). | |
7733 * row: Zero based row of data being set. | |
7734 * data: Data pointer. | |
7735 */ | |
7736 void dw_container_set_row_data(void *pointer, int row, void *data) | |
7737 { | |
7738 _dw_container_set_row_data(pointer, pointer, row, _DW_DATA_TYPE_POINTER, data); | |
7739 } | |
7740 | |
7741 /* | |
7742 * Changes the data of a row already inserted in the container. | |
7743 * Parameters: | |
7744 * handle: Handle to window (widget) of container. | |
7745 * row: Zero based row of data being set. | |
7746 * data: Data pointer. | |
7747 */ | |
7748 void dw_container_change_row_data(HWND handle, int row, void *data) | |
7749 { | |
7750 _dw_container_set_row_data(handle, NULL, row, _DW_DATA_TYPE_POINTER, data); | |
7695 } | 7751 } |
7696 | 7752 |
7697 /* | 7753 /* |
7698 * Sets the title of a row in the container. | 7754 * Sets the title of a row in the container. |
7699 * Parameters: | 7755 * Parameters: |
7820 */ | 7876 */ |
7821 char *dw_container_query_start(HWND handle, unsigned long flags) | 7877 char *dw_container_query_start(HWND handle, unsigned long flags) |
7822 { | 7878 { |
7823 GtkWidget *clist; | 7879 GtkWidget *clist; |
7824 GList *list; | 7880 GList *list; |
7825 char *retval = NULL; | 7881 void *retval = NULL; |
7826 int _locked_by_me = FALSE; | 7882 int _locked_by_me = FALSE; |
7883 int type = _DW_DATA_TYPE_STRING; | |
7884 void **params; | |
7885 | |
7886 if(flags & DW_CR_RETDATA) | |
7887 type = _DW_DATA_TYPE_POINTER; | |
7827 | 7888 |
7828 DW_MUTEX_LOCK; | 7889 DW_MUTEX_LOCK; |
7829 clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle)); | 7890 clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle)); |
7830 | 7891 |
7831 if(!clist) | 7892 if(!clist) |
7840 list = GTK_CLIST(clist)->selection; | 7901 list = GTK_CLIST(clist)->selection; |
7841 | 7902 |
7842 if(list) | 7903 if(list) |
7843 { | 7904 { |
7844 gtk_object_set_data(GTK_OBJECT(clist), "_dw_querypos", GINT_TO_POINTER(1)); | 7905 gtk_object_set_data(GTK_OBJECT(clist), "_dw_querypos", GINT_TO_POINTER(1)); |
7845 retval = (char *)gtk_clist_get_row_data(GTK_CLIST(clist), GPOINTER_TO_UINT(list->data)); | 7906 params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), GPOINTER_TO_UINT(list->data)); |
7907 retval = params ? params[type] : NULL; | |
7846 } | 7908 } |
7847 } | 7909 } |
7848 else if(flags & DW_CRA_CURSORED) | 7910 else if(flags & DW_CRA_CURSORED) |
7849 { | 7911 { |
7850 retval = (char *)gtk_clist_get_row_data(GTK_CLIST(clist), GTK_CLIST(clist)->focus_row); | 7912 params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), GTK_CLIST(clist)->focus_row); |
7913 retval = params ? params[type] : NULL; | |
7851 } | 7914 } |
7852 else | 7915 else |
7853 { | 7916 { |
7854 retval = (char *)gtk_clist_get_row_data(GTK_CLIST(clist), 0); | 7917 params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), 0); |
7855 gtk_object_set_data(GTK_OBJECT(clist), "_dw_querypos", GINT_TO_POINTER(1)); | 7918 gtk_object_set_data(GTK_OBJECT(clist), "_dw_querypos", GINT_TO_POINTER(1)); |
7919 retval = params ? params[type] : NULL; | |
7856 } | 7920 } |
7857 DW_MUTEX_UNLOCK; | 7921 DW_MUTEX_UNLOCK; |
7858 return retval; | 7922 return retval; |
7859 } | 7923 } |
7860 | 7924 |
7868 */ | 7932 */ |
7869 char *dw_container_query_next(HWND handle, unsigned long flags) | 7933 char *dw_container_query_next(HWND handle, unsigned long flags) |
7870 { | 7934 { |
7871 GtkWidget *clist; | 7935 GtkWidget *clist; |
7872 GList *list; | 7936 GList *list; |
7873 char *retval = NULL; | 7937 void *retval = NULL; |
7874 int _locked_by_me = FALSE; | 7938 int _locked_by_me = FALSE; |
7939 int type = _DW_DATA_TYPE_STRING; | |
7940 void **params; | |
7941 | |
7942 if(flags & DW_CR_RETDATA) | |
7943 type = _DW_DATA_TYPE_POINTER; | |
7875 | 7944 |
7876 DW_MUTEX_LOCK; | 7945 DW_MUTEX_LOCK; |
7877 clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle)); | 7946 clist = (GtkWidget*)gtk_object_get_user_data(GTK_OBJECT(handle)); |
7878 | 7947 |
7879 if(!clist) | 7948 if(!clist) |
7897 list = list->next; | 7966 list = list->next; |
7898 counter++; | 7967 counter++; |
7899 } | 7968 } |
7900 | 7969 |
7901 if(list) | 7970 if(list) |
7902 retval = (char *)gtk_clist_get_row_data(GTK_CLIST(clist), GPOINTER_TO_UINT(list->data)); | 7971 { |
7972 params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), GPOINTER_TO_UINT(list->data)); | |
7973 retval = params ? params[type] : NULL; | |
7974 } | |
7903 } | 7975 } |
7904 } | 7976 } |
7905 else if(flags & DW_CRA_CURSORED) | 7977 else if(flags & DW_CRA_CURSORED) |
7906 { | 7978 { |
7907 /* There will only be one item cursored, | 7979 /* There will only be one item cursored, |
7911 } | 7983 } |
7912 else | 7984 else |
7913 { | 7985 { |
7914 int pos = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(clist), "_dw_querypos")); | 7986 int pos = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(clist), "_dw_querypos")); |
7915 | 7987 |
7916 retval = (char *)gtk_clist_get_row_data(GTK_CLIST(clist), pos); | 7988 params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), pos); |
7917 gtk_object_set_data(GTK_OBJECT(clist), "_dw_querypos", GINT_TO_POINTER(pos+1)); | 7989 gtk_object_set_data(GTK_OBJECT(clist), "_dw_querypos", GINT_TO_POINTER(pos+1)); |
7990 retval = params ? params[type] : NULL; | |
7918 } | 7991 } |
7919 DW_MUTEX_UNLOCK; | 7992 DW_MUTEX_UNLOCK; |
7920 return retval; | 7993 return retval; |
7921 } | 7994 } |
7922 | 7995 |
7923 /* | 7996 void _dw_container_cursor(HWND handle, int textcomp, void *data) |
7924 * Cursors the item with the text speficied, and scrolls to that item. | |
7925 * Parameters: | |
7926 * handle: Handle to the window (widget) to be queried. | |
7927 * text: Text usually returned by dw_container_query(). | |
7928 */ | |
7929 void dw_container_cursor(HWND handle, char *text) | |
7930 { | 7997 { |
7931 int _locked_by_me = FALSE; | 7998 int _locked_by_me = FALSE; |
7932 GtkWidget *clist; | 7999 GtkWidget *clist; |
7933 int rowcount, z, textcomp; | 8000 int rowcount, z, textcomp; |
7934 char *rowdata; | 8001 char *rowdata; |
7939 if(!clist) | 8006 if(!clist) |
7940 { | 8007 { |
7941 DW_MUTEX_UNLOCK; | 8008 DW_MUTEX_UNLOCK; |
7942 return; | 8009 return; |
7943 } | 8010 } |
7944 textcomp = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(handle), "_dw_textcomp")); | |
7945 rowcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(clist), "_dw_rowcount")); | 8011 rowcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(clist), "_dw_rowcount")); |
7946 | 8012 |
7947 for(z=0;z<rowcount;z++) | 8013 for(z=0;z<rowcount;z++) |
7948 { | 8014 { |
7949 rowdata = gtk_clist_get_row_data(GTK_CLIST(clist), z); | 8015 void **params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), z); |
7950 if ( (textcomp && rowdata && strcmp(rowdata, text) == 0) || (!textcomp && rowdata == text) ) | 8016 |
8017 if ( params && ((textcomp && params[0] && strcmp((char *)params[0], (char *)data) == 0) || (!textcomp && params[1] == data)) ) | |
7951 { | 8018 { |
7952 gfloat pos; | 8019 gfloat pos; |
7953 GtkAdjustment *adj = gtk_clist_get_vadjustment(GTK_CLIST(clist)); | 8020 GtkAdjustment *adj = gtk_clist_get_vadjustment(GTK_CLIST(clist)); |
7954 | 8021 |
7955 _dw_unselect(clist); | 8022 _dw_unselect(clist); |
7965 | 8032 |
7966 DW_MUTEX_UNLOCK; | 8033 DW_MUTEX_UNLOCK; |
7967 } | 8034 } |
7968 | 8035 |
7969 /* | 8036 /* |
7970 * Deletes the item with the text speficied. | 8037 * Cursors the item with the text speficied, and scrolls to that item. |
7971 * Parameters: | 8038 * Parameters: |
7972 * handle: Handle to the window (widget). | 8039 * handle: Handle to the window (widget) to be queried. |
7973 * text: Text usually returned by dw_container_query(). | 8040 * text: Text usually returned by dw_container_query(). |
7974 */ | 8041 */ |
7975 void dw_container_delete_row(HWND handle, char *text) | 8042 void dw_container_cursor(HWND handle, char *text) |
8043 { | |
8044 _dw_container_cursor(handle, TRUE, text); | |
8045 } | |
8046 | |
8047 /* | |
8048 * Cursors the item with the data speficied, and scrolls to that item. | |
8049 * Parameters: | |
8050 * handle: Handle to the window (widget) to be queried. | |
8051 * data: Data usually returned by dw_container_query(). | |
8052 */ | |
8053 void dw_container_cursor_by_data(HWND handle, void *data) | |
8054 { | |
8055 _dw_container_cursor(handle, FALSE, data); | |
8056 } | |
8057 | |
8058 void _dw_container_delete_row(HWND handle, int textcomp, void *data) | |
7976 { | 8059 { |
7977 int _locked_by_me = FALSE; | 8060 int _locked_by_me = FALSE; |
7978 GtkWidget *clist; | 8061 GtkWidget *clist; |
7979 int rowcount, z, textcomp; | 8062 int rowcount, z, textcomp; |
7980 char *rowdata; | 8063 char *rowdata; |
7985 if(!clist) | 8068 if(!clist) |
7986 { | 8069 { |
7987 DW_MUTEX_UNLOCK; | 8070 DW_MUTEX_UNLOCK; |
7988 return; | 8071 return; |
7989 } | 8072 } |
7990 textcomp = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(handle), "_dw_textcomp")); | |
7991 rowcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(clist), "_dw_rowcount")); | 8073 rowcount = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(clist), "_dw_rowcount")); |
7992 | 8074 |
7993 for(z=0;z<rowcount;z++) | 8075 for(z=0;z<rowcount;z++) |
7994 { | 8076 { |
7995 rowdata = gtk_clist_get_row_data(GTK_CLIST(clist), z); | 8077 void **params = (void **)gtk_clist_get_row_data(GTK_CLIST(clist), z); |
7996 if ( (textcomp && rowdata && strcmp(rowdata, text) == 0) || (!textcomp && rowdata == text) ) | 8078 |
8079 if ( params && ((textcomp && params[0] && strcmp((char *)params[0], (char *)data) == 0) || (!textcomp && params[1] == data)) ) | |
7997 { | 8080 { |
7998 _dw_unselect(clist); | 8081 _dw_unselect(clist); |
7999 | 8082 |
8000 gtk_clist_remove(GTK_CLIST(clist), z); | 8083 gtk_clist_remove(GTK_CLIST(clist), z); |
8001 | 8084 |
8002 rowcount--; | 8085 rowcount--; |
8003 | 8086 |
8004 gtk_object_set_data(GTK_OBJECT(clist), "_dw_rowcount", GINT_TO_POINTER(rowcount)); | 8087 gtk_object_set_data(GTK_OBJECT(clist), "_dw_rowcount", GINT_TO_POINTER(rowcount)); |
8005 _update_clist_rows(clist); | 8088 _update_clist_rows(clist); |
8006 DW_MUTEX_UNLOCK; | 8089 DW_MUTEX_UNLOCK; |
8007 return; | 8090 return; |
8008 } | 8091 } |
8009 } | 8092 } |
8010 | 8093 |
8011 DW_MUTEX_UNLOCK; | 8094 DW_MUTEX_UNLOCK; |
8095 } | |
8096 | |
8097 /* | |
8098 * Deletes the item with the text speficied. | |
8099 * Parameters: | |
8100 * handle: Handle to the window (widget). | |
8101 * text: Text usually returned by dw_container_query(). | |
8102 */ | |
8103 void dw_container_delete_row(HWND handle, char *text) | |
8104 { | |
8105 _dw_container_delete_row(handle, _DW_DATA_TYPE_STRING, text); | |
8106 } | |
8107 | |
8108 /* | |
8109 * Deletes the item with the data speficied. | |
8110 * Parameters: | |
8111 * handle: Handle to the window (widget). | |
8112 * data: Data usually returned by dw_container_query(). | |
8113 */ | |
8114 void dw_container_delete_row_by_data(HWND handle, void *data) | |
8115 { | |
8116 _dw_container_delete_row(handle, _DW_DATA_TYPE_POINTER, data); | |
8012 } | 8117 } |
8013 | 8118 |
8014 /* | 8119 /* |
8015 * Optimizes the column widths so that all data is visible. | 8120 * Optimizes the column widths so that all data is visible. |
8016 * Parameters: | 8121 * Parameters: |