/*\ * libLB - The LBPP support library * Copyright (C) 2001 Anthony Liguori * * libLB is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * libLB is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA \*/ #include #include #include "lb.h" #include "text_window.h" int lb_open_window_text(LBContext *cxt, char *name, Variable *handle) { LBGUI *gui = malloc(sizeof(LBGUI)); Variable *width = lb_lookup_var(cxt, "WindowWidth"); Variable *height = lb_lookup_var(cxt, "WindowHeight"); Variable *x = lb_lookup_var(cxt, "UpperLeftX"); Variable *y = lb_lookup_var(cxt, "UpperLeftY"); GtkWidget *sw = gtk_scrolled_window_new(NULL, NULL); gui->w = gtk_window_new(GTK_WINDOW_TOPLEVEL); gui->c = gtk_text_new(NULL, NULL); gui->close_label = 0; gui->queue = 0; gtk_window_set_title(GTK_WINDOW(gui->w), name); gtk_container_add(GTK_CONTAINER(sw), gui->c); gtk_container_add(GTK_CONTAINER(gui->w), sw); if (width && height) { gtk_window_set_default_size(GTK_WINDOW(gui->w), (gint)width->data.db, (gint)height->data.db); } if (x && y) { gtk_window_set_position(GTK_WINDOW(gui->w), GTK_WIN_POS_CENTER); } gtk_signal_connect(GTK_OBJECT(gui->w), "delete_event", GTK_SIGNAL_FUNC(lb_gtk_delete), (gpointer)gui); gtk_signal_connect (GTK_OBJECT(gui->w), "destroy", GTK_SIGNAL_FUNC(lb_gtk_destroy), (gpointer)gui); gtk_text_set_editable(GTK_TEXT(gui->c), TRUE); gtk_widget_show(gui->c); gtk_widget_show(sw); gtk_widget_show(gui->w); handle->data.hnd.data = gui; return TRUE; } int lb_open_window_text_nsb(LBContext *cxt, char *name, Variable *handle) { LBGUI *gui = malloc(sizeof(LBGUI)); Variable *width = lb_lookup_var(cxt, "WindowWidth"); Variable *height = lb_lookup_var(cxt, "WindowHeight"); Variable *x = lb_lookup_var(cxt, "UpperLeftX"); Variable *y = lb_lookup_var(cxt, "UpperLeftY"); gui->w = gtk_window_new(GTK_WINDOW_TOPLEVEL); gui->c = gtk_text_new(NULL, NULL); gui->close_label = 0; gui->queue = 0; gtk_window_set_title(GTK_WINDOW(gui->w), name); gtk_container_add(GTK_CONTAINER(gui->w), gui->c); if (width && height) { gtk_window_set_default_size(GTK_WINDOW(gui->w), (gint)width->data.db, (gint)height->data.db); } if (x && y) { gtk_window_set_position(GTK_WINDOW(gui->w), GTK_WIN_POS_CENTER); } gtk_signal_connect(GTK_OBJECT(gui->w), "delete_event", GTK_SIGNAL_FUNC(lb_gtk_delete), (gpointer)gui); gtk_signal_connect (GTK_OBJECT(gui->w), "destroy", GTK_SIGNAL_FUNC(lb_gtk_destroy), (gpointer)gui); gtk_text_set_editable(GTK_TEXT(gui->c), TRUE); gtk_widget_show(gui->c); gtk_widget_show(gui->w); handle->data.hnd.data = gui; return TRUE; } int lb_write_window_text_str(LBContext *cxt, LBGUI *gui, LBString str) { char *ptr = str->data; char *end; ptr = lb_skip_space(ptr); if (*ptr == '!') { ptr++; end = lb_skip_symbol(ptr); if (!strncmp(ptr, "trapclose", (end - ptr)) && ((end - ptr) == 9)) { ptr = lb_skip_space(end); if (*ptr == '[') { ptr++; end = strchr(ptr, ']'); if (end) { if (gui->close_label) { lbstr_set(&(gui->close_label), lbstr_nstr(ptr, (end - ptr))); } else { gui->close_label = lbstr_nstr(ptr, (end - ptr)); } } } } else if (!strncmp(ptr, "cls", (end - ptr)) && ((end - ptr) == 3)) { gtk_editable_delete_text(GTK_EDITABLE(gui->c), 0, -1); } else if (!strncmp(ptr, "selectall", (end - ptr)) && ((end - ptr) == 9)) { gtk_editable_select_region(GTK_EDITABLE(gui->c), 0, -1); } else if (!strncmp(ptr, "origin?", (end - ptr) + 1) && ((end - ptr) == 6)) { GtkText *w = GTK_TEXT(gui->c); VarQ *q = malloc(sizeof(VarQ)); q->v = malloc(sizeof(Variable)); q->v->type = DOUBLE; q->v->data.db = (double)w->cursor_pos_x; q->next = malloc(sizeof(VarQ)); q->next->v = malloc(sizeof(Variable)); q->next->v->type = DOUBLE; q->next->v->data.db = (double)w->cursor_pos_y; q->next->next = gui->queue; gui->queue = q; } } else { gtk_text_insert(GTK_TEXT(gui->c), NULL, NULL, NULL, str->data, -1); } return str->size; } int lb_write_textbox_str(LBContext *cxt, LBGUI *gui, LBString str) { char *ptr = str->data; char *end; ptr = lb_skip_space(ptr); if (*ptr == '!') { ptr++; end = lb_skip_symbol(ptr); if (!strncmp(ptr, "contents?", (end - ptr) + 1) && ((end - ptr) == 8)) { VarQ *q = malloc(sizeof(VarQ)); q->v = malloc(sizeof(Variable)); q->v->type = STRING; q->v->data.str = lbstr_str(gtk_entry_get_text(GTK_ENTRY(gui->c))); q->next = gui->queue; gui->queue = q; } else if (!strncmp(ptr, "setfocus", (end - ptr)) && ((end - ptr) == 8)) { gtk_window_set_focus( GTK_WINDOW(gtk_widget_get_parent_window(gui->c)), gui->c); } } else { gtk_entry_set_text(GTK_ENTRY(gui->c), str->data); } return str->size; }