Mercurial > dwindows
comparison gtk3/dw.c @ 1053:0725114533fe
Changes to the GTK3 font chooser... this version doesn't block the rest of the app.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 02 Jun 2011 08:19:14 +0000 |
parents | c008a186b735 |
children | 818698b4a0df |
comparison
equal
deleted
inserted
replaced
1052:c008a186b735 | 1053:0725114533fe |
---|---|
2557 } | 2557 } |
2558 DW_MUTEX_UNLOCK; | 2558 DW_MUTEX_UNLOCK; |
2559 return TRUE; | 2559 return TRUE; |
2560 } | 2560 } |
2561 | 2561 |
2562 /* Allows the user to choose a font using the system's font chooser dialog. | 2562 static int _dw_font_active = 0; |
2563 * Parameters: | 2563 |
2564 * currfont: current font | 2564 /* Internal function to handle the color OK press */ |
2565 * Returns: | 2565 static gint _gtk_font_ok(GtkWidget *widget, DWDialog *dwwait) |
2566 * A malloced buffer with the selected font or NULL on error. | |
2567 */ | |
2568 char * API dw_font_choose(char *currfont) | |
2569 { | 2566 { |
2570 GtkFontSelectionDialog *fd; | 2567 GtkFontSelectionDialog *fd; |
2571 char *font = currfont ? strdup(currfont) : NULL; | |
2572 char *name = font ? strchr(font, '.') : NULL; | |
2573 int _locked_by_me = FALSE; | |
2574 GtkResponseType result; | |
2575 char *retfont = NULL; | 2568 char *retfont = NULL; |
2576 | 2569 gchar *fontname; |
2577 /* Detect Dynamic Windows style font name... | 2570 int len, x; |
2578 * Format: ##.Fontname | 2571 |
2579 * and convert to a Pango name | 2572 if(!dwwait) |
2580 */ | 2573 return FALSE; |
2581 if(name && isdigit(*font)) | 2574 |
2582 { | 2575 fd = dwwait->data; |
2583 int size = atoi(font); | 2576 fontname = gtk_font_selection_dialog_get_font_name(fd); |
2584 *name = 0; | 2577 if(fontname && (retfont = strdup(fontname))) |
2585 name++; | 2578 { |
2586 sprintf(font, "%s %d", name, size); | |
2587 } | |
2588 | |
2589 DW_MUTEX_LOCK; | |
2590 fd = (GtkFontSelectionDialog *)gtk_font_selection_dialog_new("Choose font"); | |
2591 if(name) | |
2592 { | |
2593 gtk_font_selection_dialog_set_font_name(fd, name); | |
2594 free(name); | |
2595 } | |
2596 | |
2597 result = gtk_dialog_run(GTK_DIALOG(fd)); | |
2598 | |
2599 if(result == GTK_RESPONSE_OK || result == GTK_RESPONSE_APPLY) | |
2600 { | |
2601 gchar *fontname = gtk_font_selection_dialog_get_font_name(fd); | |
2602 int len, x; | |
2603 | |
2604 retfont = strdup(fontname); | |
2605 len = strlen(fontname); | 2579 len = strlen(fontname); |
2606 /* Convert to Dynamic Windows format if we can... */ | 2580 /* Convert to Dynamic Windows format if we can... */ |
2607 if(len > 0 && isdigit(fontname[len-1])) | 2581 if(len > 0 && isdigit(fontname[len-1])) |
2608 { | 2582 { |
2609 int size; | 2583 int size; |
2625 } | 2599 } |
2626 } | 2600 } |
2627 dw_free(fontname); | 2601 dw_free(fontname); |
2628 } | 2602 } |
2629 gtk_widget_destroy(GTK_WIDGET(fd)); | 2603 gtk_widget_destroy(GTK_WIDGET(fd)); |
2604 dw_dialog_dismiss(dwwait, (void *)retfont); | |
2605 return FALSE; | |
2606 } | |
2607 | |
2608 /* Internal function to handle the color Cancel press */ | |
2609 static gint _gtk_font_cancel(GtkWidget *widget, DWDialog *dwwait) | |
2610 { | |
2611 if(!dwwait) | |
2612 return FALSE; | |
2613 | |
2614 gtk_widget_destroy(GTK_WIDGET(dwwait->data)); | |
2615 _dw_font_active = 0; | |
2616 dw_dialog_dismiss(dwwait, NULL); | |
2617 return FALSE; | |
2618 } | |
2619 | |
2620 /* Allows the user to choose a font using the system's font chooser dialog. | |
2621 * Parameters: | |
2622 * currfont: current font | |
2623 * Returns: | |
2624 * A malloced buffer with the selected font or NULL on error. | |
2625 */ | |
2626 char * API dw_font_choose(char *currfont) | |
2627 { | |
2628 GtkFontSelectionDialog *fd; | |
2629 GtkWidget *ok_button, *cancel_button; | |
2630 char *font = currfont ? strdup(currfont) : NULL; | |
2631 char *name = font ? strchr(font, '.') : NULL; | |
2632 int _locked_by_me = FALSE; | |
2633 char *retfont = NULL; | |
2634 DWDialog *dwwait; | |
2635 | |
2636 /* Detect Dynamic Windows style font name... | |
2637 * Format: ##.Fontname | |
2638 * and convert to a Pango name | |
2639 */ | |
2640 if(name && isdigit(*font)) | |
2641 { | |
2642 int size = atoi(font); | |
2643 *name = 0; | |
2644 name++; | |
2645 sprintf(font, "%s %d", name, size); | |
2646 } | |
2647 | |
2648 DW_MUTEX_LOCK; | |
2649 fd = (GtkFontSelectionDialog *)gtk_font_selection_dialog_new("Choose font"); | |
2650 if(name) | |
2651 { | |
2652 gtk_font_selection_dialog_set_font_name(fd, name); | |
2653 free(name); | |
2654 } | |
2655 | |
2656 _dw_font_active = 1; | |
2657 | |
2658 dwwait = dw_dialog_new((void *)fd); | |
2659 | |
2660 ok_button = gtk_font_selection_dialog_get_ok_button(fd); | |
2661 cancel_button = gtk_font_selection_dialog_get_cancel_button(fd); | |
2662 g_signal_connect(G_OBJECT(ok_button), "clicked", G_CALLBACK(_gtk_font_ok), dwwait); | |
2663 g_signal_connect(G_OBJECT(cancel_button), "clicked", G_CALLBACK(_gtk_font_cancel), dwwait); | |
2664 | |
2665 gtk_widget_show(GTK_WIDGET(fd)); | |
2666 | |
2667 retfont = (char *)dw_dialog_wait(dwwait); | |
2630 DW_MUTEX_UNLOCK; | 2668 DW_MUTEX_UNLOCK; |
2631 return retfont; | 2669 return retfont; |
2632 } | 2670 } |
2633 | 2671 |
2634 /* | 2672 /* |