Refactor jmanager to gui::Manager class.

This commit is contained in:
David Capello 2012-04-15 15:21:24 -03:00
parent 1f787e0dcb
commit 7d0bed8341
30 changed files with 477 additions and 491 deletions

View File

@ -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<Frame*>(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();
}
/**

View File

@ -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;

View File

@ -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)

View File

@ -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)

View File

@ -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();
}
//////////////////////////////////////////////////////////////////////

View File

@ -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 */

View File

@ -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<Frame*>(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<Frame*>(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<Frame*>(combobox->getRoot());
Frame* window = combobox->getRoot();
Entry* entry = window->findChildT<Entry>("filename");
char buf[MAX_PATH];
char* p;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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);

View File

@ -116,6 +116,6 @@ void _ji_reinit_theme_in_all_widgets()
static_cast<Frame*>((*widgets)[c])->remap_window();
}
// Refresh the screen
jmanager_refresh_screen();
// Redraw the whole screen
gui::Manager::getDefault()->invalidate();
}

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -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<Frame*>(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)

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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);
}
}
}

View File

@ -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 */

View File

@ -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<Frame*>(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<gui::Manager*>(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<JWidget>(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<Frame*>(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<JWidget>(link->data)->invalidateRegion(reg1);
jregion_free(reg1);
}
}
/**
Calculates the preferred size for the widget.

View File

@ -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<Widget*> 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);

View File

@ -140,7 +140,7 @@ struct Monitor
//////////////////////////////////////////////////////////////////////
static JWidget manager = NULL;
static gui::Manager* manager = NULL;
static Theme* ase_theme = NULL;
static UniquePtr<gui::Timer> 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<Frame*>(jmanager_get_top_window());
Frame* toplevel_frame = widget->getManager()->getTopFrame();
// If there is a foreground window as top level...
if (toplevel_frame &&

View File

@ -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 */

View File

@ -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)

View File

@ -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();

View File

@ -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;
}

View File

@ -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();
}
}