ICU-1428 Changes for multiple windows, open dialog.
X-SVN-Rev: 8022
This commit is contained in:
parent
c8e85a2174
commit
22cc595c26
@ -5,19 +5,33 @@
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
* file name: GnomeGUISupport.h
|
||||
* file name: GnomeGUISupport.cpp
|
||||
*
|
||||
* created on: 11/06/2001
|
||||
* created by: Eric R. Mader
|
||||
*/
|
||||
|
||||
#if 1
|
||||
#include <gnome.h>
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "GnomeGUISupport.h"
|
||||
|
||||
void GnomeGUISupport::postErrorMessage(const char *message, const char *title)
|
||||
{
|
||||
fprintf(stderr, "%s: %s\n", title, message);
|
||||
#if 1
|
||||
gchar *s;
|
||||
GtkWidget *error;
|
||||
|
||||
s = g_strconcat(title, ":\n", message, NULL);
|
||||
error = gnome_error_dialog(s);
|
||||
gtk_widget_show(error);
|
||||
g_free(s);
|
||||
#else
|
||||
fprintf(stderr, "%s: %s\n", title, message);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
/*
|
||||
****************************************************************************** *
|
||||
*
|
||||
@ -30,6 +31,22 @@
|
||||
|
||||
#define ARRAY_LENGTH(array) (sizeof array / sizeof array[0])
|
||||
|
||||
struct Context
|
||||
{
|
||||
long width;
|
||||
long height;
|
||||
Paragraph *paragraph;
|
||||
};
|
||||
|
||||
static TT_Engine engine;
|
||||
static GnomeGUISupport *guiSupport;
|
||||
static GnomeFontMap *fontMap;
|
||||
|
||||
static GSList *appList = NULL;
|
||||
|
||||
GtkWidget *newSample(const gchar *fileName);
|
||||
void closeSample(GtkWidget *sample);
|
||||
|
||||
void showabout(GtkWidget *widget, gpointer data)
|
||||
{
|
||||
GtkWidget *aboutBox;
|
||||
@ -38,9 +55,9 @@ void showabout(GtkWidget *widget, gpointer data)
|
||||
NULL
|
||||
};
|
||||
|
||||
aboutBox = gnome_about_new("Gnome Layout Demo",
|
||||
aboutBox = gnome_about_new("Gnome Layout Sample",
|
||||
"0.1",
|
||||
"Copyright (C) 1998-2001 By International Business Machines Corporation and others. All Rights Reserved.",
|
||||
"Copyright (C) 1998-2002 By International Business Machines Corporation and others. All Rights Reserved.",
|
||||
writtenBy,
|
||||
"A simple demo of the ICU LayoutEngine.",
|
||||
NULL);
|
||||
@ -53,6 +70,93 @@ void notimpl(GtkObject *object, gpointer data)
|
||||
gnome_ok_dialog("Not implemented...");
|
||||
}
|
||||
|
||||
gchar *prettyTitle(const gchar *path)
|
||||
{
|
||||
gchar *name = g_basename(path);
|
||||
gchar *title = g_strconcat("Gnome Layout Sample - ", name, NULL);
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
void openOK(GtkObject *object, gpointer data)
|
||||
{
|
||||
GtkFileSelection *fileselection = GTK_FILE_SELECTION(data);
|
||||
GtkWidget *app = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(fileselection), "app"));
|
||||
Context *context = (Context *) gtk_object_get_data(GTK_OBJECT(app), "context");
|
||||
gchar *fileName = g_strdup(gtk_file_selection_get_filename(fileselection));
|
||||
Paragraph *newPara;
|
||||
|
||||
gtk_widget_destroy(GTK_WIDGET(fileselection));
|
||||
|
||||
newPara = Paragraph::paragraphFactory(fileName, fontMap, guiSupport, NULL);
|
||||
|
||||
if (newPara != NULL) {
|
||||
gchar *title = prettyTitle(fileName);
|
||||
GtkWidget *area = GTK_WIDGET(gtk_object_get_data(GTK_OBJECT(app), "area"));
|
||||
|
||||
if (context->paragraph != NULL) {
|
||||
delete context->paragraph;
|
||||
}
|
||||
|
||||
context->paragraph = newPara;
|
||||
gtk_window_set_title(GTK_WINDOW(app), title);
|
||||
|
||||
gtk_widget_hide(area);
|
||||
context->paragraph->breakLines(context->width, context->height);
|
||||
gtk_widget_show_all(area);
|
||||
|
||||
g_free(title);
|
||||
}
|
||||
|
||||
g_free(fileName);
|
||||
}
|
||||
|
||||
void openfile(GtkObject *object, gpointer data)
|
||||
{
|
||||
GtkWidget *app = GTK_WIDGET(data);
|
||||
GtkWidget *fileselection;
|
||||
GtkWidget *okButton;
|
||||
GtkWidget *cancelButton;
|
||||
|
||||
fileselection =
|
||||
gtk_file_selection_new("Open File");
|
||||
|
||||
gtk_object_set_data(GTK_OBJECT(fileselection), "app", app);
|
||||
|
||||
okButton =
|
||||
GTK_FILE_SELECTION(fileselection)->ok_button;
|
||||
|
||||
cancelButton =
|
||||
GTK_FILE_SELECTION(fileselection)->cancel_button;
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT(fileselection), "destroy",
|
||||
GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT(okButton), "clicked",
|
||||
GTK_SIGNAL_FUNC(openOK), fileselection);
|
||||
|
||||
gtk_signal_connect_object(GTK_OBJECT(cancelButton), "clicked",
|
||||
GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(fileselection));
|
||||
|
||||
gtk_window_set_modal(GTK_WINDOW(fileselection), TRUE);
|
||||
gtk_widget_show(fileselection);
|
||||
gtk_main();
|
||||
}
|
||||
|
||||
void newapp(GtkObject *object, gpointer data)
|
||||
{
|
||||
GtkWidget *app = newSample("Sample.txt");
|
||||
|
||||
gtk_widget_show_all(app);
|
||||
}
|
||||
|
||||
void closeapp(GtkWidget *widget, gpointer data)
|
||||
{
|
||||
GtkWidget *app = GTK_WIDGET(data);
|
||||
|
||||
closeSample(app);
|
||||
}
|
||||
|
||||
void shutdown(GtkObject *object, gpointer data)
|
||||
{
|
||||
gtk_main_quit();
|
||||
@ -60,10 +164,15 @@ void shutdown(GtkObject *object, gpointer data)
|
||||
|
||||
GnomeUIInfo fileMenu[] =
|
||||
{
|
||||
GNOMEUIINFO_MENU_OPEN_ITEM(notimpl, NULL),
|
||||
GNOMEUIINFO_SEPARATOR,
|
||||
GNOMEUIINFO_MENU_EXIT_ITEM(shutdown, NULL),
|
||||
GNOMEUIINFO_END
|
||||
GNOMEUIINFO_MENU_NEW_ITEM("_New Sample",
|
||||
"Create a new Gnome Layout Sample",
|
||||
newapp, NULL),
|
||||
|
||||
GNOMEUIINFO_MENU_OPEN_ITEM(openfile, NULL),
|
||||
GNOMEUIINFO_SEPARATOR,
|
||||
GNOMEUIINFO_MENU_CLOSE_ITEM(closeapp, NULL),
|
||||
GNOMEUIINFO_MENU_EXIT_ITEM(shutdown, NULL),
|
||||
GNOMEUIINFO_END
|
||||
};
|
||||
|
||||
GnomeUIInfo helpMenu[] =
|
||||
@ -80,120 +189,154 @@ GnomeUIInfo mainMenu[] =
|
||||
GNOMEUIINFO_END
|
||||
};
|
||||
|
||||
struct Context
|
||||
{
|
||||
long width;
|
||||
long height;
|
||||
Paragraph *paragraph;
|
||||
};
|
||||
|
||||
gint eventDelete(GtkWidget *widget, GdkEvent *event, gpointer data)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
closeSample(widget);
|
||||
|
||||
gint eventDestroy(GtkWidget *widget, GdkEvent *event, Context *context)
|
||||
{
|
||||
shutdown(GTK_OBJECT(widget), context);
|
||||
return 0;
|
||||
// indicate that closeapp already destroyed the window
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gint eventConfigure(GtkWidget *widget, GdkEventConfigure *event, Context *context)
|
||||
{
|
||||
if (context->paragraph != NULL) {
|
||||
context->width = event->width;
|
||||
context->height = event->height;
|
||||
|
||||
if (context->width > 0 && context->height > 0) {
|
||||
context->paragraph->breakLines(context->width, context->height);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gint eventExpose(GtkWidget *widget, GdkEvent *event, Context *context)
|
||||
{
|
||||
if (context->paragraph != NULL) {
|
||||
gint maxLines = context->paragraph->getLineCount() - 1;
|
||||
gint firstLine = 0, lastLine = context->height / context->paragraph->getLineHeight();
|
||||
|
||||
context->paragraph->draw(widget, firstLine, (maxLines < lastLine)? maxLines : lastLine);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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, fontMap, guiSupport, NULL);
|
||||
|
||||
if (context->paragraph != NULL) {
|
||||
GtkStyle *style;
|
||||
gchar *title = prettyTitle(fileName);
|
||||
|
||||
app = gnome_app_new("gnomeLayout", title);
|
||||
|
||||
gtk_object_set_data(GTK_OBJECT(app), "context", context);
|
||||
|
||||
gtk_window_set_default_size(GTK_WINDOW(app), 600 - 24, 400);
|
||||
|
||||
gnome_app_create_menus_with_data(GNOME_APP(app), mainMenu, app);
|
||||
|
||||
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);
|
||||
|
||||
#if 1
|
||||
style = gtk_style_copy(gtk_widget_get_style(area));
|
||||
|
||||
for (int i = 0; i < 5; i += 1) {
|
||||
style->fg[i] =style->white;
|
||||
}
|
||||
|
||||
gtk_widget_set_style(area, style);
|
||||
#endif
|
||||
|
||||
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),
|
||||
"configure_event",
|
||||
GTK_SIGNAL_FUNC(eventConfigure),
|
||||
context);
|
||||
|
||||
appList = g_slist_prepend(appList, app);
|
||||
}
|
||||
|
||||
g_free(title);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
void closeSample(GtkWidget *app)
|
||||
{
|
||||
Context *context = (Context *) gtk_object_get_data(GTK_OBJECT(app), "context");
|
||||
|
||||
if (context->paragraph != NULL) {
|
||||
delete context->paragraph;
|
||||
}
|
||||
|
||||
delete context;
|
||||
|
||||
appList = g_slist_remove(appList, app);
|
||||
|
||||
gtk_widget_destroy(app);
|
||||
|
||||
if (appList == NULL) {
|
||||
gtk_main_quit();
|
||||
}
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
GtkWidget *app;
|
||||
GtkWidget *area;
|
||||
GtkStyle *style;
|
||||
unsigned short status = 0;
|
||||
Context context = {600, 400, NULL};
|
||||
TT_Engine engine;
|
||||
RFIErrorCode fontStatus = RFI_NO_ERROR;
|
||||
GtkWidget *app;
|
||||
|
||||
TT_Init_FreeType(&engine);
|
||||
|
||||
RFIErrorCode fontStatus = RFI_NO_ERROR;
|
||||
GnomeGUISupport *guiSupport = new GnomeGUISupport();
|
||||
GnomeFontMap *fontMap = new GnomeFontMap(engine, "FontMap.Gnome", 24, guiSupport, fontStatus);
|
||||
gnome_init("gnomelayout", "0.1", argc, argv);
|
||||
|
||||
guiSupport = new GnomeGUISupport();
|
||||
fontMap = new GnomeFontMap(engine, "FontMap.Gnome", 24, guiSupport, fontStatus);
|
||||
|
||||
if (LE_FAILURE(fontStatus)) {
|
||||
TT_Done_FreeType(engine);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// FIXME: is it cheating to pass NULL for surface, since we know that
|
||||
// GnomeFontInstance won't use it?
|
||||
context.paragraph = Paragraph::paragraphFactory("Sample.txt", fontMap, guiSupport, NULL);
|
||||
|
||||
if (context.paragraph != NULL) {
|
||||
gnome_init("gnomelayout", "1.0", argc, argv);
|
||||
app = gnome_app_new("gnomelayout", "Gnome Layout");
|
||||
|
||||
gtk_window_set_default_size(GTK_WINDOW(app), 600 - 24, 400);
|
||||
|
||||
gnome_app_create_menus(GNOME_APP(app), mainMenu);
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT(app),
|
||||
"delete_event",
|
||||
GTK_SIGNAL_FUNC(eventDelete),
|
||||
NULL);
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT(app),
|
||||
"destroy",
|
||||
GTK_SIGNAL_FUNC(eventDestroy),
|
||||
&context);
|
||||
|
||||
area = gtk_drawing_area_new();
|
||||
|
||||
#if 1
|
||||
style = gtk_style_copy(gtk_widget_get_style(area));
|
||||
|
||||
for (int i = 0; i < 5; i += 1) {
|
||||
style->fg[i] =style->white;
|
||||
}
|
||||
|
||||
gtk_widget_set_style(area, style);
|
||||
#if 0
|
||||
app = newSample("Sample.txt");
|
||||
gtk_widget_show_all(app);
|
||||
#else
|
||||
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);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
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),
|
||||
"configure_event",
|
||||
GTK_SIGNAL_FUNC(eventConfigure),
|
||||
&context);
|
||||
|
||||
gtk_widget_show_all(app);
|
||||
|
||||
gtk_main();
|
||||
|
||||
delete context.paragraph;
|
||||
}
|
||||
gtk_main();
|
||||
|
||||
delete fontMap;
|
||||
delete guiSupport;
|
||||
|
||||
TT_Done_FreeType(engine);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user