Changed jwidget to a C++ class with methods.

This commit is contained in:
David Capello 2009-05-30 21:22:52 +00:00
parent 973fe38847
commit 6f9bccd65b
36 changed files with 473 additions and 463 deletions

View File

@ -103,8 +103,8 @@ static void cmd_new_file_execute(const char *argument)
else if (jwidget_is_selected(radio2)) imgtype = IMAGE_GRAYSCALE; else if (jwidget_is_selected(radio2)) imgtype = IMAGE_GRAYSCALE;
else if (jwidget_is_selected(radio3)) imgtype = IMAGE_INDEXED; else if (jwidget_is_selected(radio3)) imgtype = IMAGE_INDEXED;
w = ustrtol(jwidget_get_text(width), NULL, 10); w = width->text_int();
h = ustrtol(jwidget_get_text(height), NULL, 10); h = height->text_int();
bg = jlistbox_get_selected_index(bg_box); bg = jlistbox_get_selected_index(bg_box);
w = MID(1, w, 9999); w = MID(1, w, 9999);

View File

@ -226,7 +226,7 @@ void app_loop()
menubar = jmenubar_new(); menubar = jmenubar_new();
statusbar = statusbar_new(); statusbar = statusbar_new();
colorbar = colorbar_new(box_colorbar->align); colorbar = colorbar_new(box_colorbar->align());
toolbar = toolbar_new(); toolbar = toolbar_new();
tabsbar = tabs_new(tabsbar_select_callback); tabsbar = tabs_new(tabsbar_select_callback);
view = editor_view_new(); view = editor_view_new();

View File

@ -62,13 +62,13 @@
#define THUMBSIZE (32*guiscale()) #define THUMBSIZE (32*guiscale())
/* height of the headers */ /* height of the headers */
#define HDRSIZE (3 + text_height(widget->text_font)*2 + 3 + 3) #define HDRSIZE (3 + text_height(widget->font())*2 + 3 + 3)
/* width of the frames */ /* width of the frames */
#define FRMSIZE (3 + THUMBSIZE + 3) #define FRMSIZE (3 + THUMBSIZE + 3)
/* height of the layers */ /* height of the layers */
#define LAYSIZE (3 + MAX(text_height(widget->text_font), THUMBSIZE) + 4) #define LAYSIZE (3 + MAX(text_height(widget->font()), THUMBSIZE) + 4)
/* space between icons and other information in the layer */ /* space between icons and other information in the layer */
#define ICONSEP (2*guiscale()) #define ICONSEP (2*guiscale())
@ -951,11 +951,11 @@ static void anieditor_draw_header_part(JWidget widget, JRect clip, int x1, int y
if (align1 < 0) if (align1 < 0)
x = x1+3; x = x1+3;
else if (align1 == 0) else if (align1 == 0)
x = (x1+x2)/2 - text_length(widget->text_font, line1)/2; x = (x1+x2)/2 - text_length(widget->font(), line1)/2;
else else
x = x2 - 3 - text_length(widget->text_font, line1); x = x2 - 3 - text_length(widget->font(), line1);
jdraw_text(widget->text_font, line1, jdraw_text(widget->font(), line1,
x, y1+3, x, y1+3,
fg, face, TRUE); fg, face, TRUE);
} }
@ -964,12 +964,12 @@ static void anieditor_draw_header_part(JWidget widget, JRect clip, int x1, int y
if (align2 < 0) if (align2 < 0)
x = x1+3; x = x1+3;
else if (align2 == 0) else if (align2 == 0)
x = (x1+x2)/2 - text_length(widget->text_font, line2)/2; x = (x1+x2)/2 - text_length(widget->font(), line2)/2;
else else
x = x2 - 3 - text_length(widget->text_font, line2); x = x2 - 3 - text_length(widget->font(), line2);
jdraw_text(widget->text_font, line2, jdraw_text(widget->font(), line2,
x, y1+3+ji_font_get_size(widget->text_font)+3, x, y1+3+ji_font_get_size(widget->font())+3,
fg, face, TRUE); fg, face, TRUE);
} }
} }
@ -1074,16 +1074,16 @@ static void anieditor_draw_layer(JWidget widget, JRect clip, int layer_index)
u += ICONBORDER+icon2->w+ICONBORDER+ICONSEP; u += ICONBORDER+icon2->w+ICONBORDER+ICONSEP;
/* draw the layer's name */ /* draw the layer's name */
jdraw_text(widget->text_font, layer->name, jdraw_text(widget->font(), layer->name,
u, y_mid - ji_font_get_size(widget->text_font)/2, u, y_mid - ji_font_get_size(widget->font())/2,
fg, bg, TRUE); fg, bg, TRUE);
/* the background should be underlined */ /* the background should be underlined */
if (layer_is_background(layer)) { if (layer_is_background(layer)) {
hline(ji_screen, hline(ji_screen,
u, u,
y_mid - ji_font_get_size(widget->text_font)/2 + ji_font_get_size(widget->text_font) + 1, y_mid - ji_font_get_size(widget->font())/2 + ji_font_get_size(widget->font()) + 1,
u + text_length(widget->text_font, layer->name), u + text_length(widget->font(), layer->name),
fg); fg);
} }

View File

@ -115,7 +115,7 @@ void dialogs_options()
refresh_all_editors(); refresh_all_editors();
} }
undo_size_limit_value = ustrtol(jwidget_get_text(undo_size_limit), NULL, 10); undo_size_limit_value = undo_size_limit->text_int();
undo_size_limit_value = MID(1, undo_size_limit_value, 9999); undo_size_limit_value = MID(1, undo_size_limit_value, 9999);
set_config_int("Options", "UndoSizeLimit", undo_size_limit_value); set_config_int("Options", "UndoSizeLimit", undo_size_limit_value);

View File

@ -364,7 +364,7 @@ static JWidget tips_load_box(FILE *f, char *buf, int sizeof_buf, int *take)
/* add a box with an static size to separate paragraphs */ /* add a box with an static size to separate paragraphs */
JWidget box = jbox_new(0); JWidget box = jbox_new(0);
jwidget_set_min_size(box, 0, text_height(box->text_font)); jwidget_set_min_size(box, 0, text_height(box->font()));
jwidget_add_child(vbox, box); jwidget_add_child(vbox, box);
} }

View File

