From f0f5bafd78c47ad7184ed37f80614108c22ad1ad Mon Sep 17 00:00:00 2001 From: David Capello Date: Sun, 25 Apr 2010 12:03:25 -0300 Subject: [PATCH] Refactored all jwidget_has_focus/mouse/capture functions to member functions. Added Widget::hasFocus/Mouse/Capture and Widget::hasMouseOver() members. Removed JI_HARDCAPTURE flag (it was used only by button widget). --- src/dialogs/aniedit.cpp | 20 +++--- src/jinete/jbase.h | 5 +- src/jinete/jbutton.cpp | 59 ++++++++++------ src/jinete/jcombobox.cpp | 6 +- src/jinete/jentry.cpp | 12 ++-- src/jinete/jfilesel.cpp | 2 +- src/jinete/jlistbox.cpp | 8 +-- src/jinete/jmanager.cpp | 22 +++--- src/jinete/jmenu.cpp | 2 +- src/jinete/jpanel.cpp | 8 +-- src/jinete/jslider.cpp | 12 ++-- src/jinete/jtextbox.cpp | 10 +-- src/jinete/jview.cpp | 6 +- src/jinete/jwidget.cpp | 97 +++++++++++---------------- src/jinete/jwidget.h | 21 +++--- src/jinete/jwindow.cpp | 8 +-- src/jinete/themes/jstandard_theme.cpp | 32 ++++----- src/modules/skinneable_theme.cpp | 64 +++++++++--------- src/widgets/colbar.cpp | 6 +- src/widgets/colbut.cpp | 19 ++---- src/widgets/colview.cpp | 4 +- src/widgets/curvedit.cpp | 8 +-- src/widgets/editor/click.cpp | 4 +- src/widgets/editor/editor.cpp | 18 ++--- src/widgets/editor/keys.cpp | 4 +- src/widgets/fileview.cpp | 10 +-- src/widgets/paledit.cpp | 6 +- src/widgets/toolbar.cpp | 2 +- 28 files changed, 231 insertions(+), 244 deletions(-) diff --git a/src/dialogs/aniedit.cpp b/src/dialogs/aniedit.cpp index 2d52113f5..2efc40a81 100644 --- a/src/dialogs/aniedit.cpp +++ b/src/dialogs/aniedit.cpp @@ -302,7 +302,7 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg) case JM_BUTTONPRESSED: if (msg->mouse.middle || anieditor->space_pressed) { - jwidget_hard_capture_mouse(widget); + widget->captureMouse(); anieditor->state = STATE_SCROLLING; return true; } @@ -317,7 +317,7 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg) /* do nothing */ break; case A_PART_SEPARATOR: - jwidget_hard_capture_mouse(widget); + widget->captureMouse(); anieditor->state = STATE_MOVING_SEPARATOR; break; case A_PART_HEADER_LAYER: @@ -330,7 +330,7 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg) sprite_writer->setCurrentFrame(anieditor->clk_frame); } jwidget_dirty(widget); /* TODO replace this by redrawing old current frame and new current frame */ - jwidget_hard_capture_mouse(widget); + widget->captureMouse(); anieditor->state = STATE_MOVING_FRAME; break; case A_PART_LAYER: { @@ -356,15 +356,15 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg) /* change the scroll to show the new selected cel */ anieditor_show_cel(widget, anieditor->clk_layer, sprite->getCurrentFrame()); - jwidget_hard_capture_mouse(widget); + widget->captureMouse(); anieditor->state = STATE_MOVING_LAYER; break; } case A_PART_LAYER_EYE_ICON: - jwidget_hard_capture_mouse(widget); + widget->captureMouse(); break; case A_PART_LAYER_LOCK_ICON: - jwidget_hard_capture_mouse(widget); + widget->captureMouse(); break; case A_PART_CEL: { const SpriteReader sprite((Sprite*)anieditor->sprite); @@ -397,7 +397,7 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg) anieditor_show_cel(widget, anieditor->clk_layer, sprite->getCurrentFrame()); /* capture the mouse (to move the cel) */ - jwidget_hard_capture_mouse(widget); + widget->captureMouse(); anieditor->state = STATE_MOVING_CEL; break; } @@ -419,7 +419,7 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg) int mx = msg->mouse.x - widget->rc->x1; int my = msg->mouse.y - widget->rc->y1; - if (jwidget_has_capture(widget)) { + if (widget->hasCapture()) { if (anieditor->state == STATE_SCROLLING) { anieditor_set_scroll(widget, anieditor->scroll_x+jmouse_x(1)-jmouse_x(0), @@ -504,8 +504,8 @@ static bool anieditor_msg_proc(JWidget widget, JMessage msg) } case JM_BUTTONRELEASED: - if (jwidget_has_capture(widget)) { - jwidget_release_mouse(widget); + if (widget->hasCapture()) { + widget->releaseMouse(); if (anieditor->state == STATE_SCROLLING) { anieditor->state = STATE_STANDBY; diff --git a/src/jinete/jbase.h b/src/jinete/jbase.h index 3a6c1239e..f297b6371 100644 --- a/src/jinete/jbase.h +++ b/src/jinete/jbase.h @@ -100,9 +100,8 @@ class Frame; #define JI_MAGNETIC 0x0080 /* attract the focus */ #define JI_EXPANSIVE 0x0100 /* is expansive (want more space) */ #define JI_DECORATIVE 0x0200 /* to decorate windows */ -#define JI_HARDCAPTURE 0x0400 /* only windows use hard capture */ -#define JI_INITIALIZED 0x0800 /* the widget was already initialized by a theme */ -#define JI_NOTEXT 0x1000 /* the widget does not have text */ +#define JI_INITIALIZED 0x0400 /* the widget was already initialized by a theme */ +#define JI_NOTEXT 0x0800 /* the widget does not have text */ /* widget types */ enum { diff --git a/src/jinete/jbutton.cpp b/src/jinete/jbutton.cpp index 19885e714..ec96319e3 100644 --- a/src/jinete/jbutton.cpp +++ b/src/jinete/jbutton.cpp @@ -58,6 +58,7 @@ typedef struct ButtonCommand typedef struct Button { /* generic */ + bool pressed_status; int draw_type; BITMAP *icon; int icon_align; @@ -251,10 +252,11 @@ void jradio_deselect_group(JWidget widget) static bool button_msg_proc(JWidget widget, JMessage msg) { + Button* button = reinterpret_cast(jwidget_get_data(widget, widget->type)); + switch (msg->type) { case JM_DESTROY: { - Button* button = reinterpret_cast(jwidget_get_data(widget, widget->type)); JLink link; JI_LIST_FOR_EACH(button->commands, link) @@ -270,7 +272,6 @@ static bool button_msg_proc(JWidget widget, JMessage msg) return true; case JM_DRAW: { - Button* button = reinterpret_cast(jwidget_get_data(widget, widget->type)); switch (button->draw_type) { case JI_BUTTON: widget->theme->draw_button(widget, &msg->draw.rect); break; case JI_CHECK: widget->theme->draw_check(widget, &msg->draw.rect); break; @@ -312,7 +313,7 @@ static bool button_msg_proc(JWidget widget, JMessage msg) /* for JI_BUTTON */ if (widget->type == JI_BUTTON) { /* has focus and press enter/space */ - if (jwidget_has_focus(widget)) { + if (widget->hasFocus()) { if ((msg->key.scancode == KEY_ENTER) || (msg->key.scancode == KEY_ENTER_PAD) || (msg->key.scancode == KEY_SPACE)) { @@ -344,7 +345,7 @@ static bool button_msg_proc(JWidget widget, JMessage msg) else { /* if the widget has the focus and the user press space or if the user press Alt+the underscored letter of the button */ - if ((jwidget_has_focus(widget) && + if ((widget->hasFocus() && (msg->key.scancode == KEY_SPACE)) || ((msg->any.shifts & KB_ALT_FLAG) && (jwidget_check_underscored(widget, msg->key.scancode)))) { @@ -388,7 +389,9 @@ static bool button_msg_proc(JWidget widget, JMessage msg) case JI_BUTTON: if (jwidget_is_enabled(widget)) { jwidget_select(widget); - jwidget_capture_mouse(widget); + + button->pressed_status = jwidget_is_selected(widget); + widget->captureMouse(); } return true; @@ -399,7 +402,8 @@ static bool button_msg_proc(JWidget widget, JMessage msg) else jwidget_select(widget); - jwidget_capture_mouse(widget); + button->pressed_status = jwidget_is_selected(widget); + widget->captureMouse(); } return true; @@ -410,7 +414,8 @@ static bool button_msg_proc(JWidget widget, JMessage msg) jwidget_select(widget); jwidget_signal_on(widget); - jwidget_capture_mouse(widget); + button->pressed_status = jwidget_is_selected(widget); + widget->captureMouse(); } } return true; @@ -418,10 +423,10 @@ static bool button_msg_proc(JWidget widget, JMessage msg) break; case JM_BUTTONRELEASED: - if (jwidget_has_capture(widget)) { - jwidget_release_mouse(widget); + if (widget->hasCapture()) { + widget->releaseMouse(); - if (jwidget_has_mouse(widget)) { + if (widget->hasMouseOver()) { switch (widget->type) { case JI_BUTTON: @@ -444,20 +449,30 @@ static bool button_msg_proc(JWidget widget, JMessage msg) } break; + case JM_MOTION: + if (jwidget_is_enabled(widget) && widget->hasCapture()) { + bool hasMouse = widget->hasMouseOver(); + + // Switch state when the mouse go out + if (( hasMouse && jwidget_is_selected(widget) != button->pressed_status) || + (!hasMouse && jwidget_is_selected(widget) == button->pressed_status)) { + jwidget_signal_off(widget); + + if (hasMouse) { + jwidget_set_selected(widget, button->pressed_status); + } + else { + jwidget_set_selected(widget, !button->pressed_status); + } + + jwidget_signal_on(widget); + } + } + break; + case JM_MOUSEENTER: case JM_MOUSELEAVE: - if (jwidget_is_enabled(widget) && jwidget_has_capture(widget)) { - jwidget_signal_off(widget); - - if (jwidget_is_selected(widget)) - jwidget_deselect(widget); - else - jwidget_select(widget); - - jwidget_signal_on(widget); - } - - /* TODO theme stuff */ + // TODO theme stuff if (jwidget_is_enabled(widget)) jwidget_dirty(widget); break; diff --git a/src/jinete/jcombobox.cpp b/src/jinete/jcombobox.cpp index 1e94ff199..d90ef3c7a 100644 --- a/src/jinete/jcombobox.cpp +++ b/src/jinete/jcombobox.cpp @@ -382,7 +382,7 @@ static bool combobox_msg_proc(JWidget widget, JMessage msg) case JM_BUTTONPRESSED: if (combobox->window != NULL) { - if (!jwidget_has_mouse(jwidget_get_view(combobox->listbox))) { + if (!jwidget_get_view(combobox->listbox)->hasMouse()) { combobox_close_window(widget); return true; } @@ -401,7 +401,7 @@ static bool combobox_entry_msg_proc(JWidget widget, JMessage msg) switch (msg->type) { case JM_KEYPRESSED: - if (jwidget_has_focus(widget)) { + if (widget->hasFocus()) { if (!jcombobox_is_editable(combo_widget)) { if (msg->key.scancode == KEY_SPACE || msg->key.scancode == KEY_ENTER || @@ -498,7 +498,7 @@ static bool combobox_listbox_msg_proc(JWidget widget, JMessage msg) /* } */ case JM_KEYPRESSED: - if (jwidget_has_focus(widget)) { + if (widget->hasFocus()) { if (msg->key.scancode == KEY_SPACE || msg->key.scancode == KEY_ENTER || msg->key.scancode == KEY_ENTER_PAD) { diff --git a/src/jinete/jentry.cpp b/src/jinete/jentry.cpp index 8dd017b84..d520e49f5 100644 --- a/src/jinete/jentry.cpp +++ b/src/jinete/jentry.cpp @@ -269,7 +269,7 @@ static bool entry_msg_proc(JWidget widget, JMessage msg) return true; case JM_TIMER: - if (jwidget_has_focus(widget) && + if (widget->hasFocus() && msg->timer.timer_id == entry->timer_id) { // blinking cursor entry->state = entry->state ? false: true; @@ -297,7 +297,7 @@ static bool entry_msg_proc(JWidget widget, JMessage msg) break; case JM_KEYPRESSED: - if (jwidget_has_focus(widget) && !jentry_is_readonly(widget)) { + if (widget->hasFocus() && !jentry_is_readonly(widget)) { // Command to execute EntryCmd::Type cmd = EntryCmd::NoOp; @@ -371,10 +371,10 @@ static bool entry_msg_proc(JWidget widget, JMessage msg) break; case JM_BUTTONPRESSED: - jwidget_capture_mouse(widget); + widget->captureMouse(); case JM_MOTION: - if (jwidget_has_capture(widget)) { + if (widget->hasCapture()) { const char *text = widget->getText(); bool move, dirty; int c, x; @@ -443,8 +443,8 @@ static bool entry_msg_proc(JWidget widget, JMessage msg) break; case JM_BUTTONRELEASED: - if (jwidget_has_capture(widget)) - jwidget_release_mouse(widget); + if (widget->hasCapture()) + widget->releaseMouse(); return true; case JM_DOUBLECLICK: diff --git a/src/jinete/jfilesel.cpp b/src/jinete/jfilesel.cpp index da9bd9787..628012ca5 100644 --- a/src/jinete/jfilesel.cpp +++ b/src/jinete/jfilesel.cpp @@ -377,7 +377,7 @@ static bool filesel_msg_proc(JWidget widget, JMessage msg) break; case JM_KEYPRESSED: - if ((jwidget_has_focus (widget)) && + if ((widget->hasFocus()) && ((msg->key.scancode == KEY_ENTER) || (msg->key.scancode == KEY_ENTER_PAD))) { if (enter_to_path_in_entry()) { diff --git a/src/jinete/jlistbox.cpp b/src/jinete/jlistbox.cpp index 7fedc0540..30876934b 100644 --- a/src/jinete/jlistbox.cpp +++ b/src/jinete/jlistbox.cpp @@ -189,10 +189,10 @@ static bool listbox_msg_proc(JWidget widget, JMessage msg) break; case JM_BUTTONPRESSED: - jwidget_capture_mouse(widget); + widget->captureMouse(); case JM_MOTION: - if (jwidget_has_capture(widget)) { + if (widget->hasCapture()) { int select = jlistbox_get_selected_index(widget); JWidget view = jwidget_get_view(widget); bool pick_item = true; @@ -235,7 +235,7 @@ static bool listbox_msg_proc(JWidget widget, JMessage msg) break; case JM_BUTTONRELEASED: - jwidget_release_mouse(widget); + widget->releaseMouse(); break; case JM_WHEEL: { @@ -254,7 +254,7 @@ static bool listbox_msg_proc(JWidget widget, JMessage msg) } case JM_KEYPRESSED: - if (jwidget_has_focus(widget) && !jlist_empty(widget->children)) { + if (widget->hasFocus() && !jlist_empty(widget->children)) { int select = jlistbox_get_selected_index(widget); JWidget view = jwidget_get_view(widget); int bottom = MAX(0, jlist_length(widget->children)-1); diff --git a/src/jinete/jmanager.cpp b/src/jinete/jmanager.cpp index 84c73b9fa..3491248f7 100644 --- a/src/jinete/jmanager.cpp +++ b/src/jinete/jmanager.cpp @@ -305,7 +305,7 @@ bool jmanager_generate_messages(JWidget manager) /* 1) get the magnetic widget */ magnet = find_magnetic_widget(window->getRoot()); /* 2) if magnetic widget exists and it doesn't have the focus */ - if (magnet && !jwidget_has_focus(magnet)) + if (magnet && !magnet->hasFocus()) jmanager_set_focus(magnet); /* 3) if not, put the focus in the first child */ else @@ -349,7 +349,7 @@ bool jmanager_generate_messages(JWidget manager) /* reset double click status */ double_click_level = DOUBLE_CLICK_NONE; - if (capture_widget && capture_widget->flags & JI_HARDCAPTURE) + if (capture_widget) dst = capture_widget; else dst = mouse_widget; @@ -756,7 +756,7 @@ void jmanager_set_focus(JWidget widget) break; } - if (jwidget_has_focus(reinterpret_cast(link->data))) { + if (reinterpret_cast(link->data)->hasFocus()) { ((JWidget)link->data)->flags &= ~JI_HASFOCUS; jmessage_add_dest(msg, reinterpret_cast(link->data)); } @@ -797,8 +797,7 @@ void jmanager_set_focus(JWidget widget) void jmanager_set_mouse(JWidget widget) { - if ((mouse_widget != widget) - && (!capture_widget || !(capture_widget->flags & JI_HARDCAPTURE))) { + if ((mouse_widget != widget) && (!capture_widget)) { JList widget_parents = NULL; JWidget common_parent = NULL; JLink link, link2; @@ -827,7 +826,7 @@ void jmanager_set_mouse(JWidget widget) break; } - if (jwidget_has_mouse(reinterpret_cast(link->data))) { + if (reinterpret_cast(link->data)->hasMouse()) { ((JWidget)link->data)->flags &= ~JI_HASMOUSE; jmessage_add_dest(msg, reinterpret_cast(link->data)); } @@ -875,7 +874,7 @@ void jmanager_attract_focus(JWidget 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)) + if (magnet && !magnet->hasFocus()) jmanager_set_focus(magnet); } @@ -910,13 +909,13 @@ void jmanager_free_capture() void jmanager_free_widget(JWidget widget) { /* break any relationship with the GUI manager */ - if (jwidget_has_capture(widget)) + if (widget->hasCapture()) jmanager_free_capture(); - if (jwidget_has_mouse(widget)) + if (widget->hasMouse()) jmanager_free_mouse(); - if (jwidget_has_focus(widget) || (widget == focus_widget)) + if (widget->hasFocus() || (widget == focus_widget)) jmanager_free_focus(); } @@ -1357,8 +1356,7 @@ static void generate_setcursor_message() JWidget dst; JMessage msg; - if (capture_widget && - capture_widget->flags & JI_HARDCAPTURE) + if (capture_widget) dst = capture_widget; else dst = mouse_widget; diff --git a/src/jinete/jmenu.cpp b/src/jinete/jmenu.cpp index 2a85c7794..2a5bd5976 100644 --- a/src/jinete/jmenu.cpp +++ b/src/jinete/jmenu.cpp @@ -607,7 +607,7 @@ static bool menubox_msg_proc(JWidget widget, JMessage msg) #endif /* highlight movement with keyboard */ - if (jwidget_has_focus(widget)) { + if (widget->hasFocus()) { JWidget highlight = get_highlight(menu); JWidget child; JWidget child_with_submenu_opened = NULL; diff --git a/src/jinete/jpanel.cpp b/src/jinete/jpanel.cpp index 3d027c1b0..90e7464f6 100644 --- a/src/jinete/jpanel.cpp +++ b/src/jinete/jpanel.cpp @@ -139,14 +139,14 @@ static bool panel_msg_proc(JWidget widget, JMessage msg) if (!click_bar) break; - jwidget_hard_capture_mouse(widget); + widget->captureMouse(); /* Continue with motion message... */ } else break; case JM_MOTION: - if (jwidget_has_capture(widget)) { + if (widget->hasCapture()) { Panel* panel = reinterpret_cast(jwidget_get_data(widget, JI_PANEL)); if (widget->getAlign() & JI_HORIZONTAL) { @@ -167,8 +167,8 @@ static bool panel_msg_proc(JWidget widget, JMessage msg) break; case JM_BUTTONRELEASED: - if (jwidget_has_capture(widget)) { - jwidget_release_mouse(widget); + if (widget->hasCapture()) { + widget->releaseMouse(); return true; } break; diff --git a/src/jinete/jslider.cpp b/src/jinete/jslider.cpp index c5efc410a..5177d0154 100644 --- a/src/jinete/jslider.cpp +++ b/src/jinete/jslider.cpp @@ -141,7 +141,7 @@ static bool slider_msg_proc(JWidget widget, JMessage msg) return true; jwidget_select(widget); - jwidget_hard_capture_mouse(widget); + widget->captureMouse(); slider_press_x = msg->mouse.x; slider_press_value = slider->value; @@ -152,7 +152,7 @@ static bool slider_msg_proc(JWidget widget, JMessage msg) /* continue to JM_MOTION */ case JM_MOTION: - if (jwidget_has_capture(widget)) { + if (widget->hasCapture()) { int value, accuracy, range; JRect rc = jwidget_get_child_rect(widget); @@ -201,9 +201,9 @@ static bool slider_msg_proc(JWidget widget, JMessage msg) break; case JM_BUTTONRELEASED: - if (jwidget_has_capture(widget)) { + if (widget->hasCapture()) { jwidget_deselect(widget); - jwidget_release_mouse(widget); + widget->releaseMouse(); slider_setcursor(widget); } break; @@ -227,7 +227,7 @@ static bool slider_msg_proc(JWidget widget, JMessage msg) break; case JM_KEYPRESSED: - if (jwidget_has_focus (widget)) { + if (widget->hasFocus()) { int min = slider->min; int max = slider->max; int value = slider->value; @@ -295,7 +295,7 @@ static void slider_request_size(JWidget widget, int *w, int *h) static void slider_setcursor(JWidget widget) { - if (jwidget_has_capture(widget)) { + if (widget->hasCapture()) { if (slider_press_left) jmouse_set_cursor(JI_CURSOR_NORMAL); else diff --git a/src/jinete/jtextbox.cpp b/src/jinete/jtextbox.cpp index 98609ba3e..50b34255c 100644 --- a/src/jinete/jtextbox.cpp +++ b/src/jinete/jtextbox.cpp @@ -82,7 +82,7 @@ static bool textbox_msg_proc(JWidget widget, JMessage msg) break; case JM_KEYPRESSED: - if (jwidget_has_focus(widget)) { + if (widget->hasFocus()) { JWidget view = jwidget_get_view(widget); if (view) { JRect vp = jview_get_viewport_position(view); @@ -141,7 +141,7 @@ static bool textbox_msg_proc(JWidget widget, JMessage msg) case JM_BUTTONPRESSED: { JWidget view = jwidget_get_view(widget); if (view) { - jwidget_hard_capture_mouse(widget); + widget->captureMouse(); jmouse_set_cursor(JI_CURSOR_SCROLL); return true; } @@ -150,7 +150,7 @@ static bool textbox_msg_proc(JWidget widget, JMessage msg) case JM_MOTION: { JWidget view = jwidget_get_view(widget); - if (view && jwidget_has_capture(widget)) { + if (view && widget->hasCapture()) { JRect vp = jview_get_viewport_position(view); int scroll_x, scroll_y; @@ -167,8 +167,8 @@ static bool textbox_msg_proc(JWidget widget, JMessage msg) case JM_BUTTONRELEASED: { JWidget view = jwidget_get_view(widget); - if (view && jwidget_has_capture(widget)) { - jwidget_release_mouse(widget); + if (view && widget->hasCapture()) { + widget->releaseMouse(); jmouse_set_cursor(JI_CURSOR_NORMAL); return true; } diff --git a/src/jinete/jview.cpp b/src/jinete/jview.cpp index ef919cb51..66c1352df 100644 --- a/src/jinete/jview.cpp +++ b/src/jinete/jview.cpp @@ -561,13 +561,13 @@ static bool scrollbar_msg_proc(JWidget widget, JMessage msg) return ret; jwidget_select(widget); - jwidget_hard_capture_mouse(widget); + widget->captureMouse(); // continue to JM_MOTION handler... } case JM_MOTION: - if (jwidget_has_capture(widget)) { + if (widget->hasCapture()) { View* view = reinterpret_cast(jwidget_get_data(widget->parent, JI_VIEW)); int pos, len, bar_size, viewport_size; int old_pos; @@ -601,7 +601,7 @@ static bool scrollbar_msg_proc(JWidget widget, JMessage msg) case JM_BUTTONRELEASED: jwidget_deselect(widget); - jwidget_release_mouse(widget); + widget->releaseMouse(); break; case JM_MOUSEENTER: diff --git a/src/jinete/jwidget.cpp b/src/jinete/jwidget.cpp index 7433c690f..f9e877e38 100644 --- a/src/jinete/jwidget.cpp +++ b/src/jinete/jwidget.cpp @@ -540,30 +540,6 @@ bool jwidget_is_deselected(JWidget widget) return !(jwidget_is_selected(widget)); } -/**********************************************************************/ -/* properties with manager */ - -bool jwidget_has_focus(JWidget widget) -{ - assert_valid_widget(widget); - - return (widget->flags & JI_HASFOCUS) ? true: false; -} - -bool jwidget_has_mouse(JWidget widget) -{ - assert_valid_widget(widget); - - return (widget->flags & JI_HASMOUSE) ? true: false; -} - -bool jwidget_has_capture(JWidget widget) -{ - assert_valid_widget(widget); - - return (widget->flags & JI_HASCAPTURE) ? true: false; -} - /**********************************************************************/ /* children handle */ @@ -1350,15 +1326,6 @@ bool jwidget_send_message(JWidget widget, JMessage 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; @@ -1388,40 +1355,33 @@ void Widget::closeWindow() frame->closeWindow(this); } +// =============================================================== +// FOCUS & MOUSE +// =============================================================== + +void Widget::requestFocus() +{ + jmanager_set_focus(this); +} + +void Widget::releaseFocus() +{ + if (hasFocus()) + jmanager_free_focus(); +} + /** - * Captures the mouse to send the future JM_BUTTONRELEASED messsage to - * the specified widget. There are messages like JM_MOTION and - * JM_SETCURSOR that are sent normally to the widget with the mouse - * (and not with the "soft" capture). - * - * @see jwidget_hard_capture_mouse + * Captures the mouse to send all the future mouse messsages to the + * specified widget (included the JM_MOTION and JM_SETCURSOR). */ void Widget::captureMouse() { if (!jmanager_get_capture()) { jmanager_set_capture(this); - if (jmanager_get_capture() == this) - this->flags &= ~JI_HARDCAPTURE; - } -} - -/** - * Captures the mouse to send all the future mouse messsages to the - * specified widget (included the JM_MOTION and JM_SETCURSOR). - * - * @see jwidget_capture_mouse - */ -void Widget::hardCaptureMouse() -{ - if (!jmanager_get_capture()) { - jmanager_set_capture(this); #ifdef ALLEGRO_WINDOWS SetCapture(win_get_window()); #endif - - if (jmanager_get_capture() == this) - this->flags |= JI_HARDCAPTURE; } } @@ -1432,14 +1392,33 @@ void Widget::releaseMouse() { if (jmanager_get_capture() == this) { jmanager_free_capture(); + #ifdef ALLEGRO_WINDOWS ::ReleaseCapture(); // Win32 API #endif - - this->flags &= ~JI_HARDCAPTURE; } } +bool Widget::hasFocus() +{ + return (this->flags & JI_HASFOCUS) ? true: false; +} + +bool Widget::hasMouse() +{ + return (this->flags & JI_HASMOUSE) ? true: false; +} + +bool Widget::hasMouseOver() +{ + return (this == this->pick(jmouse_x(0), jmouse_y(0))); +} + +bool Widget::hasCapture() +{ + return (this->flags & JI_HASCAPTURE) ? true: false; +} + /**********************************************************************/ /* miscellaneous */ diff --git a/src/jinete/jwidget.h b/src/jinete/jwidget.h index 974d9d7d1..6f8eb577c 100644 --- a/src/jinete/jwidget.h +++ b/src/jinete/jwidget.h @@ -96,12 +96,6 @@ bool jwidget_is_disabled(JWidget widget); bool jwidget_is_selected(JWidget widget); bool jwidget_is_deselected(JWidget widget); -/* properties with manager */ - -bool jwidget_has_focus(JWidget widget); -bool jwidget_has_mouse(JWidget widget); -bool jwidget_has_capture(JWidget widget); - /* children handle */ void jwidget_add_child(JWidget widget, JWidget child); @@ -163,9 +157,6 @@ bool jwidget_emit_signal(JWidget widget, int signal_num); bool jwidget_send_message(JWidget widget, JMessage msg); void jwidget_close_window(JWidget widget); -void jwidget_capture_mouse(JWidget widget); -void jwidget_hard_capture_mouse(JWidget widget); -void jwidget_release_mouse(JWidget widget); /* miscellaneous */ @@ -316,9 +307,19 @@ public: bool sendMessage(JMessage msg); void closeWindow(); + + // =============================================================== + // FOCUS & MOUSE + // =============================================================== + + void requestFocus(); + void releaseFocus(); void captureMouse(); - void hardCaptureMouse(); void releaseMouse(); + bool hasFocus(); + bool hasMouse(); + bool hasMouseOver(); + bool hasCapture(); protected: virtual bool msg_proc(JMessage msg); diff --git a/src/jinete/jwindow.cpp b/src/jinete/jwindow.cpp index 2c869de9e..deed02071 100644 --- a/src/jinete/jwindow.cpp +++ b/src/jinete/jwindow.cpp @@ -280,7 +280,7 @@ bool Frame::msg_proc(JMessage msg) else jrect_copy(click_pos, this->rc); - jwidget_hard_capture_mouse(this); + captureMouse(); return true; } else @@ -288,8 +288,8 @@ bool Frame::msg_proc(JMessage msg) } case JM_BUTTONRELEASED: - if (jwidget_has_capture(this)) { - jwidget_release_mouse(this); + if (hasCapture()) { + releaseMouse(); jmouse_set_cursor(JI_CURSOR_NORMAL); if (click_pos != NULL) { @@ -307,7 +307,7 @@ bool Frame::msg_proc(JMessage msg) break; /* does it have the mouse captured? */ - if (jwidget_has_capture(this)) { + if (hasCapture()) { /* reposition/resize */ if (window_action == WINDOW_MOVE) { int x = click_pos->x1 + (msg->mouse.x - press_x); diff --git a/src/jinete/themes/jstandard_theme.cpp b/src/jinete/themes/jstandard_theme.cpp index f4dfa703f..080c7e105 100644 --- a/src/jinete/themes/jstandard_theme.cpp +++ b/src/jinete/themes/jstandard_theme.cpp @@ -498,7 +498,7 @@ void jstandard_theme::draw_button(JWidget widget, JRect clip) icon_bmp ? icon_bmp->h : 0); /* with mouse */ - if (jwidget_is_enabled(widget) && jwidget_has_mouse(widget)) + if (jwidget_is_enabled(widget) && widget->hasMouseOver()) bg = COLOR_HOTFACE; /* without mouse */ else @@ -533,7 +533,7 @@ void jstandard_theme::draw_button(JWidget widget, JRect clip) jbutton_get_bevel(widget, bevel); /* 1st border */ - if (jwidget_has_focus(widget)) + if (widget->hasFocus()) draw_bevel_box(x1, y1, x2, y2, COLOR_FOREGROUND, COLOR_FOREGROUND, bevel); else { @@ -545,7 +545,7 @@ void jstandard_theme::draw_button(JWidget widget, JRect clip) /* 2nd border */ x1++, y1++, x2--, y2--; - if (jwidget_has_focus(widget)) + if (widget->hasFocus()) draw_bevel_box(x1, y1, x2, y2, c1, c2, bevel); else draw_bevel_box(x1, y1, x2, y2, bg, bg, bevel); @@ -609,11 +609,11 @@ void jstandard_theme::draw_check(JWidget widget, JRect clip) jdraw_rectfill(widget->rc, bg = get_bg_color(widget)); /* mouse */ - if (jwidget_is_enabled(widget) && jwidget_has_mouse(widget)) + if (jwidget_is_enabled(widget) && widget->hasMouseOver()) jdraw_rectfill(&box, bg = COLOR_HOTFACE); /* focus */ - if (jwidget_has_focus(widget)) { + if (widget->hasFocus()) { jrect_stretch(&box, 1); jdraw_rect(&box, COLOR_FOREGROUND); } @@ -655,7 +655,7 @@ void jstandard_theme::draw_entry(JWidget widget, JRect clip) /* 2nd border */ x1++, y1++, x2--, y2--; - if (jwidget_has_focus (widget)) + if (widget->hasFocus()) rect(ji_screen, x1, y1, x2, y2, COLOR_FOREGROUND); else rect(ji_screen, x1, y1, x2, y2, get_bg_color(widget)); @@ -677,7 +677,7 @@ void jstandard_theme::draw_entry(JWidget widget, JRect clip) /* selected */ if ((c >= selbeg) && (c <= selend)) { - if (jwidget_has_focus(widget)) + if (widget->hasFocus()) bg = COLOR_SELECTED; else bg = COLOR_DISABLED; @@ -701,13 +701,13 @@ void jstandard_theme::draw_entry(JWidget widget, JRect clip) x += w; /* cursor */ - if ((c == cursor) && (state) && (jwidget_has_focus (widget))) + if ((c == cursor) && (state) && (widget->hasFocus())) draw_entry_cursor(widget, cursor_x, y); } /* draw the cursor if it is next of the last character */ if ((c == cursor) && (state) && - (jwidget_has_focus(widget)) && + (widget->hasFocus()) && (jwidget_is_enabled(widget))) draw_entry_cursor(widget, x, y); } @@ -800,7 +800,7 @@ void jstandard_theme::draw_menuitem(JWidget widget, JRect clip) bg = COLOR_SELECTED; fg = COLOR_BACKGROUND; } - else if (jwidget_has_mouse(widget)) { + else if (widget->hasMouse()) { bg = COLOR_HOTFACE; fg = COLOR_FOREGROUND; } @@ -960,11 +960,11 @@ void jstandard_theme::draw_radio(JWidget widget, JRect clip) jdraw_rectfill(widget->rc, bg); /* mouse */ - if (jwidget_is_enabled(widget) && jwidget_has_mouse(widget)) + if (jwidget_is_enabled(widget) && widget->hasMouse()) jdraw_rectfill(&box, bg = COLOR_HOTFACE); /* focus */ - if (jwidget_has_focus(widget)) + if (widget->hasFocus()) rect(ji_screen, box.x1-1, box.y1-1, box.x2, box.y2, COLOR_FOREGROUND); @@ -1056,7 +1056,7 @@ void jstandard_theme::draw_slider(JWidget widget, JRect clip) y2 = widget->rc->y2 - 1; /* with mouse */ - if (jwidget_is_enabled(widget) && jwidget_has_mouse(widget)) + if (jwidget_is_enabled(widget) && widget->hasMouse()) bg = COLOR_HOTFACE; /* without mouse */ else @@ -1068,7 +1068,7 @@ void jstandard_theme::draw_slider(JWidget widget, JRect clip) /* 2nd border */ x1++, y1++, x2--, y2--; - if (jwidget_has_focus (widget)) + if (widget->hasFocus()) rect(ji_screen, x1, y1, x2, y2, COLOR_FOREGROUND); else rect(ji_screen, x1, y1, x2, y2, bg); @@ -1157,7 +1157,7 @@ void jstandard_theme::draw_view(JWidget widget, JRect clip) { JRect pos = jwidget_get_rect(widget); - if (jwidget_has_focus(widget)) { + if (widget->hasFocus()) { /* 1st border */ jdraw_rectedge(pos, COLOR_DISABLED, COLOR_BACKGROUND); @@ -1230,7 +1230,7 @@ void jstandard_theme::draw_view_scrollbar(JWidget widget, JRect clip) /* bar-block background */ u1++, v1++, u2--, v2--; - if (jwidget_is_enabled(widget) && jwidget_has_mouse(widget)) + if (jwidget_is_enabled(widget) && widget->hasMouse()) rectfill(ji_screen, u1, v1, u2, v2, COLOR_HOTFACE); else rectfill(ji_screen, u1, v1, u2, v2, get_bg_color(widget)); diff --git a/src/modules/skinneable_theme.cpp b/src/modules/skinneable_theme.cpp index 8df6a6bfe..851bbd1cc 100644 --- a/src/modules/skinneable_theme.cpp +++ b/src/modules/skinneable_theme.cpp @@ -632,7 +632,7 @@ void SkinneableTheme::draw_button(JWidget widget, JRect clip) PART_BUTTON_SELECTED_NW; } // with mouse - else if (jwidget_is_enabled(widget) && jwidget_has_mouse(widget)) { + else if (jwidget_is_enabled(widget) && widget->hasMouseOver()) { fg = get_button_hot_text_color(); bg = get_button_hot_face_color(); part_nw = isMiniLook ? PART_TOOLBUTTON_HOT_NW: @@ -643,7 +643,7 @@ void SkinneableTheme::draw_button(JWidget widget, JRect clip) fg = get_button_normal_text_color(); bg = get_button_normal_face_color(); - if (jwidget_has_focus(widget)) + if (widget->hasFocus()) part_nw = isMiniLook ? PART_TOOLBUTTON_HOT_NW: PART_BUTTON_FOCUSED_NW; else @@ -711,9 +711,9 @@ void SkinneableTheme::draw_check(JWidget widget, JRect clip) // mouse if (jwidget_is_enabled(widget)) { - if (jwidget_has_mouse(widget)) + if (widget->hasMouseOver()) jdraw_rectfill(widget->rc, bg = get_check_hot_face_color()); - else if (jwidget_has_focus(widget)) + else if (widget->hasFocus()) jdraw_rectfill(widget->rc, bg = get_check_focus_face_color()); } @@ -728,7 +728,7 @@ void SkinneableTheme::draw_check(JWidget widget, JRect clip) icon.x1, icon.y1); // draw focus - if (jwidget_has_focus(widget)) { + if (widget->hasFocus()) { draw_bounds_nw(ji_screen, widget->rc->x1, widget->rc->y1, @@ -763,8 +763,8 @@ void SkinneableTheme::draw_entry(JWidget widget, JRect clip) draw_bounds_nw(ji_screen, x1, y1, x2, y2, - jwidget_has_focus(widget) ? PART_SUNKEN_FOCUSED_NW: - PART_SUNKEN_NORMAL_NW, bg); + widget->hasFocus() ? PART_SUNKEN_FOCUSED_NW: + PART_SUNKEN_NORMAL_NW, bg); /* draw the text */ x = widget->rc->x1 + widget->border_width.l; @@ -779,7 +779,7 @@ void SkinneableTheme::draw_entry(JWidget widget, JRect clip) /* selected */ if ((c >= selbeg) && (c <= selend)) { - if (jwidget_has_focus(widget)) + if (widget->hasFocus()) bg = COLOR_SELECTED; else bg = COLOR_DISABLED; @@ -803,13 +803,13 @@ void SkinneableTheme::draw_entry(JWidget widget, JRect clip) x += w; /* cursor */ - if ((c == cursor) && (state) && (jwidget_has_focus (widget))) + if ((c == cursor) && (state) && (widget->hasFocus())) draw_entry_cursor(widget, cursor_x, y); } /* draw the cursor if it is next of the last character */ if ((c == cursor) && (state) && - (jwidget_has_focus(widget)) && + (widget->hasFocus()) && (jwidget_is_enabled(widget))) draw_entry_cursor(widget, x, y); } @@ -895,7 +895,7 @@ void SkinneableTheme::draw_menuitem(JWidget widget, JRect clip) fg = get_menuitem_highlight_text_color(); bg = get_menuitem_highlight_face_color(); } - else if (jwidget_has_mouse(widget)) { + else if (widget->hasMouseOver()) { fg = get_menuitem_hot_text_color(); bg = get_menuitem_hot_face_color(); } @@ -1005,9 +1005,9 @@ void SkinneableTheme::draw_radio(JWidget widget, JRect clip) /* mouse */ if (jwidget_is_enabled(widget)) { - if (jwidget_has_mouse(widget)) + if (widget->hasMouseOver()) jdraw_rectfill(widget->rc, bg = get_radio_hot_face_color()); - else if (jwidget_has_focus(widget)) + else if (widget->hasFocus()) jdraw_rectfill(widget->rc, bg = get_radio_focus_face_color()); } @@ -1022,7 +1022,7 @@ void SkinneableTheme::draw_radio(JWidget widget, JRect clip) icon.x1, icon.y1); // draw focus - if (jwidget_has_focus(widget)) { + if (widget->hasFocus()) { draw_bounds_nw(ji_screen, widget->rc->x1, widget->rc->y1, @@ -1108,16 +1108,16 @@ void SkinneableTheme::draw_slider(JWidget widget, JRect clip) int empty_part_nw; if (isMiniLook) { - full_part_nw = jwidget_has_mouse(widget) ? PART_MINI_SLIDER_FULL_FOCUSED_NW: - PART_MINI_SLIDER_FULL_NW; - empty_part_nw = jwidget_has_mouse(widget) ? PART_MINI_SLIDER_EMPTY_FOCUSED_NW: - PART_MINI_SLIDER_EMPTY_NW; + full_part_nw = widget->hasMouseOver() ? PART_MINI_SLIDER_FULL_FOCUSED_NW: + PART_MINI_SLIDER_FULL_NW; + empty_part_nw = widget->hasMouseOver() ? PART_MINI_SLIDER_EMPTY_FOCUSED_NW: + PART_MINI_SLIDER_EMPTY_NW; } else { - full_part_nw = jwidget_has_focus(widget) ? PART_SLIDER_FULL_FOCUSED_NW: - PART_SLIDER_FULL_NW; - empty_part_nw = jwidget_has_focus(widget) ? PART_SLIDER_EMPTY_FOCUSED_NW: - PART_SLIDER_EMPTY_NW; + full_part_nw = widget->hasFocus() ? PART_SLIDER_FULL_FOCUSED_NW: + PART_SLIDER_FULL_NW; + empty_part_nw = widget->hasFocus() ? PART_SLIDER_EMPTY_FOCUSED_NW: + PART_SLIDER_EMPTY_NW; } if (value == min) @@ -1184,8 +1184,8 @@ void SkinneableTheme::draw_combobox_entry(JWidget widget, JRect clip) draw_bounds_nw(ji_screen, x1, y1, x2, y2, - jwidget_has_focus(widget) ? PART_SUNKEN2_FOCUSED_NW: - PART_SUNKEN2_NORMAL_NW, bg); + widget->hasFocus() ? PART_SUNKEN2_FOCUSED_NW: + PART_SUNKEN2_NORMAL_NW, bg); /* draw the text */ x = widget->rc->x1 + widget->border_width.l; @@ -1200,7 +1200,7 @@ void SkinneableTheme::draw_combobox_entry(JWidget widget, JRect clip) /* selected */ if ((c >= selbeg) && (c <= selend)) { - if (jwidget_has_focus(widget)) + if (widget->hasFocus()) bg = COLOR_SELECTED; else bg = COLOR_DISABLED; @@ -1224,13 +1224,13 @@ void SkinneableTheme::draw_combobox_entry(JWidget widget, JRect clip) x += w; /* cursor */ - if ((c == cursor) && (state) && (jwidget_has_focus (widget))) + if ((c == cursor) && (state) && (widget->hasFocus())) draw_entry_cursor(widget, cursor_x, y); } /* draw the cursor if it is next of the last character */ if ((c == cursor) && (state) && - (jwidget_has_focus(widget)) && + (widget->hasFocus()) && (jwidget_is_enabled(widget))) draw_entry_cursor(widget, x, y); } @@ -1244,7 +1244,7 @@ void SkinneableTheme::draw_combobox_button(JWidget widget, JRect clip) /* with mouse */ if (jwidget_is_selected(widget) || - (jwidget_is_enabled(widget) && jwidget_has_mouse(widget))) { + (jwidget_is_enabled(widget) && widget->hasMouseOver())) { fg = get_button_hot_text_color(); bg = get_button_hot_face_color(); part_nw = PART_TOOLBUTTON_HOT_NW; @@ -1297,8 +1297,8 @@ void SkinneableTheme::draw_view(JWidget widget, JRect clip) widget->rc->y1, widget->rc->x2-1, widget->rc->y2-1, - jwidget_has_focus(widget) ? PART_SUNKEN_FOCUSED_NW: - PART_SUNKEN_NORMAL_NW, + widget->hasFocus() ? PART_SUNKEN_FOCUSED_NW: + PART_SUNKEN_NORMAL_NW, COLOR_BACKGROUND); } @@ -1351,7 +1351,7 @@ void SkinneableTheme::draw_view_scrollbar(JWidget widget, JRect clip) /* bar-block background */ u1++, v1++, u2--, v2--; - if (jwidget_is_enabled(widget) && jwidget_has_mouse(widget)) + if (jwidget_is_enabled(widget) && widget->hasMouseOver()) rectfill(ji_screen, u1, v1, u2, v2, COLOR_HOTFACE); else rectfill(ji_screen, u1, v1, u2, v2, BGCOLOR); @@ -1410,7 +1410,7 @@ void SkinneableTheme::draw_frame_button(JWidget widget, JRect clip) if (widget->isSelected()) part = PART_WINDOW_CLOSE_BUTTON_SELECTED; - else if (jwidget_has_mouse(widget)) + else if (widget->hasMouseOver()) part = PART_WINDOW_CLOSE_BUTTON_HOT; else part = PART_WINDOW_CLOSE_BUTTON_NORMAL; diff --git a/src/widgets/colbar.cpp b/src/widgets/colbar.cpp index a23fb4da2..546605cb6 100644 --- a/src/widgets/colbar.cpp +++ b/src/widgets/colbar.cpp @@ -267,7 +267,7 @@ bool ColorBar::msg_proc(JMessage msg) } case JM_BUTTONPRESSED: - jwidget_capture_mouse(this); + captureMouse(); m_hot_drag = m_hot; m_hot_drop = m_hot; @@ -401,7 +401,7 @@ bool ColorBar::msg_proc(JMessage msg) break; case JM_BUTTONRELEASED: - if (jwidget_has_capture(this)) { + if (hasCapture()) { /* drag and drop a color */ if (m_hot_drag != m_hot_drop) { if (m_hot_drop != HOTCOLOR_NONE) { @@ -440,7 +440,7 @@ bool ColorBar::msg_proc(JMessage msg) m_hot_drag = HOTCOLOR_NONE; m_hot_drop = HOTCOLOR_NONE; - jwidget_release_mouse(this); + releaseMouse(); } break; diff --git a/src/widgets/colbut.cpp b/src/widgets/colbut.cpp index 9f91cf712..578fdc205 100644 --- a/src/widgets/colbut.cpp +++ b/src/widgets/colbut.cpp @@ -134,21 +134,19 @@ static bool colorbutton_msg_proc(JWidget widget, JMessage msg) case JM_SIGNAL: if (msg->signal.num == JI_SIGNAL_BUTTON_SELECT) { colorbutton_close_tooltip(widget); - jwidget_hard_capture_mouse(widget); + widget->captureMouse(); return true; } break; case JM_BUTTONPRESSED: - if (jwidget_has_capture(widget) && - widget->flags & JI_HARDCAPTURE) { + if (widget->hasCapture()) { return true; } break; case JM_MOTION: - if (jwidget_has_capture(widget) && - widget->flags & JI_HARDCAPTURE) { + if (widget->hasCapture()) { JWidget picked = jwidget_pick(ji_get_default_manager(), msg->mouse.x, msg->mouse.y); @@ -194,15 +192,12 @@ static bool colorbutton_msg_proc(JWidget widget, JMessage msg) break; case JM_BUTTONRELEASED: - if (jwidget_has_capture(widget) && - widget->flags & JI_HARDCAPTURE) { - jwidget_release_mouse(widget); - } + if (widget->hasCapture()) + widget->releaseMouse(); break; case JM_SETCURSOR: - if (jwidget_has_capture(widget) && - widget->flags & JI_HARDCAPTURE) { + if (widget->hasCapture()) { jmouse_set_cursor(JI_CURSOR_EYEDROPPER); return true; } @@ -230,7 +225,7 @@ static void colorbutton_draw(JWidget widget) true, true, true, true, colorbutton->imgtype, colorbutton->color, - jwidget_has_mouse(widget), false); + widget->hasMouseOver(), false); /* draw text */ color_to_formalstring(colorbutton->imgtype, diff --git a/src/widgets/colview.cpp b/src/widgets/colview.cpp index 85e663906..afa0e7518 100644 --- a/src/widgets/colview.cpp +++ b/src/widgets/colview.cpp @@ -125,8 +125,8 @@ static bool colorviewer_msg_proc(JWidget widget, JMessage msg) jrect_shrink(rect, 1); jdraw_rect(rect, - jwidget_has_focus(widget) ? makecol(0, 0, 0): - makecol(192, 192, 192)); + widget->hasFocus() ? makecol(0, 0, 0): + makecol(192, 192, 192)); /* draw color background */ jrect_shrink(rect, 1); diff --git a/src/widgets/curvedit.cpp b/src/widgets/curvedit.cpp index a22926522..3ac9798ec 100644 --- a/src/widgets/curvedit.cpp +++ b/src/widgets/curvedit.cpp @@ -306,11 +306,11 @@ static bool curve_editor_msg_proc(JWidget widget, JMessage msg) jmouse_set_cursor(JI_CURSOR_HAND); } - jwidget_capture_mouse(widget); + widget->captureMouse(); /* continue in motion message... */ case JM_MOTION: - if (jwidget_has_capture(widget)) { + if (widget->hasCapture()) { switch (curve_editor->status) { case STATUS_SCROLLING: { @@ -391,8 +391,8 @@ static bool curve_editor_msg_proc(JWidget widget, JMessage msg) break; case JM_BUTTONRELEASED: - if (jwidget_has_capture(widget)) { - jwidget_release_mouse(widget); + if (widget->hasCapture()) { + widget->releaseMouse(); switch (curve_editor->status) { diff --git a/src/widgets/editor/click.cpp b/src/widgets/editor/click.cpp index 34f5945e0..f4f3044cc 100644 --- a/src/widgets/editor/click.cpp +++ b/src/widgets/editor/click.cpp @@ -62,7 +62,7 @@ void Editor::editor_click_start(int mode, int *x, int *y, int *b) screen_to_editor(click_start_x, click_start_y, x, y); *b = click_start_b; - jwidget_capture_mouse(this); + captureMouse(); } void Editor::editor_click_continue(int mode, int *x, int *y) @@ -79,7 +79,7 @@ void Editor::editor_click_continue(int mode, int *x, int *y) void Editor::editor_click_done() { - jwidget_release_mouse(this); + releaseMouse(); clear_keybuf(); } diff --git a/src/widgets/editor/editor.cpp b/src/widgets/editor/editor.cpp index 68250f690..f8f3c4462 100644 --- a/src/widgets/editor/editor.cpp +++ b/src/widgets/editor/editor.cpp @@ -132,8 +132,8 @@ int editor_type() void Editor::editor_set_sprite(Sprite* sprite) { - if (jwidget_has_mouse(this)) - jmanager_free_mouse(); + if (this->hasMouse()) + jmanager_free_mouse(); // TODO Why is this here? Review this code m_sprite = sprite; if (m_sprite) { @@ -925,10 +925,10 @@ bool Editor::msg_proc(JMessage msg) editor_setcursor(msg->mouse.x, msg->mouse.y); - jwidget_release_mouse(this); + releaseMouse(); } } - else if (!jwidget_has_capture(this)) { + else if (!hasCapture()) { UIContext* context = UIContext::instance(); Tool* current_tool = context->getSettings()->getCurrentTool(); @@ -1038,7 +1038,7 @@ bool Editor::msg_proc(JMessage msg) } // Capture the mouse - jwidget_hard_capture_mouse(this); + captureMouse(); } return true; @@ -1182,7 +1182,7 @@ bool Editor::msg_proc(JMessage msg) } editor_setcursor(msg->mouse.x, msg->mouse.y); - jwidget_release_mouse(this); + releaseMouse(); return true; case JM_KEYPRESSED: @@ -1193,7 +1193,7 @@ bool Editor::msg_proc(JMessage msg) return true; } - if (jwidget_has_mouse(this)) { + if (this->hasMouse()) { switch (msg->key.scancode) { // Eye-dropper is activated with ALT key @@ -1260,8 +1260,8 @@ bool Editor::msg_proc(JMessage msg) if (m_state == EDITOR_STATE_STANDBY || m_state == EDITOR_STATE_DRAWING || m_state == EDITOR_STATE_MOVING_PIXELS) { - // There are and sprite in the editor, there is the mouse inside - if (m_sprite && jwidget_has_mouse(this)) { + // There are and sprite in the editor and the mouse is inside + if (m_sprite && this->hasMouse()) { int dz = jmouse_z(1) - jmouse_z(0); WHEEL_ACTION wheelAction = WHEEL_NONE; bool scrollBigSteps = false; diff --git a/src/widgets/editor/keys.cpp b/src/widgets/editor/keys.cpp index 43b208438..b4c32d659 100644 --- a/src/widgets/editor/keys.cpp +++ b/src/widgets/editor/keys.cpp @@ -39,7 +39,7 @@ bool Editor::editor_keys_toset_zoom(int scancode) { if ((m_sprite) && - (jwidget_has_mouse(this)) && + (this->hasMouse()) && !(key_shifts & (KB_SHIFT_FLAG | KB_CTRL_FLAG | KB_ALT_FLAG))) { JWidget view = jwidget_get_view(this); JRect vp = jview_get_viewport_position(view); @@ -97,7 +97,7 @@ bool Editor::editor_keys_toset_pensize(int scancode) IPenSettings* pen = tool_settings->getPen(); if ((m_sprite) && - (jwidget_has_mouse(this)) && + (this->hasMouse()) && !(key_shifts & (KB_SHIFT_FLAG | KB_CTRL_FLAG | KB_ALT_FLAG))) { if (scancode == KEY_MINUS_PAD) { // TODO configurable keys if (pen->getSize() > 1) { diff --git a/src/widgets/fileview.cpp b/src/widgets/fileview.cpp index cfb1e0866..850da59d5 100644 --- a/src/widgets/fileview.cpp +++ b/src/widgets/fileview.cpp @@ -378,10 +378,10 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg) } case JM_BUTTONPRESSED: - jwidget_hard_capture_mouse(widget); + widget->captureMouse(); case JM_MOTION: - if (jwidget_has_capture(widget)) { + if (widget->hasCapture()) { int iw, ih; int th = jwidget_get_text_height(widget); int y = widget->rc->y1; @@ -416,13 +416,13 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg) break; case JM_BUTTONRELEASED: - if (jwidget_has_capture(widget)) { - jwidget_release_mouse(widget); + if (widget->hasCapture()) { + widget->releaseMouse(); } break; case JM_KEYPRESSED: - if (jwidget_has_focus(widget)) { + if (widget->hasFocus()) { int select = fileview_get_selected_index(widget); JWidget view = jwidget_get_view(widget); int bottom = fileview->list.size(); diff --git a/src/widgets/paledit.cpp b/src/widgets/paledit.cpp index 39713397e..9f4bea96c 100644 --- a/src/widgets/paledit.cpp +++ b/src/widgets/paledit.cpp @@ -492,11 +492,11 @@ bool PalEdit::msg_proc(JMessage msg) } case JM_BUTTONPRESSED: - jwidget_hard_capture_mouse(this); + captureMouse(); /* continue... */ case JM_MOTION: - if (jwidget_has_capture(this)) { + if (hasCapture()) { JRect cpos = jwidget_get_child_rect(this); div_t d = div(256, m_columns); int cols = m_columns; @@ -554,7 +554,7 @@ bool PalEdit::msg_proc(JMessage msg) break; case JM_BUTTONRELEASED: - jwidget_release_mouse(this); + releaseMouse(); return true; } diff --git a/src/widgets/toolbar.cpp b/src/widgets/toolbar.cpp index 6dadadb74..860e5f41d 100644 --- a/src/widgets/toolbar.cpp +++ b/src/widgets/toolbar.cpp @@ -530,7 +530,7 @@ void ToolBar::onClosePopup() { closeTipWindow(); - if (!jwidget_has_mouse(this)) + if (!hasMouse()) m_tipOpened = false; m_open_on_hot = false;