Mercurial > dwindows
comparison gtk3/dw.c @ 1576:85fa989dc833
Switched to using new GtkFontChooserDialog for GTK3 since GtkFontSelectionDialog is deprecated.
Also discontinued support for GTK 3.0, it used to limp along but now it is completely broken.
GTK 3.2 or later is now required.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 23 Jan 2012 21:07:09 +0000 |
parents | 58ed65820baf |
children | fdafbc654e9d |
comparison
equal
deleted
inserted
replaced
1575:58ed65820baf | 1576:85fa989dc833 |
---|---|
34 #ifdef USE_WEBKIT | 34 #ifdef USE_WEBKIT |
35 #include <webkit/webkit.h> | 35 #include <webkit/webkit.h> |
36 #endif | 36 #endif |
37 | 37 |
38 #include <gdk-pixbuf/gdk-pixbuf.h> | 38 #include <gdk-pixbuf/gdk-pixbuf.h> |
39 | |
40 #if !GTK_CHECK_VERSION(3,1,0) | |
41 #error GTK 3.0 is no longer supported. | |
42 #endif | |
39 | 43 |
40 #if __STDC_VERSION__ < 199901L | 44 #if __STDC_VERSION__ < 199901L |
41 # if __GNUC__ >= 2 | 45 # if __GNUC__ >= 2 |
42 # define __func__ __FUNCTION__ | 46 # define __func__ __FUNCTION__ |
43 # else | 47 # else |
2544 } | 2548 } |
2545 DW_MUTEX_UNLOCK; | 2549 DW_MUTEX_UNLOCK; |
2546 return TRUE; | 2550 return TRUE; |
2547 } | 2551 } |
2548 | 2552 |
2549 static int _dw_font_active = 0; | |
2550 | |
2551 /* Internal function to handle the font OK press */ | |
2552 static gint _gtk_font_ok(GtkWidget *widget, DWDialog *dwwait) | |
2553 { | |
2554 GtkFontSelectionDialog *fd; | |
2555 char *retfont = NULL; | |
2556 gchar *fontname; | |
2557 int len, x; | |
2558 | |
2559 if(!dwwait) | |
2560 return FALSE; | |
2561 | |
2562 fd = dwwait->data; | |
2563 fontname = gtk_font_selection_dialog_get_font_name(fd); | |
2564 if(fontname && (retfont = strdup(fontname))) | |
2565 { | |
2566 len = strlen(fontname); | |
2567 /* Convert to Dynamic Windows format if we can... */ | |
2568 if(len > 0 && isdigit(fontname[len-1])) | |
2569 { | |
2570 int size; | |
2571 | |
2572 x=len-1; | |
2573 while(x > 0 && fontname[x] != ' ') | |
2574 { | |
2575 x--; | |
2576 } | |
2577 size = atoi(&fontname[x]); | |
2578 /* If we were able to find a valid size... */ | |
2579 if(size > 0) | |
2580 { | |
2581 /* Null terminate after the name... | |
2582 * and create the Dynamic Windows style font. | |
2583 */ | |
2584 fontname[x] = 0; | |
2585 snprintf(retfont, len+1, "%d.%s", size, fontname); | |
2586 } | |
2587 } | |
2588 dw_free(fontname); | |
2589 } | |
2590 gtk_widget_destroy(GTK_WIDGET(fd)); | |
2591 _dw_font_active = 0; | |
2592 dw_dialog_dismiss(dwwait, (void *)retfont); | |
2593 return FALSE; | |
2594 } | |
2595 | |
2596 /* Internal function to handle the font Cancel press */ | |
2597 static gint _gtk_font_cancel(GtkWidget *widget, DWDialog *dwwait) | |
2598 { | |
2599 if(!dwwait) | |
2600 return FALSE; | |
2601 | |
2602 gtk_widget_destroy(GTK_WIDGET(dwwait->data)); | |
2603 _dw_font_active = 0; | |
2604 dw_dialog_dismiss(dwwait, NULL); | |
2605 return FALSE; | |
2606 } | |
2607 | |
2608 /* Allows the user to choose a font using the system's font chooser dialog. | 2553 /* Allows the user to choose a font using the system's font chooser dialog. |
2609 * Parameters: | 2554 * Parameters: |
2610 * currfont: current font | 2555 * currfont: current font |
2611 * Returns: | 2556 * Returns: |
2612 * A malloced buffer with the selected font or NULL on error. | 2557 * A malloced buffer with the selected font or NULL on error. |
2613 */ | 2558 */ |
2614 char * API dw_font_choose(char *currfont) | 2559 char * API dw_font_choose(char *currfont) |
2615 { | 2560 { |
2616 GtkFontSelectionDialog *fd; | 2561 GtkFontChooser *fd; |
2617 GtkWidget *ok_button, *cancel_button; | |
2618 char *font = currfont ? strdup(currfont) : NULL; | 2562 char *font = currfont ? strdup(currfont) : NULL; |
2619 char *name = font ? strchr(font, '.') : NULL; | 2563 char *name = font ? strchr(font, '.') : NULL; |
2620 int _locked_by_me = FALSE; | 2564 int _locked_by_me = FALSE; |
2621 char *retfont = NULL; | 2565 char *retfont = NULL; |
2622 DWDialog *dwwait; | |
2623 | 2566 |
2624 /* Detect Dynamic Windows style font name... | 2567 /* Detect Dynamic Windows style font name... |
2625 * Format: ##.Fontname | 2568 * Format: ##.Fontname |
2626 * and convert to a Pango name | 2569 * and convert to a Pango name |
2627 */ | 2570 */ |
2632 name++; | 2575 name++; |
2633 sprintf(font, "%s %d", name, size); | 2576 sprintf(font, "%s %d", name, size); |
2634 } | 2577 } |
2635 | 2578 |
2636 DW_MUTEX_LOCK; | 2579 DW_MUTEX_LOCK; |
2637 /* The DW mutex should be sufficient for | 2580 fd = (GtkFontChooser *)gtk_font_chooser_dialog_new("Choose font", NULL); |
2638 * insuring no thread changes this unknowingly. | |
2639 */ | |
2640 if(_dw_font_active) | |
2641 { | |
2642 DW_MUTEX_UNLOCK; | |
2643 if(font) | |
2644 free(font); | |
2645 return NULL; | |
2646 } | |
2647 fd = (GtkFontSelectionDialog *)gtk_font_selection_dialog_new("Choose font"); | |
2648 if(font) | 2581 if(font) |
2649 { | 2582 { |
2650 gtk_font_selection_dialog_set_font_name(fd, font); | 2583 gtk_font_chooser_set_font(fd, font); |
2651 free(font); | 2584 free(font); |
2652 } | 2585 } |
2653 | 2586 |
2654 _dw_font_active = 1; | |
2655 | |
2656 dwwait = dw_dialog_new((void *)fd); | |
2657 | |
2658 ok_button = gtk_font_selection_dialog_get_ok_button(fd); | |
2659 cancel_button = gtk_font_selection_dialog_get_cancel_button(fd); | |
2660 g_signal_connect(G_OBJECT(ok_button), "clicked", G_CALLBACK(_gtk_font_ok), dwwait); | |
2661 g_signal_connect(G_OBJECT(cancel_button), "clicked", G_CALLBACK(_gtk_font_cancel), dwwait); | |
2662 | |
2663 gtk_widget_show(GTK_WIDGET(fd)); | 2587 gtk_widget_show(GTK_WIDGET(fd)); |
2664 | 2588 |
2665 retfont = (char *)dw_dialog_wait(dwwait); | 2589 if(gtk_dialog_run(GTK_DIALOG(fd)) == GTK_RESPONSE_OK) |
2590 { | |
2591 char *fontname = gtk_font_chooser_get_font(fd); | |
2592 if(fontname && (retfont = strdup(fontname))) | |
2593 { | |
2594 int len = strlen(fontname); | |
2595 /* Convert to Dynamic Windows format if we can... */ | |
2596 if(len > 0 && isdigit(fontname[len-1])) | |
2597 { | |
2598 int size, x=len-1; | |
2599 | |
2600 while(x > 0 && fontname[x] != ' ') | |
2601 { | |
2602 x--; | |
2603 } | |
2604 size = atoi(&fontname[x]); | |
2605 /* If we were able to find a valid size... */ | |
2606 if(size > 0) | |
2607 { | |
2608 /* Null terminate after the name... | |
2609 * and create the Dynamic Windows style font. | |
2610 */ | |
2611 fontname[x] = 0; | |
2612 snprintf(retfont, len+1, "%d.%s", size, fontname); | |
2613 } | |
2614 } | |
2615 g_free(fontname); | |
2616 } | |
2617 } | |
2618 gtk_widget_destroy(GTK_WIDGET(fd)); | |
2666 DW_MUTEX_UNLOCK; | 2619 DW_MUTEX_UNLOCK; |
2667 return retfont; | 2620 return retfont; |
2668 } | 2621 } |
2669 | 2622 |
2670 /* | 2623 /* |
8551 /* Add to the grid using insert... | 8504 /* Add to the grid using insert... |
8552 * rows for vertical boxes and columns for horizontal. | 8505 * rows for vertical boxes and columns for horizontal. |
8553 */ | 8506 */ |
8554 if(boxtype == DW_VERT) | 8507 if(boxtype == DW_VERT) |
8555 { | 8508 { |
8556 #if GTK_CHECK_VERSION(3,1,0) | |
8557 gtk_grid_insert_row(GTK_GRID(box), index); | 8509 gtk_grid_insert_row(GTK_GRID(box), index); |
8558 #else | |
8559 #warning Dynamic Windows GTK3 support requires 3.1 or higher for full support. | |
8560 #endif | |
8561 gtk_grid_attach(GTK_GRID(box), item, 0, index, 1, 1); | 8510 gtk_grid_attach(GTK_GRID(box), item, 0, index, 1, 1); |
8562 } | 8511 } |
8563 else | 8512 else |
8564 { | 8513 { |
8565 #if GTK_CHECK_VERSION(3,1,0) | |
8566 gtk_grid_insert_column(GTK_GRID(box), index); | 8514 gtk_grid_insert_column(GTK_GRID(box), index); |
8567 #endif | |
8568 gtk_grid_attach(GTK_GRID(box), item, index, 0, 1, 1); | 8515 gtk_grid_attach(GTK_GRID(box), item, index, 0, 1, 1); |
8569 } | 8516 } |
8570 g_object_set_data(G_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount + 1)); | 8517 g_object_set_data(G_OBJECT(box), "_dw_boxcount", GINT_TO_POINTER(boxcount + 1)); |
8571 /* Special case for scrolled windows */ | 8518 /* Special case for scrolled windows */ |
8572 if(GTK_IS_SCROLLED_WINDOW(item)) | 8519 if(GTK_IS_SCROLLED_WINDOW(item)) |