Re: [gtkmm] TreeModelColumn associated with a TreeViewColumn ?



Daniel Elstner wrote:
On Fre, 2003-01-10 at 00:22, Jarek Dukat wrote:
On Thu, 2003-01-09 at 22:38, Liza Klerck wrote:
How do I retrieve the Gtk::TreeViewColumn associated with a 
Gtk::TreeModelColumn after the TreeViewColumn has already been created ?
Liza, have you tried looking at Gtkmm TreeView docs? It is all there...
http://gtkmm.sourceforge.net/gtkmm2/docs/reference/html/classGtk_1_1TreeView.html

TreeViewColumn* TreeView::get_column (int n);
CellRenderer* TreeView::get_column_cell_renderer (int n);
Glib::ListHandle<TreeViewColumn*> TreeView::get_columns ();
And const versions of these methods of course.

Well, that's actually not what she wants. The int n denotes the view
column index, not the model column index.

Liza, I think it's a bad idea to try to retrieve the view column from
the model column. It breaks the model/view separation, and I can't
imagine a situation where it might be useful. Could you tell us what
your code is about? That would help to find an appropriate way to do
it.

--Daniel


Ok here is an example of why I need to know which Gtk::TreeModelColumn is accociated with a specific Gtk::TreeViewColumn:

Let's say I have a treeview with 3 columns column_a, column_b and column_c;
I register for button_press_events in the TreeView so that when a user presses the mouse button in the column_b I want to call function do_column_b(row)
when he clicks in column_c I want to call function do_column_c(row)  

void do_column_b(Gtk::TreeModel::Row &row)
{   .....   }

void do_column_c(Gtk::TreeModel::Row &row)
{   .....  }

class ModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
 ModelColumns()  {   add(m_col_a); add(m_col_b);    add(m_col_c);   add(m_col_visible);  }
 Gtk::TreeModelColumn<string> m_col_a;
 Gtk::TreeModelColumn<double> m_col_b;
 Gtk::TreeModelColumn<double> m_col_c;
 Gtk::TreeModelColumn<bool> m_col_visible;   };

ModelColumns m_Columns;
Gtk::TreeView m_TreeView;
Glib::RefPtr<Gtk::TreeStore> m_refTreeModel;

m_refTreeModel = Gtk::TreeStore::create(m_Columns);
m_TreeView.set_model(m_refTreeModel);

// Append the column
m_TreeView.append_column("A", m_Columns.m_col_a);
m_TreeView.append_column("B", m_Columns.m_col_b);
m_TreeView.append_column("C", m_Columns.m_col_c);

// I register to receive a callback for button press events in the treeview.
m_TreeView.add_events(Gdk::BUTTON_PRESS_MASK);
m_TreeView.signal_button_press_event().connect(  SigC::slot(*this, &ExampleWindow::on_m_TreeView_button_press), false );

bool  ExampleWindow::on_m_TreeView_button_press(GdkEventButton *eventbutton)
{
 Gtk::TreeModel::Path  path;
 Gtk::TreeViewColumn*  column;
 int cell_x;
 int cell_y;
  Gtk::TreeModel::Row row;

 // catch mouse button1 clicks
 switch (eventbutton->type)
 {
     case GDK_BUTTON_PRESS:
     if ( eventbutton->button == 1)
       {
         if (m_TreeView.get_path_at_pos(eventbutton->x, eventbutton->y,  path, column, cell_x, cell_y ))
         {  
            // Get the row number
            int row_num = *path.get_indices().begin();             
            row = *( m_refTreeModel->children[row_num - 1]);   

            // Get the column number
            int column_number = -1;
            while (column != treeView->get_column(column_number))
            column_number)++;
          }

          // So at this point I have a Gtk::TreeViewColumn, and a column number and a row and a row number but programatically I still don't know
          // if the user clicked on [column b] or [column c] 
          // Thus I need to know which Gtk::TreeModelColumn was accociated with column  at creation time
          //  So something like this where "Column B" and "Column C" is the part I need
          if (column == "Column B")
          {
              do_function_b(row);
          }
          if (column == "Column C")
          {
              do_function_c(row);
          }
      }
  return false;
}

I hope this example explains better what I am trying to do - I am still pretty new at Gtk2.
Thanks !
Liza



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