Re: [gtkmm] beginner´s question



Thx for your help...

> What are "guiRef" and "m_TreeBrowerBox"?

The class ConstraintGui represents my main window.
The main window should hold a notebook with a table
ConstraintGui::m_TableBox and a tree browser, the
ConstraintGui::m_TreeBrowserBox.

- A Tree Browser Box is created by the constructor
  of class ConstraintTypesBrowser.
- A Table Box is created by the constructor of class
  ConstraintTable.

I must find a way to assign the created boxes to
ConstraintGui::m_TableBox and ConstraintGui::m_TreeBrowserBox.
ConstraintTypesBrowser and ConstraintTable are friend classes
to ConstraintGui.

The point is, I want to create every widget of my main window
in a separate class. ConstraintGui::showGui puts every widget
together.

guiRef is a reference to ConstraintGui (my main window).
I need a reference to this class because I want to assign
the created boxes to the class members of ConstraintGui::m_TableBox
and ConstraintGui::m_TreeBrowserBox.



main.cpp:
int main(int argc, char **argv)
{
   // Init GUI
   Gtk::Main kit(argc, argv);

   // Create GUI
   ConstraintGui cGui;           // main window = notebook with table + tree browser
   ConstraintTable cTable(cGui); // table
   ConstraintTypesBrowser cTypesBrowser(cGui); // tree browser
   cGui.showGui(); // put all into a box and show it

   // Shows the window and returns when it is closed.
   Gtk::Main::run(cGui);

   return 0;
}


ConstraintGui.cpp:
void ConstraintGui::showGui()
{
   std::cout << "START ConstraintGui::showGui()" << std::endl;

   // Create boxes and widgets on main window
   Gtk::VBox       *VBoxLeft   = Gtk::manage(new Gtk::VBox(false, 2));
   Gtk::VBox       *VBoxRight  = Gtk::manage(new Gtk::VBox(false, 2));
   Gtk::VBox       *MainBox    = Gtk::manage(new Gtk::VBox(false, 2));
   Gtk::HBox       *HWidgetBox = Gtk::manage(new Gtk::HBox(false, 2));
   Gtk::HButtonBox *ButtonBox  = Gtk::manage(new Gtk::HButtonBox());
   Gtk::Notebook   *Notebook   = Gtk::manage(new Gtk::Notebook());
   Gtk::Button     *QButton    = Gtk::manage(new Gtk::Button("Quit"));

   // Add MainBox to the main window container
   add(*MainBox);

   // Add Tree Browser to VBoxLeft
   // More widgets for VBoxLeft will come ...
   VBoxLeft->pack_start(m_TreeBrowserBox);

   // Add Table to VBoxRight
   // More widgets for VBoxRight will come ...
   VBoxRight->pack_start(m_TableBox);

   // Add the Notebook and the Quit button to the MainBox
   Notebook->set_border_width(10);
   MainBox->pack_start(*Notebook);
   ButtonBox->pack_start(*QButton, Gtk::PACK_SHRINK);
   MainBox->pack_start(*ButtonBox, Gtk::PACK_SHRINK);
   // Connect Quit-Button to signal handler
   QButton->signal_clicked().connect(SigC::slot(*this, &ConstraintGui::on_button_quit));

   // Add VBoxLeft and VBoxRight to HWidgetBox
   HWidgetBox->pack_start(*VBoxLeft);
   HWidgetBox->pack_start(*VBoxRight);

   m_TreeBrowserBox.show_all();
   m_TableBox.show_all();
   HWidgetBox->show_all();
   MainBox->show_all();

   // Add box with all my widgets to the Notebook page
   Notebook->append_page(*HWidgetBox, "Constraints #1");

   std::cout << "END   ConstraintGui::showGui()" << std::endl;
}


ConstraintGui.h:

   //## Constraint Gui = Main Window
   class ConstraintGui : public Gtk::Window {

   public:
     ConstraintGui();

     virtual ~ConstraintGui();

     ConstraintGui& operator=(const ConstraintGui& right);

	void showGui();

	friend class ConstraintTypesBrowser;
	friend class ConstraintTable;

   private:
	Gtk::VBox m_TreeBrowserBox;
	Gtk::VBox m_TableBox;

   protected:
	// Signal handlers:
	virtual void on_button_quit();


   }; // class


ConstraintTypesBrowser.cpp:

// Creates the TreeBrowser Box I want to assign to ConstraintGui::m_TreeBrowserBox
ConstraintTypesBrowser::ConstraintTypesBrowser(
  const ConstraintGui &guiRef,
  :
  m_Frame("ConstraintTypes:")
{
  cout << "START ConstraintTypesBrowser()" << endl;

  // Add the TreeView, inside a ScrolledWindow
  m_ScrolledWindow.add(m_TreeView);
  // Only show the scrollbars when they are necessary
  m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);

  // Add the ScrolledWindow with the TreeView to frame
  m_Frame.add(m_ScrolledWindow);

  // ??????
  // ?????? How can I do this properly???
  guiRef.m_TreeBrowserBox.pack_start(m_Frame);

  // Create the Tree model:
  m_refTreeModel = Gtk::TreeStore::create(m_Columns);
  m_TreeView.set_model(m_refTreeModel);

  // All the items can be reordered with drag-and-drop
  m_TreeView.set_reorderable();

  // Filling rows (snipped)
  ....

  // Add the TreeView's view columns:
  m_TreeView.append_column("Constraint Scope", m_Columns.m_col_scope);
  m_TreeView.append_column("Constraint Type", m_Columns.m_col_cName);

  // To find out what row the user has selected (single selection)
  m_TreeSelection = m_TreeView.get_selection();

  // Connect callback for change of selection
  m_TreeSelection->signal_changed().connect(SigC::slot(*this, &ConstraintTypesBrowser::selectedRowCallback));

  cout << "END   ConstraintTypesBrowser()" << endl;
}


ConstraintTable.cpp:

// Creates the table box I want to assign to ConstraintGui::m_TableBox
ConstraintTable::ConstraintTable(const ConstraintGui& guiRef)
{
  cout << "START ConstraintTable::ConstraintTable()" << endl;

  // Create a Table and put it inside a ScrolledWindow
  // Gtk::ScrolledWindow *scrolledWin = Gtk::manage(new Gtk::ScrolledWindow());
  Gtk::Table          *table       = Gtk::manage(new Gtk::Table (10, 10, FALSE));

  Gtk::VBox*VBox = Gtk::manage(new Gtk::VBox(false, 2));
  VBox->pack_start(*table);

  // ?????? How can I do this properly???
  guiRef.m_TableBox = *VBox;

  for(int i = 0; i < 10; i++)
  {
     for(int j = 0; j < 10; j++)
	 {
	   Gtk::Button* pButton = Gtk::manage(new Gtk::ToggleButton("button"));
	   table->attach(*pButton, i, i + 1, j, j + 1);
     }
  }

  cout << "END   ConstraintTable::ConstraintTable()" << endl;
}






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