2007-11-28 14:19:36 +00:00
|
|
|
/* ASE - Allegro Sprite Editor
|
2010-02-01 21:25:40 +00:00
|
|
|
* Copyright (C) 2001-2010 David Capello
|
2007-11-28 14:19:36 +00:00
|
|
|
*
|
|
|
|
* 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; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <allegro.h>
|
2008-03-22 18:43:56 +00:00
|
|
|
#include <assert.h>
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2007-12-05 01:30:50 +00:00
|
|
|
#include "jinete/jinete.h"
|
|
|
|
#include "jinete/jintern.h"
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
#include "modules/gfx.h"
|
|
|
|
#include "modules/gui.h"
|
2009-11-21 20:02:31 +00:00
|
|
|
#include "modules/skinneable_theme.h"
|
2007-11-28 14:19:36 +00:00
|
|
|
#include "widgets/tabs.h"
|
|
|
|
|
2010-03-20 15:55:25 +00:00
|
|
|
#define ARROW_W (12*jguiscale())
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
#define HAS_ARROWS(tabs) ((jwidget_get_parent(m_button_left) == (tabs)))
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
static bool tabs_button_msg_proc(JWidget widget, JMessage msg);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
static int tabs_type()
|
2007-11-28 14:19:36 +00:00
|
|
|
{
|
2010-06-13 20:51:22 +00:00
|
|
|
static int type = 0;
|
|
|
|
if (!type)
|
|
|
|
type = ji_register_widget_type();
|
|
|
|
return type;
|
|
|
|
}
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
Tabs::Tabs(ITabsHandler* handler)
|
|
|
|
: Widget(tabs_type())
|
|
|
|
, m_handler(handler)
|
|
|
|
{
|
|
|
|
m_hot = NULL;
|
|
|
|
m_selected = NULL;
|
|
|
|
m_timer_id = jmanager_add_timer(this, 1000/60);
|
|
|
|
m_scroll_x = 0;
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
m_button_left = jbutton_new(NULL);
|
|
|
|
m_button_right = jbutton_new(NULL);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
setup_mini_look(m_button_left);
|
|
|
|
setup_mini_look(m_button_right);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
jbutton_set_bevel(m_button_left, 0, 0, 0, 0);
|
|
|
|
jbutton_set_bevel(m_button_right, 0, 0, 0, 0);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
jwidget_focusrest(m_button_left, false);
|
|
|
|
jwidget_focusrest(m_button_right, false);
|
|
|
|
|
|
|
|
add_gfxicon_to_button(m_button_left, GFX_ARROW_LEFT, JI_CENTER | JI_MIDDLE);
|
|
|
|
add_gfxicon_to_button(m_button_right, GFX_ARROW_RIGHT, JI_CENTER | JI_MIDDLE);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
jwidget_add_hook(m_button_left, tabs_type(), tabs_button_msg_proc, (void *)-1);
|
|
|
|
jwidget_add_hook(m_button_right, tabs_type(), tabs_button_msg_proc, (void *)+1);
|
2010-03-25 01:08:22 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
jwidget_init_theme(this);
|
|
|
|
}
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
Tabs::~Tabs()
|
|
|
|
{
|
|
|
|
std::vector<Tab*>::iterator it, end = m_list_of_tabs.end();
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
for (it = m_list_of_tabs.begin(); it != end; ++it)
|
|
|
|
delete *it; // tab
|
|
|
|
m_list_of_tabs.clear();
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
delete m_button_left; // widget
|
|
|
|
delete m_button_right; // widget
|
2008-02-29 19:29:49 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
jmanager_remove_timer(m_timer_id);
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
void Tabs::addTab(const char* text, void* data)
|
2007-11-28 14:19:36 +00:00
|
|
|
{
|
2009-11-21 20:02:31 +00:00
|
|
|
Tab *tab = new Tab(text, data);
|
2010-07-20 02:56:12 +00:00
|
|
|
tab->width = calcTabWidth(tab);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
m_list_of_tabs.push_back(tab);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
// Update scroll (in the same position if we can
|
|
|
|
setScrollX(m_scroll_x);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
jwidget_dirty(this);
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
void Tabs::removeTab(void* data)
|
2007-11-28 14:19:36 +00:00
|
|
|
{
|
2010-06-13 20:51:22 +00:00
|
|
|
Tab *tab = getTabByData(data);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
if (tab) {
|
2010-06-13 20:51:22 +00:00
|
|
|
if (m_hot == tab) m_hot = NULL;
|
|
|
|
if (m_selected == tab) m_selected = NULL;
|
2009-11-22 14:14:06 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
Vaca::remove_from_container(m_list_of_tabs, tab);
|
2009-11-21 20:02:31 +00:00
|
|
|
delete tab;
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
// Update scroll (in the same position if we can
|
|
|
|
setScrollX(m_scroll_x);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
jwidget_dirty(this);
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
void Tabs::setTabText(const char* text, void* data)
|
2007-11-28 14:19:36 +00:00
|
|
|
{
|
2010-06-13 20:51:22 +00:00
|
|
|
Tab *tab = getTabByData(data);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
if (tab) {
|
2010-06-13 20:51:22 +00:00
|
|
|
// Change text of the tab
|
2009-11-21 20:02:31 +00:00
|
|
|
tab->text = text;
|
2010-07-20 02:56:12 +00:00
|
|
|
tab->width = calcTabWidth(tab);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
// Make it visible (if it's the selected)
|
|
|
|
if (m_selected == tab)
|
|
|
|
makeTabVisible(tab);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
jwidget_dirty(this);
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
void Tabs::selectTab(void* data)
|
2007-11-28 14:19:36 +00:00
|
|
|
{
|
2010-06-13 20:51:22 +00:00
|
|
|
Tab *tab = getTabByData(data);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2008-02-29 19:29:49 +00:00
|
|
|
if (tab != NULL) {
|
2010-06-13 20:51:22 +00:00
|
|
|
m_selected = tab;
|
|
|
|
makeTabVisible(tab);
|
|
|
|
jwidget_dirty(this);
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
void* Tabs::getSelectedTab()
|
2008-02-29 19:29:49 +00:00
|
|
|
{
|
2010-06-13 20:51:22 +00:00
|
|
|
if (m_selected != NULL)
|
|
|
|
return m_selected->data;
|
2008-02-29 19:29:49 +00:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
int Tabs::getTimerId()
|
2007-11-28 14:19:36 +00:00
|
|
|
{
|
2010-06-13 20:51:22 +00:00
|
|
|
return m_timer_id;
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
bool Tabs::msg_proc(JMessage msg)
|
2007-11-28 14:19:36 +00:00
|
|
|
{
|
2010-06-13 20:51:22 +00:00
|
|
|
SkinneableTheme* theme = static_cast<SkinneableTheme*>(this->theme);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
switch (msg->type) {
|
|
|
|
|
|
|
|
case JM_REQSIZE:
|
2009-11-21 20:02:31 +00:00
|
|
|
msg->reqsize.w = 0; // msg->reqsize.h = 4 + jwidget_get_text_height(widget) + 5;
|
|
|
|
msg->reqsize.h =
|
|
|
|
theme->get_part(PART_TAB_FILLER)->h +
|
|
|
|
theme->get_part(PART_TAB_BOTTOM_NORMAL)->h;
|
2010-01-30 16:43:13 +00:00
|
|
|
return true;
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
case JM_SETPOS:
|
2010-06-13 20:51:22 +00:00
|
|
|
jrect_copy(this->rc, &msg->setpos.rect);
|
|
|
|
setScrollX(m_scroll_x);
|
2010-01-30 16:43:13 +00:00
|
|
|
return true;
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
case JM_DRAW: {
|
2010-06-13 20:51:22 +00:00
|
|
|
JRect rect = jwidget_get_rect(this);
|
|
|
|
JRect box = jrect_new(rect->x1-m_scroll_x, rect->y1,
|
|
|
|
rect->x1-m_scroll_x+2*jguiscale(),
|
2010-03-20 15:55:25 +00:00
|
|
|
rect->y1+theme->get_part(PART_TAB_FILLER)->h);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-04-24 01:36:40 +00:00
|
|
|
theme->draw_part_as_hline(ji_screen, box->x1, box->y1, box->x2-1, box->y2-1, PART_TAB_FILLER);
|
|
|
|
theme->draw_part_as_hline(ji_screen, box->x1, box->y2, box->x2-1, rect->y2-1, PART_TAB_BOTTOM_NORMAL);
|
2009-11-21 20:02:31 +00:00
|
|
|
|
|
|
|
box->x1 = box->x2;
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
// For each tab...
|
|
|
|
std::vector<Tab*>::iterator it, end = m_list_of_tabs.end();
|
|
|
|
|
|
|
|
for (it = m_list_of_tabs.begin(); it != end; ++it) {
|
|
|
|
Tab* tab = *it;
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
box->x2 = box->x1 + tab->width;
|
|
|
|
|
2010-07-20 02:56:12 +00:00
|
|
|
// Is the tab inside the bounds of the widget?
|
2007-11-28 14:19:36 +00:00
|
|
|
if (box->x1 < rect->x2 && box->x2 > rect->x1) {
|
2009-11-21 20:02:31 +00:00
|
|
|
int text_color;
|
|
|
|
int face_color;
|
|
|
|
|
2010-07-20 02:56:12 +00:00
|
|
|
// Selected
|
2010-06-13 20:51:22 +00:00
|
|
|
if (m_selected == tab) {
|
2009-11-21 20:02:31 +00:00
|
|
|
text_color = theme->get_tab_selected_text_color();
|
|
|
|
face_color = theme->get_tab_selected_face_color();
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
2010-07-20 02:56:12 +00:00
|
|
|
// Non-selected
|
2007-11-28 14:19:36 +00:00
|
|
|
else {
|
2009-11-21 20:02:31 +00:00
|
|
|
text_color = theme->get_tab_normal_text_color();
|
|
|
|
face_color = theme->get_tab_normal_face_color();
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
|
2010-04-24 01:36:40 +00:00
|
|
|
theme->draw_bounds_nw(ji_screen,
|
|
|
|
box->x1, box->y1, box->x2-1, box->y2-1,
|
2010-06-13 20:51:22 +00:00
|
|
|
(m_selected == tab) ? PART_TAB_SELECTED_NW:
|
2010-04-24 01:36:40 +00:00
|
|
|
PART_TAB_NORMAL_NW, face_color);
|
2009-11-21 20:02:31 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
if (m_selected == tab) {
|
2010-04-24 01:36:40 +00:00
|
|
|
theme->draw_bounds_nw(ji_screen,
|
|
|
|
box->x1, box->y2, box->x2-1, rect->y2-1,
|
|
|
|
PART_TAB_BOTTOM_SELECTED_NW,
|
|
|
|
theme->get_tab_selected_face_color());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
theme->draw_part_as_hline(ji_screen,
|
|
|
|
box->x1, box->y2, box->x2-1, rect->y2-1, PART_TAB_BOTTOM_NORMAL);
|
|
|
|
}
|
2009-11-21 20:02:31 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
jdraw_text(this->getFont(), tab->text.c_str(),
|
2010-03-20 15:55:25 +00:00
|
|
|
box->x1+4*jguiscale(),
|
2010-06-13 20:51:22 +00:00
|
|
|
(box->y1+box->y2)/2-text_height(this->getFont())/2+1,
|
2010-03-08 02:42:41 +00:00
|
|
|
text_color, face_color, false, jguiscale());
|
2010-07-20 02:56:12 +00:00
|
|
|
|
|
|
|
#ifdef CLOSE_BUTTON_IN_EACH_TAB
|
|
|
|
BITMAP* close_icon = theme->get_part(PART_WINDOW_CLOSE_BUTTON_NORMAL);
|
|
|
|
set_alpha_blender();
|
|
|
|
draw_trans_sprite(ji_screen, close_icon,
|
|
|
|
box->x2-4*jguiscale()-close_icon->w,
|
|
|
|
(box->y1+box->y2)/2-close_icon->h/2+1*jguiscale());
|
|
|
|
#endif
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
box->x1 = box->x2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill the gap to the right-side */
|
|
|
|
if (box->x1 < rect->x2) {
|
2010-04-24 01:36:40 +00:00
|
|
|
theme->draw_part_as_hline(ji_screen, box->x1, box->y1, rect->x2-1, box->y2-1, PART_TAB_FILLER);
|
|
|
|
theme->draw_part_as_hline(ji_screen, box->x1, box->y2, rect->x2-1, rect->y2-1, PART_TAB_BOTTOM_NORMAL);
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
jrect_free(rect);
|
|
|
|
jrect_free(box);
|
2010-01-30 16:43:13 +00:00
|
|
|
return true;
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case JM_MOUSEENTER:
|
|
|
|
case JM_MOTION:
|
2010-06-13 20:51:22 +00:00
|
|
|
calculateHot();
|
2010-01-30 16:43:13 +00:00
|
|
|
return true;
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
case JM_MOUSELEAVE:
|
2010-06-13 20:51:22 +00:00
|
|
|
if (m_hot != NULL) {
|
|
|
|
m_hot = NULL;
|
|
|
|
jwidget_dirty(this);
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
2010-01-30 16:43:13 +00:00
|
|
|
return true;
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
case JM_BUTTONPRESSED:
|
2010-06-13 20:51:22 +00:00
|
|
|
if (m_hot != NULL) {
|
|
|
|
if (m_selected != m_hot) {
|
|
|
|
m_selected = m_hot;
|
|
|
|
jwidget_dirty(this);
|
2009-11-22 14:14:06 +00:00
|
|
|
}
|
2008-10-16 02:19:00 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
if (m_selected && m_handler)
|
|
|
|
m_handler->clickTab(this,
|
|
|
|
m_selected->data,
|
|
|
|
msg->mouse.flags);
|
2009-11-22 14:14:06 +00:00
|
|
|
}
|
2010-01-30 16:43:13 +00:00
|
|
|
return true;
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
case JM_WHEEL: {
|
2010-06-13 20:51:22 +00:00
|
|
|
int dx = (jmouse_z(1) - jmouse_z(0)) * jrect_w(this->rc)/6;
|
|
|
|
setScrollX(m_scroll_x+dx);
|
2010-01-30 16:43:13 +00:00
|
|
|
return true;
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
|
2008-01-03 23:22:04 +00:00
|
|
|
case JM_TIMER: {
|
2010-06-13 20:51:22 +00:00
|
|
|
int dir = jmanager_get_capture() == m_button_left ? -1: 1;
|
|
|
|
setScrollX(m_scroll_x + dir*8*msg->timer.count);
|
2008-01-03 23:22:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-29 19:29:49 +00:00
|
|
|
case JM_SIGNAL:
|
|
|
|
if (msg->signal.num == JI_SIGNAL_SET_FONT) {
|
2010-06-13 20:51:22 +00:00
|
|
|
std::vector<Tab*>::iterator it, end = m_list_of_tabs.end();
|
2008-02-29 19:29:49 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
for (it = m_list_of_tabs.begin(); it != end; ++it) {
|
|
|
|
Tab* tab = *it;
|
2010-07-20 02:56:12 +00:00
|
|
|
tab->width = calcTabWidth(tab);
|
2008-02-29 19:29:49 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-22 18:43:56 +00:00
|
|
|
else if (msg->signal.num == JI_SIGNAL_INIT_THEME) {
|
|
|
|
/* setup the background color */
|
2010-06-13 20:51:22 +00:00
|
|
|
jwidget_set_bg_color(this, ji_color_face());
|
2008-03-22 18:43:56 +00:00
|
|
|
}
|
2008-02-29 19:29:49 +00:00
|
|
|
break;
|
|
|
|
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
return Widget::msg_proc(msg);
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
Tabs::Tab* Tabs::getTabByData(void* data)
|
2007-11-28 14:19:36 +00:00
|
|
|
{
|
2010-06-13 20:51:22 +00:00
|
|
|
std::vector<Tab*>::iterator it, end = m_list_of_tabs.end();
|
2008-03-22 18:43:56 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
for (it = m_list_of_tabs.begin(); it != end; ++it) {
|
|
|
|
Tab* tab = *it;
|
2007-11-28 14:19:36 +00:00
|
|
|
if (tab->data == data)
|
|
|
|
return tab;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
int Tabs::getMaxScrollX()
|
2007-11-28 14:19:36 +00:00
|
|
|
{
|
2010-06-13 20:51:22 +00:00
|
|
|
std::vector<Tab*>::iterator it, end = m_list_of_tabs.end();
|
2007-11-28 14:19:36 +00:00
|
|
|
int x = 0;
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
for (it = m_list_of_tabs.begin(); it != end; ++it) {
|
|
|
|
Tab* tab = *it;
|
2007-11-28 14:19:36 +00:00
|
|
|
x += tab->width;
|
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
x -= jrect_w(this->rc);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
if (x < 0)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return x + ARROW_W*2;
|
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
void Tabs::makeTabVisible(Tab* make_visible_this_tab)
|
2007-11-28 14:19:36 +00:00
|
|
|
{
|
|
|
|
int x = 0;
|
2010-06-13 20:51:22 +00:00
|
|
|
int extra_x = getMaxScrollX() > 0 ? ARROW_W*2: 0;
|
|
|
|
std::vector<Tab*>::iterator it, end = m_list_of_tabs.end();
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
for (it = m_list_of_tabs.begin(); it != end; ++it) {
|
|
|
|
Tab* tab = *it;
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
if (tab == make_visible_this_tab) {
|
2010-06-13 20:51:22 +00:00
|
|
|
if (x - m_scroll_x < 0) {
|
|
|
|
setScrollX(x);
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
2010-06-13 20:51:22 +00:00
|
|
|
else if (x + tab->width - m_scroll_x > jrect_w(this->rc) - extra_x) {
|
|
|
|
setScrollX(x + tab->width - jrect_w(this->rc) + extra_x);
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
x += tab->width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
void Tabs::setScrollX(int scroll_x)
|
2007-11-28 14:19:36 +00:00
|
|
|
{
|
2010-06-13 20:51:22 +00:00
|
|
|
int max_x = getMaxScrollX();
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
scroll_x = MID(0, scroll_x, max_x);
|
2010-06-13 20:51:22 +00:00
|
|
|
if (m_scroll_x != scroll_x) {
|
|
|
|
m_scroll_x = scroll_x;
|
|
|
|
calculateHot();
|
|
|
|
jwidget_dirty(this);
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
// We need scroll buttons?
|
2007-11-28 14:19:36 +00:00
|
|
|
if (max_x > 0) {
|
2010-06-13 20:51:22 +00:00
|
|
|
// Add childs
|
|
|
|
if (!HAS_ARROWS(this)) {
|
|
|
|
jwidget_add_child(this, m_button_left);
|
|
|
|
jwidget_add_child(this, m_button_right);
|
|
|
|
jwidget_dirty(this);
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* disable/enable buttons */
|
2010-07-03 18:26:27 +00:00
|
|
|
m_button_left->setEnabled(m_scroll_x > 0);
|
|
|
|
m_button_right->setEnabled(m_scroll_x < max_x);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
/* setup the position of each button */
|
|
|
|
{
|
2010-06-13 20:51:22 +00:00
|
|
|
JRect rect = jwidget_get_rect(this);
|
2007-11-28 14:19:36 +00:00
|
|
|
JRect box = jrect_new(rect->x2-ARROW_W*2, rect->y1,
|
|
|
|
rect->x2-ARROW_W, rect->y2-2);
|
2010-06-13 20:51:22 +00:00
|
|
|
jwidget_set_rect(m_button_left, box);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
jrect_moveto(box, box->x1+ARROW_W, box->y1);
|
2010-06-13 20:51:22 +00:00
|
|
|
jwidget_set_rect(m_button_right, box);
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
jrect_free(box);
|
|
|
|
jrect_free(rect);
|
|
|
|
}
|
|
|
|
}
|
2010-06-13 20:51:22 +00:00
|
|
|
// Remove buttons
|
|
|
|
else if (HAS_ARROWS(this)) {
|
|
|
|
jwidget_remove_child(this, m_button_left);
|
|
|
|
jwidget_remove_child(this, m_button_right);
|
|
|
|
jwidget_dirty(this);
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
void Tabs::calculateHot()
|
2007-11-28 14:19:36 +00:00
|
|
|
{
|
2010-06-13 20:51:22 +00:00
|
|
|
JRect rect = jwidget_get_rect(this);
|
|
|
|
JRect box = jrect_new(rect->x1-m_scroll_x, rect->y1, 0, rect->y2-1);
|
2007-11-28 14:19:36 +00:00
|
|
|
Tab *hot = NULL;
|
2010-06-13 20:51:22 +00:00
|
|
|
std::vector<Tab*>::iterator it, end = m_list_of_tabs.end();
|
2007-11-28 14:19:36 +00:00
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
// For each tab
|
|
|
|
for (it = m_list_of_tabs.begin(); it != end; ++it) {
|
|
|
|
Tab* tab = *it;
|
2007-11-28 14:19:36 +00:00
|
|
|
|
|
|
|
box->x2 = box->x1 + tab->width;
|
|
|
|
|
|
|
|
if (jrect_point_in(box, jmouse_x(0), jmouse_y(0))) {
|
|
|
|
hot = tab;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
box->x1 = box->x2;
|
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
if (m_hot != hot) {
|
|
|
|
m_hot = hot;
|
|
|
|
|
|
|
|
if (m_handler)
|
|
|
|
m_handler->mouseOverTab(this, m_hot ? m_hot->data: NULL);
|
|
|
|
|
|
|
|
jwidget_dirty(this);
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
2008-02-10 12:36:00 +00:00
|
|
|
|
|
|
|
jrect_free(rect);
|
|
|
|
jrect_free(box);
|
2007-11-28 14:19:36 +00:00
|
|
|
}
|
2010-06-13 20:51:22 +00:00
|
|
|
|
2010-07-20 02:56:12 +00:00
|
|
|
int Tabs::calcTabWidth(Tab* tab)
|
|
|
|
{
|
|
|
|
int border = 4*jguiscale();
|
|
|
|
#ifdef CLOSE_BUTTON_IN_EACH_TAB
|
|
|
|
SkinneableTheme* theme = static_cast<SkinneableTheme*>(this->theme);
|
|
|
|
int close_icon_w = theme->get_part(PART_WINDOW_CLOSE_BUTTON_NORMAL)->w;
|
|
|
|
return (border + text_length(getFont(), tab->text.c_str()) + border + close_icon_w + border);
|
|
|
|
#else
|
|
|
|
return (border + text_length(getFont(), tab->text.c_str()) + border);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-06-13 20:51:22 +00:00
|
|
|
static bool tabs_button_msg_proc(JWidget widget, JMessage msg)
|
|
|
|
{
|
|
|
|
JWidget parent;
|
|
|
|
Tabs* tabs = NULL;
|
|
|
|
|
|
|
|
parent = jwidget_get_parent(widget);
|
|
|
|
if (parent)
|
|
|
|
tabs = dynamic_cast<Tabs*>(parent);
|
|
|
|
|
|
|
|
switch (msg->type) {
|
|
|
|
|
|
|
|
case JM_SIGNAL:
|
|
|
|
if (msg->signal.num == JI_SIGNAL_BUTTON_SELECT) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (msg->signal.num == JI_SIGNAL_DISABLE) {
|
|
|
|
assert(tabs != NULL);
|
|
|
|
|
2010-07-03 18:03:26 +00:00
|
|
|
if (widget->isSelected()) {
|
2010-06-13 20:51:22 +00:00
|
|
|
jmanager_stop_timer(tabs->getTimerId());
|
2010-07-03 18:03:26 +00:00
|
|
|
widget->setSelected(false);
|
2010-06-13 20:51:22 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JM_BUTTONPRESSED:
|
|
|
|
assert(tabs != NULL);
|
|
|
|
jmanager_start_timer(tabs->getTimerId());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JM_BUTTONRELEASED:
|
|
|
|
assert(tabs != NULL);
|
|
|
|
jmanager_stop_timer(tabs->getTimerId());
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|