• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ui/curswa.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //
00003 // $Id: curswa.h 3351 2010-09-17 21:55:30Z java $
00004 //
00005 // Copyright (C) 2008-2010  Rafael Ostertag
00006 //
00007 // This file is part of YAPET.
00008 //
00009 // YAPET is free software: you can redistribute it and/or modify it under the
00010 // terms of the GNU General Public License as published by the Free Software
00011 // Foundation, either version 3 of the License, or (at your option) any later
00012 // version.
00013 //
00014 // YAPET is distributed in the hope that it will be useful, but WITHOUT ANY
00015 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00016 // FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00017 // details.
00018 //
00019 // You should have received a copy of the GNU General Public License along with
00020 // YAPET.  If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 
00061 #ifndef _CURSWA_H
00062 #define _CURSWA_H
00063 
00064 #ifdef HAVE_CONFIG_H
00065 # include <config.h>
00066 #endif
00067 
00068 
00069 enum {
00070 #ifdef KEY_REFRESH
00071 #undef KEY_REFRESH
00072 
00076     KEY_REFRESH = 12,
00077 #endif // KEY_REFRESH
00078 #ifndef KEY_ESC
00079 
00082     KEY_ESC = 27,
00083 #endif // KEY_ESC
00084 #ifndef KEY_TAB
00085 
00088     KEY_TAB = '\t',
00089 #endif // KEY_TAB
00090 #ifndef KEY_SPACE
00091 
00094     KEY_SPACE = ' ',
00095 #endif // KEY_SPACE
00096     /* Used by InputWidget to indicate that the read-only mode should be
00097        left */
00098     KEY_CTRL_E = 5
00099 };
00100 
00106 inline void
00107 visibleCursor (bool v) {
00108     if (v) {
00109         int err = curs_set (2);
00110 
00111         if (err == ERR) curs_set (1);
00112     } else {
00113         curs_set (0);
00114     }
00115 }
00116 
00117 
00118 #ifdef HAVE_CURSES_H
00119 
00120 #if defined(tab) && defined(_XOPEN_CURSES)
00121 #undef tab
00122 #endif
00123 
00124 #ifdef box
00125 #undef box
00126 inline int box (WINDOW* win, int verch, int horch) {
00127     return wborder (win, verch, verch, horch, horch, 0, 0, 0, 0);
00128 }
00129 #endif
00130 
00131 #ifdef clear
00132 #undef clear
00133 inline int clear() {
00134     return wclear (stdscr);
00135 }
00136 #endif
00137 
00138 #ifdef erase
00139 #undef erase
00140 inline int erase() {
00141     return werase (stdscr);
00142 }
00143 #endif
00144 
00145 #ifdef move
00146 #undef move
00147 inline int move (int y, int x) {
00148     return wmove (stdscr, y, x);
00149 }
00150 #endif
00151 
00152 #ifdef refresh
00153 #undef refresh
00154 inline int refresh() {
00155     return wrefresh (stdscr);
00156 }
00157 #endif
00158 
00159 #endif // HAVE_CURSES_H
00160 
00161 #ifdef WADDSTR_USE_CHAR
00162 #ifdef HAVE_STDLIB_H
00163 # include <stdlib.h>
00164 #endif
00165 #ifdef HAVE_STRING_H
00166 # include <string.h>
00167 #endif
00168 
00169 inline int waddstr_c (WINDOW* win, const char* str) {
00170     char* tmp_ptr = (char*) malloc (strlen (str) + 1);
00171     memcpy (tmp_ptr, str, strlen (str) + 1);
00172     int retval = waddstr (win, tmp_ptr);
00173     free (tmp_ptr);
00174     return retval;
00175 }
00176 #define mywaddstr(a,b) waddstr_c(a,b)
00177 #else // WADDSTR_USE_CHAR
00178 #define mywaddstr(a,b) waddstr(a,b)
00179 #endif // WADDSTR_USE_CHAR
00180 
00181 #ifdef MVWADDSTR_USE_CHAR
00182 #ifdef HAVE_STDLIB_H
00183 # include <stdlib.h>
00184 #endif
00185 #ifdef HAVE_STRING_H
00186 # include <string.h>
00187 #endif
00188 
00189 inline int mvwaddstr_c (WINDOW* win, int y, int x, const char* str) {
00190     char* tmp_ptr = (char*) malloc (strlen (str) + 1);
00191     memcpy (tmp_ptr, str, strlen (str) + 1);
00192     int retval = mvwaddstr (win, y, x, tmp_ptr);
00193     free (tmp_ptr);
00194     return retval;
00195 }
00196 #define mymvwaddstr(a,b,c,d) mvwaddstr_c(a,b,c,d)
00197 #else // MVWADDSTR_USE_CHAR
00198 #define mymvwaddstr(a,b,c,d) mvwaddstr(a,b,c,d)
00199 #endif // MVWADDSTR_USE_CHAR
00200 
00201 #ifdef MVWADDNSTR_USE_CHAR
00202 #ifdef HAVE_STDLIB_H
00203 # include <stdlib.h>
00204 #endif
00205 #ifdef HAVE_STRING_H
00206 # include <string.h>
00207 #endif
00208 
00209 inline int mvwaddnstr_c (WINDOW* win, int y, int x, const char* str, int n) {
00210     char* tmp_ptr = (char*) malloc (strlen (str) + 1);
00211     memcpy (tmp_ptr, str, strlen (str) + 1);
00212     int retval = mvwaddnstr (win, y, x, tmp_ptr, n);
00213     free (tmp_ptr);
00214     return retval;
00215 }
00216 #define mymvwaddnstr(a,b,c,d,e) mvwaddnstr_c(a,b,c,d,e)
00217 #else // MVWADDSTR_USE_CHAR
00218 #define mymvwaddnstr(a,b,c,d,e) mvwaddnstr(a,b,c,d,e)
00219 #endif // MVWADDSTR_USE_CHAR
00220 
00221 #if !defined(HAVE_MVWCHGAT) || ( defined(_XOPEN_CURSES) && !defined(__NCURSES_H) )
00222 
00223 #ifdef HAVE_ALLOCA_H
00224 # include <alloca.h>
00225 #endif
00226 
00227 inline int _mvwchgat_ (WINDOW* w, int y, int x, int n, int attr, short color, const void*) {
00228     char* buff = (char*) alloca (n);
00229 
00230     if (buff == NULL)
00231         return ERR;
00232 
00233     int retval = mvwinnstr (w, y, x, buff, n);
00234 
00235     if (retval == ERR)
00236         return retval;
00237 
00238     retval = wattron (w, attr | COLOR_PAIR (color) );
00239 
00240     if (retval == ERR)
00241         return retval;
00242 
00243     retval = mymvwaddnstr (w, y, x, buff, n);
00244 
00245     if (retval == ERR)
00246         return retval;
00247 
00248     retval = wattroff (w, attr | COLOR_PAIR (color) );
00249 
00250     if (retval == ERR)
00251         return retval;
00252 
00253     return OK;
00254 }
00255 
00256 #define mymvwchgat(a,b,c,d,e,f,g) _mvwchgat_(a,b,c,d,e,f,g)
00257 #else
00258 #define mymvwchgat(a,b,c,d,e,f,g) mvwchgat(a,b,c,d,e,f,g)
00259 #endif // HAVE_MVWCHGAT
00260 
00261 #endif // _CURSWA_H

Generated on Sun Sep 19 2010 15:37:13 for YAPET by  doxygen 1.7.1