clist question about column->width



I am trying to get a list of entries to line up under a
clist.  To do this I am reading the width from the column
like this:
 new_width = clist -> column [ column ] .  width;
    
This variable doesn't seem to be initialized when the clist
is created. I don't see it change until the column width is
reset. Is this a bug or should I be accessing this data a different
way.

Another question. I only get a resize_column signal for the column
to the left of the button I adjusted. Weren't both the left and
right columns resized. And you get a resize_column for the last row
even though it is not actually resized. Is this correct behavior.

I have attached gtk-- code that illustrates what I am talking about.
If someone likes, I will struggle to convert it to straight gtk+.

thanks,
Todd.
-- 
   | Todd Dukes                      E-MAIL:  tdukes@ibmoto.com |
   | Motorola Somerset                  Phone:   (512) 424-8008 |
   | 6200 Bridgepoint Parkway Building #4 MS OE70               |
   | Austin, Texas 78730                                        |
/*
 g++ -o clistEntry  -I. `gtk-config --cflags` `gtkmm-config --cflags ` `gtk-config --libs` `gtkmm-config --libs` clistEntry.C
 */

#undef	G_LOG_DOMAIN

#include "strstream.h"

#include "gtk--.h"

#define TRACE_LINE cout << __FILE__ << ":" << __LINE__ << endl

static bool gtkmm_idle_update = false;

static gint
clearIdle () 
{
  gtkmm_idle_update = true;
  return 1;
}

static void
gtkmm_update ()
{
  Connection conn = connect_to_function ( Gtk_Main::idle (), clearIdle );
  gtkmm_idle_update = false;

  while ( !gtkmm_idle_update )
    Gtk_Main::instance () -> iteration ();

  conn . disconnect ();
}

/*
**
**  TestFixture 
**
*/

class TestFixture : public Gtk_Window 
{
public:
  virtual void destroyTest () = 0;
  Signal1 < TestFixture * > finished;

protected:
           TestFixture ();
  virtual ~TestFixture ();
  void     packControlArea ();
  // data
  Gtk_VBox            vbox;
  Gtk_VBox            actionArea;
  Gtk_VBox            controlArea;
  Gtk_HSeparator      separator;
  Gtk_Button          closeButton;
};

TestFixture::TestFixture () :
  vbox ( false, 0 ),
  actionArea ( false, 10 ),
  controlArea ( false, 10 ), 
  closeButton ( "close" )
{
  add ( &vbox );
  vbox . set_border_width ( 0 );
  vbox . pack_start ( actionArea );
  actionArea . set_border_width ( 10 );
  connect_to_signal ( destroy, finished, this ); 
};

TestFixture::~TestFixture () 
{
}

void
TestFixture::packControlArea () 
{
  vbox . pack_start ( separator, false, true, 0 );
  controlArea . set_border_width ( 10 );
  vbox . pack_start ( controlArea, false, true, 0 );
  controlArea . show ();
  connect_to_signal ( closeButton . clicked, finished, this );
  controlArea . pack_start ( closeButton, true, true, 0 );
  closeButton . set_flags ( GTK_CAN_DEFAULT );
  closeButton . grab_default ();
  closeButton . show ();
};


/*
 * GtkCTree
 */

class CListEntry : public TestFixture 
{
public:
  static TestFixture *  create ();
  virtual              ~CListEntry () { };
  virtual void          destroyTest () { delete theTest; theTest = 0; }
private:
                        CListEntry ();
  // functions

  void columnWasResized ( gint column, gint width );
  void printStats ();
  int idlePrintStats ();

  // data
  static char *title[];
  static CListEntry * theTest;
  static int numCListEntryColumns;

  Connection idleConn;
  Gtk_CList clist;
  Gtk_Widget *entryWidgets[2];
  Gtk_HBox  hbox;
  
};

CListEntry * CListEntry::theTest = 0;


TestFixture*
CListEntry::create () 
{
  if ( theTest == 0 ) 
    {
      theTest = new CListEntry ();
      return theTest;
    }
  return 0;
}
    
int CListEntry::numCListEntryColumns = 2;
char * CListEntry::title[] = { "Column 1" , "Column 2" };

CListEntry::CListEntry () :
  clist ( numCListEntryColumns, title )
{
  set_title ( "CListEntry test" );
  set_border_width ( 0 );

  actionArea . pack_start ( clist );

  entryWidgets [ 0 ] = new Gtk_Entry;
  entryWidgets [ 1 ] = new Gtk_Entry;

  for ( int i = 0 ; i < numCListEntryColumns; i ++ )
    hbox . pack_start ( manage ( entryWidgets [ i ] ), false, false );

  actionArea . pack_start ( hbox );
  
  vector < string > text;

  for ( int i = 0; i < numCListEntryColumns; i++ )
    {
      strstream ss;
      ss << i << ends;
      string s  = "column ";

      text . push_back ( s + ss . str () );
    }
  
  clist . append ( text );
  clist . append ( text );
  clist . append ( text );

  connect_to_method ( clist . resize_column, this, 
		      &CListEntry::columnWasResized );

  
  packControlArea ();
  show_all ();
}


/*
 * Main Window and Exit
 */


typedef  TestFixture * ( * TestFunc ) ();

struct TestTest 
{

  string   buttonLabel;
  TestFunc f;

} testToTest [] = { { "clist and entry", &CListEntry::create }

};

