Replace jwidget_get/set_theme with Widget::get/setTheme.

This commit is contained in:
David Capello 2011-01-21 18:08:25 -03:00
parent e9f7a035b1
commit 74b7442ae4
27 changed files with 90 additions and 100 deletions

View File

@ -1115,7 +1115,7 @@ static void anieditor_draw_layer(JWidget widget, JRect clip, int layer_index)
static void anieditor_draw_layer_padding(JWidget widget)
{
SkinTheme* theme = static_cast<SkinTheme*>(widget->theme);
SkinTheme* theme = static_cast<SkinTheme*>(widget->getTheme());
AniEditor* anieditor = anieditor_data(widget);
int layer_index = anieditor->nlayers-1;
int x1, y1, x2, y2;
@ -1138,7 +1138,7 @@ static void anieditor_draw_layer_padding(JWidget widget)
static void anieditor_draw_cel(JWidget widget, JRect clip, int layer_index, int frame)
{
SkinTheme* theme = static_cast<SkinTheme*>(widget->theme);
SkinTheme* theme = static_cast<SkinTheme*>(widget->getTheme());
AniEditor* anieditor = anieditor_data(widget);
Layer *layer = anieditor->layers[layer_index];
bool selected_layer = (layer == anieditor->sprite->getCurrentLayer());

View File

@ -88,9 +88,9 @@ bool ButtonBase::onProcessMessage(JMessage msg)
case JM_DRAW: {
switch (m_drawType) {
case JI_BUTTON: this->theme->draw_button(this, &msg->draw.rect); break;
case JI_CHECK: this->theme->draw_check(this, &msg->draw.rect); break;
case JI_RADIO: this->theme->draw_radio(this, &msg->draw.rect); break;
case JI_BUTTON: getTheme()->draw_button(this, &msg->draw.rect); break;
case JI_CHECK: getTheme()->draw_check(this, &msg->draw.rect); break;
case JI_RADIO: getTheme()->draw_radio(this, &msg->draw.rect); break;
}
return true;
}
@ -306,13 +306,13 @@ void ButtonBase::onPreferredSize(PreferredSizeEvent& ev)
switch (m_drawType) {
case JI_CHECK:
icon_w = this->theme->check_icon_size;
icon_h = this->theme->check_icon_size;
icon_w = getTheme()->check_icon_size;
icon_h = getTheme()->check_icon_size;
break;
case JI_RADIO:
icon_w = this->theme->radio_icon_size;
icon_h = this->theme->radio_icon_size;
icon_w = getTheme()->radio_icon_size;
icon_h = getTheme()->radio_icon_size;
break;
}
}

View File

@ -167,7 +167,7 @@ bool Entry::onProcessMessage(JMessage msg)
switch (msg->type) {
case JM_DRAW:
this->theme->draw_entry(this, &msg->draw.rect);
getTheme()->draw_entry(this, &msg->draw.rect);
return true;
case JM_TIMER:

View File

@ -379,7 +379,7 @@ bool Frame::onProcessMessage(JMessage msg)
break;
case JM_DRAW:
this->theme->draw_frame(this, &msg->draw.rect);
getTheme()->draw_frame(this, &msg->draw.rect);
return true;
}
@ -437,7 +437,7 @@ void Frame::window_set_position(JRect rect)
child = (JWidget)link->data;
if (jwidget_is_decorative(child))
child->theme->map_decorative_widget(child);
child->getTheme()->map_decorative_widget(child);
else
jwidget_set_rect(child, cpos);
}

View File

@ -45,7 +45,7 @@ static bool box_msg_proc(JWidget widget, JMessage msg)
return true;
case JM_DRAW:
widget->theme->draw_box(widget, &msg->draw.rect);
widget->getTheme()->draw_box(widget, &msg->draw.rect);
return true;
}

View File

@ -350,8 +350,8 @@ static bool combobox_entry_msg_proc(JWidget widget, JMessage msg)
break;
case JM_DRAW:
widget->theme->draw_combobox_entry(static_cast<Entry*>(widget),
&msg->draw.rect);
widget->getTheme()->draw_combobox_entry(static_cast<Entry*>(widget),
&msg->draw.rect);
return true;
}
@ -364,7 +364,7 @@ static bool combobox_button_msg_proc(JWidget widget, JMessage msg)
switch (msg->type) {
case JM_DRAW:
widget->theme->draw_combobox_button((ButtonBase*)widget, &msg->draw.rect);
widget->getTheme()->draw_combobox_button((ButtonBase*)widget, &msg->draw.rect);
return true;
}

View File

