/*\ * 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 "window.h" int event; LBGUI *obj; Label *label; gint lb_gtk_delete(GtkWidget *w, GdkEvent *e, gpointer data) { LBGUI *gui = (LBGUI *)data; if (gui->close_label) { event = LB_GUI_CLOSE; obj = gui; gtk_main_quit(); return (TRUE); } return (FALSE); } void lb_gtk_destroy(GtkWidget *w, gpointer data) { if (gtk_main_level() > 0) { gtk_main_quit(); } } int lb_open_window(LBContext *cxt, char *name, Variable *handle) { LBGUI *gui; 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"); if (handle->data.hnd.data) { gui = (LBGUI *)handle->data.hnd.data; } else { gui = malloc(sizeof(LBGUI)); gui->c = gtk_fixed_new(); gui->queue = 0; } gui->w = gtk_window_new(GTK_WINDOW_TOPLEVEL); gui->close_label = 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) { // Well, I'm relatively new to GTK+ stuff so I'm not terribly sure how // to position a window absolutely without doing a mouse hack so // for now, we'll be broken :( // MARK: Fixme 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_widget_show(gui->c); gtk_widget_show(gui->w); return TRUE; } void lb_close_window(LBContext *cxt, LBGUI *gui) { gtk_widget_destroy(gui->w); if (gui->close_label) { lbstr_destroy(gui->close_label); } free(gui); } int lb_eof_window(LBContext *cxt, LBGUI *gui) { return 0; } LBString lb_read_window_str(LBContext *cxt, LBGUI *gui, size_t size) { LBString ret; if (!gui->queue) { event = 0; label = 0; obj = 0; gtk_main(); if (event) { switch(event) { case LB_GUI_CLOSE: label = lb_lookup_label(cxt, obj->close_label->data); case LB_GUI_GOTO: if (label) { longjmp(label->jmp, 1); } break; default: break; } } ret = lbstr_cstr(""); } else { VarQ *q = gui->queue; if (q->v->type != STRING) { LB_NOTICE_1(cxt, lbstr_cstr("Wrong type reqested in read operation")); LB_END_0(cxt); } ret = q->v->data.str; gui->queue = q->next; free(q->v); free(q); } return ret; } int lb_write_window_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)); } } } } return str->size; } double lb_read_window_db(LBContext *cxt, LBGUI *gui) { double ret = 0; if (!gui->queue) { event = 0; label = 0; obj = 0; gtk_main(); if (event) { switch(event) { case LB_GUI_CLOSE: label = lb_lookup_label(cxt, obj->close_label->data); case LB_GUI_GOTO: if (label) { longjmp(label->jmp, 1); } break; default: break; } } } else { VarQ *q = gui->queue; if (q->v->type != DOUBLE) { LB_NOTICE_1(cxt, lbstr_cstr("Wrong type reqested in read operation")); LB_END_0(cxt); } ret = q->v->data.db; gui->queue = q->next; free(q->v); free(q); } return ret; } void lb_gtk_button_clicked(GtkWidget *w, gpointer data) { event = LB_GUI_GOTO; label = (Label *)data; gtk_main_quit(); }