1 /* $Id: console.h,v 1.1 2008-04-01 08:45:42 vsc Exp $ 2 3 Part of SWI-Prolog 4 5 Author: Jan Wielemaker 6 E-mail: jan@swi.psy.uva.nl 7 WWW: http://www.swi-prolog.org 8 Copyright (C): 1985-2002, University of Amsterdam 9 10 This library is free software; you can redistribute it and/or 11 modify it under the terms of the GNU Lesser General Public 12 License as published by the Free Software Foundation; either 13 version 2.1 of the License, or (at your option) any later version. 14 15 This library is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 Lesser General Public License for more details. 19 20 You should have received a copy of the GNU Lesser General Public 21 License along with this library; if not, write to the Free Software 22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 */ 24 25 #ifndef _CONSOLE_H_INCLUDED 26 #define _CONSOLE_H_INCLUDED 27 28 #ifndef RLC_VENDOR 29 #define RLC_VENDOR TEXT("SWI") 30 #endif 31 32 #define RLC_TITLE_MAX 256 /* max length of window title */ 33 34 #ifndef _export 35 #ifdef _MAKE_DLL 36 #define _export __declspec(dllexport) 37 #else 38 #define _export extern 39 #endif 40 #endif 41 42 #include <signal.h> 43 #include <stddef.h> 44 #if __GNUC__ 45 #include <stdint.h> 46 #else 47 #if (_MSC_VER < 1300) 48 typedef long intptr_t; 49 typedef unsigned long uintptr_t; 50 #endif 51 #endif 52 53 #define RLC_APPTIMER_ID 100 /* >=100: application timer */ 54 55 typedef struct 56 { int first; 57 int last; 58 int size; /* size of the buffer */ 59 TCHAR *buffer; /* character buffer */ 60 int flags; /* flags for the queue */ 61 } rlc_queue, *RlcQueue; 62 63 #define RLC_EOF 0x1 /* Flags on the queue */ 64 65 typedef struct 66 { int mark_x; 67 int mark_y; 68 } rlc_mark, *RlcMark; 69 70 typedef struct 71 { const TCHAR *title; /* window title */ 72 const TCHAR *key; /* Last part of registry-key */ 73 int width; /* # characters(0: default) */ 74 int height; /* # characters (0: default) */ 75 int x; /* # pixels (0: default) */ 76 int y; /* # pixels (0: default) */ 77 int savelines; /* # lines to save (0: default) */ 78 TCHAR face_name[32]; /* font name */ 79 int font_family; /* family id */ 80 int font_size; 81 int font_weight; 82 int font_char_set; 83 } rlc_console_attr; 84 85 typedef void * rlc_console; /* console handle */ 86 87 typedef void (*RlcUpdateHook)(void); /* Graphics update hook */ 88 typedef void (*RlcTimerHook)(int); /* Timer fireing hook */ 89 typedef int (*RlcRenderHook)(WPARAM); /* Render one format */ 90 typedef void (*RlcRenderAllHook)(void); /* Render all formats */ 91 typedef int (*RlcMain)(rlc_console c, int, TCHAR**); /* main() */ 92 typedef void (*RlcInterruptHook)(rlc_console, int); /* Hook for Control-C */ 93 typedef void (*RlcResizeHook)(int, int); /* Hook for window change */ 94 typedef void (*RlcMenuHook)(rlc_console, const TCHAR *id); /* Hook for menu-selection */ 95 typedef void (*RlcFreeDataHook)(uintptr_t data); /* release data */ 96 97 #if defined(_WINDOWS_) || defined(_WINDOWS_H) /* <windows.h> is included */ 98 /* rlc_color(which, ...) */ 99 #define RLC_WINDOW (0) /* window background */ 100 #define RLC_TEXT (1) /* text color */ 101 #define RLC_HIGHLIGHT (2) /* selected text background */ 102 #define RLC_HIGHLIGHTTEXT (3) /* selected text */ 103 104 _export HANDLE rlc_hinstance(void); /* hInstance of WinMain() */ 105 _export HWND rlc_hwnd(rlc_console c); /* HWND of console window */ 106 _export int rlc_window_pos(rlc_console c, 107 HWND hWndInsertAfter, 108 int x, int y, int w, int h, 109 UINT flags); /* resize/reposition window */ 110 _export int rlc_main(HANDLE hI, HANDLE hPrevI, 111 LPTSTR cmd, int show, RlcMain main, HICON icon); 112 _export void rlc_icon(rlc_console c, HICON icon); /* Change icon */ 113 _export COLORREF rlc_color(rlc_console c, int which, COLORREF color); 114 115 typedef LRESULT (*RlcMessageHook)(HWND hwnd, UINT message, 116 WPARAM wParam, LPARAM lParam); 117 _export RlcMessageHook rlc_message_hook(RlcMessageHook hook); 118 119 #endif /*_WINDOWS_*/ 120 121 _export RlcUpdateHook rlc_update_hook(RlcUpdateHook updatehook); 122 _export RlcTimerHook rlc_timer_hook(RlcTimerHook timerhook); 123 _export RlcRenderHook rlc_render_hook(RlcRenderHook renderhook); 124 _export RlcRenderAllHook rlc_render_all_hook(RlcRenderAllHook renderallhook); 125 _export RlcInterruptHook rlc_interrupt_hook(RlcInterruptHook interrupthook); 126 _export RlcResizeHook rlc_resize_hook(RlcResizeHook resizehook); 127 _export RlcMenuHook rlc_menu_hook(RlcMenuHook menuhook); 128 _export int rlc_copy_output_to_debug_output(int docopy); 129 130 _export rlc_console rlc_create_console(rlc_console_attr *attr); 131 _export void rlc_title(rlc_console c, 132 TCHAR *title, TCHAR *old, int size); 133 _export void rlc_yield(void); 134 _export void rlc_word_char(int chr, int isword); 135 _export int rlc_is_word_char(int chr); 136 _export int rlc_iswin32s(void); /* check for Win32S */ 137 138 _export void rlc_free(void *ptr); 139 _export void * rlc_malloc(size_t size); 140 _export void * rlc_realloc(void *ptr, size_t size); 141 142 _export size_t rlc_read(rlc_console c, TCHAR *buf, size_t cnt); 143 _export size_t rlc_write(rlc_console c, TCHAR *buf, size_t cnt); 144 _export int rlc_close(rlc_console c); 145 _export int rlc_flush_output(rlc_console c); 146 147 _export int getch(rlc_console c); 148 _export int getche(rlc_console c); 149 _export int getkey(rlc_console c); 150 _export int kbhit(rlc_console c); 151 _export void ScreenGetCursor(rlc_console c, int *row, int *col); 152 _export void ScreenSetCursor(rlc_console c, int row, int col); 153 _export int ScreenCols(rlc_console c); 154 _export int ScreenRows(rlc_console c); 155 156 _export int rlc_insert_menu_item(rlc_console c, 157 const TCHAR *menu, 158 const TCHAR *label, 159 const TCHAR *before); 160 _export int rlc_insert_menu(rlc_console c, 161 const TCHAR *label, 162 const TCHAR *before); 163 164 /******************************* 165 * GET/SET VALUES * 166 *******************************/ 167 168 #define RLC_APPLICATION_THREAD 0 /* thread-handle of application */ 169 #define RLC_APPLICATION_THREAD_ID 1 /* thread id of application */ 170 #define RLC_VALUE(N) (1000+(N)) 171 172 _export int rlc_get(rlc_console c, int what, 173 uintptr_t *val); 174 _export int rlc_set(rlc_console c, int what, 175 uintptr_t val, 176 RlcFreeDataHook hook); 177 178 179 /******************************* 180 * LINE EDIT STUFF * 181 *******************************/ 182 183 typedef struct _line 184 { rlc_mark origin; /* origin of edit */ 185 size_t point; /* location of the caret */ 186 size_t size; /* # characters in buffer */ 187 size_t allocated; /* # characters allocated */ 188 size_t change_start; /* start of change */ 189 int complete; /* line is completed */ 190 int reprompt; /* repeat the prompt */ 191 TCHAR *data; /* the data (malloc'ed) */ 192 rlc_console console; /* console I belong to */ 193 } line, *Line; 194 195 #define COMPLETE_MAX_WORD_LEN 256 196 #define COMPLETE_MAX_MATCHES 100 197 198 #define COMPLETE_INIT 0 199 #define COMPLETE_ENUMERATE 1 200 #define COMPLETE_CLOSE 2 201 202 typedef int (*RlcCompleteFunc)(struct _complete_data *); 203 204 typedef struct _complete_data 205 { Line line; /* line we are completing */ 206 int call_type; /* COMPLETE_* */ 207 int replace_from; /* index to start replacement */ 208 int quote; /* closing quote */ 209 int case_insensitive; /* if TRUE: insensitive match */ 210 TCHAR candidate[COMPLETE_MAX_WORD_LEN]; 211 TCHAR buf_handle[COMPLETE_MAX_WORD_LEN]; 212 RlcCompleteFunc function; /* function for continuation */ 213 void *ptr_handle; /* pointer handle for client */ 214 intptr_t num_handle; /* numeric handle for client */ 215 } rlc_complete_data, *RlcCompleteData; 216 217 _export RlcCompleteFunc rlc_complete_hook(RlcCompleteFunc func); 218 219 _export TCHAR *read_line(rlc_console console); 220 _export int rlc_complete_file_function(RlcCompleteData data); 221 _export void rlc_init_history(rlc_console c, int size); 222 _export void rlc_add_history(rlc_console c, const TCHAR *line); 223 _export int rlc_bind(int chr, const char *fname); 224 225 #endif /* _CONSOLE_H_INCLUDED */ 226