1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of the
* License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef _LF_TABVIEW_H_
#define _LF_TABVIEW_H_
#include "lf_view.h"
#include "mforms/tabview.h"
namespace mforms
{
namespace gtk
{
class TabViewImpl : public ViewImpl
{
Gtk::Notebook *_nb;
virtual Gtk::Widget *get_outer() const { return _nb; }
protected:
TabViewImpl(::mforms::TabView *self, ::mforms::TabViewType tabType)
: ViewImpl(self)
{
_nb = Gtk::manage(new Gtk::Notebook());
if (tabType == mforms::TabViewTabless)
{
_nb->set_show_tabs(false);
_nb->set_show_border(false);
}
_nb->set_scrollable(true);
_nb->signal_switch_page().connect(sigc::mem_fun(this, &TabViewImpl::tab_changed));
_nb->show();
}
void tab_changed(GtkNotebookPage*, guint)
{
TabView* tv = dynamic_cast< TabView* >(owner);
if (tv)
(*tv->signal_tab_changed())();
}
static bool create(::mforms::TabView *self, mforms::TabViewType tabtype)
{
return new TabViewImpl(self, tabtype) != 0;
}
static void set_active_tab(::mforms::TabView *self, int index)
{
TabViewImpl* cb= self->get_data<TabViewImpl>();
if ( cb)
{
cb->_nb->set_current_page(index);
}
}
static int get_active_tab(::mforms::TabView *self)
{
TabViewImpl* cb= self->get_data<TabViewImpl>();
return cb ? cb->_nb->get_current_page() : -1;
}
static int add_page(::mforms::TabView *self, ::mforms::View *page, const std::string& caption)
{
int page_index_after_insert = -1;
TabViewImpl* cb= self->get_data<TabViewImpl>();
if ( cb)
{
ViewImpl *widget_wrapper = page->get_data<ViewImpl>();
if ( widget_wrapper )
{
Gtk::Label *label= Gtk::manage(new Gtk::Label(caption));
widget_wrapper->get_outer()->set_data("TabViewLabel", label);
page_index_after_insert = cb->_nb->append_page(*widget_wrapper->get_outer(), *label);
label->show();
widget_wrapper->get_outer()->show();
}
}
return page_index_after_insert;
}
static void remove_page(::mforms::TabView *self, ::mforms::View *page)
{
TabViewImpl* cb= self->get_data<TabViewImpl>();
if ( cb)
{
ViewImpl *widget_wrapper = page->get_data<ViewImpl>();
if ( widget_wrapper )
{
cb->_nb->remove_page(*widget_wrapper->get_outer());
}
}
}
static void set_tab_title(::mforms::TabView* self,int tab,const std::string& title)
{
TabViewImpl* cb= self->get_data<TabViewImpl>();
if (cb)
{
Gtk::Widget *page= cb->_nb->get_nth_page(tab);
if (page)
{
Gtk::Label *label = reinterpret_cast<Gtk::Label*>(page->get_data("TabViewLabel"));
if (label)
{
label->set_text(title);
}
}
}
}
public:
static void init()
{
::mforms::ControlFactory *f = ::mforms::ControlFactory::get_instance();
f->_tabview_impl.create = &TabViewImpl::create;
f->_tabview_impl.get_active_tab = &TabViewImpl::get_active_tab;
f->_tabview_impl.set_active_tab = &TabViewImpl::set_active_tab;
f->_tabview_impl.add_page = &TabViewImpl::add_page;
f->_tabview_impl.remove_page = &TabViewImpl::remove_page;
f->_tabview_impl.set_tab_title = &TabViewImpl::set_tab_title;
}
};
};
};
#endif
|