summaryrefslogtreecommitdiff
path: root/iup/src/gtk/iupgtk_fontdlg.c
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-11-04 11:56:41 -0800
committerPixel <pixel@nobis-crew.org>2009-11-04 11:59:33 -0800
commitd577d991b97ae2b5ee1af23641bcffc3f83af5b2 (patch)
tree590639d50205d1bcfaff2a7d2dc6ebf3f373c7ed /iup/src/gtk/iupgtk_fontdlg.c
Initial import. Contains the im, cd and iup librairies, and a "working" Makefile for them under linux.
Diffstat (limited to 'iup/src/gtk/iupgtk_fontdlg.c')
-rwxr-xr-xiup/src/gtk/iupgtk_fontdlg.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/iup/src/gtk/iupgtk_fontdlg.c b/iup/src/gtk/iupgtk_fontdlg.c
new file mode 100755
index 0000000..5769cbc
--- /dev/null
+++ b/iup/src/gtk/iupgtk_fontdlg.c
@@ -0,0 +1,91 @@
+/** \file
+ * \brief IupFontDlg pre-defined dialog
+ *
+ * See Copyright Notice in "iup.h"
+ */
+
+#include <gtk/gtk.h>
+
+#include <string.h>
+#include <memory.h>
+
+#include "iup.h"
+
+#include "iup_object.h"
+#include "iup_attrib.h"
+#include "iup_str.h"
+#include "iup_dialog.h"
+
+#include "iupgtk_drv.h"
+
+
+static int gtkFontDlgPopup(Ihandle* ih, int x, int y)
+{
+ InativeHandle* parent = iupDialogGetNativeParent(ih);
+ GtkFontSelectionDialog* dialog;
+ int response;
+ char* preview_text;
+
+ iupAttribSetInt(ih, "_IUPDLG_X", x); /* used in iupDialogUpdatePosition */
+ iupAttribSetInt(ih, "_IUPDLG_Y", y);
+
+ dialog = (GtkFontSelectionDialog*)gtk_font_selection_dialog_new(iupgtkStrConvertToUTF8(iupAttribGet(ih, "TITLE")));
+ if (!dialog)
+ return IUP_ERROR;
+
+ if (parent)
+ gtk_window_set_transient_for((GtkWindow*)dialog, (GtkWindow*)parent);
+
+ gtk_font_selection_dialog_set_font_name(dialog, iupAttribGet(ih, "VALUE"));
+
+ preview_text = iupAttribGet(ih, "PREVIEWTEXT");
+ if (preview_text)
+ gtk_font_selection_dialog_set_preview_text(dialog, preview_text);
+
+ if (IupGetCallback(ih, "HELP_CB"))
+ gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_HELP, GTK_RESPONSE_HELP);
+
+ /* initialize the widget */
+ gtk_widget_realize(GTK_WIDGET(dialog));
+
+ ih->handle = GTK_WIDGET(dialog);
+ iupDialogUpdatePosition(ih);
+ ih->handle = NULL;
+
+ do
+ {
+ response = gtk_dialog_run(GTK_DIALOG(dialog));
+
+ if (response == GTK_RESPONSE_HELP)
+ {
+ Icallback cb = IupGetCallback(ih, "HELP_CB");
+ if (cb && cb(ih) == IUP_CLOSE)
+ response = GTK_RESPONSE_CANCEL;
+ }
+ } while (response == GTK_RESPONSE_HELP);
+
+ if (response == GTK_RESPONSE_OK)
+ {
+ char* fontname = gtk_font_selection_dialog_get_font_name(dialog);
+ iupAttribStoreStr(ih, "VALUE", fontname);
+ g_free(fontname);
+ iupAttribSetStr(ih, "STATUS", "1");
+ }
+ else
+ {
+ iupAttribSetStr(ih, "VALUE", NULL);
+ iupAttribSetStr(ih, "STATUS", NULL);
+ }
+
+ gtk_widget_destroy(GTK_WIDGET(dialog));
+
+ return IUP_NOERROR;
+}
+
+void iupdrvFontDlgInitClass(Iclass* ic)
+{
+ ic->DlgPopup = gtkFontDlgPopup;
+
+ /* IupFontDialog GTK Only */
+ iupClassRegisterAttribute(ic, "PREVIEWTEXT", NULL, NULL, NULL, NULL, IUPAF_NO_INHERIT);
+}