I have been struggling to understand how tables work, and have created a
simple program whose behaviour demonatrates my mystification.
The program in its entirety, is below.
There is one part of the program that may be compiled or left uncompiled
depending on whether one writes
#if 0
or
#if 1
Call the first of these "variant 1" and the second "variant 2".
My understanding of what this is supposed to do is as follows:
1. Create a non-resizable window that is 640x400 pixels in size
2. Create a table with 80 columns and 25 rows
3. Put the table into the window
4. Create and populate a couple of textviews with some short text.
Variant 1 of the program displays one of the textviews.
Variant 2 displays both textviews.
What I don't understand:
There is one textview that appears in both variants. Why does its width
change in the two versions ... the width of the "1234*" textview is larger
in variant 2 than in variant 1. Why?
Similarly, the enclosing window is wider in variant 2 than in variant 1. Why?
In both cases, the increase in width is not desired (nor expected --
obviously there's some part of the documentation that I've missed or
misinterpreted); how do I stop it from occurring?
Here is the program:
----
/*
* gtk-test-1.cpp
*
*/
#include <gtkmm.h>
using namespace std;
using namespace Gdk;
using namespace Gtk;
int main(int argc, char *argv[])
{ const int N_ROWS = 25;
const int N_COLS = 80;
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 400;
Gtk::Main INIT(argc, argv); // needed to init gtkmm
Gtk::Window window; // the initial window
// the table into which we will place textviews
Gtk::Table table(N_ROWS, N_COLS, true);
// set the main window to the desired size and make it non-resizable
window.set_size_request(SCREEN_WIDTH, SCREEN_HEIGHT);
window.set_resizable(false);
// we want no space in the table
table.set_row_spacings(0);
table.set_col_spacings(0);
// add the table to the window
window.add(table);
window.show_all_children();
// create and populate two textviews
Gtk::TextView * textview_p1 = new Gtk::TextView;
Gtk::TextView * textview_p2 = new Gtk::TextView;
Gtk::TextView& textview1 = *textview_p1;
Gtk::TextView& textview2 = *textview_p2;
Pango::FontDescription fdesc("Courier New, medium, 12");
textview1.override_font(fdesc);
textview2.override_font(fdesc);
// first textview -- width depends on whether second textview is present
textview1.override_color(RGBA("White"));
textview1.override_background_color(RGBA("Black"));
textview1.set_editable(false);
textview1.set_cursor_visible(false);
textview1.get_buffer()->set_text("1234*");
table.show();
table.attach(textview1, 30, 35, 3, 4); // left, right+1, top, bottom+1
table.show_all_children();
// second textview
// variant 1 does not compile the following code; variant 2 does compile it
// the size of the window that contains the text "1234*" varies depending
// on which variant we execute
#if 0
textview2.override_color(RGBA("White"));
textview2.override_background_color(RGBA("Black"));
textview2.set_editable(false);
textview2.set_cursor_visible(false);
textview2.get_buffer()->set_text("5678*");
table.attach(textview2, 20, 32, 2, 3); // left, right+1, top, bottom+1
table.show();
table.show_all_children();
#endif // 0
INIT.run(window); // draw the window and its contents
return EXIT_SUCCESS;
}
----
Doc
--
Web: http://www.sff.net/people/N7DR
Attachment:
signature.asc
Description: OpenPGP digital signature