diff --git a/src/app.cpp b/src/app.cpp
index b168b342d..644d385a3 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -178,7 +178,7 @@ int App::run()
// Setup the GUI screen
jmouse_set_cursor(JI_CURSOR_NORMAL);
- jmanager_refresh_screen();
+ gui::Manager::getDefault()->invalidate();
// Load main window
top_window = static_cast(load_widget("main_window.xml", "main_window"));
@@ -230,14 +230,14 @@ int App::run()
app_rebuild_documents_tabs();
app_rebuild_recent_list();
- /* set current editor */
+ // Set current editor
set_current_editor(editor);
- /* open the window */
+ // Open the window
top_window->open_window();
- /* refresh the screen */
- jmanager_refresh_screen();
+ // Redraw the whole screen.
+ gui::Manager::getDefault()->invalidate();
}
/* set background mode for non-GUI modes */
@@ -386,8 +386,8 @@ void app_refresh_screen(const Document* document)
else
set_current_palette(NULL, false);
- // redraw the screen
- jmanager_refresh_screen();
+ // Invalidate the whole screen.
+ gui::Manager::getDefault()->invalidate();
}
/**
diff --git a/src/commands/cmd_eyedropper.cpp b/src/commands/cmd_eyedropper.cpp
index 0f828e349..44ee07df9 100644
--- a/src/commands/cmd_eyedropper.cpp
+++ b/src/commands/cmd_eyedropper.cpp
@@ -67,7 +67,7 @@ void EyedropperCommand::onLoadParams(Params* params)
void EyedropperCommand::onExecute(Context* context)
{
- JWidget widget = jmanager_get_mouse();
+ Widget* widget = gui::Manager::getDefault()->getMouse();
if (!widget || widget->type != editor_type())
return;
diff --git a/src/commands/cmd_palette_editor.cpp b/src/commands/cmd_palette_editor.cpp
index 8fea35434..83bd47077 100644
--- a/src/commands/cmd_palette_editor.cpp
+++ b/src/commands/cmd_palette_editor.cpp
@@ -768,7 +768,7 @@ void PaletteEntryEditor::setNewPalette(Palette* palette, const char* operationNa
updateCurrentSpritePalette(operationName);
// Redraw the entire screen
- jmanager_refresh_screen();
+ gui::Manager::getDefault()->invalidate();
}
void PaletteEntryEditor::updateCurrentSpritePalette(const char* operationName)
diff --git a/src/commands/cmd_play_animation.cpp b/src/commands/cmd_play_animation.cpp
index 4ee573cd7..c5891b0a1 100644
--- a/src/commands/cmd_play_animation.cpp
+++ b/src/commands/cmd_play_animation.cpp
@@ -145,7 +145,7 @@ void PlayAnimationCommand::onExecute(Context* context)
/* refresh all */
newpal = sprite->getPalette(sprite->getCurrentFrame());
set_current_palette(newpal, true);
- jmanager_refresh_screen();
+ gui::Manager::getDefault()->invalidate();
gui_feedback();
while (mouse_b)
diff --git a/src/commands/cmd_preview.cpp b/src/commands/cmd_preview.cpp
index 9952c9845..10aef8aaa 100644
--- a/src/commands/cmd_preview.cpp
+++ b/src/commands/cmd_preview.cpp
@@ -91,7 +91,7 @@ void PreviewCommand::onExecute(Context* context)
TiledMode tiled = context->getSettings()->getTiledMode();
// Free mouse
- jmanager_free_mouse();
+ editor->getManager()->freeMouse();
// Clear extras (e.g. pen preview)
document->destroyExtraCel();
@@ -240,7 +240,7 @@ void PreviewCommand::onExecute(Context* context)
jmouse_set_position(old_mouse_x, old_mouse_y);
jmouse_set_cursor(JI_CURSOR_NORMAL);
- jmanager_refresh_screen();
+ gui::Manager::getDefault()->invalidate();
}
//////////////////////////////////////////////////////////////////////
diff --git a/src/console.cpp b/src/console.cpp
index b9d01cb64..1887e7e3c 100644
--- a/src/console.cpp
+++ b/src/console.cpp
@@ -119,7 +119,7 @@ void Console::printf(const char *format, ...)
// Open the window
if (!wid_console->isVisible()) {
wid_console->open_window();
- jmanager_refresh_screen();
+ gui::Manager::getDefault()->invalidate();
}
/* update the textbox */
diff --git a/src/dialogs/filesel.cpp b/src/dialogs/filesel.cpp
index e3ac39d6e..cb8567c3f 100644
--- a/src/dialogs/filesel.cpp
+++ b/src/dialogs/filesel.cpp
@@ -584,7 +584,7 @@ static bool fileview_msg_proc(Widget* widget, Message* msg)
IFileItem* fileitem = fileview_get_selected(widget);
if (!fileitem->isFolder()) {
- Frame* window = static_cast(widget->getRoot());
+ Frame* window = widget->getRoot();
Widget* entry = window->findChild("filename");
base::string filename = base::get_file_name(fileitem->getFileName());
@@ -601,7 +601,7 @@ static bool fileview_msg_proc(Widget* widget, Message* msg)
/* when the current folder change */
case SIGNAL_FILEVIEW_CURRENT_FOLDER_CHANGED: {
- Frame* window = static_cast(widget->getRoot());
+ Frame* window = widget->getRoot();
if (!navigation_locked)
add_in_navigation_history(fileview_get_current_folder(widget));
@@ -645,7 +645,7 @@ static bool location_msg_proc(Widget* widget, Message* msg)
// Refocus the 'fileview' (the focus in that widget is more
// useful for the user)
- jmanager_set_focus(fileview);
+ widget->getManager()->setFocus(fileview);
}
break;
}
@@ -667,7 +667,7 @@ static bool filetype_msg_proc(Widget* widget, Message* msg)
// change the file-extension in the 'filename' entry widget
case JI_SIGNAL_COMBOBOX_SELECT: {
std::string ext = combobox->getItemText(combobox->getSelectedItem());
- Frame* window = static_cast(combobox->getRoot());
+ Frame* window = combobox->getRoot();
Entry* entry = window->findChildT("filename");
char buf[MAX_PATH];
char* p;
diff --git a/src/drop_files.cpp b/src/drop_files.cpp
index d44856170..4f65cf764 100644
--- a/src/drop_files.cpp
+++ b/src/drop_files.cpp
@@ -75,7 +75,7 @@ void check_for_dropped_files()
// If the main window is not the current foreground one. We discard
// the drop-files event.
- if (jmanager_get_foreground_window() != app_get_top_window())
+ if (gui::Manager::getDefault()->getForegroundFrame() != app_get_top_window())
return;
ScopedLock lock(*dropped_files_mutex);
diff --git a/src/gfxmode.cpp b/src/gfxmode.cpp
index c88f3fdfb..e3bbf2ce9 100644
--- a/src/gfxmode.cpp
+++ b/src/gfxmode.cpp
@@ -78,7 +78,7 @@ bool GfxMode::setGfxMode() const
// Redraw top window
if (app_get_top_window()) {
app_get_top_window()->remap_window();
- jmanager_refresh_screen();
+ gui::Manager::getDefault()->invalidate();
}
return true;
diff --git a/src/gui/button.cpp b/src/gui/button.cpp
index b69e0f35b..cf23fd486 100644
--- a/src/gui/button.cpp
+++ b/src/gui/button.cpp
@@ -113,11 +113,11 @@ bool ButtonBase::onProcessMessage(Message* msg)
else if (this->isFocusMagnet() &&
((msg->key.scancode == KEY_ENTER) ||
(msg->key.scancode == KEY_ENTER_PAD))) {
- jmanager_set_focus(this);
+ getManager()->setFocus(this);
- /* dispatch focus movement messages (because the buttons
- process them) */
- jmanager_dispatch_messages(ji_get_default_manager());
+ // Dispatch focus movement messages (because the buttons
+ // process them)
+ getManager()->dispatchMessages();
this->setSelected(true);
return true;
diff --git a/src/gui/combobox.cpp b/src/gui/combobox.cpp
index 29277af99..aa4eccc23 100644
--- a/src/gui/combobox.cpp
+++ b/src/gui/combobox.cpp
@@ -353,7 +353,7 @@ static bool combobox_entry_msg_proc(JWidget widget, Message* msg)
}
if (combobox->isEditable()) {
- jmanager_set_focus(widget);
+ widget->getManager()->setFocus(widget);
}
else
return true;
@@ -475,10 +475,10 @@ void ComboBox::openListBox()
m_window->position_window(rc->x1, rc->y1);
jrect_free(rc);
- jmanager_add_msg_filter(JM_BUTTONPRESSED, this);
+ getManager()->addMessageFilter(JM_BUTTONPRESSED, this);
m_window->open_window_bg();
- jmanager_set_focus(m_listbox);
+ getManager()->setFocus(m_listbox);
}
}
@@ -489,8 +489,8 @@ void ComboBox::closeListBox()
delete m_window; // window, frame
m_window = NULL;
- jmanager_remove_msg_filter(JM_BUTTONPRESSED, this);
- jmanager_set_focus(m_entry);
+ getManager()->removeMessageFilter(JM_BUTTONPRESSED, this);
+ getManager()->setFocus(m_entry);
}
}
diff --git a/src/gui/frame.cpp b/src/gui/frame.cpp
index b8f8c3a24..eb0f9977f 100644
--- a/src/gui/frame.cpp
+++ b/src/gui/frame.cpp
@@ -52,7 +52,7 @@ Frame::Frame(bool desktop, const char* text)
Frame::~Frame()
{
- _jmanager_close_window(getManager(), this, false);
+ getManager()->_closeWindow(this, false);
}
Widget* Frame::get_killer()
@@ -218,7 +218,7 @@ void Frame::open_window()
if (m_is_autoremap)
center_window();
- _jmanager_open_window(ji_get_default_manager(), this);
+ gui::Manager::getDefault()->_openWindow(this);
}
}
@@ -226,13 +226,13 @@ void Frame::open_window_fg()
{
open_window();
- JWidget manager = getManager();
+ gui::Manager* manager = getManager();
m_is_foreground = true;
while (!(this->flags & JI_HIDDEN)) {
- if (jmanager_generate_messages(manager))
- jmanager_dispatch_messages(manager);
+ if (manager->generateMessages())
+ manager->dispatchMessages();
}
m_is_foreground = false;
@@ -247,7 +247,7 @@ void Frame::closeWindow(Widget* killer)
{
m_killer = killer;
- _jmanager_close_window(getManager(), this, true);
+ getManager()->_closeWindow(this, true);
}
bool Frame::is_toplevel()
@@ -550,7 +550,7 @@ void Frame::move_window(JRect rect, bool use_blit)
{
#define FLAGS JI_GDR_CUTTOPWINDOWS | JI_GDR_USECHILDAREA
- JWidget manager = getManager();
+ gui::Manager* manager = getManager();
JRegion old_drawable_region;
JRegion new_drawable_region;
JRegion manager_refresh_region;
@@ -559,7 +559,7 @@ void Frame::move_window(JRect rect, bool use_blit)
JRect man_pos;
Message* msg;
- jmanager_dispatch_messages(manager);
+ manager->dispatchMessages();
/* get the window's current position */
old_pos = jrect_new_copy(this->rc);
@@ -570,7 +570,7 @@ void Frame::move_window(JRect rect, bool use_blit)
/* sent a JM_WINMOVE message to the window */
msg = jmessage_new(JM_WINMOVE);
jmessage_add_dest(msg, this);
- jmanager_enqueue_message(msg);
+ manager->enqueueMessage(msg);
/* get the region & the drawable region of the window */
old_drawable_region = jwidget_get_drawable_region(this, FLAGS);
@@ -650,8 +650,8 @@ void Frame::move_window(JRect rect, bool use_blit)
jregion_free(moveable_region);
}
- jmanager_invalidate_region(manager, manager_refresh_region);
- this->invalidateRegion(window_refresh_region);
+ manager->invalidateDisplayRegion(manager_refresh_region);
+ invalidateRegion(window_refresh_region);
jregion_free(old_drawable_region);
jregion_free(new_drawable_region);
diff --git a/src/gui/intern.cpp b/src/gui/intern.cpp
index 559c13632..5f8710253 100644
--- a/src/gui/intern.cpp
+++ b/src/gui/intern.cpp
@@ -116,6 +116,6 @@ void _ji_reinit_theme_in_all_widgets()
static_cast((*widgets)[c])->remap_window();
}
- // Refresh the screen
- jmanager_refresh_screen();
+ // Redraw the whole screen
+ gui::Manager::getDefault()->invalidate();
}
diff --git a/src/gui/intern.h b/src/gui/intern.h
index 015fc361a..577f27b1c 100644
--- a/src/gui/intern.h
+++ b/src/gui/intern.h
@@ -31,12 +31,6 @@ void _ji_reinit_theme_in_all_widgets();
bool _jwindow_is_moving();
-//////////////////////////////////////////////////////////////////////
-// jmanager.c
-
-void _jmanager_open_window(JWidget manager, Frame* frame);
-void _jmanager_close_window(JWidget manager, Frame* frame, bool redraw_background);
-
//////////////////////////////////////////////////////////////////////
// theme.cpp
diff --git a/src/gui/manager.cpp b/src/gui/manager.cpp
index 6bc409c96..ea1af642d 100644
--- a/src/gui/manager.cpp
+++ b/src/gui/manager.cpp
@@ -9,18 +9,18 @@
#include "config.h"
-#ifdef REPORT_EVENTS
-#include
-#endif
-#include
-#include
+#include "gui/manager.h"
#include "base/chrono.h"
#include "base/thread.h"
#include "gui/gui.h"
#include "gui/intern.h"
-#define TOPWND(manager) reinterpret_cast(jlist_first_data((manager)->children))
+#ifdef REPORT_EVENTS
+#include
+#endif
+#include
+#include
#define ACCEPT_FOCUS(widget) \
(((widget)->flags & (JI_FOCUSSTOP | \
@@ -55,26 +55,6 @@ struct Filter
, widget(widget) { }
};
-class Manager : public Widget
-{
-public:
- Manager()
- : Widget(JI_MANAGER)
- {
- }
-
-protected:
- virtual void onBroadcastMouseMessage(WidgetsList& targets) OVERRIDE
- {
- // Ask to the first frame in the "children" list to know how to
- // propagate mouse messages.
- Widget* widget = reinterpret_cast(jlist_first_data(children));
- if (widget)
- widget->broadcastMouseMessage(targets);
- }
-
-};
-
static int double_click_level;
static int double_click_buttons;
static int double_click_ticks;
@@ -83,11 +63,10 @@ static int want_close_stage; /* variable to handle the external
close button in some Windows
enviroments */
-static Manager* default_manager = NULL;
+gui::Manager* gui::Manager::m_defaultManager = NULL;
static JList new_windows; // Windows that we should show
static WidgetsList mouse_widgets_list; // List of widgets to send mouse events
-static WidgetsList garbage;
static JList msg_queue; // Messages queue
static JList msg_filters[NFILTERS]; // Filters for every enqueued message
@@ -102,23 +81,9 @@ static char old_readed_key[KEY_MAX]; /* keyboard status of previous
static unsigned key_repeated[KEY_MAX];
-/* manager widget */
-static bool manager_msg_proc(JWidget widget, Message* msg);
-static void manager_request_size(JWidget widget, int *w, int *h);
-static void manager_set_position(JWidget widget, JRect rect);
-static void manager_pump_queue(JWidget widget);
-
-/* auxiliary */
-static void generate_setcursor_message();
-static void remove_msgs_for(JWidget widget, Message* msg);
-static bool some_parent_is_focusstop(JWidget widget);
-static JWidget find_magnetic_widget(JWidget widget);
-static Message* new_mouse_msg(int type, JWidget destination);
-static void broadcast_key_msg(JWidget manager, Message* msg);
-
/* keyboard focus movement stuff */
-static bool move_focus(JWidget manager, Message* msg);
-static int count_widgets_accept_focus(JWidget widget);
+static bool move_focus(gui::Manager* manager, Message* msg);
+static int count_widgets_accept_focus(Widget* widget);
static bool childs_accept_focus(JWidget widget, bool first);
static JWidget next_widget(JWidget widget);
static int cmp_left(JWidget widget, int x, int y);
@@ -133,31 +98,22 @@ static void allegro_window_close_hook()
want_close_stage = STAGE_WANT_CLOSE;
}
-static void collect_garbage()
+namespace gui {
+
+// static
+Manager* Manager::getDefault()
{
- for (WidgetsList::iterator
- it = garbage.begin(),
- end = garbage.end(); it != end; ++it) {
- delete *it;
- }
- garbage.clear();
+ return m_defaultManager;
}
-JWidget ji_get_default_manager()
+Manager::Manager()
+ : Widget(JI_MANAGER)
{
- return default_manager;
-}
-
-JWidget jmanager_new()
-{
- Manager* widget;
- int c;
-
- if (!default_manager) {
+ if (!m_defaultManager) {
if (!ji_screen)
ji_set_screen(screen, SCREEN_W, SCREEN_H);
- /* hook the window close message */
+ // Hook the window close message
want_close_stage = STAGE_NORMAL;
set_close_button_callback(allegro_window_close_hook);
@@ -166,10 +122,10 @@ JWidget jmanager_new()
new_windows = jlist_new();
mouse_widgets_list.clear();
- for (c=0; crc, 0, 0, JI_SCREEN_W, JI_SCREEN_H);
+ setVisible(true);
- jwidget_add_hook(widget, JI_MANAGER, manager_msg_proc, NULL);
-
- jrect_replace(widget->rc, 0, 0, JI_SCREEN_W, JI_SCREEN_H);
- widget->setVisible(true);
-
- /* default manager is the first one (and is ever visible) */
- if (!default_manager)
- default_manager = widget;
-
- return widget;
+ // Default manager is the first one (and is always visible).
+ if (!m_defaultManager)
+ m_defaultManager = this;
}
-void jmanager_free(JWidget widget)
+Manager::~Manager()
{
JLink link;
- int c;
- ASSERT_VALID_WIDGET(widget);
+ // There are some messages in queue? Dispatch everything.
+ dispatchMessages();
+ collectGarbage();
- /* there are some messages in queue? */
- jmanager_dispatch_messages(widget);
-
- collect_garbage();
-
- /* finish with main manager */
- if (default_manager == widget) {
- /* no more cursor */
+ // Finish the main manager.
+ if (m_defaultManager == this) {
+ // No more cursor
jmouse_set_cursor(JI_CURSOR_NULL);
- /* destroy this widget */
- jwidget_free(widget);
-
// Destroy timers
gui::Timer::checkNoTimers();
- /* destroy filters */
- for (c=0; c(link->data);
}
@@ -231,32 +174,28 @@ void jmanager_free(JWidget widget)
msg_filters[c] = NULL;
}
- /* no more default manager */
- default_manager = NULL;
+ // No more default manager
+ m_defaultManager = NULL;
- /* shutdown system */
+ // Shutdown system
jlist_free(msg_queue);
jlist_free(new_windows);
mouse_widgets_list.clear();
}
- else {
- /* destroy this widget */
- jwidget_free(widget);
- }
}
-void jmanager_run(JWidget widget)
+void Manager::run()
{
base::Chrono chrono;
- while (!jlist_empty(widget->children)) {
+ while (!jlist_empty(this->children)) {
chrono.reset();
- if (jmanager_generate_messages(widget)) {
- jmanager_dispatch_messages(widget);
+ if (generateMessages()) {
+ dispatchMessages();
}
- else if (!garbage.empty()) {
- collect_garbage();
+ else if (!m_garbage.empty()) {
+ collectGarbage();
}
// If the dispatching of messages was faster than 10 milliseconds,
@@ -270,11 +209,7 @@ void jmanager_run(JWidget widget)
}
}
-/**
- * @return true if there are messages in the queue to be distpatched
- * through jmanager_dispatch_messages().
- */
-bool jmanager_generate_messages(JWidget manager)
+bool Manager::generateMessages()
{
JWidget widget;
JWidget window;
@@ -283,21 +218,21 @@ bool jmanager_generate_messages(JWidget manager)
JLink link;
int c;
- /* poll keyboard */
+ // Poll keyboard
poll_keyboard();
if (first_time_poll) {
first_time_poll = false;
- jmanager_refresh_screen();
+ Manager::getDefault()->invalidate();
jmouse_set_cursor(JI_CURSOR_NORMAL);
}
- /* first check: there are windows to manage? */
- if (jlist_empty(manager->children))
+ // First check: there are windows to manage?
+ if (jlist_empty(this->children))
return false;
- /* new windows to show? */
+ // New windows to show?
if (!jlist_empty(new_windows)) {
JWidget magnet;
@@ -312,14 +247,14 @@ bool jmanager_generate_messages(JWidget manager)
window->invalidate();
// Attract the focus to the magnetic widget...
- /* 1) get the magnetic widget */
- magnet = find_magnetic_widget(window->getRoot());
- /* 2) if magnetic widget exists and it doesn't have the focus */
+ // 1) get the magnetic widget
+ magnet = findMagneticWidget(window->getRoot());
+ // 2) if magnetic widget exists and it doesn't have the focus
if (magnet && !magnet->hasFocus())
- jmanager_set_focus(magnet);
- /* 3) if not, put the focus in the first child */
+ setFocus(magnet);
+ // 3) if not, put the focus in the first child
else
- jmanager_focus_first_child(window);
+ focusFirstChild(window);
}
jlist_clear(new_windows);
@@ -330,7 +265,7 @@ bool jmanager_generate_messages(JWidget manager)
if (mousemove || !mouse_widget) {
// Get the list of widgets to send mouse messages.
mouse_widgets_list.clear();
- manager->broadcastMouseMessage(mouse_widgets_list);
+ broadcastMouseMessage(mouse_widgets_list);
// Get the widget under the mouse
widget = NULL;
@@ -346,9 +281,9 @@ bool jmanager_generate_messages(JWidget manager)
// Fixup "mouse" flag
if (widget != mouse_widget) {
if (!widget)
- jmanager_free_mouse();
+ freeMouse();
else
- jmanager_set_mouse(widget);
+ setMouse(widget);
}
// Mouse movement
@@ -364,19 +299,19 @@ bool jmanager_generate_messages(JWidget manager)
dst = mouse_widget;
// Send the mouse movement message
- msg = new_mouse_msg(JM_MOTION, dst);
- jmanager_enqueue_message(msg);
+ msg = newMouseMessage(JM_MOTION, dst);
+ enqueueMessage(msg);
- generate_setcursor_message();
+ generateSetCursorMessage();
}
}
// Mouse wheel
if (jmouse_z(0) != jmouse_z(1)) {
- msg = new_mouse_msg(JM_WHEEL,
- capture_widget ? capture_widget:
- mouse_widget);
- jmanager_enqueue_message(msg);
+ msg = newMouseMessage(JM_WHEEL,
+ capture_widget ? capture_widget:
+ mouse_widget);
+ enqueueMessage(msg);
}
// Mouse clicks
@@ -387,13 +322,13 @@ bool jmanager_generate_messages(JWidget manager)
((jmouse_b(1) & 2) == 0 && (jmouse_b(0) & 2) == 2) ||
((jmouse_b(1) & 4) == 0 && (jmouse_b(0) & 4) == 4);
- msg = new_mouse_msg(pressed ? JM_BUTTONPRESSED:
- JM_BUTTONRELEASED,
- capture_widget ? capture_widget:
- mouse_widget);
+ msg = newMouseMessage(pressed ? JM_BUTTONPRESSED:
+ JM_BUTTONRELEASED,
+ capture_widget ? capture_widget:
+ mouse_widget);
- /**********************************************************************/
- /* Double Click */
+ //////////////////////////////////////////////////////////////////////
+ // Double Click
if (msg->type == JM_BUTTONPRESSED) {
if (double_click_level != DOUBLE_CLICK_NONE) {
/* time out, back to NONE */
@@ -408,13 +343,13 @@ bool jmanager_generate_messages(JWidget manager)
double_click_level = DOUBLE_CLICK_NONE;
}
}
- /* press other button, back to NONE */
+ // Press other button, back to NONE
else {
double_click_level = DOUBLE_CLICK_NONE;
}
}
- /* this could be the beginning of the state */
+ // This could be the beginning of the state
if (double_click_level == DOUBLE_CLICK_NONE) {
double_click_level = DOUBLE_CLICK_DOWN;
double_click_buttons = msg->mouse.flags;
@@ -423,7 +358,7 @@ bool jmanager_generate_messages(JWidget manager)
}
else if (msg->type == JM_BUTTONRELEASED) {
if (double_click_level != DOUBLE_CLICK_NONE) {
- /* time out, back to NONE */
+ // Time out, back to NONE
if (current_ticks - double_click_ticks > DOUBLE_CLICK_TIMEOUT_MSECS) {
double_click_level = DOUBLE_CLICK_NONE;
}
@@ -433,7 +368,7 @@ bool jmanager_generate_messages(JWidget manager)
double_click_ticks = current_ticks;
}
}
- /* press other button, back to NONE */
+ // Press other button, back to NONE
else {
double_click_level = DOUBLE_CLICK_NONE;
}
@@ -445,8 +380,8 @@ bool jmanager_generate_messages(JWidget manager)
if (msg->type == JM_BUTTONPRESSED &&
!capture_widget && mouse_widget) {
// The clicked window
- Frame* window = static_cast(mouse_widget->getRoot());
- JWidget win_manager = window ? window->getManager(): NULL;
+ Frame* window = mouse_widget->getRoot();
+ Manager* win_manager = (window ? window->getManager(): NULL);
if ((window) &&
// We cannot change Z-order of desktop windows
@@ -456,7 +391,7 @@ bool jmanager_generate_messages(JWidget manager)
// which should be kept on top of the foreground one.
(!window->is_foreground()) &&
// If the window is not already the top window of the manager.
- (window != TOPWND(win_manager))) {
+ (window != win_manager->getTopFrame())) {
// Put it in the top of the list
jlist_remove(win_manager->children, window);
@@ -476,10 +411,10 @@ bool jmanager_generate_messages(JWidget manager)
}
// Put the focus
- jmanager_set_focus(mouse_widget);
+ setFocus(mouse_widget);
}
- jmanager_enqueue_message(msg);
+ enqueueMessage(msg);
}
// Generate Close message when the user press close button on the system window.
@@ -487,15 +422,14 @@ bool jmanager_generate_messages(JWidget manager)
want_close_stage = STAGE_NORMAL;
msg = jmessage_new(JM_CLOSE_APP);
- jmessage_broadcast_to_children(msg, manager);
- jmanager_enqueue_message(msg);
+ jmessage_broadcast_to_children(msg, this);
+ enqueueMessage(msg);
}
- /* generate JM_CHAR/JM_KEYPRESSED messages */
+ // Generate JM_CHAR/JM_KEYPRESSED messages.
while (keypressed()) {
int readkey_value = readkey();
- /* char message first */
msg = jmessage_new_key_related(JM_KEYPRESSED, readkey_value);
c = readkey_value >> 8;
@@ -504,23 +438,23 @@ bool jmanager_generate_messages(JWidget manager)
msg->key.repeat = key_repeated[c]++;
}
- broadcast_key_msg(manager, msg);
- jmanager_enqueue_message(msg);
+ broadcastKeyMsg(msg);
+ enqueueMessage(msg);
}
for (c=0; c= KEY_MODIFIERS) {
@@ -530,8 +464,8 @@ bool jmanager_generate_messages(JWidget manager)
old_readed_key[c] = key[c];
msg->key.repeat = key_repeated[c]++;
- broadcast_key_msg(manager, msg);
- jmanager_enqueue_message(msg);
+ broadcastKeyMsg(msg);
+ enqueueMessage(msg);
}
}
}
@@ -539,11 +473,8 @@ bool jmanager_generate_messages(JWidget manager)
// Generate messages for timers
gui::Timer::pollTimers();
- /* generate redraw events */
- manager->flushRedraw();
-
- /* make some OSes happy */
- rest(0);
+ // Generate redraw events.
+ flushRedraw();
if (!jlist_empty(msg_queue))
return true;
@@ -551,22 +482,18 @@ bool jmanager_generate_messages(JWidget manager)
return false;
}
-void jmanager_dispatch_messages(JWidget manager)
+void Manager::dispatchMessages()
{
- Message* msg;
+ // Add the "Queue Processing" message for the manager.
+ Message* msg = newMouseMessage(JM_QUEUEPROCESSING, this);
+ enqueueMessage(msg);
- ASSERT(manager != NULL);
-
- /* add the "Queue Processing" message for the manager */
- msg = new_mouse_msg(JM_QUEUEPROCESSING, manager);
- jmanager_enqueue_message(msg);
-
- manager_pump_queue(manager);
+ pumpQueue();
}
-void jmanager_add_to_garbage(Widget* widget)
+void Manager::addToGarbage(Widget* widget)
{
- garbage.push_back(widget);
+ m_garbage.push_back(widget);
}
/**
@@ -574,7 +501,7 @@ void jmanager_add_to_garbage(Widget* widget)
* routine. The message will be automatically freed through
* @ref jmessage_free
*/
-void jmanager_enqueue_message(Message* msg)
+void Manager::enqueueMessage(Message* msg)
{
int c;
@@ -604,18 +531,15 @@ void jmanager_enqueue_message(Message* msg)
jmessage_free(msg);
}
-JWidget jmanager_get_top_window()
+Frame* Manager::getTopFrame()
{
- if (default_manager)
- return TOPWND(default_manager);
- else
- return NULL;
+ return reinterpret_cast(jlist_first_data(this->children));
}
-JWidget jmanager_get_foreground_window()
+Frame* Manager::getForegroundFrame()
{
JLink link;
- JI_LIST_FOR_EACH(default_manager->children, link) {
+ JI_LIST_FOR_EACH(this->children, link) {
Frame* frame = (Frame*)link->data;
if (frame->is_foreground() ||
frame->is_desktop())
@@ -624,29 +548,29 @@ JWidget jmanager_get_foreground_window()
return NULL;
}
-JWidget jmanager_get_focus()
+Widget* Manager::getFocus()
{
return focus_widget;
}
-JWidget jmanager_get_mouse()
+Widget* Manager::getMouse()
{
return mouse_widget;
}
-JWidget jmanager_get_capture()
+Widget* Manager::getCapture()
{
return capture_widget;
}
-void jmanager_set_focus(JWidget widget)
+void Manager::setFocus(Widget* widget)
{
if ((focus_widget != widget)
&& (!(widget)
|| (!(widget->flags & JI_DISABLED)
&& !(widget->flags & JI_HIDDEN)
&& !(widget->flags & JI_DECORATIVE)
- && some_parent_is_focusstop(widget)))) {
+ && someParentIsFocusStop(widget)))) {
JList widget_parents = NULL;
JWidget common_parent = NULL;
JLink link, link2;
@@ -681,7 +605,7 @@ void jmanager_set_focus(JWidget widget)
}
}
- jmanager_enqueue_message(msg);
+ enqueueMessage(msg);
jlist_free(focus_parents);
}
@@ -707,14 +631,14 @@ void jmanager_set_focus(JWidget widget)
}
}
- jmanager_enqueue_message(msg);
+ enqueueMessage(msg);
}
jlist_free(widget_parents);
}
}
-void jmanager_set_mouse(JWidget widget)
+void Manager::setMouse(Widget* widget)
{
if ((mouse_widget != widget) && (!capture_widget)) {
JList widget_parents = NULL;
@@ -751,7 +675,7 @@ void jmanager_set_mouse(JWidget widget)
}
}
- jmanager_enqueue_message(msg);
+ enqueueMessage(msg);
jlist_free(mouse_parents);
}
@@ -772,52 +696,52 @@ void jmanager_set_mouse(JWidget widget)
jmessage_add_dest(msg, reinterpret_cast(link->data));
}
- jmanager_enqueue_message(msg);
- generate_setcursor_message();
+ enqueueMessage(msg);
+ generateSetCursorMessage();
}
jlist_free(widget_parents);
}
}
-void jmanager_set_capture(JWidget widget)
+void Manager::setCapture(Widget* widget)
{
widget->flags |= JI_HASCAPTURE;
capture_widget = widget;
}
/* sets the focus to the "magnetic" widget inside the window */
-void jmanager_attract_focus(JWidget widget)
+void Manager::attractFocus(Widget* widget)
{
/* get the magnetic widget */
- JWidget magnet = find_magnetic_widget(widget->getRoot());
+ JWidget magnet = findMagneticWidget(widget->getRoot());
/* if magnetic widget exists and it doesn't have the focus */
if (magnet && !magnet->hasFocus())
- jmanager_set_focus(magnet);
+ setFocus(magnet);
}
-void jmanager_focus_first_child(JWidget widget)
+void Manager::focusFirstChild(Widget* widget)
{
for (Widget* it=widget->getRoot(); it; it=next_widget(it)) {
if (ACCEPT_FOCUS(it) && !(childs_accept_focus(it, true))) {
- jmanager_set_focus(it);
+ setFocus(it);
break;
}
}
}
-void jmanager_free_focus()
+void Manager::freeFocus()
{
- jmanager_set_focus(NULL);
+ setFocus(NULL);
}
-void jmanager_free_mouse()
+void Manager::freeMouse()
{
- jmanager_set_mouse(NULL);
+ setMouse(NULL);
}
-void jmanager_free_capture()
+void Manager::freeCapture()
{
if (capture_widget) {
capture_widget->flags &= ~JI_HASCAPTURE;
@@ -825,33 +749,33 @@ void jmanager_free_capture()
}
}
-void jmanager_free_widget(JWidget widget)
+void Manager::freeWidget(Widget* widget)
{
// Break any relationship with the GUI manager
if (widget->hasCapture() || (widget == capture_widget))
- jmanager_free_capture();
+ freeCapture();
if (widget->hasMouse() || (widget == mouse_widget))
- jmanager_free_mouse();
+ freeMouse();
if (widget->hasFocus() || (widget == focus_widget))
- jmanager_free_focus();
+ freeFocus();
}
-void jmanager_remove_message(Message* msg)
+void Manager::removeMessage(Message* msg)
{
jlist_remove(msg_queue, msg);
}
-void jmanager_remove_messages_for(JWidget widget)
+void Manager::removeMessagesFor(JWidget widget)
{
JLink link;
JI_LIST_FOR_EACH(msg_queue, link)
- remove_msgs_for(widget, reinterpret_cast(link->data));
+ removeWidgetFromDests(widget, reinterpret_cast(link->data));
}
-void jmanager_remove_messages_for_timer(gui::Timer* timer)
+void Manager::removeMessagesForTimer(gui::Timer* timer)
{
JLink link, next;
@@ -866,13 +790,7 @@ void jmanager_remove_messages_for_timer(gui::Timer* timer)
}
}
-void jmanager_refresh_screen()
-{
- if (default_manager)
- default_manager->invalidate();
-}
-
-void jmanager_add_msg_filter(int message, JWidget widget)
+void Manager::addMessageFilter(int message, JWidget widget)
{
int c = message;
if (c >= JM_REGISTERED_MESSAGES)
@@ -881,7 +799,7 @@ void jmanager_add_msg_filter(int message, JWidget widget)
jlist_append(msg_filters[c], new Filter(message, widget));
}
-void jmanager_remove_msg_filter(int message, JWidget widget)
+void Manager::removeMessageFilter(int message, JWidget widget)
{
JLink link, next;
int c = message;
@@ -897,7 +815,7 @@ void jmanager_remove_msg_filter(int message, JWidget widget)
}
}
-void jmanager_remove_msg_filter_for(JWidget widget)
+void Manager::removeMessageFilterFor(JWidget widget)
{
JLink link, next;
int c;
@@ -914,39 +832,39 @@ void jmanager_remove_msg_filter_for(JWidget widget)
}
/* configures the window for begin the loop */
-void _jmanager_open_window(JWidget manager, Frame* window)
+void Manager::_openWindow(Frame* window)
{
Message* msg;
// free all widgets of special states
if (window->is_wantfocus()) {
- jmanager_free_capture();
- jmanager_free_mouse();
- jmanager_free_focus();
+ freeCapture();
+ freeMouse();
+ freeFocus();
}
/* add the window to manager */
- jlist_prepend(manager->children, window);
- window->parent = manager;
+ jlist_prepend(this->children, window);
+ window->parent = this;
/* append signal */
- jwidget_emit_signal(manager, JI_SIGNAL_MANAGER_ADD_WINDOW);
+ jwidget_emit_signal(this, JI_SIGNAL_MANAGER_ADD_WINDOW);
/* broadcast the open message */
msg = jmessage_new(JM_OPEN);
jmessage_add_dest(msg, window);
- jmanager_enqueue_message(msg);
+ enqueueMessage(msg);
/* update the new windows list to show */
jlist_append(new_windows, window);
}
-void _jmanager_close_window(JWidget manager, Frame* window, bool redraw_background)
+void Manager::_closeWindow(Frame* window, bool redraw_background)
{
Message* msg;
JRegion reg1;
- if (!manager->hasChild(window))
+ if (!hasChild(window))
return;
if (redraw_background)
@@ -958,7 +876,7 @@ void _jmanager_close_window(JWidget manager, Frame* window, bool redraw_backgrou
if (window->is_desktop()) {
JLink link, next;
- JI_LIST_FOR_EACH_SAFE(manager->children, link, next) {
+ JI_LIST_FOR_EACH_SAFE(this->children, link, next) {
if (link->data == window)
break;
else {
@@ -966,20 +884,20 @@ void _jmanager_close_window(JWidget manager, Frame* window, bool redraw_backgrou
jregion_union(reg1, reg1, reg2);
jregion_free(reg2);
- _jmanager_close_window(manager, reinterpret_cast(link->data), false);
+ _closeWindow(reinterpret_cast(link->data), false);
}
}
}
/* free all widgets of special states */
if (capture_widget != NULL && capture_widget->getRoot() == window)
- jmanager_free_capture();
+ freeCapture();
if (mouse_widget != NULL && mouse_widget->getRoot() == window)
- jmanager_free_mouse();
+ freeMouse();
if (focus_widget != NULL && focus_widget->getRoot() == window)
- jmanager_free_focus();
+ freeFocus();
/* hide window */
window->setVisible(false);
@@ -987,18 +905,18 @@ void _jmanager_close_window(JWidget manager, Frame* window, bool redraw_backgrou
/* close message */
msg = jmessage_new(JM_CLOSE);
jmessage_add_dest(msg, window);
- jmanager_enqueue_message(msg);
+ enqueueMessage(msg);
/* update manager list stuff */
- jlist_remove(manager->children, window);
+ jlist_remove(this->children, window);
window->parent = NULL;
/* remove signal */
- jwidget_emit_signal(manager, JI_SIGNAL_MANAGER_REMOVE_WINDOW);
+ jwidget_emit_signal(this, JI_SIGNAL_MANAGER_REMOVE_WINDOW);
/* redraw background */
if (reg1) {
- manager->invalidateRegion(reg1);
+ invalidateRegion(reg1);
jregion_free(reg1);
}
@@ -1006,24 +924,16 @@ void _jmanager_close_window(JWidget manager, Frame* window, bool redraw_backgrou
jlist_remove(new_windows, window);
}
-/**********************************************************************
- Manager
- **********************************************************************/
-
-static bool manager_msg_proc(JWidget widget, Message* msg)
+bool Manager::onProcessMessage(Message* msg)
{
switch (msg->type) {
- case JM_REQSIZE:
- manager_request_size(widget, &msg->reqsize.w, &msg->reqsize.h);
- return true;
-
case JM_SETPOS:
- manager_set_position(widget, &msg->setpos.rect);
+ layoutManager(&msg->setpos.rect);
return true;
case JM_DRAW:
- jdraw_rectfill(&msg->draw.rect, widget->getTheme()->desktop_color);
+ jdraw_rectfill(&msg->draw.rect, getTheme()->desktop_color);
return true;
case JM_KEYPRESSED:
@@ -1035,7 +945,7 @@ static bool manager_msg_proc(JWidget widget, Message* msg)
// Continue sending the message to the children of all windows
// (until a desktop or foreground window).
- JI_LIST_FOR_EACH(widget->children, link) {
+ JI_LIST_FOR_EACH(this->children, link) {
Frame* w = (Frame*)link->data;
// Send to the window.
@@ -1050,54 +960,67 @@ static bool manager_msg_proc(JWidget widget, Message* msg)
// Check the focus movement.
if (msg->type == JM_KEYPRESSED)
- move_focus(widget, msg);
+ move_focus(this, msg);
return true;
}
}
- return false;
+ return Widget::onProcessMessage(msg);
}
-static void manager_request_size(JWidget widget, int *w, int *h)
+void Manager::onBroadcastMouseMessage(WidgetsList& targets)
{
- if (!widget->parent) { /* hasn't parent? */
- *w = jrect_w(widget->rc);
- *h = jrect_h(widget->rc);
+ // Ask to the first frame in the "children" list to know how to
+ // propagate mouse messages.
+ Widget* widget = reinterpret_cast(jlist_first_data(children));
+ if (widget)
+ widget->broadcastMouseMessage(targets);
+}
+
+void Manager::onPreferredSize(PreferredSizeEvent& ev)
+{
+ int w = 0, h = 0;
+
+ if (!this->parent) { /* hasn't parent? */
+ w = jrect_w(this->rc);
+ h = jrect_h(this->rc);
}
else {
- JRect cpos, pos = jwidget_get_child_rect(widget->parent);
+ JRect cpos, pos = jwidget_get_child_rect(this->parent);
JLink link;
- JI_LIST_FOR_EACH(widget->children, link) {
+ JI_LIST_FOR_EACH(this->children, link) {
cpos = jwidget_get_rect(reinterpret_cast(link->data));
jrect_union(pos, cpos);
jrect_free(cpos);
}
- *w = jrect_w(pos);
- *h = jrect_h(pos);
+ w = jrect_w(pos);
+ h = jrect_h(pos);
jrect_free(pos);
}
+
+ ev.setPreferredSize(gfx::Size(w, h));
}
-static void manager_set_position(JWidget widget, JRect rect)
+void Manager::layoutManager(JRect rect)
{
JRect cpos, old_pos;
JWidget child;
JLink link;
int x, y;
- old_pos = jrect_new_copy(widget->rc);
- jrect_copy(widget->rc, rect);
+ old_pos = jrect_new_copy(this->rc);
+ jrect_copy(this->rc, rect);
/* offset for all windows */
- x = widget->rc->x1 - old_pos->x1;
- y = widget->rc->y1 - old_pos->y1;
+ x = this->rc->x1 - old_pos->x1;
+ y = this->rc->y1 - old_pos->y1;
- JI_LIST_FOR_EACH(widget->children, link) {
- child = (JWidget)link->data;
+ JI_LIST_FOR_EACH(this->children, link) {
+ child = (Widget*)link->data;
cpos = jwidget_get_rect(child);
jrect_displace(cpos, x, y);
@@ -1108,7 +1031,7 @@ static void manager_set_position(JWidget widget, JRect rect)
jrect_free(old_pos);
}
-static void manager_pump_queue(JWidget widget_manager)
+void Manager::pumpQueue()
{
Message* msg, *first_msg;
JLink link, link2, next;
@@ -1118,8 +1041,6 @@ static void manager_pump_queue(JWidget widget_manager)
int t = ji_clock;
#endif
- /* TODO get the msg_queue from 'widget_manager' */
-
ASSERT(msg_queue != NULL);
link = jlist_first(msg_queue);
@@ -1243,50 +1164,61 @@ static void manager_pump_queue(JWidget widget_manager)
}
}
-void jmanager_invalidate_region(JWidget widget, JRegion region)
+void Manager::invalidateDisplayRegion(const JRegion region)
{
- Frame* window;
JRegion reg1 = jregion_new(NULL, 0);
- JRegion reg2 = jregion_new(widget->rc, 0);
+ JRegion reg2 = jregion_new(this->rc, 0);
JRegion reg3;
JLink link;
- /* TODO intersect with jwidget_get_drawable_region()??? */
+ // TODO intersect with jwidget_get_drawable_region()???
jregion_intersect(reg1, region, reg2);
- /* redraw windows from top to background */
- JI_LIST_FOR_EACH(widget->children, link) {
- window = (Frame*)link->data;
+ // Redraw windows from top to background.
+ JI_LIST_FOR_EACH(this->children, link) {
+ Frame* window = (Frame*)link->data;
- // invalidate regions of this window
+ // Invalidate regions of this window
window->invalidateRegion(reg1);
- /* there is desktop? */
+ // There is desktop?
if (window->is_desktop())
- break; /* work done */
+ break; // Work done
- /* clip this window area for the next window */
+ // Clip this window area for the next window.
reg3 = jwidget_get_region(window);
jregion_copy(reg2, reg1);
jregion_subtract(reg1, reg2, reg3);
jregion_free(reg3);
}
- // invalidate areas outside windows (only when there are not a desktop window)
- if (link == widget->children->end)
- widget->invalidateRegion(reg1);
+ // Invalidate areas outside windows (only when there are not a
+ // desktop window).
+ if (link == children->end)
+ Widget::invalidateRegion(reg1);
jregion_free(reg1);
jregion_free(reg2);
}
+void Manager::collectGarbage()
+{
+ for (WidgetsList::iterator
+ it = m_garbage.begin(),
+ end = m_garbage.end(); it != end; ++it) {
+ delete *it;
+ }
+ m_garbage.clear();
+}
+
/**********************************************************************
Internal routines
**********************************************************************/
-static void generate_setcursor_message()
+// static
+void Manager::generateSetCursorMessage()
{
- JWidget dst;
+ Widget* dst;
Message* msg;
if (capture_widget)
@@ -1295,14 +1227,15 @@ static void generate_setcursor_message()
dst = mouse_widget;
if (dst) {
- msg = new_mouse_msg(JM_SETCURSOR, dst);
- jmanager_enqueue_message(msg);
+ msg = newMouseMessage(JM_SETCURSOR, dst);
+ enqueueMessage(msg);
}
else
jmouse_set_cursor(JI_CURSOR_NORMAL);
}
-static void remove_msgs_for(JWidget widget, Message* msg)
+// static
+void Manager::removeWidgetFromDests(Widget* widget, Message* msg)
{
JLink link, next;
@@ -1312,24 +1245,26 @@ static void remove_msgs_for(JWidget widget, Message* msg)
}
}
-static bool some_parent_is_focusstop(JWidget widget)
+// static
+bool Manager::someParentIsFocusStop(Widget* widget)
{
if (widget->isFocusStop())
return true;
if (widget->parent)
- return some_parent_is_focusstop(widget->parent);
+ return someParentIsFocusStop(widget->parent);
else
return false;
}
-static JWidget find_magnetic_widget(JWidget widget)
+// static
+Widget* Manager::findMagneticWidget(Widget* widget)
{
- JWidget found;
+ Widget* found;
JLink link;
JI_LIST_FOR_EACH(widget->children, link) {
- found = find_magnetic_widget(reinterpret_cast(link->data));
+ found = findMagneticWidget(reinterpret_cast(link->data));
if (found)
return found;
}
@@ -1340,7 +1275,8 @@ static JWidget find_magnetic_widget(JWidget widget)
return NULL;
}
-static Message* new_mouse_msg(int type, JWidget widget)
+// static
+Message* Manager::newMouseMessage(int type, JWidget widget)
{
Message* msg = jmessage_new(type);
if (!msg)
@@ -1360,7 +1296,8 @@ static Message* new_mouse_msg(int type, JWidget widget)
return msg;
}
-static void broadcast_key_msg(JWidget manager, Message* msg)
+// static
+void Manager::broadcastKeyMsg(Message* msg)
{
// Send the message to the widget with capture
if (capture_widget) {
@@ -1372,15 +1309,17 @@ static void broadcast_key_msg(JWidget manager, Message* msg)
}
// Finally, send the message to the manager, it'll know what to do
else {
- jmessage_add_dest(msg, manager);
+ jmessage_add_dest(msg, this);
}
}
+} // namespace gui
+
/***********************************************************************
Focus Movement
***********************************************************************/
-static bool move_focus(JWidget manager, Message* msg)
+static bool move_focus(gui::Manager* manager, Message* msg)
{
int (*cmp)(JWidget, int, int) = NULL;
Widget* focus = NULL;
@@ -1391,10 +1330,10 @@ static bool move_focus(JWidget manager, Message* msg)
// Who have the focus
if (focus_widget) {
- window = dynamic_cast(focus_widget->getRoot());
+ window = focus_widget->getRoot();
}
else if (!jlist_empty(manager->children)) {
- window = TOPWND(manager);
+ window = manager->getTopFrame();
}
if (!window)
@@ -1481,13 +1420,13 @@ static bool move_focus(JWidget manager, Message* msg)
}
if ((focus) && (focus != focus_widget))
- jmanager_set_focus(focus);
+ gui::Manager::getDefault()->setFocus(focus);
}
return ret;
}
-static int count_widgets_accept_focus(JWidget widget)
+static int count_widgets_accept_focus(Widget* widget)
{
ASSERT(widget != NULL);
diff --git a/src/gui/manager.h b/src/gui/manager.h
index 4fcfccfe9..b6c992f75 100644
--- a/src/gui/manager.h
+++ b/src/gui/manager.h
@@ -7,50 +7,87 @@
#ifndef GUI_MANAGER_H_INCLUDED
#define GUI_MANAGER_H_INCLUDED
-#include "gui/base.h"
+#include "base/compiler_specific.h"
+#include "gui/widget.h"
-namespace gui { class Timer; }
+class Frame;
-JWidget ji_get_default_manager();
+namespace gui {
-JWidget jmanager_new();
-void jmanager_free(JWidget manager);
+ class Timer;
-void jmanager_run(JWidget manager);
-bool jmanager_generate_messages(JWidget manager);
-void jmanager_dispatch_messages(JWidget manager);
+ class Manager : public Widget
+ {
+ public:
+ static Manager* getDefault();
-void jmanager_add_to_garbage(Widget* widget);
+ Manager();
+ ~Manager();
-/* routines that uses the ji_get_default_manager() */
+ void run();
-void jmanager_enqueue_message(Message* msg);
+ // Returns true if there are messages in the queue to be
+ // distpatched through jmanager_dispatch_messages().
+ bool generateMessages();
-JWidget jmanager_get_top_window();
-JWidget jmanager_get_foreground_window();
+ void dispatchMessages();
-JWidget jmanager_get_focus();
-JWidget jmanager_get_mouse();
-JWidget jmanager_get_capture();
+ void addToGarbage(Widget* widget);
-void jmanager_set_focus(JWidget widget);
-void jmanager_set_mouse(JWidget widget);
-void jmanager_set_capture(JWidget widget);
-void jmanager_attract_focus(JWidget widget);
-void jmanager_focus_first_child(JWidget widget);
-void jmanager_free_focus();
-void jmanager_free_mouse();
-void jmanager_free_capture();
-void jmanager_free_widget(JWidget widget);
-void jmanager_remove_message(Message* msg);
-void jmanager_remove_messages_for(JWidget widget);
-void jmanager_remove_messages_for_timer(gui::Timer* timer);
-void jmanager_refresh_screen();
+ void enqueueMessage(Message* msg);
-void jmanager_add_msg_filter(int message, JWidget widget);
-void jmanager_remove_msg_filter(int message, JWidget widget);
-void jmanager_remove_msg_filter_for(JWidget widget);
+ Frame* getTopFrame();
+ Frame* getForegroundFrame();
-void jmanager_invalidate_region(JWidget widget, JRegion region);
+ Widget* getFocus();
+ Widget* getMouse();
+ Widget* getCapture();
+
+ void setFocus(Widget* widget);
+ void setMouse(Widget* widget);
+ void setCapture(Widget* widget);
+ void attractFocus(Widget* widget);
+ void focusFirstChild(Widget* widget);
+ void freeFocus();
+ void freeMouse();
+ void freeCapture();
+ void freeWidget(Widget* widget);
+ void removeMessage(Message* msg);
+ void removeMessagesFor(Widget* widget);
+ void removeMessagesForTimer(gui::Timer* timer);
+
+ void addMessageFilter(int message, Widget* widget);
+ void removeMessageFilter(int message, Widget* widget);
+ void removeMessageFilterFor(Widget* widget);
+
+ void invalidateDisplayRegion(const JRegion region);
+
+ void _openWindow(Frame* window);
+ void _closeWindow(Frame* frame, bool redraw_background);
+
+ protected:
+ bool onProcessMessage(Message* msg) OVERRIDE;
+ void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
+ void onBroadcastMouseMessage(WidgetsList& targets) OVERRIDE;
+
+ private:
+ void layoutManager(JRect rect);
+ void pumpQueue();
+ void collectGarbage();
+ void generateSetCursorMessage();
+ static void removeWidgetFromDests(Widget* widget, Message* msg);
+ static bool someParentIsFocusStop(Widget* widget);
+ static Widget* findMagneticWidget(Widget* widget);
+ static Message* newMouseMessage(int type, Widget* destination);
+ void broadcastKeyMsg(Message* msg);
+
+ static Manager* m_defaultManager;
+
+ WidgetsList m_garbage;
+ };
+
+ void InvalidateRegion(Widget* widget, JRegion region);
+
+} // namespace gui
#endif
diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp
index 09be02e51..055e161cf 100644
--- a/src/gui/menu.cpp
+++ b/src/gui/menu.cpp
@@ -112,7 +112,7 @@ MenuBox::~MenuBox()
{
if (m_base && m_base->is_filtering) {
m_base->is_filtering = false;
- jmanager_remove_msg_filter(JM_BUTTONPRESSED, this);
+ gui::Manager::getDefault()->removeMessageFilter(JM_BUTTONPRESSED, this);
}
delete m_base;
@@ -236,7 +236,7 @@ void Menu::showPopup(int x, int y)
MenuBaseData* base = menubox->createBase();
base->was_clicked = true;
base->is_filtering = true;
- jmanager_add_msg_filter(JM_BUTTONPRESSED, menubox);
+ gui::Manager::getDefault()->addMessageFilter(JM_BUTTONPRESSED, menubox);
window->set_moveable(false); // Can't move the window
@@ -251,14 +251,14 @@ void Menu::showPopup(int x, int y)
MID(0, y, JI_SCREEN_H-jrect_h(window->rc)));
// Set the focus to the new menubox
- jmanager_set_focus(menubox);
+ gui::Manager::getDefault()->setFocus(menubox);
menubox->setFocusMagnet(true);
// Open the window
window->open_window_fg();
// Free the keyboard focus
- jmanager_free_focus();
+ gui::Manager::getDefault()->freeFocus();
// Fetch the "menu" so it isn't destroyed
menubox->setMenu(NULL);
@@ -375,7 +375,7 @@ bool MenuBox::onProcessMessage(Message* msg)
// popuped menu-box) to detect if the user press outside of
// the widget
if (msg->type == JM_BUTTONPRESSED && m_base != NULL) {
- Widget* picked = ji_get_default_manager()->pick(msg->mouse.x, msg->mouse.y);
+ Widget* picked = getManager()->pick(msg->mouse.x, msg->mouse.y);
// If one of these conditions are accomplished we have to
// close all menus (back to menu-bar or close the popuped
@@ -637,8 +637,7 @@ bool MenuBox::onProcessMessage(Message* msg)
default:
if (msg->type == JM_CLOSE_POPUP) {
- _jmanager_close_window(this->getManager(),
- static_cast(this->getRoot()), true);
+ this->getManager()->_closeWindow(this->getRoot(), true);
}
break;
@@ -837,9 +836,9 @@ bool MenuItem::onProcessMessage(Message* msg)
// Set the focus to this menu-box of this menu-item
if (base->close_all)
- jmanager_free_focus();
+ getManager()->freeFocus();
else
- jmanager_set_focus(this->parent->parent);
+ getManager()->setFocus(this->parent->parent);
// Is not necessary to free this window because it's
// automatically destroyed by the manager
@@ -1061,7 +1060,7 @@ void MenuItem::openSubmenu(bool select_first)
msg = jmessage_new(JM_OPEN_MENUITEM);
msg->user.a = select_first;
jmessage_add_dest(msg, this);
- jmanager_enqueue_message(msg);
+ gui::Manager::getDefault()->enqueueMessage(msg);
// Get the 'base'
MenuBaseData* base = get_base(this);
@@ -1078,7 +1077,7 @@ void MenuItem::openSubmenu(bool select_first)
// popuped menu-box
if (!base->is_filtering) {
base->is_filtering = true;
- jmanager_add_msg_filter(JM_BUTTONPRESSED, get_base_menubox(this));
+ gui::Manager::getDefault()->addMessageFilter(JM_BUTTONPRESSED, get_base_menubox(this));
}
}
@@ -1108,7 +1107,7 @@ void MenuItem::closeSubmenu(bool last_of_close_chain)
msg = jmessage_new(JM_CLOSE_MENUITEM);
msg->user.a = last_of_close_chain;
jmessage_add_dest(msg, this);
- jmanager_enqueue_message(msg);
+ gui::Manager::getDefault()->enqueueMessage(msg);
// If this is the last message of the chain, here we have the
// responsibility to set is_processing flag to true.
@@ -1153,7 +1152,7 @@ void Menu::closeAll()
base->was_clicked = false;
if (base->is_filtering) {
base->is_filtering = false;
- jmanager_remove_msg_filter(JM_BUTTONPRESSED, base_menubox);
+ gui::Manager::getDefault()->removeMessageFilter(JM_BUTTONPRESSED, base_menubox);
}
menu->unhighlightItem();
@@ -1184,7 +1183,7 @@ void MenuBox::closePopup()
{
Message* msg = jmessage_new(JM_CLOSE_POPUP);
jmessage_add_dest(msg, this);
- jmanager_enqueue_message(msg);
+ gui::Manager::getDefault()->enqueueMessage(msg);
}
void MenuBox::cancelMenuLoop()
@@ -1194,7 +1193,7 @@ void MenuBox::cancelMenuLoop()
menu->closeAll();
// Lost focus
- jmanager_free_focus();
+ gui::Manager::getDefault()->freeFocus();
}
void MenuItem::executeClick()
@@ -1202,7 +1201,7 @@ void MenuItem::executeClick()
// Send the message
Message* msg = jmessage_new(JM_EXE_MENUITEM);
jmessage_add_dest(msg, this);
- jmanager_enqueue_message(msg);
+ gui::Manager::getDefault()->enqueueMessage(msg);
}
static bool window_msg_proc(Widget* widget, Message* msg)
diff --git a/src/gui/popup_frame.cpp b/src/gui/popup_frame.cpp
index 0a3ddb73e..68348c13e 100644
--- a/src/gui/popup_frame.cpp
+++ b/src/gui/popup_frame.cpp
@@ -131,7 +131,7 @@ bool PopupFrame::onProcessMessage(Message* msg)
case JM_MOTION:
if (!is_moveable() &&
m_hot_region != NULL &&
- jmanager_get_capture() == NULL) {
+ getManager()->getCapture() == NULL) {
struct jrect box;
// If the mouse is outside the hot-region we have to close the
@@ -200,9 +200,11 @@ void PopupFrame::startFilteringMessages()
{
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);
+
+ gui::Manager* manager = gui::Manager::getDefault();
+ manager->addMessageFilter(JM_MOTION, this);
+ manager->addMessageFilter(JM_BUTTONPRESSED, this);
+ manager->addMessageFilter(JM_KEYPRESSED, this);
}
}
@@ -210,8 +212,10 @@ void PopupFrame::stopFilteringMessages()
{
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);
+
+ gui::Manager* manager = gui::Manager::getDefault();
+ manager->removeMessageFilter(JM_MOTION, this);
+ manager->removeMessageFilter(JM_BUTTONPRESSED, this);
+ manager->removeMessageFilter(JM_KEYPRESSED, this);
}
}
diff --git a/src/gui/system.cpp b/src/gui/system.cpp
index efa0cca40..c9a81382a 100644
--- a/src/gui/system.cpp
+++ b/src/gui/system.cpp
@@ -118,7 +118,7 @@ void ji_set_screen(BITMAP *bmp, int width, int height)
ji_screen_h = height;
if (ji_screen != NULL) {
- JWidget manager = ji_get_default_manager();
+ gui::Manager* manager = gui::Manager::getDefault();
/* update default-manager size */
if (manager && (jrect_w(manager->rc) != JI_SCREEN_W ||
@@ -443,7 +443,7 @@ static void update_mouse_position()
if (!PtInRect(&rc, pt)) {
/* if the mouse is free we can hide the cursor putting the
mouse outside the screen (right-bottom corder) */
- if (!jmanager_get_capture()) {
+ if (!gui::Manager::getDefault()->getCapture()) {
m_x[0] = JI_SCREEN_W+focus_x;
m_y[0] = JI_SCREEN_H+focus_y;
}
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index 6b62872fe..7e07812f7 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -64,7 +64,7 @@ void CurrentTheme::set(Theme* theme)
if (current_theme) {
current_theme->regenerate();
- Widget* manager = ji_get_default_manager();
+ gui::Manager* manager = gui::Manager::getDefault();
if (manager && !manager->getTheme())
manager->setTheme(theme);
}
diff --git a/src/gui/timer.cpp b/src/gui/timer.cpp
index ecce88e1f..7e6d26357 100644
--- a/src/gui/timer.cpp
+++ b/src/gui/timer.cpp
@@ -39,7 +39,7 @@ Timer::~Timer()
timers.erase(it);
// Remove messages of this timer in the queue
- jmanager_remove_messages_for_timer(this);
+ Manager::getDefault()->removeMessagesForTimer(this);
}
bool Timer::isRunning() const
@@ -99,7 +99,7 @@ void Timer::pollTimers()
msg->timer.count = count;
msg->timer.timer = timers[c];
jmessage_add_dest(msg, timers[c]->m_owner);
- jmanager_enqueue_message(msg);
+ Manager::getDefault()->enqueueMessage(msg);
}
}
}
diff --git a/src/gui/tooltips.cpp b/src/gui/tooltips.cpp
index 0a6c467c3..c25bf69ee 100644
--- a/src/gui/tooltips.cpp
+++ b/src/gui/tooltips.cpp
@@ -192,9 +192,9 @@ TipWindow::~TipWindow()
{
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);
+ getManager()->removeMessageFilter(JM_MOTION, this);
+ getManager()->removeMessageFilter(JM_BUTTONPRESSED, this);
+ getManager()->removeMessageFilter(JM_KEYPRESSED, this);
}
if (m_hot_region != NULL) {
jregion_free(m_hot_region);
@@ -214,9 +214,9 @@ void TipWindow::set_hotregion(JRegion 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);
+ getManager()->addMessageFilter(JM_MOTION, this);
+ getManager()->addMessageFilter(JM_BUTTONPRESSED, this);
+ getManager()->addMessageFilter(JM_KEYPRESSED, this);
}
m_hot_region = region;
}
@@ -238,9 +238,9 @@ bool TipWindow::onProcessMessage(Message* msg)
case JM_CLOSE:
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);
+ getManager()->removeMessageFilter(JM_MOTION, this);
+ getManager()->removeMessageFilter(JM_BUTTONPRESSED, this);
+ getManager()->removeMessageFilter(JM_KEYPRESSED, this);
}
break;
@@ -285,7 +285,7 @@ bool TipWindow::onProcessMessage(Message* msg)
case JM_MOTION:
if (m_hot_region != NULL &&
- jmanager_get_capture() == NULL) {
+ getManager()->getCapture() == NULL) {
struct jrect box;
/* if the mouse is outside the hot-region we have to close the window */
diff --git a/src/gui/widget.cpp b/src/gui/widget.cpp
index 77ee998f6..68f65c9d5 100644
--- a/src/gui/widget.cpp
+++ b/src/gui/widget.cpp
@@ -101,12 +101,15 @@ Widget::~Widget()
sendMessage(msg);
jmessage_free(msg);
- /* break relationship with the manager */
- jmanager_free_widget(this);
- jmanager_remove_messages_for(this);
- jmanager_remove_msg_filter_for(this);
+ // Break relationship with the manager.
+ if (this->type != JI_MANAGER) {
+ gui::Manager* manager = getManager();
+ manager->freeWidget(this);
+ manager->removeMessagesFor(this);
+ manager->removeMessageFilterFor(this);
+ }
- /* remove from parent */
+ // Remove from parent
if (this->parent)
this->parent->removeChild(this);
@@ -141,7 +144,7 @@ Widget::~Widget()
void Widget::deferDelete()
{
- jmanager_add_to_garbage(this);
+ getManager()->addToGarbage(this);
}
void Widget::initTheme()
@@ -327,7 +330,7 @@ void Widget::setVisible(bool state)
}
else {
if (!(this->flags & JI_HIDDEN)) {
- jmanager_free_widget(this); // Free from manager
+ getManager()->freeWidget(this); // Free from manager
this->flags |= JI_HIDDEN;
jwidget_emit_signal(this, JI_SIGNAL_HIDE);
@@ -347,7 +350,7 @@ void Widget::setEnabled(bool state)
}
else {
if (!(this->flags & JI_DISABLED)) {
- jmanager_free_widget(this); // Free from the manager
+ getManager()->freeWidget(this); // Free from the manager
this->flags |= JI_DISABLED;
invalidate();
@@ -466,13 +469,13 @@ bool Widget::isFocusMagnet() const
// PARENTS & CHILDREN
// ===============================================================
-Widget* Widget::getRoot()
+Frame* Widget::getRoot()
{
Widget* widget = this;
while (widget) {
if (widget->type == JI_FRAME)
- return widget;
+ return dynamic_cast(widget);
widget = widget->parent;
}
@@ -485,18 +488,18 @@ Widget* Widget::getParent()
return this->parent;
}
-Widget* Widget::getManager()
+gui::Manager* Widget::getManager()
{
Widget* widget = this;
while (widget) {
if (widget->type == JI_MANAGER)
- return widget;
+ return static_cast(widget);
widget = widget->parent;
}
- return ji_get_default_manager();
+ return gui::Manager::getDefault();
}
JList Widget::getParents(bool ascendant)
@@ -1099,7 +1102,7 @@ void Widget::flushRedraw()
jmessage_add_dest(msg, widget);
/* enqueue the draw message */
- jmanager_enqueue_message(msg);
+ getManager()->enqueueMessage(msg);
}
jregion_empty(widget->m_update_region);
@@ -1153,26 +1156,7 @@ void Widget::invalidateRect(const JRect rect)
void Widget::invalidateRegion(const JRegion region)
{
- if (isVisible() &&
- jregion_rect_in(region, this->rc) != JI_RGNOUT) {
- JRegion reg1 = jregion_new(NULL, 0);
- JRegion reg2 = jwidget_get_drawable_region(this,
- JI_GDR_CUTTOPWINDOWS);
- JLink link;
-
- jregion_union(reg1, this->m_update_region, region);
- jregion_intersect(this->m_update_region, reg1, reg2);
- jregion_free(reg2);
-
- jregion_subtract(reg1, region, this->m_update_region);
-
- mark_dirty_flag(this);
-
- JI_LIST_FOR_EACH(this->children, link)
- reinterpret_cast(link->data)->invalidateRegion(reg1);
-
- jregion_free(reg1);
- }
+ onInvalidateRegion(region);
}
void Widget::scrollRegion(JRegion region, int dx, int dy)
@@ -1241,7 +1225,7 @@ bool jwidget_emit_signal(JWidget widget, int signal_num)
/* send the signal to the window too */
if (!ret && widget->type != JI_FRAME) {
- Widget* window = widget->getRoot();
+ Frame* window = widget->getRoot();
if (window)
ret = window->sendMessage(msg);
}
@@ -1281,7 +1265,7 @@ bool Widget::sendMessage(Message* msg)
void Widget::closeWindow()
{
- if (Frame* frame = static_cast(getRoot()))
+ if (Frame* frame = getRoot())
frame->closeWindow(this);
}
@@ -1373,13 +1357,13 @@ void Widget::setPreferredSize(int fixedWidth, int fixedHeight)
void Widget::requestFocus()
{
- jmanager_set_focus(this);
+ getManager()->setFocus(this);
}
void Widget::releaseFocus()
{
if (hasFocus())
- jmanager_free_focus();
+ getManager()->freeFocus();
}
/**
@@ -1388,8 +1372,8 @@ void Widget::releaseFocus()
*/
void Widget::captureMouse()
{
- if (!jmanager_get_capture()) {
- jmanager_set_capture(this);
+ if (!getManager()->getCapture()) {
+ getManager()->setCapture(this);
jmouse_capture();
}
}
@@ -1399,8 +1383,8 @@ void Widget::captureMouse()
*/
void Widget::releaseMouse()
{
- if (jmanager_get_capture() == this) {
- jmanager_free_capture();
+ if (getManager()->getCapture() == this) {
+ getManager()->freeCapture();
jmouse_release();
}
}
@@ -1589,6 +1573,30 @@ bool Widget::onProcessMessage(Message* msg)
// EVENTS
// ===============================================================
+void Widget::onInvalidateRegion(const JRegion region)
+{
+ if (isVisible() &&
+ jregion_rect_in(region, this->rc) != JI_RGNOUT) {
+ JRegion reg1 = jregion_new(NULL, 0);
+ JRegion reg2 = jwidget_get_drawable_region(this,
+ JI_GDR_CUTTOPWINDOWS);
+ JLink link;
+
+ jregion_union(reg1, this->m_update_region, region);
+ jregion_intersect(this->m_update_region, reg1, reg2);
+ jregion_free(reg2);
+
+ jregion_subtract(reg1, region, this->m_update_region);
+
+ mark_dirty_flag(this);
+
+ JI_LIST_FOR_EACH(this->children, link)
+ reinterpret_cast(link->data)->invalidateRegion(reg1);
+
+ jregion_free(reg1);
+ }
+}
+
/**
Calculates the preferred size for the widget.
diff --git a/src/gui/widget.h b/src/gui/widget.h
index 18c31c725..df84b3ec5 100644
--- a/src/gui/widget.h
+++ b/src/gui/widget.h
@@ -19,6 +19,7 @@
class PaintEvent;
class PreferredSizeEvent;
+namespace gui { class Manager; }
#ifndef NDEBUG
#include "gui/intern.h"
@@ -31,6 +32,8 @@ class PreferredSizeEvent;
struct FONT;
struct BITMAP;
+class Frame;
+
typedef std::vector WidgetsList;
int ji_register_widget_type();
@@ -219,9 +222,9 @@ public:
// PARENTS & CHILDREN
// ===============================================================
- Widget* getRoot();
+ Frame* getRoot();
Widget* getParent();
- Widget* getManager();
+ gui::Manager* getManager();
// Returns a list of parents (you must free the list), if
// "ascendant" is true the list is build from child to parents, else
@@ -330,6 +333,7 @@ protected:
// EVENTS
// ===============================================================
+ virtual void onInvalidateRegion(const JRegion region);
virtual void onPreferredSize(PreferredSizeEvent& ev);
virtual void onPaint(PaintEvent& ev);
virtual void onBroadcastMouseMessage(WidgetsList& targets);
diff --git a/src/modules/gui.cpp b/src/modules/gui.cpp
index 4d50dd7b2..b2999dd43 100644
--- a/src/modules/gui.cpp
+++ b/src/modules/gui.cpp
@@ -140,7 +140,7 @@ struct Monitor
//////////////////////////////////////////////////////////////////////
-static JWidget manager = NULL;
+static gui::Manager* manager = NULL;
static Theme* ase_theme = NULL;
static UniquePtr monitor_timer;
@@ -296,7 +296,7 @@ int init_module_gui()
gfx_done:;
// Create the default-manager
- manager = jmanager_new();
+ manager = new gui::Manager();
jwidget_add_hook(manager, JI_WIDGET, manager_msg_proc, NULL);
// Setup the GUI theme for all widgets
@@ -364,7 +364,7 @@ void exit_module_gui()
ji_screen_created = false;
}
- jmanager_free(manager);
+ delete manager;
// Now we can destroy theme
CurrentTheme::set(NULL);
@@ -450,7 +450,7 @@ void update_screen_for_document(const Document* document)
// Well, change to the default palette.
if (set_current_palette(NULL, false)) {
// If the palette changes, refresh the whole screen.
- jmanager_refresh_screen();
+ gui::Manager::getDefault()->invalidate();
}
}
// With a document.
@@ -459,8 +459,9 @@ void update_screen_for_document(const Document* document)
// Select the palette of the sprite.
if (set_current_palette(sprite->getPalette(sprite->getCurrentFrame()), false)) {
- // If the palette changes, refresh the whole screen.
- jmanager_refresh_screen();
+ // If the palette changes, invalidate the whole screen, we've to
+ // redraw it.
+ gui::Manager::getDefault()->invalidate();
}
else {
// If it's the same palette update only the editors with the sprite.
@@ -474,7 +475,7 @@ void update_screen_for_document(const Document* document)
void gui_run()
{
- jmanager_run(manager);
+ manager->run();
}
void gui_feedback()
@@ -488,7 +489,7 @@ void gui_feedback()
gui_setup_screen(false);
app_get_top_window()->remap_window();
- jmanager_refresh_screen();
+ gui::Manager::getDefault()->invalidate();
}
#endif
@@ -1197,7 +1198,7 @@ static bool manager_msg_proc(JWidget widget, Message* msg)
break;
case JM_KEYPRESSED: {
- Frame* toplevel_frame = dynamic_cast(jmanager_get_top_window());
+ Frame* toplevel_frame = widget->getManager()->getTopFrame();
// If there is a foreground window as top level...
if (toplevel_frame &&
diff --git a/src/widgets/color_button.cpp b/src/widgets/color_button.cpp
index 8da34a789..1fdbe6e77 100644
--- a/src/widgets/color_button.cpp
+++ b/src/widgets/color_button.cpp
@@ -123,7 +123,7 @@ bool ColorButton::onProcessMessage(Message* msg)
case JM_MOTION:
if (hasCapture()) {
- Widget* picked = ji_get_default_manager()->pick(msg->mouse.x, msg->mouse.y);
+ Widget* picked = getManager()->pick(msg->mouse.x, msg->mouse.y);
Color color = m_color;
if (picked && picked != this) {
@@ -248,7 +248,7 @@ void ColorButton::openSelectorDialog()
m_frame->position_window(x, y);
- jmanager_dispatch_messages(m_frame->getManager());
+ m_frame->getManager()->dispatchMessages();
m_frame->layout();
/* setup the hot-region */
diff --git a/src/widgets/editor/moving_pixels_state.cpp b/src/widgets/editor/moving_pixels_state.cpp
index cd2b1b49f..f60a112fc 100644
--- a/src/widgets/editor/moving_pixels_state.cpp
+++ b/src/widgets/editor/moving_pixels_state.cpp
@@ -87,8 +87,8 @@ MovingPixelsState::MovingPixelsState(Editor* editor, Message* msg, PixelsMovemen
// Add the current editor as filter for key message of the manager
// so we can catch the Enter key, and avoid to execute the
// PlayAnimation command.
- jmanager_add_msg_filter(JM_KEYPRESSED, m_currentEditor);
- jmanager_add_msg_filter(JM_KEYRELEASED, m_currentEditor);
+ m_currentEditor->getManager()->addMessageFilter(JM_KEYPRESSED, m_currentEditor);
+ m_currentEditor->getManager()->addMessageFilter(JM_KEYRELEASED, m_currentEditor);
}
MovingPixelsState::~MovingPixelsState()
@@ -98,8 +98,8 @@ MovingPixelsState::~MovingPixelsState()
delete m_pixelsMovement;
- jmanager_remove_msg_filter(JM_KEYPRESSED, m_currentEditor);
- jmanager_remove_msg_filter(JM_KEYRELEASED, m_currentEditor);
+ m_currentEditor->getManager()->removeMessageFilter(JM_KEYPRESSED, m_currentEditor);
+ m_currentEditor->getManager()->removeMessageFilter(JM_KEYRELEASED, m_currentEditor);
}
EditorState::BeforeChangeAction MovingPixelsState::onBeforeChangeState(Editor* editor, EditorState* newState)
diff --git a/src/widgets/statebar.cpp b/src/widgets/statebar.cpp
index 286bb792d..1cfd64d9c 100644
--- a/src/widgets/statebar.cpp
+++ b/src/widgets/statebar.cpp
@@ -780,9 +780,9 @@ bool StatusBar::onProcessMessage(Message* msg)
if (hasChild(m_commandsBox)) {
// If we want restore the state-bar and the slider doesn't have
// the capture...
- if (jmanager_get_capture() != m_slider) {
+ if (getManager()->getCapture() != m_slider) {
// ...exit from command mode
- jmanager_free_focus(); // TODO Review this code
+ getManager()->freeFocus(); // TODO Review this code
removeChild(m_commandsBox);
invalidate();
diff --git a/src/widgets/tabs.cpp b/src/widgets/tabs.cpp
index cb35ddf0b..ea5c02343 100644
--- a/src/widgets/tabs.cpp
+++ b/src/widgets/tabs.cpp
@@ -382,7 +382,7 @@ bool Tabs::onProcessMessage(Message* msg)
// Do nothing
break;
case ANI_SCROLL: {
- int dir = jmanager_get_capture() == m_button_left ? -1: 1;
+ int dir = (getManager()->getCapture() == m_button_left ? -1: 1);
setScrollX(m_scrollX + dir*8*msg->timer.count);
break;
}
diff --git a/src/widgets/toolbar.cpp b/src/widgets/toolbar.cpp
index 6e44af99f..3243a0906 100644
--- a/src/widgets/toolbar.cpp
+++ b/src/widgets/toolbar.cpp
@@ -460,12 +460,12 @@ void ToolBar::openPopupFrame(int group_index, ToolGroup* tool_group)
// Redraw the overlapped area and save it to use it in the ToolStrip::onProcessMessage(JM_DRAW)
{
JRect rcTemp = jrect_new(rc.x, rc.y, rc.x+rc.w, rc.y+rc.h);
- ji_get_default_manager()->invalidateRect(rcTemp);
+ getManager()->invalidateRect(rcTemp);
jrect_free(rcTemp);
// Flush JM_DRAW messages and send them
- ji_get_default_manager()->flushRedraw();
- jmanager_dispatch_messages(ji_get_default_manager());
+ getManager()->flushRedraw();
+ getManager()->dispatchMessages();
// Save the area
toolstrip->saveOverlappedArea(rc);
@@ -604,8 +604,8 @@ void ToolBar::closeTipWindow()
m_tipWindow = NULL;
// Flush JM_DRAW messages and send them
- ji_get_default_manager()->flushRedraw();
- jmanager_dispatch_messages(ji_get_default_manager());
+ getManager()->flushRedraw();
+ getManager()->dispatchMessages();
}
}