/*\ * 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 #include #include "lb.h" #include "window.h" #include "text_window.h" void LB_INITGUI_0(LBContext *cxt) { LBDevice *dev = 0; dev = lb_register_dev(cxt, "window", "gui"); { dev->dev_type = LB_DEV_STREAM | LB_DEV_RDWR; dev->open = (LBDevOpen)&lb_open_window; dev->close = (LBDevClose)&lb_close_window; dev->eof = (LBDevEOF)&lb_eof_window; dev->read_str = (LBDevReadStr)&lb_read_window_str; dev->write_str = (LBDevWriteStr)&lb_write_window_str; dev->read_db = (LBDevReadDb)&lb_read_window_db; } dev = lb_register_dev(cxt, "text", "gui"); { dev->dev_type = LB_DEV_STREAM | LB_DEV_RDWR; dev->open = (LBDevOpen)&lb_open_window_text; dev->close = (LBDevClose)&lb_close_window; dev->eof = (LBDevEOF)&lb_eof_window; dev->read_str = (LBDevReadStr)&lb_read_window_str; dev->write_str = (LBDevWriteStr)&lb_write_window_text_str; dev->read_db = (LBDevReadDb)&lb_read_window_db; } dev = lb_register_dev(cxt, "text_nsb", "gui"); { dev->dev_type = LB_DEV_STREAM | LB_DEV_RDWR; dev->open = (LBDevOpen)&lb_open_window_text_nsb; dev->close = (LBDevClose)&lb_close_window; dev->eof = (LBDevEOF)&lb_eof_window; dev->read_str = (LBDevReadStr)&lb_read_window_str; dev->write_str = (LBDevWriteStr)&lb_write_window_text_str; dev->read_db = (LBDevReadDb)&lb_read_window_db; } dev = lb_register_dev(cxt, "button", "gui"); dev = lb_register_dev(cxt, "textbox", "gui"); { dev->dev_type = LB_DEV_STREAM | LB_DEV_RDWR; dev->read_str = (LBDevReadStr)&lb_read_window_str; dev->write_str = (LBDevWriteStr)&lb_write_textbox_str; } } LBString ret; void lb_fileselection_ok(GtkWidget *w, GtkFileSelection *fs) { ret = lbstr_str(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs))); gtk_widget_destroy(GTK_WIDGET(fs)); gtk_main_quit(); } void lb_fileselection_destroy(GtkWidget *w, gpointer data) { gtk_main_quit(); } void LB_FILEDIALOG_5(LBContext *cxt, LBString title, LBString filter, Variable *lvalue) { GtkWidget *file_widget; ret = 0; file_widget = gtk_file_selection_new(title->data); gtk_signal_connect(GTK_OBJECT (file_widget), "destroy", (GtkSignalFunc)lb_fileselection_destroy, &file_widget); gtk_signal_connect(GTK_OBJECT (GTK_FILE_SELECTION (file_widget)->ok_button), "clicked", (GtkSignalFunc) lb_fileselection_ok, file_widget); gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (file_widget)->cancel_button), "clicked", (GtkSignalFunc) gtk_widget_destroy, GTK_OBJECT (file_widget)); gtk_file_selection_set_filename (GTK_FILE_SELECTION(file_widget), filter->data); gtk_widget_show(file_widget); gtk_main(); if (ret) { lbstr_set(&(lvalue->data.str), ret); } lbstr_destroy(filter); lbstr_destroy(title); } void LB_NOTICE_1(LBContext *cxt, LBString str) { gnome_dialog_run(GNOME_DIALOG(gnome_message_box_new(str->data, GNOME_MESSAGE_BOX_INFO, "Ok", NULL))); lbstr_destroy(str); } void LB_CONFIRM_3(LBContext *cxt, LBString str, Variable *lvalue) { int ret = gnome_dialog_run(GNOME_DIALOG(gnome_message_box_new(str->data, GNOME_MESSAGE_BOX_INFO, "Yes", "No", NULL))); switch (ret) { case 0: lbstr_set(&(lvalue->data.str), lbstr_cstr("yes")); break; case 1: lbstr_set(&(lvalue->data.str), lbstr_cstr("no")); break; default: break; } lbstr_destroy(str); } void LB_BUTTON_11(LBContext *cxt, Variable *handle, LBString name, Label *label, char *corner, double _x, double _y) { char *ptr = handle->name->data; char *end; Variable *parent; LBGUI *gui; GtkWidget *button = gtk_button_new_with_label(name->data); gint16 x, y; if (!strcmp(corner, "UL")) { x = (gint16)_x; y = (gint16)_y; } else if (!strcmp(corner, "LL")) { x = (gint16)_x; y = (gint16)_y; } else if (!strcmp(corner, "UR")) { x = (gint16)_x; y = (gint16)_y; } else if (!strcmp(corner, "LR")) { x = (gint16)_x; y = (gint16)_y; } else { assert(0); } gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(lb_gtk_button_clicked), (gpointer)label); if (*ptr == '#') { end = lb_skip_symbol(ptr + 1); } else { end = lb_skip_symbol(ptr); } if (*end == '.') { LBString parent_name = lbstr_nstr(ptr, (end - ptr)); parent = lb_lookup_var(cxt, parent_name->data); assert(parent); } else { parent = handle; } if (!parent->data.hnd.dev && !parent->data.hnd.data) { gui = (LBGUI *)malloc(sizeof(LBGUI)); parent->data.hnd.data = gui; gui->w = 0; gui->c = gtk_fixed_new(); gui->queue = 0; } else { gui = (LBGUI *)parent->data.hnd.data; } gtk_fixed_put(GTK_FIXED(gui->c), button, (gint16)x, (gint16)y); gtk_widget_show(button); if (*end == '.') { handle->data.hnd.dev = lb_get_dev(cxt, "button"); handle->data.hnd.data = button; } lbstr_destroy(name); } void LB_BUTTON_15(LBContext *cxt, Variable *handle, LBString name, Label *label, char *corner, double _x, double _y, double width, double height) { char *ptr = handle->name->data; char *end; Variable *parent; LBGUI *gui; GtkWidget *button = gtk_button_new_with_label(name->data); gint16 x, y; gtk_widget_set_usize(button, (gint16)width, (gint16)height); if (!strcmp(corner, "UL")) { x = (gint16)_x; y = (gint16)_y; } else if (!strcmp(corner, "LL")) { x = (gint16)_x; y = (gint16)_y; } else if (!strcmp(corner, "UR")) { x = (gint16)_x; y = (gint16)_y; } else if (!strcmp(corner, "LR")) { x = (gint16)_x; y = (gint16)_y; } else { assert(0); } gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(lb_gtk_button_clicked), (gpointer)label); if (*ptr == '#') { end = lb_skip_symbol(ptr + 1); } else { end = lb_skip_symbol(ptr); } if (*end == '.') { LBString parent_name = lbstr_nstr(ptr, (end - ptr)); parent = lb_lookup_var(cxt, parent_name->data); assert(parent); } else { parent = handle; } if (!parent->data.hnd.dev && !parent->data.hnd.data) { gui = (LBGUI *)malloc(sizeof(LBGUI)); parent->data.hnd.data = gui; gui->w = 0; gui->c = gtk_fixed_new(); gui->queue = 0; } else { gui = (LBGUI *)parent->data.hnd.data; } gtk_fixed_put(GTK_FIXED(gui->c), button, (gint16)x, (gint16)y); gtk_widget_show(button); if (*end == '.') { handle->data.hnd.dev = lb_get_dev(cxt, "button"); handle->data.hnd.data = button; } lbstr_destroy(name); } void LB_TEXTBOX_9(LBContext *cxt, Variable *handle, double x, double y, double width, double height) { char *ptr = handle->name->data; char *end; Variable *parent; LBGUI *gui; GtkWidget *text = gtk_entry_new(); gtk_widget_set_usize(text, (gint16)width, (gint16)height); if (*ptr == '#') { end = lb_skip_symbol(ptr + 1); } else { end = lb_skip_symbol(ptr); } if (*end == '.') { LBString parent_name = lbstr_nstr(ptr, (end - ptr)); parent = lb_lookup_var(cxt, parent_name->data); assert(parent); } else { parent = handle; } if (!parent->data.hnd.dev && !parent->data.hnd.data) { gui = (LBGUI *)malloc(sizeof(LBGUI)); parent->data.hnd.data = gui; gui->w = 0; gui->c = gtk_fixed_new(); gui->queue = 0; } else { gui = (LBGUI *)parent->data.hnd.data; } gtk_fixed_put(GTK_FIXED(gui->c), text, (gint16)x, (gint16)y); gtk_widget_show(text); if (*end == '.') { GtkWidget *w = gui->w; gui = (LBGUI *)malloc(sizeof(LBGUI)); gui->w = w; gui->c = text; gui->queue = 0; handle->data.hnd.dev = lb_get_dev(cxt, "textbox"); handle->data.hnd.data = gui; } }