comparison gtk/dw.c @ 114:39932767ef46

Fixes to the notebook code to better handle removing of pages. Also, added a few mutexes where there should have been.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 09 Oct 2002 04:32:52 +0000
parents cf0115e38ef0
children 2d121d4d90c0
comparison
equal deleted inserted replaced
113:553f3b4f8b5b 114:39932767ef46
339 339
340 while(list) 340 while(list)
341 { 341 {
342 if(list->data == (gpointer)child) 342 if(list->data == (gpointer)child)
343 { 343 {
344 gtk_object_set_data(GTK_OBJECT(work->window), "item", (gpointer)item); 344 if(!gtk_object_get_data(GTK_OBJECT(work->window), "appending"))
345 selectfunc(work->window, item, work->data); 345 {
346 gtk_object_set_data(GTK_OBJECT(work->window), "item", (gpointer)item);
347 selectfunc(work->window, item, work->data);
348 }
346 break; 349 break;
347 } 350 }
348 item++; 351 item++;
349 list = list->next; 352 list = list->next;
350 } 353 }
1316 * handle: Handle to widget for which to change. 1319 * handle: Handle to widget for which to change.
1317 * cursortype: ID of the pointer you want. 1320 * cursortype: ID of the pointer you want.
1318 */ 1321 */
1319 void dw_window_pointer(HWND handle, int pointertype) 1322 void dw_window_pointer(HWND handle, int pointertype)
1320 { 1323 {
1321 GdkCursor *cursor = gdk_cursor_new(pointertype); 1324 int _locked_by_me = FALSE;
1325 GdkCursor *cursor;
1326
1327 DW_MUTEX_LOCK;
1328 cursor = gdk_cursor_new(pointertype);
1322 if(handle && handle->window) 1329 if(handle && handle->window)
1323 gdk_window_set_cursor(handle->window, cursor); 1330 gdk_window_set_cursor(handle->window, cursor);
1324 gdk_cursor_destroy(cursor); 1331 gdk_cursor_destroy(cursor);
1332 DW_MUTEX_UNLOCK;
1325 } 1333 }
1326 1334
1327 /* 1335 /*
1328 * Releases previous mouse capture. 1336 * Releases previous mouse capture.
1329 */ 1337 */
1436 * Parameters: 1444 * Parameters:
1437 * id: An ID to be used with dw_window_from_id or 0L. 1445 * id: An ID to be used with dw_window_from_id or 0L.
1438 */ 1446 */
1439 HWND dw_mdi_new(unsigned long id) 1447 HWND dw_mdi_new(unsigned long id)
1440 { 1448 {
1441 return gtk_vbox_new(FALSE, 0); 1449 GtkWidget *tmp;
1450 int _locked_by_me = FALSE;
1451
1452 DW_MUTEX_LOCK;
1453 tmp = gtk_vbox_new(FALSE, 0);
1454 DW_MUTEX_UNLOCK;
1455 return tmp;
1442 } 1456 }
1443 1457
1444 /* 1458 /*
1445 * Create a bitmap object to be packed. 1459 * Create a bitmap object to be packed.
1446 * Parameters: 1460 * Parameters:
1482 * id: An ID to be used for getting the resource from the 1496 * id: An ID to be used for getting the resource from the
1483 * resource file. 1497 * resource file.
1484 */ 1498 */
1485 HWND dw_notebook_new(unsigned long id, int top) 1499 HWND dw_notebook_new(unsigned long id, int top)
1486 { 1500 {
1487 GtkWidget *tmp; 1501 GtkWidget *tmp, **pagearray = calloc(sizeof(GtkWidget *), 256);
1488 int _locked_by_me = FALSE; 1502 int _locked_by_me = FALSE;
1489 1503
1490 DW_MUTEX_LOCK; 1504 DW_MUTEX_LOCK;
1491 tmp = gtk_notebook_new(); 1505 tmp = gtk_notebook_new();
1492 if(top) 1506 if(top)
1497 #if 0 1511 #if 0
1498 gtk_notebook_popup_enable(GTK_NOTEBOOK(tmp)); 1512 gtk_notebook_popup_enable(GTK_NOTEBOOK(tmp));
1499 #endif 1513 #endif
1500 gtk_widget_show(tmp); 1514 gtk_widget_show(tmp);
1501 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id); 1515 gtk_object_set_data(GTK_OBJECT(tmp), "id", (gpointer)id);
1516 gtk_object_set_data(GTK_OBJECT(tmp), "pagearray", (gpointer)pagearray);
1502 DW_MUTEX_UNLOCK; 1517 DW_MUTEX_UNLOCK;
1503 return tmp; 1518 return tmp;
1504 } 1519 }
1505 1520
1506 /* 1521 /*
4822 */ 4837 */
4823 unsigned long dw_notebook_page_new(HWND handle, unsigned long flags, int front) 4838 unsigned long dw_notebook_page_new(HWND handle, unsigned long flags, int front)
4824 { 4839 {
4825 int z; 4840 int z;
4826 int _locked_by_me = FALSE; 4841 int _locked_by_me = FALSE;
4827 4842 GtkWidget **pagearray;
4828 DW_MUTEX_LOCK; 4843
4829 for(z=0;z<256;z++) 4844 DW_MUTEX_LOCK;
4830 { 4845 pagearray = (GtkWidget **)gtk_object_get_data(GTK_OBJECT(handle), "pagearray");
4831 if(!gtk_notebook_get_nth_page(GTK_NOTEBOOK(handle), z)) 4846
4832 { 4847 if(pagearray)
4833 DW_MUTEX_UNLOCK; 4848 {
4834 return z; 4849 for(z=0;z<256;z++)
4835 } 4850 {
4836 } 4851 if(!pagearray[z])
4837 4852 {
4838 DW_MUTEX_UNLOCK; 4853 char text[100];
4839 4854 int num = z;
4855
4856 if(front)
4857 num |= 1 << 16;
4858
4859 sprintf(text, "page%d", z);
4860 /* Save the real id and the creation flags */
4861 gtk_object_set_data(GTK_OBJECT(handle), text, (gpointer)num);
4862 DW_MUTEX_UNLOCK;
4863 return z;
4864 }
4865 }
4866 }
4867 DW_MUTEX_UNLOCK;
4868
4840 /* Hopefully this won't happen. */ 4869 /* Hopefully this won't happen. */
4841 return 256; 4870 return 256;
4842 } 4871 }
4843 4872
4873 /* Return the physical page id from the logical page id */
4874 int _get_physical_page(HWND handle, unsigned long pageid)
4875 {
4876 int z;
4877 GtkWidget *thispage, **pagearray = gtk_object_get_data(GTK_OBJECT(handle), "pagearray");
4878
4879 if(pagearray)
4880 {
4881 for(z=0;z<256;z++)
4882 {
4883 if((thispage = gtk_notebook_get_nth_page(GTK_NOTEBOOK(handle), z)))
4884 {
4885 if(thispage == pagearray[pageid])
4886 return z;
4887 }
4888 }
4889 }
4890 return 256;
4891 }
4892
4893 /* Return the logical page id from the physical page id */
4894 int _get_logical_page(HWND handle, unsigned long pageid)
4895 {
4896 int z;
4897 GtkWidget **pagearray = gtk_object_get_data(GTK_OBJECT(handle), "pagearray");
4898 GtkWidget *thispage = gtk_notebook_get_nth_page(GTK_NOTEBOOK(handle), pageid);
4899
4900 if(pagearray && thispage)
4901 {
4902 for(z=0;z<256;z++)
4903 {
4904 if(thispage == pagearray[z])
4905 return z;
4906 }
4907 }
4908 return 256;
4909 }
4910
4844 /* 4911 /*
4845 * Remove a page from a notebook. 4912 * Remove a page from a notebook.
4846 * Parameters: 4913 * Parameters:
4847 * handle: Handle to the notebook widget. 4914 * handle: Handle to the notebook widget.
4848 * pageid: ID of the page to be destroyed. 4915 * pageid: ID of the page to be destroyed.
4849 */ 4916 */
4850 void dw_notebook_page_destroy(HWND handle, unsigned int pageid) 4917 void dw_notebook_page_destroy(HWND handle, unsigned int pageid)
4851 { 4918 {
4852 int _locked_by_me = FALSE; 4919 int realpage, _locked_by_me = FALSE;
4853 4920 GtkWidget **pagearray;
4854 DW_MUTEX_LOCK; 4921
4855 gtk_notebook_remove_page(GTK_NOTEBOOK(handle), pageid); 4922 DW_MUTEX_LOCK;
4923 realpage = _get_physical_page(handle, pageid);
4924 if(realpage > -1 && realpage < 256)
4925 {
4926 gtk_notebook_remove_page(GTK_NOTEBOOK(handle), realpage);
4927 if((pagearray = gtk_object_get_data(GTK_OBJECT(handle), "pagearray")))
4928 pagearray[pageid] = NULL;
4929 }
4856 DW_MUTEX_UNLOCK; 4930 DW_MUTEX_UNLOCK;
4857 } 4931 }
4858 4932
4859 /* 4933 /*
4860 * Queries the currently visible page ID. 4934 * Queries the currently visible page ID.
4861 * Parameters: 4935 * Parameters:
4862 * handle: Handle to the notebook widget. 4936 * handle: Handle to the notebook widget.
4863 */ 4937 */
4864 unsigned int dw_notebook_page_query(HWND handle) 4938 unsigned int dw_notebook_page_query(HWND handle)
4865 { 4939 {
4866 int retval; 4940 int retval, phys;
4867 int _locked_by_me = FALSE; 4941 int _locked_by_me = FALSE;
4868 4942
4869 DW_MUTEX_LOCK; 4943 DW_MUTEX_LOCK;
4870 retval = gtk_notebook_get_current_page(GTK_NOTEBOOK(handle)); 4944 phys = gtk_notebook_get_current_page(GTK_NOTEBOOK(handle));
4945 retval = _get_logical_page(handle, phys);
4871 DW_MUTEX_UNLOCK; 4946 DW_MUTEX_UNLOCK;
4872 return retval; 4947 return retval;
4873 } 4948 }
4874 4949
4875 /* 4950 /*
4878 * handle: Handle to the notebook widget. 4953 * handle: Handle to the notebook widget.
4879 * pageid: ID of the page to be made visible. 4954 * pageid: ID of the page to be made visible.
4880 */ 4955 */
4881 void dw_notebook_page_set(HWND handle, unsigned int pageid) 4956 void dw_notebook_page_set(HWND handle, unsigned int pageid)
4882 { 4957 {
4883 int _locked_by_me = FALSE; 4958 int realpage, _locked_by_me = FALSE;
4884 4959
4885 DW_MUTEX_LOCK; 4960 DW_MUTEX_LOCK;
4886 gtk_notebook_set_page(GTK_NOTEBOOK(handle), pageid); 4961 realpage = _get_physical_page(handle, pageid);
4962 if(realpage > -1 && realpage < 256)
4963 gtk_notebook_set_page(GTK_NOTEBOOK(handle), pageid);
4887 DW_MUTEX_UNLOCK; 4964 DW_MUTEX_UNLOCK;
4888 } 4965 }
4889 4966
4890 4967
4891 /* 4968 /*
4896 * text: Pointer to the text to set. 4973 * text: Pointer to the text to set.
4897 */ 4974 */
4898 void dw_notebook_page_set_text(HWND handle, unsigned long pageid, char *text) 4975 void dw_notebook_page_set_text(HWND handle, unsigned long pageid, char *text)
4899 { 4976 {
4900 GtkWidget *child; 4977 GtkWidget *child;
4901 int _locked_by_me = FALSE; 4978 int realpage, _locked_by_me = FALSE;
4902 4979
4903 DW_MUTEX_LOCK; 4980 DW_MUTEX_LOCK;
4904 child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(handle), pageid); 4981 realpage = _get_physical_page(handle, pageid);
4905 if(child) 4982 if(realpage < 0 || realpage > 255)
4906 gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(handle), child, text); 4983 {
4984 char ptext[100];
4985 int num;
4986
4987 sprintf(ptext, "page%d", (int)pageid);
4988 num = (int)gtk_object_get_data(GTK_OBJECT(handle), ptext);
4989 realpage = 0xFF & num;
4990 }
4991
4992 if(realpage > -1 && realpage < 256)
4993 {
4994 child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(handle), realpage);
4995 if(child)
4996 gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(handle), child, text);
4997 }
4907 DW_MUTEX_UNLOCK; 4998 DW_MUTEX_UNLOCK;
4908 } 4999 }
4909 5000
4910 /* 5001 /*
4911 * Sets the text on the specified notebook tab status area. 5002 * Sets the text on the specified notebook tab status area.
4926 * pageid: Page ID in the notebook which is being packed. 5017 * pageid: Page ID in the notebook which is being packed.
4927 * page: Box handle to be packed. 5018 * page: Box handle to be packed.
4928 */ 5019 */
4929 void dw_notebook_pack(HWND handle, unsigned long pageid, HWND page) 5020 void dw_notebook_pack(HWND handle, unsigned long pageid, HWND page)
4930 { 5021 {
4931 GtkWidget *label, *child, *oldlabel; 5022 GtkWidget *label, *child, *oldlabel, **pagearray;
4932 gchar *text = NULL; 5023 gchar *text = NULL;
4933 int pad, _locked_by_me = FALSE; 5024 int num, z, realpage = -1, pad, _locked_by_me = FALSE;
4934 5025 char ptext[100];
4935 DW_MUTEX_LOCK; 5026
4936 child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(handle), pageid); 5027 DW_MUTEX_LOCK;
4937 if(child) 5028 sprintf(ptext, "page%d", (int)pageid);
4938 { 5029 num = (int)gtk_object_get_data(GTK_OBJECT(handle), ptext);
4939 oldlabel = gtk_notebook_get_tab_label(GTK_NOTEBOOK(handle), child); 5030 gtk_object_set_data(GTK_OBJECT(handle), ptext, NULL);
4940 if(oldlabel) 5031 pagearray = (GtkWidget **)gtk_object_get_data(GTK_OBJECT(handle), "pagearray");
4941 gtk_label_get(GTK_LABEL(oldlabel), &text); 5032
4942 } 5033 if(!pagearray)
5034 {
5035 DW_MUTEX_UNLOCK;
5036 return;
5037 }
5038
5039 /* The page already exists... so get it's current page */
5040 if(pagearray[pageid])
5041 {
5042 for(z=0;z<256;z++)
5043 {
5044 child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(handle), z);
5045 if(child == pagearray[pageid])
5046 {
5047 oldlabel = gtk_notebook_get_tab_label(GTK_NOTEBOOK(handle), child);
5048 if(oldlabel)
5049 gtk_label_get(GTK_LABEL(oldlabel), &text);
5050 gtk_notebook_remove_page(GTK_NOTEBOOK(handle), z);
5051 realpage = z;
5052 break;
5053 }
5054 }
5055 }
5056
5057 pagearray[pageid] = page;
4943 5058
4944 label = gtk_label_new(text ? text : ""); 5059 label = gtk_label_new(text ? text : "");
4945 5060
4946 if(GTK_IS_TABLE(page)) 5061 if(GTK_IS_TABLE(page))
4947 { 5062 {
4948 pad = (int)gtk_object_get_data(GTK_OBJECT(page), "boxpad"); 5063 pad = (int)gtk_object_get_data(GTK_OBJECT(page), "boxpad");
4949 gtk_container_border_width(GTK_CONTAINER(page), pad); 5064 gtk_container_border_width(GTK_CONTAINER(page), pad);
4950 } 5065 }
4951 5066
4952 gtk_notebook_insert_page(GTK_NOTEBOOK(handle), page, label, pageid); 5067 if(realpage != -1)
4953 if(child) 5068 gtk_notebook_insert_page(GTK_NOTEBOOK(handle), page, label, realpage);
4954 gtk_notebook_remove_page(GTK_NOTEBOOK(handle), pageid+1); 5069 else if(num & ~(0xFF))
5070 gtk_notebook_insert_page(GTK_NOTEBOOK(handle), page, label, 0);
5071 else
5072 gtk_notebook_insert_page(GTK_NOTEBOOK(handle), page, label, 256);
4955 DW_MUTEX_UNLOCK; 5073 DW_MUTEX_UNLOCK;
4956 } 5074 }
4957 5075
4958 /* 5076 /*
4959 * Appends the specified text to the listbox's (or combobox) entry list. 5077 * Appends the specified text to the listbox's (or combobox) entry list.
4971 { 5089 {
4972 GtkWidget *tmp = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle)); 5090 GtkWidget *tmp = (GtkWidget *)gtk_object_get_user_data(GTK_OBJECT(handle));
4973 if(tmp) 5091 if(tmp)
4974 handle2 = tmp; 5092 handle2 = tmp;
4975 } 5093 }
5094 gtk_object_set_data(GTK_OBJECT(handle), "appending", (gpointer)1);
4976 if(GTK_IS_LIST(handle2)) 5095 if(GTK_IS_LIST(handle2))
4977 { 5096 {
4978 GtkWidget *list_item; 5097 GtkWidget *list_item;
4979 GList *tmp; 5098 GList *tmp;
4980 char *font = (char *)gtk_object_get_data(GTK_OBJECT(handle), "font"); 5099 char *font = (char *)gtk_object_get_data(GTK_OBJECT(handle), "font");
5004 tmp = g_list_append(tmp, addtext); 5123 tmp = g_list_append(tmp, addtext);
5005 gtk_object_set_user_data(GTK_OBJECT(handle2), tmp); 5124 gtk_object_set_user_data(GTK_OBJECT(handle2), tmp);
5006 gtk_combo_set_popdown_strings(GTK_COMBO(handle2), tmp); 5125 gtk_combo_set_popdown_strings(GTK_COMBO(handle2), tmp);
5007 } 5126 }
5008 } 5127 }
5128 gtk_object_set_data(GTK_OBJECT(handle), "appending", NULL);
5009 DW_MUTEX_UNLOCK; 5129 DW_MUTEX_UNLOCK;
5010 } 5130 }
5011 5131
5012 /* 5132 /*
5013 * Clears the listbox's (or combobox) list of all entries. 5133 * Clears the listbox's (or combobox) list of all entries.