diff options
-rw-r--r-- | textscreen/txt_window.c | 14 | ||||
-rw-r--r-- | textscreen/txt_window_action.c | 22 | ||||
-rw-r--r-- | textscreen/txt_window_action.h | 9 |
3 files changed, 33 insertions, 12 deletions
diff --git a/textscreen/txt_window.c b/textscreen/txt_window.c index 53813a02..0cc46308 100644 --- a/textscreen/txt_window.c +++ b/textscreen/txt_window.c @@ -37,13 +37,6 @@ void TXT_SetWindowAction(txt_window_t *window, 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; @@ -79,11 +72,8 @@ txt_window_t *TXT_NewWindow(char *title) // Default actions - 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); + TXT_SetWindowAction(win, TXT_HORIZ_LEFT, TXT_NewWindowEscapeAction(win)); + TXT_SetWindowAction(win, TXT_HORIZ_RIGHT, TXT_NewWindowAcceptAction()); return win; } diff --git a/textscreen/txt_window_action.c b/textscreen/txt_window_action.c index d7b82f68..727e9b56 100644 --- a/textscreen/txt_window_action.c +++ b/textscreen/txt_window_action.c @@ -79,3 +79,25 @@ txt_window_action_t *TXT_NewWindowAction(int key, char *label) return action; } +static void WindowCloseCallback(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(window)) +{ + TXT_CAST_ARG(txt_window_t, window); + + TXT_CloseWindow(window); +} + +txt_window_action_t *TXT_NewWindowEscapeAction(txt_window_t *window) +{ + txt_window_action_t *action; + + action = TXT_NewWindowAction(KEY_ESCAPE, "Abort"); + TXT_SignalConnect(action, "pressed", WindowCloseCallback, window); + + return action; +} + +txt_window_action_t *TXT_NewWindowAcceptAction(void) +{ + return TXT_NewWindowAction(KEY_ENTER, "Accept"); +} + diff --git a/textscreen/txt_window_action.h b/textscreen/txt_window_action.h index d4194ddd..2310547f 100644 --- a/textscreen/txt_window_action.h +++ b/textscreen/txt_window_action.h @@ -28,6 +28,7 @@ typedef struct txt_window_action_s txt_window_action_t; #include "txt_widget.h" +#include "txt_window.h" struct txt_window_action_s { @@ -38,5 +39,13 @@ struct txt_window_action_s txt_window_action_t *TXT_NewWindowAction(int key, char *label); +// Creates an "escape" button that closes the window + +txt_window_action_t *TXT_NewWindowEscapeAction(txt_window_t *window); + +// Accept button that does nothing + +txt_window_action_t *TXT_NewWindowAcceptAction(void); + #endif /* #ifndef TXT_WINDOW_ACTION_H */ |