Back to index

tetex-bin  3.0
lib_ins_wch.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 2002,2003 Free Software Foundation, Inc.                   *
00003  *                                                                          *
00004  * Permission is hereby granted, free of charge, to any person obtaining a  *
00005  * copy of this software and associated documentation files (the            *
00006  * "Software"), to deal in the Software without restriction, including      *
00007  * without limitation the rights to use, copy, modify, merge, publish,      *
00008  * distribute, distribute with modifications, sublicense, and/or sell       *
00009  * copies of the Software, and to permit persons to whom the Software is    *
00010  * furnished to do so, subject to the following conditions:                 *
00011  *                                                                          *
00012  * The above copyright notice and this permission notice shall be included  *
00013  * in all copies or substantial portions of the Software.                   *
00014  *                                                                          *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
00016  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
00018  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
00020  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
00021  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
00022  *                                                                          *
00023  * Except as contained in this notice, the name(s) of the above copyright   *
00024  * holders shall not be used in advertising or otherwise to promote the     *
00025  * sale, use or other dealings in this Software without prior written       *
00026  * authorization.                                                           *
00027  ****************************************************************************/
00028 
00029 /****************************************************************************
00030  *  Author: Thomas Dickey 2002                                              *
00031  ****************************************************************************/
00032 
00033 /*
00034 **     lib_ins_wch.c
00035 **
00036 **     The routine wins_wch().
00037 **
00038 */
00039 
00040 #include <curses.priv.h>
00041 
00042 MODULE_ID("$Id: lib_ins_wch.c,v 1.3 2003/03/29 21:52:29 tom Exp $")
00043 
00044 /*
00045  * Insert the given character, updating the current location to simplify
00046  * inserting a string.
00047  */
00048 static void
00049 _nc_insert_wch(WINDOW *win, const cchar_t * wch)
00050 {
00051     if (win->_curx <= win->_maxx) {
00052        struct ldat *line = &(win->_line[win->_cury]);
00053        NCURSES_CH_T *end = &(line->text[win->_curx]);
00054        NCURSES_CH_T *temp1 = &(line->text[win->_maxx]);
00055        NCURSES_CH_T *temp2 = temp1 - 1;
00056 
00057        CHANGED_TO_EOL(line, win->_curx, win->_maxx);
00058        while (temp1 > end)
00059            *temp1-- = *temp2--;
00060 
00061        *temp1 = _nc_render(win, *wch);
00062 
00063        win->_curx++;
00064     }
00065 }
00066 
00067 NCURSES_EXPORT(int)
00068 wins_wch(WINDOW *win, const cchar_t * wch)
00069 {
00070     NCURSES_SIZE_T oy;
00071     NCURSES_SIZE_T ox;
00072     int code = ERR;
00073 
00074     T((T_CALLED("wins_wch(%p, %s)"), win, _tracecchar_t(wch)));
00075 
00076     if (win != 0) {
00077        oy = win->_cury;
00078        ox = win->_curx;
00079 
00080        _nc_insert_wch(win, wch);
00081 
00082        win->_curx = ox;
00083        win->_cury = oy;
00084        _nc_synchook(win);
00085        code = OK;
00086     }
00087     returnCode(code);
00088 }
00089 
00090 NCURSES_EXPORT(int)
00091 wins_nwstr(WINDOW *win, const wchar_t * wstr, int n)
00092 {
00093     int code = ERR;
00094     NCURSES_SIZE_T oy;
00095     NCURSES_SIZE_T ox;
00096     const wchar_t *cp;
00097 
00098     T((T_CALLED("wins_nwstr(%p,%s,%d)"), win, _nc_viswbufn(wstr, n), n));
00099 
00100     if (win != 0
00101        && wstr != 0) {
00102        if (n < 1)
00103            n = wcslen(wstr);
00104        if (n > 0) {
00105            oy = win->_cury;
00106            ox = win->_curx;
00107            for (cp = wstr; *cp && ((cp - wstr) < n); cp++) {
00108               if (wcwidth(*cp) > 1) {
00109                   cchar_t tmp_cchar;
00110                   wchar_t tmp_wchar = *cp;
00111                   memset(&tmp_cchar, 0, sizeof(tmp_cchar));
00112                   (void) setcchar(&tmp_cchar,
00113                                 &tmp_wchar,
00114                                 WA_NORMAL,
00115                                 0,
00116                                 (void *) 0);
00117                   _nc_insert_wch(win, &tmp_cchar);
00118               } else {
00119                   _nc_insert_ch(win, *cp);       /* tabs, other ASCII stuff */
00120               }
00121            }
00122 
00123            win->_curx = ox;
00124            win->_cury = oy;
00125            _nc_synchook(win);
00126        }
00127        code = OK;
00128     }
00129     returnCode(code);
00130 }