shithub: choc

Download patch

ref: 240a1cfcca8f53a114a4302e93af793be21809d0
parent: 59864df095516a0e6a1fecb5a6abfeedc1e56188
author: Simon Howard <fraggle@gmail.com>
date: Tue May 23 15:33:35 EDT 2006

Add a default action to close windows when escape is pressed. Do not
make escape quit the program unless there are no open windows. Add
TXT_ExitMainLoop().

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 518

--- a/textscreen/txt_desktop.c
+++ b/textscreen/txt_desktop.c
@@ -25,6 +25,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "doomkeys.h"
+
 #include "txt_desktop.h"
 #include "txt_gui.h"
 #include "txt_main.h"
@@ -36,6 +38,7 @@
 static char *desktop_title;
 static txt_window_t *all_windows[MAXWINDOWS];
 static int num_windows = 0;
+static int main_loop_running = 0;
 
 void TXT_AddDesktopWindow(txt_window_t *win)
 {
@@ -137,9 +140,6 @@
 
     while ((c = TXT_GetChar()) > 0)
     {
-        if (c == 27)
-            exit(0);
-
         if (num_windows > 0)
         {
             // Send the keypress to the top window
@@ -146,12 +146,28 @@
 
             TXT_WindowKeyPress(all_windows[num_windows - 1], c);
         }
+        else
+        {
+            // No windows
+
+            if (c == KEY_ESCAPE)
+            {
+                TXT_ExitMainLoop();
+            }
+        }
     }
 }
 
+void TXT_ExitMainLoop(void)
+{
+    main_loop_running = 0;
+}
+
 void TXT_GUIMainLoop(void)
 {
-    for (;;) 
+    main_loop_running = 1;
+
+    while (main_loop_running)
     {
         TXT_DispatchEvents();
         TXT_DrawDesktop();
--- a/textscreen/txt_desktop.h
+++ b/textscreen/txt_desktop.h
@@ -31,6 +31,8 @@
 void TXT_RemoveDesktopWindow(txt_window_t *win);
 void TXT_SetDesktopTitle(char *title);
 void TXT_DrawDesktop(void);
+void TXT_GUIMainLoop(void);
+void TXT_ExitMainLoop(void);
 
 #endif /* #ifndef TXT_DESKTOP_T */
 
--- a/textscreen/txt_window.c
+++ b/textscreen/txt_window.c
@@ -45,6 +45,13 @@
     window->actions[position] = action;
 }
 
+static void DefaultCancelAction(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(window))
+{
+    TXT_CAST_ARG(txt_window_t, window);
+
+    TXT_CloseWindow(window);
+}
+
 txt_window_t *TXT_NewWindow(char *title)
 {
     int i;
@@ -74,6 +81,7 @@
 
     cancel_action = TXT_NewWindowAction(KEY_ESCAPE, "Abort");
     TXT_SetWindowAction(win, TXT_HORIZ_LEFT, cancel_action);
+    TXT_SignalConnect(cancel_action, "pressed", DefaultCancelAction, win);
     accept_action = TXT_NewWindowAction(KEY_ENTER, "Accept");
     TXT_SetWindowAction(win, TXT_HORIZ_RIGHT, accept_action);