Re: [gtkmm] Notebook trouble



Daniel,

I have something similar implemented for one of my GUIs.
TabWidget<> is the template class (attached).

You use it like this:
class MainWindow 
{
   void on_close_tab_window ();

   ...

   Gtk::Notebook* m_notebook;
};

MainWindow::MainWindow()
{
   ...
   /** This tab should be a widget with [x] self-destruction button
       in it. When clicked, it should wipe out this table and remove
       the tab.
    */
   irina::TabWidget<MainWindow>* tabw;
   tabw = manage (new irina::TabWidget<MainWindow> (*this, tbl_name_));
   m_notebook->prepend_page (*table, *tabw);
   m_notebook->set_current_page (m_notebook->page_num (*table));

   ...
}

And the callback:

void
MainWindow::
on_close_tab_window ()
{   
    /** Close current tab and release data structure.
     */

     int n = m_notebook->get_current_page ();
     CfgStatTbl* table = dynamic_cast<CfgStatTbl*> (m_notebook->get_nth_page(n));
     m_notebook->remove_page (n);

     ...
     delete table;
}


On Tue, Mar 16, 2004 at 08:22:26PM -0800, Daniel Pixley wrote:
> I have added a close button to my Notebook tabs in addition to a label
> (like Gedit). Both are added to a hbox, and then passed to the notebook
> dynamically using the Helpers class:
> 
> notebook1->pages().push_back(Gtk::Notebook_Helpers::TabElem(*scrolledwindow, *hbox));
> 
> How do I tell a close button what page to close when it is clicked?  I
> have tried using page_num() like this:
> 
> void window1::on_button1_clicked()  // every close button is given this
>  				    // signal before being added with 
>  				    // the Helper class.
> 
> {
> 	Glib::signal_switch_page();
> 	gint page = notebook1->page_num(*this);
> 	notebook1->remove_page(page);
> }
> 
> But this doesn't work I think because '*this' refers to the main window1
> object, and not the button.  How can I tell the button clicked signal
> which page to close?
> 
> Thanks,
> Dan
> 
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list

-- 
______________________________________________________
Vladislav Grinchenko    e-mail (w): vgrinche integ com
Software Engineer            (h): 3rdshift comcast net
Integral Systems, Inc.

   Focus on quality, and productivity will follow.
______________________________________________________
// -*- c++ -*-
//------------------------------------------------------------------------------
//                              TabWidget.h
//------------------------------------------------------------------------------
// $Id: TabWidget.h,v 1.3 2003/08/15 21:07:43 vlad Exp $
//------------------------------------------------------------------------------
// Date: Fri Aug  8 13:57:18 EDT 2003
//------------------------------------------------------------------------------

#ifndef TAB_WIDGET_H
#define TAB_WIDGET_H

#include <gtkmm/box.h>
#include <gtkmm/image.h>
#include <gtkmm/eventbox.h>
#include <gtkmm/label.h>
#include <gtkmm/stock.h>

/** @file TabWidget.h

    TabWidget is a tab for the Notebook page. It comes with the
	tab label and cancel button to close the tab. The template
    class is the calling class which suppose to have a callback
    member function on_close_tab_window() defined.

*/

namespace irina {
	
	template<class Client>
	class TabWidget : public Gtk::HBox
	{
	public:
		/** Constructor creates a managed HBox widget with
			label and cancel button inside. The widget is 
			mapped.

			@param client_ Reference to the calling client class
			@param label_ Tab label
		*/
		TabWidget (Client& client_, const std::string& label_);

		/** Callback that is called when user presses Close button.
		 */
		bool on_cancel_button_press (GdkEventButton* event_);

	private:
		/// Reference to the calling client
		Client& m_client;
	};

	template<class Client>
	inline 
	TabWidget<Client>::
	TabWidget (Client& client_, const std::string& label_)
		: m_client (client_)
	{
		Gtk::Image* image;
		image = manage (new Gtk::Image (Gtk::Stock::CLOSE, 
										Gtk::ICON_SIZE_SMALL_TOOLBAR));

		Gtk::EventBox* event_box = manage (new Gtk::EventBox);
		event_box->add (*image);
		event_box->set_events (Gdk::BUTTON_PRESS_MASK);
		event_box->signal_button_press_event ().connect (
			SigC::slot (*this, &TabWidget::on_cancel_button_press));

		std::string text (" " + label_ + " ");
		pack_start (*(manage (new Gtk::Label (label_))), 
					Gtk::PACK_EXPAND_WIDGET, 3);
		pack_start (*event_box, Gtk::PACK_SHRINK);
		show_all ();
	}

	template<class Client>
	inline bool
	TabWidget<Client>::
	on_cancel_button_press (GdkEventButton* /* event_ */)
	{
		m_client.on_close_tab_window ();
		return true;
	}

} // @end namespace

#endif /* TAB_WIDGET_H */  


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