@ -152,7 +152,7 @@ static bool grid_msg_proc(JWidget widget, JMessage msg)
return true;
case JM_DRAW:
widget->theme->draw_grid(widget, &msg->draw.rect);
widget->getTheme()->draw_grid(widget, &msg->draw.rect);
return true;
}

View File

@ -105,7 +105,8 @@ void _ji_reinit_theme_in_all_widgets()
// Then we can reinitialize the theme of each widget
for (c=0; c<widgets->size(); c++)
if (_ji_is_valid_widget((*widgets)[c])) {
(*widgets)[c]->theme = CurrentTheme::get();
(*widgets)[c]->setTheme(CurrentTheme::get());
jwidget_init_theme((*widgets)[c]);
}

View File

@ -45,7 +45,7 @@ bool LinkLabel::onProcessMessage(JMessage msg)
break;
case JM_DRAW:
this->theme->draw_link_label(this, &msg->draw.rect);
getTheme()->draw_link_label(this, &msg->draw.rect);
return true;
case JM_BUTTONRELEASED:

View File

@ -160,7 +160,7 @@ static bool listbox_msg_proc(JWidget widget, JMessage msg)
return true;
case JM_DRAW:
widget->theme->draw_listbox(widget, &msg->draw.rect);
widget->getTheme()->draw_listbox(widget, &msg->draw.rect);
return true;
case JM_DIRTYCHILDREN:
@ -396,7 +396,7 @@ static bool listitem_msg_proc(JWidget widget, JMessage msg)
}
case JM_DRAW:
widget->theme->draw_listitem(widget, &msg->draw.rect);
widget->getTheme()->draw_listitem(widget, &msg->draw.rect);
return true;
}

View File

@ -1079,7 +1079,7 @@ static bool manager_msg_proc(JWidget widget, JMessage msg)
return true;
case JM_DRAW:
jdraw_rectfill(&msg->draw.rect, widget->theme->desktop_color);
jdraw_rectfill(&msg->draw.rect, widget->getTheme()->desktop_color);
return true;
case JM_KEYPRESSED:

View File

@ -379,7 +379,7 @@ static bool menu_msg_proc(Widget* widget, JMessage msg)
return true;
case JM_DRAW:
widget->theme->draw_menu(widget, &msg->draw.rect);
widget->getTheme()->draw_menu(widget, &msg->draw.rect);
return true;
}
@ -845,7 +845,7 @@ static bool menuitem_msg_proc(Widget* widget, JMessage msg)
return true;
case JM_DRAW:
widget->theme->draw_menuitem(widget, &msg->draw.rect);
widget->getTheme()->draw_menuitem(widget, &msg->draw.rect);
return true;
case JM_MOUSEENTER:

View File

@ -76,7 +76,7 @@ static bool panel_msg_proc(JWidget widget, JMessage msg)
return true;
case JM_DRAW:
widget->theme->draw_panel(widget, &msg->draw.rect);
widget->getTheme()->draw_panel(widget, &msg->draw.rect);
return true;
case JM_BUTTONPRESSED:

View File

@ -56,7 +56,7 @@ static bool separator_msg_proc(JWidget widget, JMessage msg)
}
case JM_DRAW:
widget->theme->draw_separator(widget, &msg->draw.rect);
widget->getTheme()->draw_separator(widget, &msg->draw.rect);
return true;
}

View File

@ -45,7 +45,7 @@ static bool textbox_msg_proc(JWidget widget, JMessage msg)
return true;
case JM_DRAW:
widget->theme->draw_textbox(widget, &msg->draw.rect);
widget->getTheme()->draw_textbox(widget, &msg->draw.rect);
return true;
case JM_SIGNAL:

View File

