change/extend Tabbable API to allow for show/hide/attach/detach
This commit is contained in:
parent
73a22be077
commit
fd938d95bf
@ -46,6 +46,9 @@ class LIBGTKMM2EXT_API Tabbable : public WindowProxy {
|
|||||||
|
|
||||||
void add_to_notebook (Gtk::Notebook& notebook, const std::string& tab_title);
|
void add_to_notebook (Gtk::Notebook& notebook, const std::string& tab_title);
|
||||||
void make_visible ();
|
void make_visible ();
|
||||||
|
void make_invisible ();
|
||||||
|
void attach ();
|
||||||
|
void detach ();
|
||||||
|
|
||||||
Gtk::Widget& contents() const { return _contents; }
|
Gtk::Widget& contents() const { return _contents; }
|
||||||
|
|
||||||
@ -56,6 +59,8 @@ class LIBGTKMM2EXT_API Tabbable : public WindowProxy {
|
|||||||
bool has_own_window () const;
|
bool has_own_window () const;
|
||||||
bool is_tabbed () const;
|
bool is_tabbed () const;
|
||||||
|
|
||||||
|
void set_allow_hide (bool);
|
||||||
|
|
||||||
virtual void show_window ();
|
virtual void show_window ();
|
||||||
|
|
||||||
bool window_visible ();
|
bool window_visible ();
|
||||||
@ -83,9 +88,12 @@ class LIBGTKMM2EXT_API Tabbable : public WindowProxy {
|
|||||||
CairoIcon tab_close_image;
|
CairoIcon tab_close_image;
|
||||||
|
|
||||||
void show_tab ();
|
void show_tab ();
|
||||||
|
void hide_tab ();
|
||||||
void tab_close_clicked ();
|
void tab_close_clicked ();
|
||||||
|
void show_own_window (bool and_pack_it);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,17 +57,20 @@ Tabbable::~Tabbable ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Tabbable::set_allow_hide (bool yn)
|
||||||
|
{
|
||||||
|
if (yn) {
|
||||||
|
tab_close_image.show ();
|
||||||
|
} else {
|
||||||
|
tab_close_image.hide ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Tabbable::tab_close_clicked ()
|
Tabbable::tab_close_clicked ()
|
||||||
{
|
{
|
||||||
/* for this to happen, the tab must be visible so we
|
hide_tab ();
|
||||||
can assume that the contents are displayed in the
|
|
||||||
parent notebook
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (_parent_notebook) {
|
|
||||||
_parent_notebook->remove_page (_contents);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -147,26 +150,37 @@ Tabbable::get (bool create)
|
|||||||
return _window;
|
return _window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Tabbable::show_own_window (bool and_pack_it)
|
||||||
|
{
|
||||||
|
Gtk::Widget* parent = _contents.get_parent();
|
||||||
|
Gtk::Allocation alloc;
|
||||||
|
|
||||||
|
if (parent) {
|
||||||
|
alloc = parent->get_allocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
(void) use_own_window (and_pack_it);
|
||||||
|
|
||||||
|
if (parent) {
|
||||||
|
_window->set_default_size (alloc.get_width(), alloc.get_height());
|
||||||
|
}
|
||||||
|
|
||||||
|
_window->show_all ();
|
||||||
|
_window->present ();
|
||||||
|
}
|
||||||
|
|
||||||
Gtk::Notebook*
|
Gtk::Notebook*
|
||||||
Tabbable::tab_root_drop ()
|
Tabbable::tab_root_drop ()
|
||||||
{
|
{
|
||||||
Gtk::Allocation alloc;
|
|
||||||
|
|
||||||
alloc = _contents.get_parent()->get_allocation();
|
|
||||||
|
|
||||||
(void) use_own_window (false);
|
|
||||||
|
|
||||||
/* This is called after a drop of a tab onto the root window. Its
|
/* This is called after a drop of a tab onto the root window. Its
|
||||||
* responsibility is to return the notebook that this Tabbable's
|
* responsibility xois to return the notebook that this Tabbable's
|
||||||
* contents should be packed into before the drop handling is
|
* contents should be packed into before the drop handling is
|
||||||
* completed. It is not responsible for actually taking care of this
|
* completed. It is not responsible for actually taking care of this
|
||||||
* packing.
|
* packing.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_window->set_default_size (alloc.get_width(), alloc.get_height());
|
show_own_window (false);
|
||||||
_window->show_all ();
|
|
||||||
_window->present ();
|
|
||||||
|
|
||||||
return &_own_notebook;
|
return &_own_notebook;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,13 +196,46 @@ Tabbable::show_window ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
void
|
||||||
Tabbable::delete_event_handler (GdkEventAny *ev)
|
Tabbable::make_visible ()
|
||||||
{
|
{
|
||||||
Window* toplevel = dynamic_cast<Window*> (_contents.get_toplevel());
|
if (_window && (current_toplevel() == _window)) {
|
||||||
|
_window->present ();
|
||||||
|
} else {
|
||||||
|
show_tab ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (_window == toplevel) {
|
void
|
||||||
|
Tabbable::make_invisible ()
|
||||||
|
{
|
||||||
|
if (_window && (current_toplevel() == _window)) {
|
||||||
|
_window->hide ();
|
||||||
|
} else {
|
||||||
|
hide_tab ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Tabbable::detach ()
|
||||||
|
{
|
||||||
|
show_own_window (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Tabbable::attach ()
|
||||||
|
{
|
||||||
|
if (!_parent_notebook) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_parent_notebook->page_num (_contents) >= 0) {
|
||||||
|
/* already tabbed */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (_window && current_toplevel() == _window) {
|
||||||
/* unpack Tabbable from parent, put it back in the main tabbed
|
/* unpack Tabbable from parent, put it back in the main tabbed
|
||||||
* notebook
|
* notebook
|
||||||
*/
|
*/
|
||||||
@ -200,22 +247,20 @@ Tabbable::delete_event_handler (GdkEventAny *ev)
|
|||||||
/* leave the window around */
|
/* leave the window around */
|
||||||
|
|
||||||
_window->hide ();
|
_window->hide ();
|
||||||
|
|
||||||
if (_parent_notebook) {
|
|
||||||
|
|
||||||
_parent_notebook->append_page (_contents, _tab_box);
|
|
||||||
_parent_notebook->set_tab_detachable (_contents);
|
|
||||||
_parent_notebook->set_tab_reorderable (_contents);
|
|
||||||
_parent_notebook->set_current_page (_parent_notebook->page_num (_contents));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* don't let anything else handle this */
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* nothing to do */
|
_parent_notebook->append_page (_contents, _tab_box);
|
||||||
return false;
|
_parent_notebook->set_tab_detachable (_contents);
|
||||||
|
_parent_notebook->set_tab_reorderable (_contents);
|
||||||
|
_parent_notebook->set_current_page (_parent_notebook->page_num (_contents));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Tabbable::delete_event_handler (GdkEventAny *ev)
|
||||||
|
{
|
||||||
|
_window->hide();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@ -234,6 +279,14 @@ Tabbable::is_tabbed () const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Tabbable::hide_tab ()
|
||||||
|
{
|
||||||
|
if (_parent_notebook) {
|
||||||
|
_parent_notebook->remove_page (_contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Tabbable::show_tab ()
|
Tabbable::show_tab ()
|
||||||
{
|
{
|
||||||
@ -281,12 +334,3 @@ Tabbable::set_state (const XMLNode& node, int version)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
Tabbable::make_visible ()
|
|
||||||
{
|
|
||||||
if (_window && (current_toplevel() == _window)) {
|
|
||||||
_window->present ();
|
|
||||||
} else {
|
|
||||||
show_tab ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user