diff --git a/src/app.cpp b/src/app.cpp index 6f5b39530..419713d37 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -106,17 +106,17 @@ public: App* App::m_instance = NULL; -static JWidget top_window = NULL; /* top level window (the desktop) */ -static JWidget box_menubar = NULL; /* box where the menu bar is */ -static JWidget box_colorbar = NULL; /* box where the color bar is */ -static JWidget box_toolbar = NULL; /* box where the tools bar is */ -static JWidget box_statusbar = NULL; /* box where the status bar is */ -static JWidget box_tabsbar = NULL; /* box where the tabs bar is */ -static JWidget menubar = NULL; /* the menu bar widget */ -static JWidget statusbar = NULL; /* the status bar widget */ -static JWidget colorbar = NULL; /* the color bar widget */ -static JWidget toolbar = NULL; /* the tool bar widget */ -static JWidget tabsbar = NULL; /* the tabs bar widget */ +static Frame* top_window = NULL; /* top level window (the desktop) */ +static Widget* box_menubar = NULL; /* box where the menu bar is */ +static Widget* box_colorbar = NULL; /* box where the color bar is */ +static Widget* box_toolbar = NULL; /* box where the tools bar is */ +static Widget* box_statusbar = NULL; /* box where the status bar is */ +static Widget* box_tabsbar = NULL; /* box where the tabs bar is */ +static Widget* menubar = NULL; /* the menu bar widget */ +static Widget* statusbar = NULL; /* the status bar widget */ +static Widget* colorbar = NULL; /* the color bar widget */ +static Widget* toolbar = NULL; /* the tool bar widget */ +static Widget* tabsbar = NULL; /* the tabs bar widget */ static char *palette_filename = NULL; @@ -192,7 +192,7 @@ int App::run() { /* initialize GUI interface */ if (ase_mode & MODE_GUI) { - JWidget view, editor; + Widget* view, *editor; PRINTF("GUI mode\n"); @@ -200,8 +200,8 @@ int App::run() jmouse_set_cursor(JI_CURSOR_NORMAL); jmanager_refresh_screen(); - /* load main window */ - top_window = load_widget("main.jid", "main_window"); + // load main window + top_window = static_cast(load_widget("main.jid", "main_window")); if (!top_window) { allegro_message("Error loading data data/jids/main.jid file.\n" "You have to reinstall the program.\n"); @@ -217,7 +217,7 @@ int App::run() menubar = jmenubar_new(); statusbar = statusbar_new(); - colorbar = colorbar_new(box_colorbar->align()); + colorbar = colorbar_new(box_colorbar->getAlign()); toolbar = toolbar_new(); tabsbar = tabs_new(tabsbar_select_callback); view = editor_view_new(); @@ -249,7 +249,7 @@ int App::run() if (box_tabsbar) jwidget_add_child(box_tabsbar, tabsbar); /* prepare the window */ - jwindow_remap(top_window); + top_window->remap_window(); /* rebuild menus */ app_realloc_sprite_list(); @@ -259,7 +259,7 @@ int App::run() set_current_editor(editor); /* open the window */ - jwindow_open(top_window); + top_window->open_window(); /* refresh the screen */ jmanager_refresh_screen(); @@ -338,7 +338,7 @@ int App::run() module should destroy it) */ jmenubar_set_menu(menubar, NULL); - /* destroy the top-window */ + // destroy the top-window jwidget_free(top_window); top_window = NULL; } @@ -451,8 +451,8 @@ void app_realloc_sprite_list() */ bool app_realloc_recent_list() { - JWidget list_menuitem = get_recent_list_menuitem(); - JWidget menuitem; + Widget* list_menuitem = get_recent_list_menuitem(); + Widget* menuitem; /* update the recent file list menu item */ if (list_menuitem) { @@ -461,7 +461,7 @@ bool app_realloc_recent_list() Command *cmd_open_file = CommandsModule::instance()->get_command_by_name(CommandId::open_file); - JWidget submenu = jmenuitem_get_submenu(list_menuitem); + Widget* submenu = jmenuitem_get_submenu(list_menuitem); if (submenu) { jmenuitem_set_submenu(list_menuitem, NULL); jwidget_free(submenu); @@ -508,12 +508,12 @@ int app_get_current_image_type() return IMAGE_RGB; } -JWidget app_get_top_window() { return top_window; } -JWidget app_get_menubar() { return menubar; } -JWidget app_get_statusbar() { return statusbar; } -JWidget app_get_colorbar() { return colorbar; } -JWidget app_get_toolbar() { return toolbar; } -JWidget app_get_tabsbar() { return tabsbar; } +Frame* app_get_top_window() { return top_window; } +Widget* app_get_menubar() { return menubar; } +Widget* app_get_statusbar() { return statusbar; } +Widget* app_get_colorbar() { return colorbar; } +Widget* app_get_toolbar() { return toolbar; } +Widget* app_get_tabsbar() { return tabsbar; } void app_default_statusbar_message() { @@ -555,7 +555,7 @@ int app_get_color_to_clear_layer(Layer *layer) return get_color_for_layer(layer, color); } -static void tabsbar_select_callback(JWidget tabs, void *data, int button) +static void tabsbar_select_callback(Widget* tabs, void *data, int button) { // Note: data can be NULL (the "Nothing" tab) Sprite* sprite = (Sprite*)data; diff --git a/src/app.h b/src/app.h index b042bcfe6..327c96796 100644 --- a/src/app.h +++ b/src/app.h @@ -76,12 +76,12 @@ bool app_realloc_recent_list(); int app_get_current_image_type(); -JWidget app_get_top_window(); -JWidget app_get_menubar(); -JWidget app_get_statusbar(); -JWidget app_get_colorbar(); -JWidget app_get_toolbar(); -JWidget app_get_tabsbar(); +Frame* app_get_top_window(); +Widget* app_get_menubar(); +Widget* app_get_statusbar(); +Widget* app_get_colorbar(); +Widget* app_get_toolbar(); +Widget* app_get_tabsbar(); void app_default_statusbar_message(); diff --git a/src/commands/cmd_about.cpp b/src/commands/cmd_about.cpp index 8637e65e5..b3096c4d0 100644 --- a/src/commands/cmd_about.cpp +++ b/src/commands/cmd_about.cpp @@ -57,15 +57,15 @@ void AboutCommand::execute(Context* context) JWidget label3, label4, box2, box3, box4, button1; char *authors_txt = read_authors_txt("AUTHORS.txt"); - JWidgetPtr window; + FramePtr window; if (authors_txt) - window = jwindow_new_desktop(); + window = new Frame(true, NULL); else - window = jwindow_new(_("About ASE")); + window = new Frame(false, _("About ASE")); box1 = jbox_new(JI_VERTICAL); label1 = jlabel_new("Allegro Sprite Editor - " VERSION); - label2 = jlabel_new(_("Just another tool to create sprites")); + label2 = jlabel_new(_("A pixel-art program")); separator1 = ji_separator_new(NULL, JI_HORIZONTAL); if (authors_txt) { @@ -108,7 +108,7 @@ void AboutCommand::execute(Context* context) button1->border_width.r+16, button1->border_width.b); - jwindow_open_fg(window); + window->open_window_fg(); } char* AboutCommand::read_authors_txt(const char *filename) diff --git a/src/commands/cmd_advanced_mode.cpp b/src/commands/cmd_advanced_mode.cpp index 250036fab..874cd1939 100644 --- a/src/commands/cmd_advanced_mode.cpp +++ b/src/commands/cmd_advanced_mode.cpp @@ -66,8 +66,8 @@ void AdvancedModeCommand::execute(Context* context) jwidget_show(app_get_tabsbar()); } - jwindow_remap(app_get_top_window()); - jwidget_dirty(app_get_top_window()); + app_get_top_window()->remap_window(); + app_get_top_window()->dirty(); if (advanced_mode && get_config_bool("AdvancedMode", "Warning", true)) { @@ -77,17 +77,17 @@ void AdvancedModeCommand::execute(Context* context) char key[1024]; char buf[1024]; - JWidgetPtr window(load_widget("advanced.jid", "advanced_mode_warning")); - JWidget warning_label = find_widget(window, "warning_label"); - JWidget donot_show = find_widget(window, "donot_show"); + FramePtr window(load_widget("advanced.jid", "advanced_mode_warning")); + Widget* warning_label = find_widget(window, "warning_label"); + Widget* donot_show = find_widget(window, "donot_show"); strcpy(warning, _("You can back pressing the \"%s\" key.")); jaccel_to_string(accel, key); sprintf(buf, warning, key); - jwidget_set_text(warning_label, buf); + warning_label->setText(buf); - jwindow_open_fg(window); + window->open_window_fg(); set_config_bool("AdvancedMode", "Warning", !jwidget_is_selected(donot_show)); diff --git a/src/commands/cmd_canvas_size.cpp b/src/commands/cmd_canvas_size.cpp index df178c2d9..a00f9e577 100644 --- a/src/commands/cmd_canvas_size.cpp +++ b/src/commands/cmd_canvas_size.cpp @@ -66,7 +66,7 @@ void CanvasSizeCommand::execute(Context* context) JWidget left, top, right, bottom, ok; // load the window widget - JWidgetPtr window(load_widget("canvas.jid", "canvas_size")); + FramePtr window(load_widget("canvas.jid", "canvas_size")); get_widgets(window, "left", &left, "top", &top, @@ -74,26 +74,26 @@ void CanvasSizeCommand::execute(Context* context) "bottom", &bottom, "ok", &ok, NULL); - jwindow_remap(window); - jwindow_center(window); + window->remap_window(); + window->center_window(); - left->textf("%d", m_left); - right->textf("%d", m_right); - top->textf("%d", m_top); - bottom->textf("%d", m_bottom); + left->setTextf("%d", m_left); + right->setTextf("%d", m_right); + top->setTextf("%d", m_top); + bottom->setTextf("%d", m_bottom); load_window_pos(window, "CanvasSize"); jwidget_show(window); - jwindow_open_fg(window); + window->open_window_fg(); save_window_pos(window, "CanvasSize"); - if (jwindow_get_killer(window) != ok) + if (window->get_killer() != ok) return; - m_left = left->text_int(); - m_right = right->text_int(); - m_top = top->text_int(); - m_bottom = bottom->text_int(); + m_left = left->getTextInt(); + m_right = right->getTextInt(); + m_top = top->getTextInt(); + m_bottom = bottom->getTextInt(); } // resize canvas diff --git a/src/commands/cmd_cel_properties.cpp b/src/commands/cmd_cel_properties.cpp index 105b6e51f..f02a73a61 100644 --- a/src/commands/cmd_cel_properties.cpp +++ b/src/commands/cmd_cel_properties.cpp @@ -76,7 +76,7 @@ void CelPropertiesCommand::execute(Context* context) /* get current cel (can be NULL) */ cel = static_cast(layer)->get_cel(sprite->frame); - JWidgetPtr window(load_widget("celprop.jid", "cel_properties")); + FramePtr window(load_widget("celprop.jid", "cel_properties")); get_widgets(window, "frame", &label_frame, "pos", &label_pos, @@ -86,17 +86,17 @@ void CelPropertiesCommand::execute(Context* context) /* if the layer isn't writable */ if (!layer->is_writable()) { - jwidget_set_text(button_ok, _("Locked")); - jwidget_disable(button_ok); + button_ok->setText(_("Locked")); + button_ok->setEnabled(false); } usprintf(buf, "%d/%d", sprite->frame+1, sprite->frames); - jwidget_set_text(label_frame, buf); + label_frame->setText(buf); if (cel != NULL) { /* position */ usprintf(buf, "%d, %d", cel->x, cel->y); - jwidget_set_text(label_pos, buf); + label_pos->setText(buf); /* dimension (and memory size) */ memsize = @@ -112,7 +112,7 @@ void CelPropertiesCommand::execute(Context* context) sizeof(buf)-ustrsize(buf)); ustrcat(buf, ")"); - jwidget_set_text(label_size, buf); + label_size->setText(buf); /* opacity */ jslider_set_value(slider_opacity, cel->opacity); @@ -123,15 +123,15 @@ void CelPropertiesCommand::execute(Context* context) } } else { - jwidget_set_text(label_pos, "None"); - jwidget_set_text(label_size, "Empty (0 bytes)"); + label_pos->setText("None"); + label_size->setText("Empty (0 bytes)"); jslider_set_value(slider_opacity, 0); jwidget_disable(slider_opacity); } - jwindow_open_fg(window); + window->open_window_fg(); - if (jwindow_get_killer(window) == button_ok) { + if (window->get_killer() == button_ok) { int new_opacity = jslider_get_value(slider_opacity); /* the opacity was changed? */ diff --git a/src/commands/cmd_configure_screen.cpp b/src/commands/cmd_configure_screen.cpp index a1f1aba8f..eceb024e7 100644 --- a/src/commands/cmd_configure_screen.cpp +++ b/src/commands/cmd_configure_screen.cpp @@ -96,7 +96,7 @@ void ConfigureScreen::show_dialog(Context* context) { JWidget resolution, color_depth, pixel_scale, fullscreen; - JWidgetPtr window(load_widget("confscr.jid", "configure_screen")); + FramePtr window(load_widget("confscr.jid", "configure_screen")); get_widgets(window, "resolution", &resolution, "color_depth", &color_depth, @@ -110,9 +110,9 @@ void ConfigureScreen::show_dialog(Context* context) else jwidget_select(fullscreen); - jwindow_open_fg(window); + window->open_window_fg(); - if (jwindow_get_killer(window) == jwidget_find_name(window, "ok")) { + if (window->get_killer() == jwidget_find_name(window, "ok")) { new_w = m_resolutions[jcombobox_get_selected_index(resolution)].first; new_h = m_resolutions[jcombobox_get_selected_index(resolution)].second; new_depth = m_colordepths[jcombobox_get_selected_index(color_depth)]; @@ -122,21 +122,21 @@ void ConfigureScreen::show_dialog(Context* context) /* setup graphics mode */ if (try_new_gfx_mode(context)) { - JWidgetPtr alert_window(jalert_new("Confirm Screen" - "<open_window_fg(); jmanager_remove_timer(timer_to_accept); - if (jwindow_get_killer(alert_window) != NULL && - ustrcmp(jwidget_get_name(jwindow_get_killer(alert_window)), "button-1") == 0) { + if (alert_window->get_killer() != NULL && + ustrcmp(alert_window->get_killer()->getName(), "button-1") == 0) { /* do nothing */ } else { @@ -286,7 +286,7 @@ static bool try_new_gfx_mode(Context* context) /* redraw top window */ if (app_get_top_window()) { - jwindow_remap(app_get_top_window()); + app_get_top_window()->remap_window(); jmanager_refresh_screen(); } @@ -304,13 +304,13 @@ static bool alert_msg_proc(JWidget widget, JMessage msg) seconds_to_accept = MAX(0, seconds_to_accept); usprintf(buf, "In %d seconds the screen will be restored.", seconds_to_accept); - jwidget_set_text((JWidget)labels->end->next->next->data, buf); + ((JWidget)labels->end->next->next->data)->setText(buf); jlist_free(labels); if (seconds_to_accept == 0) { jmanager_stop_timer(timer_to_accept); - jwindow_close(widget, NULL); - return TRUE; + static_cast(widget)->closeWindow(NULL); + return true; } } } diff --git a/src/commands/cmd_configure_tools.cpp b/src/commands/cmd_configure_tools.cpp index 516c42166..a83156b0d 100644 --- a/src/commands/cmd_configure_tools.cpp +++ b/src/commands/cmd_configure_tools.cpp @@ -51,7 +51,7 @@ public: } }; -static JWidget window = NULL; +static Frame* window = NULL; static bool brush_preview_msg_proc(JWidget widget, JMessage msg); @@ -103,12 +103,12 @@ void ConfigureTools::execute(Context* context) bool first_time = FALSE; if (!window) { - window = load_widget("toolconf.jid", "configure_tool"); + window = static_cast(load_widget("toolconf.jid", "configure_tool")); first_time = TRUE; } /* if the window is opened, close it */ else if (jwidget_is_visible(window)) { - jwindow_close(window, NULL); + window->closeWindow(NULL); return; } @@ -140,7 +140,7 @@ void ConfigureTools::execute(Context* context) /* cursor-color */ if (first_time) { cursor_color = colorbutton_new(get_cursor_color(), IMAGE_INDEXED); - jwidget_set_name(cursor_color, "cursor_color"); + cursor_color->setName("cursor_color"); } else { cursor_color = jwidget_find_name(window, "cursor_color"); @@ -148,11 +148,11 @@ void ConfigureTools::execute(Context* context) /* brush-preview */ if (first_time) { - brush_preview = new jwidget(JI_WIDGET); + brush_preview = new Widget(JI_WIDGET); brush_preview->min_w = 32 + 4; brush_preview->min_h = 32 + 4; - jwidget_set_name(brush_preview, "brush_preview"); + brush_preview->setName("brush_preview"); jwidget_add_hook(brush_preview, JI_WIDGET, brush_preview_msg_proc, NULL); } @@ -167,7 +167,7 @@ void ConfigureTools::execute(Context* context) GFX_BRUSH_SQUARE, GFX_BRUSH_LINE); - jwidget_set_name(brush_type, "brush_type"); + brush_type->setName("brush_type"); } else { brush_type = jwidget_find_name(window, "brush_type"); @@ -216,13 +216,13 @@ void ConfigureTools::execute(Context* context) } /* default position */ - jwindow_remap(window); - jwindow_center(window); + window->remap_window(); + window->center_window(); /* load window configuration */ load_window_pos(window, "ConfigureTool"); - jwindow_open_bg(window); + window->open_window_bg(); } static bool brush_preview_msg_proc(JWidget widget, JMessage msg) @@ -317,8 +317,8 @@ static bool tiled_check_change_hook(JWidget widget, void *data) { bool flag = jwidget_is_selected(widget); set_tiled_mode(flag ? TILED_BOTH: TILED_NONE); - jwidget_set_selected(jwidget_find_name(jwidget_get_window(widget), "tiled_x"), flag); - jwidget_set_selected(jwidget_find_name(jwidget_get_window(widget), "tiled_y"), flag); + widget->findSibling("tiled_x")->setSelected(flag); + widget->findSibling("tiled_y")->setSelected(flag); return FALSE; } @@ -332,8 +332,7 @@ static bool tiled_xy_check_change_hook(JWidget widget, void *data) else tiled_mode &= ~tiled_axis; - jwidget_set_selected(jwidget_find_name(jwidget_get_window(widget), "tiled"), - (tiled_mode != TILED_NONE)); + widget->findSibling("tiled")->setSelected(tiled_mode != TILED_NONE); set_tiled_mode((tiled_t)tiled_mode); return FALSE; diff --git a/src/commands/cmd_duplicate_sprite.cpp b/src/commands/cmd_duplicate_sprite.cpp index 6d74e5d9d..be3a2e8d5 100644 --- a/src/commands/cmd_duplicate_sprite.cpp +++ b/src/commands/cmd_duplicate_sprite.cpp @@ -65,24 +65,24 @@ void DuplicateSpriteCommand::execute(Context* context) char buf[1024]; /* load the window widget */ - JWidgetPtr window(load_widget("dupspr.jid", "duplicate_sprite")); + FramePtr window(load_widget("dupspr.jid", "duplicate_sprite")); src_name = jwidget_find_name(window, "src_name"); dst_name = jwidget_find_name(window, "dst_name"); flatten = jwidget_find_name(window, "flatten"); - jwidget_set_text(src_name, get_filename(sprite->filename)); + src_name->setText(get_filename(sprite->filename)); sprintf(buf, "%s %s", sprite->filename, _("Copy")); - jwidget_set_text(dst_name, buf); + dst_name->setText(buf); if (get_config_bool("DuplicateSprite", "Flatten", FALSE)) jwidget_select(flatten); /* open the window */ - jwindow_open_fg(window); + window->open_window_fg(); - if (jwindow_get_killer(window) == jwidget_find_name(window, "ok")) { + if (window->get_killer() == jwidget_find_name(window, "ok")) { set_config_bool("DuplicateSprite", "Flatten", jwidget_is_selected(flatten)); @@ -94,7 +94,7 @@ void DuplicateSpriteCommand::execute(Context* context) sprite_copy = sprite_new_copy(sprite); if (sprite_copy != NULL) { - sprite_set_filename(sprite_copy, jwidget_get_text(dst_name)); + sprite_set_filename(sprite_copy, dst_name->getText()); context->add_sprite(sprite_copy); set_sprite_in_more_reliable_editor(sprite_copy); diff --git a/src/commands/cmd_exit.cpp b/src/commands/cmd_exit.cpp index d5b0e23cb..0645d6822 100644 --- a/src/commands/cmd_exit.cpp +++ b/src/commands/cmd_exit.cpp @@ -61,7 +61,7 @@ void ExitCommand::execute(Context* context) } /* close the window */ - jwindow_close(app_get_top_window(), 0); + app_get_top_window()->closeWindow(NULL); } ////////////////////////////////////////////////////////////////////// diff --git a/src/commands/cmd_frame_properties.cpp b/src/commands/cmd_frame_properties.cpp index 949b278a5..e35f86542 100644 --- a/src/commands/cmd_frame_properties.cpp +++ b/src/commands/cmd_frame_properties.cpp @@ -69,7 +69,7 @@ void dialogs_frame_length(const SpriteReader& sprite, int sprite_frame) JWidget frame, frlen, ok; char buf[64]; - JWidgetPtr window(load_widget("frlen.jid", "frame_duration")); + FramePtr window(load_widget("frlen.jid", "frame_duration")); get_widgets(window, "frame", &frame, "frlen", &frlen, @@ -79,14 +79,13 @@ void dialogs_frame_length(const SpriteReader& sprite, int sprite_frame) strcpy(buf, "All"); else sprintf(buf, "%d", sprite_frame+1); - jwidget_set_text(frame, buf); + frame->setText(buf); - sprintf(buf, "%d", sprite_get_frlen(sprite, sprite->frame)); - jwidget_set_text(frlen, buf); + frlen->setTextf("%d", sprite_get_frlen(sprite, sprite->frame)); - jwindow_open_fg(window); - if (jwindow_get_killer(window) == ok) { - int num = strtol(jwidget_get_text(frlen), NULL, 10); + window->open_window_fg(); + if (window->get_killer() == ok) { + int num = strtol(frlen->getText(), NULL, 10); if (sprite_frame < 0) { if (jalert("Warning" diff --git a/src/commands/cmd_layer_properties.cpp b/src/commands/cmd_layer_properties.cpp index 3d23f7613..aab9a1363 100644 --- a/src/commands/cmd_layer_properties.cpp +++ b/src/commands/cmd_layer_properties.cpp @@ -65,7 +65,7 @@ void LayerPropertiesCommand::execute(Context* context) Layer* layer = sprite->layer; bool with_blend_modes = (layer->is_image() && sprite->imgtype != IMAGE_INDEXED); - JWidgetPtr window(jwindow_new(_("Layer Properties"))); + FramePtr window(new Frame(false, _("Layer Properties"))); box1 = jbox_new(JI_VERTICAL); box2 = jbox_new(JI_HORIZONTAL); box3 = jbox_new(JI_HORIZONTAL + JI_HOMOGENEOUS); @@ -122,10 +122,10 @@ void LayerPropertiesCommand::execute(Context* context) jwidget_magnetic(entry_name, true); jwidget_magnetic(button_ok, true); - jwindow_open_fg(window); + window->open_window_fg(); - if (jwindow_get_killer(window) == button_ok) { - layer->set_name(jwidget_get_text(entry_name)); + if (window->get_killer() == button_ok) { + layer->set_name(entry_name->getText()); if (with_blend_modes) static_cast(layer)->set_blend_mode(jlistbox_get_selected_index(list_bm)); diff --git a/src/commands/cmd_new_file.cpp b/src/commands/cmd_new_file.cpp index 2ad656d06..a586edcbf 100644 --- a/src/commands/cmd_new_file.cpp +++ b/src/commands/cmd_new_file.cpp @@ -82,7 +82,7 @@ void NewFileCommand::execute(Context* context) }; /* load the window widget */ - JWidgetPtr window(load_widget("newspr.jid", "new_sprite")); + FramePtr window(load_widget("newspr.jid", "new_sprite")); width = jwidget_find_name(window, "width"); height = jwidget_find_name(window, "height"); @@ -99,8 +99,8 @@ void NewFileCommand::execute(Context* context) h = get_config_int("NewSprite", "Height", 200); /* default = 200 */ bg = get_config_int("NewSprite", "Background", 2); /* default = white */ - usprintf(buf, "%d", w); jwidget_set_text(width, buf); - usprintf(buf, "%d", h); jwidget_set_text(height, buf); + width->setTextf("%d", w); + height->setTextf("%d", h); /* select image-type */ switch (imgtype) { @@ -113,9 +113,9 @@ void NewFileCommand::execute(Context* context) jlistbox_select_index(bg_box, bg); /* open the window */ - jwindow_open_fg(window); + window->open_window_fg(); - if (jwindow_get_killer(window) == ok) { + if (window->get_killer() == ok) { bool ok = FALSE; /* get the options */ @@ -123,8 +123,8 @@ void NewFileCommand::execute(Context* context) else if (jwidget_is_selected(radio2)) imgtype = IMAGE_GRAYSCALE; else if (jwidget_is_selected(radio3)) imgtype = IMAGE_INDEXED; - w = width->text_int(); - h = height->text_int(); + w = width->getTextInt(); + h = height->getTextInt(); bg = jlistbox_get_selected_index(bg_box); w = MID(1, w, 9999); diff --git a/src/commands/cmd_new_layer.cpp b/src/commands/cmd_new_layer.cpp index de3a1761e..fb6ad14d2 100644 --- a/src/commands/cmd_new_layer.cpp +++ b/src/commands/cmd_new_layer.cpp @@ -63,19 +63,19 @@ void NewLayerCommand::execute(Context* context) { CurrentSpriteWriter sprite(context); - JWidgetPtr window(load_widget("newlay.jid", "new_layer")); + FramePtr window(load_widget("newlay.jid", "new_layer")); JWidget name_widget = find_widget(window, "name"); { char* name = get_unique_layer_name(sprite); - jwidget_set_text(name_widget, name); + name_widget->setText(name); jfree(name); } jwidget_set_min_size(name_widget, 128, 0); - jwindow_open_fg(window); + window->open_window_fg(); - if (jwindow_get_killer(window) == jwidget_find_name(window, "ok")) { - const char* name = jwidget_get_text(jwidget_find_name(window, "name")); + if (window->get_killer() == jwidget_find_name(window, "ok")) { + const char* name = jwidget_find_name(window, "name")->getText(); Layer* layer; { Undoable undoable(sprite, "New Layer"); diff --git a/src/commands/cmd_new_layer_set.cpp b/src/commands/cmd_new_layer_set.cpp index 295037956..b9f7fc6bd 100644 --- a/src/commands/cmd_new_layer_set.cpp +++ b/src/commands/cmd_new_layer_set.cpp @@ -60,12 +60,12 @@ void NewLayerSetCommand::execute(Context* context) CurrentSpriteWriter sprite(context); // load the window widget - JWidgetPtr window(load_widget("newlay.jid", "new_layer_set")); + FramePtr window(load_widget("newlay.jid", "new_layer_set")); - jwindow_open_fg(window); + window->open_window_fg(); - if (jwindow_get_killer(window) == jwidget_find_name(window, "ok")) { - const char *name = jwidget_get_text(jwidget_find_name(window, "name")); + if (window->get_killer() == jwidget_find_name(window, "ok")) { + const char *name = jwidget_find_name(window, "name")->getText(); Layer* layer = new LayerFolder(sprite); layer->set_name(name); diff --git a/src/commands/cmd_open_file.cpp b/src/commands/cmd_open_file.cpp index f939b4744..3b1813d39 100644 --- a/src/commands/cmd_open_file.cpp +++ b/src/commands/cmd_open_file.cpp @@ -58,7 +58,7 @@ typedef struct OpenFileData FileOp *fop; Progress *progress; JThread thread; - JWidget alert_window; + Frame* alert_window; } OpenFileData; /** @@ -142,7 +142,7 @@ static void monitor_free(void* _data) if (data->alert_window != NULL) { data->monitor = NULL; - jwindow_close(data->alert_window, NULL); + data->alert_window->closeWindow(NULL); } #if 0 @@ -204,7 +204,7 @@ void OpenFileCommand::execute(Context* context) data->monitor = add_gui_monitor(monitor_openfile_bg, monitor_free, data); - jwindow_open_fg(data->alert_window); + data->alert_window->open_window_fg(); if (data->monitor != NULL) remove_gui_monitor(data->monitor); diff --git a/src/commands/cmd_palette_editor.cpp b/src/commands/cmd_palette_editor.cpp index d50d0f85e..2aae71755 100644 --- a/src/commands/cmd_palette_editor.cpp +++ b/src/commands/cmd_palette_editor.cpp @@ -53,7 +53,7 @@ protected: void execute(Context* context); }; -#define get_sprite(wgt) (*(const SpriteReader*)(jwidget_get_window(wgt))->user_data[0]) +#define get_sprite(wgt) (*(const SpriteReader*)(wgt->getRoot())->user_data[0]) static Palette **palettes; @@ -107,7 +107,7 @@ void PaletteEditorCommand::execute(Context* context) } /* load widgets */ - JWidgetPtr window(load_widget("paledit.jid", "palette_editor")); + FramePtr window(load_widget("paledit.jid", "palette_editor")); get_widgets(window, "red", &slider_R, "green", &slider_G, @@ -216,17 +216,17 @@ void PaletteEditorCommand::execute(Context* context) jbutton_add_command(button_quantize, quantize_command); /* default position */ - jwindow_remap(window); - jwindow_center(window); + window->remap_window(); + window->center_window(); /* load window configuration */ load_window_pos(window, "PaletteEditor"); /* open and run the window */ - jwindow_open_fg(window); + window->open_window_fg(); /* check the killer widget */ - if (jwindow_get_killer(window) == button_ok) { + if (window->get_killer() == button_ok) { if (sprite) { SpriteWriter sprite_writer(sprite); sprite_reset_palettes(sprite_writer); diff --git a/src/commands/cmd_save_file.cpp b/src/commands/cmd_save_file.cpp index 257fd2713..1087ec752 100644 --- a/src/commands/cmd_save_file.cpp +++ b/src/commands/cmd_save_file.cpp @@ -39,7 +39,7 @@ typedef struct SaveFileData FileOp *fop; Progress *progress; JThread thread; - JWidget alert_window; + Frame* alert_window; } SaveFileData; /** @@ -79,11 +79,11 @@ static void monitor_savefile_bg(void *_data) */ static void monitor_free(void *_data) { - SaveFileData *data = (SaveFileData *)_data; + SaveFileData *data = (SaveFileData*)_data; if (data->alert_window != NULL) { data->monitor = NULL; - jwindow_close(data->alert_window, NULL); + data->alert_window->closeWindow(NULL); } } @@ -108,7 +108,7 @@ static void save_sprite_in_background(Sprite* sprite, bool mark_as_saved) /* TODO error handling */ - jwindow_open_fg(data->alert_window); + data->alert_window->open_window_fg(); if (data->monitor != NULL) remove_gui_monitor(data->monitor); diff --git a/src/commands/cmd_sprite_properties.cpp b/src/commands/cmd_sprite_properties.cpp index 416132319..6af999880 100644 --- a/src/commands/cmd_sprite_properties.cpp +++ b/src/commands/cmd_sprite_properties.cpp @@ -70,7 +70,7 @@ void SpritePropertiesCommand::execute(Context* context) char buf[256]; /* load the window widget */ - JWidgetPtr window(load_widget("sprprop.jid", "sprite_properties")); + FramePtr window(load_widget("sprprop.jid", "sprite_properties")); get_widgets(window, "name", &name, "type", &type, @@ -96,10 +96,10 @@ void SpritePropertiesCommand::execute(Context* context) } /* filename */ - jwidget_set_text(name, sprite->filename); + name->setText(sprite->filename); /* color mode */ - jwidget_set_text(type, imgtype_text.c_str()); + type->setText(imgtype_text.c_str()); /* sprite size (width and height) */ usprintf(buf, "%dx%d (", sprite->w, sprite->h); @@ -107,22 +107,21 @@ void SpritePropertiesCommand::execute(Context* context) buf+ustrsize(buf), sizeof(buf)-ustrsize(buf)); ustrcat(buf, ")"); - jwidget_set_text(size, buf); + size->setText(buf); /* how many frames */ - usprintf(buf, "%d", sprite->frames); - jwidget_set_text(frames, buf); + frames->setTextf("%d", sprite->frames); - jwindow_remap(window); - jwindow_center(window); + window->remap_window(); + window->center_window(); for (;;) { load_window_pos(window, "SpriteProperties"); jwidget_show(window); - jwindow_open_fg(window); + window->open_window_fg(); save_window_pos(window, "SpriteProperties"); - killer = jwindow_get_killer(window); + killer = window->get_killer(); if (killer == ok) break; else if (killer == speed) { diff --git a/src/commands/cmd_sprite_size.cpp b/src/commands/cmd_sprite_size.cpp index 7c13bbe4a..fc124c24a 100644 --- a/src/commands/cmd_sprite_size.cpp +++ b/src/commands/cmd_sprite_size.cpp @@ -187,7 +187,7 @@ void SpriteSizeCommand::execute(Context* context) const CurrentSpriteReader sprite(context); // load the window widget - JWidgetPtr window(load_widget("sprsize.jid", "sprite_size")); + FramePtr window(load_widget("sprsize.jid", "sprite_size")); get_widgets(window, "width_px", &width_px, "height_px", &height_px, @@ -197,8 +197,8 @@ void SpriteSizeCommand::execute(Context* context) "method", &method, "ok", &ok, NULL); - width_px->textf("%d", sprite->w); - height_px->textf("%d", sprite->h); + width_px->setTextf("%d", sprite->w); + height_px->setTextf("%d", sprite->h); HOOK(lock_ratio, JI_SIGNAL_CHECK_CHANGE, lock_ratio_change_hook, 0); HOOK(width_px, JI_SIGNAL_ENTRY_CHANGE, width_px_change_hook, 0); @@ -210,17 +210,17 @@ void SpriteSizeCommand::execute(Context* context) jcombobox_add_string(method, "Bilinear", NULL); jcombobox_select_index(method, get_config_int("SpriteSize", "Method", RESIZE_METHOD_NEAREST_NEIGHBOR)); - jwindow_remap(window); - jwindow_center(window); + window->remap_window(); + window->center_window(); load_window_pos(window, "SpriteSize"); jwidget_show(window); - jwindow_open_fg(window); + window->open_window_fg(); save_window_pos(window, "SpriteSize"); - if (jwindow_get_killer(window) == ok) { - int new_width = width_px->text_int(); - int new_height = height_px->text_int(); + if (window->get_killer() == ok) { + int new_width = width_px->getTextInt(); + int new_height = height_px->getTextInt(); ResizeMethod resize_method = (ResizeMethod)jcombobox_get_selected_index(method); @@ -239,8 +239,8 @@ static bool lock_ratio_change_hook(JWidget widget, void *data) { const CurrentSpriteReader sprite(UIContext::instance()); // TODO use the context in sprite size command - if (widget->selected()) - width_px_change_hook(widget->find_sibling("width_px"), NULL); + if (widget->isSelected()) + width_px_change_hook(widget->findSibling("width_px"), NULL); return true; } @@ -248,14 +248,14 @@ static bool lock_ratio_change_hook(JWidget widget, void *data) static bool width_px_change_hook(JWidget widget, void *data) { const CurrentSpriteReader sprite(UIContext::instance()); // TODO use the context in sprite size command - int width = widget->text_int(); + int width = widget->getTextInt(); double perc = 100.0 * width / sprite->w; - widget->find_sibling("width_perc")->textf(PERC_FORMAT, perc); + widget->findSibling("width_perc")->setTextf(PERC_FORMAT, perc); - if (widget->find_sibling("lock_ratio")->selected()) { - widget->find_sibling("height_perc")->textf(PERC_FORMAT, perc); - widget->find_sibling("height_px")->textf("%d", sprite->h * width / sprite->w); + if (widget->findSibling("lock_ratio")->isSelected()) { + widget->findSibling("height_perc")->setTextf(PERC_FORMAT, perc); + widget->findSibling("height_px")->setTextf("%d", sprite->h * width / sprite->w); } return true; @@ -264,14 +264,14 @@ static bool width_px_change_hook(JWidget widget, void *data) static bool height_px_change_hook(JWidget widget, void *data) { const CurrentSpriteReader sprite(UIContext::instance()); // TODO use the context in sprite size command - int height = widget->text_int(); + int height = widget->getTextInt(); double perc = 100.0 * height / sprite->h; - widget->find_sibling("height_perc")->textf(PERC_FORMAT, perc); + widget->findSibling("height_perc")->setTextf(PERC_FORMAT, perc); - if (widget->find_sibling("lock_ratio")->selected()) { - widget->find_sibling("width_perc")->textf(PERC_FORMAT, perc); - widget->find_sibling("width_px")->textf("%d", sprite->w * height / sprite->h); + if (widget->findSibling("lock_ratio")->isSelected()) { + widget->findSibling("width_perc")->setTextf(PERC_FORMAT, perc); + widget->findSibling("width_px")->setTextf("%d", sprite->w * height / sprite->h); } return true; @@ -280,13 +280,13 @@ static bool height_px_change_hook(JWidget widget, void *data) static bool width_perc_change_hook(JWidget widget, void *data) { const CurrentSpriteReader sprite(UIContext::instance()); // TODO use the context in sprite size command - double width = widget->text_double(); + double width = widget->getTextDouble(); - widget->find_sibling("width_px")->textf("%d", (int)(sprite->w * width / 100)); + widget->findSibling("width_px")->setTextf("%d", (int)(sprite->w * width / 100)); - if (widget->find_sibling("lock_ratio")->selected()) { - widget->find_sibling("height_px")->textf("%d", (int)(sprite->h * width / 100)); - widget->find_sibling("height_perc")->text(widget->text()); + if (widget->findSibling("lock_ratio")->isSelected()) { + widget->findSibling("height_px")->setTextf("%d", (int)(sprite->h * width / 100)); + widget->findSibling("height_perc")->setText(widget->getText()); } return true; @@ -295,13 +295,13 @@ static bool width_perc_change_hook(JWidget widget, void *data) static bool height_perc_change_hook(JWidget widget, void *data) { const CurrentSpriteReader sprite(UIContext::instance()); // TODO use the context in sprite size command - double height = widget->text_double(); + double height = widget->getTextDouble(); - widget->find_sibling("height_px")->textf("%d", (int)(sprite->h * height / 100)); + widget->findSibling("height_px")->setTextf("%d", (int)(sprite->h * height / 100)); - if (widget->find_sibling("lock_ratio")->selected()) { - widget->find_sibling("width_px")->textf("%d", (int)(sprite->w * height / 100)); - widget->find_sibling("width_perc")->text(widget->text()); + if (widget->findSibling("lock_ratio")->isSelected()) { + widget->findSibling("width_px")->setTextf("%d", (int)(sprite->w * height / 100)); + widget->findSibling("width_perc")->setText(widget->getText()); } return true; diff --git a/src/commands/commands.cpp b/src/commands/commands.cpp index 121de7435..6d369c18e 100644 --- a/src/commands/commands.cpp +++ b/src/commands/commands.cpp @@ -65,6 +65,7 @@ CommandsModule::~CommandsModule() CommandsModule* CommandsModule::instance() { + assert(m_instance != NULL); return m_instance; } diff --git a/src/commands/fx/cmd_color_curve.cpp b/src/commands/fx/cmd_color_curve.cpp index fdf165ac9..2505af97b 100644 --- a/src/commands/fx/cmd_color_curve.cpp +++ b/src/commands/fx/cmd_color_curve.cpp @@ -99,7 +99,7 @@ void ColorCurveCommand::execute(Context* context) App::instance()->add_hook(AppEvent::Exit, new DestroyCurve(the_curve)); } - JWidgetPtr window(load_widget("colcurv.jid", "color_curve")); + FramePtr window(load_widget("colcurv.jid", "color_curve")); get_widgets(window, "preview", &check_preview, "button_ok", &button_ok, @@ -130,8 +130,8 @@ void ColorCurveCommand::execute(Context* context) jwidget_add_hook(window, -1, window_msg_proc, NULL); /* default position */ - jwindow_remap(window); - jwindow_center(window); + window->remap_window(); + window->center_window(); /* first preview */ make_preview(); @@ -140,9 +140,9 @@ void ColorCurveCommand::execute(Context* context) load_window_pos(window, "ColorCurve"); /* open the window */ - jwindow_open_fg(window); + window->open_window_fg(); - if (jwindow_get_killer(window) == button_ok) + if (window->get_killer() == button_ok) effect_apply_to_target_with_progressbar(&effect); /* update editors */ diff --git a/src/commands/fx/cmd_convolution_matrix.cpp b/src/commands/fx/cmd_convolution_matrix.cpp index b6c201d44..5d7aeee81 100644 --- a/src/commands/fx/cmd_convolution_matrix.cpp +++ b/src/commands/fx/cmd_convolution_matrix.cpp @@ -102,7 +102,7 @@ void ConvolutionMatrixCommand::execute(Context* context) JWidget box_target; JWidget reload, generate; - JWidgetPtr window(load_widget("convmatr.jid", "convolution_matrix")); + FramePtr window(load_widget("convmatr.jid", "convolution_matrix")); get_widgets(window, "preview", &check_preview, "tiled", &check_tiled, @@ -144,8 +144,8 @@ void ConvolutionMatrixCommand::execute(Context* context) jwidget_disable(generate); /* default position */ - jwindow_remap(window); - jwindow_center(window); + window->remap_window(); + window->center_window(); /* load window configuration */ load_window_pos(window, "ConvolutionMatrix"); @@ -154,9 +154,9 @@ void ConvolutionMatrixCommand::execute(Context* context) listbox_select_current_convmatr(list_convmatr); /* open the window */ - jwindow_open_fg(window); + window->open_window_fg(); - if (jwindow_get_killer(window) == button_ok) + if (window->get_killer() == button_ok) effect_apply_to_target_with_progressbar(&effect); /* update editors */ @@ -192,7 +192,7 @@ static void listbox_select_current_convmatr(JWidget listbox) JI_LIST_FOR_EACH(listbox->children, link) { child = reinterpret_cast(link->data); - if (strcmp(jwidget_get_text(child), selected) == 0) { + if (strcmp(child->getText(), selected) == 0) { select_this = child; break; } @@ -277,7 +277,7 @@ static bool generate_select_hook(JWidget widget, void *data) jwidget_set_min_size(div, 1, 1); jwidget_set_min_size(bias, 1, 1); - jwindow_open_fg(window); + window->open_window_fg(); /* TODO do something */ diff --git a/src/commands/fx/cmd_despeckle.cpp b/src/commands/fx/cmd_despeckle.cpp index edaf80911..f4fdee05b 100644 --- a/src/commands/fx/cmd_despeckle.cpp +++ b/src/commands/fx/cmd_despeckle.cpp @@ -85,9 +85,8 @@ void DespeckleCommand::execute(Context* context) { const CurrentSpriteReader sprite(context); JWidget box_target, target_button, button_ok; - char buf[32]; - JWidgetPtr window(load_widget("median.jid", "median")); + FramePtr window(load_widget("median.jid", "median")); get_widgets(window, "width", &entry_width, "height", &entry_height, @@ -106,10 +105,8 @@ void DespeckleCommand::execute(Context* context) target_button = target_button_new(sprite->imgtype, TRUE); target_button_set_target(target_button, effect.target); - sprintf(buf, "%d", get_config_int("Median", "Width", 3)); - jwidget_set_text(entry_width, buf); - sprintf(buf, "%d", get_config_int("Median", "Height", 3)); - jwidget_set_text(entry_height, buf); + entry_width->setTextf("%d", get_config_int("Median", "Width", 3)); + entry_height->setTextf("%d", get_config_int("Median", "Height", 3)); if (get_config_bool("Median", "Preview", TRUE)) jwidget_select(check_preview); @@ -127,8 +124,8 @@ void DespeckleCommand::execute(Context* context) HOOK(check_tiled, JI_SIGNAL_CHECK_CHANGE, tiled_change_hook, 0); /* default position */ - jwindow_remap(window); - jwindow_center(window); + window->remap_window(); + window->center_window(); /* first preview */ make_preview(); @@ -137,9 +134,9 @@ void DespeckleCommand::execute(Context* context) load_window_pos(window, "Median"); /* open the window */ - jwindow_open_fg(window); + window->open_window_fg(); - if (jwindow_get_killer(window) == button_ok) + if (window->get_killer() == button_ok) effect_apply_to_target_with_progressbar(&effect); /* update editors */ @@ -151,16 +148,14 @@ void DespeckleCommand::execute(Context* context) static bool width_change_hook(JWidget widget, void *data) { - set_config_int("Median", "Width", - strtol(jwidget_get_text(widget), NULL, 10)); + set_config_int("Median", "Width", widget->getTextInt()); make_preview(); return TRUE; } static bool height_change_hook(JWidget widget, void *data) { - set_config_int("Median", "Height", - strtol(jwidget_get_text(widget), NULL, 10)); + set_config_int("Median", "Height", widget->getTextInt()); make_preview(); return TRUE; } @@ -177,7 +172,7 @@ static bool preview_change_hook(JWidget widget, void *data) { set_config_bool("Median", "Preview", jwidget_is_selected(widget)); make_preview(); - return FALSE; + return false; } static bool tiled_change_hook(JWidget widget, void *data) diff --git a/src/commands/fx/cmd_invert_color.cpp b/src/commands/fx/cmd_invert_color.cpp index c0695e209..003605954 100644 --- a/src/commands/fx/cmd_invert_color.cpp +++ b/src/commands/fx/cmd_invert_color.cpp @@ -80,7 +80,8 @@ void InvertColorCommand::execute(Context* context) { const CurrentSpriteReader sprite(context); JWidget box_target, target_button, button_ok; - JWidgetPtr window(load_widget("invrtcol.jid", "invert_color")); + + FramePtr window(load_widget("invrtcol.jid", "invert_color")); get_widgets(window, "target", &box_target, "preview", &check_preview, @@ -105,8 +106,8 @@ void InvertColorCommand::execute(Context* context) HOOK(check_preview, JI_SIGNAL_CHECK_CHANGE, preview_change_hook, 0); /* default position */ - jwindow_remap(window); - jwindow_center(window); + window->remap_window(); + window->center_window(); /* first preview */ make_preview(); @@ -115,9 +116,9 @@ void InvertColorCommand::execute(Context* context) load_window_pos(window, "InvertColor"); /* open the window */ - jwindow_open_fg(window); + window->open_window_fg(); - if (jwindow_get_killer(window) == button_ok) + if (window->get_killer() == button_ok) effect_apply_to_target_with_progressbar(&effect); /* update editors */ diff --git a/src/commands/fx/cmd_replace_color.cpp b/src/commands/fx/cmd_replace_color.cpp index bd2bb3d17..5cab492bf 100644 --- a/src/commands/fx/cmd_replace_color.cpp +++ b/src/commands/fx/cmd_replace_color.cpp @@ -86,7 +86,7 @@ void ReplaceColorCommand::execute(Context* context) JWidget box_target, target_button; JWidget button_ok; - JWidgetPtr window(load_widget("replcol.jid", "replace_color")); + FramePtr window(load_widget("replcol.jid", "replace_color")); get_widgets(window, "color_buttons_box", &color_buttons_box, "preview", &check_preview, @@ -131,8 +131,8 @@ void ReplaceColorCommand::execute(Context* context) HOOK(check_preview, JI_SIGNAL_CHECK_CHANGE, preview_change_hook, 0); /* default position */ - jwindow_remap(window); - jwindow_center(window); + window->remap_window(); + window->center_window(); /* first preview */ make_preview(); @@ -141,9 +141,9 @@ void ReplaceColorCommand::execute(Context* context) load_window_pos(window, "ReplaceColor"); /* open the window */ - jwindow_open_fg(window); + window->open_window_fg(); - if (jwindow_get_killer(window) == button_ok) + if (window->get_killer() == button_ok) effect_apply_to_target_with_progressbar(&effect); /* update editors */ diff --git a/src/commands/fx/effectbg.cpp b/src/commands/fx/effectbg.cpp index 19674986d..fb616e6d6 100644 --- a/src/commands/fx/effectbg.cpp +++ b/src/commands/fx/effectbg.cpp @@ -49,7 +49,7 @@ typedef struct ThreadData Monitor *monitor; /* monitor to update the progress-bar */ Progress *progress; /* the progress-bar */ JThread thread; /* thread to apply the effect in background */ - JWidget alert_window; /* alert for the user to cancel the + Frame* alert_window; /* alert for the user to cancel the effect-progress if he wants */ } ThreadData; @@ -138,7 +138,7 @@ static void monitor_free(void *_data) ThreadData *data = (ThreadData *)_data; if (data->alert_window != NULL) - jwindow_close(data->alert_window, NULL); + data->alert_window->closeWindow(NULL); } /** @@ -169,7 +169,7 @@ void effect_apply_to_target_with_progressbar(Effect* effect) /* TODO error handling */ - jwindow_open_fg(data->alert_window); + data->alert_window->open_window_fg(); jmutex_lock(data->mutex); if (!data->done) { diff --git a/src/console.cpp b/src/console.cpp index d7e0ea91f..b1c3728f7 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -30,10 +30,10 @@ #include "modules/gui.h" #include "widgets/statebar.h" -static JWidget wid_console = NULL; -static JWidget wid_view = NULL; -static JWidget wid_textbox = NULL; -static JWidget wid_cancel = NULL; +static Frame* wid_console = NULL; +static Widget* wid_view = NULL; +static Widget* wid_textbox = NULL; +static Widget* wid_cancel = NULL; static int console_counter = 0; static bool console_locked; static bool want_close_flag = FALSE; @@ -48,16 +48,11 @@ Console::Console() console_counter > 1) return; else { - JWidget window, grid, view, textbox, button; - - window = jwindow_new(_("Errors Console")); - if (!window) - return; - - grid = jgrid_new(1, FALSE); - view = jview_new(); - textbox = jtextbox_new(NULL, JI_WORDWRAP); - button = jbutton_new(_("&Cancel")); + Frame* window = new Frame(false, _("Errors Console")); + Widget* grid = jgrid_new(1, FALSE); + Widget* view = jview_new(); + Widget* textbox = jtextbox_new(NULL, JI_WORDWRAP); + Widget* button = jbutton_new(_("&Cancel")); if (!grid || !textbox || !button) return; @@ -95,10 +90,10 @@ Console::~Console() && !want_close_flag && jwidget_is_visible(wid_console)) { /* open in foreground */ - jwindow_open_fg(wid_console); + wid_console->open_window_fg(); } - jwidget_free(wid_console); + delete wid_console; // window wid_console = NULL; want_close_flag = FALSE; } @@ -106,7 +101,7 @@ Console::~Console() void Console::printf(const char *format, ...) { - char buf[1024]; + char buf[1024]; // TODO warning buffer overflow va_list ap; va_start(ap, format); @@ -119,7 +114,7 @@ void Console::printf(const char *format, ...) /* open the window */ if (jwidget_is_hidden(wid_console)) { - jwindow_open(wid_console); + wid_console->open_window(); jmanager_refresh_screen(); } @@ -130,15 +125,15 @@ void Console::printf(const char *format, ...) jwidget_show(wid_view); - jwindow_remap(wid_console); + wid_console->remap_window(); jwidget_set_rect(wid_console, rect); - jwindow_center(wid_console); - jwidget_dirty(wid_console); + wid_console->center_window(); + wid_console->dirty(); jrect_free(rect); } - text = jwidget_get_text(wid_textbox); + text = wid_textbox->getText(); if (!text) final = jstrdup(buf); else { @@ -149,21 +144,24 @@ void Console::printf(const char *format, ...) ustrcat(final, buf); } - jwidget_set_text(wid_textbox, final); + wid_textbox->setText(final); jfree(final); } else { - fputs(buf, stdout); - fflush(stdout); + if (ji_screen) { + fputs(buf, stdout); + fflush(stdout); - if (ji_screen) jalert("Error<<%s||OK", buf); + } + else + allegro_message(buf); } } void user_printf(const char *format, ...) { - char buf[1024]; + char buf[1024]; // TODO warning buffer overflow va_list ap; va_start(ap, format); diff --git a/src/core/drop_files.cpp b/src/core/drop_files.cpp index 93eb275e2..8c008776c 100644 --- a/src/core/drop_files.cpp +++ b/src/core/drop_files.cpp @@ -67,7 +67,7 @@ void check_for_dropped_files() if (!base_wnd_proc) // drop-files hook not installed return; - if (!jwindow_is_toplevel(app_get_top_window())) + if (!app_get_top_window()->is_toplevel()) return; jmutex_lock(dropped_files_mutex); diff --git a/src/core/job.cpp b/src/core/job.cpp index 536c0bf34..103bd7919 100644 --- a/src/core/job.cpp +++ b/src/core/job.cpp @@ -78,7 +78,7 @@ Job::~Job() void Job::do_job() { m_thread = jthread_new(&Job::thread_proc, (void*)this); - jwindow_open_fg(m_alert_window); + m_alert_window->open_window_fg(); } void Job::job_progress(float f) @@ -129,7 +129,7 @@ void Job::on_monitor_destroyed() { if (m_alert_window != NULL) { m_monitor = NULL; - jwindow_close(m_alert_window, NULL); + m_alert_window->closeWindow(NULL); } } diff --git a/src/core/job.h b/src/core/job.h index 3e0661aa5..5960a0509 100644 --- a/src/core/job.h +++ b/src/core/job.h @@ -21,6 +21,7 @@ #include "jinete/jbase.h" +class Frame; struct Monitor; struct Progress; @@ -30,7 +31,7 @@ class Job Monitor* m_monitor; Progress* m_progress; JMutex m_mutex; - JWidget m_alert_window; + Frame* m_alert_window; float m_last_progress; bool m_done_flag; bool m_canceled_flag; diff --git a/src/dialogs/aniedit.cpp b/src/dialogs/aniedit.cpp index 2dea1abed..2e89bcadd 100644 --- a/src/dialogs/aniedit.cpp +++ b/src/dialogs/aniedit.cpp @@ -63,13 +63,13 @@ #define THUMBSIZE (32*guiscale()) /* height of the headers */ -#define HDRSIZE (3 + text_height(widget->font())*2 + 3 + 3) +#define HDRSIZE (3 + text_height(widget->getFont())*2 + 3 + 3) /* width of the frames */ #define FRMSIZE (3 + THUMBSIZE + 3) /* height of the layers */ -#define LAYSIZE (3 + MAX(text_height(widget->font()), THUMBSIZE) + 4) +#define LAYSIZE (3 + MAX(text_height(widget->getFont()), THUMBSIZE) + 4) /* space between icons and other information in the layer */ #define ICONSEP (2*guiscale()) @@ -164,25 +164,22 @@ bool animation_editor_is_movingcel() void switch_between_animation_and_sprite_editor() { const Sprite* sprite = UIContext::instance()->get_current_sprite(); - JWidget window; - JWidget anieditor; - int layer; /* create the window & the animation-editor */ - window = jwindow_new_desktop(); - anieditor = anieditor_new(sprite); + Frame* window = new Frame(true, NULL); + Widget* anieditor = anieditor_new(sprite); current_anieditor = anieditor; jwidget_add_child(window, anieditor); - jwindow_remap(window); + window->remap_window(); /* show the current cel */ - layer = anieditor_get_layer_index(anieditor, sprite->layer); + int layer = anieditor_get_layer_index(anieditor, sprite->layer); if (layer >= 0) anieditor_center_cel(anieditor, layer, sprite->frame); /* show the window */ - jwindow_open_fg(window); + window->open_window_fg(); /* destroy the window */ jwidget_free(window); @@ -200,7 +197,7 @@ void switch_between_animation_and_sprite_editor() static JWidget anieditor_new(const Sprite* sprite) { - JWidget widget = new jwidget(anieditor_type()); + Widget* widget = new Widget(anieditor_type()); AniEditor* anieditor = new AniEditor; anieditor->sprite = sprite; @@ -979,11 +976,11 @@ static void anieditor_draw_header_part(JWidget widget, JRect clip, int x1, int y if (align1 < 0) x = x1+3; else if (align1 == 0) - x = (x1+x2)/2 - text_length(widget->font(), line1)/2; + x = (x1+x2)/2 - text_length(widget->getFont(), line1)/2; else - x = x2 - 3 - text_length(widget->font(), line1); + x = x2 - 3 - text_length(widget->getFont(), line1); - jdraw_text(widget->font(), line1, + jdraw_text(widget->getFont(), line1, x, y1+3, fg, face, TRUE); } @@ -992,12 +989,12 @@ static void anieditor_draw_header_part(JWidget widget, JRect clip, int x1, int y if (align2 < 0) x = x1+3; else if (align2 == 0) - x = (x1+x2)/2 - text_length(widget->font(), line2)/2; + x = (x1+x2)/2 - text_length(widget->getFont(), line2)/2; else - x = x2 - 3 - text_length(widget->font(), line2); + x = x2 - 3 - text_length(widget->getFont(), line2); - jdraw_text(widget->font(), line2, - x, y1+3+ji_font_get_size(widget->font())+3, + jdraw_text(widget->getFont(), line2, + x, y1+3+ji_font_get_size(widget->getFont())+3, fg, face, TRUE); } } @@ -1102,16 +1099,16 @@ static void anieditor_draw_layer(JWidget widget, JRect clip, int layer_index) u += ICONBORDER+icon2->w+ICONBORDER+ICONSEP; /* draw the layer's name */ - jdraw_text(widget->font(), layer->get_name().c_str(), - u, y_mid - ji_font_get_size(widget->font())/2, + jdraw_text(widget->getFont(), layer->get_name().c_str(), + u, y_mid - ji_font_get_size(widget->getFont())/2, fg, bg, TRUE); /* the background should be underlined */ if (layer->is_background()) { hline(ji_screen, u, - y_mid - ji_font_get_size(widget->font())/2 + ji_font_get_size(widget->font()) + 1, - u + text_length(widget->font(), layer->get_name().c_str()), + y_mid - ji_font_get_size(widget->getFont())/2 + ji_font_get_size(widget->getFont()) + 1, + u + text_length(widget->getFont(), layer->get_name().c_str()), fg); } diff --git a/src/dialogs/drawtext.cpp b/src/dialogs/drawtext.cpp index ce102931c..ac07a9c91 100644 --- a/src/dialogs/drawtext.cpp +++ b/src/dialogs/drawtext.cpp @@ -92,11 +92,11 @@ void dialogs_draw_text(Sprite* sprite) get_config_string("DrawText", "Text", "ABCabc")); /* window */ - jwindow_remap(window); - jwindow_center(window); - jwindow_open_fg(window); + window->remap_window(); + window->center_window(); + window->open_window_fg(); - if (jwindow_get_killer(window) == button_ok) { + if (window->get_killer() == button_ok) { color_t color_with_type = colorbutton_get_color(color_but); const char *text = jwidget_get_text(entry_text); const char *size_str = jwidget_get_text(entry_size); @@ -291,5 +291,5 @@ static void update_button_text() { const char *font_str = get_config_string("DrawText", "Font", "allegro.pcx"); - jwidget_set_text(font_button, get_filename(font_str)); + font_button->setText(get_filename(font_str)); } diff --git a/src/dialogs/filesel.cpp b/src/dialogs/filesel.cpp index c3324b435..12e35fb9c 100644 --- a/src/dialogs/filesel.cpp +++ b/src/dialogs/filesel.cpp @@ -90,10 +90,10 @@ jstring ase_file_selector(const jstring& message, const jstring& init_path, const jstring& exts) { - static JWidget window = NULL; - JWidget fileview; - JWidget filename_entry; - JWidget filetype; + static Frame* window = NULL; + Widget* fileview; + Widget* filename_entry; + Widget* filetype; jstring result; file_system_refresh(); @@ -145,9 +145,7 @@ jstring ase_file_selector(const jstring& message, if (!window) { // load the window widget - window = load_widget("filesel.jid", "file_selector"); - if (!window) - return NULL; + window = static_cast(load_widget("filesel.jid", "file_selector")); JWidget box = jwidget_find_name(window, "box"); JWidget goback = jwidget_find_name(window, "goback"); @@ -177,7 +175,7 @@ jstring ase_file_selector(const jstring& message, jwidget_add_hook(filetype, -1, filetype_msg_proc, NULL); jwidget_add_hook(filename_entry, -1, filename_msg_proc, NULL); - jwidget_set_name(fileview, "fileview"); + fileview->setName("fileview"); jview_attach(view, fileview); jwidget_expansive(view, TRUE); @@ -185,8 +183,8 @@ jstring ase_file_selector(const jstring& message, jwidget_add_child(box, view); jwidget_set_min_size(window, JI_SCREEN_W*9/10, JI_SCREEN_H*9/10); - jwindow_remap(window); - jwindow_center(window); + window->remap_window(); + window->center_window(); } else { fileview = jwidget_find_name(window, "fileview"); @@ -217,12 +215,12 @@ jstring ase_file_selector(const jstring& message, jcombobox_add_string(filetype, tok->c_str(), NULL); // file name entry field - jwidget_set_text(filename_entry, init_path.filename().c_str()); + filename_entry->setText(init_path.filename().c_str()); select_filetype_from_filename(window); jentry_select_text(filename_entry, 0, -1); // setup the title of the window - jwidget_set_text(window, message.c_str()); + window->setText(message.c_str()); // get the ok-button JWidget ok = jwidget_find_name(window, "ok"); @@ -232,14 +230,14 @@ jstring ase_file_selector(const jstring& message, // open the window and run... the user press ok? again: - jwindow_open_fg(window); - if (jwindow_get_killer(window) == ok || - jwindow_get_killer(window) == fileview) { + window->open_window_fg(); + if (window->get_killer() == ok || + window->get_killer() == fileview) { // open the selected file FileItem *folder = fileview_get_current_folder(fileview); assert(folder); - jstring fn = jwidget_get_text(filename_entry); + jstring fn = filename_entry->getText(); jstring buf; FileItem* enter_folder = NULL; @@ -325,7 +323,7 @@ again: fileview_set_current_folder(fileview, enter_folder); // clear the text of the entry widget - jwidget_set_text(filename_entry, ""); + filename_entry->setText(""); // show the window again jwidget_show(window); @@ -401,8 +399,8 @@ static void update_location(JWidget window) jwidget_signal_off(location); jcombobox_select_index(location, selected_index); - jwidget_set_text(jcombobox_get_entry_widget(location), - fileitem_get_displayname(current_folder).c_str()); + jcombobox_get_entry_widget(location) + ->setText(fileitem_get_displayname(current_folder).c_str()); jentry_deselect_text(jcombobox_get_entry_widget(location)); jwidget_signal_on(location); @@ -480,7 +478,7 @@ static void select_filetype_from_filename(JWidget window) { JWidget entry = jwidget_find_name(window, "filename"); JWidget filetype = jwidget_find_name(window, "filetype"); - const char *filename = jwidget_get_text(entry); + const char *filename = entry->getText(); char *p = get_extension(filename); char buf[MAX_PATH]; @@ -493,8 +491,7 @@ static void select_filetype_from_filename(JWidget window) static void goback_command(JWidget widget) { - JWidget fileview = jwidget_find_name(jwidget_get_window(widget), - "fileview"); + JWidget fileview = widget->findSibling("fileview"); if (jlist_length(navigation_history) > 1) { if (!navigation_position) @@ -513,8 +510,7 @@ static void goback_command(JWidget widget) static void goforward_command(JWidget widget) { - JWidget fileview = jwidget_find_name(jwidget_get_window(widget), - "fileview"); + JWidget fileview = widget->findSibling("fileview"); if (jlist_length(navigation_history) > 1) { if (!navigation_position) @@ -533,8 +529,7 @@ static void goforward_command(JWidget widget) static void goup_command(JWidget widget) { - JWidget fileview = jwidget_find_name(jwidget_get_window(widget), - "fileview"); + JWidget fileview = widget->findSibling("fileview"); fileview_goup(fileview); } @@ -548,11 +543,11 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg) FileItem* fileitem = fileview_get_selected(widget); if (!fileitem_is_folder(fileitem)) { - JWidget window = jwidget_get_window(widget); - JWidget entry = jwidget_find_name(window, "filename"); + Frame* window = static_cast(widget->getRoot()); + Widget* entry = window->findChild("filename"); jstring filename = fileitem_get_filename(fileitem).filename(); - jwidget_set_text(entry, filename.c_str()); + entry->setText(filename.c_str()); select_filetype_from_filename(window); } break; @@ -565,7 +560,7 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg) /* when the current folder change */ case SIGNAL_FILEVIEW_CURRENT_FOLDER_CHANGED: { - JWidget window = jwidget_get_window(widget); + Frame* window = static_cast(widget->getRoot()); if (!navigation_locked) add_in_navigation_history(fileview_get_current_folder(widget)); @@ -594,8 +589,7 @@ static bool location_msg_proc(JWidget widget, JMessage msg) jcombobox_get_selected_index(widget))); if (fileitem) { - JWidget fileview = jwidget_find_name(jwidget_get_window(widget), - "fileview"); + Widget* fileview = widget->findSibling("fileview"); fileview_set_current_folder(fileview, fileitem); @@ -620,16 +614,16 @@ static bool filetype_msg_proc(JWidget widget, JMessage msg) change the file-extension in the 'filename' entry widget */ case JI_SIGNAL_COMBOBOX_SELECT: { const char *ext = jcombobox_get_selected_string(widget); - JWidget window = jwidget_get_window(widget); - JWidget entry = jwidget_find_name(window, "filename"); + Frame* window = static_cast(widget->getRoot()); + Widget* entry = window->findChild("filename"); char buf[MAX_PATH]; char *p; - ustrcpy(buf, jwidget_get_text(entry)); + ustrcpy(buf, entry->getText()); p = get_extension(buf); if (p && *p != 0) { ustrcpy(p, ext); - jwidget_set_text(entry, buf); + entry->setText(buf); jentry_select_text(entry, 0, -1); } break; @@ -650,13 +644,12 @@ static bool filename_msg_proc(JWidget widget, JMessage msg) } // string to be autocompleted - jstring left_part = jwidget_get_text(widget); + jstring left_part = widget->getText(); if (left_part.empty()) return FALSE; // first we'll need the fileview widget - JWidget fileview = jwidget_find_name(jwidget_get_window(widget), - "fileview"); + Widget* fileview = widget->findSibling("fileview"); const FileItemList& children = fileview_get_filelist(fileview); @@ -676,7 +669,7 @@ static bool filename_msg_proc(JWidget widget, JMessage msg) // is the pattern (left_part) in the child_name's beginning? if (it2 == left_part.end()) { - jwidget_set_text(widget, child_name.c_str()); + widget->setText(child_name.c_str()); jentry_select_text(widget, child_name.size(), left_part.size()); diff --git a/src/dialogs/maskcol.cpp b/src/dialogs/maskcol.cpp index 818552e9d..26447851e 100644 --- a/src/dialogs/maskcol.cpp +++ b/src/dialogs/maskcol.cpp @@ -53,7 +53,7 @@ static void mask_preview(Sprite* sprite); void dialogs_mask_color(Sprite* sprite) { - JWidget window, box1, box2, box3, box4; + JWidget box1, box2, box3, box4; JWidget label_color, button_1, button_2; JWidget label_fuzziness; JWidget button_ok, button_cancel; @@ -66,7 +66,7 @@ void dialogs_mask_color(Sprite* sprite) if (!image) return; - window = jwindow_new(_("Mask by Color")); + FramePtr window(new Frame(false, _("Mask by Color"))); box1 = jbox_new(JI_VERTICAL); box2 = jbox_new(JI_HORIZONTAL); box3 = jbox_new(JI_HORIZONTAL); @@ -110,8 +110,8 @@ void dialogs_mask_color(Sprite* sprite) jwidget_add_children(box4, button_ok, button_cancel, NULL); /* default position */ - jwindow_remap(window); - jwindow_center(window); + window->remap_window(); + window->center_window(); /* mask first preview */ mask_preview(sprite); @@ -120,9 +120,9 @@ void dialogs_mask_color(Sprite* sprite) load_window_pos(window, "MaskColor"); /* open the window */ - jwindow_open_fg(window); + window->open_window_fg(); - if (jwindow_get_killer(window) == button_ok) { + if (window->get_killer() == button_ok) { Mask *mask; /* undo */ @@ -152,8 +152,6 @@ void dialogs_mask_color(Sprite* sprite) /* save window configuration */ save_window_pos(window, "MaskColor"); - - jwidget_free(window); } static void button_1_command(JWidget widget) diff --git a/src/dialogs/options.cpp b/src/dialogs/options.cpp index d33f9bc3a..62315f0ab 100644 --- a/src/dialogs/options.cpp +++ b/src/dialogs/options.cpp @@ -50,7 +50,6 @@ void dialogs_options() JWidget move_click2, draw_click2, killer; JWidget undo_size_limit; int x, y, old_x, old_y; - char buf[512]; x = get_config_int("Options", "MouseX", 6); y = get_config_int("Options", "MouseY", 6); @@ -60,7 +59,7 @@ void dialogs_options() old_y = y; /* load the window widget */ - JWidgetPtr window(load_widget("options.jid", "options")); + FramePtr window(load_widget("options.jid", "options")); get_widgets(window, "mouse_x", &slider_x, "mouse_y", &slider_y, @@ -87,14 +86,13 @@ void dialogs_options() if (get_config_bool("Options", "Dither", FALSE)) jwidget_select(check_dither); - uszprintf(buf, sizeof(buf), "%d", get_config_int("Options", "UndoSizeLimit", 8)); - jwidget_set_text(undo_size_limit, buf); + undo_size_limit->setTextf("%d", get_config_int("Options", "UndoSizeLimit", 8)); HOOK(slider_x, JI_SIGNAL_SLIDER_CHANGE, slider_mouse_hook, NULL); HOOK(slider_y, JI_SIGNAL_SLIDER_CHANGE, slider_mouse_hook, NULL); - jwindow_open_fg(window); - killer = jwindow_get_killer(window); + window->open_window_fg(); + killer = window->get_killer(); if (killer == button_ok) { int undo_size_limit_value; @@ -109,7 +107,7 @@ void dialogs_options() refresh_all_editors(); } - undo_size_limit_value = undo_size_limit->text_int(); + undo_size_limit_value = undo_size_limit->getTextInt(); undo_size_limit_value = MID(1, undo_size_limit_value, 9999); set_config_int("Options", "UndoSizeLimit", undo_size_limit_value); diff --git a/src/dialogs/repo.cpp b/src/dialogs/repo.cpp index 7325f14fb..cdf66f561 100644 --- a/src/dialogs/repo.cpp +++ b/src/dialogs/repo.cpp @@ -39,9 +39,9 @@ static void delete_command(JWidget widget, void *data); void ji_show_repo_dlg(RepoDlg *repo_dlg) { - JWidget window, box1, box2, view, button_close; + JWidget box1, box2, view, button_close; - window = jwindow_new(repo_dlg->title); + Frame* window = new Frame(false, repo_dlg->title); box1 = jbox_new(JI_HORIZONTAL); box2 = jbox_new(JI_VERTICAL); view = jview_new(); @@ -84,14 +84,14 @@ void ji_show_repo_dlg(RepoDlg *repo_dlg) jwidget_add_child(window, box1); /* default position */ - jwindow_remap(window); - jwindow_center(window); + window->remap_window(); + window->center_window(); /* load window configuration */ load_window_pos(window, repo_dlg->config_section); /* open window */ - jwindow_open_fg(window); + window->open_window_fg(); /* kill the list */ kill_listbox(repo_dlg); diff --git a/src/dialogs/tips.cpp b/src/dialogs/tips.cpp index e65b3dec7..760ba0207 100644 --- a/src/dialogs/tips.cpp +++ b/src/dialogs/tips.cpp @@ -33,7 +33,7 @@ #include "modules/palettes.h" #include "raster/palette.h" -static JWidget tips_new(); +static Widget* tips_new(); static int tips_type(); static bool tips_msg_proc(JWidget widget, JMessage msg); static void tips_request_size(JWidget widget, int *w, int *h); @@ -54,7 +54,7 @@ static bool check_change_hook(JWidget widget, void *data); void dialogs_tips(bool forced) { - JWidget window, vbox, hbox, box; + JWidget vbox, hbox, box; JWidget button_close, button_prev, button_next; JWidget view, tips; JWidget check; @@ -83,7 +83,7 @@ void dialogs_tips(bool forced) } } - window = jwindow_new("Allegro Sprite Editor"); + Frame* window = new Frame(false, "Allegro Sprite Editor"); vbox = jbox_new(JI_VERTICAL); hbox = jbox_new(JI_HORIZONTAL); box = jbox_new(0); @@ -128,7 +128,7 @@ void dialogs_tips(bool forced) /* jwidget_set_static_size(window, 282, 200); */ /* open the window */ - jwindow_open(window); + window->open_window(); jwidget_set_min_size(window, 0, 0); /* load first page */ @@ -136,7 +136,7 @@ void dialogs_tips(bool forced) tips_load_page(tips); /* run the window */ - jwindow_open_fg(window); + window->open_window_fg(); jwidget_free(window); /* restore the palette */ @@ -150,9 +150,9 @@ void dialogs_tips(bool forced) Tips ***********************************************************************/ -static JWidget tips_new() +static Widget* tips_new() { - JWidget widget = new jwidget(tips_type()); + Widget* widget = new Widget(tips_type()); jwidget_add_hook(widget, tips_type(), tips_msg_proc, NULL); jwidget_focusrest(widget, TRUE); @@ -367,7 +367,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 */ JWidget box = jbox_new(0); - jwidget_set_min_size(box, 0, text_height(box->font())); + jwidget_set_min_size(box, 0, text_height(box->getFont())); jwidget_add_child(vbox, box); } diff --git a/src/file/jpeg_format.cpp b/src/file/jpeg_format.cpp index 595d782da..87ea9854d 100644 --- a/src/file/jpeg_format.cpp +++ b/src/file/jpeg_format.cpp @@ -360,7 +360,7 @@ static FormatOptions *get_options_JPEG(FileOp *fop) return (FormatOptions*)jpeg_options; /* widgets */ - JWidgetPtr window(load_widget("jpeg_options.jid", "jpeg_options")); + FramePtr window(load_widget("jpeg_options.jid", "jpeg_options")); JWidget slider_quality, ok; get_widgets(window, "quality", &slider_quality, @@ -368,9 +368,9 @@ static FormatOptions *get_options_JPEG(FileOp *fop) jslider_set_value(slider_quality, jpeg_options->quality * 10.0f); - jwindow_open_fg(window); + window->open_window_fg(); - if (jwindow_get_killer(window) == ok) { + if (window->get_killer() == ok) { jpeg_options->quality = jslider_get_value(slider_quality) / 10.0f; set_config_float("JPEG", "Quality", jpeg_options->quality); } diff --git a/src/jinete/jalert.cpp b/src/jinete/jalert.cpp index 597ba5461..4aae19ccd 100644 --- a/src/jinete/jalert.cpp +++ b/src/jinete/jalert.cpp @@ -61,17 +61,17 @@ #include "jinete/jinete.h" -static JWidget create_alert(char *buf, JList *labels, JList *buttons); +static Frame* create_alert(char *buf, JList *labels, JList *buttons); /* creates a new alert-box the buttons will have names like: button-1, button-2, etc. */ -JWidget jalert_new(const char *format, ...) +Frame* jalert_new(const char *format, ...) { JList labels, buttons; char buf[4096]; - JWidget window; + Frame* window; va_list ap; /* process arguments */ @@ -95,7 +95,8 @@ JWidget jalert_new(const char *format, ...) int jalert(const char *format, ...) { JList labels, buttons; - JWidget window, killer; + Frame* window; + Widget* killer; char buf[4096]; int c, ret = 0; JLink link; @@ -115,10 +116,10 @@ int jalert(const char *format, ...) /* was created succefully? */ if (window) { /* open it */ - jwindow_open_fg(window); + window->open_window_fg(); /* check the killer */ - killer = jwindow_get_killer(window); + killer = window->get_killer(); if (killer) { c = 1; JI_LIST_FOR_EACH(buttons, link) { @@ -141,9 +142,10 @@ int jalert(const char *format, ...) return ret; } -static JWidget create_alert(char *buf, JList *labels, JList *buttons) +static Frame* create_alert(char *buf, JList *labels, JList *buttons) { - JWidget box1, box2, grid, box3, box4, box5, window = NULL; + JWidget box1, box2, grid, box3, box4, box5; + Frame* window = NULL; bool title = true; bool label = false; bool separator = false; @@ -169,11 +171,11 @@ static JWidget create_alert(char *buf, JList *labels, JList *buttons) buf[c] = 0; if (title) { - window = jwindow_new(beg); + window = new Frame(false, beg); } else if (label) { JWidget label = jlabel_new(beg); - jwidget_set_align(label, align); + label->setAlign(align); jlist_append(*labels, label); } else if (separator) { @@ -186,7 +188,7 @@ static JWidget create_alert(char *buf, JList *labels, JList *buttons) jlist_append(*buttons, button_widget); usprintf(button_name, "button-%d", jlist_length(*buttons)); - jwidget_set_name(button_widget, button_name); + button_widget->setName(button_name); } buf[c] = chr; @@ -220,8 +222,8 @@ static JWidget create_alert(char *buf, JList *labels, JList *buttons) box3 = jbox_new(JI_HORIZONTAL | JI_HOMOGENEOUS); /* to identify by the user */ - jwidget_set_name(box2, "labels"); - jwidget_set_name(box3, "buttons"); + box2->setName("labels"); + box3->setName("buttons"); /* pseudo separators (only to fill blank space) */ box4 = jbox_new(0); diff --git a/src/jinete/jalert.h b/src/jinete/jalert.h index d735d024c..f9524cece 100644 --- a/src/jinete/jalert.h +++ b/src/jinete/jalert.h @@ -32,9 +32,9 @@ #ifndef JINETE_JALERT_H_INCLUDED #define JINETE_JALERT_H_INCLUDED -#include "jinete/jbase.h" +class Frame; -JWidget jalert_new(const char *format, ...); +Frame* jalert_new(const char *format, ...); int jalert(const char *format, ...); #endif diff --git a/src/jinete/jbase.h b/src/jinete/jbase.h index 49476a828..efa0eef69 100644 --- a/src/jinete/jbase.h +++ b/src/jinete/jbase.h @@ -73,7 +73,9 @@ union jmessage; struct jrect; struct jregion; class jtheme; -class jwidget; + +class Widget; +class Frame; /* alignment */ #define JI_HORIZONTAL 0x0001 @@ -132,7 +134,7 @@ enum { JI_VIEW, JI_VIEW_SCROLLBAR, JI_VIEW_VIEWPORT, - JI_WINDOW, + JI_FRAME, /* user widgets */ JI_USER_WIDGET, @@ -232,7 +234,7 @@ typedef struct jstream* JStream; typedef struct jrect* JRect; typedef struct jregion* JRegion; typedef class jtheme* JTheme; -typedef class jwidget* JWidget; +typedef class Widget* JWidget; typedef struct jxml* JXml; typedef struct jxmlattr* JXmlAttr; typedef struct jxmlnode* JXmlNode; diff --git a/src/jinete/jbox.cpp b/src/jinete/jbox.cpp index a590d1f20..7247bf89b 100644 --- a/src/jinete/jbox.cpp +++ b/src/jinete/jbox.cpp @@ -45,10 +45,10 @@ static void box_set_position(JWidget widget, JRect rect); JWidget jbox_new(int align) { - JWidget widget = new jwidget(JI_BOX); + Widget* widget = new Widget(JI_BOX); jwidget_add_hook(widget, JI_BOX, box_msg_proc, NULL); - jwidget_set_align(widget, align); + widget->setAlign(align); jwidget_init_theme(widget); return widget; @@ -79,7 +79,7 @@ static void box_request_size(JWidget widget, int *w, int *h) { #define GET_CHILD_SIZE(w, h) \ { \ - if (widget->align() & JI_HOMOGENEOUS) \ + if (widget->getAlign() & JI_HOMOGENEOUS) \ *w = MAX(*w, req_##w); \ else \ *w += req_##w; \ @@ -89,7 +89,7 @@ static void box_request_size(JWidget widget, int *w, int *h) #define FINAL_SIZE(w) \ { \ - if (widget->align() & JI_HOMOGENEOUS) \ + if (widget->getAlign() & JI_HOMOGENEOUS) \ *w *= nvis_children; \ \ *w += widget->child_spacing * (nvis_children-1); \ @@ -117,7 +117,7 @@ static void box_request_size(JWidget widget, int *w, int *h) jwidget_request_size(child, &req_w, &req_h); - if (widget->align() & JI_HORIZONTAL) { + if (widget->getAlign() & JI_HORIZONTAL) { GET_CHILD_SIZE(w, h); } else { @@ -126,7 +126,7 @@ static void box_request_size(JWidget widget, int *w, int *h) } if (nvis_children > 0) { - if (widget->align() & JI_HORIZONTAL) { + if (widget->getAlign() & JI_HORIZONTAL) { FINAL_SIZE(w); } else { @@ -143,7 +143,7 @@ static void box_set_position(JWidget widget, JRect rect) #define FIXUP(x, y, w, h, l, t, r, b) \ { \ if (nvis_children > 0) { \ - if (widget->align() & JI_HOMOGENEOUS) { \ + if (widget->getAlign() & JI_HOMOGENEOUS) { \ width = (jrect_##w(widget->rc) \ - widget->border_width.l \ - widget->border_width.r \ @@ -169,7 +169,7 @@ static void box_set_position(JWidget widget, JRect rect) child = (JWidget)link->data; \ \ if (!(child->flags & JI_HIDDEN)) { \ - if (widget->align() & JI_HOMOGENEOUS) { \ + if (widget->getAlign() & JI_HOMOGENEOUS) { \ if (nvis_children == 1) \ child_width = width; \ else \ @@ -196,7 +196,7 @@ static void box_set_position(JWidget widget, JRect rect) \ w = MAX(1, child_width); \ \ - if (widget->align() & JI_HORIZONTAL) \ + if (widget->getAlign() & JI_HORIZONTAL) \ jrect_replace(&cpos, x, y, x+w, y+h); \ else \ jrect_replace(&cpos, y, x, y+h, x+w); \ @@ -234,7 +234,7 @@ static void box_set_position(JWidget widget, JRect rect) jwidget_request_size(widget, &req_w, &req_h); - if (widget->align() & JI_HORIZONTAL) { + if (widget->getAlign() & JI_HORIZONTAL) { FIXUP(x, y, w, h, l, t, r, b); } else { diff --git a/src/jinete/jbutton.cpp b/src/jinete/jbutton.cpp index 78da1309e..acad141b8 100644 --- a/src/jinete/jbutton.cpp +++ b/src/jinete/jbutton.cpp @@ -43,6 +43,7 @@ #include "jinete/jrect.h" #include "jinete/jtheme.h" #include "jinete/jwidget.h" +#include "jinete/jwindow.h" typedef void (*command_t)(JWidget widget); typedef void (*command_data_t)(JWidget widget, void *data); @@ -78,7 +79,7 @@ JWidget ji_generic_button_new(const char *text, int behavior_type, int draw_type) { - JWidget widget = new jwidget(behavior_type); + Widget* widget = new Widget(behavior_type); Button *button = jnew(Button, 1); button->draw_type = draw_type; @@ -92,8 +93,8 @@ JWidget ji_generic_button_new(const char *text, button->group = 0; jwidget_add_hook(widget, behavior_type, button_msg_proc, button); - jwidget_set_align(widget, JI_CENTER | JI_MIDDLE); - jwidget_set_text(widget, text); + widget->setAlign(JI_CENTER | JI_MIDDLE); + widget->setText(text); jwidget_focusrest(widget, true); // initialize theme @@ -143,7 +144,7 @@ JWidget jbutton_new(const char *text) { JWidget widget = ji_generic_button_new(text, JI_BUTTON, JI_BUTTON); if (widget) - jwidget_set_align(widget, JI_CENTER | JI_MIDDLE); + widget->setAlign(JI_CENTER | JI_MIDDLE); return widget; } @@ -204,7 +205,7 @@ JWidget jcheck_new(const char *text) { JWidget widget = ji_generic_button_new(text, JI_CHECK, JI_CHECK); if (widget) { - jwidget_set_align(widget, JI_LEFT | JI_MIDDLE); + widget->setAlign(JI_LEFT | JI_MIDDLE); } return widget; } @@ -216,7 +217,7 @@ JWidget jradio_new(const char *text, int radio_group) { JWidget widget = ji_generic_button_new(text, JI_RADIO, JI_RADIO); if (widget) { - jwidget_set_align(widget, JI_LEFT | JI_MIDDLE); + widget->setAlign(JI_LEFT | JI_MIDDLE); jradio_set_group(widget, radio_group); } return widget; @@ -240,7 +241,7 @@ int jradio_get_group(JWidget widget) void jradio_deselect_group(JWidget widget) { - JWidget window = jwidget_get_window(widget); + Frame* window = static_cast(widget->getRoot()); if (window) button_deselect_group(window, jradio_get_group(widget)); } diff --git a/src/jinete/jcombobox.cpp b/src/jinete/jcombobox.cpp index 83abfa584..ae0c1f554 100644 --- a/src/jinete/jcombobox.cpp +++ b/src/jinete/jcombobox.cpp @@ -35,28 +35,28 @@ #include "jinete/jinete.h" -typedef struct ComboBox +struct ComboBox { - JWidget entry; - JWidget button; - JWidget window; - JWidget listbox; + Widget* entry; + Widget* button; + Frame* window; + Widget* listbox; JList items; int selected; bool editable : 1; bool clickopen : 1; bool casesensitive : 1; -} ComboBox; +}; -typedef struct ComboItem +struct ComboItem { - char *text; - void *data; -} ComboItem; + char* text; + void* data; +}; -#define COMBOBOX(widget) ((ComboBox *)jwidget_get_data(widget, JI_COMBOBOX)) +#define COMBOBOX(widget) ((ComboBox*)jwidget_get_data(widget, JI_COMBOBOX)) #define IS_VALID_ITEM(widget, index) \ - (index >= 0 && index < jlist_length(COMBOBOX(widget)->items)) + (index >= 0 && (size_t)index < jlist_length(COMBOBOX(widget)->items)) static bool combobox_msg_proc(JWidget widget, JMessage msg); static bool combobox_entry_msg_proc(JWidget widget, JMessage msg); @@ -73,7 +73,7 @@ static void comboitem_free(ComboItem *item); JWidget jcombobox_new() { - JWidget widget = new jwidget(JI_COMBOBOX); + Widget* widget = new Widget(JI_COMBOBOX); ComboBox *combobox = jnew(ComboBox, 1); combobox->entry = jentry_new(256, ""); @@ -208,7 +208,7 @@ void jcombobox_select_index(JWidget widget, int index) combobox->selected = index; item = reinterpret_cast(link->data); - jwidget_set_text(combobox->entry, item->text); + combobox->entry->setText(item->text); } } @@ -235,7 +235,7 @@ const char *jcombobox_get_string(JWidget widget, int index) { ComboBox* combobox = reinterpret_cast(jwidget_get_data(widget, JI_COMBOBOX)); - if (index >= 0 && index < jlist_length(combobox->items)) { + if (index >= 0 && (size_t)index < jlist_length(combobox->items)) { ComboItem* item = reinterpret_cast(jlist_nth_link(combobox->items, index)->data); return item->text; } @@ -247,7 +247,7 @@ void *jcombobox_get_data(JWidget widget, int index) { ComboBox* combobox = reinterpret_cast(jwidget_get_data(widget, JI_COMBOBOX)); - if (index >= 0 && index < jlist_length(combobox->items)) { + if (index >= 0 && (size_t)index < jlist_length(combobox->items)) { ComboItem* item = reinterpret_cast(jlist_nth_link(combobox->items, index)->data); return item->data; } @@ -321,7 +321,7 @@ static bool combobox_msg_proc(JWidget widget, JMessage msg) /* get the text-length of every item and put in 'w' the maximum value */ JI_LIST_FOR_EACH(combobox->items, link) { - int item_w = 2+text_length(widget->font(), + int item_w = 2+text_length(widget->getFont(), ((ComboItem *)link->data)->text)+2; w = MAX(w, item_w); @@ -360,7 +360,7 @@ static bool combobox_msg_proc(JWidget widget, JMessage msg) case JM_WINMOVE: if (combobox->window) { JRect rc = combobox_get_windowpos(combobox); - jwindow_move(combobox->window, rc); + combobox->window->move_window(rc); jrect_free(rc); } break; @@ -511,7 +511,7 @@ static void combobox_open_window(JWidget widget) int size; JRect rc; - combobox->window = jwindow_new(NULL); + combobox->window = new Frame(false, NULL); view = jview_new(); combobox->listbox = jlistbox_new(); @@ -525,13 +525,13 @@ static void combobox_open_window(JWidget widget) jlistitem_new(item->text)); } - jwindow_ontop(combobox->window, true); + combobox->window->set_ontop(true); jwidget_noborders(combobox->window); size = jlist_length(combobox->items); jwidget_set_min_size (view, - jrect_w(combobox->entry->rc), + combobox->button->rc->x2 - combobox->entry->rc->x1, 2+(2+jwidget_get_text_height(combobox->listbox))*MID(1, size, 16)+2); jwidget_add_child(combobox->window, view); @@ -541,15 +541,15 @@ static void combobox_open_window(JWidget widget) jlistbox_select_index(combobox->listbox, combobox->selected); jwidget_signal_on(combobox->listbox); - jwindow_remap(combobox->window); + combobox->window->remap_window(); rc = combobox_get_windowpos(combobox); - jwindow_position(combobox->window, rc->x1, rc->y1); + combobox->window->position_window(rc->x1, rc->y1); jrect_free(rc); jmanager_add_msg_filter(JM_BUTTONPRESSED, widget); - jwindow_open_bg(combobox->window); + combobox->window->open_window_bg(); jmanager_set_focus(combobox->listbox); } } @@ -558,7 +558,7 @@ static void combobox_close_window(JWidget widget) { ComboBox* combobox = reinterpret_cast(jwidget_get_data(widget, JI_COMBOBOX)); if (combobox->window) { - jwindow_close(combobox->window, widget); + combobox->window->closeWindow(widget); jwidget_free(combobox->window); combobox->window = NULL; @@ -580,9 +580,8 @@ static JRect combobox_get_windowpos(ComboBox *combobox) { JRect rc = jrect_new(combobox->entry->rc->x1, combobox->entry->rc->y2, - combobox->entry->rc->x2, - combobox->entry->rc->y2+ - jrect_h(combobox->window->rc)); + combobox->button->rc->x2, + combobox->entry->rc->y2+jrect_h(combobox->window->rc)); if (rc->y2 > JI_SCREEN_H) jrect_displace(rc, 0, -(jrect_h(rc)+jrect_h(combobox->entry->rc))); return rc; diff --git a/src/jinete/jdraw.cpp b/src/jinete/jdraw.cpp index 8fa7fbdbf..30eb4e7d0 100644 --- a/src/jinete/jdraw.cpp +++ b/src/jinete/jdraw.cpp @@ -220,10 +220,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) { - if (widget->text()) { + if (widget->getText()) { struct jrect box, text, icon; jwidget_get_texticon_info(widget, &box, &text, &icon, 0, 0, 0); - jdraw_text(widget->font(), widget->text(), + jdraw_text(widget->getFont(), widget->getText(), text.x1, text.y1, fg, bg, fill_bg); } } diff --git a/src/jinete/jentry.cpp b/src/jinete/jentry.cpp index 82a482914..d8866693d 100644 --- a/src/jinete/jentry.cpp +++ b/src/jinete/jentry.cpp @@ -91,7 +91,7 @@ static void entry_backward_word(JWidget widget); JWidget jentry_new(size_t maxsize, const char *format, ...) { - JWidget widget = new jwidget(JI_ENTRY); + Widget* widget = new Widget(JI_ENTRY); Entry* entry = (Entry*)jnew(Entry, 1); char buf[4096]; @@ -122,7 +122,7 @@ JWidget jentry_new(size_t maxsize, const char *format, ...) /* TODO support for text alignment and multi-line */ /* widget->align = JI_LEFT | JI_MIDDLE; */ - widget->text(buf); + widget->setText(buf); jwidget_focusrest(widget, true); jwidget_init_theme(widget); @@ -179,7 +179,7 @@ void jentry_hide_cursor(JWidget widget) void jentry_set_cursor_pos(JWidget widget, int pos) { Entry* entry = reinterpret_cast(jwidget_get_data(widget, JI_ENTRY)); - const char *text = widget->text(); + const char *text = widget->getText(); int x, c; entry->cursor = pos; @@ -193,7 +193,7 @@ void jentry_set_cursor_pos(JWidget widget, int pos) do { x = widget->rc->x1 + widget->border_width.l; for (c=++entry->scroll; ; c++) { - x += CHARACTER_LENGTH(widget->font(), + x += CHARACTER_LENGTH(widget->getFont(), (c < ustrlen(text))? ugetat(text, c): ' '); if (x >= widget->rc->x2-widget->border_width.r) @@ -210,7 +210,7 @@ void jentry_set_cursor_pos(JWidget widget, int pos) void jentry_select_text(JWidget widget, int from, int to) { Entry* entry = reinterpret_cast(jwidget_get_data(widget, JI_ENTRY)); - int end = ustrlen(widget->text()); + int end = ustrlen(widget->getText()); entry->select = from; jentry_set_cursor_pos(widget, from); // to move scroll @@ -375,7 +375,7 @@ static bool entry_msg_proc(JWidget widget, JMessage msg) case JM_MOTION: if (jwidget_has_capture(widget)) { - const char *text = widget->text(); + const char *text = widget->getText(); bool move, dirty; int c, x; @@ -397,7 +397,7 @@ static bool entry_msg_proc(JWidget widget, JMessage msg) entry->scroll++; x = widget->rc->x1 + widget->border_width.l; for (c=entry->scroll; ; c++) { - x += CHARACTER_LENGTH(widget->font(), + x += CHARACTER_LENGTH(widget->getFont(), (c < ustrlen(text))? ugetat(text, c): ' '); if (x > widget->rc->x2-widget->border_width.r) { c--; @@ -471,14 +471,14 @@ static void entry_request_size(JWidget widget, int *w, int *h) *w = + widget->border_width.l - + ji_font_char_len(widget->font(), 'w') * MIN(entry->maxsize, 6) + + ji_font_char_len(widget->getFont(), 'w') * MIN(entry->maxsize, 6) + 2 + widget->border_width.r; *w = MIN(*w, JI_SCREEN_W/2); *h = + widget->border_width.t - + text_height(widget->font()) + + text_height(widget->getFont()) + widget->border_width.b; } @@ -493,8 +493,8 @@ static int entry_get_cursor_from_mouse(JWidget widget, JMessage msg) widget->rc->x2-widget->border_width.r-1); x = widget->rc->x1 + widget->border_width.l; - for (c=entry->scroll; ugetat(widget->text(), c); c++) { - w = CHARACTER_LENGTH(widget->font(), ugetat(widget->text(), c)); + for (c=entry->scroll; ugetat(widget->getText(), c); c++) { + w = CHARACTER_LENGTH(widget->getFont(), ugetat(widget->getText(), c)); if (x+w >= widget->rc->x2-widget->border_width.r) break; if ((mx >= x) && (mx < x+w)) { @@ -504,7 +504,7 @@ static int entry_get_cursor_from_mouse(JWidget widget, JMessage msg) x += w; } - if (!ugetat(widget->text(), c)) + if (!ugetat(widget->getText(), c)) if ((mx >= x) && (mx <= widget->rc->x2-widget->border_width.r-1)) cursor = c; @@ -516,7 +516,7 @@ static void entry_execute_cmd(JWidget widget, EntryCmd::Type cmd, int ascii, bool shift_pressed) { Entry* entry = reinterpret_cast(jwidget_get_data(widget, JI_ENTRY)); - std::string text = widget->text(); + std::string text = widget->getText(); int c, selbeg, selend; jtheme_entry_info(widget, NULL, NULL, NULL, &selbeg, &selend); @@ -674,8 +674,8 @@ static void entry_execute_cmd(JWidget widget, EntryCmd::Type cmd, break; } - if (text != widget->text()) { - widget->text(text.c_str()); + if (text != widget->getText()) { + widget->setText(text.c_str()); jwidget_emit_signal(widget, JI_SIGNAL_ENTRY_CHANGE); } @@ -692,14 +692,14 @@ static void entry_forward_word(JWidget widget) Entry* entry = reinterpret_cast(jwidget_get_data(widget, JI_ENTRY)); int ch; - for (; entry->cursortext()); entry->cursor++) { - ch = ugetat(widget->text(), entry->cursor); + for (; entry->cursorgetText()); entry->cursor++) { + ch = ugetat(widget->getText(), entry->cursor); if (IS_WORD_CHAR (ch)) break; } - for (; entry->cursortext()); entry->cursor++) { - ch = ugetat(widget->text(), entry->cursor); + for (; entry->cursorgetText()); entry->cursor++) { + ch = ugetat(widget->getText(), entry->cursor); if (!IS_WORD_CHAR(ch)) { entry->cursor++; break; @@ -713,13 +713,13 @@ static void entry_backward_word(JWidget widget) int ch; for (entry->cursor--; entry->cursor >= 0; entry->cursor--) { - ch = ugetat(widget->text(), entry->cursor); + ch = ugetat(widget->getText(), entry->cursor); if (IS_WORD_CHAR(ch)) break; } for (; entry->cursor >= 0; entry->cursor--) { - ch = ugetat(widget->text(), entry->cursor); + ch = ugetat(widget->getText(), entry->cursor); if (!IS_WORD_CHAR(ch)) { entry->cursor++; break; diff --git a/src/jinete/jfile.cpp b/src/jinete/jfile.cpp index b0ed873ff..ca0fc711b 100644 --- a/src/jinete/jfile.cpp +++ b/src/jinete/jfile.cpp @@ -124,9 +124,8 @@ static JWidget convert_xmlelement_to_widget(TiXmlElement* elem) bool bottom = bool_attr_is_true(elem, "bottom"); const char *_bevel = elem->Attribute("bevel"); - jwidget_set_align(widget, - (left ? JI_LEFT: (right ? JI_RIGHT: JI_CENTER)) | - (top ? JI_TOP: (bottom ? JI_BOTTOM: JI_MIDDLE))); + widget->setAlign((left ? JI_LEFT: (right ? JI_RIGHT: JI_CENTER)) | + (top ? JI_TOP: (bottom ? JI_BOTTOM: JI_MIDDLE))); if (_bevel != NULL) { char *bevel = jstrdup(_bevel); @@ -159,11 +158,10 @@ static JWidget convert_xmlelement_to_widget(TiXmlElement* elem) bool top = bool_attr_is_true(elem, "top"); bool bottom = bool_attr_is_true(elem, "bottom"); - jwidget_set_align(widget, - (center ? JI_CENTER: - (right ? JI_RIGHT: JI_LEFT)) | - (top ? JI_TOP: - (bottom ? JI_BOTTOM: JI_MIDDLE))); + widget->setAlign((center ? JI_CENTER: + (right ? JI_RIGHT: JI_LEFT)) | + (top ? JI_TOP: + (bottom ? JI_BOTTOM: JI_MIDDLE))); } } /* combobox */ @@ -206,11 +204,10 @@ static JWidget convert_xmlelement_to_widget(TiXmlElement* elem) bool top = bool_attr_is_true(elem, "top"); bool bottom = bool_attr_is_true(elem, "bottom"); - jwidget_set_align(widget, - (center ? JI_CENTER: - (right ? JI_RIGHT: JI_LEFT)) | - (top ? JI_TOP: - (bottom ? JI_BOTTOM: JI_MIDDLE))); + widget->setAlign((center ? JI_CENTER: + (right ? JI_RIGHT: JI_LEFT)) | + (top ? JI_TOP: + (bottom ? JI_BOTTOM: JI_MIDDLE))); } } /* listbox */ @@ -244,11 +241,10 @@ static JWidget convert_xmlelement_to_widget(TiXmlElement* elem) bool top = bool_attr_is_true(elem, "top"); bool bottom = bool_attr_is_true(elem, "bottom"); - jwidget_set_align(widget, - (center ? JI_CENTER: - (right ? JI_RIGHT: JI_LEFT)) | - (top ? JI_TOP: - (bottom ? JI_BOTTOM: JI_MIDDLE))); + widget->setAlign((center ? JI_CENTER: + (right ? JI_RIGHT: JI_LEFT)) | + (top ? JI_TOP: + (bottom ? JI_BOTTOM: JI_MIDDLE))); } } /* separator */ @@ -299,9 +295,9 @@ static JWidget convert_xmlelement_to_widget(TiXmlElement* elem) bool desktop = bool_attr_is_true(elem, "desktop"); if (desktop) - widget = jwindow_new_desktop(); + widget = new Frame(true, NULL); else - widget = jwindow_new(TRANSLATE_ATTR(text)); + widget = new Frame(false, TRANSLATE_ATTR(text)); } } @@ -322,7 +318,7 @@ static JWidget convert_xmlelement_to_widget(TiXmlElement* elem) const char *childspacing = elem->Attribute("childspacing"); if (name != NULL) - jwidget_set_name(widget, name); + widget->setName(name); if (tooltip != NULL) jwidget_add_tooltip_text(widget, tooltip); diff --git a/src/jinete/jfilesel.cpp b/src/jinete/jfilesel.cpp index c85146bea..725db7609 100644 --- a/src/jinete/jfilesel.cpp +++ b/src/jinete/jfilesel.cpp @@ -116,7 +116,7 @@ char *ji_file_select_ex(const char *message, const char *exts, JWidget widget_extension) { - JWidget window, box1, box2, box3, box4, panel, view1, view2; + JWidget box1, box2, box3, box4, panel, view1, view2; JWidget button_select, button_cancel, tmp; int size = 1024; char buf[1024]; @@ -133,7 +133,7 @@ char *ji_file_select_ex(const char *message, ustrcpy(buf, init_path); - window = jwindow_new(message); + Frame* window = new Frame(false, message); box1 = jbox_new(JI_VERTICAL); box2 = jbox_new(JI_HORIZONTAL); box3 = jbox_new(JI_HORIZONTAL | JI_HOMOGENEOUS); @@ -219,8 +219,8 @@ char *ji_file_select_ex(const char *message, /* setup window size */ jwidget_set_min_size(panel, JI_SCREEN_W*9/10, JI_SCREEN_H*3/5); - jwindow_remap(window); - jwindow_center(window); + window->remap_window(); + window->center_window(); /* jwidget_set_static_size(panel, JI_SCREEN_W*9/10, JI_SCREEN_H*3/5); */ /* jwidget_set_static_size(panel, 0, 0); */ @@ -232,12 +232,12 @@ char *ji_file_select_ex(const char *message, s = get_filename(buf); if (s > buf) *(s-1) = 0; - jwidget_set_text(entry_path, buf); - jwidget_set_text(entry_name, s); + entry_path->setText(buf); + entry_name->setText(s); /* select the filename */ JI_LIST_FOR_EACH(listbox2->children, link) { - if (ustrcmp(s, jwidget_get_text(reinterpret_cast(link->data))) == 0) { + if (ustrcmp(s, (reinterpret_cast(link->data))->getText()) == 0) { jlistbox_select_child(listbox2, reinterpret_cast(link->data)); break; } @@ -246,19 +246,19 @@ char *ji_file_select_ex(const char *message, jlistbox_center_scroll(listbox2); /* open and run */ - jwindow_open_fg(window); + window->open_window_fg(); /* button "select"? */ - if ((jwindow_get_killer(window) == button_select) || - (jwindow_get_killer(window) == listbox2) || - (jwindow_get_killer(window) == entry_path) || - (jwindow_get_killer(window) == entry_name)) { + if ((window->get_killer() == button_select) || + (window->get_killer() == listbox2) || + (window->get_killer() == entry_path) || + (window->get_killer() == entry_name)) { /* copy the new name */ selected_filename = (char*)jmalloc(1024); - ustrcpy(selected_filename, jwidget_get_text(entry_path)); + ustrcpy(selected_filename, entry_path->getText()); put_backslash(selected_filename); - ustrcat(selected_filename, jwidget_get_text(entry_name)); + ustrcat(selected_filename, entry_name->getText()); fix_filename_slashes(selected_filename); } @@ -298,8 +298,8 @@ void ji_file_select_refresh_listbox() void ji_file_select_enter_to_path(const char *path) { - jwidget_set_text(entry_path, path); - jwidget_set_text(entry_name, ""); + entry_path->setText(path); + entry_name->setText(""); enter_to_path_in_entry(); } @@ -338,9 +338,9 @@ static bool filesel_msg_proc(JWidget widget, JMessage msg) jmanager_set_focus(widget); /* close the window when we double-click in a normal file */ - ustrcpy(filename, jwidget_get_text(entry_path)); + ustrcpy(filename, entry_path->getText()); put_backslash(filename); - ustrcat(filename, jwidget_get_text(entry_name)); + ustrcat(filename, entry_name->getText()); if (file_exists(filename, FA_ALL, &attr)) { if (!(attr & FA_DIREC)) @@ -354,22 +354,22 @@ static bool filesel_msg_proc(JWidget widget, JMessage msg) (jwidget_get_data(widget, filesel_type())); JWidget item = jlistbox_get_selected_child(widget); - const char *filename = item ? jwidget_get_text(item): + const char *filename = item ? item->getText(): empty_string; jwidget_signal_off(the_other_listbox); jlistbox_select_child(the_other_listbox, 0); jwidget_signal_on(the_other_listbox); - jwidget_set_text(entry_path, current_path); - jwidget_set_text(entry_name, filename); + entry_path->setText(current_path); + entry_name->setText(filename); jentry_select_text(entry_name, 0, -1); break; } case JI_SIGNAL_ENTRY_CHANGE: { if (widget == entry_path) { - jwidget_set_text(entry_name, ""); + entry_name->setText(""); } break; } @@ -403,9 +403,9 @@ static bool enter_to_path_in_entry() jmanager_set_focus(entry_path); - fix_filename_path(path, jwidget_get_text(entry_path), sizeof(path)); + fix_filename_path(path, entry_path->getText(), sizeof(path)); put_backslash(path); - ustrcat(path, jwidget_get_text(entry_name)); + ustrcat(path, entry_name->getText()); fixup_filename(buf, from, path); ustrcpy(path, buf); @@ -432,7 +432,7 @@ static bool enter_to_path_in_entry() fill_listbox_with_files(buf, sizeof(buf)); /* change the edit text */ - jwidget_set_text(entry_path, buf); + entry_path->setText(buf); jentry_select_text(entry_path, 0, -1); /* select the filename */ @@ -440,7 +440,7 @@ static bool enter_to_path_in_entry() ustrcpy(from, ".."); JI_LIST_FOR_EACH(listbox1->children, link) { - filename = jwidget_get_text(reinterpret_cast(link->data)); + filename = (reinterpret_cast(link->data))->getText(); #ifdef HAVE_DRIVES if (ustricmp(filename, from) == 0) @@ -494,7 +494,7 @@ static void fill_listbox_callback(const char* filename, int attrib, int param) } JI_LIST_FOR_EACH(*list, link) { - other_filename = jwidget_get_text(reinterpret_cast(link->data)); + other_filename = (reinterpret_cast(link->data))->getText(); if (my_ustrfilecmp(buf, other_filename) < 0) break; } diff --git a/src/jinete/jgrid.cpp b/src/jinete/jgrid.cpp index 2bd9020ea..10bbadaa8 100644 --- a/src/jinete/jgrid.cpp +++ b/src/jinete/jgrid.cpp @@ -80,7 +80,7 @@ static void grid_inc_row_size(Grid *grid, int row, int size); JWidget jgrid_new(int columns, bool same_width_columns) { - JWidget widget = new jwidget(JI_GRID); + Widget* widget = new Widget(JI_GRID); Grid *grid = jnew(Grid, 1); int col; diff --git a/src/jinete/jimage.cpp b/src/jinete/jimage.cpp index 563fb7bc3..a366c7bad 100644 --- a/src/jinete/jimage.cpp +++ b/src/jinete/jimage.cpp @@ -45,10 +45,10 @@ static bool image_msg_proc(JWidget widget, JMessage msg); JWidget jimage_new(BITMAP *bmp, int align) { - JWidget widget = new jwidget(JI_IMAGE); + JWidget widget = new Widget(JI_IMAGE); jwidget_add_hook(widget, JI_IMAGE, image_msg_proc, bmp); - jwidget_set_align(widget, align); + widget->setAlign(align); return widget; } @@ -62,7 +62,7 @@ static bool image_msg_proc(JWidget widget, JMessage msg) struct jrect box, text, icon; jwidget_get_texticon_info(widget, &box, &text, &icon, - widget->align(), bmp->w, bmp->h); + widget->getAlign(), bmp->w, bmp->h); 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; @@ -74,7 +74,7 @@ static bool image_msg_proc(JWidget widget, JMessage msg) struct jrect box, text, icon; jwidget_get_texticon_info(widget, &box, &text, &icon, - widget->align(), bmp->w, bmp->h); + widget->getAlign(), bmp->w, bmp->h); jdraw_rectexclude(widget->rc, &icon, jwidget_get_bg_color(widget)); diff --git a/src/jinete/jinete.h b/src/jinete/jinete.h index 8860af9c4..88cdca788 100644 --- a/src/jinete/jinete.h +++ b/src/jinete/jinete.h @@ -56,10 +56,12 @@ #include "jinete/jmessage.h" #include "jinete/jmutex.h" #include "jinete/jpanel.h" +#include "jinete/jpoint.h" #include "jinete/jquickmenu.h" #include "jinete/jrect.h" #include "jinete/jregion.h" #include "jinete/jsep.h" +#include "jinete/jsize.h" #include "jinete/jslider.h" #include "jinete/jstream.h" #include "jinete/jstring.h" diff --git a/src/jinete/jintern.cpp b/src/jinete/jintern.cpp index 8ba9be1e3..9db86b8f1 100644 --- a/src/jinete/jintern.cpp +++ b/src/jinete/jintern.cpp @@ -120,7 +120,7 @@ void _ji_set_font_of_all_widgets(struct FONT *f) // first of all, we have to set the font to all the widgets for (c=0; csize(); c++) if (_ji_is_valid_widget((*widgets)[c])) - (*widgets)[c]->font(f); + (*widgets)[c]->setFont(f); /* then we can reinitialize the theme of each widget */ for (c=0; csize(); c++) @@ -130,8 +130,8 @@ void _ji_set_font_of_all_widgets(struct FONT *f) /* remap the windows */ for (c=0; csize(); c++) if (_ji_is_valid_widget((*widgets)[c])) { - if ((*widgets)[c]->type == JI_WINDOW) - jwindow_remap((*widgets)[c]); + if ((*widgets)[c]->type == JI_FRAME) + static_cast((*widgets)[c])->remap_window(); } /* refresh the screen */ diff --git a/src/jinete/jintern.h b/src/jinete/jintern.h index 1b241273b..950774375 100644 --- a/src/jinete/jintern.h +++ b/src/jinete/jintern.h @@ -36,6 +36,7 @@ struct FONT; struct BITMAP; +class Frame; ////////////////////////////////////////////////////////////////////// // jintern.c @@ -57,8 +58,8 @@ bool _jwindow_is_moving(); ////////////////////////////////////////////////////////////////////// // jmanager.c -void _jmanager_open_window(JWidget manager, JWidget window); -void _jmanager_close_window(JWidget manager, JWidget window, bool redraw_background); +void _jmanager_open_window(JWidget manager, Frame* frame); +void _jmanager_close_window(JWidget manager, Frame* frame, bool redraw_background); ////////////////////////////////////////////////////////////////////// // jtheme.c diff --git a/src/jinete/jlabel.cpp b/src/jinete/jlabel.cpp index d4687f934..2b3169375 100644 --- a/src/jinete/jlabel.cpp +++ b/src/jinete/jlabel.cpp @@ -39,11 +39,11 @@ static bool label_msg_proc(JWidget widget, JMessage msg); JWidget jlabel_new(const char *text) { - JWidget widget = new jwidget(JI_LABEL); + JWidget widget = new Widget(JI_LABEL); jwidget_add_hook(widget, JI_LABEL, label_msg_proc, NULL); - jwidget_set_align(widget, JI_LEFT | JI_MIDDLE); - jwidget_set_text(widget, text); + widget->setAlign(JI_LEFT | JI_MIDDLE); + widget->setText(text); jwidget_init_theme(widget); return widget; @@ -54,7 +54,7 @@ static bool label_msg_proc(JWidget widget, JMessage msg) switch (msg->type) { case JM_REQSIZE: - if (widget->has_text()) { + if (widget->hasText()) { msg->reqsize.w = jwidget_get_text_length(widget); msg->reqsize.h = jwidget_get_text_height(widget); } diff --git a/src/jinete/jlistbox.cpp b/src/jinete/jlistbox.cpp index ed5650e6a..064e4b033 100644 --- a/src/jinete/jlistbox.cpp +++ b/src/jinete/jlistbox.cpp @@ -52,7 +52,7 @@ static void listitem_request_size(JWidget widget, int *w, int *h); JWidget jlistbox_new() { - JWidget widget = new jwidget(JI_LISTBOX); + JWidget widget = new Widget(JI_LISTBOX); jwidget_add_hook(widget, JI_LISTBOX, listbox_msg_proc, NULL); jwidget_focusrest(widget, true); @@ -63,11 +63,11 @@ JWidget jlistbox_new() JWidget jlistitem_new(const char *text) { - JWidget widget = new jwidget(JI_LISTITEM); + JWidget widget = new Widget(JI_LISTITEM); jwidget_add_hook(widget, JI_LISTITEM, listitem_msg_proc, NULL); - jwidget_set_align(widget, JI_LEFT | JI_MIDDLE); - jwidget_set_text(widget, text); + widget->setAlign(JI_LEFT | JI_MIDDLE); + widget->setText(text); jwidget_init_theme(widget); return widget; @@ -426,7 +426,7 @@ static void listitem_request_size(JWidget widget, int *w, int *h) int req_w, req_h; JLink link; - if (widget->has_text()) { + if (widget->hasText()) { max_w = jwidget_get_text_length(widget); max_h = jwidget_get_text_height(widget); } diff --git a/src/jinete/jmanager.cpp b/src/jinete/jmanager.cpp index 59573bb91..685f6b834 100644 --- a/src/jinete/jmanager.cpp +++ b/src/jinete/jmanager.cpp @@ -44,7 +44,7 @@ #include "jinete/jinete.h" #include "jinete/jintern.h" -#define TOPWND(manager) reinterpret_cast(jlist_first_data((manager)->children)) +#define TOPWND(manager) reinterpret_cast(jlist_first_data((manager)->children)) #define ACCEPT_FOCUS(widget) \ (((widget)->flags & (JI_FOCUSREST | \ @@ -191,7 +191,7 @@ JWidget jmanager_new() n_timers = 0; } - widget = new jwidget(JI_MANAGER); + widget = new Widget(JI_MANAGER); jwidget_add_hook(widget, JI_MANAGER, manager_msg_proc, NULL); @@ -303,7 +303,7 @@ bool jmanager_generate_messages(JWidget manager) /* attract the focus to the magnetic widget... */ /* 1) get the magnetic widget */ - magnet = find_magnetic_widget(jwidget_get_window(window)); + magnet = find_magnetic_widget(window->getRoot()); /* 2) if magnetic widget exists and it doesn't have the focus */ if (magnet && !jwidget_has_focus(magnet)) jmanager_set_focus(magnet); @@ -433,21 +433,21 @@ bool jmanager_generate_messages(JWidget manager) that aren't the desktop) */ if (msg->type == JM_BUTTONPRESSED && !capture_widget && mouse_widget) { - JWidget window = jwidget_get_window(mouse_widget); - JWidget win_manager = window ? jwidget_get_manager(window): NULL; + Frame* window = static_cast(mouse_widget->getRoot()); + JWidget win_manager = window ? window->getManager(): NULL; if ((window) && - (!jwindow_is_desktop(window)) && + (!window->is_desktop()) && (window != TOPWND(win_manager))) { /* put it in the top of the list */ jlist_remove(win_manager->children, window); - if (jwindow_is_ontop(window)) + if (window->is_ontop()) jlist_prepend(win_manager->children, window); else { int pos = jlist_length(win_manager->children); JI_LIST_FOR_EACH_BACK(win_manager->children, link) { - if (jwindow_is_ontop((JWidget)link->data)) + if (((Frame*)link->data)->is_ontop()) break; pos--; } @@ -861,7 +861,7 @@ void jmanager_set_capture(JWidget widget) void jmanager_attract_focus(JWidget widget) { /* get the magnetic widget */ - JWidget magnet = find_magnetic_widget(jwidget_get_window(widget)); + JWidget magnet = find_magnetic_widget(widget->getRoot()); /* if magnetic widget exists and it doesn't have the focus */ if (magnet && !jwidget_has_focus(magnet)) @@ -870,9 +870,7 @@ void jmanager_attract_focus(JWidget widget) void jmanager_focus_first_child(JWidget widget) { - JWidget it; - - for (it=jwidget_get_window(widget); it; it=next_widget(it)) { + for (Widget* it=widget->getRoot(); it; it=next_widget(it)) { if (ACCEPT_FOCUS(it) && !(childs_accept_focus(it, true))) { jmanager_set_focus(it); break; @@ -971,12 +969,12 @@ void jmanager_remove_msg_filter_for(JWidget widget) } /* configures the window for begin the loop */ -void _jmanager_open_window(JWidget manager, JWidget window) +void _jmanager_open_window(JWidget manager, Frame* window) { JMessage msg; // free all widgets of special states - if (jwindow_is_wantfocus(window)) { + if (window->is_wantfocus()) { jmanager_free_capture(); jmanager_free_mouse(); jmanager_free_focus(); @@ -998,7 +996,7 @@ void _jmanager_open_window(JWidget manager, JWidget window) jlist_append(new_windows, window); } -void _jmanager_close_window(JWidget manager, JWidget window, bool redraw_background) +void _jmanager_close_window(JWidget manager, Frame* window, bool redraw_background) { JMessage msg; JRegion reg1; @@ -1012,7 +1010,7 @@ void _jmanager_close_window(JWidget manager, JWidget window, bool redraw_backgro reg1 = NULL; /* close all windows to this desktop */ - if (jwindow_is_desktop(window)) { + if (window->is_desktop()) { JLink link, next; JI_LIST_FOR_EACH_SAFE(manager->children, link, next) { @@ -1023,19 +1021,19 @@ void _jmanager_close_window(JWidget manager, JWidget window, bool redraw_backgro jregion_union(reg1, reg1, reg2); jregion_free(reg2); - _jmanager_close_window(manager, reinterpret_cast(link->data), false); + _jmanager_close_window(manager, reinterpret_cast(link->data), false); } } } /* free all widgets of special states */ - if (capture_widget != NULL && jwidget_get_window(capture_widget) == window) + if (capture_widget != NULL && capture_widget->getRoot() == window) jmanager_free_capture(); - if (mouse_widget != NULL && jwidget_get_window(mouse_widget) == window) + if (mouse_widget != NULL && mouse_widget->getRoot() == window) jmanager_free_mouse(); - if (focus_widget != NULL && jwidget_get_window(focus_widget) == window) + if (focus_widget != NULL && focus_widget->getRoot() == window) jmanager_free_focus(); /* hide window */ @@ -1101,15 +1099,15 @@ static bool manager_msg_proc(JWidget widget, JMessage msg) /* continue sending the message to the children of all windows (until a desktop or foreground window) */ JI_LIST_FOR_EACH(widget->children, link) { - JWidget w = (JWidget)link->data; + Frame* w = (Frame*)link->data; /* send to the window */ JI_LIST_FOR_EACH(w->children, link2) if (jwidget_send_message(reinterpret_cast(link2->data), msg)) return true; - if (jwindow_is_foreground(w) || - jwindow_is_desktop(w)) + if (w->is_foreground() || + w->is_desktop()) break; } @@ -1214,38 +1212,37 @@ static void manager_pump_queue(JWidget widget_manager) #ifdef REPORT_EVENTS { static char *msg_name[] = { - "Open", - "Close", - "Destroy", - "Draw", - "Signal", - "Timer", - "ReqSize", - "SetPos", - "WinMove", - "DrawRgn", - "DeferredFree", - "DirtyChildren", - "QueueProcessing", - "KeyPressed", - "KeyReleased", - "FocusEnter", - "FocusLeave", - "ButtonPressed", - "ButtonReleased", - "DoubleClick", - "MouseEnter", - "MouseLeave", - "Motion", - "SetCursor", - "Wheel", + "JM_OPEN", + "JM_CLOSE", + "JM_DESTROY", + "JM_DRAW", + "JM_SIGNAL", + "JM_TIMER", + "JM_REQSIZE", + "JM_SETPOS", + "JM_WINMOVE", + "JM_DEFERREDFREE", + "JM_DIRTYCHILDREN", + "JM_QUEUEPROCESSING", + "JM_KEYPRESSED", + "JM_KEYRELEASED", + "JM_FOCUSENTER", + "JM_FOCUSLEAVE", + "JM_BUTTONPRESSED", + "JM_BUTTONRELEASED", + "JM_DOUBLECLICK", + "JM_MOUSEENTER", + "JM_MOUSELEAVE", + "JM_MOTION", + "JM_SETCURSOR", + "JM_WHEEL", }; const char *string = (msg->type >= JM_OPEN && msg->type <= JM_WHEEL) ? msg_name[msg->type]: "Unknown"; - printf("Event: %s (%d)\n", string, widget->id); + printf("Event #%d: %s (%d)\n", msg->type, string, widget->id); fflush(stdout); } #endif @@ -1264,7 +1261,7 @@ static void manager_pump_queue(JWidget widget_manager) msg->draw.rect.x1, msg->draw.rect.y1, msg->draw.rect.x2-1, msg->draw.rect.y2-1); #ifdef REPORT_EVENTS - printf("set_clip(%d, %d, %d, %d)\n", + printf(" - set_clip(%d, %d, %d, %d)\n", msg->draw.rect.x1, msg->draw.rect.y1, msg->draw.rect.x2-1, msg->draw.rect.y2-1); fflush(stdout); @@ -1304,7 +1301,7 @@ static void manager_pump_queue(JWidget widget_manager) void jmanager_invalidate_region(JWidget widget, JRegion region) { - JWidget window; + Frame* window; JRegion reg1 = jregion_new(NULL, 0); JRegion reg2 = jregion_new(widget->rc, 0); JRegion reg3; @@ -1315,13 +1312,13 @@ void jmanager_invalidate_region(JWidget widget, JRegion region) /* redraw windows from top to background */ JI_LIST_FOR_EACH(widget->children, link) { - window = (JWidget)link->data; + window = (Frame*)link->data; // invalidate regions of this window jwidget_invalidate_region(window, reg1); /* there is desktop? */ - if (jwindow_is_desktop(window)) + if (window->is_desktop()) break; /* work done */ /* clip this window area for the next window */ @@ -1380,15 +1377,15 @@ static void generate_proc_windows_list() static void generate_proc_windows_list2(JWidget widget) { - JWidget window; + Frame* window; JLink link; if (widget->type == JI_MANAGER) { JI_LIST_FOR_EACH(widget->children, link) { - window = reinterpret_cast(link->data); + window = reinterpret_cast(link->data); jlist_append(proc_windows_list, window); - if (jwindow_is_foreground(window) || - jwindow_is_desktop(window)) + if (window->is_foreground() || + window->is_desktop()) break; } } @@ -1486,15 +1483,15 @@ static void filter_free(Filter* filter) static bool move_focus(JWidget manager, JMessage msg) { int (*cmp)(JWidget, int, int) = NULL; - JWidget focus = NULL; - JWidget it, *list; + Widget* focus = NULL; + Widget* it, **list; bool ret = false; - JWidget window; + Frame* window; int c, count; /* who have the focus */ if (focus_widget) - window = jwidget_get_window(focus_widget); + window = static_cast(focus_widget->getRoot()); else if (!jlist_empty(manager->children)) window = TOPWND(manager); else diff --git a/src/jinete/jmenu.cpp b/src/jinete/jmenu.cpp index 270bcd239..da3486a7a 100644 --- a/src/jinete/jmenu.cpp +++ b/src/jinete/jmenu.cpp @@ -154,7 +154,7 @@ static JWidget find_previtem(JWidget menu, JWidget menuitem); JWidget jmenu_new() { - JWidget widget = new jwidget(JI_MENU); + JWidget widget = new Widget(JI_MENU); Menu *menu = jnew(Menu, 1); menu->menuitem = NULL; @@ -179,7 +179,7 @@ JWidget jmenubar_new() JWidget jmenubox_new() { - JWidget widget = new jwidget(JI_MENUBOX); + JWidget widget = new Widget(JI_MENUBOX); MenuBox *menubox = jnew(MenuBox, 1); menubox->base = NULL; @@ -193,7 +193,7 @@ JWidget jmenubox_new() JWidget jmenuitem_new(const char *text) { - JWidget widget = new jwidget(JI_MENUITEM); + JWidget widget = new Widget(JI_MENUITEM); MenuItem *menuitem = jnew(MenuItem, 1); menuitem->accel = NULL; @@ -202,7 +202,7 @@ JWidget jmenuitem_new(const char *text) menuitem->submenu_menubox = NULL; jwidget_add_hook(widget, JI_MENUITEM, menuitem_msg_proc, menuitem); - jwidget_set_text(widget, text); + widget->setText(text); jwidget_init_theme(widget); return widget; @@ -321,41 +321,39 @@ int jmenuitem_is_highlight(JWidget widget) void jmenu_popup(JWidget menu, int x, int y) { - JWidget window, menubox; Base *base; do { jmouse_poll(); } while (jmouse_b(0)); - /* new window and new menu-box */ - window = jwindow_new(NULL); - menubox = jmenubox_new(); + // new window and new menu-box + Frame* window = new Frame(false, NULL); + Widget* menubox = jmenubox_new(); base = create_base(menubox); base->was_clicked = true; base->is_filtering = true; jmanager_add_msg_filter(JM_BUTTONPRESSED, menubox); - jwindow_moveable(window, false); /* can't move the window */ + window->set_moveable(false); /* can't move the window */ /* set children */ jmenubox_set_menu(menubox, menu); jwidget_add_child(window, menubox); - jwindow_remap(window); + window->remap_window(); /* menubox position */ - jwindow_position(window, - MID(0, x, JI_SCREEN_W-jrect_w(window->rc)), - MID(0, y, JI_SCREEN_H-jrect_h(window->rc))); + window->position_window(MID(0, x, JI_SCREEN_W-jrect_w(window->rc)), + MID(0, y, JI_SCREEN_H-jrect_h(window->rc))); /* set the focus to the new menubox */ jmanager_set_focus(menubox); jwidget_magnetic(menubox, true); /* open the window */ - jwindow_open_fg(window); + window->open_window_fg(); /* free the keyboard focus */ jmanager_free_focus(); @@ -768,8 +766,8 @@ static bool menubox_msg_proc(JWidget widget, JMessage msg) default: if (msg->type == JM_CLOSE_POPUP) { - _jmanager_close_window(jwidget_get_manager(widget), - jwidget_get_window(widget), true); + _jmanager_close_window(widget->getManager(), + static_cast(widget->getRoot()), true); } break; @@ -839,9 +837,10 @@ static bool menuitem_msg_proc(JWidget widget, JMessage msg) default: if (msg->type == JM_OPEN_MENUITEM) { Base* base = get_base(widget); - JWidget window, menubox; + Frame* window; + Widget* menubox; JRect pos, old_pos; - bool select_first = (bool)msg->user.a; + bool select_first = msg->user.a ? true: false; assert(base != NULL); assert(base->is_processing); @@ -850,20 +849,20 @@ static bool menuitem_msg_proc(JWidget widget, JMessage msg) old_pos = jwidget_get_rect(widget->parent->parent); /* new window and new menu-box */ - window = jwindow_new(NULL); + window = new Frame(false, NULL); jwidget_add_hook(window, -1, window_msg_proc, NULL); menubox = jmenubox_new(); menuitem->submenu_menubox = menubox; - jwindow_moveable(window, false); /* can't move the window */ + window->set_moveable(false); // can't move the window /* set children */ jmenubox_set_menu(menubox, menuitem->submenu); jwidget_add_child(window, menubox); - jwindow_remap(window); + window->remap_window(); /* menubox position */ pos = jwidget_get_rect(window); @@ -910,7 +909,7 @@ static bool menuitem_msg_proc(JWidget widget, JMessage msg) jrect_moveto(pos, x, y); } - jwindow_position(window, pos->x1, pos->y1); + window->position_window(pos->x1, pos->y1); jrect_free(pos); /* set the focus to the new menubox */ @@ -943,7 +942,7 @@ static bool menuitem_msg_proc(JWidget widget, JMessage msg) unhighlight(menuitem->submenu); /* run in background */ - jwindow_open_bg(window); + window->open_window_bg(); base->is_processing = false; @@ -952,8 +951,9 @@ static bool menuitem_msg_proc(JWidget widget, JMessage msg) } else if (msg->type == JM_CLOSE_MENUITEM) { Base* base = get_base(widget); - JWidget menubox, window; - bool last_of_close_chain = (bool)msg->user.a; + Frame* window; + Widget* menubox; + bool last_of_close_chain = msg->user.a ? true: false; assert(base != NULL); assert(base->is_processing); @@ -963,14 +963,14 @@ static bool menuitem_msg_proc(JWidget widget, JMessage msg) assert(menubox != NULL); - window = menubox->parent; - assert(window && window->type == JI_WINDOW); + window = (Frame*)menubox->parent; + assert(window && window->type == JI_FRAME); /* fetch the "menu" to avoid free it with 'jwidget_free()' */ jmenubox_set_menu(menubox, NULL); /* destroy the window */ - jwindow_close(window, NULL); + window->closeWindow(NULL); /* set the focus to this menu-box of this menu-item */ if (base->close_all) @@ -1006,7 +1006,7 @@ static void menuitem_request_size(JWidget widget, int *w, int *h) MenuItem *menuitem = MITEM(widget); int bar = widget->parent->parent->type == JI_MENUBAR; - if (widget->has_text()) { + if (widget->hasText()) { *w = + widget->border_width.l + jwidget_get_text_length(widget) @@ -1021,7 +1021,7 @@ static void menuitem_request_size(JWidget widget, int *w, int *h) if (menuitem->accel) { char buf[256]; jaccel_to_string(menuitem->accel, buf); - *w += ji_font_text_len(widget->font(), buf); + *w += ji_font_text_len(widget->getFont(), buf); } } else { @@ -1341,10 +1341,10 @@ static JWidget check_for_letter(JWidget menu, int ascii) if (menuitem->type != JI_MENUITEM) continue; - if (menuitem->has_text()) - for (c=0; menuitem->text()[c]; c++) - if ((menuitem->text()[c] == '&') && (menuitem->text()[c+1] != '&')) - if (tolower(ascii) == tolower(menuitem->text()[c+1])) + if (menuitem->hasText()) + for (c=0; menuitem->getText()[c]; c++) + if ((menuitem->getText()[c] == '&') && (menuitem->getText()[c+1] != '&')) + if (tolower(ascii) == tolower(menuitem->getText()[c+1])) return menuitem; } diff --git a/src/jinete/jpanel.cpp b/src/jinete/jpanel.cpp index bfe05947a..a4eaf79c1 100644 --- a/src/jinete/jpanel.cpp +++ b/src/jinete/jpanel.cpp @@ -49,11 +49,11 @@ static void panel_set_position(JWidget widget, JRect rect); JWidget jpanel_new(int align) { - JWidget widget = new jwidget(JI_PANEL); + Widget* widget = new Widget(JI_PANEL); Panel *panel = jnew(Panel, 1); jwidget_add_hook(widget, JI_PANEL, panel_msg_proc, panel); - jwidget_set_align(widget, align); + widget->setAlign(align); panel->pos = 50; @@ -117,7 +117,7 @@ static bool panel_msg_proc(JWidget widget, JMessage msg) ++bar; - if (widget->align() & JI_HORIZONTAL) { + if (widget->getAlign() & JI_HORIZONTAL) { x1 = c1->rc->x2; y1 = widget->rc->y1; x2 = c2->rc->x1; @@ -149,7 +149,7 @@ static bool panel_msg_proc(JWidget widget, JMessage msg) if (jwidget_has_capture(widget)) { Panel* panel = reinterpret_cast(jwidget_get_data(widget, JI_PANEL)); - if (widget->align() & JI_HORIZONTAL) { + if (widget->getAlign() & JI_HORIZONTAL) { panel->pos = 100.0 * (msg->mouse.x-widget->rc->x1) / jrect_w(widget->rc); } @@ -185,7 +185,7 @@ static bool panel_msg_proc(JWidget widget, JMessage msg) c1 = reinterpret_cast(link->data); c2 = reinterpret_cast(link->next->data); - if (widget->align() & JI_HORIZONTAL) { + if (widget->getAlign() & JI_HORIZONTAL) { x1 = c1->rc->x2; y1 = widget->rc->y1; x2 = c2->rc->x1; @@ -207,7 +207,7 @@ static bool panel_msg_proc(JWidget widget, JMessage msg) } if (change_cursor) { - if (widget->align() & JI_HORIZONTAL) + if (widget->getAlign() & JI_HORIZONTAL) jmouse_set_cursor(JI_CURSOR_SIZE_L); else jmouse_set_cursor(JI_CURSOR_SIZE_T); @@ -259,14 +259,14 @@ static void panel_request_size(JWidget widget, int *w, int *h) jwidget_request_size(child, &req_w, &req_h); - if (widget->align() & JI_HORIZONTAL) + if (widget->getAlign() & JI_HORIZONTAL) GET_CHILD_SIZE(w, h); else GET_CHILD_SIZE(h, w); } if (nvis_children > 0) { - if (widget->align() & JI_HORIZONTAL) + if (widget->getAlign() & JI_HORIZONTAL) FINAL_SIZE(w); else FINAL_SIZE(h); @@ -315,7 +315,7 @@ static void panel_set_position(JWidget widget, JRect rect) jwidget_request_size(child1, &req1_w, &req1_h); jwidget_request_size(child2, &req2_w, &req2_h); - if (widget->align() & JI_HORIZONTAL) + if (widget->getAlign() & JI_HORIZONTAL) FIXUP(x, y, w, h, l, t, r, b); else FIXUP(y, x, h, w, t, l, b, r); diff --git a/src/jinete/jsep.cpp b/src/jinete/jsep.cpp index 406d5c965..5c4d3a2a1 100644 --- a/src/jinete/jsep.cpp +++ b/src/jinete/jsep.cpp @@ -39,13 +39,13 @@ static bool separator_msg_proc(JWidget widget, JMessage msg); -JWidget ji_separator_new(const char *text, int align) +JWidget ji_separator_new(const char* text, int align) { - JWidget widget = new jwidget(JI_SEPARATOR); + Widget* widget = new Widget(JI_SEPARATOR); jwidget_add_hook(widget, JI_SEPARATOR, separator_msg_proc, NULL); - jwidget_set_align(widget, align); - jwidget_set_text(widget, text); + widget->setAlign(align); + widget->setText(text); jwidget_init_theme(widget); return widget; @@ -70,7 +70,7 @@ static bool separator_msg_proc(JWidget widget, JMessage msg) max_h = MAX(max_h, req_h); } - if (widget->has_text()) + if (widget->hasText()) max_w = MAX(max_w, jwidget_get_text_length(widget)); msg->reqsize.w = widget->border_width.l + max_w + widget->border_width.r; diff --git a/src/jinete/jslider.cpp b/src/jinete/jslider.cpp index d71c3fd74..7bc992b0a 100644 --- a/src/jinete/jslider.cpp +++ b/src/jinete/jslider.cpp @@ -58,8 +58,8 @@ static void slider_setcursor(JWidget widget); JWidget jslider_new(int min, int max, int value) { - JWidget widget = new jwidget(JI_SLIDER); - Slider *slider = jnew(Slider, 1); + Widget* widget = new Widget(JI_SLIDER); + Slider* slider = jnew(Slider, 1); slider->min = min; slider->max = max; @@ -281,13 +281,13 @@ static void slider_request_size(JWidget widget, int *w, int *h) char buf[256]; usprintf(buf, "%d", slider->min); - min_w = ji_font_text_len(widget->font(), buf); + min_w = ji_font_text_len(widget->getFont(), buf); usprintf(buf, "%d", slider->max); - max_w = ji_font_text_len(widget->font(), buf); + max_w = ji_font_text_len(widget->getFont(), buf); *w = MAX(min_w, max_w); - *h = text_height(widget->font()); + *h = text_height(widget->getFont()); *w += widget->border_width.l + widget->border_width.r; *h += widget->border_width.t + widget->border_width.b; diff --git a/src/jinete/jtextbox.cpp b/src/jinete/jtextbox.cpp index 52fd278d4..7c746b1ea 100644 --- a/src/jinete/jtextbox.cpp +++ b/src/jinete/jtextbox.cpp @@ -49,12 +49,12 @@ static void textbox_request_size(JWidget widget, int *w, int *h); JWidget jtextbox_new(const char *text, int align) { - JWidget widget = new jwidget(JI_TEXTBOX); + Widget* widget = new Widget(JI_TEXTBOX); jwidget_add_hook(widget, JI_TEXTBOX, textbox_msg_proc, NULL); jwidget_focusrest(widget, true); - jwidget_set_align(widget, align); - jwidget_set_text(widget, text); + widget->setAlign(align); + widget->setText(text); jwidget_init_theme(widget); @@ -204,7 +204,7 @@ static void textbox_request_size(JWidget widget, int *w, int *h) _ji_theme_textbox_draw(NULL, widget, w, h, 0, 0); - if (widget->align() & JI_WORDWRAP) { + if (widget->getAlign() & JI_WORDWRAP) { JWidget view = jwidget_get_view(widget); int width, min = *w; diff --git a/src/jinete/jtheme.cpp b/src/jinete/jtheme.cpp index f88f1930f..a3b4de513 100644 --- a/src/jinete/jtheme.cpp +++ b/src/jinete/jtheme.cpp @@ -185,14 +185,14 @@ void _ji_theme_textbox_draw(BITMAP *bmp, JWidget widget, int *w, int *h, int bg, int fg) { JWidget view = jwidget_get_view(widget); - char *text = (char*)widget->text(); // TODO warning: removing const modifier + char *text = (char*)widget->getText(); // TODO warning: removing const modifier char *beg, *end; int x1, y1, x2, y2; int x, y, chr, len; int scroll_x, scroll_y; int viewport_w, viewport_h; int textheight = jwidget_get_text_height(widget); - FONT *font = widget->font(); + FONT *font = widget->getFont(); char *beg_end, *old_end; int width; @@ -218,7 +218,7 @@ void _ji_theme_textbox_draw(BITMAP *bmp, JWidget widget, chr = 0; /* without word-wrap */ - if (!(widget->align() & JI_WORDWRAP)) { + if (!(widget->getAlign() & JI_WORDWRAP)) { width = jrect_w(widget->rc); } /* with word-wrap */ @@ -252,7 +252,7 @@ void _ji_theme_textbox_draw(BITMAP *bmp, JWidget widget, x = x1 - scroll_x; /* without word-wrap */ - if (!(widget->align() & JI_WORDWRAP)) { + if (!(widget->getAlign() & JI_WORDWRAP)) { end = ustrchr(beg, '\n'); if (end) { chr = *end; @@ -302,9 +302,9 @@ void _ji_theme_textbox_draw(BITMAP *bmp, JWidget widget, if (bmp) { int xout; - if (widget->align() & JI_CENTER) + if (widget->getAlign() & JI_CENTER) xout = x + width/2 - len/2; - else if (widget->align() & JI_RIGHT) + else if (widget->getAlign() & JI_RIGHT) xout = x + width - len; else /* left */ xout = x; diff --git a/src/jinete/jtheme.h b/src/jinete/jtheme.h index 6997480ba..245724d6c 100644 --- a/src/jinete/jtheme.h +++ b/src/jinete/jtheme.h @@ -85,7 +85,7 @@ public: virtual void draw_view(JWidget widget, JRect clip) = 0; virtual void draw_view_scrollbar(JWidget widget, JRect clip) = 0; virtual void draw_view_viewport(JWidget widget, JRect clip) = 0; - virtual void draw_window(JWidget widget, JRect clip) = 0; + virtual void draw_frame(Frame* frame, JRect clip) = 0; }; diff --git a/src/jinete/jtooltips.cpp b/src/jinete/jtooltips.cpp index 02ede5fa8..8f1110f51 100644 --- a/src/jinete/jtooltips.cpp +++ b/src/jinete/jtooltips.cpp @@ -26,27 +26,16 @@ typedef struct TipData { - JWidget widget; /* widget that shows the tooltip */ - JWidget window; /* window where is the tooltip */ + Widget* widget; // Widget that shows the tooltip + Frame* window; // Frame where is the tooltip char *text; int timer_id; } TipData; -typedef struct TipWindow -{ - bool close_on_buttonpressed; - JRegion hot_region; - bool filtering; -} TipWindow; static int tip_type(); static bool tip_hook(JWidget widget, JMessage msg); -static JWidget tipwindow_new(const char *text, bool close_on_buttonpressed); -static int tipwindow_type(); -static TipWindow *tipwindow_data(JWidget widget); -static bool tipwindow_msg_proc(JWidget widget, JMessage msg); - void jwidget_add_tooltip_text(JWidget widget, const char *text) { TipData* tip = reinterpret_cast(jwidget_get_data(widget, tip_type())); @@ -71,39 +60,6 @@ void jwidget_add_tooltip_text(JWidget widget, const char *text) } } -/** - * Creates a window to show a tool-tip. - */ -JWidget jtooltip_window_new(const char *text) -{ - JWidget window = tipwindow_new(text, false); - - return window; -} - -/** - * @param widget The tooltip window. - * @param region The new hot-region. This pointer is holded by the @a widget. - * So you can't destroy it after calling this routine. - */ -void jtooltip_window_set_hotregion(JWidget widget, JRegion region) -{ - TipWindow *tipwindow = tipwindow_data(widget); - - assert(region != NULL); - - if (tipwindow->hot_region != NULL) - jregion_free(tipwindow->hot_region); - - if (!tipwindow->filtering) { - tipwindow->filtering = true; - jmanager_add_msg_filter(JM_MOTION, widget); - jmanager_add_msg_filter(JM_BUTTONPRESSED, widget); - jmanager_add_msg_filter(JM_KEYPRESSED, widget); - } - tipwindow->hot_region = region; -} - /********************************************************************/ /* hook for widgets that want a tool-tip */ @@ -141,8 +97,8 @@ static bool tip_hook(JWidget widget, JMessage msg) case JM_BUTTONPRESSED: case JM_MOUSELEAVE: if (tip->window) { - jwindow_close(tip->window, NULL); - jwidget_free(tip->window); + tip->window->closeWindow(NULL); + delete tip->window; // widget tip->window = NULL; } @@ -153,7 +109,7 @@ static bool tip_hook(JWidget widget, JMessage msg) case JM_TIMER: if (msg->timer.timer_id == tip->timer_id) { if (!tip->window) { - JWidget window = tipwindow_new(tip->text, true); + Frame* window = new TipWindow(tip->text, true); /* int x = tip->widget->rc->x1; */ /* int y = tip->widget->rc->y2; */ int x = jmouse_x(0)+12; @@ -162,7 +118,7 @@ static bool tip_hook(JWidget widget, JMessage msg) tip->window = window; - jwindow_remap(window); + window->remap_window(); w = jrect_w(window->rc); h = jrect_h(window->rc); @@ -172,10 +128,9 @@ static bool tip_hook(JWidget widget, JMessage msg) y = jmouse_y(0); } - jwindow_position(window, - MID(0, x, JI_SCREEN_W-w), - MID(0, y, JI_SCREEN_H-h)); - jwindow_open(window); + window->position_window(MID(0, x, JI_SCREEN_W-w), + MID(0, y, JI_SCREEN_H-h)); + window->open_window(); } jmanager_stop_timer(tip->timer_id); } @@ -188,91 +143,88 @@ static bool tip_hook(JWidget widget, JMessage msg) /********************************************************************/ /* TipWindow */ -static JWidget tipwindow_new(const char *text, bool close_on_buttonpressed) +TipWindow::TipWindow(const char *text, bool close_on_buttonpressed) + : Frame(false, text) { - JWidget window = jwindow_new(text); JLink link, next; - TipWindow *tipwindow = jnew(TipWindow, 1); - tipwindow->close_on_buttonpressed = close_on_buttonpressed; - tipwindow->hot_region = NULL; - tipwindow->filtering = false; + m_close_on_buttonpressed = close_on_buttonpressed; + m_hot_region = NULL; + m_filtering = false; - jwindow_sizeable(window, false); - jwindow_moveable(window, false); - jwindow_wantfocus(window, false); + set_sizeable(false); + set_moveable(false); + set_wantfocus(false); + setAlign(JI_LEFT | JI_TOP); - jwidget_set_align(window, JI_LEFT | JI_TOP); - - /* remove decorative widgets */ - JI_LIST_FOR_EACH_SAFE(window->children, link, next) + // remove decorative widgets + JI_LIST_FOR_EACH_SAFE(this->children, link, next) jwidget_free(reinterpret_cast(link->data)); - jwidget_add_hook(window, tipwindow_type(), - tipwindow_msg_proc, tipwindow); - jwidget_init_theme(window); - - return window; + jwidget_init_theme(this); } -static int tipwindow_type() +/** + * @param region The new hot-region. This pointer is holded by the @a widget. + * So you can't destroy it after calling this routine. + */ +void TipWindow::set_hotregion(JRegion region) { - static int type = 0; - if (!type) - type = ji_register_widget_type(); - return type; + assert(region != NULL); + + if (m_hot_region != NULL) + jregion_free(m_hot_region); + + if (!m_filtering) { + m_filtering = true; + jmanager_add_msg_filter(JM_MOTION, this); + jmanager_add_msg_filter(JM_BUTTONPRESSED, this); + jmanager_add_msg_filter(JM_KEYPRESSED, this); + } + m_hot_region = region; } -static TipWindow *tipwindow_data(JWidget widget) +bool TipWindow::msg_proc(JMessage msg) { - return (TipWindow *)jwidget_get_data(widget, - tipwindow_type()); -} - -static bool tipwindow_msg_proc(JWidget widget, JMessage msg) -{ - TipWindow *tipwindow = tipwindow_data(widget); - switch (msg->type) { case JM_CLOSE: - if (tipwindow->filtering) { - tipwindow->filtering = false; - jmanager_remove_msg_filter(JM_MOTION, widget); - jmanager_remove_msg_filter(JM_BUTTONPRESSED, widget); - jmanager_remove_msg_filter(JM_KEYPRESSED, widget); + if (m_filtering) { + m_filtering = false; + jmanager_remove_msg_filter(JM_MOTION, this); + jmanager_remove_msg_filter(JM_BUTTONPRESSED, this); + jmanager_remove_msg_filter(JM_KEYPRESSED, this); } break; case JM_DESTROY: - if (tipwindow->filtering) { - tipwindow->filtering = false; - jmanager_remove_msg_filter(JM_MOTION, widget); - jmanager_remove_msg_filter(JM_BUTTONPRESSED, widget); - jmanager_remove_msg_filter(JM_KEYPRESSED, widget); + if (m_filtering) { + m_filtering = false; + jmanager_remove_msg_filter(JM_MOTION, this); + jmanager_remove_msg_filter(JM_BUTTONPRESSED, this); + jmanager_remove_msg_filter(JM_KEYPRESSED, this); } - if (tipwindow->hot_region != NULL) { - jregion_free(tipwindow->hot_region); + if (m_hot_region != NULL) { + jregion_free(m_hot_region); } - jfree(tipwindow); break; case JM_REQSIZE: { int w = 0, h = 0; - _ji_theme_textbox_draw(NULL, widget, &w, &h, 0, 0); + _ji_theme_textbox_draw(NULL, this, &w, &h, 0, 0); msg->reqsize.w = w; - msg->reqsize.h = widget->border_width.t + widget->border_width.b; + msg->reqsize.h = this->border_width.t + this->border_width.b; - if (!jlist_empty(widget->children)) { + if (!jlist_empty(this->children)) { int max_w, max_h; int req_w, req_h; JWidget child; JLink link; max_w = max_h = 0; - JI_LIST_FOR_EACH(widget->children, link) { + JI_LIST_FOR_EACH(this->children, link) { child = (JWidget)link->data; jwidget_request_size(child, &req_w, &req_h); @@ -282,7 +234,7 @@ static bool tipwindow_msg_proc(JWidget widget, JMessage msg) } msg->reqsize.w = MAX(msg->reqsize.w, - widget->border_width.l + max_w + widget->border_width.r); + this->border_width.l + max_w + this->border_width.r); msg->reqsize.h += max_h; } return true; @@ -292,80 +244,81 @@ static bool tipwindow_msg_proc(JWidget widget, JMessage msg) if (msg->signal.num == JI_SIGNAL_INIT_THEME) { int w = 0, h = 0; - widget->border_width.l = 3; - widget->border_width.t = 3; - widget->border_width.r = 3; - widget->border_width.b = 3; + this->border_width.l = 3; + this->border_width.t = 3; + this->border_width.r = 3; + this->border_width.b = 3; - _ji_theme_textbox_draw(NULL, widget, &w, &h, 0, 0); + _ji_theme_textbox_draw(NULL, this, &w, &h, 0, 0); - widget->border_width.t = h-3; + this->border_width.t = h-3; /* setup the background color */ - jwidget_set_bg_color(widget, makecol(255, 255, 200)); + setBgColor(makecol(255, 255, 200)); return true; } break; case JM_MOUSELEAVE: - if (tipwindow->hot_region == NULL) - jwindow_close(widget, NULL); + if (m_hot_region == NULL) + this->closeWindow(NULL); break; case JM_KEYPRESSED: - if (tipwindow->filtering && msg->key.scancode < KEY_MODIFIERS) - jwindow_close(widget, NULL); + if (m_filtering && msg->key.scancode < KEY_MODIFIERS) + this->closeWindow(NULL); break; case JM_BUTTONPRESSED: /* if the user click outside the window, we have to close the tooltip window */ - if (tipwindow->filtering) { - JWidget picked = jwidget_pick(widget, msg->mouse.x, msg->mouse.y); - if (!picked || jwidget_get_window(picked) != widget) { - jwindow_close(widget, NULL); + if (m_filtering) { + JWidget picked = jwidget_pick(this, msg->mouse.x, msg->mouse.y); + if (!picked || picked->getRoot() != this) { + this->closeWindow(NULL); } } /* this is used when the user click inside a small text tooltip */ - if (tipwindow->close_on_buttonpressed) - jwindow_close(widget, NULL); + if (m_close_on_buttonpressed) + this->closeWindow(NULL); break; case JM_MOTION: - if (tipwindow->hot_region != NULL && + if (m_hot_region != NULL && jmanager_get_capture() == NULL) { struct jrect box; /* if the mouse is outside the hot-region we have to close the window */ - if (!jregion_point_in(tipwindow->hot_region, + if (!jregion_point_in(m_hot_region, msg->mouse.x, msg->mouse.y, &box)) { - jwindow_close(widget, NULL); + this->closeWindow(NULL); } } break; case JM_DRAW: { - JRect pos = jwidget_get_rect(widget); + JRect pos = jwidget_get_rect(this); int oldt; jdraw_rect(pos, makecol(0, 0, 0)); jrect_shrink(pos, 1); - jdraw_rectfill(pos, widget->bg_color()); + jdraw_rectfill(pos, this->getBgColor()); - oldt = widget->border_width.t; - widget->border_width.t = 3; - _ji_theme_textbox_draw(ji_screen, widget, NULL, NULL, - widget->bg_color(), + oldt = this->border_width.t; + this->border_width.t = 3; + _ji_theme_textbox_draw(ji_screen, this, NULL, NULL, + this->getBgColor(), ji_color_foreground()); - widget->border_width.t = oldt; + this->border_width.t = oldt; jrect_free(pos); return true; } } - return false; + + return Frame::msg_proc(msg); } diff --git a/src/jinete/jtooltips.h b/src/jinete/jtooltips.h index 3a22daa34..fc2b4258a 100644 --- a/src/jinete/jtooltips.h +++ b/src/jinete/jtooltips.h @@ -33,10 +33,23 @@ #define JINETE_JTOOLTIPS_H_INCLUDED #include "jinete/jbase.h" +#include "jinete/jwindow.h" -void jwidget_add_tooltip_text(JWidget widget, const char *text); +class TipWindow : public Frame +{ + bool m_close_on_buttonpressed; + JRegion m_hot_region; + bool m_filtering; -JWidget jtooltip_window_new(const char *text); -void jtooltip_window_set_hotregion(JWidget window, JRegion region); +public: + TipWindow(const char *text, bool close_on_buttonpressed = false); + + void set_hotregion(JRegion region); + +protected: + bool msg_proc(JMessage msg); +}; + +void jwidget_add_tooltip_text(Widget* widget, const char *text); #endif diff --git a/src/jinete/jview.cpp b/src/jinete/jview.cpp index 1dfbbab05..4fe02621b 100644 --- a/src/jinete/jview.cpp +++ b/src/jinete/jview.cpp @@ -73,8 +73,8 @@ static void displace_widgets(JWidget widget, int x, int y); JWidget jview_new() { - JWidget widget = new jwidget(JI_VIEW); - View *view = jnew(View, 1); + Widget* widget = new Widget(JI_VIEW); + View* view = jnew(View, 1); view->viewport = viewport_new(); view->scrollbar_h = scrollbar_new(JI_HORIZONTAL); @@ -395,7 +395,7 @@ static bool view_msg_proc(JWidget widget, JMessage msg) static JWidget viewport_new() { - JWidget widget = new jwidget(JI_VIEW_VIEWPORT); + Widget* widget = new Widget(JI_VIEW_VIEWPORT); jwidget_add_hook(widget, JI_VIEW_VIEWPORT, viewport_msg_proc, NULL); jwidget_init_theme(widget); @@ -476,10 +476,10 @@ static void viewport_set_position(JWidget widget, JRect rect) static JWidget scrollbar_new(int align) { - JWidget widget = new jwidget(JI_VIEW_SCROLLBAR); + Widget* widget = new Widget(JI_VIEW_SCROLLBAR); jwidget_add_hook(widget, JI_VIEW_SCROLLBAR, scrollbar_msg_proc, NULL); - jwidget_set_align(widget, align); + widget->setAlign(align); jwidget_init_theme(widget); return widget; @@ -503,8 +503,8 @@ static bool scrollbar_msg_proc(JWidget widget, JMessage msg) jtheme_scrollbar_info(widget, &pos, &len); view->wherepos = pos; - view->whereclick = widget->align() & JI_HORIZONTAL ? msg->mouse.x: - msg->mouse.y; + view->whereclick = widget->getAlign() & JI_HORIZONTAL ? msg->mouse.x: + msg->mouse.y; x1 = widget->rc->x1; y1 = widget->rc->y1; @@ -516,7 +516,7 @@ static bool scrollbar_msg_proc(JWidget widget, JMessage msg) u2 = x2 - widget->border_width.r; v2 = y2 - widget->border_width.b; - if (widget->align() & JI_HORIZONTAL) { + if (widget->getAlign() & JI_HORIZONTAL) { /* in the bar */ if (MOUSE_IN(u1+pos, v1, u1+pos+len-1, v2)) { /* capture mouse */ @@ -577,7 +577,7 @@ static bool scrollbar_msg_proc(JWidget widget, JMessage msg) old_pos = pos; if (bar_size > len) { - if (widget->align() & JI_HORIZONTAL) { + if (widget->getAlign() & JI_HORIZONTAL) { pos = (view->wherepos + msg->mouse.x - view->whereclick); pos = MID(0, pos, bar_size - len); @@ -626,7 +626,7 @@ static void scrollbar_info(JWidget widget, int *_pos, int *_len, int pos, len, max, scroll; int border_width; - if (widget->align() & JI_HORIZONTAL) { + if (widget->getAlign() & JI_HORIZONTAL) { max = view->max_w; scroll = view->scroll_x; bar_size = jrect_w(widget->rc) diff --git a/src/jinete/jwidget.cpp b/src/jinete/jwidget.cpp index 273ca6b06..8e7864de8 100644 --- a/src/jinete/jwidget.cpp +++ b/src/jinete/jwidget.cpp @@ -57,7 +57,7 @@ int ji_register_widget_type() return type++; } -jwidget::jwidget(int type) +Widget::Widget(int type) { _ji_add_widget(this); @@ -104,7 +104,7 @@ void jwidget_free(JWidget widget) delete widget; } -jwidget::~jwidget() +Widget::~Widget() { JLink link, next; JMessage msg; @@ -233,64 +233,53 @@ void *jwidget_get_data(JWidget widget, int type) /**********************************************************************/ /* main properties */ -int jwidget_get_type(JWidget widget) +int Widget::getType() { - assert_valid_widget(widget); - - return widget->type; + return this->type; } -const char *jwidget_get_name(JWidget widget) +const char *Widget::getName() { - assert_valid_widget(widget); - - return widget->name; + return this->name; } -const char *jwidget_get_text(JWidget widget) +int Widget::getAlign() const { - assert_valid_widget(widget); - return widget->text(); + return m_align; } -void jwidget_set_name(JWidget widget, const char *name) +void Widget::setName(const char *name) { - assert_valid_widget(widget); + if (this->name) + jfree(this->name); - if (widget->name) - jfree(widget->name); - - widget->name = name ? jstrdup(name) : NULL; + this->name = name ? jstrdup(name) : NULL; } -void jwidget_set_text(JWidget widget, const char *text) +void Widget::setAlign(int align) { - assert_valid_widget(widget); - - widget->set_text_quiet(text); - - jwidget_emit_signal(widget, JI_SIGNAL_SET_TEXT); - jwidget_dirty(widget); + m_align = align; } -void jwidget_set_align(JWidget widget, int align) -{ - assert_valid_widget(widget); - - widget->align(align); -} - -int jwidget::text_int() const +int Widget::getTextInt() const { return ustrtol(m_text.c_str(), NULL, 10); } -double jwidget::text_double() const +double Widget::getTextDouble() const { return ustrtod(m_text.c_str(), NULL); } -void jwidget::textf(const char *format, ...) +void Widget::setText(const char *text) +{ + this->setTextQuiet(text); + + jwidget_emit_signal(this, JI_SIGNAL_SET_TEXT); + dirty(); +} + +void Widget::setTextf(const char *format, ...) { char buf[4096]; @@ -306,10 +295,10 @@ void jwidget::textf(const char *format, ...) ustrcpy(buf, empty_string); } - text(buf); + setText(buf); } -void jwidget::set_text_quiet(const char *text) +void Widget::setTextQuiet(const char *text) { if (text) { m_text = text; @@ -321,17 +310,12 @@ void jwidget::set_text_quiet(const char *text) } } -void jwidget::align(int align) -{ - m_align = align; -} - -FONT *jwidget::font() +FONT *Widget::getFont() { return m_font; } -void jwidget::font(FONT* f) +void Widget::setFont(FONT* f) { m_font = f; @@ -648,21 +632,30 @@ void jwidget_replace_child(JWidget widget, JWidget old_child, JWidget new_child) /**********************************************************************/ /* parents and children */ -/* gets the widget parent */ JWidget jwidget_get_parent(JWidget widget) -{ - assert_valid_widget(widget); +{ return widget->getParent(); } - return widget->parent; -} +JWidget jwidget_get_manager(JWidget widget) +{ return widget->getManager(); } -/* get the parent window */ -JWidget jwidget_get_window(JWidget widget) +JList jwidget_get_parents(JWidget widget, bool ascendant) +{ return widget->getParents(ascendant); } + +JList jwidget_get_children(JWidget widget) +{ return widget->getChildren(); } + +JWidget jwidget_pick(JWidget widget, int x, int y) +{ return widget->pick(x, y); } + +bool jwidget_has_child(JWidget widget, JWidget child) +{ return widget->hasChild(child); } + +Widget* Widget::getRoot() { - assert_valid_widget(widget); + Widget* widget = this; while (widget) { - if (widget->type == JI_WINDOW) + if (widget->type == JI_FRAME) return widget; widget = widget->parent; @@ -671,9 +664,14 @@ JWidget jwidget_get_window(JWidget widget) return NULL; } -JWidget jwidget_get_manager(JWidget widget) +Widget* Widget::getParent() { - assert_valid_widget(widget); + return this->parent; +} + +Widget* Widget::getManager() +{ + Widget* widget = this; while (widget) { if (widget->type == JI_MANAGER) @@ -688,17 +686,15 @@ JWidget jwidget_get_manager(JWidget widget) /* returns a list of parents (you must free the list), if "ascendant" is true the list is build from child to parents, else the list is from parent to children */ -JList jwidget_get_parents(JWidget widget, bool ascendant) +JList Widget::getParents(bool ascendant) { JList list = jlist_new(); - assert_valid_widget(widget); - - for (; widget; widget=widget->parent) { - /* append parents in tail */ + for (Widget* widget=this; widget; widget=widget->parent) { + // append parents in tail if (ascendant) jlist_append(list, widget); - /* append parents in head */ + // append parents in head else jlist_prepend(list, widget); } @@ -707,26 +703,22 @@ JList jwidget_get_parents(JWidget widget, bool ascendant) } /* returns a list of children (you must free the list) */ -JList jwidget_get_children(JWidget widget) +JList Widget::getChildren() { - assert_valid_widget(widget); - - return jlist_copy(widget->children); + return jlist_copy(this->children); } -JWidget jwidget_pick(JWidget widget, int x, int y) +Widget* Widget::pick(int x, int y) { - JWidget inside, picked = NULL; + Widget* inside, *picked = NULL; JLink link; - assert_valid_widget(widget); + if (!(this->flags & JI_HIDDEN) && /* is visible */ + jrect_point_in(this->rc, x, y)) { /* the point is inside the bounds */ + picked = this; - if (!(widget->flags & JI_HIDDEN) && /* is visible */ - jrect_point_in(widget->rc, x, y)) { /* the point is inside the bounds */ - picked = widget; - - JI_LIST_FOR_EACH(widget->children, link) { - inside = jwidget_pick(reinterpret_cast(link->data), x, y); + JI_LIST_FOR_EACH(this->children, link) { + inside = jwidget_pick(reinterpret_cast(link->data), x, y); if (inside) { picked = inside; break; @@ -737,17 +729,54 @@ JWidget jwidget_pick(JWidget widget, int x, int y) return picked; } -bool jwidget_has_child(JWidget widget, JWidget child) +bool Widget::hasChild(Widget* child) { - assert_valid_widget(widget); assert_valid_widget(child); - return jlist_find(widget->children, child) != widget->children->end ? true: false; + return jlist_find(this->children, child) != this->children->end ? true: false; +} + +Widget* Widget::findChild(const char* name) +{ + Widget* child; + JLink link; + + JI_LIST_FOR_EACH(this->children, link) { + child = (Widget*)link->data; + if (child->name != NULL && strcmp(child->name, name) == 0) + return child; + } + + JI_LIST_FOR_EACH(this->children, link) { + if ((child = ((Widget*)link->data)->findChild(name))) + return child; + } + + return 0; +} + +/** + * Returns a widget in the same window that is located "sibling". + */ +Widget* Widget::findSibling(const char* name) +{ + return getRoot()->findChild(name); } /**********************************************************************/ /* position and geometry */ +Rect Widget::getBounds() const +{ + return Rect(rc->x1, rc->y1, jrect_w(rc), jrect_h(rc)); +} + +void Widget::setBounds(const Rect& rc) +{ + jrect jrc = { rc.x, rc.y, rc.x+rc.w, rc.y+rc.h }; + jwidget_set_rect(this, &jrc); +} + void jwidget_request_size(JWidget widget, int *w, int *h) { JMessage msg; @@ -792,7 +821,7 @@ JRegion jwidget_get_region(JWidget widget) assert_valid_widget(widget); - if (widget->type == JI_WINDOW) + if (widget->type == JI_FRAME) region = widget->theme->get_window_mask(widget); else region = jregion_new(widget->rc, 1); @@ -815,7 +844,7 @@ JRegion jwidget_get_drawable_region(JWidget widget, int flags) /* cut the top windows areas */ if (flags & JI_GDR_CUTTOPWINDOWS) { - window = jwidget_get_window(widget); + window = widget->getRoot(); manager = window ? jwidget_get_manager(window): NULL; while (manager) { @@ -833,8 +862,8 @@ JRegion jwidget_get_drawable_region(JWidget widget, int flags) } } - window = jwidget_get_window(manager); - manager = window ? jwidget_get_manager(window): NULL; + window = manager->getRoot(); + manager = window ? window->getManager(): NULL; } } @@ -893,8 +922,8 @@ JRegion jwidget_get_drawable_region(JWidget widget, int flags) } /* limit to the manager area */ - window = jwidget_get_window(widget); - manager = window ? jwidget_get_manager(window): NULL; + window = widget->getRoot(); + manager = window ? window->getManager(): NULL; while (manager) { view = jwidget_get_view(manager); @@ -912,8 +941,8 @@ JRegion jwidget_get_drawable_region(JWidget widget, int flags) jregion_free(reg1); jrect_free(cpos); - window = jwidget_get_window(manager); - manager = window ? jwidget_get_manager(window): NULL; + window = manager->getRoot(); + manager = window ? window->getManager(): NULL; } /* return the region */ @@ -924,7 +953,7 @@ int jwidget_get_bg_color(JWidget widget) { assert_valid_widget(widget); - return widget->bg_color(); + return widget->getBgColor(); } JTheme jwidget_get_theme(JWidget widget) @@ -937,7 +966,7 @@ JTheme jwidget_get_theme(JWidget widget) int jwidget_get_text_length(JWidget widget) { #if 1 - return ji_font_text_len(widget->font(), widget->text()); + return ji_font_text_len(widget->getFont(), widget->getText()); #else /* use cached text size */ return widget->text_size_pix; #endif @@ -947,7 +976,7 @@ int jwidget_get_text_height(JWidget widget) { assert_valid_widget(widget); - return text_height(widget->font()); + return text_height(widget->getFont()); } void jwidget_get_texticon_info(JWidget widget, @@ -970,7 +999,7 @@ void jwidget_get_texticon_info(JWidget widget, text_x = text_y = 0; /* size of the text */ - if (widget->has_text()) { + if (widget->hasText()) { text_w = jwidget_get_text_length(widget); text_h = jwidget_get_text_height(widget); } @@ -987,32 +1016,32 @@ void jwidget_get_texticon_info(JWidget widget, /* with the icon in the top or bottom */ else { box_w = MAX(icon_w, text_w); - box_h = icon_h + (widget->has_text() ? widget->child_spacing: 0) + text_h; + box_h = icon_h + (widget->hasText() ? widget->child_spacing: 0) + text_h; } } /* with the icon in left or right that doesn't care by now */ else { - box_w = icon_w + (widget->has_text() ? widget->child_spacing: 0) + text_w; + box_w = icon_w + (widget->hasText() ? widget->child_spacing: 0) + text_w; box_h = MAX(icon_h, text_h); } /* box position */ - if (widget->align() & JI_RIGHT) + if (widget->getAlign() & JI_RIGHT) box_x = widget->rc->x2 - box_w - widget->border_width.r; - else if (widget->align() & JI_CENTER) + else if (widget->getAlign() & JI_CENTER) box_x = (widget->rc->x1+widget->rc->x2)/2 - box_w/2; else box_x = widget->rc->x1 + widget->border_width.l; - if (widget->align() & JI_BOTTOM) + if (widget->getAlign() & JI_BOTTOM) box_y = widget->rc->y2 - box_h - widget->border_width.b; - else if (widget->align() & JI_MIDDLE) + else if (widget->getAlign() & JI_MIDDLE) box_y = (widget->rc->y1+widget->rc->y2)/2 - box_h/2; else box_y = widget->rc->y1 + widget->border_width.t; /* with text */ - if (widget->has_text()) { + if (widget->hasText()) { /* text/icon X position */ if (icon_align & JI_RIGHT) { text_x = box_x; @@ -1107,7 +1136,8 @@ void jwidget_set_max_size(JWidget widget, int w, int h) void jwidget_set_bg_color(JWidget widget, int color) { assert_valid_widget(widget); - widget->bg_color(color); + + widget->setBgColor(color); } void jwidget_set_theme(JWidget widget, JTheme theme) @@ -1116,7 +1146,7 @@ void jwidget_set_theme(JWidget widget, JTheme theme) widget->theme = theme; /* TODO mmhhh... maybe some JStyle in JWidget should be great */ - widget->font(widget->theme ? widget->theme->default_font: NULL); + widget->setFont(widget->theme ? widget->theme->default_font: NULL); } /**********************************************************************/ @@ -1277,10 +1307,10 @@ bool jwidget_emit_signal(JWidget widget, int signal_num) ret = jwidget_send_message(widget, msg); /* send the signal to the window too */ - if (!ret && widget->type != JI_WINDOW) { - JWidget window = jwidget_get_window(widget); + if (!ret && widget->type != JI_FRAME) { + Widget* window = widget->getRoot(); if (window) - ret = jwidget_send_message(window, msg); + ret = window->sendMessage(msg); } jmessage_free(msg); @@ -1293,42 +1323,48 @@ bool jwidget_emit_signal(JWidget widget, int signal_num) /**********************************************************************/ /* manager handler */ -#define SENDMSG() \ - if (hook->msg_proc) { \ - done = (*hook->msg_proc)(widget, msg); \ - if (done) \ - break; \ - } - bool jwidget_send_message(JWidget widget, JMessage msg) +{ return widget->sendMessage(msg); } + +void jwidget_close_window(JWidget widget) +{ widget->closeWindow(); } + +void jwidget_capture_mouse(JWidget widget) +{ widget->captureMouse(); } + +void jwidget_hard_capture_mouse(JWidget widget) +{ widget->hardCaptureMouse(); } + +void jwidget_release_mouse(JWidget widget) +{ widget->releaseMouse(); } + +bool Widget::sendMessage(JMessage msg) { bool done = false; JHook hook; JLink link; - assert_valid_widget(widget); assert(msg != NULL); - JI_LIST_FOR_EACH(widget->hooks, link) { + JI_LIST_FOR_EACH(this->hooks, link) { hook = reinterpret_cast(link->data); - SENDMSG(); + if (hook->msg_proc) { + done = (*hook->msg_proc)(this, msg); + if (done) + break; + } } if (!done) - done = widget->msg_proc(msg); + done = this->msg_proc(msg); return done; } -void jwidget_close_window(JWidget widget) +void Widget::closeWindow() { - JWidget window; - - assert_valid_widget(widget); - - window = jwidget_get_window(widget); - if (window) - jwindow_close(window, widget); + if (Frame* frame = static_cast(getRoot())) + frame->closeWindow(this); } /** @@ -1339,15 +1375,13 @@ void jwidget_close_window(JWidget widget) * * @see jwidget_hard_capture_mouse */ -void jwidget_capture_mouse(JWidget widget) +void Widget::captureMouse() { - assert_valid_widget(widget); - if (!jmanager_get_capture()) { - jmanager_set_capture(widget); + jmanager_set_capture(this); - if (jmanager_get_capture() == widget) - widget->flags &= ~JI_HARDCAPTURE; + if (jmanager_get_capture() == this) + this->flags &= ~JI_HARDCAPTURE; } } @@ -1357,35 +1391,31 @@ void jwidget_capture_mouse(JWidget widget) * * @see jwidget_capture_mouse */ -void jwidget_hard_capture_mouse(JWidget widget) +void Widget::hardCaptureMouse() { - assert_valid_widget(widget); - if (!jmanager_get_capture()) { - jmanager_set_capture(widget); + jmanager_set_capture(this); #ifdef ALLEGRO_WINDOWS SetCapture(win_get_window()); #endif - if (jmanager_get_capture() == widget) - widget->flags |= JI_HARDCAPTURE; + if (jmanager_get_capture() == this) + this->flags |= JI_HARDCAPTURE; } } /** * Releases the capture of the mouse events. */ -void jwidget_release_mouse(JWidget widget) +void Widget::releaseMouse() { - assert_valid_widget(widget); - - if (jmanager_get_capture() == widget) { + if (jmanager_get_capture() == this) { jmanager_free_capture(); #ifdef ALLEGRO_WINDOWS - ReleaseCapture(); + ::ReleaseCapture(); // Win32 API #endif - widget->flags &= ~JI_HARDCAPTURE; + this->flags &= ~JI_HARDCAPTURE; } } @@ -1394,23 +1424,8 @@ void jwidget_release_mouse(JWidget widget) JWidget jwidget_find_name(JWidget widget, const char *name) { - JWidget child; - JLink link; - assert_valid_widget(widget); - - JI_LIST_FOR_EACH(widget->children, link) { - child = (JWidget)link->data; - if (child->name != NULL && strcmp(child->name, name) == 0) - return child; - } - - JI_LIST_FOR_EACH(widget->children, link) { - if ((child = jwidget_find_name((JWidget)link->data, name))) - return child; - } - - return 0; + return widget->findChild(name); } bool jwidget_check_underscored(JWidget widget, int scancode) @@ -1427,8 +1442,8 @@ bool jwidget_check_underscored(JWidget widget, int scancode) else return false; - if (widget->has_text()) { - const char* text = widget->text(); + if (widget->hasText()) { + const char* text = widget->getText(); for (c=0; text[c]; c++) if ((text[c] == '&') && (text[c+1] != '&')) @@ -1442,7 +1457,7 @@ bool jwidget_check_underscored(JWidget widget, int scancode) /**********************************************************************/ /* widget message procedure */ -bool jwidget::msg_proc(JMessage msg) +bool Widget::msg_proc(JMessage msg) { JWidget widget = this; diff --git a/src/jinete/jwidget.h b/src/jinete/jwidget.h index 6afe774a8..f95c734be 100644 --- a/src/jinete/jwidget.h +++ b/src/jinete/jwidget.h @@ -33,6 +33,7 @@ #define JINETE_JWIDGET_H_INCLUDED #include "jinete/jbase.h" +#include "jinete/jrect.h" #include @@ -60,16 +61,6 @@ void jwidget_add_hook(JWidget widget, int type, JMessageFunc msg_proc, void *data); JHook jwidget_get_hook(JWidget widget, int type); void *jwidget_get_data(JWidget widget, int type); - -/* main properties */ - -int jwidget_get_type(JWidget widget); -const char *jwidget_get_name(JWidget widget); -const char *jwidget_get_text(JWidget widget); - -void jwidget_set_name(JWidget widget, const char *name); -void jwidget_set_text(JWidget widget, const char *text); -void jwidget_set_align(JWidget widget, int align); /* behavior properties */ @@ -118,8 +109,7 @@ void jwidget_replace_child(JWidget widget, JWidget old_child, /* parents and children */ JWidget jwidget_get_parent(JWidget widget); -JWidget jwidget_get_window(JWidget widget); -JWidget jwidget_get_manager(JWidget window); +JWidget jwidget_get_manager(JWidget widget); JList jwidget_get_parents(JWidget widget, bool ascendant); JList jwidget_get_children(JWidget widget); JWidget jwidget_pick(JWidget widget, int x, int y); @@ -179,7 +169,7 @@ bool jwidget_check_underscored(JWidget widget, int scancode); ////////////////////////////////////////////////////////////////////// -class jwidget +class Widget { public: JID id; /* identify code */ @@ -230,43 +220,57 @@ public: ////////////////////////////////////////////////////////////////////// // Methods - jwidget(int type); - ~jwidget(); + Widget(int type); + virtual ~Widget(); - bool has_text() { return flags & JI_NOTEXT ? false: true; } + // main properties - 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); + int getType(); + const char* getName(); + int getAlign() const; - bool enabled() { return jwidget_is_enabled(this); } - void enabled(bool state) { + void setName(const char* name); + void setAlign(int align); + + // text property + + bool hasText() { return flags & JI_NOTEXT ? false: true; } + + const char* getText() const { return m_text.c_str(); } + int getTextInt() const; + double getTextDouble() const; + size_t getTextSize() const { return m_text.size(); } + void setText(const char* text); + void setTextf(const char* text, ...); + void setTextQuiet(const char* text); + + // enable/disable + + bool isEnabled() { return jwidget_is_enabled(this); } + void setEnabled(bool state) { if (state) jwidget_enable(this); else jwidget_disable(this); } - bool selected() { return jwidget_is_selected(this); } - void selected(bool state) { jwidget_set_selected(this, state); } + // selected - int align() const { return m_align; } - void align(int align); + bool isSelected() { return jwidget_is_selected(this); } + void setSelected(bool state) { jwidget_set_selected(this, state); } - struct FONT* font(); - void font(struct FONT* font); + // font + + FONT* getFont(); + void setFont(FONT* font); /** * Gets the background color of the widget. */ - int bg_color() + int getBgColor() { if (m_bg_color < 0 && parent) - return parent->bg_color(); + return parent->getBgColor(); else return m_bg_color; } @@ -274,21 +278,44 @@ public: /** * Sets the background color of the widget. */ - void bg_color(int bg_color) + void setBgColor(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); + ////////////////////////////////////////////////////////////////////// + // parents and children + + Widget* getRoot(); + Widget* getParent(); + Widget* getManager(); + JList getParents(bool ascendant); + JList getChildren(); + Widget* pick(int x, int y); + bool hasChild(Widget* child); + Widget* findChild(const char* name); + Widget* findSibling(const char* name); + + void dirty() { + jwidget_dirty(this); } - void dirty() { jwidget_dirty(this); } + ////////////////////////////////////////////////////////////////////// + // position and geometry + Rect getBounds() const; + void setBounds(const Rect& rc); + + ////////////////////////////////////////////////////////////////////// + // manager handler + + bool sendMessage(JMessage msg); + void closeWindow(); + void captureMouse(); + void hardCaptureMouse(); + void releaseMouse(); + +protected: virtual bool msg_proc(JMessage msg); }; diff --git a/src/jinete/jwindow.cpp b/src/jinete/jwindow.cpp index e0b43ceef..c0f40f76b 100644 --- a/src/jinete/jwindow.cpp +++ b/src/jinete/jwindow.cpp @@ -39,18 +39,6 @@ #include "jinete/jinete.h" #include "jinete/jintern.h" -typedef struct Window -{ - JWidget killer; - bool is_desktop : 1; - bool is_moveable : 1; - bool is_sizeable : 1; - bool is_ontop : 1; - bool is_wantfocus : 1; - bool is_foreground : 1; - bool is_autoremap : 1; -} Window; - enum { WINDOW_NONE = 0, WINDOW_MOVE = 1, @@ -64,14 +52,6 @@ static JRect click_pos = NULL; static int press_x, press_y; static int window_action = WINDOW_NONE; -static JWidget window_new(bool desktop, const char *text); -static bool window_msg_proc(JWidget widget, JMessage msg); -static void window_request_size(JWidget widget, int *w, int *h); -static void window_set_position(JWidget widget, JRect rect); - -static int get_action(JWidget widget, int x, int y); -static void limit_size(JWidget widget, int *w, int *h); -static void move_window(JWidget widget, JRect rect, bool use_blit); static void displace_widgets(JWidget widget, int x, int y); bool _jwindow_is_moving() @@ -79,264 +59,227 @@ bool _jwindow_is_moving() return (window_action == WINDOW_MOVE) ? true: false; } -JWidget jwindow_new(const char *text) +Frame::Frame(bool desktop, const char* text) + : Widget(JI_FRAME) { - return window_new(false, text); + m_killer = NULL; + m_is_desktop = desktop; + m_is_moveable = !desktop; + m_is_sizeable = !desktop; + m_is_ontop = false; + m_is_wantfocus = true; + m_is_foreground = false; + m_is_autoremap = true; + + jwidget_hide(this); + this->setText(text); + this->setAlign(JI_LEFT | JI_MIDDLE); + + jwidget_init_theme(this); } -JWidget jwindow_new_desktop() +Widget* Frame::get_killer() { - return window_new(true, NULL); + return m_killer; } -JWidget jwindow_get_killer(JWidget widget) +void Frame::set_autoremap(bool state) { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); - - return window->killer; + m_is_autoremap = state; } -void jwindow_moveable(JWidget widget, bool state) +void Frame::set_moveable(bool state) { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); - - window->is_moveable = state; + m_is_moveable = state; } -void jwindow_sizeable(JWidget widget, bool state) +void Frame::set_sizeable(bool state) { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); - - window->is_sizeable = state; + m_is_sizeable = state; } -void jwindow_ontop(JWidget widget, bool state) +void Frame::set_ontop(bool state) { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); - - window->is_ontop = state; + m_is_ontop = state; } -void jwindow_wantfocus(JWidget widget, bool state) +void Frame::set_wantfocus(bool state) { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); - - window->is_wantfocus = state; + m_is_wantfocus = state; } -void jwindow_remap(JWidget widget) +void Frame::remap_window() { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); int req_w, req_h; JRect rect; - if (window->is_autoremap) { - window->is_autoremap = false; - jwidget_show(widget); + if (m_is_autoremap) { + m_is_autoremap = false; + jwidget_show(this); } - jwidget_request_size(widget, &req_w, &req_h); + jwidget_request_size(this, &req_w, &req_h); - rect = jrect_new(widget->rc->x1, widget->rc->y1, - widget->rc->x1+req_w, - widget->rc->y1+req_h); - jwidget_set_rect(widget, rect); + rect = jrect_new(this->rc->x1, this->rc->y1, + this->rc->x1+req_w, + this->rc->y1+req_h); + jwidget_set_rect(this, rect); jrect_free(rect); - jwidget_emit_signal(widget, JI_SIGNAL_WINDOW_RESIZE); - jwidget_dirty(widget); + jwidget_emit_signal(this, JI_SIGNAL_WINDOW_RESIZE); + jwidget_dirty(this); } -void jwindow_center(JWidget widget) +void Frame::center_window() { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); - JWidget manager = jwidget_get_manager(widget); + JWidget manager = getManager(); - if (window->is_autoremap) - jwindow_remap(widget); + if (m_is_autoremap) + this->remap_window(); - jwindow_position(widget, - jrect_w(manager->rc)/2 - jrect_w(widget->rc)/2, - jrect_h(manager->rc)/2 - jrect_h(widget->rc)/2); + position_window(jrect_w(manager->rc)/2 - jrect_w(this->rc)/2, + jrect_h(manager->rc)/2 - jrect_h(this->rc)/2); } -void jwindow_position(JWidget widget, int x, int y) +void Frame::position_window(int x, int y) { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); int old_action = window_action; JRect rect; window_action = WINDOW_MOVE; - if (window->is_autoremap) - jwindow_remap(widget); + if (m_is_autoremap) + remap_window(); - rect = jrect_new(x, y, x+jrect_w(widget->rc), y+jrect_h(widget->rc)); - jwidget_set_rect(widget, rect); + rect = jrect_new(x, y, x+jrect_w(this->rc), y+jrect_h(this->rc)); + jwidget_set_rect(this, rect); jrect_free(rect); window_action = old_action; - jwidget_dirty(widget); + dirty(); } -void jwindow_move(JWidget widget, JRect rect) +void Frame::move_window(JRect rect) { - move_window(widget, rect, true); + move_window(rect, true); } -void jwindow_open(JWidget widget) +void Frame::open_window() { - if (!widget->parent) { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); + if (!this->parent) { + if (m_is_autoremap) + center_window(); - if (window->is_autoremap) - jwindow_center(widget); - - _jmanager_open_window(ji_get_default_manager(), widget); + _jmanager_open_window(ji_get_default_manager(), this); } } -void jwindow_open_fg(JWidget widget) +void Frame::open_window_fg() { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); - JWidget manager; + open_window(); - jwindow_open(widget); - manager = jwidget_get_manager(widget); + JWidget manager = getManager(); - window->is_foreground = true; + m_is_foreground = true; - while (!(widget->flags & JI_HIDDEN)) { + while (!(this->flags & JI_HIDDEN)) { if (jmanager_generate_messages(manager)) jmanager_dispatch_messages(manager); } - window->is_foreground = false; + m_is_foreground = false; } -void jwindow_open_bg(JWidget widget) +void Frame::open_window_bg() { - jwindow_open(widget); + this->open_window(); } -void jwindow_close(JWidget widget, JWidget killer) +void Frame::closeWindow(Widget* killer) { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); + m_killer = killer; - window->killer = killer; - - _jmanager_close_window(jwidget_get_manager(widget), widget, true); + _jmanager_close_window(getManager(), this, true); } -bool jwindow_is_toplevel(JWidget widget) +bool Frame::is_toplevel() { - JWidget manager = jwidget_get_manager(widget); + JWidget manager = getManager(); if (!jlist_empty(manager->children)) - return (widget == jlist_first(manager->children)->data); + return (this == jlist_first(manager->children)->data); else return false; } -bool jwindow_is_foreground(JWidget widget) +bool Frame::is_foreground() const { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); - - return window->is_foreground; + return m_is_foreground; } -bool jwindow_is_desktop(JWidget widget) +bool Frame::is_desktop() const { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); - - return window->is_desktop; + return m_is_desktop; } -bool jwindow_is_ontop(JWidget widget) +bool Frame::is_ontop() const { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); - - return window->is_ontop; + return m_is_ontop; } -bool jwindow_is_wantfocus(JWidget widget) +bool Frame::is_wantfocus() const { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); - - return window->is_wantfocus; + return m_is_wantfocus; } -static JWidget window_new(bool desktop, const char *text) +bool Frame::msg_proc(JMessage msg) { - JWidget widget = new jwidget(JI_WINDOW); - Window *window = jnew(Window, 1); - - window->killer = NULL; - window->is_desktop = desktop; - window->is_moveable = !desktop; - window->is_sizeable = !desktop; - window->is_ontop = false; - window->is_wantfocus = true; - window->is_foreground = false; - window->is_autoremap = true; - - jwidget_hide(widget); - jwidget_add_hook(widget, JI_WINDOW, window_msg_proc, window); - jwidget_set_text(widget, text); - jwidget_set_align(widget, JI_LEFT | JI_MIDDLE); - - jwidget_init_theme(widget); - - return widget; -} - -static bool window_msg_proc(JWidget widget, JMessage msg) -{ - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); - switch (msg->type) { case JM_DESTROY: - _jmanager_close_window(jwidget_get_manager(widget), widget, false); - jfree(window); + _jmanager_close_window(getManager(), this, false); break; case JM_REQSIZE: - window_request_size(widget, &msg->reqsize.w, &msg->reqsize.h); + this->window_request_size(&msg->reqsize.w, &msg->reqsize.h); return true; case JM_SETPOS: - window_set_position(widget, &msg->setpos.rect); + this->window_set_position(&msg->setpos.rect); return true; case JM_OPEN: - window->killer = NULL; + m_killer = NULL; break; case JM_CLOSE: - jwidget_emit_signal(widget, JI_SIGNAL_WINDOW_CLOSE); + // Fire Close signal + { + Vaca::CloseEvent ev; + Close(ev); + } break; case JM_SIGNAL: if (msg->signal.num == JI_SIGNAL_SET_TEXT) - jwidget_init_theme(widget); + jwidget_init_theme(this); break; case JM_BUTTONPRESSED: { - if (!window->is_moveable) + if (!m_is_moveable) break; press_x = msg->mouse.x; press_y = msg->mouse.y; - window_action = get_action(widget, press_x, press_y); + window_action = this->get_action(press_x, press_y); if (window_action != WINDOW_NONE) { if (click_pos == NULL) - click_pos = jrect_new_copy(widget->rc); + click_pos = jrect_new_copy(this->rc); else - jrect_copy(click_pos, widget->rc); + jrect_copy(click_pos, this->rc); - jwidget_hard_capture_mouse(widget); + jwidget_hard_capture_mouse(this); return true; } else @@ -344,8 +287,8 @@ static bool window_msg_proc(JWidget widget, JMessage msg) } case JM_BUTTONRELEASED: - if (jwidget_has_capture(widget)) { - jwidget_release_mouse(widget); + if (jwidget_has_capture(this)) { + jwidget_release_mouse(this); jmouse_set_cursor(JI_CURSOR_NORMAL); if (click_pos != NULL) { @@ -359,19 +302,19 @@ static bool window_msg_proc(JWidget widget, JMessage msg) break; case JM_MOTION: - if (!window->is_moveable) + if (!m_is_moveable) break; /* does it have the mouse captured? */ - if (jwidget_has_capture(widget)) { + if (jwidget_has_capture(this)) { /* reposition/resize */ if (window_action == WINDOW_MOVE) { int x = click_pos->x1 + (msg->mouse.x - press_x); int y = click_pos->y1 + (msg->mouse.y - press_y); JRect rect = jrect_new(x, y, - x+jrect_w(widget->rc), - y+jrect_h(widget->rc)); - move_window(widget, rect, true); + x+jrect_w(this->rc), + y+jrect_h(this->rc)); + this->move_window(rect, true); jrect_free(rect); } else { @@ -390,27 +333,27 @@ static bool window_msg_proc(JWidget widget, JMessage msg) else if (window_action & WINDOW_RESIZE_BOTTOM) h += (msg->mouse.y - press_y); - limit_size(widget, &w, &h); + this->limit_size(&w, &h); - if ((jrect_w(widget->rc) != w) || - (jrect_h(widget->rc) != h)) { + if ((jrect_w(this->rc) != w) || + (jrect_h(this->rc) != h)) { if (window_action & WINDOW_RESIZE_LEFT) x = click_pos->x1 - (w - jrect_w(click_pos)); else - x = widget->rc->x1; + x = this->rc->x1; if (window_action & WINDOW_RESIZE_TOP) y = click_pos->y1 - (h - jrect_h(click_pos)); else - y = widget->rc->y1; + y = this->rc->y1; { JRect rect = jrect_new(x, y, x+w, y+h); - move_window(widget, rect, false); + this->move_window(rect, false); jrect_free(rect); - jwidget_emit_signal(widget, JI_SIGNAL_WINDOW_RESIZE); - jwidget_dirty(widget); + jwidget_emit_signal(this, JI_SIGNAL_WINDOW_RESIZE); + jwidget_dirty(this); } } } @@ -418,7 +361,7 @@ static bool window_msg_proc(JWidget widget, JMessage msg) /* TODO */ /* { */ -/* JWidget manager = jwindow_get_manager(widget); */ +/* JWidget manager = get_manager(); */ /* JWidget view = jwidget_get_view(manager); */ /* if (view) { */ /* jview_update(view); */ @@ -427,10 +370,8 @@ static bool window_msg_proc(JWidget widget, JMessage msg) break; case JM_SETCURSOR: - if (window->is_moveable) { - int action = get_action(widget, - msg->mouse.x, - msg->mouse.y); + if (m_is_moveable) { + int action = this->get_action(msg->mouse.x, msg->mouse.y); int cursor = JI_CURSOR_NORMAL; if (action == WINDOW_MOVE) @@ -462,20 +403,19 @@ static bool window_msg_proc(JWidget widget, JMessage msg) break; case JM_DRAW: - widget->theme->draw_window(widget, &msg->draw.rect); + this->theme->draw_frame(this, &msg->draw.rect); return true; } - return false; + return Widget::msg_proc(msg); } -static void window_request_size(JWidget widget, int *w, int *h) +void Frame::window_request_size(int *w, int *h) { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); - JWidget manager = jwidget_get_manager(widget); + JWidget manager = getManager(); - if (window->is_desktop) { + if (m_is_desktop) { JRect cpos = jwidget_get_child_rect(manager); *w = jrect_w(cpos); *h = jrect_h(cpos); @@ -488,7 +428,7 @@ static void window_request_size(JWidget widget, int *w, int *h) JLink link; max_w = max_h = 0; - JI_LIST_FOR_EACH(widget->children, link) { + JI_LIST_FOR_EACH(this->children, link) { child = (JWidget)link->data; if (!jwidget_is_decorative(child)) { @@ -499,26 +439,26 @@ static void window_request_size(JWidget widget, int *w, int *h) } } - if (widget->has_text()) - max_w = MAX(max_w, jwidget_get_text_length(widget)); + if (this->hasText()) + max_w = MAX(max_w, jwidget_get_text_length(this)); - *w = widget->border_width.l + max_w + widget->border_width.r; - *h = widget->border_width.t + max_h + widget->border_width.b; + *w = this->border_width.l + max_w + this->border_width.r; + *h = this->border_width.t + max_h + this->border_width.b; } } -static void window_set_position(JWidget widget, JRect rect) +void Frame::window_set_position(JRect rect) { JWidget child; JRect cpos; JLink link; /* copy the new position rectangle */ - jrect_copy(widget->rc, rect); - cpos = jwidget_get_child_rect(widget); + jrect_copy(this->rc, rect); + cpos = jwidget_get_child_rect(this); /* set all the children to the same "child_pos" */ - JI_LIST_FOR_EACH(widget->children, link) { + JI_LIST_FOR_EACH(this->children, link) { child = (JWidget)link->data; if (jwidget_is_decorative(child)) @@ -530,30 +470,29 @@ static void window_set_position(JWidget widget, JRect rect) jrect_free(cpos); } -static int get_action(JWidget widget, int x, int y) +int Frame::get_action(int x, int y) { - Window* window = reinterpret_cast(jwidget_get_data(widget, JI_WINDOW)); int action = WINDOW_NONE; JRect pos; JRect cpos; - if (!window->is_moveable) + if (!m_is_moveable) return action; - pos = jwidget_get_rect(widget); - cpos = jwidget_get_child_rect(widget); + pos = jwidget_get_rect(this); + cpos = jwidget_get_child_rect(this); /* move */ - if ((widget->has_text()) + if ((this->hasText()) && (((x >= cpos->x1) && (x < cpos->x2) && - (y >= pos->y1+widget->border_width.b) && + (y >= pos->y1+this->border_width.b) && (y < cpos->y1)) || (key_shifts & KB_ALT_FLAG))) { action = WINDOW_MOVE; } /* resize */ - else if (window->is_sizeable) { + else if (m_is_sizeable) { /* left *****************************************/ if ((x >= pos->x1) && (x < cpos->x1)) { action |= WINDOW_RESIZE_LEFT; @@ -604,21 +543,21 @@ static int get_action(JWidget widget, int x, int y) return action; } -static void limit_size(JWidget widget, int *w, int *h) +void Frame::limit_size(int *w, int *h) { int req_w, req_h; - jwidget_request_size(widget, &req_w, &req_h); + jwidget_request_size(this, &req_w, &req_h); - *w = MAX(*w, widget->border_width.l+widget->border_width.r); - *h = MAX(*h, widget->border_width.t+widget->border_width.b); + *w = MAX(*w, this->border_width.l+this->border_width.r); + *h = MAX(*h, this->border_width.t+this->border_width.b); } -static void move_window(JWidget widget, JRect rect, bool use_blit) +void Frame::move_window(JRect rect, bool use_blit) { #define FLAGS JI_GDR_CUTTOPWINDOWS | JI_GDR_USECHILDAREA - JWidget manager = jwidget_get_manager(widget); + JWidget manager = getManager(); JRegion old_drawable_region; JRegion new_drawable_region; JRegion manager_refresh_region; @@ -630,37 +569,37 @@ static void move_window(JWidget widget, JRect rect, bool use_blit) jmanager_dispatch_messages(manager); /* get the window's current position */ - old_pos = jrect_new_copy(widget->rc); + old_pos = jrect_new_copy(this->rc); /* get the manager's current position */ man_pos = jwidget_get_rect(manager); /* sent a JM_WINMOVE message to the window */ msg = jmessage_new(JM_WINMOVE); - jmessage_add_dest(msg, widget); + jmessage_add_dest(msg, this); jmanager_enqueue_message(msg); /* get the region & the drawable region of the window */ - old_drawable_region = jwidget_get_drawable_region(widget, FLAGS); + old_drawable_region = jwidget_get_drawable_region(this, FLAGS); /* if the size of the window changes... */ if (jrect_w(old_pos) != jrect_w(rect) || jrect_h(old_pos) != jrect_h(rect)) { /* we have to change the whole positions sending JM_SETPOS messages... */ - window_set_position(widget, rect); + window_set_position(rect); } else { /* we can just displace all the widgets by a delta (new_position - old_position)... */ - displace_widgets(widget, + displace_widgets(this, rect->x1 - old_pos->x1, rect->y1 - old_pos->y1); } /* get the new drawable region of the window (it's new because we moved the window to "rect") */ - new_drawable_region = jwidget_get_drawable_region(widget, FLAGS); + new_drawable_region = jwidget_get_drawable_region(this, FLAGS); /* create a new region to refresh the manager later */ manager_refresh_region = jregion_new(NULL, 0); @@ -693,14 +632,14 @@ static void move_window(JWidget widget, JRect rect, bool use_blit) /* add a region to draw areas which were outside of the screen */ jregion_copy(reg1, new_drawable_region); jregion_translate(reg1, - old_pos->x1 - widget->rc->x1, - old_pos->y1 - widget->rc->y1); + old_pos->x1 - this->rc->x1, + old_pos->y1 - this->rc->y1); jregion_intersect(moveable_region, old_drawable_region, reg1); jregion_subtract(reg1, reg1, moveable_region); jregion_translate(reg1, - widget->rc->x1 - old_pos->x1, - widget->rc->y1 - old_pos->y1); + this->rc->x1 - old_pos->x1, + this->rc->y1 - old_pos->y1); jregion_union(window_refresh_region, window_refresh_region, reg1); /* move the window's graphics */ @@ -709,8 +648,8 @@ static void move_window(JWidget widget, JRect rect, bool use_blit) man_pos->x1, man_pos->y1, man_pos->x2-1, man_pos->y2-1); ji_move_region(moveable_region, - widget->rc->x1 - old_pos->x1, - widget->rc->y1 - old_pos->y1); + this->rc->x1 - old_pos->x1, + this->rc->y1 - old_pos->y1); set_clip(ji_screen, 0, 0, JI_SCREEN_W-1, JI_SCREEN_H-1); jmouse_show(); @@ -719,7 +658,7 @@ static void move_window(JWidget widget, JRect rect, bool use_blit) } jmanager_invalidate_region(manager, manager_refresh_region); - jwidget_invalidate_region(widget, window_refresh_region); + jwidget_invalidate_region(this, window_refresh_region); jregion_free(old_drawable_region); jregion_free(new_drawable_region); diff --git a/src/jinete/jwindow.h b/src/jinete/jwindow.h index e38bc620c..6c2de9a65 100644 --- a/src/jinete/jwindow.h +++ b/src/jinete/jwindow.h @@ -32,32 +32,64 @@ #ifndef JINETE_JWINDOW_H_INCLUDED #define JINETE_JWINDOW_H_INCLUDED -#include "jinete/jbase.h" +#include "jinete/jwidget.h" +#include "Vaca/Signal.h" -JWidget jwindow_new(const char *text); -JWidget jwindow_new_desktop(); +namespace Vaca { + class CloseEvent { }; // TODO +} -JWidget jwindow_get_killer(JWidget window); +class Frame : public Widget +{ + JWidget m_killer; + bool m_is_desktop : 1; + bool m_is_moveable : 1; + bool m_is_sizeable : 1; + bool m_is_ontop : 1; + bool m_is_wantfocus : 1; + bool m_is_foreground : 1; + bool m_is_autoremap : 1; -void jwindow_moveable(JWidget window, bool state); -void jwindow_sizeable(JWidget window, bool state); -void jwindow_ontop(JWidget window, bool state); -void jwindow_wantfocus(JWidget window, bool state); +public: + Frame(bool is_desktop, const char* text); -void jwindow_remap(JWidget window); -void jwindow_center(JWidget window); -void jwindow_position(JWidget window, int x, int y); -void jwindow_move(JWidget window, JRect rect); + Widget* get_killer(); -void jwindow_open(JWidget window); -void jwindow_open_fg(JWidget window); -void jwindow_open_bg(JWidget window); -void jwindow_close(JWidget window, JWidget killer); + void set_autoremap(bool state); + void set_moveable(bool state); + void set_sizeable(bool state); + void set_ontop(bool state); + void set_wantfocus(bool state); -bool jwindow_is_toplevel(JWidget window); -bool jwindow_is_foreground(JWidget window); -bool jwindow_is_desktop(JWidget window); -bool jwindow_is_ontop(JWidget window); -bool jwindow_is_wantfocus(JWidget window); + void remap_window(); + void center_window(); + void position_window(int x, int y); + void move_window(JRect rect); + + void open_window(); + void open_window_fg(); + void open_window_bg(); + void closeWindow(Widget* killer); + + bool is_toplevel(); + bool is_foreground() const; + bool is_desktop() const; + bool is_ontop() const; + bool is_wantfocus() const; + + // Signals + Vaca::Signal1 Close; + +protected: + bool msg_proc(JMessage msg); + +private: + void window_request_size(int* w, int* h); + void window_set_position(JRect rect); + int get_action(int x, int y); + void limit_size(int* w, int* h); + void move_window(JRect rect, bool use_blit); + +}; #endif diff --git a/src/jinete/themes/jstandard_theme.cpp b/src/jinete/themes/jstandard_theme.cpp index 7af327b9a..7f253f7d7 100644 --- a/src/jinete/themes/jstandard_theme.cpp +++ b/src/jinete/themes/jstandard_theme.cpp @@ -41,8 +41,6 @@ #define CHARACTER_LENGTH(f, c) ((f)->vtable->char_length((f), (c))) -#define BGCOLOR (get_bg_color(widget)) - #define COLOR_FOREGROUND makecol(0, 0, 0) #define COLOR_DISABLED makecol(128, 128, 128) #define COLOR_FACE makecol(210, 200, 190) @@ -133,7 +131,7 @@ public: void draw_view(JWidget widget, JRect clip); void draw_view_scrollbar(JWidget widget, JRect clip); void draw_view_viewport(JWidget widget, JRect clip); - void draw_window(JWidget widget, JRect clip); + void draw_frame(Frame* frame, JRect clip); private: @@ -273,7 +271,7 @@ void jstandard_theme::init_widget(JWidget widget) widget->border_width.b = B; if ((widget->flags & JI_INITIALIZED) && - (widget->type != JI_WINDOW) && + (widget->type != JI_FRAME) && (widget->type != JI_SEPARATOR)) return; @@ -347,12 +345,12 @@ void jstandard_theme::init_widget(JWidget widget) case JI_SEPARATOR: /* frame */ - if ((widget->align() & JI_HORIZONTAL) && - (widget->align() & JI_VERTICAL)) { + if ((widget->getAlign() & JI_HORIZONTAL) && + (widget->getAlign() & JI_VERTICAL)) { BORDER(4); } /* horizontal bar */ - else if (widget->align() & JI_HORIZONTAL) { + else if (widget->getAlign() & JI_HORIZONTAL) { BORDER4(2, 4, 2, 0); } /* vertical bar */ @@ -360,10 +358,10 @@ void jstandard_theme::init_widget(JWidget widget) BORDER4(4, 2, 0, 2); } - if (widget->has_text()) { - if (widget->align() & JI_TOP) + if (widget->hasText()) { + if (widget->getAlign() & JI_TOP) widget->border_width.t = jwidget_get_text_height(widget); - else if (widget->align() & JI_BOTTOM) + else if (widget->getAlign() & JI_BOTTOM) widget->border_width.b = jwidget_get_text_height(widget); } break; @@ -371,7 +369,7 @@ void jstandard_theme::init_widget(JWidget widget) case JI_SLIDER: BORDER(4); widget->child_spacing = jwidget_get_text_height(widget); - widget->align(JI_CENTER | JI_MIDDLE); + widget->setAlign(JI_CENTER | JI_MIDDLE); break; case JI_TEXTBOX: @@ -394,9 +392,9 @@ void jstandard_theme::init_widget(JWidget widget) widget->child_spacing = 0; break; - case JI_WINDOW: - if (!jwindow_is_desktop(widget)) { - if (widget->has_text()) { + case JI_FRAME: + if (!static_cast(widget)->is_desktop()) { + if (widget->hasText()) { BORDER4(6, 4+jwidget_get_text_height(widget)+6, 6, 6); #if 1 /* add close button */ if (!(widget->flags & JI_INITIALIZED)) { @@ -406,7 +404,7 @@ void jstandard_theme::init_widget(JWidget widget) theme_button_msg_proc, NULL); jwidget_decorative(button, true); jwidget_add_child(widget, button); - jwidget_set_name(button, "theme_close_button"); + button->setName("theme_close_button"); } #endif } @@ -481,7 +479,7 @@ int jstandard_theme::color_background() void jstandard_theme::draw_box(JWidget widget, JRect clip) { - jdraw_rectfill(clip, BGCOLOR); + jdraw_rectfill(clip, get_bg_color(widget)); } void jstandard_theme::draw_button(JWidget widget, JRect clip) @@ -529,7 +527,7 @@ void jstandard_theme::draw_button(JWidget widget, JRect clip) y2 = widget->rc->y2-1; /* extern background */ - rectfill(ji_screen, x1, y1, x2, y2, BGCOLOR); + rectfill(ji_screen, x1, y1, x2, y2, get_bg_color(widget)); /* get bevel info */ jbutton_get_bevel(widget, bevel); @@ -608,7 +606,7 @@ void jstandard_theme::draw_check(JWidget widget, JRect clip) widget->theme->check_icon_size); /* background */ - jdraw_rectfill(widget->rc, bg = BGCOLOR); + jdraw_rectfill(widget->rc, bg = get_bg_color(widget)); /* mouse */ if (jwidget_is_enabled(widget) && jwidget_has_mouse(widget)) @@ -629,14 +627,14 @@ void jstandard_theme::draw_check(JWidget widget, JRect clip) void jstandard_theme::draw_grid(JWidget widget, JRect clip) { - jdraw_rectfill(clip, BGCOLOR); + jdraw_rectfill(clip, get_bg_color(widget)); } void jstandard_theme::draw_entry(JWidget widget, JRect clip) { bool password = jentry_is_password(widget); int scroll, cursor, state, selbeg, selend; - const char *text = widget->text(); + const char *text = widget->getText(); int c, ch, x, y, w, fg, bg; int x1, y1, x2, y2; int cursor_x; @@ -660,7 +658,7 @@ void jstandard_theme::draw_entry(JWidget widget, JRect clip) if (jwidget_has_focus (widget)) rect(ji_screen, x1, y1, x2, y2, COLOR_FOREGROUND); else - rect(ji_screen, x1, y1, x2, y2, BGCOLOR); + rect(ji_screen, x1, y1, x2, y2, get_bg_color(widget)); /* background border */ x1++, y1++, x2--, y2--; @@ -692,14 +690,14 @@ void jstandard_theme::draw_entry(JWidget widget, JRect clip) fg = COLOR_DISABLED; } - w = CHARACTER_LENGTH(widget->font(), ch); + w = CHARACTER_LENGTH(widget->getFont(), ch); if (x+w > widget->rc->x2-3) return; cursor_x = x; - ji_font_set_aa_mode(widget->font(), bg >= 0 ? bg: COLOR_BACKGROUND); - widget->font()->vtable->render_char(widget->font(), - ch, fg, bg, ji_screen, x, y); + ji_font_set_aa_mode(widget->getFont(), bg >= 0 ? bg: COLOR_BACKGROUND); + widget->getFont()->vtable->render_char(widget->getFont(), + ch, fg, bg, ji_screen, x, y); x += w; /* cursor */ @@ -716,7 +714,7 @@ void jstandard_theme::draw_entry(JWidget widget, JRect clip) void jstandard_theme::draw_label(JWidget widget, JRect clip) { - int bg = BGCOLOR; + int bg = get_bg_color(widget); jdraw_rectfill(widget->rc, bg); @@ -756,9 +754,9 @@ void jstandard_theme::draw_listitem(JWidget widget, JRect clip) x = widget->rc->x1+widget->border_width.l; y = widget->rc->y1+widget->border_width.t; - if (widget->has_text()) { + if (widget->hasText()) { /* text */ - jdraw_text(widget->font(), widget->text(), x, y, fg, bg, true); + jdraw_text(widget->getFont(), widget->getText(), x, y, fg, bg, true); /* background */ jrectexclude @@ -777,7 +775,7 @@ void jstandard_theme::draw_listitem(JWidget widget, JRect clip) void jstandard_theme::draw_menu(JWidget widget, JRect clip) { - jdraw_rectfill(widget->rc, BGCOLOR); + jdraw_rectfill(widget->rc, get_bg_color(widget)); } void jstandard_theme::draw_menuitem(JWidget widget, JRect clip) @@ -794,7 +792,7 @@ void jstandard_theme::draw_menuitem(JWidget widget, JRect clip) /* colors */ if (jwidget_is_disabled(widget)) { - bg = BGCOLOR; + bg = get_bg_color(widget); fg = -1; } else { @@ -807,7 +805,7 @@ void jstandard_theme::draw_menuitem(JWidget widget, JRect clip) fg = COLOR_FOREGROUND; } else { - bg = BGCOLOR; + bg = get_bg_color(widget); fg = COLOR_FOREGROUND; } } @@ -837,9 +835,9 @@ void jstandard_theme::draw_menuitem(JWidget widget, JRect clip) /* text */ if (bar) - widget->align(JI_CENTER | JI_MIDDLE); + widget->setAlign(JI_CENTER | JI_MIDDLE); else - widget->align(JI_LEFT | JI_MIDDLE); + widget->setAlign(JI_LEFT | JI_MIDDLE); pos = jwidget_get_rect(widget); if (!bar) @@ -875,7 +873,7 @@ void jstandard_theme::draw_menuitem(JWidget widget, JRect clip) } /* draw the keyboard shortcut */ else if (jmenuitem_get_accel(widget)) { - int old_align = widget->align(); + int old_align = widget->getAlign(); char buf[256]; pos = jwidget_get_rect(widget); @@ -883,9 +881,9 @@ void jstandard_theme::draw_menuitem(JWidget widget, JRect clip) jaccel_to_string(jmenuitem_get_accel(widget), buf); - widget->align(JI_RIGHT | JI_MIDDLE); + widget->setAlign(JI_RIGHT | JI_MIDDLE); draw_textstring(buf, fg, bg, false, widget, pos, 0); - widget->align(old_align); + widget->setAlign(old_align); jrect_free(pos); } @@ -910,7 +908,7 @@ void jstandard_theme::draw_panel(JWidget widget, JRect clip) c1 = (JWidget)link->data; c2 = (JWidget)link->next->data; - if (widget->align() & JI_HORIZONTAL) { + if (widget->getAlign() & JI_HORIZONTAL) { /* vline(ji_screen, */ /* (c1->pos->x+c1->pos->w+c2->pos->x-1)/2, */ /* widget->rect->y, */ @@ -951,7 +949,7 @@ void jstandard_theme::draw_panel(JWidget widget, JRect clip) void jstandard_theme::draw_radio(JWidget widget, JRect clip) { struct jrect box, text, icon; - int bg = BGCOLOR; + int bg = get_bg_color(widget); jwidget_get_texticon_info(widget, &box, &text, &icon, ji_generic_button_get_icon_align(widget), @@ -988,23 +986,23 @@ void jstandard_theme::draw_separator(JWidget widget, JRect clip) y2 = widget->rc->y2 - 1 - widget->border_width.b/2; /* background */ - jdraw_rectfill(widget->rc, BGCOLOR); + jdraw_rectfill(widget->rc, get_bg_color(widget)); /* TOP line */ - if (widget->align() & JI_HORIZONTAL) { + if (widget->getAlign() & JI_HORIZONTAL) { hline(ji_screen, x1, y1-1, x2, COLOR_DISABLED); hline(ji_screen, x1, y1, x2, COLOR_BACKGROUND); } /* LEFT line */ - if (widget->align() & JI_VERTICAL) { + if (widget->getAlign() & JI_VERTICAL) { vline(ji_screen, x1-1, y1, y2, COLOR_DISABLED); vline(ji_screen, x1, y1, y2, COLOR_BACKGROUND); } /* frame */ - if ((widget->align() & JI_HORIZONTAL) && - (widget->align() & JI_VERTICAL)) { + if ((widget->getAlign() & JI_HORIZONTAL) && + (widget->getAlign() & JI_VERTICAL)) { /* union between the LEFT and TOP lines */ putpixel(ji_screen, x1-1, y1-1, COLOR_DISABLED); @@ -1021,10 +1019,10 @@ void jstandard_theme::draw_separator(JWidget widget, JRect clip) } /* text */ - if (widget->has_text()) { + if (widget->hasText()) { int h = jwidget_get_text_height(widget); 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, get_bg_color(widget), false, widget, &r, 0); } } @@ -1114,13 +1112,13 @@ void jstandard_theme::draw_slider(JWidget widget, JRect clip) /* text */ { - std::string old_text = widget->text(); + std::string old_text = widget->getText(); int cx1, cy1, cx2, cy2; JRect r; usprintf(buf, "%d", value); - widget->set_text_quiet(buf); + widget->setTextQuiet(buf); r = jrect_new(x1, y1, x2+1, y2+1); @@ -1145,7 +1143,7 @@ void jstandard_theme::draw_slider(JWidget widget, JRect clip) set_clip(ji_screen, cx1, cy1, cx2, cy2); - widget->set_text_quiet(old_text.c_str()); + widget->setTextQuiet(old_text.c_str()); jrect_free(r); } } @@ -1185,12 +1183,12 @@ void jstandard_theme::draw_view(JWidget widget, JRect clip) /* 2nd border */ jrect_shrink(pos, 1); - jdraw_rect(pos, BGCOLOR); + jdraw_rect(pos, get_bg_color(widget)); } /* background */ jrect_shrink(pos, 1); - jdraw_rectfill(pos, BGCOLOR); + jdraw_rectfill(pos, get_bg_color(widget)); jrect_free(pos); } @@ -1209,13 +1207,13 @@ void jstandard_theme::draw_view_scrollbar(JWidget widget, JRect clip) y2 = widget->rc->y2-1; /* border */ - rect(ji_screen, x1, y1, x2, y2, BGCOLOR); + rect(ji_screen, x1, y1, x2, y2, get_bg_color(widget)); /* draw the content */ x1++, y1++, x2--, y2--; /* horizontal bar */ - if (widget->align() & JI_HORIZONTAL) { + if (widget->getAlign() & JI_HORIZONTAL) { u1 = x1+pos; v1 = y1; u2 = x1+pos+len-1; @@ -1232,7 +1230,7 @@ void jstandard_theme::draw_view_scrollbar(JWidget widget, JRect clip) /* background */ jrectexclude(ji_screen, x1, y1, x2, y2, - u1, v1, u2, v2, BGCOLOR); + u1, v1, u2, v2, get_bg_color(widget)); /* 1st border */ if (jwidget_is_selected(widget)) @@ -1247,30 +1245,30 @@ void jstandard_theme::draw_view_scrollbar(JWidget widget, JRect clip) if (jwidget_is_enabled(widget) && jwidget_has_mouse(widget)) rectfill(ji_screen, u1, v1, u2, v2, COLOR_HOTFACE); else - rectfill(ji_screen, u1, v1, u2, v2, BGCOLOR); + rectfill(ji_screen, u1, v1, u2, v2, get_bg_color(widget)); } void jstandard_theme::draw_view_viewport(JWidget widget, JRect clip) { - jdraw_rectfill(widget->rc, BGCOLOR); + jdraw_rectfill(widget->rc, get_bg_color(widget)); } -void jstandard_theme::draw_window(JWidget widget, JRect clip) +void jstandard_theme::draw_frame(Frame* frame, JRect clip) { - JRect pos = jwidget_get_rect(widget); - JRect cpos = jwidget_get_child_rect(widget); + JRect pos = jwidget_get_rect(frame); + JRect cpos = jwidget_get_child_rect(frame); /* extra lines */ - if (!jwindow_is_desktop(widget)) { - // draw window borders + if (!frame->is_desktop()) { + // draw frame borders jdraw_rect(pos, COLOR_FOREGROUND); jrect_shrink(pos, 1); jdraw_rectedge(pos, COLOR_BACKGROUND, COLOR_DISABLED); jrect_shrink(pos, 1); - jdraw_rectfill(pos, BGCOLOR); + jdraw_rectfill(pos, get_bg_color(frame)); // draw title bar - if (widget->has_text()) { + if (frame->hasText()) { int bg = COLOR_SELECTED; jrect_shrink(pos, 1); @@ -1281,15 +1279,15 @@ void jstandard_theme::draw_window(JWidget widget, JRect clip) jrect_stretch(pos, 1); jdraw_rectedge(cpos, COLOR_DISABLED, COLOR_BACKGROUND); - jdraw_text(widget->font(), widget->text(), + jdraw_text(frame->getFont(), frame->getText(), cpos->x1, - pos->y1+jrect_h(pos)/2-text_height(widget->font())/2, + pos->y1+jrect_h(pos)/2-text_height(frame->getFont())/2, COLOR_BACKGROUND, bg, false); } } /* desktop */ else { - jdraw_rectfill(pos, widget->theme->desktop_color); + jdraw_rectfill(pos, frame->theme->desktop_color); } jrect_free(pos); @@ -1309,33 +1307,33 @@ void jstandard_theme::draw_textstring(const char *t, int fg_color, int bg_color, bool fill_bg, JWidget widget, const JRect rect, int selected_offset) { - if (t || widget->has_text()) { + if (t || widget->hasText()) { int x, y, w, h; if (!t) { - t = widget->text(); + t = widget->getText(); w = jwidget_get_text_length(widget); h = jwidget_get_text_height(widget); } else { - w = ji_font_text_len(widget->font(), t); - h = text_height(widget->font()); + w = ji_font_text_len(widget->getFont(), t); + h = text_height(widget->getFont()); } /* horizontally text alignment */ - if (widget->align() & JI_RIGHT) + if (widget->getAlign() & JI_RIGHT) x = rect->x2 - w; - else if (widget->align() & JI_CENTER) + else if (widget->getAlign() & JI_CENTER) x = (rect->x1+rect->x2)/2 - w/2; else x = rect->x1; /* vertically text alignment */ - if (widget->align() & JI_BOTTOM) + if (widget->getAlign() & JI_BOTTOM) y = rect->y2 - h; - else if (widget->align() & JI_MIDDLE) + else if (widget->getAlign() & JI_MIDDLE) y = (rect->y1+rect->y2)/2 - h/2; else y = rect->y1; @@ -1357,17 +1355,17 @@ void jstandard_theme::draw_textstring(const char *t, int fg_color, int bg_color, if (jwidget_is_disabled (widget)) { /* TODO avoid this */ if (fill_bg) /* only to draw the background */ - jdraw_text(widget->font(), t, x, y, 0, bg_color, fill_bg); + jdraw_text(widget->getFont(), t, x, y, 0, bg_color, fill_bg); /* draw white part */ - jdraw_text(widget->font(), t, x+1, y+1, + jdraw_text(widget->getFont(), t, x+1, y+1, COLOR_BACKGROUND, bg_color, fill_bg); if (fill_bg) fill_bg = false; } - jdraw_text(widget->font(), t, x, y, + jdraw_text(widget->getFont(), t, x, y, jwidget_is_disabled(widget) ? COLOR_DISABLED: (fg_color >= 0 ? fg_color : COLOR_FOREGROUND), diff --git a/src/modules/editors.cpp b/src/modules/editors.cpp index 66e932a0a..f23497c24 100644 --- a/src/modules/editors.cpp +++ b/src/modules/editors.cpp @@ -32,8 +32,8 @@ #include "widgets/editor.h" #define FIXUP_TOP_WINDOW() \ - jwindow_remap(app_get_top_window()); \ - jwidget_dirty(app_get_top_window()); + app_get_top_window()->remap_window(); \ + app_get_top_window()->dirty(); JWidget current_editor = NULL; JWidget box_editors = NULL; diff --git a/src/modules/gui.cpp b/src/modules/gui.cpp index caa08191f..0e289a928 100644 --- a/src/modules/gui.cpp +++ b/src/modules/gui.cpp @@ -479,7 +479,7 @@ void gui_feedback() resize_screen(); gui_setup_screen(false); - jwindow_remap(app_get_top_window()); + app_get_top_window()->remap_window(); jmanager_refresh_screen(); } #endif @@ -1086,18 +1086,17 @@ static bool manager_msg_proc(JWidget widget, JMessage msg) } // all other keys are only available in the main-window else { - JWidget child; JLink link; JI_LIST_FOR_EACH(widget->children, link) { - child = reinterpret_cast(link->data); + Frame* child = reinterpret_cast(link->data); /* there are a foreground window executing? */ - if (jwindow_is_foreground(child)) { + if (child->is_foreground()) { break; } /* is it the desktop and the top-window= */ - else if (jwindow_is_desktop(child) && child == app_get_top_window()) { + else if (child->is_desktop() && child == app_get_top_window()) { /* ok, so we can execute the command represented by the pressed-key in the message... */ UIContext::instance()->execute_command(command, shortcut->params); diff --git a/src/modules/gui.h b/src/modules/gui.h index 9104d9528..c339ba10c 100644 --- a/src/modules/gui.h +++ b/src/modules/gui.h @@ -77,27 +77,27 @@ void gui_setup_screen(bool reload_font); void reload_default_font(); -void load_window_pos(JWidget window, const char *section); -void save_window_pos(JWidget window, const char *section); +void load_window_pos(Widget* window, const char *section); +void save_window_pos(Widget* window, const char *section); -JWidget load_widget(const char *filename, const char *name); -JWidget find_widget(JWidget widget, const char *name); +Widget* load_widget(const char *filename, const char *name); +Widget* find_widget(Widget* widget, const char *name); void schedule_rebuild_recent_list(); -void hook_signal(JWidget widget, +void hook_signal(Widget* widget, int signal_num, - bool (*signal_handler)(JWidget widget, void *data), + bool (*signal_handler)(Widget* widget, void *data), void *data); -void get_widgets(JWidget window, ...); +void get_widgets(Widget* window, ...); -void add_gfxicon_to_button(JWidget button, int gfx_id, int icon_align); -void set_gfxicon_in_button(JWidget button, int gfx_id); +void add_gfxicon_to_button(Widget* button, int gfx_id, int icon_align); +void set_gfxicon_in_button(Widget* button, int gfx_id); -JWidget radio_button_new(int radio_group, int b1, int b2, int b3, int b4); -JWidget check_button_new(const char *text, int b1, int b2, int b3, int b4); -/* void change_to_button_style(JWidget widget, int b1, int b2, int b3, int b4); */ +Widget* radio_button_new(int radio_group, int b1, int b2, int b3, int b4); +Widget* check_button_new(const char *text, int b1, int b2, int b3, int b4); +/* void change_to_button_style(Widget* widget, int b1, int b2, int b3, int b4); */ ////////////////////////////////////////////////////////////////////// // Keyboard shortcuts @@ -118,47 +118,56 @@ void remove_gui_monitor(Monitor* monitor); void* get_monitor_data(Monitor* monitor); ////////////////////////////////////////////////////////////////////// -// Smart JWidget pointer +// Smart Widget* pointer -class JWidgetPtr +template +class ScopedPtr { - JWidget m_widget; + T* m_ptr; // TODO make this class copyable and count references (so this is // really "smart" pointer)... - JWidgetPtr(const JWidgetPtr&); - JWidgetPtr& operator=(const JWidgetPtr&); + ScopedPtr(const ScopedPtr&); + ScopedPtr& operator=(const ScopedPtr&); public: - JWidgetPtr() { - m_widget = NULL; + ScopedPtr() { + m_ptr = NULL; } - explicit JWidgetPtr(JWidget widget) { - m_widget = widget; + explicit ScopedPtr(T* widget) { + m_ptr = widget; } - ~JWidgetPtr() { - delete m_widget; + template + explicit ScopedPtr(T2* widget) { + m_ptr = static_cast(widget); } - JWidgetPtr& operator=(JWidget widget) { - if (m_widget) - delete m_widget; + ~ScopedPtr() { + delete m_ptr; + } - m_widget = widget; + ScopedPtr& operator=(T* widget) { + if (m_ptr) + delete m_ptr; + + m_ptr = widget; return *this; } - operator JWidget() { - return m_widget; + operator T*() { + return m_ptr; } - JWidget operator->() { - assert(m_widget != NULL); - return m_widget; + T* operator->() { + assert(m_ptr != NULL); + return m_ptr; } }; +typedef ScopedPtr WidgetPtr; +typedef ScopedPtr FramePtr; + #endif diff --git a/src/modules/rootmenu.cpp b/src/modules/rootmenu.cpp index 7e19f12f8..53480f5a9 100644 --- a/src/modules/rootmenu.cpp +++ b/src/modules/rootmenu.cpp @@ -89,11 +89,10 @@ static int load_root_menu() if (app_get_menubar()) jmenubar_set_menu(app_get_menubar(), NULL); - /* destroy `root-menu' if it exists */ - if (root_menu) - jwidget_free(root_menu); + // destroy `root-menu' + delete root_menu; // widget - /* create a new empty-menu */ + // create a new empty-menu root_menu = NULL; recent_list_menuitem = NULL; layer_popup_menu = NULL; @@ -230,7 +229,7 @@ static int load_root_menu() /* sets the "menu" of the "menu-bar" to the new "root-menu" */ if (app_get_menubar()) { jmenubar_set_menu(app_get_menubar(), root_menu); - jwindow_remap(app_get_top_window()); + app_get_top_window()->remap_window(); jwidget_dirty(app_get_top_window()); } @@ -345,7 +344,7 @@ static void apply_shortcut_to_menuitems_with_command(JWidget menu, Command *comm JI_LIST_FOR_EACH(children, link) { menuitem = (JWidget)link->data; - if (jwidget_get_type(menuitem) == JI_MENUITEM) { + if (menuitem->getType() == JI_MENUITEM) { Command* mi_command = menuitem_get_command(menuitem); Params* mi_params = menuitem_get_params(menuitem); diff --git a/src/modules/skinneable_theme.cpp b/src/modules/skinneable_theme.cpp index e2b468069..adc801037 100644 --- a/src/modules/skinneable_theme.cpp +++ b/src/modules/skinneable_theme.cpp @@ -492,12 +492,12 @@ void SkinneableTheme::init_widget(JWidget widget) case JI_SEPARATOR: /* frame */ - if ((widget->align() & JI_HORIZONTAL) && - (widget->align() & JI_VERTICAL)) { + if ((widget->getAlign() & JI_HORIZONTAL) && + (widget->getAlign() & JI_VERTICAL)) { BORDER(4); } /* horizontal bar */ - else if (widget->align() & JI_HORIZONTAL) { + else if (widget->getAlign() & JI_HORIZONTAL) { BORDER4(2, 4, 2, 0); } /* vertical bar */ @@ -505,10 +505,10 @@ void SkinneableTheme::init_widget(JWidget widget) BORDER4(4, 2, 0, 2); } - if (widget->has_text()) { - if (widget->align() & JI_TOP) + if (widget->hasText()) { + if (widget->getAlign() & JI_TOP) widget->border_width.t = jwidget_get_text_height(widget); - else if (widget->align() & JI_BOTTOM) + else if (widget->getAlign() & JI_BOTTOM) widget->border_width.b = jwidget_get_text_height(widget); } break; @@ -519,7 +519,7 @@ void SkinneableTheme::init_widget(JWidget widget) widget->border_width.r = m_part[PART_SLIDER_EMPTY_E]->w-1; widget->border_width.b = m_part[PART_SLIDER_EMPTY_S]->h-1; widget->child_spacing = jwidget_get_text_height(widget); - widget->align(JI_CENTER | JI_MIDDLE); + widget->setAlign(JI_CENTER | JI_MIDDLE); break; case JI_TEXTBOX: @@ -545,19 +545,19 @@ void SkinneableTheme::init_widget(JWidget widget) widget->child_spacing = 0; break; - case JI_WINDOW: - if (!jwindow_is_desktop(widget)) { - if (widget->has_text()) { + case JI_FRAME: + if (!static_cast(widget)->is_desktop()) { + if (widget->hasText()) { BORDER4(6, 4+jwidget_get_text_height(widget)+6, 6, 6); #if 1 /* add close button */ if (!(widget->flags & JI_INITIALIZED)) { JWidget button = jbutton_new(""); jbutton_set_bevel(button, 0, 0, 0, 0); jwidget_add_hook(button, JI_WIDGET, - &SkinneableTheme::theme_window_button_msg_proc, NULL); + &SkinneableTheme::theme_frame_button_msg_proc, NULL); jwidget_decorative(button, true); jwidget_add_child(widget, button); - jwidget_set_name(button, "theme_close_button"); + button->setName("theme_close_button"); } #endif } @@ -569,7 +569,7 @@ void SkinneableTheme::init_widget(JWidget widget) BORDER(0); } widget->child_spacing = 4; - widget->bg_color(get_window_face_color()); + widget->setBgColor(get_window_face_color()); break; default: @@ -766,7 +766,7 @@ void SkinneableTheme::draw_entry(JWidget widget, JRect clip) { bool password = jentry_is_password(widget); int scroll, cursor, state, selbeg, selend; - const char *text = widget->text(); + const char *text = widget->getText(); int c, ch, x, y, w, fg, bg; int x1, y1, x2, y2; int cursor_x; @@ -811,14 +811,14 @@ void SkinneableTheme::draw_entry(JWidget widget, JRect clip) fg = COLOR_DISABLED; } - w = CHARACTER_LENGTH(widget->font(), ch); + w = CHARACTER_LENGTH(widget->getFont(), ch); if (x+w > widget->rc->x2-3) return; cursor_x = x; - ji_font_set_aa_mode(widget->font(), bg >= 0 ? bg: COLOR_BACKGROUND); - widget->font()->vtable->render_char(widget->font(), - ch, fg, bg, ji_screen, x, y); + ji_font_set_aa_mode(widget->getFont(), bg >= 0 ? bg: COLOR_BACKGROUND); + widget->getFont()->vtable->render_char(widget->getFont(), + ch, fg, bg, ji_screen, x, y); x += w; /* cursor */ @@ -868,9 +868,9 @@ void SkinneableTheme::draw_listitem(JWidget widget, JRect clip) x = widget->rc->x1+widget->border_width.l; y = widget->rc->y1+widget->border_width.t; - if (widget->has_text()) { + if (widget->hasText()) { /* text */ - jdraw_text(widget->font(), widget->text(), x, y, fg, bg, true); + jdraw_text(widget->getFont(), widget->getText(), x, y, fg, bg, true); /* background */ jrectexclude @@ -946,9 +946,9 @@ void SkinneableTheme::draw_menuitem(JWidget widget, JRect clip) /* text */ if (bar) - widget->align(JI_CENTER | JI_MIDDLE); + widget->setAlign(JI_CENTER | JI_MIDDLE); else - widget->align(JI_LEFT | JI_MIDDLE); + widget->setAlign(JI_LEFT | JI_MIDDLE); pos = jwidget_get_rect(widget); if (!bar) @@ -984,7 +984,7 @@ void SkinneableTheme::draw_menuitem(JWidget widget, JRect clip) } /* draw the keyboard shortcut */ else if (jmenuitem_get_accel(widget)) { - int old_align = widget->align(); + int old_align = widget->getAlign(); char buf[256]; pos = jwidget_get_rect(widget); @@ -992,9 +992,9 @@ void SkinneableTheme::draw_menuitem(JWidget widget, JRect clip) jaccel_to_string(jmenuitem_get_accel(widget), buf); - widget->align(JI_RIGHT | JI_MIDDLE); + widget->setAlign(JI_RIGHT | JI_MIDDLE); draw_textstring(buf, fg, bg, false, widget, pos, 0); - widget->align(old_align); + widget->setAlign(old_align); jrect_free(pos); } @@ -1058,7 +1058,7 @@ void SkinneableTheme::draw_separator(JWidget widget, JRect clip) // background jdraw_rectfill(widget->rc, BGCOLOR); - if (widget->align() & JI_HORIZONTAL) { + if (widget->getAlign() & JI_HORIZONTAL) { draw_hline(widget->rc->x1, widget->rc->y1, widget->rc->x2-1, @@ -1066,7 +1066,7 @@ void SkinneableTheme::draw_separator(JWidget widget, JRect clip) } // text - if (widget->has_text()) { + if (widget->hasText()) { int h = jwidget_get_text_height(widget); struct jrect r = { x1+h/2, y1-h/2, x2+1-h, y2+1+h }; draw_textstring(NULL, -1, BGCOLOR, false, widget, &r, 0); @@ -1130,13 +1130,13 @@ void SkinneableTheme::draw_slider(JWidget widget, JRect clip) /* text */ { - std::string old_text = widget->text(); + std::string old_text = widget->getText(); int cx1, cy1, cx2, cy2; JRect r; usprintf(buf, "%d", value); - widget->set_text_quiet(buf); + widget->setTextQuiet(buf); r = jrect_new(x1, y1, x2+1, y2+1); @@ -1163,7 +1163,7 @@ void SkinneableTheme::draw_slider(JWidget widget, JRect clip) set_clip(ji_screen, cx1, cy1, cx2, cy2); - widget->set_text_quiet(old_text.c_str()); + widget->setTextQuiet(old_text.c_str()); jrect_free(r); } } @@ -1172,7 +1172,7 @@ void SkinneableTheme::draw_combobox_entry(JWidget widget, JRect clip) { bool password = jentry_is_password(widget); int scroll, cursor, state, selbeg, selend; - const char *text = widget->text(); + const char *text = widget->getText(); int c, ch, x, y, w, fg, bg; int x1, y1, x2, y2; int cursor_x; @@ -1217,14 +1217,14 @@ void SkinneableTheme::draw_combobox_entry(JWidget widget, JRect clip) fg = COLOR_DISABLED; } - w = CHARACTER_LENGTH(widget->font(), ch); + w = CHARACTER_LENGTH(widget->getFont(), ch); if (x+w > widget->rc->x2-3) return; cursor_x = x; - ji_font_set_aa_mode(widget->font(), bg >= 0 ? bg: COLOR_BACKGROUND); - widget->font()->vtable->render_char(widget->font(), - ch, fg, bg, ji_screen, x, y); + ji_font_set_aa_mode(widget->getFont(), bg >= 0 ? bg: COLOR_BACKGROUND); + widget->getFont()->vtable->render_char(widget->getFont(), + ch, fg, bg, ji_screen, x, y); x += w; /* cursor */ @@ -1324,7 +1324,7 @@ void SkinneableTheme::draw_view_scrollbar(JWidget widget, JRect clip) x1++, y1++, x2--, y2--; /* horizontal bar */ - if (widget->align() & JI_HORIZONTAL) { + if (widget->getAlign() & JI_HORIZONTAL) { u1 = x1+pos; v1 = y1; u2 = x1+pos+len-1; @@ -1364,14 +1364,14 @@ void SkinneableTheme::draw_view_viewport(JWidget widget, JRect clip) jdraw_rectfill(widget->rc, BGCOLOR); } -void SkinneableTheme::draw_window(JWidget widget, JRect clip) +void SkinneableTheme::draw_frame(Frame* window, JRect clip) { - JRect pos = jwidget_get_rect(widget); - JRect cpos = jwidget_get_child_rect(widget); + JRect pos = jwidget_get_rect(window); + JRect cpos = jwidget_get_child_rect(window); - if (!jwindow_is_desktop(widget)) { + if (!window->is_desktop()) { // window frame - if (widget->has_text()) { + if (window->hasText()) { draw_bounds(pos->x1, pos->y1, pos->x2-1, @@ -1381,9 +1381,9 @@ void SkinneableTheme::draw_window(JWidget widget, JRect clip) pos->y2 = cpos->y1; // titlebar - jdraw_text(widget->font(), widget->text(), + jdraw_text(window->getFont(), window->getText(), cpos->x1, - pos->y1+jrect_h(pos)/2-text_height(widget->font())/2, + pos->y1+jrect_h(pos)/2-text_height(window->getFont())/2, COLOR_BACKGROUND, -1, false); } // menubox @@ -1397,18 +1397,18 @@ void SkinneableTheme::draw_window(JWidget widget, JRect clip) } // desktop else { - jdraw_rectfill(pos, widget->theme->desktop_color); + jdraw_rectfill(pos, window->theme->desktop_color); } jrect_free(pos); jrect_free(cpos); } -void SkinneableTheme::draw_window_button(JWidget widget, JRect clip) +void SkinneableTheme::draw_frame_button(JWidget widget, JRect clip) { int part; - if (widget->selected()) + if (widget->isSelected()) part = PART_WINDOW_CLOSE_BUTTON_SELECTED; else if (jwidget_has_mouse(widget)) part = PART_WINDOW_CLOSE_BUTTON_HOT; @@ -1431,33 +1431,33 @@ void SkinneableTheme::draw_textstring(const char *t, int fg_color, int bg_color, bool fill_bg, JWidget widget, const JRect rect, int selected_offset) { - if (t || widget->has_text()) { + if (t || widget->hasText()) { int x, y, w, h; if (!t) { - t = widget->text(); + t = widget->getText(); w = jwidget_get_text_length(widget); h = jwidget_get_text_height(widget); } else { - w = ji_font_text_len(widget->font(), t); - h = text_height(widget->font()); + w = ji_font_text_len(widget->getFont(), t); + h = text_height(widget->getFont()); } /* horizontally text alignment */ - if (widget->align() & JI_RIGHT) + if (widget->getAlign() & JI_RIGHT) x = rect->x2 - w; - else if (widget->align() & JI_CENTER) + else if (widget->getAlign() & JI_CENTER) x = (rect->x1+rect->x2)/2 - w/2; else x = rect->x1; /* vertically text alignment */ - if (widget->align() & JI_BOTTOM) + if (widget->getAlign() & JI_BOTTOM) y = rect->y2 - h; - else if (widget->align() & JI_MIDDLE) + else if (widget->getAlign() & JI_MIDDLE) y = (rect->y1+rect->y2)/2 - h/2; else y = rect->y1; @@ -1479,17 +1479,17 @@ void SkinneableTheme::draw_textstring(const char *t, int fg_color, int bg_color, if (jwidget_is_disabled (widget)) { /* TODO avoid this */ if (fill_bg) /* only to draw the background */ - jdraw_text(widget->font(), t, x, y, 0, bg_color, fill_bg); + jdraw_text(widget->getFont(), t, x, y, 0, bg_color, fill_bg); /* draw white part */ - jdraw_text(widget->font(), t, x+1, y+1, + jdraw_text(widget->getFont(), t, x+1, y+1, COLOR_BACKGROUND, bg_color, fill_bg); if (fill_bg) fill_bg = false; } - jdraw_text(widget->font(), t, x, y, + jdraw_text(widget->getFont(), t, x, y, jwidget_is_disabled(widget) ? COLOR_DISABLED: (fg_color >= 0 ? fg_color : COLOR_FOREGROUND), @@ -1622,7 +1622,7 @@ void SkinneableTheme::less_bevel(int *bevel) } /* controls the "X" button in a window to close it */ -bool SkinneableTheme::theme_window_button_msg_proc(JWidget widget, JMessage msg) +bool SkinneableTheme::theme_frame_button_msg_proc(JWidget widget, JMessage msg) { switch (msg->type) { @@ -1631,7 +1631,7 @@ bool SkinneableTheme::theme_window_button_msg_proc(JWidget widget, JMessage msg) return true; case JM_DRAW: - ((SkinneableTheme*)widget->theme)->draw_window_button(widget, &msg->draw.rect); + ((SkinneableTheme*)widget->theme)->draw_frame_button(widget, &msg->draw.rect); return true; case JM_KEYPRESSED: diff --git a/src/modules/skinneable_theme.h b/src/modules/skinneable_theme.h index 9473ea79a..75f8e2c2b 100644 --- a/src/modules/skinneable_theme.h +++ b/src/modules/skinneable_theme.h @@ -321,8 +321,8 @@ public: void draw_view(JWidget widget, JRect clip); void draw_view_scrollbar(JWidget widget, JRect clip); void draw_view_viewport(JWidget widget, JRect clip); - void draw_window(JWidget widget, JRect clip); - void draw_window_button(JWidget widget, JRect clip); + void draw_frame(Frame* frame, JRect clip); + void draw_frame_button(JWidget widget, JRect clip); int get_button_normal_text_color() const { return makecol(0, 0, 0); } int get_button_normal_face_color() const { return makecol(198, 198, 198); } @@ -387,7 +387,7 @@ private: void draw_bevel_box(int x1, int y1, int x2, int y2, int c1, int c2, int *bevel); void less_bevel(int *bevel); - static bool theme_window_button_msg_proc(JWidget widget, JMessage msg); + static bool theme_frame_button_msg_proc(JWidget widget, JMessage msg); static bool theme_combobox_button_msg_proc(JWidget widget, JMessage msg); }; diff --git a/src/tests/jinete/00hello.cpp b/src/tests/jinete/00hello.cpp index b29d53ca0..8ea9bbd1a 100644 --- a/src/tests/jinete/00hello.cpp +++ b/src/tests/jinete/00hello.cpp @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) /* create a simple centered label with "Hello World!" text */ label = jlabel_new("Hello World!"); - jwidget_set_align(label, JI_CENTER | JI_MIDDLE); + label->set_align(JI_CENTER | JI_MIDDLE); /* create a button to close the window */ button = jbutton_new("&Close"); @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) /* show the window in the screen and leave it in the background (the manager will free it) */ - jwindow_open_bg(window); + window->open_window_bg(); /* run windows */ jmanager_run(manager); diff --git a/src/tests/jinete/01simple.cpp b/src/tests/jinete/01simple.cpp index 72107ccde..5c6c1948f 100644 --- a/src/tests/jinete/01simple.cpp +++ b/src/tests/jinete/01simple.cpp @@ -61,7 +61,7 @@ int main (int argc, char *argv[]) button_ok = jbutton_new ("&OK"); button_cancel = jbutton_new ("&Cancel"); - jwidget_set_align (label, JI_CENTER | JI_MIDDLE); + label->set_align(JI_CENTER | JI_MIDDLE); jwidget_expansive (label, TRUE); jwidget_add_child (window, box1); @@ -70,7 +70,7 @@ int main (int argc, char *argv[]) jwidget_add_child (box2, button_ok); jwidget_add_child (box2, button_cancel); - jwindow_open_bg (window); + window->open_window_bg(); jmanager_run (manager); jmanager_free (manager); diff --git a/src/tests/jinete/02label.cpp b/src/tests/jinete/02label.cpp index 6e3a490f0..15279ca7d 100644 --- a/src/tests/jinete/02label.cpp +++ b/src/tests/jinete/02label.cpp @@ -59,10 +59,10 @@ int main (int argc, char *argv[]) label3 = jlabel_new ("&Right Bottom"); label4 = jlabel_new ("&Disabled"); - jwidget_set_align (label1, JI_LEFT | JI_TOP); - jwidget_set_align (label2, JI_CENTER | JI_MIDDLE); - jwidget_set_align (label3, JI_RIGHT | JI_BOTTOM); - jwidget_set_align (label4, JI_CENTER | JI_BOTTOM); + label1->set_align(JI_LEFT | JI_TOP); + label2->set_align(JI_CENTER | JI_MIDDLE); + label3->set_align(JI_RIGHT | JI_BOTTOM); + label4->set_align(JI_CENTER | JI_BOTTOM); jwidget_disable (label4); @@ -72,7 +72,7 @@ int main (int argc, char *argv[]) jwidget_add_child (box, label3); jwidget_add_child (box, label4); - jwindow_open_bg (window); + window->open_window_bg(); jmanager_run (manager); jmanager_free (manager); diff --git a/src/tests/jinete/03slider.cpp b/src/tests/jinete/03slider.cpp index 52f080b2d..551001e06 100644 --- a/src/tests/jinete/03slider.cpp +++ b/src/tests/jinete/03slider.cpp @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) slider1, slider2, slider3, slider4, slider5, button1, NULL); - jwindow_open_bg(window); + window->open_window_bg(); jmanager_run(manager); jmanager_free(manager); diff --git a/src/tests/jinete/06entry.cpp b/src/tests/jinete/06entry.cpp index 8af582ba6..e37334950 100644 --- a/src/tests/jinete/06entry.cpp +++ b/src/tests/jinete/06entry.cpp @@ -84,7 +84,7 @@ int main (int argc, char *argv[]) jwidget_add_child (box5, button1); jwidget_add_child (box5, button2); - jwindow_open_bg (window1); + window1->open_window_bg(); jmanager_run (manager); jmanager_free (manager); return 0; diff --git a/src/tests/jinete/07panel.cpp b/src/tests/jinete/07panel.cpp index 5d666869b..ec676303a 100644 --- a/src/tests/jinete/07panel.cpp +++ b/src/tests/jinete/07panel.cpp @@ -66,7 +66,7 @@ int main (int argc, char *argv[]) jwidget_add_children(box1, box2, button, NULL); jwidget_add_children(box2, view1, view2, NULL); - jwindow_open_bg (window); + window->open_window_bg(); jmanager_run (manager); jmanager_free (manager); diff --git a/src/tests/jinete/08txtbox.cpp b/src/tests/jinete/08txtbox.cpp index 30ea89099..36ff129c6 100644 --- a/src/tests/jinete/08txtbox.cpp +++ b/src/tests/jinete/08txtbox.cpp @@ -86,7 +86,7 @@ void do_text(const char *title, int align) jwidget_add_child(box1, button); jwidget_add_child(window, box1); - jwindow_open_bg(window); + window->open_window_bg(); } int main(int argc, char *argv[]) diff --git a/src/tests/jinete/09lists.cpp b/src/tests/jinete/09lists.cpp index a1b4e8ebc..2d31e7a62 100644 --- a/src/tests/jinete/09lists.cpp +++ b/src/tests/jinete/09lists.cpp @@ -93,10 +93,10 @@ JRect test1() jwidget_add_child (box, listbox); jwidget_add_child (box, button); - jwindow_center(window); + window->center_window(); pos = jwidget_get_rect(window); - jwindow_open_fg(window); + window->open_window_fg(); jwidget_free(window); return pos; @@ -129,10 +129,10 @@ void test2(JRect pos) jwidget_add_child (box, view); jwidget_add_child (box, button); - jwindow_remap(window); + window->remap_window(); jwidget_set_rect(window, pos); - jwindow_open_fg(window); + window->open_window_fg(); jwidget_free(window); } @@ -163,10 +163,10 @@ void test3(JRect pos) jwidget_add_child (box, view); jwidget_add_child (box, button); - jwindow_remap(window); + window->remap_window(); jwidget_set_rect(window, pos); - jwindow_open_fg(window); + window->open_window_fg(); jwidget_free(window); } @@ -199,9 +199,9 @@ void test4(JRect pos) jwidget_add_child (box, view); jwidget_add_child (box, button); - jwindow_remap(window); + window->remap_window(); jwidget_set_rect(window, pos); - jwindow_open_fg(window); + window->open_window_fg(); jwidget_free(window); } diff --git a/src/tests/jinete/10chcks.cpp b/src/tests/jinete/10chcks.cpp index 6211f72c2..6ee97539d 100644 --- a/src/tests/jinete/10chcks.cpp +++ b/src/tests/jinete/10chcks.cpp @@ -108,7 +108,7 @@ int main (int argc, char *argv[]) jwidget_expansive (check, TRUE); update_radios (); - jwindow_open_bg (window); + window->open_window_bg(); jmanager_run (manager); jmanager_free (manager); return 0; @@ -162,7 +162,7 @@ static bool hooked_check_msg_proc (JWidget widget, JMessage msg) } if (text_align != jwidget_get_align(check)) - jwidget_set_align(check, text_align); + check->set_align(text_align); if (icon_align != ji_generic_button_get_icon_align(check)) ji_generic_button_set_icon_align(check, icon_align); diff --git a/src/tests/jinete/11file.cpp b/src/tests/jinete/11file.cpp index 964bd8774..f72bbd674 100644 --- a/src/tests/jinete/11file.cpp +++ b/src/tests/jinete/11file.cpp @@ -59,7 +59,7 @@ int main (int argc, char *argv[]) if (window) { JWidget button_poll = jwidget_find_name (window, "Poll"); jbutton_add_command (button_poll, poll_button); - jwindow_open_bg (window); + window->open_window_bg(); } else jalert ("Error loading main window||&OK"); @@ -83,9 +83,9 @@ static void poll_button (JWidget widget) if (window) { JWidget button_select = jwidget_find_name (window, "Select"); - jwindow_open_fg (window); + window->open_window_fg(); - if (jwindow_get_killer (window) == button_select) { + if (window->get_killer() == button_select) { JWidget option1 = jwidget_find_name (window, "Option1"); JWidget option2 = jwidget_find_name (window, "Option2"); JWidget option3 = jwidget_find_name (window, "Option3"); diff --git a/src/tests/jinete/12qckmnu.cpp b/src/tests/jinete/12qckmnu.cpp index 649e1445b..a1e6c356a 100644 --- a/src/tests/jinete/12qckmnu.cpp +++ b/src/tests/jinete/12qckmnu.cpp @@ -85,7 +85,7 @@ int main (int argc, char *argv[]) jwidget_add_child (box, menubar); jwidget_add_child (box, button); - jwindow_open_bg (window); + window->open_window_bg(); jmanager_run (manager); jmanager_free (manager); diff --git a/src/tests/jinete/13menu.cpp b/src/tests/jinete/13menu.cpp index cbda4a3ae..710b9c94a 100644 --- a/src/tests/jinete/13menu.cpp +++ b/src/tests/jinete/13menu.cpp @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) jwidget_add_child(box1, button); jwidget_add_child(window, box1); - jwindow_open_bg(window); + window->open_window_bg(); jmanager_run(manager); jmanager_free(manager); diff --git a/src/tests/jinete/14win.cpp b/src/tests/jinete/14win.cpp index c8e85079f..24e1c44df 100644 --- a/src/tests/jinete/14win.cpp +++ b/src/tests/jinete/14win.cpp @@ -34,8 +34,9 @@ int main (int argc, char *argv[]) { - JWidget manager, desktop, box, view, sub_manager, button, window; - JWidget subwindows[256]; + JWidget manager, desktop, box, view, sub_manager, button; + Window* subwindows[256]; + Window* window; char buf[256]; int c; @@ -69,7 +70,7 @@ int main (int argc, char *argv[]) jwidget_add_child(box, view); jwidget_add_child(box, button); - jwindow_open_bg(desktop); + desktop->open_window_bg(); /* generate 128 windows in random positions */ for (c=0; c<128; c++) { @@ -80,7 +81,7 @@ int main (int argc, char *argv[]) jwidget_add_child(window, button); - jwindow_remap(window); + window->remap_window(); jwindow_position (window, sub_manager->rc->x1 + (rand () % (jrect_w(sub_manager->rc) - jrect_w(window->rc))), diff --git a/src/tests/jinete/15colbut.cpp b/src/tests/jinete/15colbut.cpp index 2db1cecb5..e7c9e968d 100644 --- a/src/tests/jinete/15colbut.cpp +++ b/src/tests/jinete/15colbut.cpp @@ -85,7 +85,7 @@ int main (int argc, char *argv[]) jwidget_add_child (box1, button5); jwidget_add_child (window1, box1); - jwindow_open_bg(window1); + window1->open_window_bg(); jmanager_run(manager); jlist_free(windows); @@ -97,12 +97,12 @@ END_OF_MAIN(); static JWidget my_button_new(const char *text, int color) { - JWidget widget = jbutton_new (text); + JWidget widget = jbutton_new(text); widget->user_data[0] = (void *)color; - jwidget_add_hook (widget, JI_WIDGET, my_button_msg_proc, NULL); - jwidget_set_align (widget, JI_LEFT | JI_BOTTOM); + jwidget_add_hook(widget, JI_WIDGET, my_button_msg_proc, NULL); + widget->set_align(JI_LEFT | JI_BOTTOM); return widget; } @@ -174,7 +174,7 @@ static bool my_button_msg_proc(JWidget widget, JMessage msg) jlist_append(windows, alert); jwidget_add_hook(alert, JI_WIDGET, hooked_window_bg_msg_proc, NULL); - jwindow_open_bg(alert); + alert->open_window_bg(); /* return TRUE to avoid close the window */ return TRUE; @@ -199,7 +199,7 @@ static void new_palette_window(JWidget widget) jlist_append(windows, window); jwidget_add_hook(window, JI_WIDGET, hooked_window_bg_msg_proc, NULL); - jwindow_open_bg(window); + window->open_window_bg(); } static bool hooked_window1_msg_proc(JWidget widget, JMessage msg) @@ -207,7 +207,7 @@ static bool hooked_window1_msg_proc(JWidget widget, JMessage msg) if (msg->type == JM_CLOSE) { JLink link, next; JI_LIST_FOR_EACH_SAFE(windows, link, next) /* close all windows */ - jwindow_close(reinterpret_cast(link->data), NULL); + reinterpret_cast(link->data)->close_window(NULL); } return FALSE; } diff --git a/src/tests/jinete/16theme.cpp b/src/tests/jinete/16theme.cpp index 858fb5d0f..56d87a457 100644 --- a/src/tests/jinete/16theme.cpp +++ b/src/tests/jinete/16theme.cpp @@ -166,7 +166,7 @@ JTheme my_theme_new() jtheme_set_method(theme, JI_BOX, theme_draw_box); jtheme_set_method(theme, JI_BUTTON, theme_draw_button); jtheme_set_method(theme, JI_LABEL, theme_draw_label); - jtheme_set_method(theme, JI_WINDOW, theme_draw_window); + jtheme_set_method(theme, JI_FRAME, theme_draw_frame); return theme; } @@ -207,7 +207,7 @@ static void theme_init_widget(JWidget widget) widget->child_spacing = 0; break; - case JI_WINDOW: + case JI_FRAME: BORDER4(8, 12+jwidget_get_text_height(widget)+12, 8, 8); widget->child_spacing = 1; break; diff --git a/src/tests/jinete/17theme.cpp b/src/tests/jinete/17theme.cpp index 4dd57c7df..1e8e2035c 100644 --- a/src/tests/jinete/17theme.cpp +++ b/src/tests/jinete/17theme.cpp @@ -106,9 +106,9 @@ int main(int argc, char *argv[]) jwindow_sizeable(window, FALSE); again:; - jwindow_open_fg(window); + window->open_window_fg(); - if (jwindow_get_killer(window) == button1) { + if (window->get_killer() == button1) { if (*jwidget_get_text(entry_username) && *jwidget_get_text(entry_password)) jalert("Login Successful" @@ -202,7 +202,7 @@ JTheme my_theme_new() jtheme_set_method(theme, JI_BUTTON, theme_draw_button); jtheme_set_method(theme, JI_ENTRY, theme_draw_entry); jtheme_set_method(theme, JI_LABEL, theme_draw_label); - jtheme_set_method(theme, JI_WINDOW, theme_draw_window); + jtheme_set_method(theme, JI_FRAME, theme_draw_frame); return theme; } @@ -248,7 +248,7 @@ static void theme_init_widget(JWidget widget) widget->child_spacing = 0; break; - case JI_WINDOW: + case JI_FRAME: BORDER4(7, 7+jwidget_get_text_height(widget)+7, 7, 7); widget->child_spacing = 1; break; diff --git a/src/tests/jinete/18tips.cpp b/src/tests/jinete/18tips.cpp index c4952d3dd..a10b5634e 100644 --- a/src/tests/jinete/18tips.cpp +++ b/src/tests/jinete/18tips.cpp @@ -70,7 +70,7 @@ int main (int argc, char *argv[]) jwidget_add_child(box, button1); jwidget_add_child(box, button2); - jwindow_open_bg(window); + window->open_window_bg(); jmanager_run(manager); jmanager_free(manager); @@ -143,7 +143,7 @@ static bool tip_hook(JWidget widget, JMessage msg) JWidget window = tip_window_new(tip->text); int w = jrect_w(window->rc); int h = jrect_h(window->rc); - jwindow_remap(window); + window->remap_window(); jwindow_position(window, MID(0, jmouse_x(0)-w/2, JI_SCREEN_W-w), MID(0, jmouse_y(0)-h/2, JI_SCREEN_H-h)); @@ -165,7 +165,7 @@ static JWidget tip_window_new(const char *text) jwindow_sizeable(window, FALSE); jwindow_moveable(window, FALSE); - jwidget_set_align(window, JI_CENTER | JI_MIDDLE); + window->set_align(JI_CENTER | JI_MIDDLE); /* remove decorative widgets */ JI_LIST_FOR_EACH_SAFE(window->children, link, next) { @@ -194,7 +194,7 @@ static bool tip_window_hook(JWidget widget, JMessage msg) case JM_MOUSELEAVE: case JM_BUTTONPRESSED: - jwindow_close(widget, NULL); + widget->close_window(NULL); break; case JM_DRAW: { diff --git a/src/tests/jinete/20combo.cpp b/src/tests/jinete/20combo.cpp index aa0e883d3..e5350767d 100644 --- a/src/tests/jinete/20combo.cpp +++ b/src/tests/jinete/20combo.cpp @@ -87,7 +87,7 @@ int main (int argc, char *argv[]) jwidget_add_children(box1, label1, combobox1, label2, combobox2, box2, 0); jwidget_add_children(box2, button_ok, button_cancel, 0); - jwindow_open_bg(window); + window->open_window_bg(); jmanager_run(manager); jmanager_free(manager); diff --git a/src/tests/jinete/21manage.cpp b/src/tests/jinete/21manage.cpp index 007af6b48..ee1f380c5 100644 --- a/src/tests/jinete/21manage.cpp +++ b/src/tests/jinete/21manage.cpp @@ -35,7 +35,8 @@ int main (int argc, char *argv[]) { - JWidget manager1, manager2, manager3, window1, window2, window3; + JWidget manager1, manager2, manager3; + Window* window1, *window2, *window3; JWidget view2, view3; JRect rect; @@ -69,9 +70,9 @@ int main (int argc, char *argv[]) jwidget_add_child(window1, view2); jwidget_add_child(window2, view3); - jwindow_remap(window1); - jwindow_remap(window2); - jwindow_remap(window3); + window1->remap_window(); + window2->remap_window(); + window3->remap_window(); rect = jrect_new(JI_SCREEN_W/2-100, JI_SCREEN_H/2-70, JI_SCREEN_W/2+100, JI_SCREEN_H/2+70); @@ -88,7 +89,7 @@ int main (int argc, char *argv[]) jwidget_set_rect(window3, rect); jrect_free(rect); - jwindow_open_bg(window1); + window1->open_window_bg(); _jmanager_open_window(manager2, window2); _jmanager_open_window(manager3, window3); diff --git a/src/tests/jinete/22xml.cpp b/src/tests/jinete/22xml.cpp index f47bbda2e..d8a824b2b 100644 --- a/src/tests/jinete/22xml.cpp +++ b/src/tests/jinete/22xml.cpp @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) jwidget_add_child(vbox, button); jwidget_add_child(window, vbox); - jwindow_open_bg(window); + window->open_window_bg(); jmanager_run(manager); jmanager_free(manager); diff --git a/src/tests/jinete/23grid.cpp b/src/tests/jinete/23grid.cpp index ffcfc00a2..79c30bfad 100644 --- a/src/tests/jinete/23grid.cpp +++ b/src/tests/jinete/23grid.cpp @@ -79,7 +79,7 @@ int main(int argc, char *argv[]) jwidget_add_child(window, grid); } - jwindow_open_bg(window); + window->open_window_bg(); jmanager_run(manager); jmanager_free(manager); diff --git a/src/widgets/colbar.cpp b/src/widgets/colbar.cpp index 8645616a3..c8ae20856 100644 --- a/src/widgets/colbar.cpp +++ b/src/widgets/colbar.cpp @@ -56,10 +56,10 @@ typedef enum { HOTCOLOR_GRADIENT = 0, } hotcolor_t; -typedef struct ColorBar +struct ColorBar { - JWidget widget; - JWidget tooltip_window; + Widget* widget; + Frame* tooltip_window; int ncolor; int refresh_timer_id; color_t color[COLORBAR_MAX_COLORS]; @@ -70,7 +70,7 @@ typedef struct ColorBar /* drag & drop colors */ hotcolor_t hot_drag; hotcolor_t hot_drop; -} ColorBar; +}; static ColorBar *colorbar_data(JWidget colorbar); @@ -89,7 +89,7 @@ static void get_info(JWidget widget, int *beg, int *end); JWidget colorbar_new(int align) { - JWidget widget = new jwidget(colorbar_type()); + Widget* widget = new Widget(colorbar_type()); ColorBar *colorbar = jnew0(ColorBar, 1); colorbar->widget = widget; @@ -104,8 +104,8 @@ JWidget colorbar_new(int align) colorbar->hot_drop = HOTCOLOR_NONE; jwidget_add_hook(widget, colorbar_type(), colorbar_msg_proc, colorbar); - jwidget_focusrest(widget, TRUE); - jwidget_set_align(widget, align); + jwidget_focusrest(widget, true); + widget->setAlign(align); widget->border_width.l = 2; widget->border_width.t = 2; @@ -320,7 +320,7 @@ static bool colorbar_msg_proc(JWidget widget, JMessage msg) color_get_green(imgtype, colorbar->fgcolor), color_get_blue(imgtype, colorbar->fgcolor)); - textout_ex(doublebuffer, widget->font(), "FG", + textout_ex(doublebuffer, widget->getFont(), "FG", x1+4, v1+2, neg, -1); } @@ -329,8 +329,8 @@ static bool colorbar_msg_proc(JWidget widget, JMessage msg) color_get_green(imgtype, colorbar->bgcolor), color_get_blue(imgtype, colorbar->bgcolor)); - textout_ex(doublebuffer, widget->font(), "BG", - x2-3-text_length(widget->font(), "BG"), + textout_ex(doublebuffer, widget->getFont(), "BG", + x2-3-text_length(widget->getFont(), "BG"), v2-jwidget_get_text_height(widget), neg, -1); } } @@ -580,12 +580,12 @@ static void colorbar_open_tooltip(JWidget widget, int x1, int x2, int y1, int y2 color_t color, hotcolor_t hot) { ColorBar *colorbar = colorbar_data(widget); - JWidget window; + Frame* window; char buf[1024]; /* TODO warning buffer overflow */ int x, y; if (colorbar->tooltip_window == NULL) { - window = colorselector_new(TRUE); + window = colorselector_new(true); window->user_data[0] = widget; jwidget_add_hook(window, -1, tooltip_window_msg_proc, NULL); @@ -617,12 +617,12 @@ static void colorbar_open_tooltip(JWidget widget, int x1, int x2, int y1, int y2 usprintf(buf, _("Gradient Entry %d"), colorbar->hot); break; } - jwidget_set_text(window, buf); + window->setText(buf); colorselector_set_color(window, color); colorbar->hot_editing = hot; - jwindow_open(window); + window->open_window(); /* window position */ if (x2+jrect_w(window->rc) <= JI_SCREEN_W) @@ -634,7 +634,7 @@ static void colorbar_open_tooltip(JWidget widget, int x1, int x2, int y1, int y2 x = MID(0, x, JI_SCREEN_W-jrect_w(window->rc)); y = MID(widget->rc->y1, y, widget->rc->y2-jrect_h(window->rc)); - jwindow_position(window, x, y); + window->position_window(x, y); jmanager_dispatch_messages(jwidget_get_manager(window)); jwidget_relayout(window); @@ -656,7 +656,7 @@ static void colorbar_open_tooltip(JWidget widget, int x1, int x2, int y1, int y2 jrect_free(rc2); jrect_free(rc); - jtooltip_window_set_hotregion(window, rgn); + static_cast(window)->set_hotregion(rgn); } } @@ -666,7 +666,7 @@ static void colorbar_close_tooltip(JWidget widget) if (colorbar->tooltip_window != NULL) { /* close the widget */ - jwindow_close(colorbar->tooltip_window, NULL); + colorbar->tooltip_window->closeWindow(NULL); /* dispatch the JM_CLOSE event to 'tooltip_window_msg_proc' */ jmanager_dispatch_messages(jwidget_get_manager(widget)); diff --git a/src/widgets/colbut.cpp b/src/widgets/colbut.cpp index 3e8fd7746..ffe705421 100644 --- a/src/widgets/colbut.cpp +++ b/src/widgets/colbut.cpp @@ -34,7 +34,7 @@ typedef struct ColorButton { color_t color; int imgtype; - JWidget tooltip_window; + Frame* tooltip_window; } ColorButton; static ColorButton* colorbutton_data(JWidget widget); @@ -235,11 +235,11 @@ static void colorbutton_draw(JWidget widget) color_to_formalstring(colorbutton->imgtype, colorbutton->color, buf, sizeof(buf), FALSE); - widget->set_text_quiet(buf); + widget->setTextQuiet(buf); 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)); - jdraw_text(widget->font(), widget->text(), text.x1, text.y1, + jdraw_text(widget->getFont(), widget->getText(), text.x1, text.y1, makecol(255, 255, 255), makecol(0, 0, 0), FALSE); } @@ -247,14 +247,14 @@ static void colorbutton_draw(JWidget widget) static void colorbutton_open_tooltip(JWidget widget) { ColorButton* colorbutton = colorbutton_data(widget); - JWidget window; + Frame* window; int x, y; if (colorbutton->tooltip_window == NULL) { - window = colorselector_new(FALSE); + window = colorselector_new(false); window->user_data[0] = widget; jwidget_add_hook(window, -1, tooltip_window_msg_proc, NULL); - jwidget_set_text(window, "Select color"); + window->setText("Select color"); colorbutton->tooltip_window = window; } @@ -264,7 +264,7 @@ static void colorbutton_open_tooltip(JWidget widget) colorselector_set_color(window, colorbutton->color); - jwindow_open(window); + window->open_window(); x = MID(0, widget->rc->x1, JI_SCREEN_W-jrect_w(window->rc)); if (widget->rc->y2 <= JI_SCREEN_H-jrect_h(window->rc)) @@ -272,7 +272,7 @@ static void colorbutton_open_tooltip(JWidget widget) else y = MAX(0, widget->rc->y1-jrect_h(window->rc)); - jwindow_position(window, x, y); + window->position_window(x, y); jmanager_dispatch_messages(jwidget_get_manager(window)); jwidget_relayout(window); @@ -286,7 +286,7 @@ static void colorbutton_open_tooltip(JWidget widget) JRegion rgn = jregion_new(rc, 1); jrect_free(rc); - jtooltip_window_set_hotregion(window, rgn); + static_cast(window)->set_hotregion(rgn); } } @@ -295,7 +295,7 @@ static void colorbutton_close_tooltip(JWidget widget) ColorButton* colorbutton = colorbutton_data(widget); if (colorbutton->tooltip_window != NULL) - jwindow_close(colorbutton->tooltip_window, NULL); + colorbutton->tooltip_window->closeWindow(NULL); } static bool tooltip_window_msg_proc(JWidget widget, JMessage msg) diff --git a/src/widgets/colsel.cpp b/src/widgets/colsel.cpp index da6a3920c..9c06a9e47 100644 --- a/src/widgets/colsel.cpp +++ b/src/widgets/colsel.cpp @@ -86,9 +86,9 @@ static Model models[] = { { NULL, 0, 0, NULL } }; -JWidget colorselector_new(bool editable_palette) +Frame* colorselector_new(bool editable_palette) { - JWidget window = jtooltip_window_new(""); + Frame* window = new TipWindow(""); JWidget grid1 = jgrid_new(3, FALSE); JWidget grid2 = jgrid_new(5, FALSE); JWidget tabs = tabs_new(select_tab_callback); @@ -99,11 +99,11 @@ JWidget colorselector_new(bool editable_palette) ColorSelector* colorselector = jnew(ColorSelector, 1); Model* m; - jwidget_set_name(pal, "pal"); - jwidget_set_name(idx, "idx"); - jwidget_set_name(lock, "lock"); - jwidget_set_name(tabs, "tabs"); - jwidget_set_name(grid2, "grid2"); + pal->setName("pal"); + idx->setName("idx"); + lock->setName("lock"); + tabs->setName("tabs"); + grid2->setName("grid2"); /* color selector */ colorselector->color = color_mask(); @@ -117,7 +117,7 @@ JWidget colorselector_new(bool editable_palette) add_gfxicon_to_button(lock, GFX_BOX_LOCK, JI_CENTER | JI_MIDDLE); /* tabs */ - jwidget_set_bg_color(tabs, window->bg_color()); + tabs->setBgColor(window->getBgColor()); /* data for a better layout */ grid1->child_spacing = 0; @@ -129,7 +129,7 @@ JWidget colorselector_new(bool editable_palette) tabs_append_tab(tabs, _(m->text), (void*)m); child = (*m->create)(); - jwidget_set_name(child, m->text); + child->setName(m->text); jgrid_add_child(grid2, child, 1, 1, JI_HORIZONTAL | JI_TOP); } @@ -189,9 +189,9 @@ static JWidget create_rgb_container() jgrid_add_child(grid, blabel, 1, 1, JI_RIGHT); jgrid_add_child(grid, bslider, 1, 1, JI_HORIZONTAL); - jwidget_set_name(rslider, "rgb_r"); - jwidget_set_name(gslider, "rgb_g"); - jwidget_set_name(bslider, "rgb_b"); + rslider->setName("rgb_r"); + gslider->setName("rgb_g"); + bslider->setName("rgb_b"); HOOK(rslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); HOOK(gslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); @@ -216,9 +216,9 @@ static JWidget create_hsv_container() jgrid_add_child(grid, vlabel, 1, 1, JI_RIGHT); jgrid_add_child(grid, vslider, 1, 1, JI_HORIZONTAL); - jwidget_set_name(hslider, "hsv_h"); - jwidget_set_name(sslider, "hsv_s"); - jwidget_set_name(vslider, "hsv_v"); + hslider->setName("hsv_h"); + sslider->setName("hsv_s"); + vslider->setName("hsv_v"); HOOK(hslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); HOOK(sslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); @@ -235,7 +235,7 @@ static JWidget create_gray_container() jgrid_add_child(grid, klabel, 1, 1, JI_RIGHT); jgrid_add_child(grid, vslider, 1, 1, JI_HORIZONTAL); - jwidget_set_name(vslider, "gray_v"); + vslider->setName("gray_v"); HOOK(vslider, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0); @@ -278,7 +278,7 @@ static bool colorselector_msg_proc(JWidget widget, JMessage msg) JWidget idx = jwidget_find_name(widget, "idx"); JWidget pal = jwidget_find_name(widget, "pal"); JWidget grid2 = jwidget_find_name(widget, "grid2"); - int idxlen = ji_font_text_len(idx->font(), "Index=888"); + int idxlen = ji_font_text_len(idx->getFont(), "Index=888"); jwidget_set_min_size(idx, idxlen, 0); paledit_set_boxsize(pal, 4*guiscale()); @@ -417,12 +417,12 @@ static void colorselector_set_paledit_index(JWidget widget, int index, bool sele jwidget_disable(lock); } - jwidget_set_text(idx, buf); + idx->setText(buf); } static void select_tab_callback(JWidget tabs, void* data, int button) { - JWidget window = jwidget_get_window(tabs); + Frame* window = static_cast(tabs->getRoot()); Model* selected_model = (Model*)data; JWidget child; Model* m; @@ -451,7 +451,7 @@ static void select_tab_callback(JWidget tabs, void* data, int button) static bool slider_change_hook(JWidget widget, void* data) { - JWidget window = jwidget_get_window(widget); + Frame* window = static_cast(widget->getRoot()); ColorSelector* colorselector = colorselector_data(window); JWidget tabs = jwidget_find_name(window, "tabs"); JWidget pal = jwidget_find_name(window, "pal"); @@ -522,7 +522,7 @@ static bool slider_change_hook(JWidget widget, void* data) static bool button_mask_select_hook(JWidget widget, void* data) { - JWidget window = jwidget_get_window(widget); + Frame* window = static_cast(widget->getRoot()); colorselector_set_color(window, color_mask()); jwidget_emit_signal(window, SIGNAL_COLORSELECTOR_COLOR_CHANGED); return TRUE; @@ -530,7 +530,7 @@ static bool button_mask_select_hook(JWidget widget, void* data) static bool paledit_change_hook(JWidget widget, void* data) { - JWidget window = jwidget_get_window(widget); + Frame* window = static_cast(widget->getRoot()); bool array[256]; color_t color = colorselector_get_color(window); int i; @@ -549,7 +549,7 @@ static bool paledit_change_hook(JWidget widget, void* data) static bool lock_button_select_hook(JWidget widget, void* data) { - JWidget window = jwidget_get_window(widget); + Frame* window = static_cast(widget->getRoot()); ColorSelector* colorselector = colorselector_data(window); colorselector->palette_locked = !colorselector->palette_locked; diff --git a/src/widgets/colsel.h b/src/widgets/colsel.h index 996bf45c1..13eecfe67 100644 --- a/src/widgets/colsel.h +++ b/src/widgets/colsel.h @@ -23,10 +23,12 @@ #include "core/color.h" +class Frame; + // TODO use some JI_SIGNAL_USER #define SIGNAL_COLORSELECTOR_COLOR_CHANGED 0x10009 -JWidget colorselector_new(bool editable_palette); +Frame* colorselector_new(bool editable_palette); void colorselector_set_color(JWidget widget, color_t color); color_t colorselector_get_color(JWidget widget); diff --git a/src/widgets/colview.cpp b/src/widgets/colview.cpp index da1724b0d..ab0cc2ba1 100644 --- a/src/widgets/colview.cpp +++ b/src/widgets/colview.cpp @@ -43,7 +43,7 @@ static bool colorviewer_msg_proc(JWidget widget, JMessage msg); JWidget colorviewer_new(color_t color, int imgtype) { - JWidget widget = new jwidget(colorviewer_type()); + Widget* widget = new Widget(colorviewer_type()); ColorViewer *colorviewer = jnew(ColorViewer, 1); colorviewer->color = color; @@ -53,7 +53,7 @@ JWidget colorviewer_new(color_t color, int imgtype) colorviewer_msg_proc, colorviewer); jwidget_focusrest(widget, TRUE); jwidget_set_border(widget, 2, 2, 2, 2); - jwidget_set_align(widget, JI_CENTER | JI_MIDDLE); + widget->setAlign(JI_CENTER | JI_MIDDLE); return widget; } @@ -105,7 +105,7 @@ static bool colorviewer_msg_proc(JWidget widget, JMessage msg) break; case JM_REQSIZE: { - msg->reqsize.w = ji_font_text_len(widget->font(), "255,255,255,255"); + msg->reqsize.w = ji_font_text_len(widget->getFont(), "255,255,255,255"); msg->reqsize.h = jwidget_get_text_height(widget); 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, colorviewer->color, buf, sizeof(buf), FALSE); - widget->set_text_quiet(buf); + widget->setTextQuiet(buf); jwidget_get_texticon_info(widget, &box, &text, &icon, 0, 0, 0); jdraw_rectfill(&text, makecol(0, 0, 0)); - jdraw_text(widget->font(), widget->text(), text.x1, text.y1, + jdraw_text(widget->getFont(), widget->getText(), text.x1, text.y1, makecol(255, 255, 255), makecol(0, 0, 0), FALSE); jrect_free(rect); diff --git a/src/widgets/curvedit.cpp b/src/widgets/curvedit.cpp index a812bdb5b..f8d9dffcd 100644 --- a/src/widgets/curvedit.cpp +++ b/src/widgets/curvedit.cpp @@ -91,12 +91,12 @@ static int edit_node_manual(CurvePoint* point); JWidget curve_editor_new(Curve *curve, int x1, int y1, int x2, int y2) { - JWidget widget = new jwidget(curve_editor_type()); + JWidget widget = new Widget(curve_editor_type()); CurveEditor* curve_editor = jnew(CurveEditor, 1); jwidget_add_hook(widget, curve_editor_type(), curve_editor_msg_proc, curve_editor); - jwidget_focusrest(widget, TRUE); + jwidget_focusrest(widget, true); widget->border_width.l = widget->border_width.r = 1; widget->border_width.t = widget->border_width.b = 1; @@ -471,32 +471,24 @@ static CurvePoint* curve_editor_get_more_close_point(JWidget widget, static int edit_node_manual(CurvePoint* point) { - JWidget window, entry_x, entry_y, button_ok; + JWidget entry_x, entry_y, button_ok; CurvePoint point_copy = *point; - char buf[512]; int res; - window = load_widget("pntprop.jid", "point_properties"); - if (!window) { - jalert(_("Error<x); - jwidget_set_text(entry_x, buf); + entry_x->setTextf("%d", point->x); + entry_y->setTextf("%d", point->y); - sprintf(buf, "%d", point->y); - jwidget_set_text(entry_y, buf); + window->open_window_fg(); - jwindow_open_fg(window); - - if (jwindow_get_killer(window) == button_ok) { - point->x = strtod(jwidget_get_text(entry_x), NULL); - point->y = strtod(jwidget_get_text(entry_y), NULL); + if (window->get_killer() == button_ok) { + point->x = entry_x->getTextDouble(); + point->y = entry_y->getTextDouble(); res = TRUE; } else { @@ -505,6 +497,5 @@ static int edit_node_manual(CurvePoint* point) res = FALSE; } - jwidget_free(window); return res; } diff --git a/src/widgets/editor/editor.cpp b/src/widgets/editor/editor.cpp index d63195cd0..6d792a3b3 100644 --- a/src/widgets/editor/editor.cpp +++ b/src/widgets/editor/editor.cpp @@ -96,7 +96,7 @@ JWidget editor_view_new() JWidget editor_new() { - JWidget widget = new jwidget(editor_type()); + Widget* widget = new Widget(editor_type()); Editor* editor = jnew0(Editor, 1); editor->widget = widget; diff --git a/src/widgets/fileview.cpp b/src/widgets/fileview.cpp index 7319493ed..7f7cc76f5 100644 --- a/src/widgets/fileview.cpp +++ b/src/widgets/fileview.cpp @@ -91,7 +91,7 @@ static void monitor_free_thumbnail_generation(void *data); JWidget fileview_new(FileItem *start_folder, const jstring& exts) { - JWidget widget = new jwidget(fileview_type()); + Widget* widget = new Widget(fileview_type()); FileView* fileview = new FileView; if (!start_folder) @@ -268,10 +268,10 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg) x = widget->rc->x1+2; if (fileitem_is_folder(fi)) { - int icon_w = ji_font_text_len(widget->font(), "[+]"); - int icon_h = ji_font_get_size(widget->font()); + int icon_w = ji_font_text_len(widget->getFont(), "[+]"); + int icon_h = ji_font_get_size(widget->getFont()); - jdraw_text(widget->font(), + jdraw_text(widget->getFont(), "[+]", x, y+2, fgcolor, bgcolor, TRUE); @@ -298,7 +298,7 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg) } // item name - jdraw_text(widget->font(), + jdraw_text(widget->getFont(), fileitem_get_displayname(fi).c_str(), x, y+2, fgcolor, bgcolor, TRUE); @@ -309,9 +309,9 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg) widget->rc->x2-1, y+2+th+2-1, /* exclude where is the text located */ x, y+2, - x+ji_font_text_len(widget->font(), + x+ji_font_text_len(widget->getFont(), fileitem_get_displayname(fi).c_str())-1, - y+2+ji_font_get_size(widget->font())-1, + y+2+ji_font_get_size(widget->getFont())-1, /* fill with the background color */ bgcolor); @@ -580,10 +580,10 @@ static void fileview_get_fileitem_size(JWidget widget, FileItem *fi, int *w, int int len = 0; if (fileitem_is_folder(fi)) { - len += ji_font_text_len(widget->font(), "[+]")+2; + len += ji_font_text_len(widget->getFont(), "[+]")+2; } - len += ji_font_text_len(widget->font(), + len += ji_font_text_len(widget->getFont(), fileitem_get_displayname(fi).c_str()); /* if (!fileitem_is_folder(fi)) { */ diff --git a/src/widgets/groupbut.cpp b/src/widgets/groupbut.cpp index 30c6c68ba..18b7ae886 100644 --- a/src/widgets/groupbut.cpp +++ b/src/widgets/groupbut.cpp @@ -69,7 +69,7 @@ JWidget group_button_new(int w, int h, int first_selected, ...) radio->user_data[1] = (void *)c; usprintf(buf, "radio%d", c); - jwidget_set_name(radio, buf); + radio->setName(buf); if (icon >= 0) add_gfxicon_to_button(radio, icon, JI_CENTER | JI_MIDDLE); diff --git a/src/widgets/menuitem.cpp b/src/widgets/menuitem.cpp index 6bcf26e6d..e9b97378d 100644 --- a/src/widgets/menuitem.cpp +++ b/src/widgets/menuitem.cpp @@ -114,8 +114,8 @@ static bool menuitem_msg_proc(JWidget widget, JMessage msg) if (menuitem->m_params) menuitem->m_command->load_params(menuitem->m_params); - widget->enabled(menuitem->m_command->enabled(context)); - widget->selected(menuitem->m_command->checked(context)); + widget->setEnabled(menuitem->m_command->enabled(context)); + widget->setSelected(menuitem->m_command->checked(context)); } break; } diff --git a/src/widgets/paledit.cpp b/src/widgets/paledit.cpp index c283f5a64..778809422 100644 --- a/src/widgets/paledit.cpp +++ b/src/widgets/paledit.cpp @@ -59,7 +59,7 @@ static void paledit_update_scroll(JWidget widget, int color); JWidget paledit_new(Palette *palette, bool editable, int boxsize) { - JWidget widget = new jwidget(paledit_type()); + Widget* widget = new Widget(paledit_type()); PalEdit *paledit = jnew(PalEdit, 1); paledit->widget = widget; diff --git a/src/widgets/preview.cpp b/src/widgets/preview.cpp index f1b9111c1..286e509f0 100644 --- a/src/widgets/preview.cpp +++ b/src/widgets/preview.cpp @@ -42,7 +42,7 @@ static bool preview_msg_proc(JWidget widget, JMessage msg); */ JWidget preview_new(Effect *effect) { - JWidget widget = new jwidget(preview_type()); + Widget* widget = new Widget(preview_type()); Preview *preview = jnew(Preview, 1); preview->effect = effect; diff --git a/src/widgets/statebar.cpp b/src/widgets/statebar.cpp index 7284e1830..f662b1b46 100644 --- a/src/widgets/statebar.cpp +++ b/src/widgets/statebar.cpp @@ -69,8 +69,8 @@ JWidget statusbar_new() BUTTON_NEW((name), NULL, (action)); \ add_gfxicon_to_button((name), (icon), JI_CENTER | JI_MIDDLE); - JWidget widget = new jwidget(statusbar_type()); - StatusBar *statusbar = jnew(StatusBar, 1); + Widget* widget = new Widget(statusbar_type()); + StatusBar* statusbar = jnew(StatusBar, 1); jwidget_add_hook(widget, statusbar_type(), statusbar_msg_proc, statusbar); @@ -142,7 +142,7 @@ void statusbar_set_text(JWidget widget, int msecs, const char *format, ...) vsprintf(buf, format, ap); va_end(ap); - widget->text(buf); + widget->setText(buf); statusbar->timeout = ji_clock + msecs; jwidget_dirty(widget); } @@ -151,7 +151,7 @@ void statusbar_set_text(JWidget widget, int msecs, const char *format, ...) void statusbar_show_tip(JWidget widget, int msecs, const char *format, ...) { StatusBar *statusbar = statusbar_data(widget); - JWidget tipwindow = statusbar->tipwindow; + Frame* tipwindow = statusbar->tipwindow; char buf[256]; /* TODO warning buffer overflow */ va_list ap; int x, y; @@ -161,7 +161,7 @@ void statusbar_show_tip(JWidget widget, int msecs, const char *format, ...) va_end(ap); if (tipwindow == NULL) { - tipwindow = jtooltip_window_new(buf); + tipwindow = new TipWindow(buf); tipwindow->user_data[0] = (void *)jmanager_add_timer(tipwindow, msecs); tipwindow->user_data[1] = statusbar; jwidget_add_hook(tipwindow, -1, tipwindow_msg_proc, NULL); @@ -169,20 +169,20 @@ void statusbar_show_tip(JWidget widget, int msecs, const char *format, ...) statusbar->tipwindow = tipwindow; } else { - jwidget_set_text(tipwindow, buf); + tipwindow->setText(buf); jmanager_set_timer_interval((size_t)tipwindow->user_data[0], msecs); } if (jwidget_is_visible(tipwindow)) - jwindow_close(tipwindow, NULL); + tipwindow->closeWindow(NULL); - jwindow_open(tipwindow); - jwindow_remap(tipwindow); + tipwindow->open_window(); + tipwindow->remap_window(); x = widget->rc->x2 - jrect_w(tipwindow->rc); y = widget->rc->y1 - jrect_h(tipwindow->rc); - jwindow_position(tipwindow, x, y); + tipwindow->position_window(x, y); jmanager_start_timer((size_t)tipwindow->user_data[0]); } @@ -274,12 +274,12 @@ static bool statusbar_msg_proc(JWidget widget, JMessage msg) jrect_shrink(rc, 1); /* status bar text */ - if (widget->text()) { + if (widget->getText()) { jdraw_rectfill(rc, ji_color_face()); - textout_ex(ji_screen, widget->font(), widget->text(), + textout_ex(ji_screen, widget->getFont(), widget->getText(), rc->x1+2, - (widget->rc->y1+widget->rc->y2)/2-text_height(widget->font())/2, + (widget->rc->y1+widget->rc->y2)/2-text_height(widget->getFont())/2, ji_color_foreground(), -1); } @@ -327,9 +327,9 @@ static bool statusbar_msg_proc(JWidget widget, JMessage msg) ustrcpy(buf, "Sprite is Locked"); } - textout_right_ex(ji_screen, widget->font(), buf, + textout_right_ex(ji_screen, widget->getFont(), buf, rc->x2-2, - (widget->rc->y1+widget->rc->y2)/2-text_height(widget->font())/2, + (widget->rc->y1+widget->rc->y2)/2-text_height(widget->getFont())/2, ji_color_foreground(), -1); } @@ -341,11 +341,11 @@ static bool statusbar_msg_proc(JWidget widget, JMessage msg) if (!jwidget_has_child(widget, statusbar->commands_box)) { bool state = (UIContext::instance()->get_current_sprite() != NULL); - statusbar->b_first->enabled(state); - statusbar->b_prev->enabled(state); - statusbar->b_play->enabled(state); - statusbar->b_next->enabled(state); - statusbar->b_last->enabled(state); + statusbar->b_first->setEnabled(state); + statusbar->b_prev->setEnabled(state); + statusbar->b_play->setEnabled(state); + statusbar->b_next->setEnabled(state); + statusbar->b_last->setEnabled(state); update_from_layer(statusbar); @@ -381,7 +381,7 @@ static bool tipwindow_msg_proc(JWidget widget, JMessage msg) break; case JM_TIMER: - jwindow_close(widget, NULL); + static_cast(widget)->closeWindow(NULL); break; } @@ -437,13 +437,11 @@ static void update_from_layer(StatusBar *statusbar) /* layer button */ if (sprite && sprite->layer) { - char buf[512]; - usprintf(buf, "[%d] %s", sprite->frame, sprite->layer->get_name().c_str()); - jwidget_set_text(statusbar->b_layer, buf); + statusbar->b_layer->setTextf("[%d] %s", sprite->frame, sprite->layer->get_name().c_str()); jwidget_enable(statusbar->b_layer); } else { - jwidget_set_text(statusbar->b_layer, "Nothing"); + statusbar->b_layer->setText("Nothing"); jwidget_disable(statusbar->b_layer); } diff --git a/src/widgets/statebar.h b/src/widgets/statebar.h index e632a9c80..0babba332 100644 --- a/src/widgets/statebar.h +++ b/src/widgets/statebar.h @@ -23,33 +23,36 @@ #include "core/color.h" -typedef struct Progress -{ - JWidget statusbar; - float pos; -} Progress; +class Widget; +class Frame; -typedef struct StatusBar +struct Progress { - JWidget widget; + Widget* statusbar; + float pos; +}; + +struct StatusBar +{ + Widget* widget; int timeout; /* progress bar */ JList progress; /* box of main commands */ - JWidget commands_box; - JWidget b_layer; /* layer button */ - JWidget slider; /* opacity slider */ - JWidget b_first; /* go to first frame */ - JWidget b_prev; /* go to previous frame */ - JWidget b_play; /* play animation */ - JWidget b_next; /* go to next frame */ - JWidget b_last; /* go to last frame */ + Widget* commands_box; + Widget* b_layer; /* layer button */ + Widget* slider; /* opacity slider */ + Widget* b_first; /* go to first frame */ + Widget* b_prev; /* go to previous frame */ + Widget* b_play; /* play animation */ + Widget* b_next; /* go to next frame */ + Widget* b_last; /* go to last frame */ /* tip window */ - JWidget tipwindow; -} StatusBar; + Frame* tipwindow; +}; /* statusbar */ diff --git a/src/widgets/tabs.cpp b/src/widgets/tabs.cpp index e6cf067a4..690ff5443 100644 --- a/src/widgets/tabs.cpp +++ b/src/widgets/tabs.cpp @@ -30,7 +30,7 @@ #include "widgets/tabs.h" #define CALC_TAB_WIDTH(widget, tab) \ - (4 + text_length(widget->font(), tab->text.c_str()) + 4) + (4 + text_length(widget->getFont(), tab->text.c_str()) + 4) #define ARROW_W 12 @@ -80,7 +80,7 @@ static void draw_bevel_box(JRect box, int c1, int c2, int bottom); JWidget tabs_new(void (*select_callback)(JWidget tabs, void *data, int button)) { - JWidget widget = new jwidget(tabs_type()); + Widget* widget = new Widget(tabs_type()); Tabs *tabs = jnew0(Tabs, 1); tabs->list_of_tabs = jlist_new(); @@ -272,9 +272,9 @@ static bool tabs_msg_proc(JWidget widget, JMessage msg) else theme->draw_hline(box->x1, box->y2, box->x2-1, rect->y2-1, PART_TAB_BOTTOM_NORMAL); - jdraw_text(widget->font(), tab->text.c_str(), + jdraw_text(widget->getFont(), tab->text.c_str(), box->x1+4, - (box->y1+box->y2)/2-text_height(widget->font())/2+1, + (box->y1+box->y2)/2-text_height(widget->getFont())/2+1, text_color, face_color, false); } diff --git a/src/widgets/target.cpp b/src/widgets/target.cpp index b52ac1e47..c587c8dca 100644 --- a/src/widgets/target.cpp +++ b/src/widgets/target.cpp @@ -73,17 +73,17 @@ JWidget target_button_new(int imgtype, bool with_channels) g = check_button_new("G", 0, 0, 0, 0); b = check_button_new("B", 0, (imgtype == IMAGE_RGB) ? 0: 2, 0, 0); - jwidget_set_name(r, "r"); - jwidget_set_name(g, "g"); - jwidget_set_name(b, "b"); + r->setName("r"); + g->setName("g"); + b->setName("b"); if (imgtype == IMAGE_RGB) { a = check_button_new("A", 0, 2, 0, 0); - jwidget_set_name(a, "a"); + a->setName("a"); } else { index = check_button_new("Index", 0, 0, 0, 0); - jwidget_set_name(index, "i"); + index->setName("i"); } break; @@ -91,8 +91,8 @@ JWidget target_button_new(int imgtype, bool with_channels) k = check_button_new("K", 2, 0, 0, 0); a = check_button_new("A", 0, 2, 0, 0); - jwidget_set_name(k, "k"); - jwidget_set_name(a, "a"); + k->setName("k"); + a->setName("a"); break; } } diff --git a/src/widgets/toolbar.cpp b/src/widgets/toolbar.cpp index ec3049e57..b74a31052 100644 --- a/src/widgets/toolbar.cpp +++ b/src/widgets/toolbar.cpp @@ -98,7 +98,7 @@ JWidget toolbar_new() box->user_data[0] = tools; SkinneableTheme* theme = static_cast(box->theme); - box->bg_color(theme->get_panel_face_color()); + box->setBgColor(theme->get_panel_face_color()); return box; }