@ -17,7 +17,7 @@
#include "gui/theme.h"
#include "gui/widget.h"
#define BAR_SIZE widget->theme->scrollbar_size
#define BAR_SIZE widget->getTheme()->scrollbar_size
using namespace gfx;
@ -141,13 +141,13 @@ void jview_set_size(JWidget widget, int w, int h)
jwidget_remove_child(widget, view->scrollbar_v);
if (view->hasbars) {
if (CHECK (w, h, l, t, r, b)) {
if (CHECK(w, h, l, t, r, b)) {
pos->y2 -= BAR_SIZE;
jwidget_add_child(widget, view->scrollbar_h);
if (CHECK (h, w, t, l, b, r)) {
if (CHECK(h, w, t, l, b, r)) {
pos->x2 -= BAR_SIZE;
if (CHECK (w, h, l, t, r, b))
if (CHECK(w, h, l, t, r, b))
jwidget_add_child(widget, view->scrollbar_v);
else {
pos->x2 += BAR_SIZE;
@ -156,13 +156,13 @@ void jview_set_size(JWidget widget, int w, int h)
}
}
}
else if (CHECK (h, w, t, l, b, r)) {
else if (CHECK(h, w, t, l, b, r)) {
pos->x2 -= BAR_SIZE;
jwidget_add_child(widget, view->scrollbar_v);
if (CHECK (w, h, l, t, r, b)) {
if (CHECK(w, h, l, t, r, b)) {
pos->y2 -= BAR_SIZE;
if (CHECK (h, w, t, l, b, r))
if (CHECK(h, w, t, l, b, r))
jwidget_add_child(widget, view->scrollbar_h);
else {
pos->x2 += BAR_SIZE;
@ -352,7 +352,7 @@ static bool view_msg_proc(JWidget widget, JMessage msg)
return true;
case JM_DRAW:
widget->theme->draw_view(widget, &msg->draw.rect);
widget->getTheme()->draw_view(widget, &msg->draw.rect);
return true;
case JM_FOCUSENTER:
@ -394,7 +394,7 @@ static bool viewport_msg_proc(JWidget widget, JMessage msg)
return true;
case JM_DRAW:
widget->theme->draw_view_viewport(widget, &msg->draw.rect);
widget->getTheme()->draw_view_viewport(widget, &msg->draw.rect);
return true;
}
@ -587,7 +587,7 @@ static bool scrollbar_msg_proc(JWidget widget, JMessage msg)
break;
case JM_DRAW:
widget->theme->draw_view_scrollbar(widget, &msg->draw.rect);
widget->getTheme()->draw_view_scrollbar(widget, &msg->draw.rect);
return true;
}

View File

@ -35,7 +35,7 @@ bool Label::onProcessMessage(JMessage msg)
return true;
case JM_DRAW:
this->theme->draw_label(this, &msg->draw.rect);
this->getTheme()->draw_label(this, &msg->draw.rect);
return true;
}

View File

@ -71,7 +71,7 @@ bool Slider::onProcessMessage(JMessage msg)
switch (msg->type) {
case JM_DRAW:
this->theme->draw_slider(this, &msg->draw.rect);
this->getTheme()->draw_slider(this, &msg->draw.rect);
return true;
case JM_FOCUSENTER:

View File

@ -56,15 +56,14 @@ void Theme::regenerate()
void CurrentTheme::set(Theme* theme)
{
JWidget manager = ji_get_default_manager();
current_theme = theme;
if (current_theme) {
current_theme->regenerate();
if (manager && jwidget_get_theme(manager) == NULL)
jwidget_set_theme(manager, theme);
Widget* manager = ji_get_default_manager();
if (manager && !manager->getTheme())
manager->setTheme(theme);
}
}

View File

@ -59,12 +59,12 @@ Widget::Widget(int type)
this->max_h = INT_MAX;
this->children = jlist_new();
this->parent = NULL;
this->theme = CurrentTheme::get();
this->m_theme = CurrentTheme::get();
this->hooks = jlist_new();
this->m_align = 0;
this->m_text = "";
this->m_font = this->theme ? this->theme->default_font: NULL;
this->m_font = this->m_theme ? this->m_theme->default_font: NULL;
this->m_bg_color = -1;
this->update_region = jregion_new(NULL, 0);
@ -153,8 +153,8 @@ void jwidget_init_theme(JWidget widget)
{
ASSERT_VALID_WIDGET(widget);
if (widget->theme) {
widget->theme->init_widget(widget);
if (widget->getTheme()) {
widget->getTheme()->init_widget(widget);
if (!(widget->flags & JI_INITIALIZED))
widget->flags |= JI_INITIALIZED;
@ -310,6 +310,14 @@ void Widget::setFont(FONT* f)
dirty();
}
void Widget::setTheme(Theme* theme)
{
m_theme = theme;
// TODO maybe some Style in Widget should be great
setFont(m_theme ? m_theme->default_font: NULL);
}
/**********************************************************************/
/* behavior properties */
@ -724,7 +732,7 @@ JRegion jwidget_get_region(JWidget widget)
ASSERT_VALID_WIDGET(widget);
if (widget->type == JI_FRAME)
region = widget->theme->get_window_mask(widget);
region = widget->getTheme()->get_window_mask(widget);
else
region = jregion_new(widget->rc, 1);
@ -858,13 +866,6 @@ int jwidget_get_bg_color(JWidget widget)
return widget->getBgColor();
}
Theme* jwidget_get_theme(JWidget widget)
{
ASSERT_VALID_WIDGET(widget);
return widget->theme;
}
int jwidget_get_text_length(JWidget widget)
{
#if 1
@ -1054,15 +1055,6 @@ void jwidget_set_bg_color(JWidget widget, int color)
widget->setBgColor(color);
}
void jwidget_set_theme(JWidget widget, Theme* theme)
{
ASSERT_VALID_WIDGET(widget);
widget->theme = theme;
/* TODO mmhhh... maybe some JStyle in JWidget should be great */
widget->setFont(widget->theme ? widget->theme->default_font: NULL);
}
/**********************************************************************/
/* drawing methods */

View File

@ -82,7 +82,6 @@ JRect jwidget_get_child_rect(JWidget widget);
JRegion jwidget_get_region(JWidget widget);
JRegion jwidget_get_drawable_region(JWidget widget, int flags);
int jwidget_get_bg_color(JWidget widget);
Theme* jwidget_get_theme(JWidget widget);
int jwidget_get_text_length(JWidget widget);
int jwidget_get_text_height(JWidget widget);
void jwidget_get_texticon_info(JWidget widget,
@ -96,7 +95,6 @@ void jwidget_set_rect(JWidget widget, JRect rect);
void jwidget_set_min_size(JWidget widget, int w, int h);
void jwidget_set_max_size(JWidget widget, int w, int h);
void jwidget_set_bg_color(JWidget widget, int color);
void jwidget_set_theme(JWidget widget, Theme* theme);
/* drawing methods */
@ -149,17 +147,17 @@ public:
/* structures */
JList children; /* sub-objects */
JWidget parent; /* who is the parent? */
Theme* theme; // Widget's theme
/* virtual properties */
JList hooks; /* hooks with msg_proc and specific data */
/* common widget properties */
private:
int m_align; // widget alignment
std::string m_text; // widget text
struct FONT *m_font; // text font type
int m_bg_color; // background color
Theme* m_theme; // Widget's theme
int m_align; // Widget alignment
std::string m_text; // Widget text
struct FONT *m_font; // Text font type
int m_bg_color; // Background color
public:
/* drawable cycle */
@ -213,30 +211,29 @@ public:
bool isSelected() const;
void setSelected(bool state);
// font
// ===============================================================
// LOOK & FEEL
// ===============================================================
FONT* getFont();
void setFont(FONT* font);
/**
* Gets the background color of the widget.
*/
int getBgColor()
{
// Gets the background color of the widget.
int getBgColor() const {
if (m_bg_color < 0 && parent)
return parent->getBgColor();
else
return m_bg_color;
}
/**
* Sets the background color of the widget.
*/
void setBgColor(int bg_color)
{
// Sets the background color of the widget
void setBgColor(int bg_color) {
m_bg_color = bg_color;
}
Theme* getTheme() const { return m_theme; }
void setTheme(Theme* theme);
//////////////////////////////////////////////////////////////////////
// parents and children

View File

@ -710,8 +710,8 @@ void SkinTheme::draw_check(ButtonBase* widget, JRect clip)
jwidget_get_texticon_info(widget, &box, &text, &icon,
widget->getButtonIconAlign(),
widget->theme->check_icon_size,
widget->theme->check_icon_size);
this->check_icon_size,
this->check_icon_size);
// background
jdraw_rectfill(widget->rc, bg = BGCOLOR);
@ -1021,8 +1021,8 @@ void SkinTheme::draw_radio(ButtonBase* widget, JRect clip)
jwidget_get_texticon_info(widget, &box, &text, &icon,
widget->getButtonIconAlign(),
widget->theme->radio_icon_size,
widget->theme->radio_icon_size);
this->radio_icon_size,
this->radio_icon_size);
/* background */
jdraw_rectfill(widget->rc, bg);
@ -1318,8 +1318,8 @@ void SkinTheme::draw_combobox_button(ButtonBase* widget, JRect clip)
void SkinTheme::draw_textbox(JWidget widget, JRect clip)
{
_ji_theme_textbox_draw(ji_screen, widget, NULL, NULL,
widget->theme->textbox_bg_color,
widget->theme->textbox_fg_color);
this->textbox_bg_color,
this->textbox_fg_color);
}
void SkinTheme::draw_view(JWidget widget, JRect clip)
@ -1413,7 +1413,7 @@ void SkinTheme::draw_frame(Frame* window, JRect clip)
}
// desktop
else {
jdraw_rectfill(pos, window->theme->desktop_color);
jdraw_rectfill(pos, this->desktop_color);
}
jrect_free(pos);
@ -1725,7 +1725,8 @@ bool SkinTheme::theme_frame_button_msg_proc(JWidget widget, JMessage msg)
ButtonBase* button = dynamic_cast<ButtonBase*>(widget);
ASSERT(button && "theme_frame_button_msg_proc() must be hooked in a ButtonBase widget");
((SkinTheme*)widget->theme)->draw_frame_button(button, &msg->draw.rect);
((SkinTheme*)button->getTheme())
->draw_frame_button(button, &msg->draw.rect);
}
return true;

View File

@ -172,7 +172,7 @@ bool ColorBar::onProcessMessage(JMessage msg)
ASSERT(m_colorsPerColumn*m_columns <= 256);
}
SkinTheme* theme = static_cast<SkinTheme*>(this->theme);
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
BITMAP *doublebuffer = create_bitmap(jrect_w(&msg->draw.rect),
jrect_h(&msg->draw.rect));
int imgtype = app_get_current_image_type();

View File

@ -63,7 +63,7 @@ static bool editor_view_msg_proc(JWidget widget, JMessage msg);
JWidget editor_view_new()
{
JWidget widget = jview_new();
SkinTheme* theme = static_cast<SkinTheme*>(widget->theme);
SkinTheme* theme = static_cast<SkinTheme*>(widget->getTheme());
int l = theme->get_part(PART_EDITOR_SELECTED_W)->w;
int t = theme->get_part(PART_EDITOR_SELECTED_N)->h;
int r = theme->get_part(PART_EDITOR_SELECTED_E)->w;
@ -861,7 +861,7 @@ static bool editor_view_msg_proc(JWidget widget, JMessage msg)
JWidget viewport = jview_get_viewport(widget);
JWidget child = reinterpret_cast<JWidget>(jlist_first_data(viewport->children));
JRect pos = jwidget_get_rect(widget);
SkinTheme* theme = static_cast<SkinTheme*>(widget->theme);
SkinTheme* theme = static_cast<SkinTheme*>(widget->getTheme());
theme->draw_bounds_nw(ji_screen,
pos->x1, pos->y1,
@ -905,7 +905,7 @@ bool Editor::onProcessMessage(JMessage msg)
break;
case JM_DRAW: {
SkinTheme* theme = static_cast<SkinTheme*>(this->theme);
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
if (m_old_cursor_thick == 0) {
m_old_cursor_thick = m_cursor_thick;

View File

@ -392,7 +392,7 @@ bool StatusBar::onProcessMessage(JMessage msg)
break;
case JM_DRAW: {
SkinTheme* theme = static_cast<SkinTheme*>(this->theme);
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
int text_color = ji_color_foreground();
int face_color = ji_color_face();
JRect rc = jwidget_get_rect(this);

View File

@ -187,7 +187,7 @@ void* Tabs::getSelectedTab()
bool Tabs::onProcessMessage(JMessage msg)
{
SkinTheme* theme = static_cast<SkinTheme*>(this->theme);
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
switch (msg->type) {
@ -407,7 +407,7 @@ void Tabs::drawTab(BITMAP* bmp, JRect box, Tab* tab, int y_delta, bool selected)
if (box->x1 >= this->rc->x2 || box->x2 <= this->rc->x1)
return;
SkinTheme* theme = static_cast<SkinTheme*>(this->theme);
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
int text_color;
int face_color;

View File

@ -111,7 +111,7 @@ private:
static Size getToolIconSize(Widget* widget)
{
SkinTheme* theme = static_cast<SkinTheme*>(widget->theme);
SkinTheme* theme = static_cast<SkinTheme*>(widget->getTheme());
BITMAP* icon = theme->get_toolicon("configuration");
if (icon)
return Size(icon->w, icon->h);
@ -187,7 +187,7 @@ bool ToolBar::onProcessMessage(JMessage msg)
case JM_DRAW: {
BITMAP *doublebuffer = create_bitmap(jrect_w(&msg->draw.rect),
jrect_h(&msg->draw.rect));
SkinTheme* theme = static_cast<SkinTheme*>(this->theme);
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
ToolBox* toolbox = App::instance()->getToolBox();
ToolGroupList::iterator it = toolbox->begin_group();
int groups = toolbox->getGroupsCount();
@ -594,7 +594,7 @@ bool ToolStrip::onProcessMessage(JMessage msg)
case JM_DRAW: {
BITMAP *doublebuffer = create_bitmap(jrect_w(&msg->draw.rect),
jrect_h(&msg->draw.rect));
SkinTheme* theme = static_cast<SkinTheme*>(this->theme);
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
ToolBox* toolbox = App::instance()->getToolBox();
Rect toolrc;
int index = 0;