comparison gtk4/dw.c @ 2314:eda7642d80df

GTK4: Code cleanup, add _dw prefix to internal functions and structures.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 16 Feb 2021 04:10:32 +0000
parents c6ea79c74c03
children 112595f9a645
comparison
equal deleted inserted replaced
2313:c6ea79c74c03 2314:eda7642d80df
2935 { 2935 {
2936 if(menu && *menu && G_MENU(*menu)) 2936 if(menu && *menu && G_MENU(*menu))
2937 { 2937 {
2938 GtkWidget *tmp = gtk_popover_menu_new_from_model_full(G_MENU_MODEL(*menu), GTK_POPOVER_MENU_NESTED); 2938 GtkWidget *tmp = gtk_popover_menu_new_from_model_full(G_MENU_MODEL(*menu), GTK_POPOVER_MENU_NESTED);
2939 GdkRectangle rect = { x, y, 1, 1 }; 2939 GdkRectangle rect = { x, y, 1, 1 };
2940 2940
2941 gtk_widget_set_parent(tmp, GTK_WIDGET(parent)); 2941 gtk_widget_set_parent(tmp, GTK_WIDGET(parent));
2942
2942 if(!g_object_get_data(G_OBJECT(*menu), "_dw_menuparent")) 2943 if(!g_object_get_data(G_OBJECT(*menu), "_dw_menuparent"))
2943 { 2944 {
2944 int menugroup = DW_POINTER_TO_INT(g_object_get_data(G_OBJECT(*menu), "_dw_menugroup")); 2945 int menugroup = DW_POINTER_TO_INT(g_object_get_data(G_OBJECT(*menu), "_dw_menugroup"));
2945 GSimpleActionGroup *group = g_object_get_data(G_OBJECT(*menu), "_dw_group"); 2946 GSimpleActionGroup *group = g_object_get_data(G_OBJECT(*menu), "_dw_group");
2946 char tempbuf[25] = {0}; 2947 char tempbuf[25] = {0};
5924 g_free(temp); 5925 g_free(temp);
5925 } 5926 }
5926 DW_FUNCTION_RETURN_THIS(retval); 5927 DW_FUNCTION_RETURN_THIS(retval);
5927 } 5928 }
5928 5929
5929 int _find_iter(GtkListStore *store, GtkTreeIter *iter, void *data, int textcomp) 5930 int _dw_find_iter(GtkListStore *store, GtkTreeIter *iter, void *data, int textcomp)
5930 { 5931 {
5931 int z, rows = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL); 5932 int z, rows = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL);
5932 void *thisdata; 5933 void *thisdata;
5933 int retval = FALSE; 5934 int retval = FALSE;
5934 5935
5963 5964
5964 if(store) 5965 if(store)
5965 { 5966 {
5966 GtkTreeIter iter; 5967 GtkTreeIter iter;
5967 5968
5968 if(_find_iter(store, &iter, data, textcomp)) 5969 if(_dw_find_iter(store, &iter, data, textcomp))
5969 { 5970 {
5970 GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); 5971 GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
5971 5972
5972 if(path) 5973 if(path)
5973 { 5974 {
6022 if(store) 6023 if(store)
6023 { 6024 {
6024 GtkTreeIter iter; 6025 GtkTreeIter iter;
6025 int rows = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cont), "_dw_rowcount")); 6026 int rows = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cont), "_dw_rowcount"));
6026 6027
6027 if(_find_iter(store, &iter, data, textcomp)) 6028 if(_dw_find_iter(store, &iter, data, textcomp))
6028 { 6029 {
6029 gtk_list_store_remove(store, &iter); 6030 gtk_list_store_remove(store, &iter);
6030 rows--; 6031 rows--;
6031 } 6032 }
6032 6033
7038 void dw_beep(int freq, int dur) 7039 void dw_beep(int freq, int dur)
7039 { 7040 {
7040 gdk_display_beep(gdk_display_get_default()); 7041 gdk_display_beep(gdk_display_get_default());
7041 } 7042 }
7042 7043
7043 void _my_strlwr(char *buf) 7044 void _dw_strlwr(char *buf)
7044 { 7045 {
7045 int z, len = strlen(buf); 7046 int z, len = strlen(buf);
7046 7047
7047 for(z=0;z<len;z++) 7048 for(z=0;z<len;z++)
7048 { 7049 {
7075 7076
7076 if(!newname) 7077 if(!newname)
7077 return -1; 7078 return -1;
7078 7079
7079 sprintf(newname, "lib%s.so", name); 7080 sprintf(newname, "lib%s.so", name);
7080 _my_strlwr(newname); 7081 _dw_strlwr(newname);
7081 7082
7082 *handle = dlopen(newname, RTLD_NOW); 7083 *handle = dlopen(newname, RTLD_NOW);
7083 if(*handle == NULL) 7084 if(*handle == NULL)
7084 { 7085 {
7085 strncpy(errorbuf, dlerror(), 1024); 7086 strncpy(errorbuf, dlerror(), 1024);
7303 *eve = NULL; 7304 *eve = NULL;
7304 7305
7305 return DW_ERROR_NONE; 7306 return DW_ERROR_NONE;
7306 } 7307 }
7307 7308
7308 struct _seminfo { 7309 struct _dw_seminfo {
7309 int fd; 7310 int fd;
7310 int waiting; 7311 int waiting;
7311 }; 7312 };
7312 7313
7313 static void _handle_sem(int *tmpsock) 7314 static void _dw_handle_sem(int *tmpsock)
7314 { 7315 {
7315 fd_set rd; 7316 fd_set rd;
7316 struct _seminfo *array = (struct _seminfo *)malloc(sizeof(struct _seminfo)); 7317 struct _dw_seminfo *array = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo));
7317 int listenfd = tmpsock[0]; 7318 int listenfd = tmpsock[0];
7318 int bytesread, connectcount = 1, maxfd, z, posted = 0; 7319 int bytesread, connectcount = 1, maxfd, z, posted = 0;
7319 char command; 7320 char command;
7320 sigset_t mask; 7321 sigset_t mask;
7321 7322
7358 return; 7359 return;
7359 } 7360 }
7360 7361
7361 if(FD_ISSET(listenfd, &rd)) 7362 if(FD_ISSET(listenfd, &rd))
7362 { 7363 {
7363 struct _seminfo *newarray; 7364 struct _dw_seminfo *newarray;
7364 int newfd = accept(listenfd, 0, 0); 7365 int newfd = accept(listenfd, 0, 0);
7365 7366
7366 if(newfd > -1) 7367 if(newfd > -1)
7367 { 7368 {
7368 /* Add new connections to the set */ 7369 /* Add new connections to the set */
7369 newarray = (struct _seminfo *)malloc(sizeof(struct _seminfo)*(connectcount+1)); 7370 newarray = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo)*(connectcount+1));
7370 memcpy(newarray, array, sizeof(struct _seminfo)*(connectcount)); 7371 memcpy(newarray, array, sizeof(struct _dw_seminfo)*(connectcount));
7371 7372
7372 newarray[connectcount].fd = newfd; 7373 newarray[connectcount].fd = newfd;
7373 newarray[connectcount].waiting = 0; 7374 newarray[connectcount].waiting = 0;
7374 7375
7375 connectcount++; 7376 connectcount++;
7385 { 7386 {
7386 if(FD_ISSET(array[z].fd, &rd)) 7387 if(FD_ISSET(array[z].fd, &rd))
7387 { 7388 {
7388 if((bytesread = read(array[z].fd, &command, 1)) < 1) 7389 if((bytesread = read(array[z].fd, &command, 1)) < 1)
7389 { 7390 {
7390 struct _seminfo *newarray; 7391 struct _dw_seminfo *newarray;
7391 7392
7392 /* Remove this connection from the set */ 7393 /* Remove this connection from the set */
7393 newarray = (struct _seminfo *)malloc(sizeof(struct _seminfo)*(connectcount-1)); 7394 newarray = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo)*(connectcount-1));
7394 if(!z) 7395 if(!z)
7395 memcpy(newarray, &array[1], sizeof(struct _seminfo)*(connectcount-1)); 7396 memcpy(newarray, &array[1], sizeof(struct _dw_seminfo)*(connectcount-1));
7396 else 7397 else
7397 { 7398 {
7398 memcpy(newarray, array, sizeof(struct _seminfo)*z); 7399 memcpy(newarray, array, sizeof(struct _dw_seminfo)*z);
7399 if(z!=(connectcount-1)) 7400 if(z!=(connectcount-1))
7400 memcpy(&newarray[z], &array[z+1], sizeof(struct _seminfo)*(z-connectcount-1)); 7401 memcpy(&newarray[z], &array[z+1], sizeof(struct _dw_seminfo)*(z-connectcount-1));
7401 } 7402 }
7402 connectcount--; 7403 connectcount--;
7403 7404
7404 /* Replace old array with new one */ 7405 /* Replace old array with new one */
7405 free(array); 7406 free(array);
7505 free(tmpsock); 7506 free(tmpsock);
7506 return NULL; 7507 return NULL;
7507 } 7508 }
7508 7509
7509 /* Create a thread to handle this event semaphore */ 7510 /* Create a thread to handle this event semaphore */
7510 pthread_create(&dwthread, NULL, (void *)_handle_sem, (void *)tmpsock); 7511 pthread_create(&dwthread, NULL, (void *)_dw_handle_sem, (void *)tmpsock);
7511 return GINT_TO_POINTER(ev); 7512 return GINT_TO_POINTER(ev);
7512 } 7513 }
7513 7514
7514 /* Open an already existing named event semaphore. 7515 /* Open an already existing named event semaphore.
7515 * Parameters: 7516 * Parameters:
7633 * an open or create call. 7634 * an open or create call.
7634 */ 7635 */
7635 int dw_named_event_close(HEV eve) 7636 int dw_named_event_close(HEV eve)
7636 { 7637 {
7637 /* Finally close the domain socket, 7638 /* Finally close the domain socket,
7638 * cleanup will continue in _handle_sem. 7639 * cleanup will continue in _dw_handle_sem.
7639 */ 7640 */
7640 close(GPOINTER_TO_INT(eve)); 7641 close(GPOINTER_TO_INT(eve));
7641 return DW_ERROR_NONE; 7642 return DW_ERROR_NONE;
7642 } 7643 }
7643 7644
7862 dw_shutdown(); 7863 dw_shutdown();
7863 exit(exitcode); 7864 exit(exitcode);
7864 } 7865 }
7865 7866
7866 /* Internal function to get the recommended size of scrolled items */ 7867 /* Internal function to get the recommended size of scrolled items */
7867 void _get_scrolled_size(GtkWidget *item, gint *thiswidth, gint *thisheight) 7868 void _dw_get_scrolled_size(GtkWidget *item, gint *thiswidth, gint *thisheight)
7868 { 7869 {
7869 GtkWidget *widget = g_object_get_data(G_OBJECT(item), "_dw_user"); 7870 GtkWidget *widget = g_object_get_data(G_OBJECT(item), "_dw_user");
7870 7871
7871 *thisheight = *thiswidth = 0; 7872 *thisheight = *thiswidth = 0;
7872 7873
8062 { 8063 {
8063 gint scrolledwidth = 0, scrolledheight = 0; 8064 gint scrolledwidth = 0, scrolledheight = 0;
8064 8065
8065 /* Pre-run the calculation code for MLE/Container/Tree if needed */ 8066 /* Pre-run the calculation code for MLE/Container/Tree if needed */
8066 if((width < 1 && !hsize) || (height < 1 && !vsize)) 8067 if((width < 1 && !hsize) || (height < 1 && !vsize))
8067 _get_scrolled_size(item, &scrolledwidth, &scrolledheight); 8068 _dw_get_scrolled_size(item, &scrolledwidth, &scrolledheight);
8068 8069
8069 if(width > 0) 8070 if(width > 0)
8070 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(item), width); 8071 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(item), width);
8071 else if(!hsize) 8072 else if(!hsize)
8072 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(item), scrolledwidth); 8073 gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(item), scrolledwidth);
8325 { 8326 {
8326 if(GTK_IS_SCROLLED_WINDOW(handle)) 8327 if(GTK_IS_SCROLLED_WINDOW(handle))
8327 { 8328 {
8328 gint scrolledwidth, scrolledheight; 8329 gint scrolledwidth, scrolledheight;
8329 8330
8330 _get_scrolled_size(handle, &scrolledwidth, &scrolledheight); 8331 _dw_get_scrolled_size(handle, &scrolledwidth, &scrolledheight);
8331 8332
8332 if(width) 8333 if(width)
8333 *width = scrolledwidth; 8334 *width = scrolledwidth;
8334 if(height) 8335 if(height)
8335 *height = scrolledheight; 8336 *height = scrolledheight;
8608 } 8609 }
8609 DW_FUNCTION_RETURN_THIS(retval); 8610 DW_FUNCTION_RETURN_THIS(retval);
8610 } 8611 }
8611 8612
8612 /* Return the physical page id from the logical page id */ 8613 /* Return the physical page id from the logical page id */
8613 int _get_physical_page(HWND handle, unsigned long pageid) 8614 int _dw_get_physical_page(HWND handle, unsigned long pageid)
8614 { 8615 {
8615 int z; 8616 int z;
8616 GtkWidget *thispage, **pagearray = g_object_get_data(G_OBJECT(handle), "_dw_pagearray"); 8617 GtkWidget *thispage, **pagearray = g_object_get_data(G_OBJECT(handle), "_dw_pagearray");
8617 8618
8618 if(pagearray) 8619 if(pagearray)
8638 DW_FUNCTION_DEFINITION(dw_notebook_page_destroy, void, HWND handle, unsigned int pageid) 8639 DW_FUNCTION_DEFINITION(dw_notebook_page_destroy, void, HWND handle, unsigned int pageid)
8639 DW_FUNCTION_ADD_PARAM2(handle, pageid) 8640 DW_FUNCTION_ADD_PARAM2(handle, pageid)
8640 DW_FUNCTION_NO_RETURN(dw_notebook_page_destroy) 8641 DW_FUNCTION_NO_RETURN(dw_notebook_page_destroy)
8641 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, pageid, unsigned int) 8642 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, pageid, unsigned int)
8642 { 8643 {
8643 int realpage;
8644 GtkWidget **pagearray; 8644 GtkWidget **pagearray;
8645 8645 int realpage = _dw_get_physical_page(handle, pageid);
8646 realpage = _get_physical_page(handle, pageid); 8646
8647 if(realpage > -1 && realpage < 256) 8647 if(realpage > -1 && realpage < 256)
8648 { 8648 {
8649 gtk_notebook_remove_page(GTK_NOTEBOOK(handle), realpage); 8649 gtk_notebook_remove_page(GTK_NOTEBOOK(handle), realpage);
8650 if((pagearray = g_object_get_data(G_OBJECT(handle), "_dw_pagearray"))) 8650 if((pagearray = g_object_get_data(G_OBJECT(handle), "_dw_pagearray")))
8651 pagearray[pageid] = NULL; 8651 pagearray[pageid] = NULL;
8661 DW_FUNCTION_DEFINITION(dw_notebook_page_get, ULONG, HWND handle) 8661 DW_FUNCTION_DEFINITION(dw_notebook_page_get, ULONG, HWND handle)
8662 DW_FUNCTION_ADD_PARAM1(handle) 8662 DW_FUNCTION_ADD_PARAM1(handle)
8663 DW_FUNCTION_RETURN(dw_notebook_page_get, ULONG) 8663 DW_FUNCTION_RETURN(dw_notebook_page_get, ULONG)
8664 DW_FUNCTION_RESTORE_PARAM1(handle, HWND) 8664 DW_FUNCTION_RESTORE_PARAM1(handle, HWND)
8665 { 8665 {
8666 int phys;
8667 ULONG retval; 8666 ULONG retval;
8668 8667 int phys = gtk_notebook_get_current_page(GTK_NOTEBOOK(handle));
8669 phys = gtk_notebook_get_current_page(GTK_NOTEBOOK(handle)); 8668
8670 retval = _dw_get_logical_page(handle, phys); 8669 retval = _dw_get_logical_page(handle, phys);
8671 DW_FUNCTION_RETURN_THIS(retval); 8670 DW_FUNCTION_RETURN_THIS(retval);
8672 } 8671 }
8673 8672
8674 /* 8673 /*
8680 DW_FUNCTION_DEFINITION(dw_notebook_page_set, void, HWND handle, unsigned int pageid) 8679 DW_FUNCTION_DEFINITION(dw_notebook_page_set, void, HWND handle, unsigned int pageid)
8681 DW_FUNCTION_ADD_PARAM2(handle, pageid) 8680 DW_FUNCTION_ADD_PARAM2(handle, pageid)
8682 DW_FUNCTION_NO_RETURN(dw_notebook_page_set) 8681 DW_FUNCTION_NO_RETURN(dw_notebook_page_set)
8683 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, pageid, unsigned int) 8682 DW_FUNCTION_RESTORE_PARAM2(handle, HWND, pageid, unsigned int)
8684 { 8683 {
8685 int realpage; 8684 int realpage = _dw_get_physical_page(handle, pageid);
8686 8685
8687 realpage = _get_physical_page(handle, pageid);
8688 if(realpage > -1 && realpage < 256) 8686 if(realpage > -1 && realpage < 256)
8689 gtk_notebook_set_current_page(GTK_NOTEBOOK(handle), pageid); 8687 gtk_notebook_set_current_page(GTK_NOTEBOOK(handle), pageid);
8690 DW_FUNCTION_RETURN_NOTHING; 8688 DW_FUNCTION_RETURN_NOTHING;
8691 } 8689 }
8692 8690
8702 DW_FUNCTION_ADD_PARAM3(handle, pageid, text) 8700 DW_FUNCTION_ADD_PARAM3(handle, pageid, text)
8703 DW_FUNCTION_NO_RETURN(dw_notebook_page_set_text) 8701 DW_FUNCTION_NO_RETURN(dw_notebook_page_set_text)
8704 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, pageid, ULONG, text, const char *) 8702 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, pageid, ULONG, text, const char *)
8705 { 8703 {
8706 GtkWidget *child; 8704 GtkWidget *child;
8707 int realpage; 8705 int realpage = _dw_get_physical_page(handle, pageid);
8708 8706
8709 realpage = _get_physical_page(handle, pageid);
8710 if(realpage < 0 || realpage > 255) 8707 if(realpage < 0 || realpage > 255)
8711 { 8708 {
8712 char ptext[101] = {0}; 8709 char ptext[101] = {0};
8713 int num; 8710 int num;
8714 8711
10367 } 10364 }
10368 10365
10369 /* Get the actual signal window handle not the user window handle 10366 /* Get the actual signal window handle not the user window handle
10370 * Should mimic the code in dw_signal_connect() below. 10367 * Should mimic the code in dw_signal_connect() below.
10371 */ 10368 */
10372 static HWND _find_signal_window(HWND window, const char *signame) 10369 static HWND _dw_find_signal_window(HWND window, const char *signame)
10373 { 10370 {
10374 HWND thiswindow = window; 10371 HWND thiswindow = window;
10375 10372
10376 if(GTK_IS_SCROLLED_WINDOW(thiswindow)) 10373 if(GTK_IS_SCROLLED_WINDOW(thiswindow))
10377 thiswindow = (HWND)g_object_get_data(G_OBJECT(window), "_dw_user"); 10374 thiswindow = (HWND)g_object_get_data(G_OBJECT(window), "_dw_user");
10633 { 10630 {
10634 int z, count; 10631 int z, count;
10635 SignalList signal; 10632 SignalList signal;
10636 void **params = alloca(sizeof(void *) * 3); 10633 void **params = alloca(sizeof(void *) * 3);
10637 10634
10638 params[2] = _find_signal_window(window, signame); 10635 params[2] = _dw_find_signal_window(window, signame);
10639 count = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(params[2]), "_dw_sigcounter")); 10636 count = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(params[2]), "_dw_sigcounter"));
10640 signal = _dw_findsignal(signame); 10637 signal = _dw_findsignal(signame);
10641 10638
10642 if(signal.func) 10639 if(signal.func)
10643 { 10640 {
10662 void dw_signal_disconnect_by_window(HWND window) 10659 void dw_signal_disconnect_by_window(HWND window)
10663 { 10660 {
10664 HWND thiswindow; 10661 HWND thiswindow;
10665 int z, count; 10662 int z, count;
10666 10663
10667 thiswindow = _find_signal_window(window, NULL); 10664 thiswindow = _dw_find_signal_window(window, NULL);
10668 count = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(thiswindow), "_dw_sigcounter")); 10665 count = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(thiswindow), "_dw_sigcounter"));
10669 10666
10670 for(z=0;z<count;z++) 10667 for(z=0;z<count;z++)
10671 _dw_remove_signal_handler(thiswindow, z); 10668 _dw_remove_signal_handler(thiswindow, z);
10672 g_object_set_data(G_OBJECT(thiswindow), "_dw_sigcounter", NULL); 10669 g_object_set_data(G_OBJECT(thiswindow), "_dw_sigcounter", NULL);
10681 void dw_signal_disconnect_by_data(HWND window, void *data) 10678 void dw_signal_disconnect_by_data(HWND window, void *data)
10682 { 10679 {
10683 int z, count; 10680 int z, count;
10684 void **params = alloca(sizeof(void *) * 3); 10681 void **params = alloca(sizeof(void *) * 3);
10685 10682
10686 params[2] = _find_signal_window(window, NULL); 10683 params[2] = _dw_find_signal_window(window, NULL);
10687 count = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(params[2]), "_dw_sigcounter")); 10684 count = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(params[2]), "_dw_sigcounter"));
10688 10685
10689 for(z=0;z<count;z++) 10686 for(z=0;z<count;z++)
10690 { 10687 {
10691 SignalHandler sh; 10688 SignalHandler sh;