|
From: <ho...@us...> - 2004-02-03 21:30:20
|
Update of /cvsroot/ganc/ganc/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14434/src Modified Files: callbacks.c display.c interface.c main.c Log Message: Fixed initial size and resizing problems with gtk2 Index: callbacks.c =================================================================== RCS file: /cvsroot/ganc/ganc/src/callbacks.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** callbacks.c 20 Jan 2004 01:33:40 -0000 1.10 --- callbacks.c 3 Feb 2004 21:28:01 -0000 1.11 *************** *** 110,114 **** --- 110,119 ---- void on_button_exe_clicked (GtkWidget *button, gpointer user_data) { + int ww, wh; + ExpressionReady (); + + gtk_window_get_size (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (button))), &ww, &wh); + printf ("%d, %d\n", ww, wh); } Index: display.c =================================================================== RCS file: /cvsroot/ganc/ganc/src/display.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** display.c 20 Jan 2004 01:33:40 -0000 1.1 --- display.c 3 Feb 2004 21:28:01 -0000 1.2 *************** *** 10,17 **** #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> #include "include/defines.h" #include "include/functions.h" ! --- 10,19 ---- #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> + #include <gconf/gconf-client.h> + #include <pango/pango.h> #include "include/defines.h" #include "include/functions.h" ! #include "support.h" *************** *** 317,320 **** --- 319,327 ---- for (i= 0; i<num_sublines; ++i) { line[sublines[i]]= '\0'; + // ignore empty sublines + if (LineIsEmpty (line + start)) { + start= sublines[i] + 1; + continue; + } error= ParseTypedExpression (line + start); *************** *** 328,332 **** size+= strlen (parse_errors[perror - 1]); output_text= (char *) malloc (size); ! sprintf (output_text, "error: %s\n", parse_errors[perror - 1]); } else { size= 30; --- 335,340 ---- size+= strlen (parse_errors[perror - 1]); output_text= (char *) malloc (size); ! //sprintf (output_text, "error: %s\n", parse_errors[perror - 1]); ! sprintf (output_text, "%s\n", parse_errors[perror - 1]); } else { size= 30; *************** *** 334,339 **** size+= strlen (extra); output_text= (char *) malloc (size); ! sprintf (output_text, "error: %s: %s\n", ! parse_errors[perror - 1], extra); free (extra); } --- 342,347 ---- size+= strlen (extra); output_text= (char *) malloc (size); ! //sprintf (output_text, "error: %s: %s\n", parse_errors[perror - 1], extra); ! sprintf (output_text, "%s: %s\n", parse_errors[perror - 1], extra); free (extra); } *************** *** 375,378 **** --- 383,458 ---- + // + // sets geometry hints for display (minimum size, size increment) + // + void SetDisplayGeometryHints (GtkWindow *window) + { + GdkGeometry hints; + PangoLayout *playout; + PangoContext *pcontext; + int width, height; + int ww, wh; + + // pcontext belongs to widget, so we don't free it + pcontext= gtk_widget_get_pango_context (GTK_WIDGET (display)); + playout= pango_layout_new (pcontext); + pango_layout_set_text(playout, "X", 1); + pango_layout_get_pixel_size(playout, &width, &height); + g_object_unref (G_OBJECT (playout)); // free created playout + + // geometry hints + hints.base_width= 0; + hints.base_height= 0; + hints.width_inc= width; // x increment size + hints.height_inc= height; // y increment size + hints.min_width= 20*hints.width_inc; // min x size + hints.min_height= 4*hints.height_inc; // min y size + gtk_window_set_geometry_hints(window, GTK_WIDGET(display), &hints, + GDK_HINT_RESIZE_INC|GDK_HINT_MIN_SIZE| + GDK_HINT_BASE_SIZE);//|GDK_HINT_USER_SIZE); + + // copied from gnome-terminal source (terminal-window.c) + GtkRequisition toplevel_request; + GtkRequisition widget_request; + int w, h, xpad, ypad; + int grid_width, grid_height; + + gtk_widget_set_size_request (GTK_WIDGET (display), 2000, 2000); + gtk_widget_size_request (window, &toplevel_request); + gtk_widget_size_request (GTK_WIDGET (display), &widget_request); + + w= toplevel_request.width - widget_request.width; + h= toplevel_request.height - widget_request.height; + + grid_width= 30; + grid_height= 10; + + xpad= 0; + ypad= 0; + + w+= xpad + width * grid_width; + h+= ypad + height * grid_height; + + //gtk_window_resize (window, w, h); + gtk_window_set_default_size (window, w, h); + } + + + // + // get monospace font (terminal font) from gnome preferences (gconf) + // set font for display + // + void SetDisplayDefaultFont (void) + { + PangoFontDescription *monospace_font_desc; + GConfClient *conf_client; + + conf_client= gconf_client_get_default (); + monospace_font_desc= pango_font_description_from_string (gconf_client_get_string (conf_client, "/desktop/gnome/interface/monospace_font_name", NULL)); + gtk_widget_modify_font (display, monospace_font_desc); + pango_font_description_free (monospace_font_desc); + g_object_unref (G_OBJECT (conf_client)); // free conf_client + } + /* Index: interface.c =================================================================== RCS file: /cvsroot/ganc/ganc/src/interface.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** interface.c 20 Jan 2004 01:33:40 -0000 1.4 --- interface.c 3 Feb 2004 21:28:01 -0000 1.5 *************** *** 149,153 **** display = gtk_text_view_new (); ! gtk_widget_set_size_request (display, 250, 200); gtk_widget_show (display); gtk_container_add (GTK_CONTAINER (scrolledwindow1), display); --- 149,156 ---- display = gtk_text_view_new (); ! // don't quite understand how this size_request work ! // it seems to work fine as long as xsize and ysize are bigger than the ! // minimum size specified later with geometry hints ! //gtk_widget_set_size_request (display, -1, -1); gtk_widget_show (display); gtk_container_add (GTK_CONTAINER (scrolledwindow1), display); *************** *** 187,192 **** table1 = gtk_table_new (6, 7, TRUE); gtk_widget_show (table1); gtk_box_pack_start (GTK_BOX (vbox2), table1, FALSE, TRUE, 0); - button1 = make_empty_space (table1, 2, 3, 0, 1); button2 = make_empty_space (table1, 3, 4, 0, 1); --- 190,195 ---- table1 = gtk_table_new (6, 7, TRUE); gtk_widget_show (table1); + gtk_box_pack_start (GTK_BOX (vbox2), table1, FALSE, TRUE, 0); button1 = make_empty_space (table1, 2, 3, 0, 1); button2 = make_empty_space (table1, 3, 4, 0, 1); Index: main.c =================================================================== RCS file: /cvsroot/ganc/ganc/src/main.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** main.c 20 Jan 2004 01:33:40 -0000 1.9 --- main.c 3 Feb 2004 21:28:01 -0000 1.10 *************** *** 10,15 **** #ifdef BUILD_GUI #include <gtk/gtk.h> - #include <gconf/gconf-client.h> - #include <pango/pango-font.h> #include "callbacks.h" #include "support.h" --- 10,13 ---- *************** *** 96,101 **** // create interface window= create_window1 (); ! //TerminalSetGeometry (window); ! gtk_widget_show (window); // show main window // extract widgets --- 94,98 ---- // create interface window= create_window1 (); ! // extract widgets *************** *** 109,122 **** // get font from gnome preferences and set it ! { ! PangoFontDescription *monospace_font_desc; ! GConfClient *conf_client; - conf_client= gconf_client_get_default (); - monospace_font_desc= pango_font_description_from_string (gconf_client_get_string (conf_client, "/desktop/gnome/interface/monospace_font_name", NULL)); - gtk_widget_modify_font (display, monospace_font_desc); - pango_font_description_free (monospace_font_desc); - g_object_unref (G_OBJECT (conf_client)); - } display_text_buffer= gtk_text_view_get_buffer (GTK_TEXT_VIEW (display)); --- 106,116 ---- // get font from gnome preferences and set it ! SetDisplayDefaultFont(); ! ! // set geometry hints (min size, increment size) ! SetDisplayGeometryHints (GTK_WINDOW (window)); ! ! gtk_widget_show (window); // show main window display_text_buffer= gtk_text_view_get_buffer (GTK_TEXT_VIEW (display)); |