@ -73,7 +73,7 @@ union jmessage;
struct jrect; struct jrect;
struct jregion; struct jregion;
struct jtheme; struct jtheme;
struct jwidget; class jwidget;
/* alignment */ /* alignment */
#define JI_HORIZONTAL 0x0001 #define JI_HORIZONTAL 0x0001
@ -100,6 +100,7 @@ struct jwidget;
#define JI_DECORATIVE 0x0200 /* to decorate windows */ #define JI_DECORATIVE 0x0200 /* to decorate windows */
#define JI_HARDCAPTURE 0x0400 /* only windows use hard capture */ #define JI_HARDCAPTURE 0x0400 /* only windows use hard capture */
#define JI_INITIALIZED 0x0800 /* the widget was already initialized by a theme */ #define JI_INITIALIZED 0x0800 /* the widget was already initialized by a theme */
#define JI_NOTEXT 0x1000 /* the widget does not have text */
/* widget types */ /* widget types */
enum { enum {
@ -190,7 +191,6 @@ enum {
JI_SIGNAL_ADD_CHILD, JI_SIGNAL_ADD_CHILD,
JI_SIGNAL_REMOVE_CHILD, JI_SIGNAL_REMOVE_CHILD,
JI_SIGNAL_NEW_PARENT, JI_SIGNAL_NEW_PARENT,
JI_SIGNAL_GET_TEXT,
JI_SIGNAL_SET_TEXT, JI_SIGNAL_SET_TEXT,
JI_SIGNAL_SET_FONT, JI_SIGNAL_SET_FONT,
JI_SIGNAL_INIT_THEME, JI_SIGNAL_INIT_THEME,
@ -233,7 +233,7 @@ typedef struct jstream* JStream;
typedef struct jrect* JRect; typedef struct jrect* JRect;
typedef struct jregion* JRegion; typedef struct jregion* JRegion;
typedef struct jtheme* JTheme; typedef struct jtheme* JTheme;
typedef struct jwidget* JWidget; typedef class jwidget* JWidget;
typedef struct jxml* JXml; typedef struct jxml* JXml;
typedef struct jxmlattr* JXmlAttr; typedef struct jxmlattr* JXmlAttr;
typedef struct jxmlnode* JXmlNode; typedef struct jxmlnode* JXmlNode;

View File

@ -71,7 +71,7 @@ static void box_request_size(JWidget widget, int *w, int *h)
{ {
#define GET_CHILD_SIZE(w, h) \ #define GET_CHILD_SIZE(w, h) \
{ \ { \
if (widget->align & JI_HOMOGENEOUS) \ if (widget->align() & JI_HOMOGENEOUS) \
*w = MAX(*w, req_##w); \ *w = MAX(*w, req_##w); \
else \ else \
*w += req_##w; \ *w += req_##w; \
@ -81,7 +81,7 @@ static void box_request_size(JWidget widget, int *w, int *h)
#define FINAL_SIZE(w) \ #define FINAL_SIZE(w) \
{ \ { \
if (widget->align & JI_HOMOGENEOUS) \ if (widget->align() & JI_HOMOGENEOUS) \
*w *= nvis_children; \ *w *= nvis_children; \
\ \
*w += widget->child_spacing * (nvis_children-1); \ *w += widget->child_spacing * (nvis_children-1); \
@ -109,7 +109,7 @@ static void box_request_size(JWidget widget, int *w, int *h)
jwidget_request_size(child, &req_w, &req_h); jwidget_request_size(child, &req_w, &req_h);
if (widget->align & JI_HORIZONTAL) { if (widget->align() & JI_HORIZONTAL) {
GET_CHILD_SIZE(w, h); GET_CHILD_SIZE(w, h);
} }
else { else {
@ -118,7 +118,7 @@ static void box_request_size(JWidget widget, int *w, int *h)
} }
if (nvis_children > 0) { if (nvis_children > 0) {
if (widget->align & JI_HORIZONTAL) { if (widget->align() & JI_HORIZONTAL) {
FINAL_SIZE(w); FINAL_SIZE(w);
} }
else { else {
@ -135,7 +135,7 @@ static void box_set_position(JWidget widget, JRect rect)
#define FIXUP(x, y, w, h, l, t, r, b) \ #define FIXUP(x, y, w, h, l, t, r, b) \
{ \ { \
if (nvis_children > 0) { \ if (nvis_children > 0) { \
if (widget->align & JI_HOMOGENEOUS) { \ if (widget->align() & JI_HOMOGENEOUS) { \
width = (jrect_##w(widget->rc) \ width = (jrect_##w(widget->rc) \
- widget->border_width.l \ - widget->border_width.l \
- widget->border_width.r \ - widget->border_width.r \
@ -161,7 +161,7 @@ static void box_set_position(JWidget widget, JRect rect)
child = (JWidget)link->data; \ child = (JWidget)link->data; \
\ \
if (!(child->flags & JI_HIDDEN)) { \ if (!(child->flags & JI_HIDDEN)) { \
if (widget->align & JI_HOMOGENEOUS) { \ if (widget->align() & JI_HOMOGENEOUS) { \
if (nvis_children == 1) \ if (nvis_children == 1) \
child_width = width; \ child_width = width; \
else \ else \
@ -188,7 +188,7 @@ static void box_set_position(JWidget widget, JRect rect)
\ \
w = MAX(1, child_width); \ w = MAX(1, child_width); \
\ \
if (widget->align & JI_HORIZONTAL) \ if (widget->align() & JI_HORIZONTAL) \
jrect_replace(&cpos, x, y, x+w, y+h); \ jrect_replace(&cpos, x, y, x+w, y+h); \
else \ else \
jrect_replace(&cpos, y, x, y+h, x+w); \ jrect_replace(&cpos, y, x, y+h, x+w); \
@ -226,7 +226,7 @@ static void box_set_position(JWidget widget, JRect rect)
jwidget_request_size(widget, &req_w, &req_h); jwidget_request_size(widget, &req_w, &req_h);
if (widget->align & JI_HORIZONTAL) { if (widget->align() & JI_HORIZONTAL) {
FIXUP(x, y, w, h, l, t, r, b); FIXUP(x, y, w, h, l, t, r, b);
} }
else { else {

View File

@ -317,7 +317,7 @@ static bool combobox_msg_proc(JWidget widget, JMessage msg)
/* get the text-length of every item and put in 'w' the maximum value */ /* get the text-length of every item and put in 'w' the maximum value */
JI_LIST_FOR_EACH(combobox->items, link) { JI_LIST_FOR_EACH(combobox->items, link) {
int item_w = 2+text_length(widget->text_font, int item_w = 2+text_length(widget->font(),
((ComboItem *)link->data)->text)+2; ((ComboItem *)link->data)->text)+2;
w = MAX(w, item_w); w = MAX(w, item_w);

View File

@ -218,10 +218,10 @@ void jdraw_text(FONT *font, const char *s, int x, int y,
void jdraw_widget_text(JWidget widget, int fg, int bg, bool fill_bg) void jdraw_widget_text(JWidget widget, int fg, int bg, bool fill_bg)
{ {
if (widget->text) { if (widget->text()) {
struct jrect box, text, icon; struct jrect box, text, icon;
jwidget_get_texticon_info(widget, &box, &text, &icon, 0, 0, 0); jwidget_get_texticon_info(widget, &box, &text, &icon, 0, 0, 0);
jdraw_text(widget->text_font, widget->text, jdraw_text(widget->font(), widget->text(),
text.x1, text.y1, fg, bg, fill_bg); text.x1, text.y1, fg, bg, fill_bg);
} }
} }

View File

@ -47,6 +47,7 @@
typedef struct Entry typedef struct Entry
{ {
int maxsize;
int cursor; int cursor;
int scroll; int scroll;
int select; int select;
@ -72,20 +73,21 @@ JWidget jentry_new(int maxsize, const char *format, ...)
Entry* entry = (Entry*)jnew(Entry, 1); Entry* entry = (Entry*)jnew(Entry, 1);
char buf[4096]; char buf[4096];
/* formatted string */ // formatted string
if (format) { if (format) {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
vsprintf(buf, format, ap); vsprintf(buf, format, ap);
va_end(ap); va_end(ap);
} }
/* empty string */ // empty string
else { else {
ustrcpy(buf, empty_string); ustrcpy(buf, empty_string);
} }
jwidget_add_hook(widget, JI_ENTRY, entry_msg_proc, entry); jwidget_add_hook(widget, JI_ENTRY, entry_msg_proc, entry);
entry->maxsize = maxsize;
entry->cursor = 0; entry->cursor = 0;
entry->scroll = 0; entry->scroll = 0;
entry->select = 0; entry->select = 0;
@ -98,9 +100,7 @@ JWidget jentry_new(int maxsize, const char *format, ...)
/* TODO support for text alignment and multi-line */ /* TODO support for text alignment and multi-line */
/* widget->align = JI_LEFT | JI_MIDDLE; */ /* widget->align = JI_LEFT | JI_MIDDLE; */
widget->text_size = maxsize+1; widget->text(buf);
widget->text = (char*)jmalloc(widget->text_size);
jwidget_set_text(widget, buf);
jwidget_focusrest(widget, TRUE); jwidget_focusrest(widget, TRUE);
jwidget_init_theme(widget); jwidget_init_theme(widget);
@ -157,7 +157,7 @@ void jentry_hide_cursor(JWidget widget)
void jentry_set_cursor_pos(JWidget widget, int pos) void jentry_set_cursor_pos(JWidget widget, int pos)
{ {
Entry* entry = reinterpret_cast<Entry*>(jwidget_get_data(widget, JI_ENTRY)); Entry* entry = reinterpret_cast<Entry*>(jwidget_get_data(widget, JI_ENTRY));
const char *text = widget->text; const char *text = widget->text();
int x, c; int x, c;
entry->cursor = pos; entry->cursor = pos;
@ -171,7 +171,7 @@ void jentry_set_cursor_pos(JWidget widget, int pos)
do { do {
x = widget->rc->x1 + widget->border_width.l; x = widget->rc->x1 + widget->border_width.l;
for (c=++entry->scroll; ; c++) { for (c=++entry->scroll; ; c++) {
x += CHARACTER_LENGTH(widget->text_font, x += CHARACTER_LENGTH(widget->font(),
(c < ustrlen(text))? ugetat(text, c): ' '); (c < ustrlen(text))? ugetat(text, c): ' ');
if (x >= widget->rc->x2-widget->border_width.r) if (x >= widget->rc->x2-widget->border_width.r)
@ -188,7 +188,7 @@ void jentry_set_cursor_pos(JWidget widget, int pos)
void jentry_select_text(JWidget widget, int from, int to) void jentry_select_text(JWidget widget, int from, int to)
{ {
Entry* entry = reinterpret_cast<Entry*>(jwidget_get_data(widget, JI_ENTRY)); Entry* entry = reinterpret_cast<Entry*>(jwidget_get_data(widget, JI_ENTRY));
int end = ustrlen(widget->text); int end = ustrlen(widget->text());
entry->select = from; entry->select = from;
jentry_set_cursor_pos(widget, from); // to move scroll jentry_set_cursor_pos(widget, from); // to move scroll
@ -271,13 +271,11 @@ static bool entry_msg_proc(JWidget widget, JMessage msg)
case JM_KEYPRESSED: case JM_KEYPRESSED:
if (jwidget_has_focus(widget) && !jentry_is_readonly(widget)) { if (jwidget_has_focus(widget) && !jentry_is_readonly(widget)) {
char* text = (char*)jmalloc(widget->text_size); std::string text = widget->text();
int c, selbeg, selend; int c, selbeg, selend;
jtheme_entry_info(widget, NULL, NULL, NULL, &selbeg, &selend); jtheme_entry_info(widget, NULL, NULL, NULL, &selbeg, &selend);
ustrcpy(text, widget->text);
switch (msg->key.scancode) { switch (msg->key.scancode) {
case KEY_LEFT: case KEY_LEFT:
@ -310,7 +308,7 @@ static bool entry_msg_proc(JWidget widget, JMessage msg)
if (msg->any.shifts & KB_CTRL_FLAG) if (msg->any.shifts & KB_CTRL_FLAG)
entry_forward_word(widget); entry_forward_word(widget);
/* forward char */ /* forward char */
else if (entry->cursor < ustrlen (text)) else if (entry->cursor < text.size())
entry->cursor++; entry->cursor++;
break; break;
@ -335,31 +333,30 @@ static bool entry_msg_proc(JWidget widget, JMessage msg)
else else
entry->select = -1; entry->select = -1;
entry->cursor = ustrlen(text); entry->cursor = text.size();
break; break;
case KEY_DEL: case KEY_DEL:
/* delete the entire selection */ // delete the entire selection
if (selbeg >= 0) { if (selbeg >= 0) {
/* *cut* text! */ // *cut* text!
if (msg->any.shifts & KB_SHIFT_FLAG) { if (msg->any.shifts & KB_SHIFT_FLAG) {
char buf[1024]; char buf[1024];
ustrcpy(buf, empty_string); ustrcpy(buf, empty_string);
for (c=selbeg; c<=selend; c++) for (c=selbeg; c<=selend; c++)
uinsert(buf, ustrlen(buf), ugetat(text, c)); uinsert(buf, ustrlen(buf), text[c]);
jclipboard_set_text(buf); jclipboard_set_text(buf);
} }
/* remove text */ // remove text
for (c=0; c<selend-selbeg+1; c++) text.erase(selbeg, selend-selbeg+1);
uremove(text, selbeg);
entry->cursor = selbeg; entry->cursor = selbeg;
} }
/* delete the next character */ /* delete the next character */
else { else {
if (entry->cursor < ustrlen (text)) if (entry->cursor < text.size())
uremove(text, entry->cursor); text.erase(entry->cursor, 1);
} }
entry->select = -1; entry->select = -1;
@ -370,20 +367,19 @@ static bool entry_msg_proc(JWidget widget, JMessage msg)
if (msg->any.shifts & KB_SHIFT_FLAG) { if (msg->any.shifts & KB_SHIFT_FLAG) {
const char *clipboard; const char *clipboard;
if ((clipboard = jclipboard_get_text ())) { if ((clipboard = jclipboard_get_text())) {
/* delete the entire selection */ /* delete the entire selection */
if (selbeg >= 0) { if (selbeg >= 0) {
for (c=0; c<selend-selbeg+1; c++) text.erase(selbeg, selend-selbeg+1);
uremove(text, selbeg);
entry->cursor = selbeg; entry->cursor = selbeg;
entry->select = -1; entry->select = -1;
} }
/* paste text */ /* paste text */
for (c=0; c<ustrlen (clipboard); c++) for (c=0; c<ustrlen(clipboard); c++)
if (ustrsizez(text) < widget->text_size) if (text.size() < entry->maxsize)
uinsert(text, entry->cursor+c, ugetat(clipboard, c)); text.insert(entry->cursor+c, 1, ugetat(clipboard, c));
else else
break; break;
@ -395,7 +391,7 @@ static bool entry_msg_proc(JWidget widget, JMessage msg)
char buf[1024]; char buf[1024];
ustrcpy(buf, empty_string); ustrcpy(buf, empty_string);
for (c=selbeg; c<=selend; c++) for (c=selbeg; c<=selend; c++)
uinsert(buf, ustrlen(buf), ugetat(text, c)); uinsert(buf, ustrlen(buf), text[c]);
jclipboard_set_text(buf); jclipboard_set_text(buf);
} }
break; break;
@ -403,15 +399,14 @@ static bool entry_msg_proc(JWidget widget, JMessage msg)
case KEY_BACKSPACE: case KEY_BACKSPACE:
/* delete the entire selection */ /* delete the entire selection */
if (selbeg >= 0) { if (selbeg >= 0) {
for (c=0; c<selend-selbeg+1; c++) text.erase(selbeg, selend-selbeg+1);
uremove(text, selbeg);
entry->cursor = selbeg; entry->cursor = selbeg;
} }
/* delete the previous character */ /* delete the previous character */
else { else {
if (entry->cursor > 0) if (entry->cursor > 0)
uremove(text, --entry->cursor); text.erase(--entry->cursor, 1);
} }
entry->select = -1; entry->select = -1;
@ -421,34 +416,29 @@ static bool entry_msg_proc(JWidget widget, JMessage msg)
if (msg->key.ascii >= 32) { if (msg->key.ascii >= 32) {
/* delete the entire selection */ /* delete the entire selection */
if (selbeg >= 0) { if (selbeg >= 0) {
for (c=0; c<selend-selbeg+1; c++) text.erase(selbeg, selend-selbeg+1);
uremove(text, selbeg);
entry->cursor = selbeg; entry->cursor = selbeg;
} }
/* put the character */ /* put the character */
if (ustrsizez(text) < widget->text_size) if (text.size() < entry->maxsize)
uinsert(text, entry->cursor++, msg->key.ascii); text.insert(entry->cursor++, 1, msg->key.ascii);
entry->select = -1; entry->select = -1;
break; break;
} }
else { else
jfree(text); return false;
return FALSE;
}
} }
if (ustrcmp(widget->text, text) != 0) { if (text != widget->text()) {
jwidget_set_text(widget, text); widget->text(text.c_str());
jwidget_emit_signal(widget, JI_SIGNAL_ENTRY_CHANGE); jwidget_emit_signal(widget, JI_SIGNAL_ENTRY_CHANGE);
} }
jfree(text);
jentry_set_cursor_pos(widget, entry->cursor); jentry_set_cursor_pos(widget, entry->cursor);
jwidget_dirty(widget); widget->dirty();
return TRUE; return TRUE;
} }
break; break;
@ -458,7 +448,7 @@ static bool entry_msg_proc(JWidget widget, JMessage msg)
case JM_MOTION: case JM_MOTION:
if (jwidget_has_capture(widget)) { if (jwidget_has_capture(widget)) {
const char *text = widget->text; const char *text = widget->text();
bool move, dirty; bool move, dirty;
int c, x; int c, x;
@ -480,7 +470,7 @@ static bool entry_msg_proc(JWidget widget, JMessage msg)
entry->scroll++; entry->scroll++;
x = widget->rc->x1 + widget->border_width.l; x = widget->rc->x1 + widget->border_width.l;
for (c=entry->scroll; ; c++) { for (c=entry->scroll; ; c++) {
x += CHARACTER_LENGTH(widget->text_font, x += CHARACTER_LENGTH(widget->font(),
(c < ustrlen(text))? ugetat(text, c): ' '); (c < ustrlen(text))? ugetat(text, c): ' ');
if (x > widget->rc->x2-widget->border_width.r) { if (x > widget->rc->x2-widget->border_width.r) {
c--; c--;
@ -550,16 +540,18 @@ static bool entry_msg_proc(JWidget widget, JMessage msg)
static void entry_request_size(JWidget widget, int *w, int *h) static void entry_request_size(JWidget widget, int *w, int *h)
{ {
Entry* entry = reinterpret_cast<Entry*>(jwidget_get_data(widget, JI_ENTRY));
*w = *w =
+ widget->border_width.l + widget->border_width.l
+ ji_font_char_len(widget->text_font, 'w') * MIN(widget->text_size, 6) + ji_font_char_len(widget->font(), 'w') * MIN(entry->maxsize, 6)
+ 2 + widget->border_width.r; + 2 + widget->border_width.r;
*w = MIN(*w, JI_SCREEN_W/2); *w = MIN(*w, JI_SCREEN_W/2);
*h = *h =
+ widget->border_width.t + widget->border_width.t
+ text_height(widget->text_font) + text_height(widget->font())
+ widget->border_width.b; + widget->border_width.b;
} }
@ -574,8 +566,8 @@ static int entry_get_cursor_from_mouse(JWidget widget, JMessage msg)
widget->rc->x2-widget->border_width.r-1); widget->rc->x2-widget->border_width.r-1);
x = widget->rc->x1 + widget->border_width.l; x = widget->rc->x1 + widget->border_width.l;
for (c=entry->scroll; ugetat (widget->text, c); c++) { for (c=entry->scroll; ugetat(widget->text(), c); c++) {
w = CHARACTER_LENGTH(widget->text_font, ugetat(widget->text, c)); w = CHARACTER_LENGTH(widget->font(), ugetat(widget->text(), c));
if (x+w >= widget->rc->x2-widget->border_width.r) if (x+w >= widget->rc->x2-widget->border_width.r)
break; break;
if ((mx >= x) && (mx < x+w)) { if ((mx >= x) && (mx < x+w)) {
@ -585,7 +577,7 @@ static int entry_get_cursor_from_mouse(JWidget widget, JMessage msg)
x += w; x += w;
} }
if (!ugetat (widget->text, c)) if (!ugetat(widget->text(), c))
if ((mx >= x) && if ((mx >= x) &&
(mx <= widget->rc->x2-widget->border_width.r-1)) (mx <= widget->rc->x2-widget->border_width.r-1))
cursor = c; cursor = c;
@ -602,14 +594,14 @@ static void entry_forward_word(JWidget widget)
Entry* entry = reinterpret_cast<Entry*>(jwidget_get_data(widget, JI_ENTRY)); Entry* entry = reinterpret_cast<Entry*>(jwidget_get_data(widget, JI_ENTRY));
int ch; int ch;
for (; entry->cursor<ustrlen (widget->text); entry->cursor++) { for (; entry->cursor<ustrlen(widget->text()); entry->cursor++) {
ch = ugetat(widget->text, entry->cursor); ch = ugetat(widget->text(), entry->cursor);
if (IS_WORD_CHAR (ch)) if (IS_WORD_CHAR (ch))
break; break;
} }
for (; entry->cursor<ustrlen(widget->text); entry->cursor++) { for (; entry->cursor<ustrlen(widget->text()); entry->cursor++) {
ch = ugetat(widget->text, entry->cursor); ch = ugetat(widget->text(), entry->cursor);
if (!IS_WORD_CHAR(ch)) { if (!IS_WORD_CHAR(ch)) {
entry->cursor++; entry->cursor++;
break; break;
@ -623,13 +615,13 @@ static void entry_backward_word(JWidget widget)
int ch; int ch;
for (entry->cursor--; entry->cursor >= 0; entry->cursor--) { for (entry->cursor--; entry->cursor >= 0; entry->cursor--) {
ch = ugetat(widget->text, entry->cursor); ch = ugetat(widget->text(), entry->cursor);
if (IS_WORD_CHAR(ch)) if (IS_WORD_CHAR(ch))
break; break;
} }
for (; entry->cursor >= 0; entry->cursor--) { for (; entry->cursor >= 0; entry->cursor--) {
ch = ugetat(widget->text, entry->cursor); ch = ugetat(widget->text(), entry->cursor);
if (!IS_WORD_CHAR(ch)) { if (!IS_WORD_CHAR(ch)) {
entry->cursor++; entry->cursor++;
break; break;

View File

@ -176,7 +176,7 @@ static JWidget convert_tag_to_widget(JXmlElem elem)
text ? TRANSLATE_ATTR(text): NULL); text ? TRANSLATE_ATTR(text): NULL);
if (readonly) if (readonly)
jentry_readonly(widget, TRUE); jentry_readonly(widget, true);
} }
} }
/* grid */ /* grid */
@ -279,7 +279,7 @@ static JWidget convert_tag_to_widget(JXmlElem elem)
/* TODO add translatable support */ /* TODO add translatable support */
/* TODO here we need jxmlelem_get_text(elem) */ /* TODO here we need jxmlelem_get_text(elem) */
/* widget = jtextbox_new(tag->text, wordwrap ? JI_WORDWRAP: 0); */ /* widget = jtextbox_new(tag->text, wordwrap ? JI_WORDWRAP: 0); */
assert(FALSE); assert(false);
} }
/* view */ /* view */
else if (ustrcmp(elem_name, "view") == 0) { else if (ustrcmp(elem_name, "view") == 0) {
@ -303,6 +303,7 @@ static JWidget convert_tag_to_widget(JXmlElem elem)
if (widget) { if (widget) {
const char *name = jxmlelem_get_attr(elem, "name"); const char *name = jxmlelem_get_attr(elem, "name");
const char *tooltip = jxmlelem_get_attr(elem, "tooltip"); const char *tooltip = jxmlelem_get_attr(elem, "tooltip");
bool selected = jxmlelem_has_attr(elem, "selected");
bool expansive = jxmlelem_has_attr(elem, "expansive"); bool expansive = jxmlelem_has_attr(elem, "expansive");
bool magnetic = jxmlelem_has_attr(elem, "magnetic"); bool magnetic = jxmlelem_has_attr(elem, "magnetic");
bool noborders = jxmlelem_has_attr(elem, "noborders"); bool noborders = jxmlelem_has_attr(elem, "noborders");
@ -321,11 +322,14 @@ static JWidget convert_tag_to_widget(JXmlElem elem)
if (tooltip != NULL) if (tooltip != NULL)
jwidget_add_tooltip_text(widget, tooltip); jwidget_add_tooltip_text(widget, tooltip);
if (selected)
jwidget_set_selected(widget, selected);
if (expansive) if (expansive)
jwidget_expansive(widget, TRUE); jwidget_expansive(widget, true);
if (magnetic) if (magnetic)
jwidget_magnetic(widget, TRUE); jwidget_magnetic(widget, true);
if (noborders) if (noborders)
jwidget_noborders(widget); jwidget_noborders(widget);

View File

@ -60,8 +60,7 @@ static bool image_msg_proc(JWidget widget, JMessage msg)
struct jrect box, text, icon; struct jrect box, text, icon;
jwidget_get_texticon_info(widget, &box, &text, &icon, jwidget_get_texticon_info(widget, &box, &text, &icon,
jwidget_get_align(widget), widget->align(), bmp->w, bmp->h);
bmp->w, bmp->h);
msg->reqsize.w = widget->border_width.l + jrect_w(&box) + widget->border_width.r; msg->reqsize.w = widget->border_width.l + jrect_w(&box) + widget->border_width.r;
msg->reqsize.h = widget->border_width.t + jrect_h(&box) + widget->border_width.b; msg->reqsize.h = widget->border_width.t + jrect_h(&box) + widget->border_width.b;
@ -73,8 +72,7 @@ static bool image_msg_proc(JWidget widget, JMessage msg)
struct jrect box, text, icon; struct jrect box, text, icon;
jwidget_get_texticon_info(widget, &box, &text, &icon, jwidget_get_texticon_info(widget, &box, &text, &icon,
jwidget_get_align(widget), widget->align(), bmp->w, bmp->h);
bmp->w, bmp->h);
jdraw_rectexclude(widget->rc, &icon, jdraw_rectexclude(widget->rc, &icon,
jwidget_get_bg_color(widget)); jwidget_get_bg_color(widget));

View File

@ -30,93 +30,72 @@
*/ */
#include <assert.h> #include <assert.h>
#include <vector>
#include "jinete/jmanager.h" #include "jinete/jmanager.h"
#include "jinete/jtheme.h" #include "jinete/jtheme.h"
#include "jinete/jwidget.h" #include "jinete/jwidget.h"
#include "jinete/jwindow.h" #include "jinete/jwindow.h"
static JID nwidgets = 0; static std::vector<JWidget> widgets;
static JWidget *widgets = NULL;
JWidget _ji_get_widget_by_id(JID widget_id) JWidget _ji_get_widget_by_id(JID widget_id)
{ {
assert((widget_id >= 0) && (widget_id < nwidgets)); assert((widget_id >= 0) && (widget_id < widgets.size()));
return widgets[widget_id]; return widgets[widget_id];
} }
JWidget *_ji_get_widget_array(int *n) JWidget* _ji_get_widget_array(int* n)
{ {
*n = nwidgets; *n = widgets.size();
return widgets; return &widgets.front();
} }
JWidget _ji_get_new_widget() void _ji_add_widget(JWidget widget)
{ {
JID widget_id; JID widget_id;
/* first widget */ // first widget
if (!widgets) { if (widgets.empty()) {
nwidgets = 2; widgets.resize(2);
widgets = (JWidget *)jmalloc(sizeof(JWidget) * nwidgets);
/* id=0 no widget */ // id=0 no widget
widgets[0] = NULL; widgets[0] = NULL;
/* id>0 all widgets */ // id>0 all widgets
widgets[1] = (JWidget)jnew(struct jwidget, 1); widgets[1] = widget;
widgets[1]->id = widget_id = 1; widgets[1]->id = widget_id = 1;
} }
else { else {
/* find a free slot */ // find a free slot
for (widget_id=1; widget_id<nwidgets; widget_id++) { for (widget_id=1; widget_id<widgets.size(); widget_id++) {
/* is it free? */ // is it free?
if (widgets[widget_id]->id != widget_id) if (widgets[widget_id] == NULL)
/* yeah */
break; break;
} }
/* we need make other widget? */ // we need space for other widget more?
if (widget_id == nwidgets) { if (widget_id == widgets.size())
nwidgets++; widgets.resize(widgets.size()+1);
widgets = (JWidget *)jrealloc(widgets,
sizeof(JWidget) * nwidgets);
widgets[widget_id] = (JWidget)jnew(struct jwidget, 1);
}
/* using this */ widgets[widget_id] = widget;
widgets[widget_id]->id = widget_id; widgets[widget_id]->id = widget_id;
} }
return widgets[widget_id];
} }
void _ji_free_widget(JWidget widget) void _ji_remove_widget(JWidget widget)
{ {
widgets[widget->id]->id = 0; assert_valid_widget(widget);
}
void _ji_free_all_widgets() widgets[widget->id] = NULL;
{
int c;
if (nwidgets) {
for (c=0; c<nwidgets; c++)
if (widgets[c] != NULL)
jfree(widgets[c]);
jfree(widgets);
widgets = NULL;
nwidgets = 0;
}
} }
bool _ji_is_valid_widget(JWidget widget) bool _ji_is_valid_widget(JWidget widget)
{ {
return (widget && return (widget &&
widget->id >= 0 && widget->id >= 0 &&
widget->id < nwidgets && widget->id < widgets.size() &&
widgets[widget->id] && widgets[widget->id] &&
widgets[widget->id]->id == widget->id); widgets[widget->id]->id == widget->id);
} }
@ -126,17 +105,17 @@ void _ji_set_font_of_all_widgets(struct FONT *f)
int c; int c;
/* first of all, we have to set the font to all the widgets */ /* first of all, we have to set the font to all the widgets */
for (c=0; c<nwidgets; c++) for (c=0; c<widgets.size(); c++)
if (_ji_is_valid_widget(widgets[c])) if (_ji_is_valid_widget(widgets[c]))
jwidget_set_font(widgets[c], f); widgets[c]->font(f);
/* then we can reinitialize the theme of each widget */ /* then we can reinitialize the theme of each widget */
for (c=0; c<nwidgets; c++) for (c=0; c<widgets.size(); c++)
if (_ji_is_valid_widget(widgets[c])) if (_ji_is_valid_widget(widgets[c]))
jwidget_init_theme(widgets[c]); jwidget_init_theme(widgets[c]);
/* remap the windows */ /* remap the windows */
for (c=0; c<nwidgets; c++) for (c=0; c<widgets.size(); c++)
if (_ji_is_valid_widget(widgets[c])) { if (_ji_is_valid_widget(widgets[c])) {
if (widgets[c]->type == JI_WINDOW) if (widgets[c]->type == JI_WINDOW)
jwindow_remap(widgets[c]); jwindow_remap(widgets[c]);

View File

@ -42,11 +42,9 @@ struct BITMAP;
JWidget _ji_get_widget_by_id(JID widget_id); JWidget _ji_get_widget_by_id(JID widget_id);
JWidget *_ji_get_widget_array(int *nwidgets); JWidget *_ji_get_widget_array(int *nwidgets);
JWidget _ji_get_new_widget();
void _ji_free_widget(JWidget widget);
void _ji_free_all_widgets();
void _ji_add_widget(JWidget widget);
void _ji_remove_widget(JWidget widget);
bool _ji_is_valid_widget(JWidget widget); bool _ji_is_valid_widget(JWidget widget);
void _ji_set_font_of_all_widgets(struct FONT *f); void _ji_set_font_of_all_widgets(struct FONT *f);

View File

@ -52,7 +52,7 @@ static bool label_msg_proc(JWidget widget, JMessage msg)
switch (msg->type) { switch (msg->type) {
case JM_REQSIZE: case JM_REQSIZE:
if (widget->text) { if (widget->has_text()) {
msg->reqsize.w = jwidget_get_text_length(widget); msg->reqsize.w = jwidget_get_text_length(widget);
msg->reqsize.h = jwidget_get_text_height(widget); msg->reqsize.h = jwidget_get_text_height(widget);
} }

View File

@ -416,7 +416,7 @@ static void listitem_request_size(JWidget widget, int *w, int *h)
int req_w, req_h; int req_w, req_h;
JLink link; JLink link;
if (widget->text) { if (widget->has_text()) {
max_w = jwidget_get_text_length(widget); max_w = jwidget_get_text_length(widget);
max_h = jwidget_get_text_height(widget); max_h = jwidget_get_text_height(widget);
} }

View File

@ -255,7 +255,6 @@ void jmanager_free(JWidget widget)
_ji_theme_exit(); _ji_theme_exit();
_ji_font_exit(); _ji_font_exit();
_ji_system_exit(); _ji_system_exit();
_ji_free_all_widgets();
jlist_free(msg_queue); jlist_free(msg_queue);
jlist_free(new_windows); jlist_free(new_windows);

View File

@ -996,7 +996,7 @@ static void menuitem_request_size(JWidget widget, int *w, int *h)
MenuItem *menuitem = MITEM(widget); MenuItem *menuitem = MITEM(widget);
int bar = widget->parent->parent->type == JI_MENUBAR; int bar = widget->parent->parent->type == JI_MENUBAR;
if (widget->text) { if (widget->has_text()) {
*w = *w =
+ widget->border_width.l + widget->border_width.l
+ jwidget_get_text_length(widget) + jwidget_get_text_length(widget)
@ -1011,7 +1011,7 @@ static void menuitem_request_size(JWidget widget, int *w, int *h)
if (menuitem->accel) { if (menuitem->accel) {
char buf[256]; char buf[256];
jaccel_to_string(menuitem->accel, buf); jaccel_to_string(menuitem->accel, buf);
*w += ji_font_text_len(widget->text_font, buf); *w += ji_font_text_len(widget->font(), buf);
} }
} }
else { else {
@ -1331,10 +1331,10 @@ static JWidget check_for_letter(JWidget menu, int ascii)
if (menuitem->type != JI_MENUITEM) if (menuitem->type != JI_MENUITEM)
continue; continue;
if (menuitem->text) if (menuitem->has_text())
for (c=0; menuitem->text[c]; c++) for (c=0; menuitem->text()[c]; c++)
if ((menuitem->text[c] == '&') && (menuitem->text[c+1] != '&')) if ((menuitem->text()[c] == '&') && (menuitem->text()[c+1] != '&'))
if (tolower(ascii) == tolower(menuitem->text[c+1])) if (tolower(ascii) == tolower(menuitem->text()[c+1]))
return menuitem; return menuitem;
} }

View File

@ -111,7 +111,7 @@ static bool panel_msg_proc(JWidget widget, JMessage msg)
++bar; ++bar;
if (widget->align & JI_HORIZONTAL) { if (widget->align() & JI_HORIZONTAL) {
x1 = c1->rc->x2; x1 = c1->rc->x2;
y1 = widget->rc->y1; y1 = widget->rc->y1;
x2 = c2->rc->x1; x2 = c2->rc->x1;
@ -143,7 +143,7 @@ static bool panel_msg_proc(JWidget widget, JMessage msg)
if (jwidget_has_capture(widget)) { if (jwidget_has_capture(widget)) {
Panel* panel = reinterpret_cast<Panel*>(jwidget_get_data(widget, JI_PANEL)); Panel* panel = reinterpret_cast<Panel*>(jwidget_get_data(widget, JI_PANEL));
if (widget->align & JI_HORIZONTAL) { if (widget->align() & JI_HORIZONTAL) {
panel->pos = panel->pos =
100.0 * (msg->mouse.x-widget->rc->x1) / jrect_w(widget->rc); 100.0 * (msg->mouse.x-widget->rc->x1) / jrect_w(widget->rc);
} }
@ -179,7 +179,7 @@ static bool panel_msg_proc(JWidget widget, JMessage msg)
c1 = reinterpret_cast<JWidget>(link->data); c1 = reinterpret_cast<JWidget>(link->data);
c2 = reinterpret_cast<JWidget>(link->next->data); c2 = reinterpret_cast<JWidget>(link->next->data);
if (widget->align & JI_HORIZONTAL) { if (widget->align() & JI_HORIZONTAL) {
x1 = c1->rc->x2; x1 = c1->rc->x2;
y1 = widget->rc->y1; y1 = widget->rc->y1;
x2 = c2->rc->x1; x2 = c2->rc->x1;
@ -201,7 +201,7 @@ static bool panel_msg_proc(JWidget widget, JMessage msg)
} }
if (change_cursor) { if (change_cursor) {
if (widget->align & JI_HORIZONTAL) if (widget->align() & JI_HORIZONTAL)
jmouse_set_cursor(JI_CURSOR_SIZE_L); jmouse_set_cursor(JI_CURSOR_SIZE_L);
else else
jmouse_set_cursor(JI_CURSOR_SIZE_T); jmouse_set_cursor(JI_CURSOR_SIZE_T);
@ -253,14 +253,14 @@ static void panel_request_size(JWidget widget, int *w, int *h)
jwidget_request_size(child, &req_w, &req_h); jwidget_request_size(child, &req_w, &req_h);
if (widget->align & JI_HORIZONTAL) if (widget->align() & JI_HORIZONTAL)
GET_CHILD_SIZE(w, h); GET_CHILD_SIZE(w, h);
else else
GET_CHILD_SIZE(h, w); GET_CHILD_SIZE(h, w);
} }
if (nvis_children > 0) { if (nvis_children > 0) {
if (widget->align & JI_HORIZONTAL) if (widget->align() & JI_HORIZONTAL)
FINAL_SIZE(w); FINAL_SIZE(w);
else else
FINAL_SIZE(h); FINAL_SIZE(h);
@ -309,7 +309,7 @@ static void panel_set_position(JWidget widget, JRect rect)
jwidget_request_size(child1, &req1_w, &req1_h); jwidget_request_size(child1, &req1_w, &req1_h);
jwidget_request_size(child2, &req2_w, &req2_h); jwidget_request_size(child2, &req2_w, &req2_h);
if (widget->align & JI_HORIZONTAL) if (widget->align() & JI_HORIZONTAL)
FIXUP(x, y, w, h, l, t, r, b); FIXUP(x, y, w, h, l, t, r, b);
else else
FIXUP(y, x, h, w, t, l, b, r); FIXUP(y, x, h, w, t, l, b, r);

View File

@ -68,7 +68,7 @@ static bool separator_msg_proc(JWidget widget, JMessage msg)
max_h = MAX(max_h, req_h); max_h = MAX(max_h, req_h);
} }
if (widget->text) if (widget->has_text())
max_w = MAX(max_w, jwidget_get_text_length(widget)); max_w = MAX(max_w, jwidget_get_text_length(widget));
msg->reqsize.w = widget->border_width.l + max_w + widget->border_width.r; msg->reqsize.w = widget->border_width.l + max_w + widget->border_width.r;

View File

@ -275,13 +275,13 @@ static void slider_request_size(JWidget widget, int *w, int *h)
char buf[256]; char buf[256];
usprintf(buf, "%d", slider->min); usprintf(buf, "%d", slider->min);
min_w = ji_font_text_len(widget->text_font, buf); min_w = ji_font_text_len(widget->font(), buf);
usprintf(buf, "%d", slider->max); usprintf(buf, "%d", slider->max);
max_w = ji_font_text_len(widget->text_font, buf); max_w = ji_font_text_len(widget->font(), buf);
*w = MAX(min_w, max_w); *w = MAX(min_w, max_w);
*h = text_height(widget->text_font); *h = text_height(widget->font());
*w += widget->border_width.l + widget->border_width.r; *w += widget->border_width.l + widget->border_width.r;
*h += widget->border_width.t + widget->border_width.b; *h += widget->border_width.t + widget->border_width.b;

View File

@ -198,7 +198,7 @@ static void textbox_request_size(JWidget widget, int *w, int *h)
_ji_theme_textbox_draw(NULL, widget, w, h, 0, 0); _ji_theme_textbox_draw(NULL, widget, w, h, 0, 0);
if (widget->align & JI_WORDWRAP) { if (widget->align() & JI_WORDWRAP) {
JWidget view = jwidget_get_view(widget); JWidget view = jwidget_get_view(widget);
int width, min = *w; int width, min = *w;

View File

@ -255,14 +255,14 @@ void _ji_theme_textbox_draw(BITMAP *bmp, JWidget widget,
int *w, int *h, int bg, int fg) int *w, int *h, int bg, int fg)
{ {
JWidget view = jwidget_get_view(widget); JWidget view = jwidget_get_view(widget);
char *text = widget->text; char *text = (char*)widget->text(); // TODO warning: removing const modifier
char *beg, *end;
int x1, y1, x2, y2; int x1, y1, x2, y2;
int x, y, chr, len; int x, y, chr, len;
char *beg, *end;
int scroll_x, scroll_y; int scroll_x, scroll_y;
int viewport_w, viewport_h; int viewport_w, viewport_h;
int textheight = jwidget_get_text_height(widget); int textheight = jwidget_get_text_height(widget);
FONT *font = widget->text_font; FONT *font = widget->font();
char *beg_end, *old_end; char *beg_end, *old_end;
int width; int width;
@ -288,7 +288,7 @@ void _ji_theme_textbox_draw(BITMAP *bmp, JWidget widget,
chr = 0; chr = 0;
/* without word-wrap */ /* without word-wrap */
if (!(widget->align & JI_WORDWRAP)) { if (!(widget->align() & JI_WORDWRAP)) {
width = jrect_w(widget->rc); width = jrect_w(widget->rc);
} }
/* with word-wrap */ /* with word-wrap */
@ -322,7 +322,7 @@ void _ji_theme_textbox_draw(BITMAP *bmp, JWidget widget,
x = x1 - scroll_x; x = x1 - scroll_x;
/* without word-wrap */ /* without word-wrap */
if (!(widget->align & JI_WORDWRAP)) { if (!(widget->align() & JI_WORDWRAP)) {
end = ustrchr(beg, '\n'); end = ustrchr(beg, '\n');
if (end) { if (end) {
chr = *end; chr = *end;
@ -372,9 +372,9 @@ void _ji_theme_textbox_draw(BITMAP *bmp, JWidget widget,
if (bmp) { if (bmp) {
int xout; int xout;
if (widget->align & JI_CENTER) if (widget->align() & JI_CENTER)
xout = x + width/2 - len/2; xout = x + width/2 - len/2;
else if (widget->align & JI_RIGHT) else if (widget->align() & JI_RIGHT)
xout = x + width - len; xout = x + width - len;
else /* left */ else /* left */
xout = x; xout = x;

View File

@ -351,12 +351,12 @@ static bool tipwindow_msg_proc(JWidget widget, JMessage msg)
jdraw_rect(pos, makecol(0, 0, 0)); jdraw_rect(pos, makecol(0, 0, 0));
jrect_shrink(pos, 1); jrect_shrink(pos, 1);
jdraw_rectfill(pos, widget->bg_color); jdraw_rectfill(pos, widget->bg_color());
oldt = widget->border_width.t; oldt = widget->border_width.t;
widget->border_width.t = 3; widget->border_width.t = 3;
_ji_theme_textbox_draw(ji_screen, widget, NULL, NULL, _ji_theme_textbox_draw(ji_screen, widget, NULL, NULL,
widget->bg_color, widget->bg_color(),
ji_color_foreground()); ji_color_foreground());
widget->border_width.t = oldt; widget->border_width.t = oldt;

View File

@ -493,8 +493,8 @@ static bool scrollbar_msg_proc(JWidget widget, JMessage msg)
jtheme_scrollbar_info(widget, &pos, &len); jtheme_scrollbar_info(widget, &pos, &len);
view->wherepos = pos; view->wherepos = pos;
view->whereclick = widget->align & JI_HORIZONTAL ? msg->mouse.x: view->whereclick = widget->align() & JI_HORIZONTAL ? msg->mouse.x:
msg->mouse.y; msg->mouse.y;
x1 = widget->rc->x1; x1 = widget->rc->x1;
y1 = widget->rc->y1; y1 = widget->rc->y1;
@ -506,7 +506,7 @@ static bool scrollbar_msg_proc(JWidget widget, JMessage msg)
u2 = x2 - widget->border_width.r; u2 = x2 - widget->border_width.r;
v2 = y2 - widget->border_width.b; v2 = y2 - widget->border_width.b;
if (widget->align & JI_HORIZONTAL) { if (widget->align() & JI_HORIZONTAL) {
/* in the bar */ /* in the bar */
if (MOUSE_IN(u1+pos, v1, u1+pos+len-1, v2)) { if (MOUSE_IN(u1+pos, v1, u1+pos+len-1, v2)) {
/* capture mouse */ /* capture mouse */
@ -565,7 +565,7 @@ static bool scrollbar_msg_proc(JWidget widget, JMessage msg)
old_pos = pos; old_pos = pos;
if (bar_size > len) { if (bar_size > len) {
if (widget->align & JI_HORIZONTAL) { if (widget->align() & JI_HORIZONTAL) {
pos = (view->wherepos + msg->mouse.x - view->whereclick); pos = (view->wherepos + msg->mouse.x - view->whereclick);
pos = MID(0, pos, bar_size - len); pos = MID(0, pos, bar_size - len);
@ -610,7 +610,7 @@ static void scrollbar_info(JWidget widget, int *_pos, int *_len,
int pos, len, max, scroll; int pos, len, max, scroll;
int border_width; int border_width;
if (widget->align & JI_HORIZONTAL) { if (widget->align() & JI_HORIZONTAL) {
max = view->max_w; max = view->max_w;
scroll = view->scroll_x; scroll = view->scroll_x;
bar_size = jrect_w(widget->rc) bar_size = jrect_w(widget->rc)

View File

@ -58,104 +58,103 @@ int ji_register_widget_type()
/* creates a new widget with an unique JID */ /* creates a new widget with an unique JID */
JWidget jwidget_new(int type) JWidget jwidget_new(int type)
{ {
JWidget widget = _ji_get_new_widget(); return new jwidget(type);
if (!widget) }
return NULL;
widget->type = type; jwidget::jwidget(int type)
widget->name = NULL; {
widget->rc = jrect_new(0, 0, 0, 0); _ji_add_widget(this);
widget->border_width.l = 0;
widget->border_width.t = 0;
widget->border_width.r = 0;
widget->border_width.b = 0;
widget->child_spacing = 0;
widget->flags = 0;
widget->emit_signals = 0;
widget->min_w = 0;
widget->min_h = 0;
widget->max_w = INT_MAX;
widget->max_h = INT_MAX;
widget->children = jlist_new();
widget->parent = NULL;
widget->theme = ji_get_theme();
widget->hooks = jlist_new();
widget->draw_type = type;
widget->draw_method = NULL;
widget->align = 0; this->type = type;
widget->text_size = 0; this->name = NULL;
widget->text = NULL; this->rc = jrect_new(0, 0, 0, 0);
widget->text_size_pix = 0; this->border_width.l = 0;
widget->text_font = widget->theme ? widget->theme->default_font: NULL; this->border_width.t = 0;
widget->bg_color = -1; this->border_width.r = 0;
this->border_width.b = 0;
this->child_spacing = 0;
this->flags = 0;
this->emit_signals = 0;
this->min_w = 0;
this->min_h = 0;
this->max_w = INT_MAX;
this->max_h = INT_MAX;
this->children = jlist_new();
this->parent = NULL;
this->theme = ji_get_theme();
this->hooks = jlist_new();
this->draw_type = type;
this->draw_method = NULL;
widget->update_region = jregion_new(NULL, 0); this->m_align = 0;
this->m_text = "";
this->m_font = this->theme ? this->theme->default_font: NULL;
this->m_bg_color = -1;
widget->theme_data[0] = NULL; this->update_region = jregion_new(NULL, 0);
widget->theme_data[1] = NULL;
widget->theme_data[2] = NULL;
widget->theme_data[3] = NULL;
widget->user_data[0] = NULL; this->theme_data[0] = NULL;
widget->user_data[1] = NULL; this->theme_data[1] = NULL;
widget->user_data[2] = NULL; this->theme_data[2] = NULL;
widget->user_data[3] = NULL; this->theme_data[3] = NULL;
jwidget_add_hook(widget, JI_WIDGET, widget_msg_proc, NULL); this->user_data[0] = NULL;
this->user_data[1] = NULL;
this->user_data[2] = NULL;
this->user_data[3] = NULL;
return widget; jwidget_add_hook(this, JI_WIDGET, widget_msg_proc, NULL);
} }
void jwidget_free(JWidget widget) void jwidget_free(JWidget widget)
{
assert_valid_widget(widget);
delete widget;
}
jwidget::~jwidget()
{ {
JLink link, next; JLink link, next;
JMessage msg; JMessage msg;
assert_valid_widget(widget);
/* send destroy message */ /* send destroy message */
msg = jmessage_new(JM_DESTROY); msg = jmessage_new(JM_DESTROY);
jwidget_send_message(widget, msg); jwidget_send_message(this, msg);
jmessage_free(msg); jmessage_free(msg);
/* break relationship with the manager */ /* break relationship with the manager */
jmanager_free_widget(widget); jmanager_free_widget(this);
jmanager_remove_messages_for(widget); jmanager_remove_messages_for(this);
jmanager_remove_msg_filter_for(widget); jmanager_remove_msg_filter_for(this);
/* remove from parent */ /* remove from parent */
if (widget->parent) if (this->parent)
jwidget_remove_child(widget->parent, widget); jwidget_remove_child(this->parent, this);
/* remove children */ /* remove children */
JI_LIST_FOR_EACH_SAFE(widget->children, link, next) JI_LIST_FOR_EACH_SAFE(this->children, link, next)
jwidget_free(reinterpret_cast<JWidget>(link->data)); jwidget_free(reinterpret_cast<JWidget>(link->data));
jlist_free(widget->children); jlist_free(this->children);
/* destroy the update region */ /* destroy the update region */
if (widget->update_region) if (this->update_region)
jregion_free(widget->update_region); jregion_free(this->update_region);
/* destroy the text */
if (widget->text)
jfree(widget->text);
/* destroy the name */ /* destroy the name */
if (widget->name) if (this->name)
jfree(widget->name); jfree(this->name);
/* destroy widget position */ /* destroy widget position */
if (widget->rc) if (this->rc)
jrect_free(widget->rc); jrect_free(this->rc);
/* destroy hooks */ /* destroy hooks */
JI_LIST_FOR_EACH(widget->hooks, link) JI_LIST_FOR_EACH(this->hooks, link)
jhook_free(reinterpret_cast<JHook>(link->data)); jhook_free(reinterpret_cast<JHook>(link->data));
jlist_free(widget->hooks); jlist_free(this->hooks);
/* low level free */ /* low level free */
_ji_free_widget(widget); _ji_remove_widget(this);
} }
void jwidget_free_deferred(JWidget widget) void jwidget_free_deferred(JWidget widget)
@ -278,23 +277,7 @@ const char *jwidget_get_name(JWidget widget)
const char *jwidget_get_text(JWidget widget) const char *jwidget_get_text(JWidget widget)
{ {
assert_valid_widget(widget); assert_valid_widget(widget);
return widget->text();
jwidget_emit_signal(widget, JI_SIGNAL_GET_TEXT);
return widget->text;
}
int jwidget_get_align(JWidget widget)
{
assert_valid_widget(widget);
return widget->align;
}
FONT *jwidget_get_font(JWidget widget)
{
assert_valid_widget(widget);
return widget->text_font;
} }
void jwidget_set_name(JWidget widget, const char *name) void jwidget_set_name(JWidget widget, const char *name)
@ -311,61 +294,77 @@ void jwidget_set_text(JWidget widget, const char *text)
{ {
assert_valid_widget(widget); assert_valid_widget(widget);
jwidget_set_text_soft(widget, text); widget->set_text_quiet(text);
jwidget_emit_signal(widget, JI_SIGNAL_SET_TEXT); jwidget_emit_signal(widget, JI_SIGNAL_SET_TEXT);
jwidget_dirty(widget); jwidget_dirty(widget);
} }
void jwidget_set_text_soft(JWidget widget, const char *text)
{
assert_valid_widget(widget);
if (text) {
/* more space needed */
if (!widget->text || widget->text_size < strlen(text)+1) {
widget->text_size = strlen(text)+1;
widget->text = (char*)jrealloc(widget->text, widget->text_size);
}
/* copy the text string */
strcpy(widget->text, text);
if (widget->text_font)
widget->text_size_pix = ji_font_text_len(widget->text_font,
widget->text);
}
/* NULL text */
else if (widget->text) {
widget->text_size = 0;
jfree(widget->text);
widget->text = NULL;
}
}
void jwidget_set_align(JWidget widget, int align) void jwidget_set_align(JWidget widget, int align)
{ {
assert_valid_widget(widget); assert_valid_widget(widget);
widget->align = align; widget->align(align);
jwidget_dirty(widget);
} }
void jwidget_set_font(JWidget widget, FONT *font) int jwidget::text_int() const
{ {
assert_valid_widget(widget); return ustrtol(m_text.c_str(), NULL, 10);
}
widget->text_font = font; double jwidget::text_double() const
{
return ustrtod(m_text.c_str(), NULL);
}
if (widget->text && widget->text_font) void jwidget::textf(const char *format, ...)
widget->text_size_pix = ji_font_text_len(widget->text_font, {
widget->text); char buf[4096];
else
widget->text_size_pix = 0;
jwidget_emit_signal(widget, JI_SIGNAL_SET_FONT); // formatted string
jwidget_dirty(widget); if (format) {
va_list ap;
va_start(ap, format);
vsprintf(buf, format, ap);
va_end(ap);
}
// empty string
else {
ustrcpy(buf, empty_string);
}
text(buf);
}
void jwidget::set_text_quiet(const char *text)
{
if (text) {
m_text = text;
flags &= ~JI_NOTEXT;
}
else {
m_text.clear();
flags |= JI_NOTEXT;
}
}
void jwidget::align(int align)
{
m_align = align;
dirty();
}
FONT *jwidget::font()
{
return m_font;
}
void jwidget::font(FONT* f)
{
m_font = f;
jwidget_emit_signal(this, JI_SIGNAL_SET_FONT);
dirty();
} }
/**********************************************************************/ /**********************************************************************/
@ -953,10 +952,7 @@ int jwidget_get_bg_color(JWidget widget)
{ {
assert_valid_widget(widget); assert_valid_widget(widget);
if (widget->bg_color < 0 && widget->parent) return widget->bg_color();
return jwidget_get_bg_color(widget->parent);
else
return widget->bg_color;
} }
JTheme jwidget_get_theme(JWidget widget) JTheme jwidget_get_theme(JWidget widget)
@ -969,7 +965,7 @@ JTheme jwidget_get_theme(JWidget widget)
int jwidget_get_text_length(JWidget widget) int jwidget_get_text_length(JWidget widget)
{ {
#if 1 #if 1
return ji_font_text_len(widget->text_font, widget->text); return ji_font_text_len(widget->font(), widget->text());
#else /* use cached text size */ #else /* use cached text size */
return widget->text_size_pix; return widget->text_size_pix;
#endif #endif
@ -979,7 +975,7 @@ int jwidget_get_text_height(JWidget widget)
{ {
assert_valid_widget(widget); assert_valid_widget(widget);
return text_height(widget->text_font); return text_height(widget->font());
} }
void jwidget_get_texticon_info(JWidget widget, void jwidget_get_texticon_info(JWidget widget,
@ -1002,7 +998,7 @@ void jwidget_get_texticon_info(JWidget widget,
text_x = text_y = 0; text_x = text_y = 0;
/* size of the text */ /* size of the text */
if (widget->text) { if (widget->has_text()) {
text_w = jwidget_get_text_length(widget); text_w = jwidget_get_text_length(widget);
text_h = jwidget_get_text_height(widget); text_h = jwidget_get_text_height(widget);
} }
@ -1019,32 +1015,32 @@ void jwidget_get_texticon_info(JWidget widget,
/* with the icon in the top or bottom */ /* with the icon in the top or bottom */
else { else {
box_w = MAX(icon_w, text_w); box_w = MAX(icon_w, text_w);
box_h = icon_h + ((widget->text)? widget->child_spacing: 0) + text_h; box_h = icon_h + (widget->has_text() ? widget->child_spacing: 0) + text_h;
} }
} }
/* with the icon in left or right that doesn't care by now */ /* with the icon in left or right that doesn't care by now */
else { else {
box_w = icon_w + ((widget->text)? widget->child_spacing: 0) + text_w; box_w = icon_w + (widget->has_text() ? widget->child_spacing: 0) + text_w;
box_h = MAX(icon_h, text_h); box_h = MAX(icon_h, text_h);
} }
/* box position */ /* box position */
if (widget->align & JI_RIGHT) if (widget->align() & JI_RIGHT)
box_x = widget->rc->x2 - box_w - widget->border_width.r; box_x = widget->rc->x2 - box_w - widget->border_width.r;
else if (widget->align & JI_CENTER) else if (widget->align() & JI_CENTER)
box_x = (widget->rc->x1+widget->rc->x2)/2 - box_w/2; box_x = (widget->rc->x1+widget->rc->x2)/2 - box_w/2;
else else
box_x = widget->rc->x1 + widget->border_width.l; box_x = widget->rc->x1 + widget->border_width.l;
if (widget->align & JI_BOTTOM) if (widget->align() & JI_BOTTOM)
box_y = widget->rc->y2 - box_h - widget->border_width.b; box_y = widget->rc->y2 - box_h - widget->border_width.b;
else if (widget->align & JI_MIDDLE) else if (widget->align() & JI_MIDDLE)
box_y = (widget->rc->y1+widget->rc->y2)/2 - box_h/2; box_y = (widget->rc->y1+widget->rc->y2)/2 - box_h/2;
else else
box_y = widget->rc->y1 + widget->border_width.t; box_y = widget->rc->y1 + widget->border_width.t;
/* with text */ /* with text */
if (widget->text) { if (widget->has_text()) {
/* text/icon X position */ /* text/icon X position */
if (icon_align & JI_RIGHT) { if (icon_align & JI_RIGHT) {
text_x = box_x; text_x = box_x;
@ -1139,8 +1135,7 @@ void jwidget_set_max_size(JWidget widget, int w, int h)
void jwidget_set_bg_color(JWidget widget, int color) void jwidget_set_bg_color(JWidget widget, int color)
{ {
assert_valid_widget(widget); assert_valid_widget(widget);
widget->bg_color(color);
widget->bg_color = color;
} }
void jwidget_set_theme(JWidget widget, JTheme theme) void jwidget_set_theme(JWidget widget, JTheme theme)
@ -1149,7 +1144,7 @@ void jwidget_set_theme(JWidget widget, JTheme theme)
widget->theme = theme; widget->theme = theme;
/* TODO mmhhh... maybe some JStyle in JWidget should be great */ /* TODO mmhhh... maybe some JStyle in JWidget should be great */
widget->text_font = widget->theme ? widget->theme->default_font: NULL; widget->font(widget->theme ? widget->theme->default_font: NULL);
} }
/**********************************************************************/ /**********************************************************************/
@ -1499,10 +1494,12 @@ bool jwidget_check_underscored(JWidget widget, int scancode)
else else
return FALSE; return FALSE;
if (widget->text) { if (widget->has_text()) {
for (c=0; widget->text[c]; c++) const char* text = widget->text();
if ((widget->text[c] == '&') && (widget->text[c+1] != '&'))
if (ascii == tolower(widget->text[c+1])) for (c=0; text[c]; c++)
if ((text[c] == '&') && (text[c+1] != '&'))
if (ascii == tolower(text[c+1]))
return TRUE; return TRUE;
} }

View File

@ -34,6 +34,8 @@
#include "jinete/jbase.h" #include "jinete/jbase.h"
#include <string>
#ifndef NDEBUG #ifndef NDEBUG
#include "jinete/jintern.h" #include "jinete/jintern.h"
#define assert_valid_widget(widget) assert((widget) != NULL && \ #define assert_valid_widget(widget) assert((widget) != NULL && \
@ -45,57 +47,6 @@
struct FONT; struct FONT;
struct BITMAP; struct BITMAP;
struct jwidget
{
JID id; /* identify code */
int type; /* widget's type */
char *name; /* widget's name */
JRect rc; /* position rectangle */
struct {
int l, t, r, b;
} border_width; /* border separation with the parent */
int child_spacing; /* separation between children */
/* flags */
int flags;
int emit_signals; /* emit signal counter */
/* widget size limits */
int min_w, min_h;
int max_w, max_h;
/* structures */
JList children; /* sub-objects */
JWidget parent; /* who is the parent? */
JTheme theme; /* widget's theme */
/* virtual properties */
JList hooks; /* hooks with msg_proc and specific data */
int draw_type;
JDrawFunc draw_method; /* virtual method to draw the widget
(the default msg_proc uses it) */
/* common widget properties */
int align; /* widget alignment */
int text_size; /* text size (in characters) */
char *text; /* widget text */
int text_size_pix; /* cached text size in pixels */
struct FONT *text_font; /* text font type */
int bg_color; /* background color */
/* drawable cycle */
JRegion update_region; /* region to be redrawed */
/* more properties... */
/* for JTheme */
void *theme_data[4];
/* for user */
void *user_data[4];
};
int ji_register_widget_type(); int ji_register_widget_type();
JWidget jwidget_new(int type); JWidget jwidget_new(int type);
@ -116,14 +67,10 @@ void *jwidget_get_data(JWidget widget, int type);
int jwidget_get_type(JWidget widget); int jwidget_get_type(JWidget widget);
const char *jwidget_get_name(JWidget widget); const char *jwidget_get_name(JWidget widget);
const char *jwidget_get_text(JWidget widget); const char *jwidget_get_text(JWidget widget);
int jwidget_get_align(JWidget widget);
struct FONT *jwidget_get_font(JWidget widget);
void jwidget_set_name(JWidget widget, const char *name); void jwidget_set_name(JWidget widget, const char *name);
void jwidget_set_text(JWidget widget, const char *text); void jwidget_set_text(JWidget widget, const char *text);
void jwidget_set_text_soft(JWidget widget, const char *text);
void jwidget_set_align(JWidget widget, int align); void jwidget_set_align(JWidget widget, int align);
void jwidget_set_font(JWidget widget, struct FONT *font);
/* behavior properties */ /* behavior properties */
@ -233,4 +180,105 @@ void jwidget_release_mouse(JWidget widget);
JWidget jwidget_find_name(JWidget widget, const char *name); JWidget jwidget_find_name(JWidget widget, const char *name);
bool jwidget_check_underscored(JWidget widget, int scancode); bool jwidget_check_underscored(JWidget widget, int scancode);
//////////////////////////////////////////////////////////////////////
class jwidget
{
public:
JID id; /* identify code */
int type; /* widget's type */
char *name; /* widget's name */
JRect rc; /* position rectangle */
struct {
int l, t, r, b;
} border_width; /* border separation with the parent */
int child_spacing; /* separation between children */
/* flags */
int flags;
int emit_signals; /* emit signal counter */
/* widget size limits */
int min_w, min_h;
int max_w, max_h;
/* structures */
JList children; /* sub-objects */
JWidget parent; /* who is the parent? */
JTheme theme; /* widget's theme */
/* virtual properties */
JList hooks; /* hooks with msg_proc and specific data */
int draw_type;
JDrawFunc draw_method; /* virtual method to draw the widget
(the default msg_proc uses it) */
/* 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
public:
/* drawable cycle */
JRegion update_region; /* region to be redrawed */
/* more properties... */
/* for JTheme */
void *theme_data[4];
/* for user */
void *user_data[4];
//////////////////////////////////////////////////////////////////////
// Methods
jwidget(int type);
~jwidget();
bool has_text() { return flags & JI_NOTEXT ? false: true; }
const char* text() const { return m_text.c_str(); }
int text_int() const;
double text_double() const;
void text(const char* text) { jwidget_set_text(this, text); }
size_t text_size() const { return m_text.size(); }
void textf(const char* text, ...);
void set_text_quiet(const char* text);
bool selected() { return jwidget_is_selected(this); }
void selected(bool state) { jwidget_set_selected(this, state); }
int align() const { return m_align; }
void align(int align);
struct FONT* font();
void font(struct FONT* font);
int bg_color()
{
if (m_bg_color < 0 && parent)
return parent->bg_color();
else
return m_bg_color;
}
void bg_color(int bg_color)
{
m_bg_color = bg_color;
}
// Returns a widget in the same window that is located "sibling".
inline JWidget find_sibling(const char* name)
{
return jwidget_find_name(jwidget_get_window(this), name);
}
void dirty() { jwidget_dirty(this); }
};
#endif /* JINETE_WIDGET_H */ #endif /* JINETE_WIDGET_H */

View File

@ -234,7 +234,7 @@ bool jwindow_is_toplevel(JWidget widget)
if (!jlist_empty(manager->children)) if (!jlist_empty(manager->children))
return (widget == jlist_first(manager->children)->data); return (widget == jlist_first(manager->children)->data);
else else
return FALSE; return false;
} }
bool jwindow_is_foreground(JWidget widget) bool jwindow_is_foreground(JWidget widget)
@ -493,7 +493,7 @@ static void window_request_size(JWidget widget, int *w, int *h)
} }
} }
if (widget->text) if (widget->has_text())
max_w = MAX(max_w, jwidget_get_text_length(widget)); max_w = MAX(max_w, jwidget_get_text_length(widget));
*w = widget->border_width.l + max_w + widget->border_width.r; *w = widget->border_width.l + max_w + widget->border_width.r;
@ -538,7 +538,7 @@ static int get_action(JWidget widget, int x, int y)
cpos = jwidget_get_child_rect(widget); cpos = jwidget_get_child_rect(widget);
/* move */ /* move */
if ((widget->text) if ((widget->has_text())
&& (((x >= cpos->x1) && && (((x >= cpos->x1) &&
(x < cpos->x2) && (x < cpos->x2) &&
(y >= pos->y1+widget->border_width.b) && (y >= pos->y1+widget->border_width.b) &&

View File

@ -374,12 +374,12 @@ static void theme_init_widget(JWidget widget)
case JI_SEPARATOR: case JI_SEPARATOR:
/* frame */ /* frame */
if ((widget->align & JI_HORIZONTAL) && if ((widget->align() & JI_HORIZONTAL) &&
(widget->align & JI_VERTICAL)) { (widget->align() & JI_VERTICAL)) {
BORDER(4); BORDER(4);
} }
/* horizontal bar */ /* horizontal bar */
else if (widget->align & JI_HORIZONTAL) { else if (widget->align() & JI_HORIZONTAL) {
BORDER4(2, 4, 2, 0); BORDER4(2, 4, 2, 0);
} }
/* vertical bar */ /* vertical bar */
@ -387,10 +387,10 @@ static void theme_init_widget(JWidget widget)
BORDER4(4, 2, 0, 2); BORDER4(4, 2, 0, 2);
} }
if (widget->text) { if (widget->has_text()) {
if (widget->align & JI_TOP) if (widget->align() & JI_TOP)
widget->border_width.t = jwidget_get_text_height(widget); widget->border_width.t = jwidget_get_text_height(widget);
else if (widget->align & JI_BOTTOM) else if (widget->align() & JI_BOTTOM)
widget->border_width.b = jwidget_get_text_height(widget); widget->border_width.b = jwidget_get_text_height(widget);
} }
break; break;
@ -422,7 +422,7 @@ static void theme_init_widget(JWidget widget)
case JI_WINDOW: case JI_WINDOW:
if (!jwindow_is_desktop(widget)) { if (!jwindow_is_desktop(widget)) {
if (widget->text) { if (widget->has_text()) {
BORDER4(6, 4+jwidget_get_text_height(widget)+6, 6, 6); BORDER4(6, 4+jwidget_get_text_height(widget)+6, 6, 6);
#if 1 /* add close button */ #if 1 /* add close button */
if (!(widget->flags & JI_INITIALIZED)) { if (!(widget->flags & JI_INITIALIZED)) {
@ -662,7 +662,7 @@ static void theme_draw_entry(JWidget widget, JRect clip)
{ {
bool password = jentry_is_password(widget); bool password = jentry_is_password(widget);
int scroll, cursor, state, selbeg, selend; int scroll, cursor, state, selbeg, selend;
const char *text = widget->text; const char *text = widget->text();
int c, ch, x, y, w, fg, bg; int c, ch, x, y, w, fg, bg;
int x1, y1, x2, y2; int x1, y1, x2, y2;
int cursor_x; int cursor_x;
@ -696,7 +696,7 @@ static void theme_draw_entry(JWidget widget, JRect clip)
x = widget->rc->x1 + widget->border_width.l; x = widget->rc->x1 + widget->border_width.l;
y = (widget->rc->y1+widget->rc->y2)/2 - jwidget_get_text_height(widget)/2; y = (widget->rc->y1+widget->rc->y2)/2 - jwidget_get_text_height(widget)/2;
for (c=scroll; ugetat (text, c); c++) { for (c=scroll; ugetat(text, c); c++) {
ch = password ? '*': ugetat(text, c); ch = password ? '*': ugetat(text, c);
/* normal text */ /* normal text */
@ -718,15 +718,14 @@ static void theme_draw_entry(JWidget widget, JRect clip)
fg = COLOR_DISABLED; fg = COLOR_DISABLED;
} }
w = CHARACTER_LENGTH(widget->text_font, ch); w = CHARACTER_LENGTH(widget->font(), ch);
if (x+w > widget->rc->x2-3) if (x+w > widget->rc->x2-3)
return; return;
cursor_x = x; cursor_x = x;
ji_font_set_aa_mode(widget->text_font, ji_font_set_aa_mode(widget->font(), bg >= 0 ? bg: COLOR_BACKGROUND);
bg >= 0 ? bg: COLOR_BACKGROUND); widget->font()->vtable->render_char(widget->font(),
widget->text_font->vtable->render_char(widget->text_font, ch, fg, bg, ji_screen, x, y);
ch, fg, bg, ji_screen, x, y);
x += w; x += w;
/* cursor */ /* cursor */
@ -783,9 +782,9 @@ static void theme_draw_listitem(JWidget widget, JRect clip)
x = widget->rc->x1+widget->border_width.l; x = widget->rc->x1+widget->border_width.l;
y = widget->rc->y1+widget->border_width.t; y = widget->rc->y1+widget->border_width.t;
if (widget->text) { if (widget->has_text()) {
/* text */ /* text */
jdraw_text(widget->text_font, widget->text, x, y, fg, bg, TRUE); jdraw_text(widget->font(), widget->text(), x, y, fg, bg, TRUE);
/* background */ /* background */
jrectexclude jrectexclude
@ -864,9 +863,9 @@ static void theme_draw_menuitem(JWidget widget, JRect clip)
/* text */ /* text */
if (bar) if (bar)
widget->align = JI_CENTER | JI_MIDDLE; widget->align(JI_CENTER | JI_MIDDLE);
else else
widget->align = JI_LEFT | JI_MIDDLE; widget->align(JI_LEFT | JI_MIDDLE);
pos = jwidget_get_rect(widget); pos = jwidget_get_rect(widget);
if (!bar) if (!bar)
@ -902,7 +901,7 @@ static void theme_draw_menuitem(JWidget widget, JRect clip)
} }
/* draw the keyboard shortcut */ /* draw the keyboard shortcut */
else if (jmenuitem_get_accel(widget)) { else if (jmenuitem_get_accel(widget)) {
int old_align = widget->align; int old_align = widget->align();
char buf[256]; char buf[256];
pos = jwidget_get_rect(widget); pos = jwidget_get_rect(widget);
@ -910,9 +909,9 @@ static void theme_draw_menuitem(JWidget widget, JRect clip)
jaccel_to_string(jmenuitem_get_accel(widget), buf); jaccel_to_string(jmenuitem_get_accel(widget), buf);
widget->align = JI_RIGHT | JI_MIDDLE; widget->align(JI_RIGHT | JI_MIDDLE);
draw_textstring(buf, fg, bg, FALSE, widget, pos, 0); draw_textstring(buf, fg, bg, FALSE, widget, pos, 0);
widget->align = old_align; widget->align(old_align);
jrect_free(pos); jrect_free(pos);
} }
@ -937,7 +936,7 @@ static void theme_draw_panel(JWidget widget, JRect clip)
c1 = (JWidget)link->data; c1 = (JWidget)link->data;
c2 = (JWidget)link->next->data; c2 = (JWidget)link->next->data;
if (widget->align & JI_HORIZONTAL) { if (widget->align() & JI_HORIZONTAL) {
/* vline(ji_screen, */ /* vline(ji_screen, */
/* (c1->pos->x+c1->pos->w+c2->pos->x-1)/2, */ /* (c1->pos->x+c1->pos->w+c2->pos->x-1)/2, */
/* widget->rect->y, */ /* widget->rect->y, */
@ -1018,20 +1017,20 @@ static void theme_draw_separator(JWidget widget, JRect clip)
jdraw_rectfill(widget->rc, BGCOLOR); jdraw_rectfill(widget->rc, BGCOLOR);
/* TOP line */ /* TOP line */
if (widget->align & JI_HORIZONTAL) { if (widget->align() & JI_HORIZONTAL) {
hline(ji_screen, x1, y1-1, x2, COLOR_DISABLED); hline(ji_screen, x1, y1-1, x2, COLOR_DISABLED);
hline(ji_screen, x1, y1, x2, COLOR_BACKGROUND); hline(ji_screen, x1, y1, x2, COLOR_BACKGROUND);
} }
/* LEFT line */ /* LEFT line */
if (widget->align & JI_VERTICAL) { if (widget->align() & JI_VERTICAL) {
vline(ji_screen, x1-1, y1, y2, COLOR_DISABLED); vline(ji_screen, x1-1, y1, y2, COLOR_DISABLED);
vline(ji_screen, x1, y1, y2, COLOR_BACKGROUND); vline(ji_screen, x1, y1, y2, COLOR_BACKGROUND);
} }
/* frame */ /* frame */
if ((widget->align & JI_HORIZONTAL) && if ((widget->align() & JI_HORIZONTAL) &&
(widget->align & JI_VERTICAL)) { (widget->align() & JI_VERTICAL)) {
/* union between the LEFT and TOP lines */ /* union between the LEFT and TOP lines */
putpixel(ji_screen, x1-1, y1-1, COLOR_DISABLED); putpixel(ji_screen, x1-1, y1-1, COLOR_DISABLED);
@ -1048,7 +1047,7 @@ static void theme_draw_separator(JWidget widget, JRect clip)
} }
/* text */ /* text */
if (widget->text) { if (widget->has_text()) {
int h = jwidget_get_text_height(widget); int h = jwidget_get_text_height(widget);
struct jrect r = { x1+h/2, y1-h/2, x2+1-h, y2+1+h }; struct jrect r = { x1+h/2, y1-h/2, x2+1-h, y2+1+h };
draw_textstring(NULL, -1, BGCOLOR, FALSE, widget, &r, 0); draw_textstring(NULL, -1, BGCOLOR, FALSE, widget, &r, 0);
@ -1141,14 +1140,14 @@ static void theme_draw_slider(JWidget widget, JRect clip)
/* text */ /* text */
{ {
char *old_text = widget->text; std::string old_text = widget->text();
int cx1, cy1, cx2, cy2; int cx1, cy1, cx2, cy2;
JRect r; JRect r;
usprintf(buf, "%d", value); usprintf(buf, "%d", value);
widget->align = JI_CENTER | JI_MIDDLE; widget->align(JI_CENTER | JI_MIDDLE);
widget->text = buf; widget->text(buf);
r = jrect_new(x1, y1, x2+1, y2+1); r = jrect_new(x1, y1, x2+1, y2+1);
@ -1173,7 +1172,7 @@ static void theme_draw_slider(JWidget widget, JRect clip)
set_clip(ji_screen, cx1, cy1, cx2, cy2); set_clip(ji_screen, cx1, cy1, cx2, cy2);
widget->text = old_text; widget->text(old_text.c_str());
jrect_free(r); jrect_free(r);
} }
} }
@ -1233,7 +1232,7 @@ static void theme_draw_view_scrollbar(JWidget widget, JRect clip)
x1++, y1++, x2--, y2--; x1++, y1++, x2--, y2--;
/* horizontal bar */ /* horizontal bar */
if (widget->align & JI_HORIZONTAL) { if (widget->align() & JI_HORIZONTAL) {
u1 = x1+pos; u1 = x1+pos;
v1 = y1; v1 = y1;
u2 = x1+pos+len-1; u2 = x1+pos+len-1;
@ -1287,7 +1286,7 @@ static void theme_draw_window(JWidget widget, JRect clip)
jdraw_rectfill(pos, BGCOLOR); jdraw_rectfill(pos, BGCOLOR);
/* draw title bar */ /* draw title bar */
if (widget->text) { if (widget->has_text()) {
int bg = COLOR_SELECTED; int bg = COLOR_SELECTED;
jrect_shrink(pos, 1); jrect_shrink(pos, 1);
@ -1298,10 +1297,10 @@ static void theme_draw_window(JWidget widget, JRect clip)
jrect_stretch(pos, 1); jrect_stretch(pos, 1);
jdraw_rectedge(cpos, COLOR_DISABLED, COLOR_BACKGROUND); jdraw_rectedge(cpos, COLOR_DISABLED, COLOR_BACKGROUND);
jdraw_text(widget->text_font, widget->text, jdraw_text(widget->font(), widget->text(),
cpos->x1, cpos->x1,
pos->y1+jrect_h(pos)/2-text_height(widget->text_font)/2, pos->y1+jrect_h(pos)/2-text_height(widget->font())/2,
COLOR_BACKGROUND, bg, FALSE); COLOR_BACKGROUND, bg, FALSE);
} }
} }
/* desktop */ /* desktop */
@ -1326,33 +1325,33 @@ static void draw_textstring(const char *t, int fg_color, int bg_color,
bool fill_bg, JWidget widget, const JRect rect, bool fill_bg, JWidget widget, const JRect rect,
int selected_offset) int selected_offset)
{ {
if (t || widget->text) { if (t || widget->has_text()) {
int x, y, w, h; int x, y, w, h;
if (!t) { if (!t) {
t = widget->text; t = widget->text();
w = jwidget_get_text_length(widget); w = jwidget_get_text_length(widget);
h = jwidget_get_text_height(widget); h = jwidget_get_text_height(widget);
} }
else { else {
w = ji_font_text_len(widget->text_font, t); w = ji_font_text_len(widget->font(), t);
h = text_height(widget->text_font); h = text_height(widget->font());
} }
/* horizontally text alignment */ /* horizontally text alignment */
if (widget->align & JI_RIGHT) if (widget->align() & JI_RIGHT)
x = rect->x2 - w; x = rect->x2 - w;
else if (widget->align & JI_CENTER) else if (widget->align() & JI_CENTER)
x = (rect->x1+rect->x2)/2 - w/2; x = (rect->x1+rect->x2)/2 - w/2;
else else
x = rect->x1; x = rect->x1;
/* vertically text alignment */ /* vertically text alignment */
if (widget->align & JI_BOTTOM) if (widget->align() & JI_BOTTOM)
y = rect->y2 - h; y = rect->y2 - h;
else if (widget->align & JI_MIDDLE) else if (widget->align() & JI_MIDDLE)
y = (rect->y1+rect->y2)/2 - h/2; y = (rect->y1+rect->y2)/2 - h/2;
else else
y = rect->y1; y = rect->y1;
@ -1374,17 +1373,17 @@ static void draw_textstring(const char *t, int fg_color, int bg_color,
if (jwidget_is_disabled (widget)) { if (jwidget_is_disabled (widget)) {
/* TODO avoid this */ /* TODO avoid this */
if (fill_bg) /* only to draw the background */ if (fill_bg) /* only to draw the background */
jdraw_text(widget->text_font, t, x, y, 0, bg_color, fill_bg); jdraw_text(widget->font(), t, x, y, 0, bg_color, fill_bg);
/* draw white part */ /* draw white part */
jdraw_text(widget->text_font, t, x+1, y+1, jdraw_text(widget->font(), t, x+1, y+1,
COLOR_BACKGROUND, bg_color, fill_bg); COLOR_BACKGROUND, bg_color, fill_bg);
if (fill_bg) if (fill_bg)
fill_bg = FALSE; fill_bg = FALSE;
} }
jdraw_text(widget->text_font, t, x, y, jdraw_text(widget->font(), t, x, y,
jwidget_is_disabled(widget) ? jwidget_is_disabled(widget) ?
COLOR_DISABLED: (fg_color >= 0 ? fg_color : COLOR_DISABLED: (fg_color >= 0 ? fg_color :
COLOR_FOREGROUND), COLOR_FOREGROUND),

View File

@ -235,11 +235,11 @@ static void colorbutton_draw(JWidget widget)
color_to_formalstring(colorbutton->imgtype, color_to_formalstring(colorbutton->imgtype,
colorbutton->color, buf, sizeof(buf), FALSE); colorbutton->color, buf, sizeof(buf), FALSE);
jwidget_set_text_soft(widget, buf); widget->set_text_quiet(buf);
jwidget_get_texticon_info(widget, &box, &text, &icon, 0, 0, 0); jwidget_get_texticon_info(widget, &box, &text, &icon, 0, 0, 0);
rectfill(ji_screen, text.x1, text.y1, text.x2-1, text.y2-1, makecol(0, 0, 0)); rectfill(ji_screen, text.x1, text.y1, text.x2-1, text.y2-1, makecol(0, 0, 0));
jdraw_text(widget->text_font, widget->text, text.x1, text.y1, jdraw_text(widget->font(), widget->text(), text.x1, text.y1,
makecol(255, 255, 255), makecol(255, 255, 255),
makecol(0, 0, 0), FALSE); makecol(0, 0, 0), FALSE);
} }

View File

@ -117,7 +117,7 @@ JWidget colorselector_new(bool editable_palette)
add_gfxicon_to_button(lock, GFX_BOX_LOCK, JI_CENTER | JI_MIDDLE); add_gfxicon_to_button(lock, GFX_BOX_LOCK, JI_CENTER | JI_MIDDLE);
/* tabs */ /* tabs */
jwidget_set_bg_color(tabs, window->bg_color); jwidget_set_bg_color(tabs, window->bg_color());
/* data for a better layout */ /* data for a better layout */
grid1->child_spacing = 0; grid1->child_spacing = 0;
@ -278,7 +278,7 @@ static bool colorselector_msg_proc(JWidget widget, JMessage msg)
JWidget idx = jwidget_find_name(widget, "idx"); JWidget idx = jwidget_find_name(widget, "idx");
JWidget pal = jwidget_find_name(widget, "pal"); JWidget pal = jwidget_find_name(widget, "pal");
JWidget grid2 = jwidget_find_name(widget, "grid2"); JWidget grid2 = jwidget_find_name(widget, "grid2");
int idxlen = ji_font_text_len(jwidget_get_font(idx), "Index=888"); int idxlen = ji_font_text_len(idx->font(), "Index=888");
jwidget_set_min_size(idx, idxlen, 0); jwidget_set_min_size(idx, idxlen, 0);
paledit_set_boxsize(pal, 4*guiscale()); paledit_set_boxsize(pal, 4*guiscale());

View File

@ -105,7 +105,7 @@ static bool colorviewer_msg_proc(JWidget widget, JMessage msg)
break; break;
case JM_REQSIZE: { case JM_REQSIZE: {
msg->reqsize.w = ji_font_text_len(widget->text_font, "255,255,255,255"); msg->reqsize.w = ji_font_text_len(widget->font(), "255,255,255,255");
msg->reqsize.h = jwidget_get_text_height(widget); msg->reqsize.h = jwidget_get_text_height(widget);
msg->reqsize.w += widget->border_width.l + widget->border_width.r; msg->reqsize.w += widget->border_width.l + widget->border_width.r;
@ -137,11 +137,11 @@ static bool colorviewer_msg_proc(JWidget widget, JMessage msg)
color_to_formalstring(colorviewer->imgtype, color_to_formalstring(colorviewer->imgtype,
colorviewer->color, buf, sizeof(buf), FALSE); colorviewer->color, buf, sizeof(buf), FALSE);
jwidget_set_text_soft(widget, buf); widget->set_text_quiet(buf);
jwidget_get_texticon_info(widget, &box, &text, &icon, 0, 0, 0); jwidget_get_texticon_info(widget, &box, &text, &icon, 0, 0, 0);
jdraw_rectfill(&text, makecol(0, 0, 0)); jdraw_rectfill(&text, makecol(0, 0, 0));
jdraw_text(widget->text_font, widget->text, text.x1, text.y1, jdraw_text(widget->font(), widget->text(), text.x1, text.y1,
makecol(255, 255, 255), makecol(0, 0, 0), FALSE); makecol(255, 255, 255), makecol(0, 0, 0), FALSE);
jrect_free(rect); jrect_free(rect);

View File

@ -332,7 +332,6 @@ void editor_draw_sprite(JWidget widget, int x1, int y1, int x2, int y2)
image_free(rendered); image_free(rendered);
destroy_bitmap(bmp); destroy_bitmap(bmp);
#else #else
acquire_bitmap(ji_screen); acquire_bitmap(ji_screen);
use_current_sprite_rgb_map(); use_current_sprite_rgb_map();

View File

@ -284,10 +284,10 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg)
x = widget->rc->x1+2; x = widget->rc->x1+2;
if (fileitem_is_folder(fi)) { if (fileitem_is_folder(fi)) {
int icon_w = ji_font_text_len(widget->text_font, "[+]"); int icon_w = ji_font_text_len(widget->font(), "[+]");
int icon_h = ji_font_get_size(widget->text_font); int icon_h = ji_font_get_size(widget->font());
jdraw_text(widget->text_font, jdraw_text(widget->font(),
"[+]", x, y+2, "[+]", x, y+2,
fgcolor, bgcolor, TRUE); fgcolor, bgcolor, TRUE);
@ -314,7 +314,7 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg)
} }
/* item name */ /* item name */
jdraw_text(widget->text_font, jdraw_text(widget->font(),
fileitem_get_displayname(fi).c_str(), x, y+2, fileitem_get_displayname(fi).c_str(), x, y+2,
fgcolor, bgcolor, TRUE); fgcolor, bgcolor, TRUE);
@ -325,9 +325,9 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg)
widget->rc->x2-1, y+2+th+2-1, widget->rc->x2-1, y+2+th+2-1,
/* exclude where is the text located */ /* exclude where is the text located */
x, y+2, x, y+2,
x+ji_font_text_len(widget->text_font, x+ji_font_text_len(widget->font(),
fileitem_get_displayname(fi).c_str())-1, fileitem_get_displayname(fi).c_str())-1,
y+2+ji_font_get_size(widget->text_font)-1, y+2+ji_font_get_size(widget->font())-1,
/* fill with the background color */ /* fill with the background color */
bgcolor); bgcolor);
@ -571,10 +571,10 @@ static void fileview_get_fileitem_size(JWidget widget, FileItem *fi, int *w, int
int len = 0; int len = 0;
if (fileitem_is_folder(fi)) { if (fileitem_is_folder(fi)) {
len += ji_font_text_len(widget->text_font, "[+]")+2; len += ji_font_text_len(widget->font(), "[+]")+2;
} }
len += ji_font_text_len(widget->text_font, len += ji_font_text_len(widget->font(),
fileitem_get_displayname(fi).c_str()); fileitem_get_displayname(fi).c_str());
/* if (!fileitem_is_folder(fi)) { */ /* if (!fileitem_is_folder(fi)) { */

View File

@ -141,10 +141,7 @@ void statusbar_set_text(JWidget widget, int msecs, const char *format, ...)
vsprintf(buf, format, ap); vsprintf(buf, format, ap);
va_end(ap); va_end(ap);
if (widget->text) widget->text(buf);
jfree(widget->text);
widget->text = jstrdup(buf);
statusbar->timeout = ji_clock + msecs; statusbar->timeout = ji_clock + msecs;
jwidget_dirty(widget); jwidget_dirty(widget);
} }
@ -283,12 +280,12 @@ static bool statusbar_msg_proc(JWidget widget, JMessage msg)
jrect_shrink(rc, 1); jrect_shrink(rc, 1);
/* status bar text */ /* status bar text */
if (widget->text) { if (widget->text()) {
jdraw_rectfill(rc, ji_color_face()); jdraw_rectfill(rc, ji_color_face());
textout_ex(ji_screen, widget->text_font, widget->text, textout_ex(ji_screen, widget->font(), widget->text(),
rc->x1+2, rc->x1+2,
(widget->rc->y1+widget->rc->y2)/2-text_height(widget->text_font)/2, (widget->rc->y1+widget->rc->y2)/2-text_height(widget->font())/2,
ji_color_foreground(), -1); ji_color_foreground(), -1);
} }
@ -332,9 +329,9 @@ static bool statusbar_msg_proc(JWidget widget, JMessage msg)
buf+ustrsize(buf), buf+ustrsize(buf),
sizeof(buf)-ustrsize(buf)); sizeof(buf)-ustrsize(buf));
textout_right_ex(ji_screen, widget->text_font, buf, textout_right_ex(ji_screen, widget->font(), buf,
rc->x2-2, rc->x2-2,
(widget->rc->y1+widget->rc->y2)/2-text_height(widget->text_font)/2, (widget->rc->y1+widget->rc->y2)/2-text_height(widget->font())/2,
ji_color_foreground(), -1); ji_color_foreground(), -1);
} }

View File

@ -29,7 +29,7 @@
#include "widgets/tabs.h" #include "widgets/tabs.h"
#define CALC_TAB_WIDTH(widget, tab) \ #define CALC_TAB_WIDTH(widget, tab) \
(4 + text_length(widget->text_font, tab->text) + 4) (4 + text_length(widget->font(), tab->text) + 4)
#define ARROW_W 12 #define ARROW_W 12
@ -249,7 +249,7 @@ static bool tabs_msg_proc(JWidget widget, JMessage msg)
bottom = ji_color_facelight(); bottom = ji_color_facelight();
} }
hline(ji_screen, box->x1, box->y1, box->x2-1, widget->bg_color); hline(ji_screen, box->x1, box->y1, box->x2-1, widget->bg_color());
rectfill(ji_screen, box->x1+1, box->y1+1, box->x2-2, box->y2-1, face); rectfill(ji_screen, box->x1+1, box->y1+1, box->x2-2, box->y2-1, face);
hline(ji_screen, box->x1, rect->y2-1, box->x2-1, ji_color_selected()); hline(ji_screen, box->x1, rect->y2-1, box->x2-1, ji_color_selected());
@ -258,9 +258,9 @@ static bool tabs_msg_proc(JWidget widget, JMessage msg)
ji_color_faceshadow(), ji_color_faceshadow(),
bottom); bottom);
jdraw_text(widget->text_font, tab->text, jdraw_text(widget->font(), tab->text,
box->x1+4, box->x1+4,
(box->y1+box->y2)/2-text_height(widget->text_font)/2, (box->y1+box->y2)/2-text_height(widget->font())/2,
fg, face, FALSE); fg, face, FALSE);
} }
@ -270,7 +270,7 @@ static bool tabs_msg_proc(JWidget widget, JMessage msg)
/* fill the gap to the right-side */ /* fill the gap to the right-side */
if (box->x1 < rect->x2) { if (box->x1 < rect->x2) {
rectfill(ji_screen, box->x1, rect->y1, rect->x2-1, rect->y2-3, rectfill(ji_screen, box->x1, rect->y1, rect->x2-1, rect->y2-3,
widget->bg_color); widget->bg_color());
hline(ji_screen, box->x1, rect->y2-2, rect->x2-1, ji_color_facelight()); hline(ji_screen, box->x1, rect->y2-2, rect->x2-1, ji_color_facelight());
hline(ji_screen, box->x1, rect->y2-1, rect->x2-1, ji_color_selected()); hline(ji_screen, box->x1, rect->y2-1, rect->x2-1, ji_color_selected());
} }