comparison gtk4/dw.c @ 2266:bb0690c04413

GTK4: First buildable version... although tons still left to do. No thread safety at all, only single threaded apps... no menus. Signal handlers are a complete mess.... but progress.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 30 Jan 2021 01:53:20 +0000
parents 63bb97e94cd3
children 7ac85e938b71
comparison
equal deleted inserted replaced
2265:63bb97e94cd3 2266:bb0690c04413
1284 GtkButtonsType gtkbuttons = GTK_BUTTONS_OK; 1284 GtkButtonsType gtkbuttons = GTK_BUTTONS_OK;
1285 GtkWidget *dialog; 1285 GtkWidget *dialog;
1286 int response; 1286 int response;
1287 va_list args; 1287 va_list args;
1288 char outbuf[1025] = {0}; 1288 char outbuf[1025] = {0};
1289 DWDialog *tmp = dw_dialog_new(NULL);
1289 1290
1290 va_start(args, format); 1291 va_start(args, format);
1291 vsnprintf(outbuf, 1024, format, args); 1292 vsnprintf(outbuf, 1024, format, args);
1292 va_end(args); 1293 va_end(args);
1293 1294
1309 GTK_DIALOG_USE_HEADER_BAR | 1310 GTK_DIALOG_USE_HEADER_BAR |
1310 GTK_DIALOG_MODAL, gtkicon, gtkbuttons, "%s", title); 1311 GTK_DIALOG_MODAL, gtkicon, gtkbuttons, "%s", title);
1311 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", outbuf); 1312 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", outbuf);
1312 if(flags & DW_MB_YESNOCANCEL) 1313 if(flags & DW_MB_YESNOCANCEL)
1313 gtk_dialog_add_button(GTK_DIALOG(dialog), "Cancel", GTK_RESPONSE_CANCEL); 1314 gtk_dialog_add_button(GTK_DIALOG(dialog), "Cancel", GTK_RESPONSE_CANCEL);
1314 response = gtk_dialog_run(GTK_DIALOG(dialog)); 1315 gtk_widget_show(GTK_WIDGET(dialog));
1316 /* TODO: Implement signal handlers so this will return */
1317 response = DW_POINTER_TO_INT(dw_dialog_wait(tmp));
1315 if(GTK_IS_WINDOW(dialog)) 1318 if(GTK_IS_WINDOW(dialog))
1316 gtk_window_destroy(GTK_WINDOW(dialog)); 1319 gtk_window_destroy(GTK_WINDOW(dialog));
1317 switch(response) 1320 switch(response)
1318 { 1321 {
1319 case GTK_RESPONSE_OK: 1322 case GTK_RESPONSE_OK:
1663 { 1666 {
1664 GtkFontChooser *fd; 1667 GtkFontChooser *fd;
1665 char *font = currfont ? strdup(currfont) : NULL; 1668 char *font = currfont ? strdup(currfont) : NULL;
1666 char *name = font ? strchr(font, '.') : NULL; 1669 char *name = font ? strchr(font, '.') : NULL;
1667 char *retfont = NULL; 1670 char *retfont = NULL;
1671 DWDialog *tmp = dw_dialog_new(NULL);
1668 1672
1669 /* Detect Dynamic Windows style font name... 1673 /* Detect Dynamic Windows style font name...
1670 * Format: ##.Fontname 1674 * Format: ##.Fontname
1671 * and convert to a Pango name 1675 * and convert to a Pango name
1672 */ 1676 */
1685 free(font); 1689 free(font);
1686 } 1690 }
1687 1691
1688 gtk_widget_show(GTK_WIDGET(fd)); 1692 gtk_widget_show(GTK_WIDGET(fd));
1689 1693
1690 if(gtk_dialog_run(GTK_DIALOG(fd)) == GTK_RESPONSE_OK) 1694 /* TODO: Connect signal handlers so this actually returns */
1695 if(DW_POINTER_TO_INT(dw_dialog_wait(tmp)) == GTK_RESPONSE_OK)
1691 { 1696 {
1692 char *fontname = gtk_font_chooser_get_font(fd); 1697 char *fontname = gtk_font_chooser_get_font(fd);
1693 if(fontname && (retfont = strdup(fontname))) 1698 if(fontname && (retfont = strdup(fontname)))
1694 { 1699 {
1695 int len = strlen(fontname); 1700 int len = strlen(fontname);
1714 } 1719 }
1715 } 1720 }
1716 g_free(fontname); 1721 g_free(fontname);
1717 } 1722 }
1718 } 1723 }
1719 g_object_unref(G_OBJECT(fd)); 1724 if(GTK_IS_WINDOW(fd))
1725 gtk_window_destroy(GTK_WINDOW(fd));
1720 return retfont; 1726 return retfont;
1721 } 1727 }
1722 1728
1723 /* 1729 /*
1724 * Gets the font used by a specified window (widget) handle. 1730 * Gets the font used by a specified window (widget) handle.
2151 * id: An ID to be used for getting the resource from the 2157 * id: An ID to be used for getting the resource from the
2152 * resource file. 2158 * resource file.
2153 */ 2159 */
2154 HMENUI dw_menu_new(unsigned long id) 2160 HMENUI dw_menu_new(unsigned long id)
2155 { 2161 {
2156 HMENUI tmp; 2162 HMENUI tmp = NULL;
2157 2163
2164 #if 0 /* TODO: Implement this with GMenuModel and GtkPopoverMenu */
2158 tmp = gtk_menu_new(); 2165 tmp = gtk_menu_new();
2159 gtk_widget_show(tmp); 2166 gtk_widget_show(tmp);
2160 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 2167 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
2168 #endif
2161 return tmp; 2169 return tmp;
2162 } 2170 }
2163 2171
2164 /* 2172 /*
2165 * Create a menubar on a window. 2173 * Create a menubar on a window.
2168 * If there is no box already packed into the "location", the menu will not appear 2176 * If there is no box already packed into the "location", the menu will not appear
2169 * so tell the user. 2177 * so tell the user.
2170 */ 2178 */
2171 HMENUI dw_menubar_new(HWND location) 2179 HMENUI dw_menubar_new(HWND location)
2172 { 2180 {
2181 HMENUI tmp = 0;
2182 #if 0 /* TODO: Implement this with GMenuModel and GtkPopoverMenu */
2173 GtkWidget *box; 2183 GtkWidget *box;
2174 HMENUI tmp = 0;
2175 2184
2176 if(GTK_IS_WINDOW(location) && 2185 if(GTK_IS_WINDOW(location) &&
2177 (box = (GtkWidget *)g_object_get_data(G_OBJECT(location), "_dw_grid"))) 2186 (box = (GtkWidget *)g_object_get_data(G_OBJECT(location), "_dw_grid")))
2178 { 2187 {
2179 /* If there is an existing menu bar, remove it */ 2188 /* If there is an existing menu bar, remove it */
2186 /* Save pointers to each other */ 2195 /* Save pointers to each other */
2187 g_object_set_data(G_OBJECT(location), "_dw_menubar", (gpointer)tmp); 2196 g_object_set_data(G_OBJECT(location), "_dw_menubar", (gpointer)tmp);
2188 g_object_set_data(G_OBJECT(tmp), "_dw_window", (gpointer)location); 2197 g_object_set_data(G_OBJECT(tmp), "_dw_window", (gpointer)location);
2189 gtk_grid_attach(GTK_GRID(box), tmp, 0, 0, 1, 1); 2198 gtk_grid_attach(GTK_GRID(box), tmp, 0, 0, 1, 1);
2190 } 2199 }
2200 #endif
2191 return tmp; 2201 return tmp;
2192 } 2202 }
2193 2203
2194 /* 2204 /*
2195 * Destroys a menu created with dw_menubar_new or dw_menu_new. 2205 * Destroys a menu created with dw_menubar_new or dw_menu_new.
2196 * Parameters: 2206 * Parameters:
2197 * menu: Handle of a menu. 2207 * menu: Handle of a menu.
2198 */ 2208 */
2199 void dw_menu_destroy(HMENUI *menu) 2209 void dw_menu_destroy(HMENUI *menu)
2200 { 2210 {
2211 #if 0 /* TODO: Implement this with GMenuModel and GtkPopoverMenu */
2201 if(menu && *menu) 2212 if(menu && *menu)
2202 { 2213 {
2203 GtkWidget *window; 2214 GtkWidget *window;
2204 2215
2205 /* If it is a menu bar, try to delete the reference to it */ 2216 /* If it is a menu bar, try to delete the reference to it */
2209 /* Actually destroy the menu */ 2220 /* Actually destroy the menu */
2210 if(GTK_IS_WIDGET(*menu)) 2221 if(GTK_IS_WIDGET(*menu))
2211 g_object_unref(G_OBJECT(*menu)); 2222 g_object_unref(G_OBJECT(*menu));
2212 *menu = NULL; 2223 *menu = NULL;
2213 } 2224 }
2214 } 2225 #endif
2215
2216 char _removetilde(char *dest, const char *src)
2217 {
2218 int z, cur=0;
2219 char accel = '\0';
2220
2221 for(z=0;z<strlen(src);z++)
2222 {
2223 if(src[z] != '~')
2224 {
2225 dest[cur] = src[z];
2226 cur++;
2227 }
2228 else
2229 {
2230 dest[cur] = '_';
2231 accel = src[z+1];
2232 cur++;
2233 }
2234 }
2235 dest[cur] = 0;
2236 return accel;
2237 } 2226 }
2238 2227
2239 /* 2228 /*
2240 * Adds a menuitem or submenu to an existing menu. 2229 * Adds a menuitem or submenu to an existing menu.
2241 * Parameters: 2230 * Parameters:
2247 * check: If TRUE menu is "check"able. 2236 * check: If TRUE menu is "check"able.
2248 * submenu: Handle to an existing menu to be a submenu or NULL. 2237 * submenu: Handle to an existing menu to be a submenu or NULL.
2249 */ 2238 */
2250 HWND dw_menu_append_item(HMENUI menu, const char *title, unsigned long id, unsigned long flags, int end, int check, HMENUI submenu) 2239 HWND dw_menu_append_item(HMENUI menu, const char *title, unsigned long id, unsigned long flags, int end, int check, HMENUI submenu)
2251 { 2240 {
2252 GtkWidget *tmphandle; 2241 GtkWidget *tmphandle = NULL;
2242 #if 0 /* TODO: Implement this with GMenuModel and GtkPopoverMenu */
2253 char accel, *tempbuf = malloc(strlen(title)+1); 2243 char accel, *tempbuf = malloc(strlen(title)+1);
2254 int submenucount; 2244 int submenucount;
2255 GtkAccelGroup *accel_group;
2256 2245
2257 if (!menu) 2246 if (!menu)
2258 { 2247 {
2259 free(tempbuf); 2248 free(tempbuf);
2260 return NULL; 2249 return NULL;
2261 } 2250 }
2262 2251
2263 accel = _removetilde(tempbuf, title); 2252 accel = _removetilde(tempbuf, title);
2264 2253
2265 accel_group = (GtkAccelGroup *)g_object_get_data(G_OBJECT(menu), "_dw_accel");
2266 submenucount = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menu), "_dw_submenucount")); 2254 submenucount = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menu), "_dw_submenucount"));
2267 2255
2268 if (strlen(tempbuf) == 0) 2256 if (strlen(tempbuf) == 0)
2269 tmphandle=gtk_menu_item_new(); 2257 tmphandle=gtk_menu_item_new();
2270 else 2258 else
2272 char numbuf[25] = {0}; 2260 char numbuf[25] = {0};
2273 2261
2274 if (check) 2262 if (check)
2275 { 2263 {
2276 tmphandle = gtk_check_menu_item_new_with_label(tempbuf); 2264 tmphandle = gtk_check_menu_item_new_with_label(tempbuf);
2277 if (accel && accel_group) 2265 if (accel)
2266 gtk_label_set_use_underline(GTK_LABEL(gtk_bin_get_child(GTK_BIN(tmphandle))), TRUE);
2267 snprintf(numbuf, 24, "%lu", id);
2268 g_object_set_data(G_OBJECT(menu), numbuf, (gpointer)tmphandle);
2269 }
2270 else
2271 {
2272 tmphandle=gtk_menu_item_new_with_label(tempbuf);
2273 if (accel)
2278 { 2274 {
2279 gtk_label_set_use_underline(GTK_LABEL(gtk_bin_get_child(GTK_BIN(tmphandle))), TRUE); 2275 gtk_label_set_use_underline(GTK_LABEL(gtk_bin_get_child(GTK_BIN(tmphandle))), TRUE);
2280 #if 0 /* TODO: This isn't working right */
2281 gtk_widget_add_accelerator(tmphandle, "activate", accel_group, tmp_key, GDK_MOD1_MASK, 0);
2282 #endif
2283 }
2284 snprintf(numbuf, 24, "%lu", id);
2285 g_object_set_data(G_OBJECT(menu), numbuf, (gpointer)tmphandle);
2286 }
2287 else
2288 {
2289 tmphandle=gtk_menu_item_new_with_label(tempbuf);
2290 if (accel && accel_group)
2291 {
2292 gtk_label_set_use_underline(GTK_LABEL(gtk_bin_get_child(GTK_BIN(tmphandle))), TRUE);
2293 #if 0 /* TODO: This isn't working right */
2294 gtk_widget_add_accelerator(tmphandle, "activate", accel_group, tmp_key, GDK_MOD1_MASK, 0);
2295 #endif
2296 } 2276 }
2297 snprintf(numbuf, 24, "%lu", id); 2277 snprintf(numbuf, 24, "%lu", id);
2298 g_object_set_data(G_OBJECT(menu), numbuf, (gpointer)tmphandle); 2278 g_object_set_data(G_OBJECT(menu), numbuf, (gpointer)tmphandle);
2299 } 2279 }
2300 } 2280 }
2329 _dw_ignore_click = 0; 2309 _dw_ignore_click = 0;
2330 } 2310 }
2331 2311
2332 if ( flags & DW_MIS_DISABLED ) 2312 if ( flags & DW_MIS_DISABLED )
2333 gtk_widget_set_sensitive( tmphandle, FALSE ); 2313 gtk_widget_set_sensitive( tmphandle, FALSE );
2334 2314 #endif
2335 return tmphandle; 2315 return tmphandle;
2336 } 2316 }
2337 2317
2338 GtkWidget *_find_submenu_id(GtkWidget *start, const char *name) 2318 GtkWidget *_find_submenu_id(GtkWidget *start, const char *name)
2339 { 2319 {
2367 * check: TRUE for checked FALSE for not checked. 2347 * check: TRUE for checked FALSE for not checked.
2368 * deprecated: use dw_menu_item_set_state() 2348 * deprecated: use dw_menu_item_set_state()
2369 */ 2349 */
2370 void dw_menu_item_set_check(HMENUI menu, unsigned long id, int check) 2350 void dw_menu_item_set_check(HMENUI menu, unsigned long id, int check)
2371 { 2351 {
2352 #if 0 /* TODO: Implement this with GMenuModel and GtkPopoverMenu */
2372 char numbuf[25] = {0}; 2353 char numbuf[25] = {0};
2373 GtkWidget *tmphandle; 2354 GtkWidget *tmphandle;
2374 2355
2375 if(!menu) 2356 if(!menu)
2376 return; 2357 return;
2383 _dw_ignore_click = 1; 2364 _dw_ignore_click = 1;
2384 if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(tmphandle)) != check) 2365 if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(tmphandle)) != check)
2385 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tmphandle), check); 2366 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(tmphandle), check);
2386 _dw_ignore_click = 0; 2367 _dw_ignore_click = 0;
2387 } 2368 }
2369 #endif
2388 } 2370 }
2389 2371
2390 /* 2372 /*
2391 * Sets the state of a menu item. 2373 * Sets the state of a menu item.
2392 * Parameters: 2374 * Parameters:
2394 * id: Menuitem id. 2376 * id: Menuitem id.
2395 * state: TRUE for checked FALSE for not checked. 2377 * state: TRUE for checked FALSE for not checked.
2396 */ 2378 */
2397 void dw_menu_item_set_state(HMENUI menu, unsigned long id, unsigned long state) 2379 void dw_menu_item_set_state(HMENUI menu, unsigned long id, unsigned long state)
2398 { 2380 {
2381 #if 0 /* TODO: Implement this with GMenuModel and GtkPopoverMenu */
2399 char numbuf[25] = {0}; 2382 char numbuf[25] = {0};
2400 GtkWidget *tmphandle; 2383 GtkWidget *tmphandle;
2401 int check; 2384 int check;
2402 2385
2403 if(!menu) 2386 if(!menu)
2431 else 2414 else
2432 gtk_widget_set_sensitive( tmphandle, FALSE ); 2415 gtk_widget_set_sensitive( tmphandle, FALSE );
2433 _dw_ignore_click = 0; 2416 _dw_ignore_click = 0;
2434 } 2417 }
2435 } 2418 }
2419 #endif
2436 } 2420 }
2437 2421
2438 /* 2422 /*
2439 * Deletes the menu item specified. 2423 * Deletes the menu item specified.
2440 * Parameters: 2424 * Parameters:
2443 * Returns: 2427 * Returns:
2444 * DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure. 2428 * DW_ERROR_NONE (0) on success or DW_ERROR_UNKNOWN on failure.
2445 */ 2429 */
2446 int API dw_menu_delete_item(HMENUI menu, unsigned long id) 2430 int API dw_menu_delete_item(HMENUI menu, unsigned long id)
2447 { 2431 {
2432 int ret = DW_ERROR_UNKNOWN;
2433 #if 0 /* TODO: Implement this with GMenuModel and GtkPopoverMenu */
2448 char numbuf[25] = {0}; 2434 char numbuf[25] = {0};
2449 GtkWidget *tmphandle; 2435 GtkWidget *tmphandle;
2450 int ret = DW_ERROR_UNKNOWN;
2451 2436
2452 if(!menu) 2437 if(!menu)
2453 return ret; 2438 return ret;
2454 2439
2455 snprintf(numbuf, 24, "%lu", id); 2440 snprintf(numbuf, 24, "%lu", id);
2460 if(GTK_IS_WIDGET(tmphandle)) 2445 if(GTK_IS_WIDGET(tmphandle))
2461 g_object_unref(G_OBJECT(tmphandle)); 2446 g_object_unref(G_OBJECT(tmphandle));
2462 g_object_set_data(G_OBJECT(menu), numbuf, NULL); 2447 g_object_set_data(G_OBJECT(menu), numbuf, NULL);
2463 ret = DW_ERROR_NONE; 2448 ret = DW_ERROR_NONE;
2464 } 2449 }
2450 #endif
2465 return ret; 2451 return ret;
2466 } 2452 }
2467 2453
2468 /* 2454 /*
2469 * Pops up a context menu at given x and y coordinates. 2455 * Pops up a context menu at given x and y coordinates.
2476 void dw_menu_popup(HMENUI *menu, HWND parent, int x, int y) 2462 void dw_menu_popup(HMENUI *menu, HWND parent, int x, int y)
2477 { 2463 {
2478 if(!menu || !*menu) 2464 if(!menu || !*menu)
2479 return; 2465 return;
2480 2466
2467 #if 0 /* TODO: Implement this with GMenuModel and GtkPopoverMenu */
2481 popup = parent; 2468 popup = parent;
2482 2469
2483 gtk_menu_popup_at_pointer(GTK_MENU(*menu), NULL); 2470 gtk_menu_popup_at_pointer(GTK_MENU(*menu), NULL);
2471 #endif
2484 *menu = NULL; 2472 *menu = NULL;
2485 } 2473 }
2486 2474
2487 2475
2488 /* 2476 /*
2491 * x: Pointer to variable to store X coordinate. 2479 * x: Pointer to variable to store X coordinate.
2492 * y: Pointer to variable to store Y coordinate. 2480 * y: Pointer to variable to store Y coordinate.
2493 */ 2481 */
2494 void dw_pointer_query_pos(long *x, long *y) 2482 void dw_pointer_query_pos(long *x, long *y)
2495 { 2483 {
2496 GdkModifierType state = 0; 2484 /* TODO: See if this is possible in GTK4 */
2497 int gx, gy;
2498 GdkDisplay *display;
2499 GdkDevice *device;
2500 GdkSeat *seat;
2501
2502 #ifdef GDK_WINDOWING_X11
2503 display = gdk_display_get_default();
2504 seat = gdk_display_get_default_seat(display);
2505 device = gdk_seat_get_pointer(seat);
2506 gdk_window_get_device_position(gdk_x11_window_lookup_for_display(display, GDK_ROOT_WINDOW()),
2507 device, &gx, &gy, &state);
2508 #endif
2509 if(x) 2485 if(x)
2510 *x = gx; 2486 *x = 0;
2511 if(y) 2487 if(y)
2512 *y = gy; 2488 *y = 0;
2513 } 2489 }
2514 2490
2515 /* 2491 /*
2516 * Sets the X and Y coordinates of the mouse pointer. 2492 * Sets the X and Y coordinates of the mouse pointer.
2517 * Parameters: 2493 * Parameters:
2518 * x: X coordinate. 2494 * x: X coordinate.
2519 * y: Y coordinate. 2495 * y: Y coordinate.
2520 */ 2496 */
2521 void dw_pointer_set_pos(long x, long y) 2497 void dw_pointer_set_pos(long x, long y)
2522 { 2498 {
2523 GdkDisplay *display; 2499 /* TODO: See if this is possible in GTK4 */
2524 GdkDevice *device;
2525 GdkSeat *seat;
2526
2527 #ifdef GDK_WINDOWING_X11
2528 display = gdk_display_get_default();
2529 seat = gdk_display_get_default_seat(display);
2530 device = gdk_seat_get_pointer(seat);
2531 gdk_device_warp(device, gdk_screen_get_default(), x, y);
2532 #endif
2533 } 2500 }
2534 2501
2535 #define _DW_TREE_CONTAINER 1 2502 #define _DW_TREE_CONTAINER 1
2536 #define _DW_TREE_TREE 2 2503 #define _DW_TREE_TREE 2
2537 #define _DW_TREE_LISTBOX 3 2504 #define _DW_TREE_LISTBOX 3
2538 2505
2539 GtkWidget *_tree_create(unsigned long id) 2506 GtkWidget *_tree_create(unsigned long id)
2540 { 2507 {
2541 GtkWidget *tmp; 2508 GtkWidget *tmp;
2542 2509
2543 tmp = gtk_scrolled_window_new(NULL, NULL); 2510 tmp = gtk_scrolled_window_new();
2544 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (tmp), 2511 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (tmp),
2545 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); 2512 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2546 2513
2547 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 2514 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
2548 gtk_widget_show(tmp); 2515 gtk_widget_show(tmp);
2551 2518
2552 GtkWidget *_tree_setup(GtkWidget *tmp, GtkTreeModel *store) 2519 GtkWidget *_tree_setup(GtkWidget *tmp, GtkTreeModel *store)
2553 { 2520 {
2554 GtkWidget *tree = gtk_tree_view_new_with_model(store); 2521 GtkWidget *tree = gtk_tree_view_new_with_model(store);
2555 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tree), FALSE); 2522 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tree), FALSE);
2556 #if GTK_CHECK_VERSION(3,8,0) 2523 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(tmp), tree);
2557 gtk_container_add(GTK_CONTAINER(tmp), tree);
2558 #else
2559 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(tmp), tree);
2560 #endif
2561 g_object_set_data(G_OBJECT(tmp), "_dw_user", (gpointer)tree); 2524 g_object_set_data(G_OBJECT(tmp), "_dw_user", (gpointer)tree);
2562 return tree; 2525 return tree;
2563 } 2526 }
2564 2527
2565 /* 2528 /*
2653 HWND dw_status_text_new(const char *text, ULONG id) 2616 HWND dw_status_text_new(const char *text, ULONG id)
2654 { 2617 {
2655 GtkWidget *tmp, *frame; 2618 GtkWidget *tmp, *frame;
2656 2619
2657 frame = gtk_frame_new(NULL); 2620 frame = gtk_frame_new(NULL);
2658 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
2659 tmp = gtk_label_new(text); 2621 tmp = gtk_label_new(text);
2660 gtk_container_add(GTK_CONTAINER(frame), tmp); 2622 gtk_frame_set_child(GTK_FRAME(frame), tmp);
2661 gtk_widget_show(tmp); 2623 gtk_widget_show(tmp);
2662 gtk_widget_show(frame); 2624 gtk_widget_show(frame);
2663 2625
2664 /* Left and centered */ 2626 /* Left and centered */
2665 gtk_label_set_xalign(GTK_LABEL(tmp), 0.0f); 2627 gtk_label_set_xalign(GTK_LABEL(tmp), 0.0f);
2678 */ 2640 */
2679 HWND dw_mle_new(unsigned long id) 2641 HWND dw_mle_new(unsigned long id)
2680 { 2642 {
2681 GtkWidget *tmp, *tmpbox; 2643 GtkWidget *tmp, *tmpbox;
2682 2644
2683 tmpbox = gtk_scrolled_window_new (NULL, NULL); 2645 tmpbox = gtk_scrolled_window_new();
2684 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(tmpbox), 2646 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(tmpbox),
2685 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); 2647 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
2686 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(tmpbox), GTK_SHADOW_ETCHED_IN);
2687 tmp = gtk_text_view_new(); 2648 tmp = gtk_text_view_new();
2688 gtk_container_add (GTK_CONTAINER(tmpbox), tmp); 2649 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(tmpbox), tmp);
2689 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(tmp), GTK_WRAP_WORD); 2650 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(tmp), GTK_WRAP_WORD);
2690 2651
2691 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 2652 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
2692 g_object_set_data(G_OBJECT(tmpbox), "_dw_user", (gpointer)tmp); 2653 g_object_set_data(G_OBJECT(tmpbox), "_dw_user", (gpointer)tmp);
2693 gtk_widget_show(tmp); 2654 gtk_widget_show(tmp);
2704 * id: An ID to be used with dw_window_from_id() or 0L. 2665 * id: An ID to be used with dw_window_from_id() or 0L.
2705 */ 2666 */
2706 HWND dw_entryfield_new(const char *text, unsigned long id) 2667 HWND dw_entryfield_new(const char *text, unsigned long id)
2707 { 2668 {
2708 GtkWidget *tmp; 2669 GtkWidget *tmp;
2709 2670 GtkEntryBuffer *buffer = gtk_entry_buffer_new(text, -1);
2710 tmp = gtk_entry_new(); 2671
2711 2672 tmp = gtk_entry_new_with_buffer(buffer);
2712 gtk_entry_set_text(GTK_ENTRY(tmp), text);
2713 gtk_entry_set_width_chars(GTK_ENTRY(tmp), 0);
2714 2673
2715 gtk_widget_show(tmp); 2674 gtk_widget_show(tmp);
2716 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 2675 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
2717 2676
2718 if(_DWDefaultFont) 2677 if(_DWDefaultFont)
2727 * id: An ID to be used with dw_window_from_id() or 0L. 2686 * id: An ID to be used with dw_window_from_id() or 0L.
2728 */ 2687 */
2729 HWND dw_entryfield_password_new(const char *text, ULONG id) 2688 HWND dw_entryfield_password_new(const char *text, ULONG id)
2730 { 2689 {
2731 GtkWidget *tmp; 2690 GtkWidget *tmp;
2732 2691 GtkEntryBuffer *buffer = gtk_entry_buffer_new(text, -1);
2733 tmp = gtk_entry_new(); 2692
2693 tmp = gtk_entry_new_with_buffer(buffer);
2734 2694
2735 gtk_entry_set_visibility(GTK_ENTRY(tmp), FALSE); 2695 gtk_entry_set_visibility(GTK_ENTRY(tmp), FALSE);
2736 gtk_entry_set_text(GTK_ENTRY(tmp), text);
2737 gtk_entry_set_width_chars(GTK_ENTRY(tmp), 0);
2738 2696
2739 gtk_widget_show(tmp); 2697 gtk_widget_show(tmp);
2740 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 2698 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
2741 2699
2742 if(_DWDefaultFont) 2700 if(_DWDefaultFont)
2751 * id: An ID to be used with dw_window_from_id() or 0L. 2709 * id: An ID to be used with dw_window_from_id() or 0L.
2752 */ 2710 */
2753 HWND dw_combobox_new(const char *text, unsigned long id) 2711 HWND dw_combobox_new(const char *text, unsigned long id)
2754 { 2712 {
2755 GtkWidget *tmp; 2713 GtkWidget *tmp;
2714 GtkEntryBuffer *buffer;
2756 GtkListStore *store; 2715 GtkListStore *store;
2757 2716
2758 store = gtk_list_store_new(1, G_TYPE_STRING); 2717 store = gtk_list_store_new(1, G_TYPE_STRING);
2759 tmp = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(store)); 2718 tmp = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(store));
2760 gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(tmp), 0); 2719 gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(tmp), 0);
2761 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(tmp))), text); 2720 buffer = gtk_entry_get_buffer(GTK_ENTRY(gtk_combo_box_get_child(GTK_COMBO_BOX(tmp))));
2762 gtk_entry_set_width_chars(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(tmp))), 0); 2721 gtk_entry_buffer_set_max_length(buffer, 0);
2722 gtk_entry_buffer_set_text(buffer, text, -1);
2763 gtk_widget_show(tmp); 2723 gtk_widget_show(tmp);
2764 g_object_set_data(G_OBJECT(tmp), "_dw_tree_type", GINT_TO_POINTER(_DW_TREE_TYPE_COMBOBOX)); 2724 g_object_set_data(G_OBJECT(tmp), "_dw_tree_type", GINT_TO_POINTER(_DW_TREE_TYPE_COMBOBOX));
2765 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 2725 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
2766 if(_DWDefaultFont) 2726 if(_DWDefaultFont)
2767 dw_window_set_font(tmp, _DWDefaultFont); 2727 dw_window_set_font(tmp, _DWDefaultFont);
2801 bitmap = dw_bitmap_new(id); 2761 bitmap = dw_bitmap_new(id);
2802 2762
2803 if(bitmap) 2763 if(bitmap)
2804 { 2764 {
2805 dw_window_set_bitmap(bitmap, id, NULL); 2765 dw_window_set_bitmap(bitmap, id, NULL);
2806 gtk_container_add (GTK_CONTAINER(tmp), bitmap); 2766 gtk_button_set_child(GTK_BUTTON(tmp), bitmap);
2807 g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap); 2767 g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap);
2808 } 2768 }
2809 gtk_widget_show(tmp); 2769 gtk_widget_show(tmp);
2810 if(text) 2770 if(text)
2811 {
2812 gtk_widget_set_tooltip_text(tmp, text); 2771 gtk_widget_set_tooltip_text(tmp, text);
2813 }
2814 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 2772 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
2815 return tmp; 2773 return tmp;
2816 } 2774 }
2817 2775
2818 /* 2776 /*
2834 tmp = gtk_button_new(); 2792 tmp = gtk_button_new();
2835 /* Now on to the image stuff */ 2793 /* Now on to the image stuff */
2836 bitmap = dw_bitmap_new(id); 2794 bitmap = dw_bitmap_new(id);
2837 if(bitmap) 2795 if(bitmap)
2838 { 2796 {
2839 dw_window_set_bitmap( bitmap, 0, filename ); 2797 dw_window_set_bitmap(bitmap, 0, filename);
2840 gtk_container_add (GTK_CONTAINER(tmp), bitmap); 2798 gtk_button_set_child(GTK_BUTTON(tmp), bitmap);
2841 g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap); 2799 g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap);
2842 } 2800 }
2843 gtk_widget_show(tmp); 2801 gtk_widget_show(tmp);
2844 if(text) 2802 if(text)
2845 {
2846 gtk_widget_set_tooltip_text(tmp, text); 2803 gtk_widget_set_tooltip_text(tmp, text);
2847 }
2848 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 2804 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
2849 return tmp; 2805 return tmp;
2850 } 2806 }
2851 2807
2852 /* 2808 /*
2867 bitmap = dw_bitmap_new(id); 2823 bitmap = dw_bitmap_new(id);
2868 2824
2869 if(bitmap) 2825 if(bitmap)
2870 { 2826 {
2871 dw_window_set_bitmap_from_data(bitmap, 0, data, len); 2827 dw_window_set_bitmap_from_data(bitmap, 0, data, len);
2872 gtk_container_add (GTK_CONTAINER(tmp), bitmap); 2828 gtk_button_set_child(GTK_BUTTON(tmp), bitmap);
2873 g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap); 2829 g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap);
2874 } 2830 }
2875 gtk_widget_show(tmp); 2831 gtk_widget_show(tmp);
2876 if(text) 2832 if(text)
2877 {
2878 gtk_widget_set_tooltip_text(tmp, text); 2833 gtk_widget_set_tooltip_text(tmp, text);
2879 }
2880 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 2834 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
2881 return tmp; 2835 return tmp;
2882 } 2836 }
2883 2837
2884 /* 2838 /*
2890 HWND dw_spinbutton_new(const char *text, unsigned long id) 2844 HWND dw_spinbutton_new(const char *text, unsigned long id)
2891 { 2845 {
2892 GtkAdjustment *adj; 2846 GtkAdjustment *adj;
2893 GtkWidget *tmp; 2847 GtkWidget *tmp;
2894 2848
2895 adj = (GtkAdjustment *)gtk_adjustment_new ((float)atoi(text), -65536.0, 65536.0, 1.0, 5.0, 0.0); 2849 adj = (GtkAdjustment *)gtk_adjustment_new((float)atoi(text), -65536.0, 65536.0, 1.0, 5.0, 0.0);
2896 tmp = gtk_spin_button_new (adj, 0, 0); 2850 tmp = gtk_spin_button_new(adj, 0, 0);
2897 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(tmp), TRUE); 2851 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(tmp), TRUE);
2898 gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(tmp), TRUE); 2852 gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(tmp), TRUE);
2899 gtk_widget_show(tmp); 2853 gtk_widget_show(tmp);
2900 g_object_set_data(G_OBJECT(tmp), "_dw_adjustment", (gpointer)adj); 2854 g_object_set_data(G_OBJECT(tmp), "_dw_adjustment", (gpointer)adj);
2901 g_object_set_data(G_OBJECT(adj), "_dw_spinbutton", (gpointer)tmp); 2855 g_object_set_data(G_OBJECT(adj), "_dw_spinbutton", (gpointer)tmp);
2911 * text: The text to be display by the static text widget. 2865 * text: The text to be display by the static text widget.
2912 * id: An ID to be used with dw_window_from_id() or 0L. 2866 * id: An ID to be used with dw_window_from_id() or 0L.
2913 */ 2867 */
2914 HWND dw_radiobutton_new(const char *text, ULONG id) 2868 HWND dw_radiobutton_new(const char *text, ULONG id)
2915 { 2869 {
2916 /* This will have to be fixed in the future. */ 2870 GtkWidget *tmp = gtk_toggle_button_new_with_label(text);
2917 GtkWidget *tmp;
2918
2919 tmp = gtk_radio_button_new_with_label(NULL, text);
2920 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 2871 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
2921 gtk_widget_show(tmp); 2872 gtk_widget_show(tmp);
2922 2873
2923 if(_DWDefaultFont) 2874 if(_DWDefaultFont)
2924 dw_window_set_font(tmp, _DWDefaultFont); 2875 dw_window_set_font(tmp, _DWDefaultFont);
3054 * handle: Handle to the window. 3005 * handle: Handle to the window.
3055 * id: An ID to be used to specify the icon. 3006 * id: An ID to be used to specify the icon.
3056 */ 3007 */
3057 void dw_window_set_icon(HWND handle, HICN icon) 3008 void dw_window_set_icon(HWND handle, HICN icon)
3058 { 3009 {
3010 /* TODO: figure out how to do this for GTK4 */
3011 #if GTK3
3059 GdkPixbuf *icon_pixbuf; 3012 GdkPixbuf *icon_pixbuf;
3060 3013
3061 icon_pixbuf = _find_pixbuf(icon, NULL, NULL); 3014 icon_pixbuf = _find_pixbuf(icon, NULL, NULL);
3062 3015
3063 if(gtk_widget_get_window(handle) && icon_pixbuf) 3016 if(icon_pixbuf)
3064 { 3017 {
3065 GList *list = g_list_append(NULL, icon_pixbuf); 3018 gtk_window_set_icon_name(
3066 gdk_window_set_icon_list(gtk_widget_get_window(handle), list); 3019 }
3067 g_list_free(list); 3020 #endif
3068 }
3069 } 3021 }
3070 3022
3071 /* 3023 /*
3072 * Sets the bitmap used for a given static window. 3024 * Sets the bitmap used for a given static window.
3073 * Parameters: 3025 * Parameters:
3198 * handle: Handle to the window. 3150 * handle: Handle to the window.
3199 * text: The text associated with a given window. 3151 * text: The text associated with a given window.
3200 */ 3152 */
3201 void dw_window_set_text(HWND handle, const char *text) 3153 void dw_window_set_text(HWND handle, const char *text)
3202 { 3154 {
3203 GtkWidget *tmp;
3204
3205 if((tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_mdi_title")))
3206 handle = tmp;
3207 if(GTK_IS_ENTRY(handle)) 3155 if(GTK_IS_ENTRY(handle))
3208 gtk_entry_set_text(GTK_ENTRY(handle), text); 3156 {
3157 GtkEntryBuffer *buffer = gtk_entry_get_buffer(GTK_ENTRY(handle));
3158 if(buffer)
3159 gtk_entry_buffer_set_text(buffer, text, -1);
3160 }
3209 else if(GTK_IS_COMBO_BOX(handle)) 3161 else if(GTK_IS_COMBO_BOX(handle))
3210 gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(handle))), text); 3162 {
3163 GtkWidget *entry = gtk_combo_box_get_child(GTK_COMBO_BOX(handle));
3164 GtkEntryBuffer *buffer = gtk_entry_get_buffer(GTK_ENTRY(entry));
3165 if(buffer)
3166 gtk_entry_buffer_set_text(buffer, text, -1);
3167 }
3211 else if(GTK_IS_LABEL(handle)) 3168 else if(GTK_IS_LABEL(handle))
3212 gtk_label_set_text(GTK_LABEL(handle), text); 3169 gtk_label_set_text(GTK_LABEL(handle), text);
3213 else if(GTK_IS_BUTTON(handle)) 3170 else if(GTK_IS_BUTTON(handle))
3214 {
3215 gtk_button_set_label(GTK_BUTTON(handle), text); 3171 gtk_button_set_label(GTK_BUTTON(handle), text);
3216 } 3172 else if(GTK_IS_WINDOW(handle))
3217 else if(gtk_widget_is_toplevel(handle))
3218 gtk_window_set_title(GTK_WINDOW(handle), text); 3173 gtk_window_set_title(GTK_WINDOW(handle), text);
3219 else if (GTK_IS_FRAME(handle)) 3174 else if (GTK_IS_FRAME(handle))
3220 { 3175 {
3221 /* 3176 /*
3222 * This is a groupbox or status_text 3177 * This is a groupbox or status_text
3223 */ 3178 */
3224 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_label"); 3179 GtkWidget *tmp = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_label");
3225 if ( tmp && GTK_IS_LABEL(tmp) ) 3180 if (tmp && GTK_IS_LABEL(tmp))
3226 gtk_label_set_text(GTK_LABEL(tmp), text); 3181 gtk_label_set_text(GTK_LABEL(tmp), text);
3227 else /* assume groupbox */ 3182 else /* assume groupbox */
3228 gtk_frame_set_label(GTK_FRAME(handle), text && *text ? text : NULL); 3183 gtk_frame_set_label(GTK_FRAME(handle), text && *text ? text : NULL);
3229 } 3184 }
3230 } 3185 }
3253 char *dw_window_get_text(HWND handle) 3208 char *dw_window_get_text(HWND handle)
3254 { 3209 {
3255 const char *possible = NULL; 3210 const char *possible = NULL;
3256 3211
3257 if(GTK_IS_ENTRY(handle)) 3212 if(GTK_IS_ENTRY(handle))
3258 possible = gtk_entry_get_text(GTK_ENTRY(handle)); 3213 {
3214 GtkEntryBuffer *buffer = gtk_entry_get_buffer(GTK_ENTRY(handle));
3215 possible = gtk_entry_buffer_get_text(buffer);
3216 }
3259 else if(GTK_IS_COMBO_BOX(handle)) 3217 else if(GTK_IS_COMBO_BOX(handle))
3260 possible = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(handle)))); 3218 {
3219 GtkWidget *entry = gtk_combo_box_get_child(GTK_COMBO_BOX(handle));
3220 GtkEntryBuffer *buffer = gtk_entry_get_buffer(GTK_ENTRY(entry));
3221 possible = gtk_entry_buffer_get_text(buffer);
3222 }
3261 else if(GTK_IS_LABEL(handle)) 3223 else if(GTK_IS_LABEL(handle))
3262 possible = gtk_label_get_text(GTK_LABEL(handle)); 3224 possible = gtk_label_get_text(GTK_LABEL(handle));
3263 3225
3264 return strdup(possible ? possible : ""); 3226 return strdup(possible ? possible : "");
3265 } 3227 }
3290 * handle: Handle to the parent window. 3252 * handle: Handle to the parent window.
3291 * id: Integer ID of the child. 3253 * id: Integer ID of the child.
3292 */ 3254 */
3293 HWND API dw_window_from_id(HWND handle, int id) 3255 HWND API dw_window_from_id(HWND handle, int id)
3294 { 3256 {
3257 /* TODO: Figure out how to do this in GTK4 without GtkContainer */
3258 #if GTK3
3295 GList *orig = NULL, *list = NULL; 3259 GList *orig = NULL, *list = NULL;
3296 3260
3297 if(handle && GTK_IS_CONTAINER(handle)) 3261 if(handle && GTK_IS_CONTAINER(handle))
3298 { 3262 {
3299 orig = list = gtk_container_get_children(GTK_CONTAINER(handle)); 3263 orig = list = gtk_container_get_children(GTK_CONTAINER(handle));
3311 } 3275 }
3312 list = list->next; 3276 list = list->next;
3313 } 3277 }
3314 if(orig) 3278 if(orig)
3315 g_list_free(orig); 3279 g_list_free(orig);
3280 #endif
3316 return 0L; 3281 return 0L;
3317 } 3282 }
3318 3283
3319 /* 3284 /*
3320 * Adds text to an MLE box and returns the current point. 3285 * Adds text to an MLE box and returns the current point.
5340 /* Make sure it is the correct tree type */ 5305 /* Make sure it is the correct tree type */
5341 if(cont && GTK_IS_TREE_VIEW(cont) && g_object_get_data(G_OBJECT(cont), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_CONTAINER)) 5306 if(cont && GTK_IS_TREE_VIEW(cont) && g_object_get_data(G_OBJECT(cont), "_dw_tree_type") == GINT_TO_POINTER(_DW_TREE_TYPE_CONTAINER))
5342 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(cont)); 5307 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(cont));
5343 } 5308 }
5344 5309
5345 /* Translate the status message into a message on our buddy window */
5346 static void _status_translate(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data)
5347 {
5348 GdkEventButton event = { 0 };
5349 long x, y;
5350 gboolean retval;
5351
5352 dw_pointer_query_pos(&x, &y);
5353
5354 event.button = button;
5355 event.x = x;
5356 event.y = y;
5357
5358 g_signal_emit_by_name(G_OBJECT(user_data), "button_press_event", &event, &retval);
5359 }
5360
5361 /* 5310 /*
5362 * Inserts an icon into the taskbar. 5311 * Inserts an icon into the taskbar.
5363 * Parameters: 5312 * Parameters:
5364 * handle: Window handle that will handle taskbar icon messages. 5313 * handle: Window handle that will handle taskbar icon messages.
5365 * icon: Icon handle to display in the taskbar. 5314 * icon: Icon handle to display in the taskbar.
5366 * bubbletext: Text to show when the mouse is above the icon. 5315 * bubbletext: Text to show when the mouse is above the icon.
5367 */ 5316 */
5368 void dw_taskbar_insert(HWND handle, HICN icon, const char *bubbletext) 5317 void dw_taskbar_insert(HWND handle, HICN icon, const char *bubbletext)
5369 { 5318 {
5370 GtkStatusIcon *status; 5319 /* TODO: Removed in GTK4.... no replacement? */
5371 GdkPixbuf *pixbuf;
5372
5373 pixbuf = _find_pixbuf(icon, NULL, NULL);
5374 status = gtk_status_icon_new_from_pixbuf(pixbuf);
5375 if(bubbletext)
5376 gtk_status_icon_set_tooltip_text(status, bubbletext);
5377 g_object_set_data(G_OBJECT(handle), "_dw_taskbar", status);
5378 g_signal_connect(G_OBJECT (status), "popup-menu", G_CALLBACK (_status_translate), handle);
5379 gtk_status_icon_set_visible(status, TRUE);
5380 } 5320 }
5381 5321
5382 /* 5322 /*
5383 * Deletes an icon from the taskbar. 5323 * Deletes an icon from the taskbar.
5384 * Parameters: 5324 * Parameters:
5385 * handle: Window handle that was used with dw_taskbar_insert(). 5325 * handle: Window handle that was used with dw_taskbar_insert().
5386 * icon: Icon handle that was used with dw_taskbar_insert(). 5326 * icon: Icon handle that was used with dw_taskbar_insert().
5387 */ 5327 */
5388 void dw_taskbar_delete(HWND handle, HICN icon) 5328 void dw_taskbar_delete(HWND handle, HICN icon)
5389 { 5329 {
5390 GtkStatusIcon *status; 5330 /* TODO: Removed in GTK4.... no replacement? */
5391
5392 status = g_object_get_data(G_OBJECT(handle), "_dw_taskbar");
5393 g_object_unref(G_OBJECT(status));
5394 } 5331 }
5395 5332
5396 /* 5333 /*
5397 * Creates a rendering context widget (window) to be packed. 5334 * Creates a rendering context widget (window) to be packed.
5398 * Parameters: 5335 * Parameters:
5403 HWND dw_render_new(unsigned long id) 5340 HWND dw_render_new(unsigned long id)
5404 { 5341 {
5405 GtkWidget *tmp; 5342 GtkWidget *tmp;
5406 5343
5407 tmp = gtk_drawing_area_new(); 5344 tmp = gtk_drawing_area_new();
5408 gtk_widget_set_events(tmp, GDK_EXPOSURE_MASK
5409 | GDK_LEAVE_NOTIFY_MASK
5410 | GDK_BUTTON_PRESS_MASK
5411 | GDK_BUTTON_RELEASE_MASK
5412 | GDK_KEY_PRESS_MASK
5413 | GDK_POINTER_MOTION_MASK
5414 | GDK_POINTER_MOTION_HINT_MASK);
5415 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 5345 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
5416 gtk_widget_set_can_focus(tmp, TRUE); 5346 gtk_widget_set_can_focus(tmp, TRUE);
5417 gtk_widget_show(tmp); 5347 gtk_widget_show(tmp);
5418 if(_DWDefaultFont) 5348 if(_DWDefaultFont)
5419 dw_window_set_font(tmp, _DWDefaultFont); 5349 dw_window_set_font(tmp, _DWDefaultFont);
5487 unsigned long API dw_color_choose(unsigned long value) 5417 unsigned long API dw_color_choose(unsigned long value)
5488 { 5418 {
5489 GtkColorChooser *cd; 5419 GtkColorChooser *cd;
5490 GdkRGBA color = _internal_color(value); 5420 GdkRGBA color = _internal_color(value);
5491 unsigned long retcolor = value; 5421 unsigned long retcolor = value;
5422 DWDialog *tmp = dw_dialog_new(NULL);
5492 5423
5493 cd = (GtkColorChooser *)gtk_color_chooser_dialog_new("Choose color", NULL); 5424 cd = (GtkColorChooser *)gtk_color_chooser_dialog_new("Choose color", NULL);
5494 gtk_color_chooser_set_use_alpha(cd, FALSE); 5425 gtk_color_chooser_set_use_alpha(cd, FALSE);
5495 gtk_color_chooser_set_rgba(cd, &color); 5426 gtk_color_chooser_set_rgba(cd, &color);
5496 5427
5497 gtk_widget_show(GTK_WIDGET(cd)); 5428 gtk_widget_show(GTK_WIDGET(cd));
5498 5429
5499 if(gtk_dialog_run(GTK_DIALOG(cd)) == GTK_RESPONSE_OK) 5430 if(DW_POINTER_TO_INT(dw_dialog_wait(tmp)) == GTK_RESPONSE_OK)
5500 { 5431 {
5501 gtk_color_chooser_get_rgba(cd, &color); 5432 gtk_color_chooser_get_rgba(cd, &color);
5502 retcolor = DW_RGB((int)(color.red * 255), (int)(color.green * 255), (int)(color.blue * 255)); 5433 retcolor = DW_RGB((int)(color.red * 255), (int)(color.green * 255), (int)(color.blue * 255));
5503 } 5434 }
5504 if(GTK_IS_WIDGET(cd)) 5435 if(GTK_IS_WINDOW(cd))
5505 g_object_unref(G_OBJECT(cd)); 5436 gtk_window_destroy(GTK_WINDOW(cd));
5506 return retcolor; 5437 return retcolor;
5507 } 5438 }
5508 5439
5509 /* Draw a point on a window (preferably a render window). 5440 /* Draw a point on a window (preferably a render window).
5510 * Parameters: 5441 * Parameters:
5519 GdkDrawingContext *dc = NULL; 5450 GdkDrawingContext *dc = NULL;
5520 cairo_region_t *clip = NULL; 5451 cairo_region_t *clip = NULL;
5521 5452
5522 if(handle) 5453 if(handle)
5523 { 5454 {
5455 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
5456 #if GTK3
5524 GdkWindow *window = gtk_widget_get_window(handle); 5457 GdkWindow *window = gtk_widget_get_window(handle);
5525 /* Safety check for non-existant windows */ 5458 /* Safety check for non-existant windows */
5526 if(!window || !GDK_IS_WINDOW(window)) 5459 if(!window || !GDK_IS_WINDOW(window))
5527 return; 5460 return;
5528 clip = gdk_window_get_clip_region(window); 5461 clip = gdk_window_get_clip_region(window);
5529 dc = gdk_window_begin_draw_frame(window, clip); 5462 dc = gdk_window_begin_draw_frame(window, clip);
5530 cr = gdk_drawing_context_get_cairo_context(dc); 5463 cr = gdk_drawing_context_get_cairo_context(dc);
5464 #endif
5531 } 5465 }
5532 else if(pixmap) 5466 else if(pixmap)
5533 cr = cairo_create(pixmap->image); 5467 cr = cairo_create(pixmap->image);
5534 if(cr) 5468 if(cr)
5535 { 5469 {
5539 cairo_set_line_width(cr, 1); 5473 cairo_set_line_width(cr, 1);
5540 cairo_move_to(cr, x, y); 5474 cairo_move_to(cr, x, y);
5541 cairo_stroke(cr); 5475 cairo_stroke(cr);
5542 if(clip) 5476 if(clip)
5543 cairo_region_destroy(clip); 5477 cairo_region_destroy(clip);
5478 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
5479 #if GTK3
5544 /* If we are using a drawing context... 5480 /* If we are using a drawing context...
5545 * we don't own the cairo context so don't destroy it. 5481 * we don't own the cairo context so don't destroy it.
5546 */ 5482 */
5547 if(dc) 5483 if(dc)
5548 gdk_window_end_draw_frame(gtk_widget_get_window(handle), dc); 5484 gdk_window_end_draw_frame(gtk_widget_get_window(handle), dc);
5549 else 5485 else
5550 cairo_destroy(cr); 5486 #else
5487 if(!dc)
5488 #endif
5489 cairo_destroy(cr);
5551 } 5490 }
5552 } 5491 }
5553 5492
5554 /* Draw a line on a window (preferably a render window). 5493 /* Draw a line on a window (preferably a render window).
5555 * Parameters: 5494 * Parameters:
5566 GdkDrawingContext *dc = NULL; 5505 GdkDrawingContext *dc = NULL;
5567 cairo_region_t *clip = NULL; 5506 cairo_region_t *clip = NULL;
5568 5507
5569 if(handle) 5508 if(handle)
5570 { 5509 {
5510 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
5511 #if GTK3
5512 GdkWindow *window = gtk_widget_get_window(handle);
5513 /* Safety check for non-existant windows */
5514 if(!window || !GDK_IS_WINDOW(window))
5515 return;
5516 clip = gdk_window_get_clip_region(window);
5517 dc = gdk_window_begin_draw_frame(window, clip);
5518 cr = gdk_drawing_context_get_cairo_context(dc);
5519 #endif
5520 }
5521 else if(pixmap)
5522 cr = cairo_create(pixmap->image);
5523 if(cr)
5524 {
5525 GdkRGBA *foreground = pthread_getspecific(_dw_fg_color_key);
5526
5527 gdk_cairo_set_source_rgba(cr, foreground);
5528 cairo_set_line_width(cr, 1);
5529 cairo_move_to(cr, x1, y1);
5530 cairo_line_to(cr, x2, y2);
5531 cairo_stroke(cr);
5532 if(clip)
5533 cairo_region_destroy(clip);
5534 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
5535 #if GTK3
5536 /* If we are using a drawing context...
5537 * we don't own the cairo context so don't destroy it.
5538 */
5539 if(dc)
5540 gdk_window_end_draw_frame(gtk_widget_get_window(handle), dc);
5541 else
5542 #else
5543 if(!dc)
5544 #endif
5545 cairo_destroy(cr);
5546 }
5547 }
5548
5549 /* Draw a closed polygon on a window (preferably a render window).
5550 * Parameters:
5551 * handle: Handle to the window.
5552 * pixmap: Handle to the pixmap. (choose only one of these)
5553 * flags: DW_DRAW_FILL (1) to fill the polygon or DW_DRAW_DEFAULT (0).
5554 * number of points
5555 * x[]: X coordinates.
5556 * y[]: Y coordinates.
5557 */
5558 void dw_draw_polygon(HWND handle, HPIXMAP pixmap, int flags, int npoints, int *x, int *y)
5559 {
5560 cairo_t *cr = NULL;
5561 int z;
5562 GdkDrawingContext *dc = NULL;
5563 cairo_region_t *clip = NULL;
5564
5565 if(handle)
5566 {
5567 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
5568 #if GTK3
5571 GdkWindow *window = gtk_widget_get_window(handle); 5569 GdkWindow *window = gtk_widget_get_window(handle);
5572 /* Safety check for non-existant windows */ 5570 /* Safety check for non-existant windows */
5573 if(!window || !GDK_IS_WINDOW(window)) 5571 if(!window || !GDK_IS_WINDOW(window))
5574 return; 5572 return;
5575 clip = gdk_window_get_clip_region(window); 5573 clip = gdk_window_get_clip_region(window);
5576 dc = gdk_window_begin_draw_frame(window, clip); 5574 dc = gdk_window_begin_draw_frame(window, clip);
5577 cr = gdk_drawing_context_get_cairo_context(dc); 5575 cr = gdk_drawing_context_get_cairo_context(dc);
5576 #endif
5578 } 5577 }
5579 else if(pixmap) 5578 else if(pixmap)
5580 cr = cairo_create(pixmap->image); 5579 cr = cairo_create(pixmap->image);
5581 if(cr) 5580 if(cr)
5582 { 5581 {
5583 GdkRGBA *foreground = pthread_getspecific(_dw_fg_color_key); 5582 GdkRGBA *foreground = pthread_getspecific(_dw_fg_color_key);
5584 5583
5584 if(flags & DW_DRAW_NOAA)
5585 cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
5586
5585 gdk_cairo_set_source_rgba(cr, foreground); 5587 gdk_cairo_set_source_rgba(cr, foreground);
5586 cairo_set_line_width(cr, 1); 5588 cairo_set_line_width(cr, 1);
5587 cairo_move_to(cr, x1, y1); 5589 cairo_move_to(cr, x[0], y[0]);
5588 cairo_line_to(cr, x2, y2); 5590 for(z=1;z<npoints;z++)
5591 {
5592 cairo_line_to(cr, x[z], y[z]);
5593 }
5594 if(flags & DW_DRAW_FILL)
5595 cairo_fill(cr);
5589 cairo_stroke(cr); 5596 cairo_stroke(cr);
5590 if(clip) 5597 if(clip)
5591 cairo_region_destroy(clip); 5598 cairo_region_destroy(clip);
5599 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
5600 #if GTK3
5592 /* If we are using a drawing context... 5601 /* If we are using a drawing context...
5593 * we don't own the cairo context so don't destroy it. 5602 * we don't own the cairo context so don't destroy it.
5594 */ 5603 */
5595 if(dc) 5604 if(dc)
5596 gdk_window_end_draw_frame(gtk_widget_get_window(handle), dc); 5605 gdk_window_end_draw_frame(gtk_widget_get_window(handle), dc);
5597 else 5606 else
5598 cairo_destroy(cr); 5607 #else
5599 } 5608 if(!dc)
5600 } 5609 #endif
5601 5610 cairo_destroy(cr);
5602 /* Draw a closed polygon on a window (preferably a render window). 5611 }
5612 }
5613
5614 /* Draw a rectangle on a window (preferably a render window).
5603 * Parameters: 5615 * Parameters:
5604 * handle: Handle to the window. 5616 * handle: Handle to the window.
5605 * pixmap: Handle to the pixmap. (choose only one of these) 5617 * pixmap: Handle to the pixmap. (choose only one of these)
5606 * flags: DW_DRAW_FILL (1) to fill the polygon or DW_DRAW_DEFAULT (0). 5618 * flags: DW_DRAW_FILL (1) to fill the box or DW_DRAW_DEFAULT (0).
5607 * number of points 5619 * x: X coordinate.
5608 * x[]: X coordinates. 5620 * y: Y coordinate.
5609 * y[]: Y coordinates. 5621 * width: Width of rectangle.
5610 */ 5622 * height: Height of rectangle.
5611 void dw_draw_polygon(HWND handle, HPIXMAP pixmap, int flags, int npoints, int *x, int *y) 5623 */
5624 void dw_draw_rect(HWND handle, HPIXMAP pixmap, int flags, int x, int y, int width, int height)
5612 { 5625 {
5613 cairo_t *cr = NULL; 5626 cairo_t *cr = NULL;
5614 int z;
5615 GdkDrawingContext *dc = NULL; 5627 GdkDrawingContext *dc = NULL;
5616 cairo_region_t *clip = NULL; 5628 cairo_region_t *clip = NULL;
5617 5629
5618 if(handle) 5630 if(handle)
5619 { 5631 {
5632 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
5633 #if GTK3
5620 GdkWindow *window = gtk_widget_get_window(handle); 5634 GdkWindow *window = gtk_widget_get_window(handle);
5621 /* Safety check for non-existant windows */ 5635 /* Safety check for non-existant windows */
5622 if(!window || !GDK_IS_WINDOW(window)) 5636 if(!window || !GDK_IS_WINDOW(window))
5623 return; 5637 return;
5624 clip = gdk_window_get_clip_region(window); 5638 clip = gdk_window_get_clip_region(window);
5625 dc = gdk_window_begin_draw_frame(window, clip); 5639 dc = gdk_window_begin_draw_frame(window, clip);
5626 cr = gdk_drawing_context_get_cairo_context(dc); 5640 cr = gdk_drawing_context_get_cairo_context(dc);
5627 } 5641 #endif
5628 else if(pixmap)
5629 cr = cairo_create(pixmap->image);
5630 if(cr)
5631 {
5632 GdkRGBA *foreground = pthread_getspecific(_dw_fg_color_key);
5633
5634 if(flags & DW_DRAW_NOAA)
5635 cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
5636
5637 gdk_cairo_set_source_rgba(cr, foreground);
5638 cairo_set_line_width(cr, 1);
5639 cairo_move_to(cr, x[0], y[0]);
5640 for(z=1;z<npoints;z++)
5641 {
5642 cairo_line_to(cr, x[z], y[z]);
5643 }
5644 if(flags & DW_DRAW_FILL)
5645 cairo_fill(cr);
5646 cairo_stroke(cr);
5647 if(clip)
5648 cairo_region_destroy(clip);
5649 /* If we are using a drawing context...
5650 * we don't own the cairo context so don't destroy it.
5651 */
5652 if(dc)
5653 gdk_window_end_draw_frame(gtk_widget_get_window(handle), dc);
5654 else
5655 cairo_destroy(cr);
5656 }
5657 }
5658
5659 /* Draw a rectangle on a window (preferably a render window).
5660 * Parameters:
5661 * handle: Handle to the window.
5662 * pixmap: Handle to the pixmap. (choose only one of these)
5663 * flags: DW_DRAW_FILL (1) to fill the box or DW_DRAW_DEFAULT (0).
5664 * x: X coordinate.
5665 * y: Y coordinate.
5666 * width: Width of rectangle.
5667 * height: Height of rectangle.
5668 */
5669 void dw_draw_rect(HWND handle, HPIXMAP pixmap, int flags, int x, int y, int width, int height)
5670 {
5671 cairo_t *cr = NULL;
5672 GdkDrawingContext *dc = NULL;
5673 cairo_region_t *clip = NULL;
5674
5675 if(handle)
5676 {
5677 GdkWindow *window = gtk_widget_get_window(handle);
5678 /* Safety check for non-existant windows */
5679 if(!window || !GDK_IS_WINDOW(window))
5680 return;
5681 clip = gdk_window_get_clip_region(window);
5682 dc = gdk_window_begin_draw_frame(window, clip);
5683 cr = gdk_drawing_context_get_cairo_context(dc);
5684 } 5642 }
5685 else if(pixmap) 5643 else if(pixmap)
5686 cr = cairo_create(pixmap->image); 5644 cr = cairo_create(pixmap->image);
5687 if(cr) 5645 if(cr)
5688 { 5646 {
5700 if(flags & DW_DRAW_FILL) 5658 if(flags & DW_DRAW_FILL)
5701 cairo_fill(cr); 5659 cairo_fill(cr);
5702 cairo_stroke(cr); 5660 cairo_stroke(cr);
5703 if(clip) 5661 if(clip)
5704 cairo_region_destroy(clip); 5662 cairo_region_destroy(clip);
5663 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
5664 #if GTK3
5705 /* If we are using a drawing context... 5665 /* If we are using a drawing context...
5706 * we don't own the cairo context so don't destroy it. 5666 * we don't own the cairo context so don't destroy it.
5707 */ 5667 */
5708 if(dc) 5668 if(dc)
5709 gdk_window_end_draw_frame(gtk_widget_get_window(handle), dc); 5669 gdk_window_end_draw_frame(gtk_widget_get_window(handle), dc);
5710 else 5670 else
5711 cairo_destroy(cr); 5671 #else
5672 if(!dc)
5673 #endif
5674 cairo_destroy(cr);
5712 } 5675 }
5713 } 5676 }
5714 5677
5715 /* Draw an arc on a window (preferably a render window). 5678 /* Draw an arc on a window (preferably a render window).
5716 * Parameters: 5679 * Parameters:
5731 GdkDrawingContext *dc = NULL; 5694 GdkDrawingContext *dc = NULL;
5732 cairo_region_t *clip = NULL; 5695 cairo_region_t *clip = NULL;
5733 5696
5734 if(handle) 5697 if(handle)
5735 { 5698 {
5699 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
5700 #if GTK3
5736 GdkWindow *window = gtk_widget_get_window(handle); 5701 GdkWindow *window = gtk_widget_get_window(handle);
5737 /* Safety check for non-existant windows */ 5702 /* Safety check for non-existant windows */
5738 if(!window || !GDK_IS_WINDOW(window)) 5703 if(!window || !GDK_IS_WINDOW(window))
5739 return; 5704 return;
5740 clip = gdk_window_get_clip_region(window); 5705 clip = gdk_window_get_clip_region(window);
5741 dc = gdk_window_begin_draw_frame(window, clip); 5706 dc = gdk_window_begin_draw_frame(window, clip);
5742 cr = gdk_drawing_context_get_cairo_context(dc); 5707 cr = gdk_drawing_context_get_cairo_context(dc);
5708 #endif
5743 } 5709 }
5744 else if(pixmap) 5710 else if(pixmap)
5745 cr = cairo_create(pixmap->image); 5711 cr = cairo_create(pixmap->image);
5746 if(cr) 5712 if(cr)
5747 { 5713 {
5771 if(flags & DW_DRAW_FILL) 5737 if(flags & DW_DRAW_FILL)
5772 cairo_fill(cr); 5738 cairo_fill(cr);
5773 cairo_stroke(cr); 5739 cairo_stroke(cr);
5774 if(clip) 5740 if(clip)
5775 cairo_region_destroy(clip); 5741 cairo_region_destroy(clip);
5742 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
5743 #if GTK3
5776 /* If we are using a drawing context... 5744 /* If we are using a drawing context...
5777 * we don't own the cairo context so don't destroy it. 5745 * we don't own the cairo context so don't destroy it.
5778 */ 5746 */
5779 if(dc) 5747 if(dc)
5780 gdk_window_end_draw_frame(gtk_widget_get_window(handle), dc); 5748 gdk_window_end_draw_frame(gtk_widget_get_window(handle), dc);
5781 else 5749 else
5782 cairo_destroy(cr); 5750 #else
5751 if(!dc)
5752 #endif
5753 cairo_destroy(cr);
5783 } 5754 }
5784 } 5755 }
5785 5756
5786 /* Draw text on a window (preferably a render window). 5757 /* Draw text on a window (preferably a render window).
5787 * Parameters: 5758 * Parameters:
5802 if(!text) 5773 if(!text)
5803 return; 5774 return;
5804 5775
5805 if(handle) 5776 if(handle)
5806 { 5777 {
5778 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
5779 #if GTK3
5807 GdkWindow *window = gtk_widget_get_window(handle); 5780 GdkWindow *window = gtk_widget_get_window(handle);
5808 /* Safety check for non-existant windows */ 5781 /* Safety check for non-existant windows */
5809 if(!window || !GDK_IS_WINDOW(window)) 5782 if(!window || !GDK_IS_WINDOW(window))
5810 return; 5783 return;
5811 clip = gdk_window_get_clip_region(window); 5784 clip = gdk_window_get_clip_region(window);
5812 dc = gdk_window_begin_draw_frame(window, clip); 5785 dc = gdk_window_begin_draw_frame(window, clip);
5813 cr = gdk_drawing_context_get_cairo_context(dc); 5786 cr = gdk_drawing_context_get_cairo_context(dc);
5814 if((tmpname = (char *)g_object_get_data(G_OBJECT(handle), "_dw_fontname"))) 5787 if((tmpname = (char *)g_object_get_data(G_OBJECT(handle), "_dw_fontname")))
5815 fontname = tmpname; 5788 fontname = tmpname;
5789 #endif
5816 } 5790 }
5817 else if(pixmap) 5791 else if(pixmap)
5818 { 5792 {
5819 if(pixmap->font) 5793 if(pixmap->font)
5820 fontname = pixmap->font; 5794 fontname = pixmap->font;
5866 } 5840 }
5867 pango_font_description_free(font); 5841 pango_font_description_free(font);
5868 } 5842 }
5869 if(clip) 5843 if(clip)
5870 cairo_region_destroy(clip); 5844 cairo_region_destroy(clip);
5845 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
5846 #if GTK3
5871 /* If we are using a drawing context... 5847 /* If we are using a drawing context...
5872 * we don't own the cairo context so don't destroy it. 5848 * we don't own the cairo context so don't destroy it.
5873 */ 5849 */
5874 if(dc) 5850 if(dc)
5875 gdk_window_end_draw_frame(gtk_widget_get_window(handle), dc); 5851 gdk_window_end_draw_frame(gtk_widget_get_window(handle), dc);
5876 else 5852 else
5877 cairo_destroy(cr); 5853 #else
5854 if(!dc)
5855 #endif
5856 cairo_destroy(cr);
5878 } 5857 }
5879 } 5858 }
5880 5859
5881 /* Query the width and height of a text string. 5860 /* Query the width and height of a text string.
5882 * Parameters: 5861 * Parameters:
5913 } 5892 }
5914 5893
5915 font = pango_font_description_from_string(fontname ? fontname : "monospace 10"); 5894 font = pango_font_description_from_string(fontname ? fontname : "monospace 10");
5916 if(font) 5895 if(font)
5917 { 5896 {
5918 PangoContext *context = gdk_pango_context_get(); 5897 PangoContext *context = pango_context_new();
5919 5898
5920 if(context) 5899 if(context)
5921 { 5900 {
5922 PangoLayout *layout = pango_layout_new(context); 5901 PangoLayout *layout = pango_layout_new(context);
5923 5902
5938 } 5917 }
5939 g_object_unref(context); 5918 g_object_unref(context);
5940 } 5919 }
5941 pango_font_description_free(font); 5920 pango_font_description_free(font);
5942 } 5921 }
5943 if ( free_fontname ) 5922 if(free_fontname)
5944 free( fontname ); 5923 free(fontname);
5945 } 5924 }
5946 5925
5947 /* 5926 /*
5948 * Creates a pixmap with given parameters. 5927 * Creates a pixmap with given parameters.
5949 * Parameters: 5928 * Parameters:
6197 if((!dest && (!destp || !destp->image)) || (!src && (!srcp || !srcp->image))) 6176 if((!dest && (!destp || !destp->image)) || (!src && (!srcp || !srcp->image)))
6198 return retval; 6177 return retval;
6199 6178
6200 if(dest) 6179 if(dest)
6201 { 6180 {
6181 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
6182 #if GTK3
6202 GdkWindow *window = gtk_widget_get_window(dest); 6183 GdkWindow *window = gtk_widget_get_window(dest);
6203 /* Safety check for non-existant windows */ 6184 /* Safety check for non-existant windows */
6204 if(!window || !GDK_IS_WINDOW(window)) 6185 if(!window || !GDK_IS_WINDOW(window))
6205 return retval; 6186 return retval;
6206 clip = gdk_window_get_clip_region(window); 6187 clip = gdk_window_get_clip_region(window);
6207 dc = gdk_window_begin_draw_frame(window, clip); 6188 dc = gdk_window_begin_draw_frame(window, clip);
6208 cr = gdk_drawing_context_get_cairo_context(dc); 6189 cr = gdk_drawing_context_get_cairo_context(dc);
6190 #endif
6209 } 6191 }
6210 else if(destp) 6192 else if(destp)
6211 cr = cairo_create(destp->image); 6193 cr = cairo_create(destp->image);
6212 6194
6213 if(cr) 6195 if(cr)
6220 yscale = (double)height / (double)srcheight; 6202 yscale = (double)height / (double)srcheight;
6221 cairo_scale(cr, xscale, yscale); 6203 cairo_scale(cr, xscale, yscale);
6222 } 6204 }
6223 6205
6224 if(src) 6206 if(src)
6207 ;
6208 #ifdef GTK3
6225 gdk_cairo_set_source_window (cr, gtk_widget_get_window(src), (xdest + xsrc) / xscale, (ydest + ysrc) / yscale); 6209 gdk_cairo_set_source_window (cr, gtk_widget_get_window(src), (xdest + xsrc) / xscale, (ydest + ysrc) / yscale);
6210 #endif
6226 else if(srcp) 6211 else if(srcp)
6227 cairo_set_source_surface (cr, srcp->image, (xdest + xsrc) / xscale, (ydest + ysrc) / yscale); 6212 cairo_set_source_surface (cr, srcp->image, (xdest + xsrc) / xscale, (ydest + ysrc) / yscale);
6228 6213
6229 cairo_rectangle(cr, xdest / xscale, ydest / yscale, width, height); 6214 cairo_rectangle(cr, xdest / xscale, ydest / yscale, width, height);
6230 cairo_fill(cr); 6215 cairo_fill(cr);
6231 if(clip) 6216 if(clip)
6232 cairo_region_destroy(clip); 6217 cairo_region_destroy(clip);
6218 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
6219 #if GTK3
6233 /* If we are using a drawing context... 6220 /* If we are using a drawing context...
6234 * we don't own the cairo context so don't destroy it. 6221 * we don't own the cairo context so don't destroy it.
6235 */ 6222 */
6236 if(dc) 6223 if(dc)
6237 gdk_window_end_draw_frame(gtk_widget_get_window(dest), dc); 6224 gdk_window_end_draw_frame(gtk_widget_get_window(dest), dc);
6238 else 6225 else
6226 #else
6227 if(!dc)
6228 #endif
6239 cairo_destroy(cr); 6229 cairo_destroy(cr);
6240 retval = DW_ERROR_NONE; 6230 retval = DW_ERROR_NONE;
6241 } 6231 }
6242 return retval; 6232 return retval;
6243 } 6233 }
7141 if(hscrolled) 7131 if(hscrolled)
7142 *thisheight += 10; 7132 *thisheight += 10;
7143 } 7133 }
7144 else 7134 else
7145 { 7135 {
7146 gtk_widget_get_preferred_height(GTK_WIDGET(widget), NULL, thisheight); 7136 gtk_widget_measure(GTK_WIDGET(widget), GTK_ORIENTATION_HORIZONTAL, -1, thiswidth, NULL, NULL, NULL);
7147 gtk_widget_get_preferred_width(GTK_WIDGET(widget), NULL, thiswidth); 7137 gtk_widget_measure(GTK_WIDGET(widget), GTK_ORIENTATION_VERTICAL, -1, thisheight, NULL, NULL, NULL);
7148 7138
7149 *thisheight += 20; 7139 *thisheight += 20;
7150 *thiswidth += 20; 7140 *thiswidth += 20;
7151 } 7141 }
7152 } 7142 }
7161 } 7151 }
7162 7152
7163 /* Internal box packing function called by the other 3 functions */ 7153 /* Internal box packing function called by the other 3 functions */
7164 void _dw_box_pack(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad, char *funcname) 7154 void _dw_box_pack(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad, char *funcname)
7165 { 7155 {
7166 int warn = FALSE;
7167 GtkWidget *tmp, *tmpitem, *image = NULL; 7156 GtkWidget *tmp, *tmpitem, *image = NULL;
7168 7157
7169 if(!box) 7158 if(!box)
7170 return; 7159 return;
7171 7160
7188 /* Can't pack nothing with GTK, so create an empty label */ 7177 /* Can't pack nothing with GTK, so create an empty label */
7189 if(!item) 7178 if(!item)
7190 { 7179 {
7191 item = gtk_label_new(""); 7180 item = gtk_label_new("");
7192 g_object_set_data(G_OBJECT(item), "_dw_padding", GINT_TO_POINTER(1)); 7181 g_object_set_data(G_OBJECT(item), "_dw_padding", GINT_TO_POINTER(1));
7193 gtk_widget_show_all(item); 7182 gtk_widget_show(item);
7194 } 7183 }
7195 /* Due to GTK3 minimum size limitations, if we are packing a widget 7184 /* Due to GTK3 minimum size limitations, if we are packing a widget
7196 * with an image, we need to scale the image down to fit the packed size. 7185 * with an image, we need to scale the image down to fit the packed size.
7197 */ 7186 */
7198 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap"))) 7187 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap")))
7199 { 7188 {
7189 /* TODO: Figure out how to do this in GTK4 since gtk_image_get_pixbif() is gone...
7190 * Might need to save the pixbuf in the window data manually.
7191 */
7192 #if GTK3
7200 GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image)); 7193 GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image));
7201 7194
7202 if(pixbuf) 7195 if(pixbuf)
7203 { 7196 {
7204 int pwidth = gdk_pixbuf_get_width(pixbuf); 7197 int pwidth = gdk_pixbuf_get_width(pixbuf);
7211 7204
7212 if(pwidth > width || pheight > height) 7205 if(pwidth > width || pheight > height)
7213 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR); 7206 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR);
7214 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); 7207 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
7215 } 7208 }
7209 #endif
7216 } 7210 }
7217 7211
7218 /* Check if the item to be packed is a special box */ 7212 /* Check if the item to be packed is a special box */
7219 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle"); 7213 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle");
7220 7214
7229 * due to a bug in the OS/2 and Win32 renderer and a limitation 7223 * due to a bug in the OS/2 and Win32 renderer and a limitation
7230 * of the GtkTable class. 7224 * of the GtkTable class.
7231 */ 7225 */
7232 if(GTK_IS_GRID(item) || (tmpitem && GTK_IS_GRID(tmpitem))) 7226 if(GTK_IS_GRID(item) || (tmpitem && GTK_IS_GRID(tmpitem)))
7233 { 7227 {
7234 GtkWidget *eventbox = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_eventbox");
7235
7236 /* NOTE: I left in the ability to pack boxes with a size, 7228 /* NOTE: I left in the ability to pack boxes with a size,
7237 * this eliminates that by forcing the size to 0. 7229 * this eliminates that by forcing the size to 0.
7238 */ 7230 */
7239 height = width = 0; 7231 height = width = 0;
7240 7232 /* TODO: Might need to add "_dw_boxpad" to item here */
7241 if(eventbox)
7242 {
7243 int boxpad = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(item), "_dw_boxpad"));
7244 gtk_container_add(GTK_CONTAINER(eventbox), item);
7245 gtk_container_set_border_width(GTK_CONTAINER(eventbox), boxpad);
7246 item = eventbox;
7247 }
7248 }
7249 else
7250 {
7251 /* Only show warning if item is not a box */
7252 warn = TRUE;
7253 } 7233 }
7254 7234
7255 /* Do some sanity bounds checking */ 7235 /* Do some sanity bounds checking */
7256 if(index < 0) 7236 if(index < 0)
7257 index = 0; 7237 index = 0;
7306 else if(width == -1 && GTK_IS_SPIN_BUTTON(item)) 7286 else if(width == -1 && GTK_IS_SPIN_BUTTON(item))
7307 gtk_widget_set_size_request(item, 50, height); 7287 gtk_widget_set_size_request(item, 50, height);
7308 else 7288 else
7309 gtk_widget_set_size_request(item, width, height); 7289 gtk_widget_set_size_request(item, width, height);
7310 } 7290 }
7311 if(GTK_IS_RADIO_BUTTON(item)) 7291 if(GTK_IS_TOGGLE_BUTTON(item))
7312 { 7292 {
7313 GSList *group; 7293 GtkToggleButton *groupstart = (GtkToggleButton *)g_object_get_data(G_OBJECT(box), "_dw_group");
7314 GtkWidget *groupstart = (GtkWidget *)g_object_get_data(G_OBJECT(box), "_dw_group");
7315 7294
7316 if(groupstart) 7295 if(groupstart)
7317 { 7296 gtk_toggle_button_set_group(GTK_TOGGLE_BUTTON(item), groupstart);
7318 group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(groupstart));
7319 gtk_radio_button_set_group(GTK_RADIO_BUTTON(item), group);
7320 }
7321 else 7297 else
7322 g_object_set_data(G_OBJECT(box), "_dw_group", (gpointer)item); 7298 g_object_set_data(G_OBJECT(box), "_dw_group", (gpointer)item);
7323 } 7299 }
7324 /* If we previously incremented the reference count... drop it now that it is packed */ 7300 /* If we previously incremented the reference count... drop it now that it is packed */
7325 if(g_object_get_data(G_OBJECT(item), "_dw_refed")) 7301 if(g_object_get_data(G_OBJECT(item), "_dw_refed"))
7326 { 7302 {
7327 g_object_unref(G_OBJECT(item)); 7303 g_object_unref(G_OBJECT(item));
7328 g_object_set_data(G_OBJECT(item), "_dw_refed", NULL); 7304 g_object_set_data(G_OBJECT(item), "_dw_refed", NULL);
7329 } 7305 }
7330 }
7331
7332 if(warn)
7333 {
7334 if ( width == 0 && hsize == FALSE )
7335 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
7336 if ( height == 0 && vsize == FALSE )
7337 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Height and expand Vertical both unset for box: %x item: %x",box,item);
7338 } 7306 }
7339 } 7307 }
7340 7308
7341 /* 7309 /*
7342 * Remove windows (widgets) from the box they are packed into. 7310 * Remove windows (widgets) from the box they are packed into.
7446 { 7414 {
7447 g_object_ref(G_OBJECT(item)); 7415 g_object_ref(G_OBJECT(item));
7448 g_object_set_data(G_OBJECT(item), "_dw_refed", GINT_TO_POINTER(1)); 7416 g_object_set_data(G_OBJECT(item), "_dw_refed", GINT_TO_POINTER(1));
7449 } 7417 }
7450 /* Remove the widget from the box */ 7418 /* Remove the widget from the box */
7451 gtk_container_remove(GTK_CONTAINER(box), item); 7419 gtk_grid_remove(GTK_GRID(box), item);
7452 if(boxtype == DW_VERT) 7420 if(boxtype == DW_VERT)
7453 gtk_grid_remove_row(GTK_GRID(box), index); 7421 gtk_grid_remove_row(GTK_GRID(box), index);
7454 else 7422 else
7455 gtk_grid_remove_column(GTK_GRID(box), index); 7423 gtk_grid_remove_column(GTK_GRID(box), index);
7456 retval = item; 7424 retval = item;
7522 { 7490 {
7523 if(!handle) 7491 if(!handle)
7524 return; 7492 return;
7525 7493
7526 if(GTK_IS_WINDOW(handle)) 7494 if(GTK_IS_WINDOW(handle))
7527 gtk_window_set_default_size(handle, width, height); 7495 gtk_window_set_default_size(GTK_WINDOW(handle), width, height);
7528 else 7496 else
7529 gtk_widget_set_size_request(handle, width, height); 7497 gtk_widget_set_size_request(GTK_WIDGET(handle), width, height);
7530 } 7498 }
7531 7499
7532 /* 7500 /*
7533 * Gets the size the system thinks the widget should be. 7501 * Gets the size the system thinks the widget should be.
7534 * Parameters: 7502 * Parameters:
7549 if(height) 7517 if(height)
7550 *height = scrolledheight; 7518 *height = scrolledheight;
7551 } 7519 }
7552 else 7520 else
7553 { 7521 {
7554 if(width) 7522 if(width)
7555 gtk_widget_get_preferred_width(handle, NULL, width); 7523 gtk_widget_measure(GTK_WIDGET(handle), GTK_ORIENTATION_HORIZONTAL, -1, width, NULL, NULL, NULL);
7556 if(height) 7524 if(height)
7557 gtk_widget_get_preferred_height(handle, NULL, height); 7525 gtk_widget_measure(GTK_WIDGET(handle), GTK_ORIENTATION_VERTICAL, -1, height, NULL, NULL, NULL);
7558 } 7526 }
7559 } 7527 }
7560 7528
7561 /* Internal version to simplify the code with multiple versions of GTK */ 7529 /* Internal version to simplify the code with multiple versions of GTK */
7562 int _dw_screen_width(void) 7530 int _dw_screen_width(void)
7563 { 7531 {
7564 GdkDisplay *display = gdk_display_get_default(); 7532 GdkDisplay *display = gdk_display_get_default();
7565 7533
7566 if(display) 7534 if(display)
7567 { 7535 {
7568 GdkMonitor *monitor = gdk_display_get_primary_monitor(display); 7536 /* TODO: Verify this is the correct way to do this */
7537 GListModel *monitors = gdk_display_get_monitors(display);
7538 GdkMonitor *monitor = GDK_MONITOR(g_list_model_get_object(monitors, 0));
7569 7539
7570 if(monitor) 7540 if(monitor)
7571 { 7541 {
7572 GdkRectangle rc = { 0, 0, 0 ,0 }; 7542 GdkRectangle rc = { 0, 0, 0 ,0 };
7573 gdk_monitor_get_geometry(monitor, &rc); 7543 gdk_monitor_get_geometry(monitor, &rc);
7590 { 7560 {
7591 GdkDisplay *display = gdk_display_get_default(); 7561 GdkDisplay *display = gdk_display_get_default();
7592 7562
7593 if(display) 7563 if(display)
7594 { 7564 {
7595 GdkMonitor *monitor = gdk_display_get_primary_monitor(display); 7565 /* TODO: Verify this is the correct way to do this */
7566 GListModel *monitors = gdk_display_get_monitors(display);
7567 GdkMonitor *monitor = GDK_MONITOR(g_list_model_get_object(monitors, 0));
7596 7568
7597 if(monitor) 7569 if(monitor)
7598 { 7570 {
7599 GdkRectangle rc = { 0, 0, 0 ,0 }; 7571 GdkRectangle rc = { 0, 0, 0 ,0 };
7600 gdk_monitor_get_geometry(monitor, &rc); 7572 gdk_monitor_get_geometry(monitor, &rc);
7613 } 7585 }
7614 7586
7615 /* This should return the current color depth */ 7587 /* This should return the current color depth */
7616 unsigned long dw_color_depth_get(void) 7588 unsigned long dw_color_depth_get(void)
7617 { 7589 {
7618 GdkVisual *vis = gdk_screen_get_system_visual(gdk_screen_get_default()); 7590 /* TODO: Make this work on GTK4... with no GdkVisual */
7619 return gdk_visual_get_depth(vis); 7591 return 32;
7620 } 7592 }
7621 7593
7622 /* 7594 /*
7623 * Sets the gravity of a given window (widget). 7595 * Sets the gravity of a given window (widget).
7624 * Gravity controls which corner of the screen and window the position is relative to. 7596 * Gravity controls which corner of the screen and window the position is relative to.
7640 * x: X location from the bottom left. 7612 * x: X location from the bottom left.
7641 * y: Y location from the bottom left. 7613 * y: Y location from the bottom left.
7642 */ 7614 */
7643 void dw_window_set_pos(HWND handle, long x, long y) 7615 void dw_window_set_pos(HWND handle, long x, long y)
7644 { 7616 {
7617 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
7645 if(!handle) 7618 if(!handle)
7646 return; 7619 return;
7647
7648 {
7649 GdkWindow *window = NULL;
7650
7651 if(GTK_IS_WINDOW(handle))
7652 {
7653 GdkWindow *window = gtk_widget_get_window(handle);
7654 int horz = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(handle), "_dw_grav_horz"));
7655 int vert = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(handle), "_dw_grav_vert"));
7656 int cx = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(handle), "_dw_frame_width"));
7657 int cy = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(handle), "_dw_frame_height"));
7658 int newx = x, newy = y, width = 0, height = 0;
7659
7660 /* If the window is mapped */
7661 if(window && gtk_widget_get_mapped(handle))
7662 {
7663 /* If we need the width or height... */
7664 if(horz || vert)
7665 {
7666 GdkRectangle frame;
7667 int count = 0;
7668
7669 /* Get the frame size */
7670 gdk_window_get_frame_extents(window, &frame);
7671
7672 /* FIXME: Sometimes we get returned an invalid 200x200
7673 * result... so if we get this... try the call a second
7674 * time and hope for a better result.
7675 */
7676 while((frame.width == 200 || frame.width == (200 + cx)) &&
7677 (frame.height == 200 || frame.height == (200 + cy)) && count < 10)
7678 {
7679 _dw_msleep(1);
7680 count++;
7681 gdk_window_get_frame_extents(window, &frame);
7682 }
7683 width = frame.width;
7684 height = frame.height;
7685 }
7686 }
7687 else
7688 {
7689 /* Check if we have cached frame size values */
7690 if(!(cx | cy))
7691 {
7692 /* If not try to ask the window manager for the estimated size...
7693 * and finally if all else fails, guess.
7694 */
7695 _dw_get_frame_extents(handle, &cy, &cx);
7696 /* Cache values for later use */
7697 g_object_set_data(G_OBJECT(handle), "_dw_frame_width", GINT_TO_POINTER(cx));
7698 g_object_set_data(G_OBJECT(handle), "_dw_frame_height", GINT_TO_POINTER(cy));
7699 }
7700 /* Save the positions for when it is shown */
7701 g_object_set_data(G_OBJECT(handle), "_dw_x", GINT_TO_POINTER(x));
7702 g_object_set_data(G_OBJECT(handle), "_dw_y", GINT_TO_POINTER(y));
7703 g_object_set_data(G_OBJECT(handle), "_dw_pos", GINT_TO_POINTER(1));
7704 /* Check to see if there is a pending size request too */
7705 width = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(handle), "_dw_width"));
7706 height = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(handle), "_dw_height"));
7707 if(!width || !height)
7708 {
7709 /* Ask what GTK is planning on suggesting for the window size */
7710 gtk_window_get_size(GTK_WINDOW(handle), !width ? &width : NULL, !height ? &height : NULL);
7711 }
7712 /* Add the frame size to it */
7713 width += cx;
7714 height += cy;
7715 }
7716 /* Do any gravity calculations */
7717 if(horz || vert)
7718 {
7719 /* Handle horizontal center gravity */
7720 if((horz & 0xf) == DW_GRAV_CENTER)
7721 newx += ((_dw_screen_width() / 2) - (width / 2));
7722 /* Handle right gravity */
7723 else if((horz & 0xf) == DW_GRAV_RIGHT)
7724 newx = _dw_screen_width() - width - x;
7725 /* Handle vertical center gravity */
7726 if((vert & 0xf) == DW_GRAV_CENTER)
7727 newy += ((_dw_screen_height() / 2) - (height / 2));
7728 else if((vert & 0xf) == DW_GRAV_BOTTOM)
7729 newy = _dw_screen_height() - height - y;
7730
7731 /* Adjust the values to avoid Gnome bar if requested */
7732 if((horz | vert) & DW_GRAV_OBSTACLES)
7733 {
7734 GdkRectangle rect = { 0, 0, 0, 0 };
7735 GdkDisplay *display = gdk_display_get_default();
7736
7737 if(display)
7738 {
7739 GdkMonitor *monitor = gdk_display_get_primary_monitor(display);
7740
7741 if(monitor)
7742 gdk_monitor_get_workarea(monitor, &rect);
7743 }
7744 if(horz & DW_GRAV_OBSTACLES)
7745 {
7746 if((horz & 0xf) == DW_GRAV_LEFT)
7747 newx += rect.x;
7748 else if((horz & 0xf) == DW_GRAV_RIGHT)
7749 newx -= _dw_screen_width() - (rect.x + rect.width);
7750 }
7751 if(vert & DW_GRAV_OBSTACLES)
7752 {
7753 if((vert & 0xf) == DW_GRAV_TOP)
7754 newy += rect.y;
7755 else if((vert & 0xf) == DW_GRAV_BOTTOM)
7756 newy -= _dw_screen_height() - (rect.y + rect.height);
7757 }
7758 }
7759 }
7760 /* Finally move the window into place */
7761 gtk_window_move(GTK_WINDOW(handle), newx, newy);
7762 }
7763 else if((window = gtk_widget_get_window(handle)))
7764 gdk_window_move(window, x, y);
7765 }
7766 } 7620 }
7767 7621
7768 /* 7622 /*
7769 * Sets the position and size of a given window (widget). 7623 * Sets the position and size of a given window (widget).
7770 * Parameters: 7624 * Parameters:
7789 * width: Width of the widget. 7643 * width: Width of the widget.
7790 * height: Height of the widget. 7644 * height: Height of the widget.
7791 */ 7645 */
7792 void dw_window_get_pos_size(HWND handle, long *x, long *y, ULONG *width, ULONG *height) 7646 void dw_window_get_pos_size(HWND handle, long *x, long *y, ULONG *width, ULONG *height)
7793 { 7647 {
7794 gint gx = 0, gy = 0, gwidth = 0, gheight = 0; 7648 /* TODO: Figure out how to do this in GTK4 with no GdkWindow */
7795 7649 if(!handle || !GTK_IS_WIDGET(handle))
7796 { 7650 return;
7797 GdkWindow *window; 7651
7798 7652 if(width)
7799 /* Can only query if the window is realized */ 7653 *width = (ULONG)gtk_widget_get_width(GTK_WIDGET(handle));
7800 if(handle && (window = gtk_widget_get_window(handle))) 7654 if(height)
7801 { 7655 *height = (ULONG)gtk_widget_get_height(GTK_WIDGET(handle));
7802 /* If it is a toplevel window */
7803 if(GTK_IS_WINDOW(handle))
7804 {
7805 if(gtk_widget_get_mapped(handle))
7806 {
7807 GdkRectangle frame;
7808
7809 /* Calculate the border rectangle */
7810 gdk_window_get_frame_extents(window, &frame);
7811 gx = frame.x;
7812 gy = frame.y;
7813 gwidth = frame.width;
7814 gheight = frame.height;
7815 }
7816 }
7817 else
7818 {
7819 /* Get an individual widget coordinates */
7820 gdk_window_get_geometry(window, &gx, &gy, &gwidth, &gheight);
7821 gdk_window_get_root_origin(window, &gx, &gy);
7822 }
7823 }
7824 }
7825 /* Fill in the requested fields */
7826 if(x) 7656 if(x)
7827 *x = gx; 7657 *x = 0;
7828 if(y) 7658 if(y)
7829 *y = gy; 7659 *y = 0;
7830 if(width)
7831 *width = gwidth;
7832 if(height)
7833 *height = gheight;
7834 } 7660 }
7835 7661
7836 /* 7662 /*
7837 * Sets the style of a given window (widget). 7663 * Sets the style of a given window (widget).
7838 * Parameters: 7664 * Parameters:
7858 } 7684 }
7859 else if(GTK_IS_BUTTON(handle)) 7685 else if(GTK_IS_BUTTON(handle))
7860 { 7686 {
7861 if(mask & DW_BS_NOBORDER) 7687 if(mask & DW_BS_NOBORDER)
7862 { 7688 {
7689 /* TODO: Figure out how to do this in GTK4 with no Shadow or Relief */
7863 if(style & DW_BS_NOBORDER) 7690 if(style & DW_BS_NOBORDER)
7864 { 7691 ;
7865 gtk_button_set_relief((GtkButton *)handle, GTK_RELIEF_NONE);
7866 }
7867 else 7692 else
7868 { 7693 ;
7869 gtk_button_set_relief((GtkButton *)handle, GTK_RELIEF_NORMAL);
7870 }
7871 } 7694 }
7872 } 7695 }
7873 if ( GTK_IS_LABEL(handle2) ) 7696 if(GTK_IS_LABEL(handle2))
7874 { 7697 {
7875 gfloat x=DW_LEFT, y=DW_CENTER; 7698 gfloat x=DW_LEFT, y=DW_CENTER;
7876 /* horizontal... */ 7699 /* horizontal... */
7877 if ( style & DW_DT_CENTER ) 7700 if ( style & DW_DT_CENTER )
7878 x = DW_CENTER; 7701 x = DW_CENTER;
7887 y = DW_TOP; 7710 y = DW_TOP;
7888 if ( style & DW_DT_BOTTOM ) 7711 if ( style & DW_DT_BOTTOM )
7889 y = DW_BOTTOM; 7712 y = DW_BOTTOM;
7890 gtk_label_set_xalign(GTK_LABEL(handle2), x); 7713 gtk_label_set_xalign(GTK_LABEL(handle2), x);
7891 gtk_label_set_yalign(GTK_LABEL(handle2), y); 7714 gtk_label_set_yalign(GTK_LABEL(handle2), y);
7892 if ( style & DW_DT_WORDBREAK ) 7715 if(style & DW_DT_WORDBREAK)
7893 gtk_label_set_line_wrap( GTK_LABEL(handle), TRUE ); 7716 gtk_label_set_wrap(GTK_LABEL(handle), TRUE);
7894 } 7717 }
7895 if ( GTK_IS_CHECK_MENU_ITEM(handle2) && (mask & (DW_MIS_CHECKED | DW_MIS_UNCHECKED)) ) 7718 /* TODO: Convert to GMenuModel */
7719 #if GTK3
7720 if(GTK_IS_CHECK_MENU_ITEM(handle2) && (mask & (DW_MIS_CHECKED | DW_MIS_UNCHECKED))
7896 { 7721 {
7897 int check = 0; 7722 int check = 0;
7898 7723
7899 if ( style & DW_MIS_CHECKED ) 7724 if ( style & DW_MIS_CHECKED )
7900 check = 1; 7725 check = 1;
7902 _dw_ignore_click = 1; 7727 _dw_ignore_click = 1;
7903 if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(handle2)) != check) 7728 if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(handle2)) != check)
7904 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(handle2), check); 7729 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(handle2), check);
7905 _dw_ignore_click = 0; 7730 _dw_ignore_click = 0;
7906 } 7731 }
7907 if ( (GTK_IS_CHECK_MENU_ITEM(handle2) || GTK_IS_MENU_ITEM(handle2)) && (mask & (DW_MIS_ENABLED | DW_MIS_DISABLED) )) 7732 if((GTK_IS_CHECK_MENU_ITEM(handle2) || GTK_IS_MENU_ITEM(handle2)) && (mask & (DW_MIS_ENABLED | DW_MIS_DISABLED)))
7908 { 7733 {
7909 _dw_ignore_click = 1; 7734 _dw_ignore_click = 1;
7910 if ( style & DW_MIS_ENABLED ) 7735 if ( style & DW_MIS_ENABLED )
7911 gtk_widget_set_sensitive( handle2, TRUE ); 7736 gtk_widget_set_sensitive(handle2, TRUE);
7912 else 7737 else
7913 gtk_widget_set_sensitive( handle2, FALSE ); 7738 gtk_widget_set_sensitive(handle2, FALSE);
7914 _dw_ignore_click = 0; 7739 _dw_ignore_click = 0;
7915 } 7740 }
7741 #endif
7916 } 7742 }
7917 7743
7918 /* 7744 /*
7919 * Adds a new page to specified notebook. 7745 * Adds a new page to specified notebook.
7920 * Parameters: 7746 * Parameters:
8111 label = gtk_label_new(text ? text : ""); 7937 label = gtk_label_new(text ? text : "");
8112 7938
8113 if(GTK_IS_GRID(page)) 7939 if(GTK_IS_GRID(page))
8114 { 7940 {
8115 pad = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(page), "_dw_boxpad")); 7941 pad = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(page), "_dw_boxpad"));
8116 gtk_container_set_border_width(GTK_CONTAINER(page), pad); 7942 /* TODO: Add padding to page with no GtkContainer in GTK4 */
7943 pad = pad;
8117 } 7944 }
8118 7945
8119 if(realpage != -1) 7946 if(realpage != -1)
8120 gtk_notebook_insert_page(GTK_NOTEBOOK(handle), page, label, realpage); 7947 gtk_notebook_insert_page(GTK_NOTEBOOK(handle), page, label, realpage);
8121 else if(num & ~(0xFF)) 7948 else if(num & ~(0xFF))
8693 { 8520 {
8694 GtkWidget *tmp = NULL; 8521 GtkWidget *tmp = NULL;
8695 float *percent = malloc(sizeof(float)); 8522 float *percent = malloc(sizeof(float));
8696 8523
8697 tmp = gtk_paned_new(type == DW_HORZ ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL); 8524 tmp = gtk_paned_new(type == DW_HORZ ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL);
8698 gtk_paned_pack1(GTK_PANED(tmp), topleft, TRUE, FALSE); 8525 gtk_paned_set_start_child(GTK_PANED(tmp), topleft);
8699 gtk_paned_pack2(GTK_PANED(tmp), bottomright, TRUE, FALSE); 8526 gtk_paned_set_resize_start_child(GTK_PANED(tmp), TRUE);
8527 gtk_paned_set_shrink_start_child(GTK_PANED(tmp), FALSE);
8528 gtk_paned_set_end_child(GTK_PANED(tmp), bottomright);
8529 gtk_paned_set_resize_end_child(GTK_PANED(tmp), TRUE);
8530 gtk_paned_set_shrink_end_child(GTK_PANED(tmp), FALSE);
8700 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 8531 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
8701 *percent = 50.0; 8532 *percent = 50.0;
8702 g_object_set_data(G_OBJECT(tmp), "_dw_percent", (gpointer)percent); 8533 g_object_set_data(G_OBJECT(tmp), "_dw_percent", (gpointer)percent);
8703 g_signal_connect(G_OBJECT(tmp), "size-allocate", G_CALLBACK(_splitbar_size_allocate), NULL); 8534 g_signal_connect(G_OBJECT(tmp), "size-allocate", G_CALLBACK(_splitbar_size_allocate), NULL);
8704 gtk_widget_show(tmp); 8535 gtk_widget_show(tmp);
8752 * Returns: 8583 * Returns:
8753 * A handle to a calendar window or NULL on failure. 8584 * A handle to a calendar window or NULL on failure.
8754 */ 8585 */
8755 HWND dw_calendar_new(unsigned long id) 8586 HWND dw_calendar_new(unsigned long id)
8756 { 8587 {
8757 GtkWidget *tmp; 8588 GtkWidget *tmp = gtk_calendar_new();
8758 GtkCalendarDisplayOptions flags; 8589 GTimeZone *tz = g_time_zone_new_local();
8759 time_t now; 8590 GDateTime *now = g_date_time_new_now(tz);
8760 struct tm *tmdata; 8591
8761
8762 tmp = gtk_calendar_new();
8763 gtk_widget_show(tmp); 8592 gtk_widget_show(tmp);
8764 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); 8593 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id));
8765 /* select today */ 8594 /* select today */
8766 flags = GTK_CALENDAR_SHOW_HEADING|GTK_CALENDAR_SHOW_DAY_NAMES; 8595 gtk_calendar_set_show_day_names(GTK_CALENDAR(tmp), TRUE);
8767 gtk_calendar_set_display_options( GTK_CALENDAR(tmp), flags ); 8596 gtk_calendar_set_show_heading(GTK_CALENDAR(tmp), TRUE);
8768 now = time( NULL ); 8597 gtk_calendar_select_day(GTK_CALENDAR(tmp), now);
8769 tmdata = localtime( & now ); 8598 g_date_time_unref(now);
8770 gtk_calendar_select_month( GTK_CALENDAR(tmp), tmdata->tm_mon, 1900+tmdata->tm_year ); 8599 g_time_zone_unref(tz);
8771 gtk_calendar_select_day( GTK_CALENDAR(tmp), tmdata->tm_mday );
8772 return tmp; 8600 return tmp;
8773 } 8601 }
8774 8602
8775 /* 8603 /*
8776 * Sets the current date of a calendar 8604 * Sets the current date of a calendar
8780 */ 8608 */
8781 void dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day) 8609 void dw_calendar_set_date(HWND handle, unsigned int year, unsigned int month, unsigned int day)
8782 { 8610 {
8783 if(GTK_IS_CALENDAR(handle)) 8611 if(GTK_IS_CALENDAR(handle))
8784 { 8612 {
8785 gtk_calendar_select_month(GTK_CALENDAR(handle),month-1,year); 8613 GTimeZone *tz = g_time_zone_new_local();
8786 gtk_calendar_select_day(GTK_CALENDAR(handle), day); 8614 GDateTime *datetime = g_date_time_new(tz, year, month, day, 0, 0, 0);
8615 gtk_calendar_select_day(GTK_CALENDAR(handle), datetime);
8616 g_date_time_unref(datetime);
8617 g_time_zone_unref(tz);
8787 } 8618 }
8788 } 8619 }
8789 8620
8790 /* 8621 /*
8791 * Gets the position of a splitbar (pecentage). 8622 * Gets the position of a splitbar (pecentage).
8794 */ 8625 */
8795 void dw_calendar_get_date(HWND handle, unsigned int *year, unsigned int *month, unsigned int *day) 8626 void dw_calendar_get_date(HWND handle, unsigned int *year, unsigned int *month, unsigned int *day)
8796 { 8627 {
8797 if(GTK_IS_CALENDAR(handle)) 8628 if(GTK_IS_CALENDAR(handle))
8798 { 8629 {
8799 gtk_calendar_get_date(GTK_CALENDAR(handle),year,month,day); 8630 GDateTime *datetime = gtk_calendar_get_date(GTK_CALENDAR(handle));
8800 *month = *month + 1; 8631 if(year)
8632 *year = g_date_time_get_year(datetime);
8633 if(month)
8634 *month = g_date_time_get_month(datetime);
8635 if(day)
8636 *day = g_date_time_get_day_of_month(datetime);
8801 } 8637 }
8802 } 8638 }
8803 8639
8804 /* 8640 /*
8805 * Sets the current focus item for a window/dialog. 8641 * Sets the current focus item for a window/dialog.
8980 GtkFileFilter *filter1 = NULL; 8816 GtkFileFilter *filter1 = NULL;
8981 GtkFileFilter *filter2 = NULL; 8817 GtkFileFilter *filter2 = NULL;
8982 gchar *button; 8818 gchar *button;
8983 char *filename = NULL; 8819 char *filename = NULL;
8984 char buf[1000]; 8820 char buf[1000];
8985 char mypath[PATH_MAX+1]; 8821 DWDialog *tmp = dw_dialog_new(NULL);
8986 8822
8987 switch (flags ) 8823 switch (flags )
8988 { 8824 {
8989 case DW_DIRECTORY_OPEN: 8825 case DW_DIRECTORY_OPEN:
8990 action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; 8826 action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
9009 action, 8845 action,
9010 _("_Cancel"), GTK_RESPONSE_CANCEL, 8846 _("_Cancel"), GTK_RESPONSE_CANCEL,
9011 button, GTK_RESPONSE_ACCEPT, 8847 button, GTK_RESPONSE_ACCEPT,
9012 NULL); 8848 NULL);
9013 8849
9014 if ( flags == DW_FILE_SAVE ) 8850 if(ext)
9015 gtk_file_chooser_set_do_overwrite_confirmation( GTK_FILE_CHOOSER( filew ), TRUE );
9016
9017 if ( ext )
9018 { 8851 {
9019 filter1 = gtk_file_filter_new(); 8852 filter1 = gtk_file_filter_new();
9020 sprintf( buf, "*.%s", ext ); 8853 sprintf( buf, "*.%s", ext );
9021 gtk_file_filter_add_pattern( filter1, (gchar *)buf ); 8854 gtk_file_filter_add_pattern( filter1, (gchar *)buf );
9022 sprintf( buf, "\"%s\" files", ext ); 8855 sprintf( buf, "\"%s\" files", ext );
9026 gtk_file_filter_set_name( filter2, (gchar *)"All Files" ); 8859 gtk_file_filter_set_name( filter2, (gchar *)"All Files" );
9027 gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( filew ), filter1 ); 8860 gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( filew ), filter1 );
9028 gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( filew ), filter2 ); 8861 gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( filew ), filter2 );
9029 } 8862 }
9030 8863
9031 if ( defpath ) 8864 if(defpath)
9032 { 8865 {
9033 struct stat buf; 8866 GFile *path = g_file_new_for_path(defpath);
9034
9035 if ( g_path_is_absolute( defpath ) || !realpath(defpath, mypath))
9036 {
9037 strcpy( mypath, defpath );
9038 }
9039 8867
9040 /* See if the path exists */ 8868 /* See if the path exists */
9041 if(stat(mypath, &buf) == 0) 8869 if(path)
9042 { 8870 {
9043 /* If the path is a directory... set the current folder */ 8871 /* If the path is a directory... set the current folder */
9044 if(buf.st_mode & S_IFDIR) 8872 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(filew), path, NULL);
9045 gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( filew ), mypath ); 8873 gtk_file_chooser_set_file(GTK_FILE_CHOOSER(filew), path, NULL);
9046 else if(flags == DW_FILE_SAVE) /* Otherwise set the filename */ 8874
9047 gtk_file_chooser_set_filename( GTK_FILE_CHOOSER( filew ), mypath ); 8875 g_object_unref(G_OBJECT(path));
9048 else if(flags == DW_FILE_OPEN) 8876 }
9049 gtk_file_chooser_select_filename( GTK_FILE_CHOOSER( filew), mypath ); 8877 }
9050 } 8878
9051 else if(flags == DW_FILE_SAVE) 8879 /* TODO: Connect signal handlers so this actually returns */
9052 { 8880 if(DW_POINTER_TO_INT(dw_dialog_wait(tmp)) == GTK_RESPONSE_ACCEPT)
9053 if(strchr(mypath, '/')) 8881 {
9054 { 8882 GFile *file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(filew));
9055 unsigned long x = strlen(mypath) - 1; 8883 filename = g_file_get_path(file);
9056 8884 g_object_unref(G_OBJECT(file));
9057 /* Trim off the filename */ 8885 }
9058 while(x > 0 && mypath[x] != '/') 8886
9059 { 8887 if(GTK_IS_WINDOW(filew))
9060 x--; 8888 gtk_window_destroy(GTK_WINDOW(filew));
9061 }
9062 if(mypath[x] == '/')
9063 {
9064 char *file = NULL;
9065 char temp[PATH_MAX+1];
9066
9067 /* Save the original path in temp */
9068 strcpy(temp, mypath);
9069 mypath[x] = 0;
9070
9071 /* Check to make sure the trimmed piece is a directory */
9072 if(realpath(mypath, temp) && stat(temp, &buf) == 0)
9073 {
9074 if(buf.st_mode & S_IFDIR)
9075 {
9076 /* We now have it split */
9077 file = &mypath[x+1];
9078 }
9079 }
9080
9081 /* Select folder... */
9082 gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(filew), temp );
9083 /* ... and file separately */
9084 if(file)
9085 gtk_file_chooser_set_current_name( GTK_FILE_CHOOSER(filew), file );
9086 }
9087 }
9088 }
9089 }
9090
9091 if ( gtk_dialog_run( GTK_DIALOG( filew ) ) == GTK_RESPONSE_ACCEPT )
9092 {
9093 filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( filew ) );
9094 /*g_free (filename);*/
9095 }
9096
9097 if(GTK_IS_WIDGET(filew))
9098 g_object_unref(G_OBJECT(filew));
9099 return filename; 8889 return filename;
9100 } 8890 }
9101 8891
9102 8892
9103 /* 8893 /*
9167 * url: Uniform resource locator. 8957 * url: Uniform resource locator.
9168 */ 8958 */
9169 int dw_browse(const char *url) 8959 int dw_browse(const char *url)
9170 { 8960 {
9171 /* If possible load the URL/URI using gvfs... */ 8961 /* If possible load the URL/URI using gvfs... */
9172 #if GTK_CHECK_VERSION(3,22,0) 8962 gtk_show_uri(NULL, url, GDK_CURRENT_TIME);
9173 if(gtk_show_uri_on_window(NULL, url, GDK_CURRENT_TIME, NULL)) 8963 return DW_ERROR_NONE;
9174 #else
9175 if(gtk_show_uri(gdk_screen_get_default(), url, GDK_CURRENT_TIME, NULL))
9176 #endif
9177 {
9178 return DW_ERROR_NONE;
9179 }
9180 else
9181 {
9182 /* Otherwise just fall back to executing firefox...
9183 * or the browser defined by the DW_BROWSER variable.
9184 */
9185 char *execargs[3], *browser = "firefox", *tmp;
9186
9187 tmp = getenv( "DW_BROWSER" );
9188 if(tmp) browser = tmp;
9189 execargs[0] = browser;
9190 execargs[1] = (char *)url;
9191 execargs[2] = NULL;
9192
9193 return dw_exec(browser, DW_EXEC_GUI, execargs);
9194 }
9195 } 8964 }
9196 8965
9197 #ifdef USE_WEBKIT 8966 #ifdef USE_WEBKIT
9198 /* Helper function to get the web view handle */ 8967 /* Helper function to get the web view handle */
9199 WebKitWebView *_dw_html_web_view(GtkWidget *widget) 8968 WebKitWebView *_dw_html_web_view(GtkWidget *widget)
9360 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not 9129 * Pointer to an allocated string of text or NULL if clipboard empty or contents could not
9361 * be converted to text. 9130 * be converted to text.
9362 */ 9131 */
9363 char *dw_clipboard_get_text() 9132 char *dw_clipboard_get_text()
9364 { 9133 {
9365 GtkClipboard *clipboard_object; 9134 GdkDisplay *display = gdk_display_get_default();
9135 GdkClipboard *clipboard_object;
9366 char *ret = NULL; 9136 char *ret = NULL;
9367 9137
9368 if((clipboard_object = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ))) 9138 if((clipboard_object = gdk_display_get_clipboard(display)))
9369 { 9139 {
9140 /* TODO: Finish conversion to GdkClipboard */
9141 #if GTK3
9370 gchar *clipboard_contents; 9142 gchar *clipboard_contents;
9371 9143
9372 if((clipboard_contents = gtk_clipboard_wait_for_text( clipboard_object ))) 9144 if((clipboard_contents = gtk_clipboard_wait_for_text( clipboard_object )))
9373 { 9145 {
9374 ret = strdup((char *)clipboard_contents); 9146 ret = strdup((char *)clipboard_contents);
9375 g_free(clipboard_contents); 9147 g_free(clipboard_contents);
9376 } 9148 }
9149 #endif
9377 } 9150 }
9378 return ret; 9151 return ret;
9379 } 9152 }
9380 9153
9381 /* 9154 /*
9383 * Parameters: 9156 * Parameters:
9384 * Text. 9157 * Text.
9385 */ 9158 */
9386 void dw_clipboard_set_text(const char *str, int len) 9159 void dw_clipboard_set_text(const char *str, int len)
9387 { 9160 {
9388 GtkClipboard *clipboard_object; 9161 GdkDisplay *display = gdk_display_get_default();
9389 9162 GdkClipboard *clipboard_object;
9390 if((clipboard_object = gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ))) 9163
9391 { 9164 if((clipboard_object = gdk_display_get_clipboard(display)))
9165 {
9166 /* TODO: Finish conversion to GdkClipboard */
9167 #if GTK3
9392 gtk_clipboard_set_text( clipboard_object, str, len ); 9168 gtk_clipboard_set_text( clipboard_object, str, len );
9169 #endif
9393 } 9170 }
9394 } 9171 }
9395 9172
9396 /* Internal function to create the drawable pixmap and call the function */ 9173 /* Internal function to create the drawable pixmap and call the function */
9397 static void _dw_draw_page(GtkPrintOperation *operation, GtkPrintContext *context, int page_nr) 9174 static void _dw_draw_page(GtkPrintOperation *operation, GtkPrintContext *context, int page_nr)
9756 9533
9757 if (strcmp(signame, DW_SIGNAL_EXPOSE) == 0) 9534 if (strcmp(signame, DW_SIGNAL_EXPOSE) == 0)
9758 { 9535 {
9759 thisname = "draw"; 9536 thisname = "draw";
9760 } 9537 }
9538 /* TODO: Convert to GMenuModel */
9539 #if GTK3
9761 else if (GTK_IS_MENU_ITEM(thiswindow) && strcmp(signame, DW_SIGNAL_CLICKED) == 0) 9540 else if (GTK_IS_MENU_ITEM(thiswindow) && strcmp(signame, DW_SIGNAL_CLICKED) == 0)
9762 { 9541 {
9763 thisname = "activate"; 9542 thisname = "activate";
9764 thisfunc = _findsigfunc(thisname); 9543 thisfunc = _findsigfunc(thisname);
9765 } 9544 }
9545 #endif
9766 else if (GTK_IS_TREE_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_ITEM_CONTEXT) == 0) 9546 else if (GTK_IS_TREE_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_ITEM_CONTEXT) == 0)
9767 { 9547 {
9768 sigid = _set_signal_handler(thiswindow, window, sigfunc, data, thisfunc, discfunc); 9548 sigid = _set_signal_handler(thiswindow, window, sigfunc, data, thisfunc, discfunc);
9769 params[0] = GINT_TO_POINTER(sigid); 9549 params[0] = GINT_TO_POINTER(sigid);
9770 params[2] = (void *)thiswindow; 9550 params[2] = (void *)thiswindow;
9822 } 9602 }
9823 else if (strcmp(signame, DW_SIGNAL_SET_FOCUS) == 0) 9603 else if (strcmp(signame, DW_SIGNAL_SET_FOCUS) == 0)
9824 { 9604 {
9825 thisname = "focus-in-event"; 9605 thisname = "focus-in-event";
9826 if (GTK_IS_COMBO_BOX(thiswindow)) 9606 if (GTK_IS_COMBO_BOX(thiswindow))
9827 thiswindow = gtk_bin_get_child(GTK_BIN(thiswindow)); 9607 thiswindow = gtk_combo_box_get_child(GTK_COMBO_BOX(thiswindow));
9828 } 9608 }
9829 #ifdef USE_WEBKIT 9609 #ifdef USE_WEBKIT
9830 else if (WEBKIT_IS_WEB_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_HTML_CHANGED) == 0) 9610 else if (WEBKIT_IS_WEB_VIEW(thiswindow) && strcmp(signame, DW_SIGNAL_HTML_CHANGED) == 0)
9831 { 9611 {
9832 thisname = "load-changed"; 9612 thisname = "load-changed";