typedef list < Gtk_Widget * > PL_Gtk_Widget;

class MainWindow : public Gtk_Window 
{
public:
  MainWindow ();
  void testFinished ( TestFixture * testWindow );
private:
  /* test fixtures */
  void buttonClicked( int n);
  /* main window data */
  Gtk_VBox           vbox;
  Gtk_VBox           testFixturesBox;
  Gtk_VBox           closeButtonBox;
  Gtk_ScrolledWindow scrolled_window;
  Gtk_Button         *button;
  Gtk_Label          label;
  string             buffer;
  Gtk_HSeparator     separator;
  Gtk_Button         closeButton;
  PL_Gtk_Widget      deletableChildren;
};

MainWindow::MainWindow ():
  // main window data
  vbox ( false, 0 ),
  testFixturesBox ( false, 0 ),
  closeButtonBox ( false, 10 ), 
  button ( 0 ),
  closeButton ( "close" )
{

  set_policy ( FALSE, FALSE, FALSE );
  set_name ( "main window" );
  set_usize ( 200, 400 );
  set_uposition ( 20, 20 );
  connect_to_method ( destroy, Gtk_Main::instance (), &( Gtk_Main::quit ) );
  // what does this do? How can I connect it?
  //  connect_to_function( delete_event, gtk_false);
  //  gtk_signal_connect (GTK_OBJECT (window), "delete-event",
  //		      GTK_SIGNAL_FUNC (gtk_false),
  //		      NULL);
  add ( &vbox );
  {

    strstream ss;

    if ( gtkmm_micro_version > 0 )
      {
	ss << "Gtk-- v" 
	   << gtkmm_major_version << "."
	   << gtkmm_minor_version << "."
	   << gtkmm_micro_version << ends;
      } 
    else 
      {
	ss << "Gtk-- v"
	   << gtkmm_major_version << "."
	   << gtkmm_minor_version << ends;
      }
    buffer = ss . str ();
  } // end scope of ss
  label . set_text ( buffer );
  vbox . pack_start ( label, false, false, 0 );

  scrolled_window . set_border_width ( 10 );
  scrolled_window . set_policy ( GTK_POLICY_AUTOMATIC, 
				 GTK_POLICY_AUTOMATIC );
  vbox . pack_start ( scrolled_window, true, true, 0 );
  testFixturesBox . set_border_width ( 10 );
  scrolled_window . add_with_viewport ( testFixturesBox );
  
  const Gtk_Adjustment * adj = scrolled_window.get_vadjustment();

  if ( adj )
    {
      testFixturesBox . set_focus_vadjustment ( *adj );
    } 
  else
    {
      cout << "testgtk-- warning: scrolled_window.get_vadjustment() returned 0" << endl;
    }
  testFixturesBox . show ();

  int numberOfTest = sizeof ( testToTest ) / sizeof ( TestTest );

  for ( int n = 0; n < numberOfTest; n++ )
    {

      Gtk_Button * pb = new Gtk_Button ( testToTest [ n ] . buttonLabel );

      deletableChildren . push_back ( pb );
      testFixturesBox . pack_start ( *pb );
      connect_to_method ( pb -> clicked, this, &( MainWindow::buttonClicked ), n );
    }
  vbox . pack_start ( separator, false );
  closeButtonBox . set_border_width ( 10 );
  vbox . pack_start ( closeButtonBox, false );
  connect_to_method ( closeButton . clicked, Gtk_Main::instance (), &Gtk_Main::quit );
  closeButtonBox . pack_start ( closeButton );
  closeButton . set_flags ( GTK_CAN_DEFAULT );
  closeButton . grab_default ();
  show_all ();
}

void 
MainWindow::testFinished ( TestFixture * testWindow )
{ 
  testWindow->hide();
  testWindow->destroyTest();
}

void
MainWindow::buttonClicked ( int n )
{
  TestFixture * testFixture;
  testFixture = testToTest [ n ] . f ();
  if ( testFixture ) 
    connect_to_method ( testFixture -> finished, this, &MainWindow::testFinished );

}

int 
main ( int argc, char *argv [] )
{
  Gtk_Main m ( &argc, &argv );
  MainWindow mainWindow;
  
  mainWindow . show ();
  m . run ();

  return 0;
}

gint
CListEntry::idlePrintStats ()
{
  printStats ();
  idleConn . disconnect ();
  return 1;
}

void
CListEntry::printStats ()
{
  cout << "clist's total width is " << clist . width () << endl;

  for ( int i = 0; i < numCListEntryColumns; i++ )
    {
      cout << "column " << i << " width is " 
	   << clist . get_column_width ( i )
	   << endl;
    }
  for ( int i = 0; i < numCListEntryColumns; i++ )
    {
      cout << "widget " << i << " width is " 
	   << entryWidgets [ i ] -> width ()
	   << endl;
    }
}

void
CListEntry::columnWasResized ( gint column, gint width )
{
  cout << "column " << column << " was resized to " << width << endl;
  for ( int i = 0; i < numCListEntryColumns; i++ )
    {
      cout << "widget " << i << " width is " 
	   << entryWidgets [ i ] -> width ()
	   << endl;
    }

  entryWidgets [ column ] -> set_usize ( width, -1 );

  printStats ();

  cout << "run idlePrintStats " << endl;

  idleConn = connect_to_method ( Gtk_Main::idle (), this, idlePrintStats );  
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]