Add JM_CLOSE_APP message to know when the user pressed the native window close button.

This way is a lot better than simulating an ESC key down/up event.
This commit is contained in:
David Capello 2012-02-02 20:01:54 -03:00
parent 037070730e
commit bad1178617
4 changed files with 13 additions and 8 deletions

View File

@ -17,7 +17,7 @@
<key command="DeveloperConsole" shortcut="F11" />
<key command="ScreenShot" shortcut="F12" />
<key command="Exit" shortcut="Ctrl+Q" />
<key command="Exit" shortcut="Esc" />
<key command="Exit" shortcut="Alt+F4" />
<!-- Edit -->
<key command="Undo" shortcut="Ctrl+Z" /> <key command="Undo" shortcut="Ctrl+U" />
<key command="Redo" shortcut="Ctrl+Y" />

View File

@ -109,6 +109,7 @@ enum {
// General messages.
JM_OPEN, // Windows is open.
JM_CLOSE, // Windows is closed.
JM_CLOSE_APP, // The user wants to close the entire application.
JM_DESTROY, // Widget is destroyed.
JM_DRAW, // Widget needs be repainted.
JM_SIGNAL, // Signal from some widget.

View File

@ -477,16 +477,12 @@ bool jmanager_generate_messages(JWidget manager)
jmanager_enqueue_message(msg);
}
/* generate ESC key when the user press close button in the system window */
// Generate Close message when the user press close button on the system window.
if (want_close_stage == STAGE_WANT_CLOSE) {
want_close_stage = STAGE_NORMAL;
msg = jmessage_new_key_related(JM_KEYPRESSED, (KEY_ESC << 8) | 27);
broadcast_key_msg(manager, msg);
jmanager_enqueue_message(msg);
msg = jmessage_new_key_related(JM_KEYRELEASED, (KEY_ESC << 8) | 27);
broadcast_key_msg(manager, msg);
msg = jmessage_new(JM_CLOSE_APP);
jmessage_broadcast_to_children(msg, manager);
jmanager_enqueue_message(msg);
}

View File

@ -1147,6 +1147,14 @@ static bool manager_msg_proc(JWidget widget, Message* msg)
{
switch (msg->type) {
case JM_CLOSE_APP:
{
// Execute the "Exit" command.
Command* command = CommandsModule::instance()->getCommandByName(CommandId::Exit);
UIContext::instance()->executeCommand(command);
}
break;
case JM_QUEUEPROCESSING:
gui_feedback();