X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..ef6cf650f4a75c3f97de06b51fa104f2069b9ea2:/icuSources/samples/layout/gnomelayout.cpp diff --git a/icuSources/samples/layout/gnomelayout.cpp b/icuSources/samples/layout/gnomelayout.cpp index ab1dba37..31e25871 100644 --- a/icuSources/samples/layout/gnomelayout.cpp +++ b/icuSources/samples/layout/gnomelayout.cpp @@ -2,7 +2,7 @@ /* ****************************************************************************** * * - * Copyright (C) 1999-2003, International Business Machines + * Copyright (C) 1999-2007, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** * @@ -13,7 +13,8 @@ */ #include -#include "freetype/freetype.h" +#include +#include FT_FREETYPE_H #include "unicode/ustring.h" #include "unicode/uscript.h" @@ -36,7 +37,7 @@ struct Context Paragraph *paragraph; }; -static TT_Engine engine; +static FT_Library engine; static GnomeGUISupport *guiSupport; static GnomeFontMap *fontMap; static ScriptCompositeFontInstance *font; @@ -46,9 +47,10 @@ static GSList *appList = NULL; GtkWidget *newSample(const gchar *fileName); void closeSample(GtkWidget *sample); -void showabout(GtkWidget *widget, gpointer data) +void showabout(GtkWidget */*widget*/, gpointer /*data*/) { GtkWidget *aboutBox; + const gchar *documentedBy[] = {NULL}; const gchar *writtenBy[] = { "Eric Mader", NULL @@ -56,28 +58,30 @@ void showabout(GtkWidget *widget, gpointer data) aboutBox = gnome_about_new("Gnome Layout Sample", "0.1", - "Copyright (C) 1998-2002 By International Business Machines Corporation and others. All Rights Reserved.", - writtenBy, + "Copyright (C) 1998-2006 By International Business Machines Corporation and others. All Rights Reserved.", "A simple demo of the ICU LayoutEngine.", + writtenBy, + documentedBy, + "", NULL); gtk_widget_show(aboutBox); } -void notimpl(GtkObject *object, gpointer data) +void notimpl(GtkObject */*object*/, gpointer /*data*/) { gnome_ok_dialog("Not implemented..."); } gchar *prettyTitle(const gchar *path) { - gchar *name = g_basename(path); + const gchar *name = g_basename(path); gchar *title = g_strconcat("Gnome Layout Sample - ", name, NULL); return title; } -void openOK(GtkObject *object, gpointer data) +void openOK(GtkObject */*object*/, gpointer data) { GtkFileSelection *fileselection = GTK_FILE_SELECTION(data); GtkWidget *app = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(fileselection), "app")); @@ -110,7 +114,7 @@ void openOK(GtkObject *object, gpointer data) g_free(fileName); } -void openfile(GtkObject *object, gpointer data) +void openfile(GtkObject */*object*/, gpointer data) { GtkWidget *app = GTK_WIDGET(data); GtkWidget *fileselection; @@ -142,29 +146,29 @@ void openfile(GtkObject *object, gpointer data) gtk_main(); } -void newapp(GtkObject *object, gpointer data) +void newapp(GtkObject */*object*/, gpointer /*data*/) { GtkWidget *app = newSample("Sample.txt"); gtk_widget_show_all(app); } -void closeapp(GtkWidget *widget, gpointer data) +void closeapp(GtkWidget */*widget*/, gpointer data) { GtkWidget *app = GTK_WIDGET(data); closeSample(app); } -void shutdown(GtkObject *object, gpointer data) +void shutdown(GtkObject */*object*/, gpointer /*data*/) { gtk_main_quit(); } GnomeUIInfo fileMenu[] = { - GNOMEUIINFO_MENU_NEW_ITEM("_New Sample", - "Create a new Gnome Layout Sample", + GNOMEUIINFO_MENU_NEW_ITEM((gchar *) "_New Sample", + (gchar *) "Create a new Gnome Layout Sample", newapp, NULL), GNOMEUIINFO_MENU_OPEN_ITEM(openfile, NULL), @@ -183,12 +187,12 @@ GnomeUIInfo helpMenu[] = GnomeUIInfo mainMenu[] = { - GNOMEUIINFO_SUBTREE(N_("File"), fileMenu), - GNOMEUIINFO_SUBTREE(N_("Help"), helpMenu), + GNOMEUIINFO_SUBTREE(N_((gchar *) "File"), fileMenu), + GNOMEUIINFO_SUBTREE(N_((gchar *) "Help"), helpMenu), GNOMEUIINFO_END }; -gint eventDelete(GtkWidget *widget, GdkEvent *event, gpointer data) +gint eventDelete(GtkWidget *widget, GdkEvent */*event*/, gpointer /*data*/) { closeSample(widget); @@ -196,7 +200,7 @@ gint eventDelete(GtkWidget *widget, GdkEvent *event, gpointer data) return TRUE; } -gint eventConfigure(GtkWidget *widget, GdkEventConfigure *event, Context *context) +gint eventConfigure(GtkWidget */*widget*/, GdkEventConfigure *event, Context *context) { if (context->paragraph != NULL) { context->width = event->width; @@ -210,7 +214,7 @@ gint eventConfigure(GtkWidget *widget, GdkEventConfigure *event, Context *contex return TRUE; } -gint eventExpose(GtkWidget *widget, GdkEvent *event, Context *context) +gint eventExpose(GtkWidget *widget, GdkEvent */*event*/, Context *context) { if (context->paragraph != NULL) { gint maxLines = context->paragraph->getLineCount() - 1; @@ -225,57 +229,48 @@ gint eventExpose(GtkWidget *widget, GdkEvent *event, Context *context) GtkWidget *newSample(const gchar *fileName) { - gchar *title = NULL; - GtkWidget *app = NULL; - GtkWidget *area = NULL; Context *context = new Context(); context->width = 600; context->height = 400; context->paragraph = Paragraph::paragraphFactory(fileName, font, guiSupport); - if (context->paragraph != NULL) { - GtkStyle *style; - gchar *title = prettyTitle(fileName); - - app = gnome_app_new("gnomeLayout", title); + gchar *title = prettyTitle(fileName); + GtkWidget *app = gnome_app_new("gnomeLayout", title); - gtk_object_set_data(GTK_OBJECT(app), "context", context); + gtk_object_set_data(GTK_OBJECT(app), "context", context); - gtk_window_set_default_size(GTK_WINDOW(app), 600 - 24, 400); + gtk_window_set_default_size(GTK_WINDOW(app), 600 - 24, 400); - gnome_app_create_menus_with_data(GNOME_APP(app), mainMenu, app); + gnome_app_create_menus_with_data(GNOME_APP(app), mainMenu, app); - gtk_signal_connect(GTK_OBJECT(app), "delete_event", - GTK_SIGNAL_FUNC(eventDelete), NULL); + gtk_signal_connect(GTK_OBJECT(app), "delete_event", + GTK_SIGNAL_FUNC(eventDelete), NULL); - area = gtk_drawing_area_new(); - gtk_object_set_data(GTK_OBJECT(app), "area", area); + GtkWidget *area = gtk_drawing_area_new(); + gtk_object_set_data(GTK_OBJECT(app), "area", area); -#if 1 - style = gtk_style_copy(gtk_widget_get_style(area)); + GtkStyle *style = gtk_style_copy(gtk_widget_get_style(area)); - for (int i = 0; i < 5; i += 1) { - style->fg[i] = style->white; - } + for (int i = 0; i < 5; i += 1) { + style->fg[i] = style->white; + } - gtk_widget_set_style(area, style); -#endif + gtk_widget_set_style(area, style); - gnome_app_set_contents(GNOME_APP(app), area); + gnome_app_set_contents(GNOME_APP(app), area); - gtk_signal_connect(GTK_OBJECT(area), - "expose_event", - GTK_SIGNAL_FUNC(eventExpose), - context); + gtk_signal_connect(GTK_OBJECT(area), + "expose_event", + GTK_SIGNAL_FUNC(eventExpose), + context); - gtk_signal_connect(GTK_OBJECT(area), - "configure_event", - GTK_SIGNAL_FUNC(eventConfigure), - context); + gtk_signal_connect(GTK_OBJECT(area), + "configure_event", + GTK_SIGNAL_FUNC(eventConfigure), + context); - appList = g_slist_prepend(appList, app); - } + appList = g_slist_prepend(appList, app); g_free(title); @@ -304,37 +299,43 @@ void closeSample(GtkWidget *app) int main (int argc, char *argv[]) { LEErrorCode fontStatus = LE_NO_ERROR; - GtkWidget *app; + poptContext ptctx; + GtkWidget *app; - TT_Init_FreeType(&engine); + FT_Init_FreeType(&engine); - gnome_init("gnomelayout", "0.1", argc, argv); + gnome_init_with_popt_table("gnomelayout", "0.1", argc, argv, NULL, 0, &ptctx); guiSupport = new GnomeGUISupport(); fontMap = new GnomeFontMap(engine, "FontMap.Gnome", 24, guiSupport, fontStatus); font = new ScriptCompositeFontInstance(fontMap); if (LE_FAILURE(fontStatus)) { - TT_Done_FreeType(engine); + FT_Done_FreeType(engine); return 1; } - if (argc <= 1) { - app = newSample("Sample.txt"); - gtk_widget_show_all(app); - } else { - for (int i = 1; i < argc; i += 1) { - app = newSample(argv[i]); - gtk_widget_show_all(app); - } + const char *defaultArgs[] = {"Sample.txt", NULL}; + const char **args = poptGetArgs(ptctx); + + if (args == NULL) { + args = defaultArgs; } + for (int i = 0; args[i] != NULL; i += 1) { + app = newSample(args[i]); + + gtk_widget_show_all(app); + } + + poptFreeContext(ptctx); + gtk_main(); delete font; delete guiSupport; - TT_Done_FreeType(engine); + FT_Done_FreeType(engine); exit(0); }