diff --git a/x11/pdcclip.c b/x11/pdcclip.c index f630d35c..4196ca01 100644 --- a/x11/pdcclip.c +++ b/x11/pdcclip.c @@ -19,39 +19,38 @@ */ #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H -# include +# include #endif #include #ifdef PDCDEBUG -char *rcsid_PDCclip = "$Id: pdcclip.c,v 1.4 2006/01/03 07:34:43 wmcbrine Exp $"; +char *rcsid_PDCclip = "$Id: pdcclip.c,v 1.5 2006/01/11 06:46:24 wmcbrine Exp $"; #endif - /*man-start********************************************************************* PDC_getclipboard() - Gets the contents of the clipboard PDCurses Description: - This is a PDCurses only routine. + This is a PDCurses only routine. - Gets the textual contents of the system's clipboard. This - function returns the contents of the clipboard in the contents - argument. It is the responsibilitiy of the caller to free the - memory returned with the PDC_freeclipboard() call. The length of the - clipboard contents is returned in the length argument. + Gets the textual contents of the system's clipboard. This + function returns the contents of the clipboard in the contents + argument. It is the responsibilitiy of the caller to free the + memory returned with the PDC_freeclipboard() call. The length + of the clipboard contents is returned in the length argument. PDCurses Return Value: - indicator of success/failure of call. - PDC_CLIP_SUCCESS the call was successful - PDC_CLIP_ACCESS_ERROR an error occured while accessing the - clipboard - PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for - the clipboard contents - PDC_CLIP_EMPTY the clipboard contains no text + indicator of success/failure of call. + PDC_CLIP_SUCCESS the call was successful + PDC_CLIP_ACCESS_ERROR an error occured while accessing the + clipboard + PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for + the clipboard contents + PDC_CLIP_EMPTY the clipboard contains no text Portability: - PDCurses int PDC_getclipboard( char **contents, long *length ); + PDCurses int PDC_getclipboard(char **contents, long *length); **man-end**********************************************************************/ @@ -59,28 +58,27 @@ int PDC_CDECL PDC_getclipboard(char **contents, long *length) { PDC_LOG(("PDC_getclipboard() - called\n")); - return XCurses_getclipboard( contents, length ); + return XCurses_getclipboard(contents, length); } - /*man-start********************************************************************* PDC_setclipboard() - Sets the contents of the clipboard PDCurses Description: - This is a PDCurses only routine. + This is a PDCurses only routine. - Copies the supplied text into the system's clipboard, emptying - the clipboard prior to the copy. + Copies the supplied text into the system's clipboard, emptying + the clipboard prior to the copy. PDCurses Return Value: - indicator of success/failure of call. - PDC_CLIP_SUCCESS the call was successful - PDC_CLIP_ACCESS_ERROR an error occured while accessing the - clipboard + indicator of success/failure of call. + PDC_CLIP_SUCCESS the call was successful + PDC_CLIP_ACCESS_ERROR an error occured while accessing the + clipboard Portability: - PDCurses int PDC_getclipboard( char *contents, long length ); + PDCurses int PDC_getclipboard(char *contents, long length); **man-end**********************************************************************/ @@ -88,23 +86,24 @@ int PDC_CDECL PDC_setclipboard(char *contents, long length) { PDC_LOG(("PDC_setclipboard() - called\n")); - return XCurses_setclipboard( contents, length ); + return XCurses_setclipboard(contents, length); } /*man-start********************************************************************* - PDC_freeclipboard() - Frees the memory associated with the contents of the clipboard + PDC_freeclipboard() - Frees the memory associated with the contents + of the clipboard PDCurses Description: - This is a PDCurses only routine. + This is a PDCurses only routine. - Frees the memory allocated by PDC_getclipboard(). + Frees the memory allocated by PDC_getclipboard(). PDCurses Return Value: - Always returns PDC_CLIP_SUCCESS + Always returns PDC_CLIP_SUCCESS Portability: - PDCurses int PDC_freeclipboard( char *contents ); + PDCurses int PDC_freeclipboard(char *contents); **man-end**********************************************************************/ @@ -121,19 +120,19 @@ int PDC_CDECL PDC_freeclipboard(char *contents) PDC_clearclipboard() - Clears the contents of the clipboard PDCurses Description: - This is a PDCurses only routine. + This is a PDCurses only routine. - Clears the internal clipboard. + Clears the internal clipboard. PDCurses Return Value: - Always returns PDC_CLIP_SUCCESS + Always returns PDC_CLIP_SUCCESS Portability: - PDCurses int PDC_clearclipboard( void ); + PDCurses int PDC_clearclipboard(void); **man-end**********************************************************************/ -int PDC_CDECL PDC_clearclipboard( void ) +int PDC_CDECL PDC_clearclipboard(void) { - return XCurses_clearclipboard( ); + return XCurses_clearclipboard(); } diff --git a/x11/pdcdisp.c b/x11/pdcdisp.c index 59341984..33154103 100644 --- a/x11/pdcdisp.c +++ b/x11/pdcdisp.c @@ -19,18 +19,18 @@ */ #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H -# include +# include #endif #include #include #ifdef HAVE_MEMORY_H -# include +# include #endif #ifdef PDCDEBUG -char *rcsid_PDCdisp = "$Id: pdcdisp.c,v 1.5 2006/01/03 19:54:29 wmcbrine Exp $"; +char *rcsid_PDCdisp = "$Id: pdcdisp.c,v 1.6 2006/01/11 06:46:24 wmcbrine Exp $"; #endif /*man-start********************************************************************* @@ -38,59 +38,57 @@ char *rcsid_PDCdisp = "$Id: pdcdisp.c,v 1.5 2006/01/03 19:54:29 wmcbrine Exp $" PDC_clr_update() - Updates the screen with a full redraw. PDCurses Description: - Updates the screen by clearing it and then redraw it in its - entirety. If SP->refrbrk is TRUE, and there is pending - input characters, the update will be prematurely terminated. + Updates the screen by clearing it and then redraw it in its + entirety. If SP->refrbrk is TRUE, and there is pending + input characters, the update will be prematurely terminated. PDCurses Return Value: - This routine returns ERR if it is unable to accomplish its task. + This routine returns ERR if it is unable to accomplish its task. - The return value OK is returned if there were no errors. + The return value OK is returned if there were no errors. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_clr_update( WINDOW* s ); + PDCurses int PDC_clr_update(WINDOW *s); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_clr_update(WINDOW *s) +int PDC_clr_update(WINDOW *s) #else -int PDC_clr_update(s) +int PDC_clr_update(s) WINDOW *s; #endif /***********************************************************************/ { - register int i=0; - WINDOW* w=NULL; - bool rc=FALSE; + int i; PDC_LOG(("PDC_clr_update() - called\n")); - w = curscr; - if (w == (WINDOW *)NULL) - return( ERR ); + if (curscr == (WINDOW *)NULL) + return ERR; s->_clear = FALSE; + for (i = 0; i < LINES; i++) /* update physical screen */ { - if (s != w) /* copy s to curscr */ - memcpy(w->_y[i], s->_y[i], COLS * sizeof(chtype)); - XCurses_transform_line(w->_y[i],i,0,COLS); + if (s != curscr) /* copy s to curscr */ + memcpy(curscr->_y[i], s->_y[i], COLS * sizeof(chtype)); - if (SP->refrbrk && (SP->cbreak || SP->raw_inp)) - { - rc = PDC_breakout(); - if(rc) - break; - } - w->_firstch[i] = _NO_CHANGE; - w->_lastch[i] = _NO_CHANGE; + XCurses_transform_line(curscr->_y[i], i, 0, COLS); + + if (SP->refrbrk && (SP->cbreak || SP->raw_inp) + && PDC_breakout()) + break; + + curscr->_firstch[i] = _NO_CHANGE; + curscr->_lastch[i] = _NO_CHANGE; } - return( OK ); + + return OK; } /*man-start********************************************************************* @@ -98,27 +96,27 @@ WINDOW *s; PDC_cursor_on() - Turns on the hardware cursor. PDCurses Description: - Turns on the hardware curses, it does nothing if it is already on. + Turns on the hardware curses, it does nothing if it is already on. PDCurses Return Value: - Returns OK upon success, ERR upon failure. + Returns OK upon success, ERR upon failure. Portability: - PDCurses int PDC_cursor_on( void ); + PDCurses int PDC_cursor_on(void); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_cursor_on(void) +int PDC_cursor_on(void) #else -int PDC_cursor_on() +int PDC_cursor_on() #endif /***********************************************************************/ { PDC_LOG(("PDC_cursor_on() - called\n")); - return( OK ); + return OK; } /*man-start********************************************************************* @@ -126,31 +124,30 @@ int PDC_cursor_on() PDC_cursor_off() - Turns off the hardware cursor. PDCurses Description: - Turns off the hardware curses, it does nothing if it is already off. + Turns off the hardware curses, it does nothing if it is already off. PDCurses Return Value: - Returns OK upon success, ERR upon failure. + Returns OK upon success, ERR upon failure. PDCurses Errors: - ERR will be returned if the hardware cursor - can not be disabled. + ERR will be returned if the hardware cursor can not be disabled. Portability: - PDCurses int PDC_cursor_off( void ); + PDCurses int PDC_cursor_off(void); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_cursor_off(void) +int PDC_cursor_off(void) #else -int PDC_cursor_off() +int PDC_cursor_off() #endif /***********************************************************************/ { PDC_LOG(("PDC_cursor_off() - called\n")); - return( OK ); + return OK; } /*man-start********************************************************************* @@ -158,37 +155,39 @@ int PDC_cursor_off() PDC_gotoxy() - position hardware cursor at (x, y) PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Moves the physical cursor to the desired address on the - screen. We don't optimize here -- on a PC, it takes more time - to optimize than to do things directly. + Moves the physical cursor to the desired address on the + screen. We don't optimize here -- on a PC, it takes more time + to optimize than to do things directly. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_gotoxy( int row, int col ); + PDCurses int PDC_gotoxy(int row, int col); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_gotoxy(int row, int col) +int PDC_gotoxy(int row, int col) #else -int PDC_gotoxy(row,col) +int PDC_gotoxy(row, col) int row; int col; #endif /***********************************************************************/ { - PDC_LOG(("PDC_gotoxy() - called: row %d col %d\n",row,col)); + PDC_LOG(("PDC_gotoxy() - called: row %d col %d\n", row, col)); - XCurses_display_cursor(SP->cursrow,SP->curscol,row,col,SP->visibility); - return(OK); + XCurses_display_cursor(SP->cursrow, SP->curscol, row, col, + SP->visibility); + + return OK; } /*man-start********************************************************************* @@ -196,59 +195,53 @@ int col; PDC_transform_line() - display a physical line of the screen PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - Updates the given physical line to look like the corresponding - line in _curscr. + Updates the given physical line to look like the corresponding + line in _curscr. PDCurses Return Value: - This routine returns TRUE if a premature refresh end - is allowed, and there is an input character pending. Otherwise, - FALSE is returned. + This routine returns TRUE if a premature refresh end is allowed, + and there is an input character pending. Otherwise, FALSE is + returned. PDCurses Errors: - No errors are defined for this routine. + No errors are defined for this routine. Portability: - PDCurses bool PDC_transform_line( int lineno ); + PDCurses bool PDC_transform_line(int lineno); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -bool PDC_transform_line(register int lineno) +bool PDC_transform_line(int lineno) #else -bool PDC_transform_line(lineno) -register int lineno; +bool PDC_transform_line(lineno) +int lineno; #endif /***********************************************************************/ { - register chtype* dstp=NULL; - int x=0; - int endx=0; - int len=0; - bool rc=FALSE; + chtype *dstp; + int x, endx, len; - PDC_LOG(("PDC_transform_line() - called: line %d\n",lineno)); + PDC_LOG(("PDC_transform_line() - called: line %d\n", lineno)); if (curscr == (WINDOW *)NULL) - return( FALSE ); + return FALSE; x = curscr->_firstch[lineno]; endx = curscr->_lastch[lineno]; dstp = curscr->_y[lineno] + x; - len = endx-x+1; + len = endx - x + 1; - XCurses_transform_line(dstp,lineno,x,len); + XCurses_transform_line(dstp, lineno, x, len); curscr->_firstch[lineno] = _NO_CHANGE; curscr->_lastch[lineno] = _NO_CHANGE; - if (SP->refrbrk && (SP->cbreak || SP->raw_inp)) - { - rc = PDC_breakout(); - if(rc) - return(TRUE); - } - return(FALSE); + if (SP->refrbrk && (SP->cbreak || SP->raw_inp) && PDC_breakout()) + return TRUE; + + return FALSE; } diff --git a/x11/pdcgetsc.c b/x11/pdcgetsc.c index ba6e598c..0295f140 100644 --- a/x11/pdcgetsc.c +++ b/x11/pdcgetsc.c @@ -19,12 +19,12 @@ */ #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H -# include +# include #endif #include #ifdef PDCDEBUG -char *rcsid_PDCgetsc = "$Id: pdcgetsc.c,v 1.2 2006/01/03 07:34:43 wmcbrine Exp $"; +char *rcsid_PDCgetsc = "$Id: pdcgetsc.c,v 1.3 2006/01/11 06:46:24 wmcbrine Exp $"; #endif /*man-start********************************************************************* @@ -32,33 +32,33 @@ char *rcsid_PDCgetsc = "$Id: pdcgetsc.c,v 1.2 2006/01/03 07:34:43 wmcbrine Exp PDC_get_columns() - return width of screen/viewport. PDCurses Description: - This is a private PDCurses function + This is a private PDCurses function - This function will return the width of the current screen. + This function will return the width of the current screen. PDCurses Return Value: - This routine will return OK upon success and otherwise ERR will be - returned. + This routine will return OK upon success and otherwise ERR will + be returned. PDCurses Errors: - There are no defined errors for this routine. + There are no defined errors for this routine. Portability: - PDCurses int PDC_get_columns( void ); + PDCurses int PDC_get_columns(void); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_get_columns(void) +int PDC_get_columns(void) #else -int PDC_get_columns() +int PDC_get_columns() #endif /***********************************************************************/ { PDC_LOG(("PDC_get_columns() - called\n")); - return(XCurses_get_cols()); + return XCurses_get_cols(); } /*man-start********************************************************************* @@ -66,33 +66,33 @@ int PDC_get_columns() PDC_get_rows() - Return number of screen rows. PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Returns the maximum number of rows supported by the display. - e.g. 25, 28, 43, 50, 60, 66... + Returns the maximum number of rows supported by the display. + e.g. 25, 28, 43, 50, 60, 66... PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_get_rows( void ); + PDCurses int PDC_get_rows(void); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_get_rows(void) +int PDC_get_rows(void) #else -int PDC_get_rows() +int PDC_get_rows() #endif /***********************************************************************/ { PDC_LOG(("PDC_get_rows() - called\n")); - return(XCurses_get_rows()); + return XCurses_get_rows(); } /*man-start********************************************************************* @@ -100,31 +100,31 @@ int PDC_get_rows() PDC_get_font() - Get the current font size PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - This function returns the current font size. This function only - works if the #define FAST_VIDEO is true. + This function returns the current font size. This function only + works if the #define FAST_VIDEO is true. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - An ERR will be returned if FAST_VIDEO is not true. + An ERR will be returned if FAST_VIDEO is not true. Portability: - PDCurses int PDC_get_font( void ); + PDCurses int PDC_get_font(void); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_get_font(void) +int PDC_get_font(void) #else -int PDC_get_font() +int PDC_get_font() #endif /***********************************************************************/ { PDC_LOG(("PDC_get_font() - called\n")); - return(OK); + return OK; } diff --git a/x11/pdckbd.c b/x11/pdckbd.c index e0e8dde9..590eb29c 100644 --- a/x11/pdckbd.c +++ b/x11/pdckbd.c @@ -20,12 +20,12 @@ #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H -# include +# include #endif #include #ifdef PDCDEBUG -char *rcsid_PDCkbd = "$Id: pdckbd.c,v 1.9 2006/01/03 19:54:29 wmcbrine Exp $"; +char *rcsid_PDCkbd = "$Id: pdckbd.c,v 1.10 2006/01/11 06:46:24 wmcbrine Exp $"; #endif /*man-start********************************************************************* @@ -33,19 +33,19 @@ char *rcsid_PDCkbd = "$Id: pdckbd.c,v 1.9 2006/01/03 19:54:29 wmcbrine Exp $"; PDC_get_input_fd() - Get file descriptor used for PDCurses input PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - This routine will return the file descriptor that PDCurses reads - its input from. It can be used for select(). + This routine will return the file descriptor that PDCurses reads + its input from. It can be used for select(). PDCurses Return Value: - Returns a file descriptor. + Returns a file descriptor. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_get_input_fd( void ); + PDCurses int PDC_get_input_fd(void); **man-end**********************************************************************/ @@ -67,19 +67,19 @@ unsigned long PDC_get_input_fd() PDC_check_bios_key() - Check BIOS key data area for input PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - This routine will check the BIOS for any indication that - keystrokes are pending. + This routine will check the BIOS for any indication that + keystrokes are pending. PDCurses Return Value: - Returns 1 if a keyboard character is available, 0 otherwise. + Returns 1 if a keyboard character is available, 0 otherwise. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses bool PDC_check_bios_key( void ); + PDCurses bool PDC_check_bios_key(void); **man-end**********************************************************************/ @@ -93,7 +93,7 @@ bool PDC_check_bios_key() { PDC_LOG(("PDC_check_bios_key() - called\n")); - return(XCurses_kbhit()); + return XCurses_kbhit(); } /*man-start********************************************************************* @@ -101,89 +101,82 @@ bool PDC_check_bios_key() PDC_get_ctrl_break() - return OS control break state PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Returns the current OS Control Break Check state. + Returns the current OS Control Break Check state. PDCurses Return Value: - This function returns TRUE if the Control Break - Check is enabled otherwise FALSE is returned. + This function returns TRUE if the Control Break + Check is enabled otherwise FALSE is returned. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses bool PDC_get_ctrl_break( void ); + PDCurses bool PDC_get_ctrl_break(void); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -bool PDC_get_ctrl_break(void) +bool PDC_get_ctrl_break(void) #else -bool PDC_get_ctrl_break() +bool PDC_get_ctrl_break() #endif /***********************************************************************/ { PDC_LOG(("PDC_get_ctrl_break() - called\n")); - return(FALSE); + return FALSE; } /*man-start********************************************************************* - PDC_rawgetch() - Returns the next uninterpreted character (if available). + PDC_rawgetch() - Returns the next uninterpreted character + (if available). PDCurses Description: - Gets a character without any interpretation at all and returns - it. If keypad mode is active for the designated window, - function key translation will be performed. Otherwise, - function keys are ignored. If nodelay mode is active in the - window, then PDC_rawgetch() returns -1 if no character is - available. + Gets a character without any interpretation at all and returns + it. If keypad mode is active for the designated window, + function key translation will be performed. Otherwise, + function keys are ignored. If nodelay mode is active in the + window, then PDC_rawgetch() returns -1 if no character is + available. - WARNING: It is unknown whether the FUNCTION key translation - is performed at this level. --Frotz 911130 BUG + WARNING: It is unknown whether the FUNCTION key translation + is performed at this level. --Frotz 911130 BUG PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_rawgetch( void ); + PDCurses int PDC_rawgetch(void); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_rawgetch(void) +int PDC_rawgetch(void) #else -int PDC_rawgetch() +int PDC_rawgetch() #endif /***********************************************************************/ { - extern WINDOW* _getch_win_; + extern WINDOW *_getch_win_; - int c; - bool return_immediately; + PDC_LOG(("PDC_rawgetch() - called\n")); - PDC_LOG(("PDC_rawgetch() - called\n")); + if (_getch_win_ == (WINDOW *)NULL) + return -1; - if (_getch_win_ == (WINDOW *)NULL) /* @@ */ - return( -1 ); + if ((SP->delaytenths || _getch_win_->_delayms || _getch_win_->_nodelay) + && !PDC_breakout()) + return -1; - if (SP->delaytenths || _getch_win_->_delayms || _getch_win_->_nodelay) - return_immediately = TRUE; - else - return_immediately = FALSE; - - if (return_immediately && !PDC_breakout()) - return( -1 ); - - c = XCurses_rawgetch( 0 ); - return(c); + return XCurses_rawgetch(0); } /*man-start********************************************************************* @@ -191,70 +184,70 @@ int PDC_rawgetch() PDC_set_ctrl_break() - Enables/Disables the host OS BREAK key check. PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Enables/Disables the host OS BREAK key check. If the supplied setting - is TRUE, this enables CTRL/C and CTRL/BREAK to abort the process. - If FALSE, CTRL/C and CTRL/BREAK are ignored. + Enables/Disables the host OS BREAK key check. If the supplied + setting is TRUE, this enables CTRL/C and CTRL/BREAK to abort the + process. If FALSE, CTRL/C and CTRL/BREAK are ignored. PDCurses Return Value: - This function returns OK on success and ERR on error. + This function returns OK on success and ERR on error. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_set_ctrl_break( bool setting ); + PDCurses int PDC_set_ctrl_break(bool setting); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_set_ctrl_break(bool setting) +int PDC_set_ctrl_break(bool setting) #else -int PDC_set_ctrl_break(setting) +int PDC_set_ctrl_break(setting) bool setting; #endif /***********************************************************************/ { PDC_LOG(("PDC_set_ctrl_break() - called\n")); - return(OK); + return OK; } /*man-start********************************************************************* - PDC_get_key_modifiers() - Returns the keyboard modifier(s) at time of last getch() + PDC_get_key_modifiers() - Returns the keyboard modifier(s) + at time of last getch() PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Returns the keyboard modifiers effective at the time of the last getch() - call only if PDC_save_key_modifiers(TRUE) has been called before the - getch(); - Use the macros; PDC_KEY_MODIFIER_* to determine which modifier(s) - were set. + Returns the keyboard modifiers effective at the time of the last + getch() call only if PDC_save_key_modifiers(TRUE) has been + called before the getch(). Use the macros; PDC_KEY_MODIFIER_* to + determine which modifier(s) were set. PDCurses Return Value: - This function returns the modifiers. + This function returns the modifiers. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_get_key_modifiers( void ); + PDCurses int PDC_get_key_modifiers(void); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -unsigned long PDC_get_key_modifiers(void) +unsigned long PDC_get_key_modifiers(void) #else -unsigned long PDC_get_key_modifiers() +unsigned long PDC_get_key_modifiers() #endif /***********************************************************************/ { PDC_LOG(("PDC_get_key_modifiers() - called\n")); - return(XCurses_get_key_modifiers()); + return XCurses_get_key_modifiers(); } diff --git a/x11/pdcprint.c b/x11/pdcprint.c index 39c3969e..598ddc2f 100644 --- a/x11/pdcprint.c +++ b/x11/pdcprint.c @@ -19,12 +19,12 @@ */ #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H -# include +# include #endif #include #ifdef PDCDEBUG -char *rcsid_PDCprint = "$Id: pdcprint.c,v 1.2 2006/01/03 07:34:43 wmcbrine Exp $"; +char *rcsid_PDCprint = "$Id: pdcprint.c,v 1.3 2006/01/11 06:46:24 wmcbrine Exp $"; #endif @@ -33,30 +33,30 @@ char *rcsid_PDCprint = "$Id: pdcprint.c,v 1.2 2006/01/03 07:34:43 wmcbrine Exp PDC_print() - Provides primitive access to the BIOS printer functions PDCurses Description: - This is a private PDCurses routine. + This is a private PDCurses routine. - Implements write/init/read printer services at the BIOS level. + Implements write/init/read printer services at the BIOS level. - This provides the basic support that PDCurses needs to dump the - contents of windows or pads to the printer attached to the BIOS - printer port. + This provides the basic support that PDCurses needs to dump the + contents of windows or pads to the printer attached to the BIOS + printer port. PDCurses Return Value: - See the BIOS INT 0x17 specifications. + See the BIOS INT 0x17 specifications. PDCurses Errors: - See the BIOS INT 0x17 specifications. + See the BIOS INT 0x17 specifications. Portability: - PDCurses int PDC_print( int cmd, int byte, int port ); + PDCurses int PDC_print(int cmd, int byte, int port); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_print(int cmd, int byte, int port) +int PDC_print(int cmd, int byte, int port) #else -int PDC_print(cmd,byte,port) +int PDC_print(cmd, byte, port) int cmd; int byte; int port; @@ -65,6 +65,5 @@ int port; { PDC_LOG(("PDC_print() - called\n")); - /* to be done */ - return(OK); + return OK; } diff --git a/x11/pdcscrn.c b/x11/pdcscrn.c index db8f9c8f..6cef03f6 100644 --- a/x11/pdcscrn.c +++ b/x11/pdcscrn.c @@ -19,40 +19,41 @@ */ #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H -# include +# include #endif #include #ifdef PDCDEBUG -char *rcsid_PDCscrn = "$Id: pdcscrn.c,v 1.6 2006/01/03 19:54:29 wmcbrine Exp $"; +char *rcsid_PDCscrn = "$Id: pdcscrn.c,v 1.7 2006/01/11 06:46:24 wmcbrine Exp $"; #endif -bool GLOBAL_sb_on=FALSE; -bool GLOBAL_slk_on=FALSE; +bool GLOBAL_sb_on = FALSE; +bool GLOBAL_slk_on = FALSE; /*man-start********************************************************************* - PDC_scr_close() - Internal low-level binding to close the physical screen + PDC_scr_close() - Internal low-level binding to close the + physical screen PDCurses Description: - This is a nop for the DOS platform. + This is a nop for the DOS platform. PDCurses Return Value: - This function returns OK on success, otherwise an ERR is returned. + This function returns OK on success, otherwise an ERR is returned. PDCurses Errors: - The DOS platform will never fail. + The DOS platform will never fail. Portability: - PDCurses int PDC_scr_close( void ); + PDCurses int PDC_scr_close(void); **man-end**********************************************************************/ -int PDC_scr_close(void) +int PDC_scr_close(void) { PDC_LOG(("PDC_scr_close() - called\n")); - return( OK ); + return OK; } /*man-start********************************************************************* @@ -60,27 +61,28 @@ int PDC_scr_close(void) PDC_scrn_modes_equal() - Decide if two screen modes are equal PDCurses Description: - Mainly required for OS/2. It decides if two screen modes - (VIOMODEINFO structure) are equal. Under DOS it just compares - two integers + Mainly required for OS/2. It decides if two screen modes + (VIOMODEINFO structure) are equal. Under DOS it just compares + two integers PDCurses Return Value: - This function returns TRUE if equal else FALSe. + This function returns TRUE if equal else FALSe. PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses int PDC_scrn_modes_equal( int mode1, int mode2 ); - OS2 PDCurses int PDC_scrn_modes_equal( VIOMODEINFO mode1, VIOMODEINFO mode2 ); + PDCurses int PDC_scrn_modes_equal(int mode1, int mode2); + OS2 PDCurses int PDC_scrn_modes_equal(VIOMODEINFO mode1, + VIOMODEINFO mode2); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -bool PDC_scrn_modes_equal(int mode1, int mode2) +bool PDC_scrn_modes_equal(int mode1, int mode2) #else -bool PDC_scrn_modes_equal(mode1,mode2) +bool PDC_scrn_modes_equal(mode1, mode2) int mode1; int mode2; #endif @@ -93,27 +95,28 @@ int mode2; /*man-start********************************************************************* - PDC_scr_open() - Internal low-level binding to open the physical screen + PDC_scr_open() - Internal low-level binding to open the physical + screen PDCurses Description: This is a NOP in DOS. PDCurses Return Value: - This function returns OK on success, otherwise an ERR is returned. + This function returns OK on success, otherwise an ERR is returned. PDCurses Errors: - The DOS platform will never fail. + The DOS platform will never fail. Portability: - PDCurses int PDC_scr_open( SCREEN* internal, bool echo ); + PDCurses int PDC_scr_open(SCREEN *internal, bool echo); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_scr_open(SCREEN *internal, bool echo) +int PDC_scr_open(SCREEN *internal, bool echo) #else -int PDC_scr_open(internal,echo) +int PDC_scr_open(internal, echo) SCREEN *internal; bool echo; #endif @@ -124,7 +127,7 @@ bool echo; PDC_LOG(("PDC_scr_open() - called\n")); internal->cursrow = internal->curscol = 0; - internal->direct_video = FALSE; /* Assume that we can't */ + internal->direct_video = FALSE; /* Assume that we can't */ internal->autocr = TRUE; /* lf -> crlf by default */ internal->raw_out = FALSE; /* tty I/O modes */ internal->raw_inp = FALSE; /* tty I/O modes */ @@ -159,7 +162,7 @@ bool echo; internal->sb_cur_x = 0; internal->line_color = COLOR_WHITE; - return( OK ); + return OK; } /*man-start********************************************************************* @@ -167,35 +170,33 @@ bool echo; PDC_resize_screen() - Internal low-level function to resize screen PDCurses Description: - This function provides a means for the application program to - resize the overall dimensions of the screen. Under DOS and OS/2 - the application can tell PDCurses what size to make the screen; - under X11, resizing is done by the user and this function simply - adjusts its internal structures to fit the new size. + This function provides a means for the application program to + resize the overall dimensions of the screen. Under DOS and OS/2 + the application can tell PDCurses what size to make the screen; + under X11, resizing is done by the user and this function simply + adjusts its internal structures to fit the new size. PDCurses Return Value: - This function returns OK on success, otherwise an ERR is returned. + This function returns OK on success, otherwise an ERR is returned. PDCurses Errors: Portability: - PDCurses int PDC_resize_screen( int, int ); + PDCurses int PDC_resize_screen(int, int); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_resize_screen(int nlines, int ncols) +int PDC_resize_screen(int nlines, int ncols) #else -int PDC_resize_screen(nlines, ncols) -int nlines,ncols; +int PDC_resize_screen(nlines, ncols) +int nlines, ncols; #endif /***********************************************************************/ { - int rc=OK; + PDC_LOG(("PDC_resize_screen() - called. Lines: %d Cols: %d\n", + nlines, ncols)); - PDC_LOG(("PDC_resize_screen() - called. Lines: %d Cols: %d\n",nlines,ncols)); - - rc = XCursesResizeScreen(nlines,ncols); - return (rc); + return XCursesResizeScreen(nlines, ncols); } diff --git a/x11/pdcsetsc.c b/x11/pdcsetsc.c index 234b4697..e9814608 100644 --- a/x11/pdcsetsc.c +++ b/x11/pdcsetsc.c @@ -19,51 +19,50 @@ */ #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H -# include +# include #endif #include #ifdef PDCDEBUG -char *rcsid_PDCsetsc = "$Id: pdcsetsc.c,v 1.4 2006/01/03 19:54:29 wmcbrine Exp $"; +char *rcsid_PDCsetsc = "$Id: pdcsetsc.c,v 1.5 2006/01/11 06:46:24 wmcbrine Exp $"; #endif - /*man-start********************************************************************* PDC_set_font() - sets the current font size PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - This routine sets the current font size, if the adapter allows - such a change. + This routine sets the current font size, if the adapter allows + such a change. PDCurses Return Value: - This function returns OK upon success otherwise ERR is returned. + This function returns OK upon success otherwise ERR is returned. PDCurses Errors: - It is an error to attempt to change the font size on a "bogus" - adapter. The reason for this is that we have a known video - adapter identity problem. e.g. Two adapters report the same - identifying characteristics. + It is an error to attempt to change the font size on a "bogus" + adapter. The reason for this is that we have a known video + adapter identity problem. e.g. Two adapters report the same + identifying characteristics. Portability: - PDCurses int PDC_set_font( int size ); + PDCurses int PDC_set_font(int size); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_set_font(int size) +int PDC_set_font(int size) #else -int PDC_set_font(size) +int PDC_set_font(size) int size; #endif /***********************************************************************/ { PDC_LOG(("PDC_set_font() - called\n")); - return(OK); + return OK; } /*man-start********************************************************************* @@ -71,57 +70,60 @@ int size; PDC_set_rows() - sets the physical number of rows on screen PDCurses Description: - This is a private PDCurses function. + This is a private PDCurses function. - This routine attempts to set the number of rows on the physical - screen to the passed value. + This routine attempts to set the number of rows on the physical + screen to the passed value. PDCurses Return Value: - This function returns OK upon success otherwise ERR is returned. + This function returns OK upon success otherwise ERR is returned. PDCurses Errors: - It is an error to attempt to change the screen size on a "bogus" - adapter. The reason for this is that we have a known video - adapter identity problem. e.g. Two adapters report the same - identifying characteristics. + It is an error to attempt to change the screen size on a "bogus" + adapter. The reason for this is that we have a known video + adapter identity problem. e.g. Two adapters report the same + identifying characteristics. Portability: - PDCurses int PDC_set_rows( int rows ); + PDCurses int PDC_set_rows(int rows); **man-end**********************************************************************/ /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_set_rows(int rows) +int PDC_set_rows(int rows) #else -int PDC_set_rows(rows) +int PDC_set_rows(rows) int rows; #endif /***********************************************************************/ { PDC_LOG(("PDC_set_rows() - called\n")); - return(0); + return 0; } + /***********************************************************************/ #ifdef HAVE_PROTO -int PDC_curs_set(int visibility) +int PDC_curs_set(int visibility) #else -int PDC_curs_set(visibility) +int PDC_curs_set(visibility) int visibility; #endif /***********************************************************************/ { - int ret_vis = SP->visibility; + int ret_vis = SP->visibility; - PDC_LOG(("PDC_curs_set() - called: visibility=%d\n",visibility)); + PDC_LOG(("PDC_curs_set() - called: visibility=%d\n", + visibility)); - if ( visibility != -1 ) - { - SP->visibility = visibility; - } - XCurses_display_cursor(SP->cursrow,SP->curscol,SP->cursrow,SP->curscol,visibility); - return(ret_vis); + if (visibility != -1) + SP->visibility = visibility; + + XCurses_display_cursor(SP->cursrow, SP->curscol, SP->cursrow, + SP->curscol, visibility); + + return ret_vis; } /*man-start********************************************************************* @@ -129,30 +131,30 @@ int visibility; PDC_set_title() - Set window title PDCurses Description: - Sets the title of the window in which the curses program is running. - This function may not do anything on some platforms. + Sets the title of the window in which the curses program is running. + This function may not do anything on some platforms. PDCurses Return Value: - N/A + N/A PDCurses Errors: - No errors are defined for this function. + No errors are defined for this function. Portability: - PDCurses void PDC_set_title( char *title ); + PDCurses void PDC_set_title(char *title); **man-end**********************************************************************/ + /***********************************************************************/ #ifdef HAVE_PROTO -void PDC_set_title(char *title) +void PDC_set_title(char *title) #else -void PDC_set_title(title) +void PDC_set_title(title) char *title; #endif /***********************************************************************/ { - PDC_LOG(("PDC_set_title() - called:<%s>\n",title)); + PDC_LOG(("PDC_set_title() - called:<%s>\n", title)); XCurses_set_title(title); - return; } diff --git a/x11/pdcx11.c b/x11/pdcx11.c index 0e4d15c3..396b4edd 100644 --- a/x11/pdcx11.c +++ b/x11/pdcx11.c @@ -21,7 +21,6 @@ *************************************************************************** */ -#if defined(XCURSES) #include "pdcx11.h" AppData app_data; @@ -37,78 +36,82 @@ AppData app_data; /***************************************************************************/ #define BIG_ICON_WIDTH 64 #define BIG_ICON_HEIGHT 64 -static unsigned char big_icon_bitmap_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, - 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0xc0, 0x00, 0x00, - 0x00, 0x00, 0xfc, 0x03, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, - 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0x00, 0x18, 0x00, 0x00, - 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x1f, - 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x06, 0x00, 0x00, - 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x80, 0x7f, - 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xfe, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, - 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x33, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xf8, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, - 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0e, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x60, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, - 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x7f, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x98, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, - 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xfe, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x03, 0xfc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, - 0xfc, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xf8, 0x07, 0x00, 0x00, - 0x00, 0x00, 0xc0, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, - 0xe0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0xe0, 0x1f, 0x00, 0x00, - 0x00, 0x00, 0x18, 0x00, 0xc0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, - 0x80, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0xff, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x23, 0x50, 0x1e, - 0x7c, 0xf0, 0xe0, 0x03, 0x60, 0x26, 0x50, 0x33, 0xc6, 0x98, 0x31, 0x06, - 0x30, 0x2c, 0xd0, 0x61, 0x83, 0x0d, 0x1b, 0x0c, 0x10, 0x28, 0xd0, 0x40, - 0x01, 0x05, 0x0a, 0x08, 0x10, 0x20, 0x50, 0x00, 0x01, 0x05, 0x0a, 0x08, - 0x10, 0x20, 0x50, 0x00, 0x03, 0x04, 0x1a, 0x00, 0x10, 0x20, 0x50, 0x00, - 0x06, 0x04, 0x32, 0x00, 0x10, 0x20, 0x50, 0x00, 0x7c, 0xfc, 0xe3, 0x03, - 0x10, 0x20, 0x50, 0x00, 0xc0, 0x04, 0x00, 0x06, 0x10, 0x20, 0x50, 0x00, - 0x80, 0x05, 0x00, 0x0c, 0x10, 0x20, 0x50, 0x00, 0x01, 0x05, 0x0a, 0x08, - 0x10, 0x28, 0x50, 0x00, 0x01, 0x05, 0x0a, 0x08, 0x30, 0x6c, 0x58, 0x00, - 0x83, 0x0d, 0x1b, 0x0c, 0x60, 0xc6, 0x4c, 0x00, 0xc6, 0x98, 0x31, 0x06, - 0xc0, 0x83, 0x47, 0x00, 0x7c, 0xf0, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +static unsigned char big_icon_bitmap_bits[] = +{ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, + 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0xc0, 0x00, 0x00, + 0x00, 0x00, 0xfc, 0x03, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, + 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0x00, 0x18, 0x00, 0x00, + 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x1f, + 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x06, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x80, 0x7f, + 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xfe, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, + 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x33, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf8, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, + 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x60, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, + 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x7f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x98, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, + 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xfe, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0xfc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, + 0xfc, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xf8, 0x07, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, + 0xe0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0xe0, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0x18, 0x00, 0xc0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, + 0x80, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0xff, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x23, 0x50, 0x1e, + 0x7c, 0xf0, 0xe0, 0x03, 0x60, 0x26, 0x50, 0x33, 0xc6, 0x98, 0x31, 0x06, + 0x30, 0x2c, 0xd0, 0x61, 0x83, 0x0d, 0x1b, 0x0c, 0x10, 0x28, 0xd0, 0x40, + 0x01, 0x05, 0x0a, 0x08, 0x10, 0x20, 0x50, 0x00, 0x01, 0x05, 0x0a, 0x08, + 0x10, 0x20, 0x50, 0x00, 0x03, 0x04, 0x1a, 0x00, 0x10, 0x20, 0x50, 0x00, + 0x06, 0x04, 0x32, 0x00, 0x10, 0x20, 0x50, 0x00, 0x7c, 0xfc, 0xe3, 0x03, + 0x10, 0x20, 0x50, 0x00, 0xc0, 0x04, 0x00, 0x06, 0x10, 0x20, 0x50, 0x00, + 0x80, 0x05, 0x00, 0x0c, 0x10, 0x20, 0x50, 0x00, 0x01, 0x05, 0x0a, 0x08, + 0x10, 0x28, 0x50, 0x00, 0x01, 0x05, 0x0a, 0x08, 0x30, 0x6c, 0x58, 0x00, + 0x83, 0x0d, 0x1b, 0x0c, 0x60, 0xc6, 0x4c, 0x00, 0xc6, 0x98, 0x31, 0x06, + 0xc0, 0x83, 0x47, 0x00, 0x7c, 0xf0, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; #define LITTLE_ICON_WIDTH 32 #define LITTLE_ICON_HEIGHT 32 -static unsigned char little_icon_bitmap_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x80, 0x07, 0x00, 0x01, 0x00, 0x0f, 0x80, 0x00, 0x00, 0x1e, 0x40, 0x00, - 0x00, 0x3c, 0x20, 0x00, 0x00, 0x78, 0x10, 0x00, 0x00, 0xf0, 0x08, 0x00, - 0x00, 0xe0, 0x05, 0x00, 0x00, 0xc0, 0x06, 0x00, 0x00, 0x40, 0x07, 0x00, - 0x00, 0x20, 0x0f, 0x00, 0x00, 0x10, 0x1e, 0x00, 0x00, 0x08, 0x3c, 0x00, - 0x00, 0x04, 0x78, 0x00, 0x00, 0x02, 0xf0, 0x00, 0x00, 0x01, 0xe0, 0x01, - 0x80, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x4c, 0x2a, 0xc6, 0x18, 0x52, 0x5a, 0x29, 0x25, 0x42, 0x0a, 0x29, 0x25, - 0x42, 0x0a, 0xe2, 0x09, 0x42, 0x0a, 0x24, 0x10, 0x42, 0x0a, 0x29, 0x20, - 0x52, 0x0a, 0x29, 0x25, 0x8c, 0x09, 0xc6, 0x18, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - +static unsigned char little_icon_bitmap_bits[] = +{ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x07, 0x00, 0x01, 0x00, 0x0f, 0x80, 0x00, 0x00, 0x1e, 0x40, 0x00, + 0x00, 0x3c, 0x20, 0x00, 0x00, 0x78, 0x10, 0x00, 0x00, 0xf0, 0x08, 0x00, + 0x00, 0xe0, 0x05, 0x00, 0x00, 0xc0, 0x06, 0x00, 0x00, 0x40, 0x07, 0x00, + 0x00, 0x20, 0x0f, 0x00, 0x00, 0x10, 0x1e, 0x00, 0x00, 0x08, 0x3c, 0x00, + 0x00, 0x04, 0x78, 0x00, 0x00, 0x02, 0xf0, 0x00, 0x00, 0x01, 0xe0, 0x01, + 0x80, 0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x4c, 0x2a, 0xc6, 0x18, 0x52, 0x5a, 0x29, 0x25, 0x42, 0x0a, 0x29, 0x25, + 0x42, 0x0a, 0xe2, 0x09, 0x42, 0x0a, 0x24, 0x10, 0x42, 0x0a, 0x29, 0x20, + 0x52, 0x0a, 0x29, 0x25, 0x8c, 0x09, 0xc6, 0x18, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; struct XCursesKey { - int keycode; - int numkeypad; - int normal; - int shifted; - int control; - int alt; + int keycode; + int numkeypad; + int normal; + int shifted; + int control; + int alt; }; + typedef struct XCursesKey XCURSESKEY; XCURSESKEY XCursesKeys[] = @@ -242,7 +245,9 @@ XCURSESKEY XCursesKeys[] = #define MAX_COMPOSE_CHARS 14 #define MAX_COMPOSE_PRE 60 + char *compose_chars = "`'~^,/\"AaPpSs!?0123CcRr-_<>Xx.=Yy |EeIiOoUu+NnLlgDd:*TtMmVv"; + /* ` : À È Ì Ò Ù à è ì ò ù ' : ´ Á É Í Ó Ú Ý á é í ó ú ý ´ @@ -304,6 +309,7 @@ char *compose_chars = "`'~^,/\"AaPpSs!?0123CcRr-_<>Xx.=Yy |EeIiOoUu+NnLlgDd:*TtM V : ¦ v : ¦ */ + char compose_lookups[MAX_COMPOSE_PRE][MAX_COMPOSE_CHARS] = { /* ` */ {'A','E','I','O','U','a','e','i','o','u',000,000,000,000}, @@ -430,385 +436,421 @@ int compose_keys[MAX_COMPOSE_PRE][MAX_COMPOSE_CHARS] = /* v */ {166,000,000,000,000,000,000,000,000,000,000,000,000,000}, }; - - #define BITMAPDEPTH 1 -/* - * X11 Variables common to both process and thread ports - */ +/* X11 Variables common to both process and thread ports */ + MOUSE_STATUS Trapped_Mouse_status; -unsigned long pdc_key_modifier=0L; -GC normal_gc,block_cursor_gc,rect_cursor_gc,italic_gc,border_gc; -int XCursesFontHeight,XCursesFontWidth; -int XCursesFontAscent,XCursesFontDescent; -int XCursesWindowWidth,XCursesWindowHeight; -int resizeXCursesWindowWidth=0,resizeXCursesWindowHeight=0; -char *bitmap_file=NULL; +unsigned long pdc_key_modifier = 0L; +GC normal_gc, block_cursor_gc, rect_cursor_gc, italic_gc, border_gc; +int XCursesFontHeight, XCursesFontWidth; +int XCursesFontAscent, XCursesFontDescent; +int XCursesWindowWidth, XCursesWindowHeight; +int resizeXCursesWindowWidth = 0,resizeXCursesWindowHeight = 0; +char *bitmap_file = NULL; #ifdef HAVE_XPM_H -char *pixmap_file=NULL; +char *pixmap_file = NULL; #endif -KeySym compose_key=0; -int compose_mask=0; +KeySym compose_key = 0; +int compose_mask = 0; + int state_mask[8] = { - ShiftMask, - LockMask, - ControlMask, - Mod1Mask, - Mod2Mask, - Mod3Mask, - Mod4Mask, - Mod5Mask + ShiftMask, + LockMask, + ControlMask, + Mod1Mask, + Mod2Mask, + Mod3Mask, + Mod4Mask, + Mod5Mask }; + Atom wm_atom[2]; -char *XCursesClassName="XCurses"; +char *XCursesClassName = "XCurses"; XtAppContext app_context; -Widget topLevel,drawing,d1,scrollBox,scrollVert,scrollHoriz; -int ReceivedMapNotify=0; -Boolean mouse_selection=False; -char *tmpsel=NULL; -unsigned long tmpsel_length=0; -int selection_start_x=0; -int selection_start_y=0; -int selection_end_x=0; -int selection_end_y=0; +Widget topLevel, drawing, d1, scrollBox, scrollVert, scrollHoriz; +int ReceivedMapNotify = 0; +Boolean mouse_selection = False; +char *tmpsel = NULL; +unsigned long tmpsel_length = 0; +int selection_start_x = 0; +int selection_start_y = 0; +int selection_end_x = 0; +int selection_end_y = 0; Pixmap icon_bitmap; #ifdef HAVE_XPM_H Pixmap icon_pixmap; Pixmap icon_pixmap_mask; #endif + XtResource app_resources[PDC_NUMBER_APP_RESOURCES] = { - { - XtNlines, - XtCLines, - XtRInt, - sizeof(int), - XtOffsetOf(AppData,lines), - XtRImmediate, - (XtPointer)24, - }, - { - XtNcols, - XtCCols, - XtRInt, - sizeof(int), - XtOffsetOf(AppData,cols), - XtRImmediate, - (XtPointer)80, - }, - { - XtNcursorColor, - XtCCursorColor, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,cursorColor), - XtRString, - (XtPointer)"Red", - }, - { - XtNcolorBlack, - XtCColorBlack, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorBlack), - XtRString, - (XtPointer)"Black", - }, - { - XtNcolorRed, - XtCColorRed, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorRed), - XtRString, - (XtPointer)"red3", - }, - { - XtNcolorGreen, - XtCColorGreen, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorGreen), - XtRString, - (XtPointer)"green3", - }, - { - XtNcolorYellow, - XtCColorYellow, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorYellow), - XtRString, - (XtPointer)"yellow3", - }, - { - XtNcolorBlue, - XtCColorBlue, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorBlue), - XtRString, - (XtPointer)"blue3", - }, - { - XtNcolorMagenta, - XtCColorMagenta, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorMagenta), - XtRString, - (XtPointer)"magenta3", - }, - { - XtNcolorCyan, - XtCColorCyan, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorCyan), - XtRString, - (XtPointer)"cyan3", - }, - { - XtNcolorWhite, - XtCColorWhite, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorWhite), - XtRString, - (XtPointer)"Grey", - }, - { - XtNcolorBoldBlack, - XtCColorBoldBlack, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorBoldBlack), - XtRString, - (XtPointer)"grey40", - }, - { - XtNcolorBoldRed, - XtCColorBoldRed, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorBoldRed), - XtRString, - (XtPointer)"red1", - }, - { - XtNcolorBoldGreen, - XtCColorBoldGreen, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorBoldGreen), - XtRString, - (XtPointer)"green1", - }, - { - XtNcolorBoldYellow, - XtCColorBoldYellow, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorBoldYellow), - XtRString, - (XtPointer)"yellow1", - }, - { - XtNcolorBoldBlue, - XtCColorBoldBlue, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorBoldBlue), - XtRString, - (XtPointer)"blue1", - }, - { - XtNcolorBoldMagenta, - XtCColorBoldMagenta, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorBoldMagenta), - XtRString, - (XtPointer)"magenta1", - }, - { - XtNcolorBoldCyan, - XtCColorBoldCyan, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorBoldCyan), - XtRString, - (XtPointer)"cyan1", - }, - { - XtNcolorBoldWhite, - XtCColorBoldWhite, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,colorBoldWhite), - XtRString, - (XtPointer)"White", - }, - { - XtNnormalFont, - XtCNormalFont, - XtRFontStruct, - sizeof(XFontStruct), - XtOffsetOf(AppData,normalfont), - XtRString, - (XtPointer)"7x13", - }, - { - XtNitalicFont, - XtCItalicFont, - XtRFontStruct, - sizeof(XFontStruct), - XtOffsetOf(AppData,italicfont), - XtRString, - (XtPointer)"7x13", - }, - { - XtNbitmap, - XtCBitmap, - XtRString, - MAX_PATH, - XtOffsetOf(AppData,bitmapFile), - XtRString, - (XtPointer)"", - }, + { + XtNlines, + XtCLines, + XtRInt, + sizeof(int), + XtOffsetOf(AppData, lines), + XtRImmediate, + (XtPointer)24, + }, + + { + XtNcols, + XtCCols, + XtRInt, + sizeof(int), + XtOffsetOf(AppData, cols), + XtRImmediate, + (XtPointer)80, + }, + + { + XtNcursorColor, + XtCCursorColor, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, cursorColor), + XtRString, + (XtPointer)"Red", + }, + + { + XtNcolorBlack, + XtCColorBlack, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorBlack), + XtRString, + (XtPointer)"Black", + }, + + { + XtNcolorRed, + XtCColorRed, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorRed), + XtRString, + (XtPointer)"red3", + }, + + { + XtNcolorGreen, + XtCColorGreen, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorGreen), + XtRString, + (XtPointer)"green3", + }, + + { + XtNcolorYellow, + XtCColorYellow, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorYellow), + XtRString, + (XtPointer)"yellow3", + }, + + { + XtNcolorBlue, + XtCColorBlue, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorBlue), + XtRString, + (XtPointer)"blue3", + }, + + { + XtNcolorMagenta, + XtCColorMagenta, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorMagenta), + XtRString, + (XtPointer)"magenta3", + }, + + { + XtNcolorCyan, + XtCColorCyan, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorCyan), + XtRString, + (XtPointer)"cyan3", + }, + + { + XtNcolorWhite, + XtCColorWhite, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorWhite), + XtRString, + (XtPointer)"Grey", + }, + + { + XtNcolorBoldBlack, + XtCColorBoldBlack, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorBoldBlack), + XtRString, + (XtPointer)"grey40", + }, + + { + XtNcolorBoldRed, + XtCColorBoldRed, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorBoldRed), + XtRString, + (XtPointer)"red1", + }, + + { + XtNcolorBoldGreen, + XtCColorBoldGreen, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorBoldGreen), + XtRString, + (XtPointer)"green1", + }, + + { + XtNcolorBoldYellow, + XtCColorBoldYellow, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorBoldYellow), + XtRString, + (XtPointer)"yellow1", + }, + + { + XtNcolorBoldBlue, + XtCColorBoldBlue, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorBoldBlue), + XtRString, + (XtPointer)"blue1", + }, + + { + XtNcolorBoldMagenta, + XtCColorBoldMagenta, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorBoldMagenta), + XtRString, + (XtPointer)"magenta1", + }, + + { + XtNcolorBoldCyan, + XtCColorBoldCyan, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorBoldCyan), + XtRString, + (XtPointer)"cyan1", + }, + + { + XtNcolorBoldWhite, + XtCColorBoldWhite, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, colorBoldWhite), + XtRString, + (XtPointer)"White", + }, + + { + XtNnormalFont, + XtCNormalFont, + XtRFontStruct, + sizeof(XFontStruct), + XtOffsetOf(AppData, normalfont), + XtRString, + (XtPointer)"7x13", + }, + + { + XtNitalicFont, + XtCItalicFont, + XtRFontStruct, + sizeof(XFontStruct), + XtOffsetOf(AppData, italicfont), + XtRString, + (XtPointer)"7x13", + }, + + { + XtNbitmap, + XtCBitmap, + XtRString, + MAX_PATH, + XtOffsetOf(AppData, bitmapFile), + XtRString, + (XtPointer)"", + }, + #ifdef HAVE_XPM_H - { - XtNpixmap, - XtCPixmap, - XtRString, - MAX_PATH, - XtOffsetOf(AppData,pixmapFile), - XtRString, - (XtPointer)"", - }, + { + XtNpixmap, + XtCPixmap, + XtRString, + MAX_PATH, + XtOffsetOf(AppData, pixmapFile), + XtRString, + (XtPointer)"", + }, #endif - { - XtNcomposeKey, - XtCComposeKey, - XtRString, - MAX_PATH, - XtOffsetOf(AppData,composeKey), - XtRString, - (XtPointer)"", - }, - { - XtNpointer, - XtCPointer, - XtRCursor, - sizeof(Cursor), - XtOffsetOf(AppData,pointer), - XtRString, - (XtPointer)"xterm", - }, - { - XtNpointerForeColor, - XtCPointerForeColor, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,pointerForeColor), - XtRString, - (XtPointer)"Black", - }, - { - XtNpointerBackColor, - XtCPointerBackColor, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,pointerBackColor), - XtRString, - (XtPointer)"White", - }, - { - XtNshmmin, - XtCShmmin, - XtRInt, - sizeof(int), - XtOffsetOf(AppData,shmmin), - XtRImmediate, - (XtPointer)0, - }, - { - XtNborderWidth, - XtCBorderWidth, - XtRInt, - sizeof(int), - XtOffsetOf(AppData,borderWidth), - XtRImmediate, - (XtPointer)0, - }, - { - XtNborderColor, - XtCBorderColor, - XtRPixel, - sizeof(Pixel), - XtOffsetOf(AppData,borderColor), - XtRString, - (XtPointer)"Black", - }, - { - XtNdoubleClickPeriod, - XtCDoubleClickPeriod, - XtRInt, - sizeof(int), - XtOffsetOf(AppData,doubleClickPeriod), - XtRImmediate, - (XtPointer)200, - }, - { - XtNclickPeriod, - XtCClickPeriod, - XtRInt, - sizeof(int), - XtOffsetOf(AppData,clickPeriod), - XtRImmediate, - (XtPointer)100, - }, - { - XtNscrollbarWidth, - XtCScrollbarWidth, - XtRInt, - sizeof(int), - XtOffsetOf(AppData,scrollbarWidth), - XtRImmediate, - (XtPointer)15, - }, - { - XtNcursorBlinkRate, - XtCCursorBlinkRate, - XtRInt, - sizeof(int), - XtOffsetOf(AppData,cursorBlinkRate), - XtRImmediate, - (XtPointer)0, - }, - { - XtNtextCursor, - XtCTextCursor, - XtRString, - MAX_PATH, - XtOffsetOf(AppData,textCursor), - XtRString, - (XtPointer)"", - }, + + { + XtNcomposeKey, + XtCComposeKey, + XtRString, + MAX_PATH, + XtOffsetOf(AppData, composeKey), + XtRString, + (XtPointer)"", + }, + + { + XtNpointer, + XtCPointer, + XtRCursor, + sizeof(Cursor), + XtOffsetOf(AppData, pointer), + XtRString, + (XtPointer)"xterm", + }, + + { + XtNpointerForeColor, + XtCPointerForeColor, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, pointerForeColor), + XtRString, + (XtPointer)"Black", + }, + + { + XtNpointerBackColor, + XtCPointerBackColor, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, pointerBackColor), + XtRString, + (XtPointer)"White", + }, + + { + XtNshmmin, + XtCShmmin, + XtRInt, + sizeof(int), + XtOffsetOf(AppData, shmmin), + XtRImmediate, + (XtPointer)0, + }, + + { + XtNborderWidth, + XtCBorderWidth, + XtRInt, + sizeof(int), + XtOffsetOf(AppData, borderWidth), + XtRImmediate, + (XtPointer)0, + }, + + { + XtNborderColor, + XtCBorderColor, + XtRPixel, + sizeof(Pixel), + XtOffsetOf(AppData, borderColor), + XtRString, + (XtPointer)"Black", + }, + + { + XtNdoubleClickPeriod, + XtCDoubleClickPeriod, + XtRInt, + sizeof(int), + XtOffsetOf(AppData, doubleClickPeriod), + XtRImmediate, + (XtPointer)200, + }, + + { + XtNclickPeriod, + XtCClickPeriod, + XtRInt, + sizeof(int), + XtOffsetOf(AppData, clickPeriod), + XtRImmediate, + (XtPointer)100, + }, + + { + XtNscrollbarWidth, + XtCScrollbarWidth, + XtRInt, + sizeof(int), + XtOffsetOf(AppData, scrollbarWidth), + XtRImmediate, + (XtPointer)15, + }, + + { + XtNcursorBlinkRate, + XtCCursorBlinkRate, + XtRInt, + sizeof(int), + XtOffsetOf(AppData, cursorBlinkRate), + XtRImmediate, + (XtPointer)0, + }, + + { + XtNtextCursor, + XtCTextCursor, + XtRString, + MAX_PATH, + XtOffsetOf(AppData, textCursor), + XtRString, + (XtPointer)"", + }, + #if 0 - { - XtNgeometry, - XtCGeometry, - XtRGeometry, - sizeof(XtWidgetGeometry), - XtOffsetOf(AppData,geometry), - XtRString, - (XtPointer)"80x25", - }, + { + XtNgeometry, + XtCGeometry, + XtRGeometry, + sizeof(XtWidgetGeometry), + XtOffsetOf(AppData, geometry), + XtRString, + (XtPointer)"80x25", + }, #endif }; + XrmOptionDescRec options[PDC_NUMBER_OPTIONS] = { {"-lines", "*lines", XrmoptionSepArg, NULL }, @@ -847,6 +889,7 @@ XrmOptionDescRec options[PDC_NUMBER_OPTIONS] = {"-colorBoldCyan", "*colorBoldCyan", XrmoptionSepArg, NULL }, {"-colorBoldWhite", "*colorBoldWhite", XrmoptionSepArg, NULL }, }; + XtActionsRec XCursesActions[PDC_NUMBER_XCURSES_ACTIONS] = { {"XCursesButton", (XtActionProc)XCursesButton}, @@ -855,13 +898,13 @@ XtActionsRec XCursesActions[PDC_NUMBER_XCURSES_ACTIONS] = {"XCursesPasteSelection", (XtActionProc)XCursesPasteSelection}, {"string", (XtActionProc)XCursesHandleString}, }; -char global_display_name[100]; /* large enough for DISPLAY=machine */ + +char global_display_name[100]; /* large enough for DISPLAY=machine */ Bool after_first_curses_request = False; -int colors[(2*MAX_COLORS)+2]; +int colors[(2 * MAX_COLORS) + 2]; Bool vertical_cursor = False; -/* - * End X11 Variables common to both process and thread ports - */ + +/* End X11 Variables common to both process and thread ports */ #if NOT_USED #define SHM_CURSVAR 0 @@ -873,55 +916,50 @@ Bool vertical_cursor = False; SCREEN *XSP; #endif - #ifdef FOREIGN - XIM Xim; - XIC Xic; - long im_event_mask; - XIMStyles *im_supported_styles=NULL; - XIMStyle my_style=0; + XIM Xim; + XIC Xic; + long im_event_mask; + XIMStyles *im_supported_styles = NULL; + XIMStyle my_style = 0; #endif - - #if 0 - "Shift_L,: XCursesKeyPress() \n" \ - "Shift_R,: XCursesKeyPress() \n" \ - "Control_L,: XCursesKeyPress() \n" \ - "Control_R,: XCursesKeyPress() \n" \ - "Alt_L,: XCursesKeyPress() \n" \ - "Alt_R,: XCursesKeyPress() \n" \ - "Shift_L: XCursesModifierPress() \n" \ - "Shift_R: XCursesModifierPress() \n" \ - "Control_L: XCursesModifierPress() \n" \ - "Control_R: XCursesModifierPress() \n" \ - "Alt_L: XCursesModifierPress() \n" \ - "Alt_R: XCursesModifierPress() \n" + "Shift_L,: XCursesKeyPress() \n" \ + "Shift_R,: XCursesKeyPress() \n" \ + "Control_L,: XCursesKeyPress() \n" \ + "Control_R,: XCursesKeyPress() \n" \ + "Alt_L,: XCursesKeyPress() \n" \ + "Alt_R,: XCursesKeyPress() \n" \ + "Shift_L: XCursesModifierPress() \n" \ + "Shift_R: XCursesModifierPress() \n" \ + "Control_L: XCursesModifierPress() \n" \ + "Control_R: XCursesModifierPress() \n" \ + "Alt_L: XCursesModifierPress() \n" \ + "Alt_R: XCursesModifierPress() \n" #endif XtTranslations XCursesTranslations; + char *defaultTranslations = { - ": XCursesKeyPress() \n" \ - ": XCursesButton() \n" \ - "!Ctrl : XCursesButton() \n" \ - "!Shift : XCursesButton() \n" \ - "!Ctrl : XCursesButton() \n" \ - "!Shift : XCursesButton() \n" \ - ": XCursesButton() \n" \ - ",: XCursesPasteSelection() \n" \ - ": XCursesButton() \n" \ - ": XCursesButton() \n" \ - ": XCursesButton() \n" \ - ": XCursesButton() \n" \ - ": XCursesButton() \n" \ - ": XCursesButton() \n" \ - ": XCursesButton()" + ": XCursesKeyPress() \n" \ + ": XCursesButton() \n" \ + "!Ctrl : XCursesButton() \n" \ + "!Shift : XCursesButton() \n" \ + "!Ctrl : XCursesButton() \n" \ + "!Shift : XCursesButton() \n" \ + ": XCursesButton() \n" \ + ",: XCursesPasteSelection() \n" \ + ": XCursesButton() \n" \ + ": XCursesButton() \n" \ + ": XCursesButton() \n" \ + ": XCursesButton() \n" \ + ": XCursesButton() \n" \ + ": XCursesButton() \n" \ + ": XCursesButton()" }; - -static int opposite[8]={7,6,5,4,3,2,1,0}; - #ifdef USE_THREADS pthread_mutex_t key_queue_mutex = PTHREAD_MUTEX_INITIALIZER; #endif @@ -935,47 +973,50 @@ void say(msg) char *msg; #endif { - PDC_LOG(("%s:%s",(XCursesProcess)?" X":"CURSES",msg)); + PDC_LOG(("%s:%s", XCLOGMSG, msg)); } #ifdef HAVE_PROTO -void dummy_function( void ) +void dummy_function(void) #else void dummy_function() #endif { - return; } /***********************************************************************/ #ifdef HAVE_PROTO -signal_handler XCursesSetSignal(int signo,signal_handler action) +signal_handler XCursesSetSignal(int signo, signal_handler action) #else -signal_handler XCursesSetSignal(signo,action) +signal_handler XCursesSetSignal(signo, action) int signo; signal_handler action; #endif /***********************************************************************/ { #if defined(SA_INTERRUPT) || defined(SA_RESTART) - struct sigaction sigact,osigact; + struct sigaction sigact, osigact; + + sigact.sa_handler = action; - sigact.sa_handler = action; # ifdef SA_INTERRUPT # ifdef SA_RESTART - sigact.sa_flags = SA_INTERRUPT | SA_RESTART; + sigact.sa_flags = SA_INTERRUPT | SA_RESTART; # else - sigact.sa_flags = SA_INTERRUPT; + sigact.sa_flags = SA_INTERRUPT; # endif -# else /* must be SA_RESTART */ - sigact.sa_flags = SA_RESTART; +# else /* must be SA_RESTART */ + sigact.sa_flags = SA_RESTART; # endif - sigemptyset(&sigact.sa_mask); - if (sigaction(signo,&sigact,&osigact) != 0) - return(SIG_ERR); - return(osigact.sa_handler); -#else /* not SA_INTERRUPT or SA_RESTART, use plain signal */ - return(signal(signo,action)); + sigemptyset(&sigact.sa_mask); + + if (sigaction(signo, &sigact, &osigact) != 0) + return SIG_ERR; + + return osigact.sa_handler; + +#else /* not SA_INTERRUPT or SA_RESTART, use plain signal */ + return signal(signo, action); #endif } @@ -988,24 +1029,21 @@ int signo; #endif /***********************************************************************/ { - PDC_LOG(("%s:XCursesSigwinchHandler() - called: SIGNO: %d\n",(XCursesProcess)?" X":"CURSES",signo)); + PDC_LOG(("%s:XCursesSigwinchHandler() - called: SIGNO: %d\n", + XCLOGMSG, signo)); + + /* Patch by: Georg Fuchs, georg.fuchs@rz.uni-regensburg.de + 02-Feb-1999 */ + + SP->resized += 1; + + /* Always trap SIGWINCH if the C library supports SIGWINCH */ -#ifdef BEFORE_CHANGE_BY_G_FUCHS - /* - * Patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 - */ - SP->resized=TRUE; -#else - SP->resized += 1; -#endif -/*---------------------------------------------------------------------*/ -/* Always trap SIGWINCH if the C library supports SIGWINCH... */ -/*---------------------------------------------------------------------*/ #ifdef SIGWINCH - XCursesSetSignal(SIGWINCH, XCursesSigwinchHandler ); + XCursesSetSignal(SIGWINCH, XCursesSigwinchHandler); #endif } + /***********************************************************************/ /* NOT USED */ #ifdef HAVE_PROTO @@ -1015,258 +1053,312 @@ int XCurses_redraw_curscr() #endif /***********************************************************************/ { - int i; + int i; - PDC_LOG(("%s:XCurses_redraw_curscr() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCurses_redraw_curscr() - called\n", XCLOGMSG)); - for (i=0;i_maxy;i++) - XCurses_transform_line(curscr->_y[i],i,0,curscr->_maxx); - return(OK); + for (i = 0; i < curscr->_maxy; i++) + XCurses_transform_line(curscr->_y[i], i, 0, curscr->_maxx); + + return OK; } /***********************************************************************/ #ifdef HAVE_PROTO -int XCursesDisplayText(chtype *ch, int row, int x, int num_cols, bool highlight) +int XCursesDisplayText(chtype *ch, int row, int x, int num_cols, + bool highlight) #else int XCursesDisplayText(ch, row, x, num_cols, highlight) chtype *ch; -int row,x,num_cols; +int row, x, num_cols; bool highlight; #endif /***********************************************************************/ { - char text[300]; - bool new_packet=FALSE; - short fore,back; - int original_x,pair_num,i,j,k,asc=XCursesFontAscent,desc=XCursesFontDescent; /* 11 and 1 */ - chtype old_attr,save_ch,attr; - int xpos,ypos; - int fore_offset=0, back_offset=0; - GC gc; + char text[300]; + bool new_packet = FALSE; + short fore, back; + int original_x, pair_num, i, j, k; - PDC_LOG(("%s:XCursesDisplayText() - called: Row: %d X: %d NumCols: %d\n",(XCursesProcess)?" X":"CURSES", row,x,num_cols)); + /* 11 and 1 */ + int asc = XCursesFontAscent, desc = XCursesFontDescent; - if (num_cols == 0) - return(OK); + chtype old_attr, save_ch, attr; + int xpos, ypos; + int fore_offset = 0, back_offset = 0; + GC gc; + + PDC_LOG(("%s:XCursesDisplayText() - called: Row: %d X: %d NumCols: %d\n", + XCLOGMSG, row, x, num_cols)); + + if (num_cols == 0) + return OK; + + old_attr = *ch & A_ATTRIBUTES; + save_ch = *ch; + original_x = x; + + for (i = 0, j = 0; j < num_cols; x++, j++) + { + attr = ch[j] & A_ATTRIBUTES; + + if (attr != old_attr) + new_packet = TRUE; + + if (new_packet) + { + if ((pair_num = PAIR_NUMBER(save_ch)) != 0) + { + if (pair_content(pair_num, &fore, &back) == ERR) + return ERR; + } + else + { + fore = COLOR_WHITE; + back = COLOR_BLACK; + } + + text[i] = '\0'; + + /* Specify the colour table offsets */ + + if (old_attr & A_BOLD) + fore_offset = 8; + else + fore_offset = 0; + + if (old_attr & A_BLINK) + back_offset = 8; + else + back_offset = 0; + + /* Determine which GC to use - normal or italic */ + + if (old_attr & A_ITALIC) + gc = italic_gc; + else + gc = normal_gc; + + if (!!(old_attr & A_REVERSE) ^ highlight) + { + XSetForeground(XCURSESDISPLAY, gc, + colors[back + back_offset]); + XSetBackground(XCURSESDISPLAY, gc, + colors[fore + fore_offset]); + } + else + { + XSetForeground(XCURSESDISPLAY, gc, + colors[fore + fore_offset]); + XSetBackground(XCURSESDISPLAY, gc, + colors[back + back_offset]); + } + + makeXY(original_x, row, XCursesFontWidth, + XCursesFontHeight, &xpos, &ypos); + + XDrawImageString(XCURSESDISPLAY, XCURSESWIN, gc, + xpos, ypos, text, i); + + for (k = 0; k < i; k++) + { + if (old_attr & A_LEFTLINE) /* LEFT */ + { + XSetForeground(XCURSESDISPLAY, gc, + colors[(SP->line_color)]); + + XDrawLine(XCURSESDISPLAY, XCURSESWIN, + gc, xpos + (XCursesFontWidth * + (k)) - 1, ypos - asc, xpos + + (XCursesFontWidth*(k)) - 1, ypos + + desc); + } + + if (old_attr & A_RIGHTLINE) /* RIGHT */ + { + XSetForeground(XCURSESDISPLAY, gc, + colors[(SP->line_color)]); + + XDrawLine(XCURSESDISPLAY, XCURSESWIN, + gc, xpos + (XCursesFontWidth * + (k + 1)) - 1, ypos - asc, xpos + + (XCursesFontWidth * (k + 1)) - + 1, ypos + desc); + } + } +#if 0 + if (old_attr & A_OVERLINE) /* ABOVE */ + { + XSetForeground(XCURSESDISPLAY, gc, + colors[(SP->line_color)]); + + XDrawLine(XCURSESDISPLAY, XCURSESWIN, gc, xpos, + ypos - asc, xpos + XCursesFontWidth * i, + ypos - asc); + } +#endif + if (old_attr & A_UNDERLINE) /* UNDER */ + { + XSetForeground(XCURSESDISPLAY, gc, + colors[(SP->line_color)]); + + XDrawLine(XCURSESDISPLAY, XCURSESWIN, gc, xpos, + ypos + 1, xpos + XCursesFontWidth * i, + ypos + 1); + } + + PDC_LOG(("%s:XCursesDisplayText() - row: %d col: %d num_cols: %d fore: %d back: %d text:<%s>\n", + XCLOGMSG, row, original_x, i, fore, back, text)); + + new_packet = FALSE; + old_attr = attr; + original_x = x; + i = 0; + } + + text[i++] = ch[j] & A_CHARTEXT; + save_ch = ch[j]; + } + + if ((pair_num = PAIR_NUMBER(save_ch)) != 0) + { + if (pair_content(pair_num, &fore, &back) == ERR) + return ERR; + } + else + { + fore = COLOR_WHITE; + back = COLOR_BLACK; + } + + /* Specify the colour table offsets */ + + text[i] = '\0'; + + if (old_attr & A_BOLD) + fore_offset = 8; + else + fore_offset = 0; + + if (old_attr & A_BLINK) + back_offset = 8; + else + back_offset = 0; + + /* Determine which GC to use - normal or italic */ + + if (old_attr & A_ITALIC) + gc = italic_gc; + else + gc = normal_gc; + + if (!!(old_attr & A_REVERSE) ^ highlight) + { + XSetForeground(XCURSESDISPLAY, gc, colors[back + back_offset]); + XSetBackground(XCURSESDISPLAY, gc, colors[fore + fore_offset]); + } + else + { + XSetForeground(XCURSESDISPLAY, gc, colors[fore + fore_offset]); + XSetBackground(XCURSESDISPLAY, gc, colors[back + back_offset]); + } + + makeXY(original_x, row, XCursesFontWidth, XCursesFontHeight, + &xpos, &ypos); + + XDrawImageString(XCURSESDISPLAY, XCURSESWIN, gc, xpos, ypos, + text, i); + + for (k = 0; k < i; k++) + { + if (old_attr & A_LEFTLINE) /* LEFT */ + { + XSetForeground(XCURSESDISPLAY, gc, + colors[(SP->line_color)]); + + XDrawLine(XCURSESDISPLAY, XCURSESWIN, gc, xpos + + XCursesFontWidth * k - 1, ypos - asc, xpos + + XCursesFontWidth * k - 1, ypos + desc); + } + + if (old_attr & A_RIGHTLINE) /* RIGHT */ + { + XSetForeground(XCURSESDISPLAY, gc, + colors[(SP->line_color)]); + + XDrawLine(XCURSESDISPLAY, XCURSESWIN, gc, xpos + + XCursesFontWidth * (k + 1) - 1, ypos - asc, xpos + + XCursesFontWidth * (k + 1) - 1, ypos + desc); + } + } #if 0 - fprintf(stderr,"%2.2d ",x); - for (idx=0;idx %8.8x ",attr,old_attr); - } - fprintf(stderr,"\n"); + if (old_attr & A_OVERLINE) /* ABOVE */ + { + XSetForeground(XCURSESDISPLAY, gc, colors[(SP->line_color)]); + XDrawLine(XCURSESDISPLAY, XCURSESWIN, gc, xpos, ypos - asc, + xpos + XCursesFontWidth * i, ypos - asc); + } #endif + if (old_attr & A_UNDERLINE) /* UNDER */ + { + XSetForeground(XCURSESDISPLAY, gc, colors[(SP->line_color)]); + XDrawLine(XCURSESDISPLAY, XCURSESWIN, gc, xpos, ypos + 1, + xpos + XCursesFontWidth * i, ypos + 1); + } - old_attr = *ch & A_ATTRIBUTES; - save_ch = *ch; - original_x = x; - for (i=0,j=0; j\n", + XCLOGMSG, row, original_x, i, fore, back, text)); - if ( !!(old_attr & A_REVERSE) ^ highlight ) - { - XSetForeground(XCURSESDISPLAY, gc, colors[back+back_offset]); - XSetBackground(XCURSESDISPLAY, gc, colors[fore+fore_offset]); - } - else - { - XSetForeground(XCURSESDISPLAY, gc, colors[fore+fore_offset]); - XSetBackground(XCURSESDISPLAY, gc, colors[back+back_offset]); - } - - makeXY(original_x,row,XCursesFontWidth,XCursesFontHeight,&xpos,&ypos); - XDrawImageString(XCURSESDISPLAY,XCURSESWIN,gc,xpos,ypos,text,i); - - for (k=0;kline_color)]); - XDrawLine(XCURSESDISPLAY,XCURSESWIN,gc,xpos+(XCursesFontWidth*(k))-1,ypos-asc,xpos+(XCursesFontWidth*(k))-1,ypos+desc); - } - if ( old_attr & A_RIGHTLINE ) /* RIGHT */ - { - XSetForeground(XCURSESDISPLAY, gc, colors[(SP->line_color)]); - XDrawLine(XCURSESDISPLAY,XCURSESWIN,gc,xpos+(XCursesFontWidth*(k+1))-1,ypos-asc,xpos+(XCursesFontWidth*(k+1))-1,ypos+desc); - } - } -#if 0 - if ( old_attr & A_OVERLINE ) /* ABOVE */ - { - XSetForeground(XCURSESDISPLAY, gc, colors[(SP->line_color)]); - XDrawLine(XCURSESDISPLAY,XCURSESWIN,gc,xpos,ypos-asc,xpos+(XCursesFontWidth*i),ypos-asc); - } -#endif - if (old_attr & A_UNDERLINE) /* UNDER */ - { - XSetForeground(XCURSESDISPLAY, gc, colors[(SP->line_color)]); - XDrawLine(XCURSESDISPLAY,XCURSESWIN,gc,xpos,ypos+1,xpos+(XCursesFontWidth*i),ypos+1); - } - - PDC_LOG(("%s:XCursesDisplayText() - row: %d col: %d num_cols: %d fore: %d back: %d text:<%s>\n",(XCursesProcess)?" X":"CURSES",row,original_x,i,fore,back,text)); - - new_packet = FALSE; - old_attr = attr; - original_x = x; - i = 0; - } - text[i++] = *(ch+j) & A_CHARTEXT; - save_ch = *(ch+j); - } - - if ((pair_num = PAIR_NUMBER(save_ch)) != 0) - { - if (pair_content(pair_num,&fore,&back) == ERR) - return(ERR); - } - else - { - fore = COLOR_WHITE; - back = COLOR_BLACK; - } - /* - * Specify the colour table offsets - */ - text[i] = '\0'; - if ( old_attr & A_BOLD ) - fore_offset = 8; - else - fore_offset = 0; - if ( old_attr & A_BLINK ) - back_offset = 8; - else - back_offset = 0; - /* - * Determine which GC to use - normal or italic - */ - if ( old_attr & A_ITALIC ) - gc = italic_gc; - else - gc = normal_gc; - - if ( !!(old_attr & A_REVERSE) ^ highlight ) - { - XSetForeground(XCURSESDISPLAY, gc, colors[back+back_offset]); - XSetBackground(XCURSESDISPLAY, gc, colors[fore+fore_offset]); - } - else - { - XSetForeground(XCURSESDISPLAY, gc, colors[fore+fore_offset]); - XSetBackground(XCURSESDISPLAY, gc, colors[back+back_offset]); - } - - makeXY(original_x,row,XCursesFontWidth,XCursesFontHeight,&xpos,&ypos); - XDrawImageString(XCURSESDISPLAY,XCURSESWIN,gc,xpos,ypos,text,i); - - for (k=0;kline_color)]); - XDrawLine(XCURSESDISPLAY,XCURSESWIN,gc,xpos+(XCursesFontWidth*(k))-1,ypos-asc,xpos+(XCursesFontWidth*(k))-1,ypos+desc); - } - if ( old_attr & A_RIGHTLINE ) /* RIGHT */ - { - XSetForeground(XCURSESDISPLAY, gc, colors[(SP->line_color)]); - XDrawLine(XCURSESDISPLAY,XCURSESWIN,gc,xpos+(XCursesFontWidth*(k+1))-1,ypos-asc,xpos+(XCursesFontWidth*(k+1))-1,ypos+desc); - } - } -#if 0 - if ( old_attr & A_OVERLINE ) /* ABOVE */ - { - XSetForeground(XCURSESDISPLAY, gc, colors[(SP->line_color)]); - XDrawLine(XCURSESDISPLAY,XCURSESWIN,gc,xpos,ypos-asc,xpos+(XCursesFontWidth*i),ypos-asc); - } -#endif - if (old_attr & A_UNDERLINE) /* UNDER */ - { - XSetForeground(XCURSESDISPLAY, gc, colors[(SP->line_color)]); - XDrawLine(XCURSESDISPLAY,XCURSESWIN,gc,xpos,ypos+1,xpos+(XCursesFontWidth*i),ypos+1); - } - - PDC_LOG(("%s:XCursesDisplayText() (end) row: %d col: %d num_cols: %d fore: %d back: %d text:<%s>\n",(XCursesProcess)?" X":"CURSES",row,original_x,i,fore,back,text)); - - return(OK); + return OK; } + /***********************************************************************/ #ifdef HAVE_PROTO -void get_GC(Display *display, Window win, GC *gc, XFontStruct *font_info, int fore, int back,bool highlight) +void get_GC(Display *display, Window win, GC *gc, XFontStruct *font_info, + int fore, int back, bool highlight) #else -void get_GC(display,win, gc, font_info,fore,back,highlight) +void get_GC(display, win, gc, font_info, fore, back, highlight) Display *display; Window win; GC *gc; XFontStruct *font_info; -int fore,back; +int fore, back; bool highlight; #endif /***********************************************************************/ { - XGCValues values; + XGCValues values; /* Create default Graphics Context */ - *gc = XCreateGC(display,win, 0L, &values); + + *gc = XCreateGC(display, win, 0L, &values); /* specify font */ - XSetFont(display, *gc, font_info->fid); + + XSetFont(display, *gc, font_info->fid); /* specify black foreground since default may be white on white */ - XSetForeground(display, *gc, colors[fore]); - XSetBackground(display, *gc, colors[back]); - if (highlight) - XSetFunction(display, *gc, GXxor); - return; + + XSetForeground(display, *gc, colors[fore]); + XSetBackground(display, *gc, colors[back]); + + if (highlight) + XSetFunction(display, *gc, GXxor); } + /***********************************************************************/ #ifdef HAVE_PROTO -void makeXY(int x,int y,int fontwidth,int fontheight,int *xpos,int *ypos) +void makeXY(int x, int y, int fontwidth, int fontheight, int *xpos, int *ypos) #else -void makeXY(x,y,fontwidth,fontheight,xpos,ypos) -int x,y,fontwidth,fontheight,*xpos,*ypos; +void makeXY(x, y, fontwidth, fontheight, xpos, ypos) +int x, y, fontwidth, fontheight, *xpos,* ypos; #endif /***********************************************************************/ { - *xpos = (x * fontwidth)+XCURSESBORDERWIDTH; - *ypos = XCURSESNORMALFONTINFO->ascent + (y * fontheight) + XCURSESBORDERWIDTH; - return; + *xpos = (x * fontwidth) + XCURSESBORDERWIDTH; + *ypos = XCURSESNORMALFONTINFO->ascent + (y * fontheight) + + XCURSESBORDERWIDTH; } /***********************************************************************/ @@ -1278,31 +1370,30 @@ int get_colors() /***********************************************************************/ { #ifdef PDCDEBUG - say("in get_colors\n"); + say("in get_colors\n"); #endif - - colors[0] = app_data.colorBlack; - colors[1] = app_data.colorRed; - colors[2] = app_data.colorGreen; - colors[3] = app_data.colorYellow; - colors[4] = app_data.colorBlue; - colors[5] = app_data.colorMagenta; - colors[6] = app_data.colorCyan; - colors[7] = app_data.colorWhite; - colors[8] = app_data.colorBoldBlack; - colors[9] = app_data.colorBoldRed; - colors[10] = app_data.colorBoldGreen; - colors[11] = app_data.colorBoldYellow; - colors[12] = app_data.colorBoldBlue; - colors[13] = app_data.colorBoldMagenta; - colors[14] = app_data.colorBoldCyan; - colors[15] = app_data.colorBoldWhite; - colors[COLOR_CURSOR] = XCURSESCURSORCOLOR; - colors[COLOR_BORDER] = XCURSESBORDERCOLOR; + colors[0] = app_data.colorBlack; + colors[1] = app_data.colorRed; + colors[2] = app_data.colorGreen; + colors[3] = app_data.colorYellow; + colors[4] = app_data.colorBlue; + colors[5] = app_data.colorMagenta; + colors[6] = app_data.colorCyan; + colors[7] = app_data.colorWhite; + colors[8] = app_data.colorBoldBlack; + colors[9] = app_data.colorBoldRed; + colors[10] = app_data.colorBoldGreen; + colors[11] = app_data.colorBoldYellow; + colors[12] = app_data.colorBoldBlue; + colors[13] = app_data.colorBoldMagenta; + colors[14] = app_data.colorBoldCyan; + colors[15] = app_data.colorBoldWhite; + colors[COLOR_CURSOR] = XCURSESCURSORCOLOR; + colors[COLOR_BORDER] = XCURSESBORDERCOLOR; #ifdef PDCDEBUG - say("out of get_colors\n"); + say("out of get_colors\n"); #endif - return(OK); + return OK; } /***********************************************************************/ @@ -1313,34 +1404,36 @@ int XCursesEndwin() #endif /***********************************************************************/ { - PDC_LOG(("%s:XCursesEndwin() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesEndwin() - called\n", XCLOGMSG)); + + if (bitmap_file != NULL) + { + XFreePixmap(XCURSESDISPLAY, icon_bitmap); + free(bitmap_file); + } - if (bitmap_file != NULL) - { - XFreePixmap(XCURSESDISPLAY,icon_bitmap); - free(bitmap_file); - } #ifdef HAVE_XPM_H - if (pixmap_file != NULL) - { - XFreePixmap(XCURSESDISPLAY,icon_pixmap); - XFreePixmap(XCURSESDISPLAY,icon_pixmap_mask); - free(pixmap_file); - } + if (pixmap_file != NULL) + { + XFreePixmap(XCURSESDISPLAY, icon_pixmap); + XFreePixmap(XCURSESDISPLAY, icon_pixmap_mask); + free(pixmap_file); + } #endif - XFreeGC(XCURSESDISPLAY, normal_gc); - XFreeGC(XCURSESDISPLAY, italic_gc); - XFreeGC(XCURSESDISPLAY, block_cursor_gc); - XFreeGC(XCURSESDISPLAY, rect_cursor_gc); - XFreeGC(XCURSESDISPLAY, border_gc); + XFreeGC(XCURSESDISPLAY, normal_gc); + XFreeGC(XCURSESDISPLAY, italic_gc); + XFreeGC(XCURSESDISPLAY, block_cursor_gc); + XFreeGC(XCURSESDISPLAY, rect_cursor_gc); + XFreeGC(XCURSESDISPLAY, border_gc); #ifdef FOREIGN - XDestroyIC(Xic); + XDestroyIC(Xic); #endif #if 0 - XCloseDisplay(XCURSESDISPLAY); + XCloseDisplay(XCURSESDISPLAY); #endif - return(0); + return 0; } + /***********************************************************************/ #ifdef HAVE_PROTO int XCursesRefreshScrollbar(void) @@ -1349,70 +1442,75 @@ int XCursesRefreshScrollbar() #endif /***********************************************************************/ { - PDC_SCROLLBAR_TYPE total_y=(PDC_SCROLLBAR_TYPE)(SP->sb_total_y*XCursesFontHeight); - PDC_SCROLLBAR_TYPE viewport_y=(PDC_SCROLLBAR_TYPE)(SP->sb_viewport_y*XCursesFontHeight); - PDC_SCROLLBAR_TYPE cur_y=(PDC_SCROLLBAR_TYPE)(SP->sb_cur_y*XCursesFontHeight); - PDC_SCROLLBAR_TYPE total_x=(PDC_SCROLLBAR_TYPE)(SP->sb_total_x*XCursesFontWidth); - PDC_SCROLLBAR_TYPE viewport_x=(PDC_SCROLLBAR_TYPE)(SP->sb_viewport_x*XCursesFontWidth); - PDC_SCROLLBAR_TYPE cur_x=(PDC_SCROLLBAR_TYPE)(SP->sb_cur_x*XCursesFontWidth); - PDC_SCROLLBAR_TYPE vtop=(PDC_SCROLLBAR_TYPE)(cur_y/total_y); - PDC_SCROLLBAR_TYPE vlength=(PDC_SCROLLBAR_TYPE)(viewport_y/total_y); - PDC_SCROLLBAR_TYPE htop=(PDC_SCROLLBAR_TYPE)(cur_x/total_x); - PDC_SCROLLBAR_TYPE hlength=(PDC_SCROLLBAR_TYPE)(viewport_x/total_x); + PDC_SCROLLBAR_TYPE cur_x = + (PDC_SCROLLBAR_TYPE)(SP->sb_cur_x * XCursesFontWidth); + PDC_SCROLLBAR_TYPE cur_y = + (PDC_SCROLLBAR_TYPE)(SP->sb_cur_y * XCursesFontHeight); - PDC_LOG(("%s:XCursesRefreshScrollbar() - called: \n",(XCursesProcess)?" X":"CURSES")); + PDC_SCROLLBAR_TYPE total_x = + (PDC_SCROLLBAR_TYPE)(SP->sb_total_x * XCursesFontWidth); + PDC_SCROLLBAR_TYPE total_y = + (PDC_SCROLLBAR_TYPE)(SP->sb_total_y * XCursesFontHeight); - if (!SP->sb_on) - return(ERR); -#if 0 -fprintf(stderr,"%s:XCursesRefreshScrollbar() - vert: %d %f %f %f %f %f\n",(XCursesProcess)?" X":"CURSES", - SP->sb_total_y,total_y,viewport_y,cur_y, - vtop,vlength); -fprintf(stderr,"%s:XCursesRefreshScrollbar() - horz: %d %f %f %f %f %f\n",(XCursesProcess)?" X":"CURSES", - SP->sb_total_x,total_x,viewport_x,cur_x, - htop,hlength); -#endif - if (SP->sb_total_y != (PDC_SCROLLBAR_TYPE)0) - XawScrollbarSetThumb( scrollVert, (PDC_SCROLLBAR_TYPE)vtop, (PDC_SCROLLBAR_TYPE)vlength ); - if (SP->sb_total_x != (PDC_SCROLLBAR_TYPE)0) - XawScrollbarSetThumb( scrollHoriz, (PDC_SCROLLBAR_TYPE)htop, (PDC_SCROLLBAR_TYPE)hlength ); - return(OK); + PDC_SCROLLBAR_TYPE viewport_x = + (PDC_SCROLLBAR_TYPE)(SP->sb_viewport_x * XCursesFontWidth); + PDC_SCROLLBAR_TYPE viewport_y = + (PDC_SCROLLBAR_TYPE)(SP->sb_viewport_y * XCursesFontHeight); + + PDC_SCROLLBAR_TYPE vtop = cur_y / total_y; + PDC_SCROLLBAR_TYPE vlength = viewport_y / total_y; + PDC_SCROLLBAR_TYPE htop = cur_x / total_x; + PDC_SCROLLBAR_TYPE hlength = viewport_x / total_x; + + PDC_LOG(("%s:XCursesRefreshScrollbar() - called: \n", XCLOGMSG)); + + if (!SP->sb_on) + return ERR; + + if (SP->sb_total_y != 0) + XawScrollbarSetThumb(scrollVert, vtop, vlength); + + if (SP->sb_total_x != 0) + XawScrollbarSetThumb(scrollHoriz, htop, hlength); + + return OK; } + /***********************************************************************/ #ifdef HAVE_PROTO -void SetCursorColor(chtype *ch,short *fore, short *back) +void SetCursorColor(chtype *ch, short *fore, short *back) #else -void SetCursorColor(ch,fore,back) +void SetCursorColor(ch, fore, back) chtype *ch; short *fore; short *back; #endif /***********************************************************************/ { - chtype attr=0; - short f=0,b=0; + int attr; + short f, b; - attr = (chtype)((*ch & A_COLOR)>>24); - if (attr) - { - pair_content(attr,&f,&b); - *fore = opposite[f]; - *back = opposite[b]; - } - else - { - if (*ch & A_REVERSE) - { - *back = COLOR_BLACK; - *fore = COLOR_WHITE; - } - else - { - *back = COLOR_WHITE; - *fore = COLOR_BLACK; - } - } - return; + attr = PAIR_NUMBER(*ch); + + if (attr) + { + pair_content(attr, &f, &b); + *fore = 7 - f; + *back = 7 - b; + } + else + { + if (*ch & A_REVERSE) + { + *back = COLOR_BLACK; + *fore = COLOR_WHITE; + } + else + { + *back = COLOR_WHITE; + *fore = COLOR_BLACK; + } + } } /***********************************************************************/ @@ -1423,108 +1521,122 @@ void XCursesGetIcon() #endif /***********************************************************************/ { - XIconSize *icon_size; - int size_count=0; - Status rc=0; - unsigned char *bitmap_bits=NULL; - unsigned int icon_bitmap_width=0,icon_bitmap_height=0; - unsigned int file_bitmap_width=0,file_bitmap_height=0; - int max_height=0,max_width=0; - int x_hot=0,y_hot=0; - int i; + XIconSize *icon_size; + int size_count = 0; + Status rc; + unsigned char *bitmap_bits = NULL; + unsigned int icon_bitmap_width = 0, icon_bitmap_height = 0; + unsigned int file_bitmap_width = 0, file_bitmap_height = 0; - PDC_LOG(("%s:XCursesGetIcon\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesGetIcon\n", XCLOGMSG)); - icon_size = XAllocIconSize(); - rc = XGetIconSizes(XtDisplay(topLevel), - RootWindowOfScreen(XtScreen(topLevel)), - &icon_size, - &size_count); - if (rc /* if the WM can advise on icon sizes... */ - && size_count) - { - PDC_LOG(("%s:size_count: %d rc: %d\n",(XCursesProcess)?" X":"CURSES",size_count,rc)); + icon_size = XAllocIconSize(); - for (i=0;i max_width) - max_width = icon_size[i].max_width; - if (icon_size[i].max_height > max_height) - max_height = icon_size[i].max_height; + rc = XGetIconSizes(XtDisplay(topLevel), + RootWindowOfScreen(XtScreen(topLevel)), + &icon_size, &size_count); - PDC_LOG(("%s:min: %d %d\n",(XCursesProcess)?" X":"CURSES",icon_size[i].min_width,icon_size[i].min_height)); - PDC_LOG(("%s:max: %d %d\n",(XCursesProcess)?" X":"CURSES",icon_size[i].max_width,icon_size[i].max_height)); - PDC_LOG(("%s:inc: %d %d\n",(XCursesProcess)?" X":"CURSES",icon_size[i].width_inc,icon_size[i].height_inc)); - } - if (max_width >= BIG_ICON_WIDTH - && max_height >= BIG_ICON_HEIGHT) - { - icon_bitmap_width = BIG_ICON_WIDTH; - icon_bitmap_height = BIG_ICON_HEIGHT; - bitmap_bits = (unsigned char *)big_icon_bitmap_bits; - } - else - { - icon_bitmap_width = LITTLE_ICON_WIDTH; - icon_bitmap_height = LITTLE_ICON_HEIGHT; - bitmap_bits = (unsigned char *)little_icon_bitmap_bits; - } - } - else /* WM won't tell us what icon size to use, so use small icon :-( */ - { - icon_bitmap_width = LITTLE_ICON_WIDTH; - icon_bitmap_height = LITTLE_ICON_HEIGHT; - bitmap_bits = (unsigned char *)little_icon_bitmap_bits; - } - XFree((char *)icon_size); + /* if the WM can advise on icon sizes... */ + + if (rc && size_count) + { + int i; + int max_height = 0, max_width = 0; + + PDC_LOG(("%s:size_count: %d rc: %d\n", + XCLOGMSG, size_count, rc)); + + for (i = 0; i < size_count; i++) + { + if (icon_size[i].max_width > max_width) + max_width = icon_size[i].max_width; + if (icon_size[i].max_height > max_height) + max_height = icon_size[i].max_height; + + PDC_LOG(("%s:min: %d %d\n", XCLOGMSG, + icon_size[i].min_width, + icon_size[i].min_height)); + + PDC_LOG(("%s:max: %d %d\n", XCLOGMSG, + icon_size[i].max_width, + icon_size[i].max_height)); + + PDC_LOG(("%s:inc: %d %d\n", XCLOGMSG, + icon_size[i].width_inc, + icon_size[i].height_inc)); + } + + if (max_width >= BIG_ICON_WIDTH && + max_height >= BIG_ICON_HEIGHT) + { + icon_bitmap_width = BIG_ICON_WIDTH; + icon_bitmap_height = BIG_ICON_HEIGHT; + bitmap_bits = (unsigned char *)big_icon_bitmap_bits; + } + else + { + icon_bitmap_width = LITTLE_ICON_WIDTH; + icon_bitmap_height = LITTLE_ICON_HEIGHT; + bitmap_bits = (unsigned char *)little_icon_bitmap_bits; + } + + } + else /* use small icon */ + { + icon_bitmap_width = LITTLE_ICON_WIDTH; + icon_bitmap_height = LITTLE_ICON_HEIGHT; + bitmap_bits = (unsigned char *)little_icon_bitmap_bits; + } + + XFree((char *)icon_size); #ifdef HAVE_XPM_H - if (strcmp(XCURSESPIXMAPFILE,"") != 0) /* supplied pixmap */ - { - rc = XpmReadFileToPixmap( XtDisplay(topLevel), - RootWindowOfScreen(XtScreen(topLevel)), - (char *)XCURSESPIXMAPFILE, - &icon_pixmap, - &icon_pixmap_mask, - NULL ); - return; - } + if (strcmp(XCURSESPIXMAPFILE, "") != 0) /* supplied pixmap */ + { + XpmReadFileToPixmap(XtDisplay(topLevel), + RootWindowOfScreen(XtScreen(topLevel)), + (char *)XCURSESPIXMAPFILE, + &icon_pixmap, &icon_pixmap_mask, NULL); + return; + } #endif - if (strcmp(XCURSESBITMAPFILE,"") != 0) /* supplied bitmap */ - { - rc = XReadBitmapFile(XtDisplay(topLevel), - RootWindowOfScreen(XtScreen(topLevel)), - (char *)XCURSESBITMAPFILE, - &file_bitmap_width, - &file_bitmap_height, - &icon_bitmap, - &x_hot, - &y_hot); - switch(rc) - { - case BitmapOpenFailed: - fprintf(stderr,"bitmap file %s: not found\n",XCURSESBITMAPFILE); - break; - case BitmapFileInvalid: - fprintf(stderr,"bitmap file %s: contents invalid\n",XCURSESBITMAPFILE); - break; - default: - return; - break; - } - } - icon_bitmap = XCreateBitmapFromData(XtDisplay(topLevel), - RootWindowOfScreen(XtScreen(topLevel)), - (char *)bitmap_bits, - icon_bitmap_width, - icon_bitmap_height); - return; + + if (strcmp(XCURSESBITMAPFILE, "") != 0) /* supplied bitmap */ + { + int x_hot = 0, y_hot = 0; + + rc = XReadBitmapFile(XtDisplay(topLevel), + RootWindowOfScreen(XtScreen(topLevel)), + (char *)XCURSESBITMAPFILE, + &file_bitmap_width, &file_bitmap_height, + &icon_bitmap, &x_hot, &y_hot); + + switch(rc) + { + case BitmapOpenFailed: + fprintf(stderr, "bitmap file %s: not found\n", + XCURSESBITMAPFILE); + break; + case BitmapFileInvalid: + fprintf(stderr, "bitmap file %s: contents invalid\n", + XCURSESBITMAPFILE); + break; + default: + return; + } + } + + XCreateBitmapFromData(XtDisplay(topLevel), + RootWindowOfScreen(XtScreen(topLevel)), + (char *)bitmap_bits, icon_bitmap_width, icon_bitmap_height); } + /***********************************************************************/ #ifdef HAVE_PROTO -void XCursesExpose(Widget w,XtPointer client_data,XEvent *event,Boolean *continue_to_dispatch) +void XCursesExpose(Widget w, XtPointer client_data, XEvent *event, + Boolean *continue_to_dispatch) #else -void XCursesExpose(w,client_data,event,continue_to_dispatch) +void XCursesExpose(w, client_data, event, continue_to_dispatch) Widget w; XtPointer client_data; XEvent *event; @@ -1532,46 +1644,23 @@ Boolean *continue_to_dispatch; #endif /***********************************************************************/ { - PDC_LOG(("%s:XCursesExpose called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesExpose called\n", XCLOGMSG)); -#if 0 -/* get all other Expose events on the queue */ - while (XCheckTypedEvent(display, Expose, &event)) -#endif - if (event->xexpose.count != 0) /* ignore all Exposes except last */ - return; + /* ignore all Exposes except last */ -#if 0 - XCursesDisplayScreen(FALSE); -/* - * Can we here determine largest rectangle to refresh based on all outstanding - * expose events? - */ -/* - * should refresh that portion of the screen now exposed - in XCursesProcess - * using event.x, event.y, event.width, event.height to determine row/col - * to refresh. Call XCursesDisplayText() to do the refresh. - */ - if (after_first_curses_request - && after_first_expose_event) - { - XCursesRefreshScreen(); - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); - } - after_first_expose_event = True; -#else - if (after_first_curses_request - && ReceivedMapNotify) - XCursesDisplayScreen(FALSE); -#endif - return; + if (event->xexpose.count != 0) + return; + + if (after_first_curses_request && ReceivedMapNotify) + XCursesDisplayScreen(FALSE); } + /***********************************************************************/ #ifdef HAVE_PROTO -void XCursesNonmaskable(Widget w,XtPointer client_data,XEvent *event,Boolean *continue_to_dispatch) +void XCursesNonmaskable(Widget w, XtPointer client_data, XEvent *event, + Boolean *continue_to_dispatch) #else -void XCursesNonmaskable(w,client_data,event,continue_to_dispatch) +void XCursesNonmaskable(w, client_data, event, continue_to_dispatch) Widget w; XtPointer client_data; XEvent *event; @@ -1579,35 +1668,32 @@ Boolean *continue_to_dispatch; #endif /***********************************************************************/ { - XClientMessageEvent *client_event=(XClientMessageEvent *)event; + XClientMessageEvent *client_event = (XClientMessageEvent *)event; - PDC_LOG(("%s:XCursesNonmaskable called: otherpid %d\n",(XCursesProcess)?" X":"CURSES",otherpid)); + PDC_LOG(("%s:XCursesNonmaskable called: otherpid %d event %d\n", + XCLOGMSG, otherpid, event->type)); - switch(event->type) - { - case ClientMessage: + if (event->type == ClientMessage) + { #ifdef PDCDEBUG - say("ClientMessage received\n"); + say("ClientMessage received\n"); #endif - /* - * This code used to include handling of WM_SAVE_YOURSELF, but - * it resulted in continual failure of THE on my Toshiba laptop. - * Removed on 3-3-2001. Now only exits on WM_DELETE_WINDOW - */ - if ( (Atom)client_event->data.s[0] == wm_atom[0] ) - XCursesExitXCursesProcess(0,SIGKILL,""); - break; - default: - PDC_LOG(("%s:XCursesNonmaskable - unknown event %d\n",(XCursesProcess)?" X":"CURSES",event->type)); - break; - } - return; + /* This code used to include handling of + WM_SAVE_YOURSELF, but it resulted in continual + failure of THE on my Toshiba laptop. Removed on + 3-3-2001. Now only exits on WM_DELETE_WINDOW. */ + + if ((Atom)client_event->data.s[0] == wm_atom[0]) + XCursesExitXCursesProcess(0, SIGKILL, ""); + } } + /***********************************************************************/ #ifdef HAVE_PROTO -void XCursesModifierPress(Widget w,XEvent *event, String *params, Cardinal *nparams) +void XCursesModifierPress(Widget w, XEvent *event, String *params, + Cardinal *nparams) #else -void XCursesModifierPress(w,event,params,nparams) +void XCursesModifierPress(w, event, params, nparams) Widget w; XEvent *event; String *params; @@ -1618,57 +1704,61 @@ Cardinal *nparams; #define STATE_NORMAL 0 #define STATE_COMPOSE 1 #define STATE_CHAR 2 + #ifdef FOREIGN - wchar_t buffer[120]; + wchar_t buffer[120]; #else - char buffer[120]; -#endif - int buflen=40; - int count,key; - KeySym keysym; - XComposeStatus compose; -#ifdef FOREIGN - Status status; + char buffer[120]; #endif + int buflen = 40; + int count, key; + KeySym keysym; + XComposeStatus compose; - PDC_LOG(("%s:XCursesModifierPress called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesModifierPress called\n", XCLOGMSG)); - buffer[0] = '\0'; - count = XLookupString(&(event->xkey),buffer,buflen,&keysym, &compose); - /* - * Handle modifier keys first. - */ + buffer[0] = '\0'; - SP->return_key_modifiers = True; + count = XLookupString(&(event->xkey), buffer, buflen, &keysym, + &compose); -#ifdef PDCDEBUG - printf("%d: %ld %s %d %d %d\n",__LINE__,keysym, - (event->type == KeyPress) ? "Press" : "Release", - (keysym != compose_key), - (IsModifierKey(keysym)), - (SP->return_key_modifiers)); -#endif + /* Handle modifier keys first */ - if (SP->return_key_modifiers) - { - key = 0; - if (keysym == XK_Shift_L) { key = KEY_SHIFT_L; } - else if (keysym == XK_Shift_R) { key = KEY_SHIFT_R; } - else if (keysym == XK_Control_L) { key = KEY_CONTROL_L; } - else if (keysym == XK_Control_R) { key = KEY_CONTROL_R; } - else if (keysym == XK_Alt_L) { key = KEY_ALT_L; } - else if (keysym == XK_Alt_R) { key = KEY_ALT_R; } - if (key) - XCursesSendKeyToCurses( (unsigned long)key, NULL ); - return; - } - return; + SP->return_key_modifiers = True; + + switch (keysym) { + case XK_Shift_L: + key = KEY_SHIFT_L; + break; + case XK_Shift_R: + key = KEY_SHIFT_R; + break; + case XK_Control_L: + key = KEY_CONTROL_L; + break; + case XK_Control_R: + key = KEY_CONTROL_R; + break; + case XK_Alt_L: + key = KEY_ALT_L; + break; + case XK_Alt_R: + key = KEY_ALT_R; + break; + default: + key = 0; + } + + if (key) + XCursesSendKeyToCurses((unsigned long)key, NULL); } + /***********************************************************************/ #ifdef HAVE_PROTO -void XCursesKeyPress(Widget w,XEvent *event, String *params, Cardinal *nparams) +void XCursesKeyPress(Widget w, XEvent *event, String *params, + Cardinal *nparams) #else -void XCursesKeyPress(w,event,params,nparams) +void XCursesKeyPress(w, event, params, nparams) Widget w; XEvent *event; String *params; @@ -1679,320 +1769,308 @@ Cardinal *nparams; #define STATE_NORMAL 0 #define STATE_COMPOSE 1 #define STATE_CHAR 2 + #ifdef FOREIGN - wchar_t buffer[120]; + Status status; + wchar_t buffer[120]; #else - char buffer[120]; + char buffer[120]; #endif - int buflen=40; - int count,key,i; - KeySym keysym; - XComposeStatus compose; - static int compose_state=STATE_NORMAL; - static int compose_index=0; - int save_visibility=0; - int char_idx=0; - int xpos,ypos; + int buflen = 40; + int count, key, i; + KeySym keysym; + XComposeStatus compose; + static int compose_state = STATE_NORMAL; + static int compose_index = 0; + int save_visibility = 0; + int char_idx = 0; + int xpos,ypos; + chtype *ch; + short fore = 0, back = 0; + unsigned long modifier = 0; + + PDC_LOG(("%s:XCursesKeyPress called\n", XCLOGMSG)); + + /* ignore KeyReleases */ + + if (event->type == KeyRelease) + return; + + buffer[0] = '\0'; + #ifdef FOREIGN - Status status; -#endif - chtype *ch; - short fore=0,back=0; - unsigned long modifier=0; - - PDC_LOG(("%s:XCursesKeyPress called\n",(XCursesProcess)?" X":"CURSES")); - - if (event->type == KeyRelease) - return; /* ignore KeyReleases */ - - buffer[0] = '\0'; -#ifdef FOREIGN - count = XwcLookupString(Xic,&(event->xkey),buffer,buflen,&keysym, &status); - switch(status) - { - case XLookupNone: - fprintf(stderr,"XLookupNone status\n"); - break; - case XLookupKeySym: - fprintf(stderr,"XLookupKeySym status\n"); - break; - case XLookupBoth: - fprintf(stderr,"XLookupBoth status\n"); - break; - case XLookupChars: - fprintf(stderr,"XLookupChars status\n"); - break; - } + count = XwcLookupString(Xic, &(event->xkey), buffer, buflen, + &keysym, &status); #else - count = XLookupString(&(event->xkey),buffer,buflen,&keysym, &compose); + count = XLookupString(&(event->xkey), buffer, buflen, &keysym, + &compose); #endif - /* - * Handle modifier keys first. - */ + /* Handle modifier keys first */ -#if 0 -printf("Keypress\n"); -SP->return_key_modifiers = True; + if (event->type == KeyPress && keysym != compose_key + && IsModifierKey(keysym) && SP->return_key_modifiers) + { + switch (keysym) { + case XK_Shift_L: + key = KEY_SHIFT_L; + break; + case XK_Shift_R: + key = KEY_SHIFT_R; + break; + case XK_Control_L: + key = KEY_CONTROL_L; + break; + case XK_Control_R: + key = KEY_CONTROL_R; + break; + case XK_Alt_L: + key = KEY_ALT_L; + break; + case XK_Alt_R: + key = KEY_ALT_R; + break; + default: + key = 0; + } -printf("%d: %ld %d %d %d %d\n",__LINE__,keysym, - (event->type == KeyPress), - (keysym != compose_key), - (IsModifierKey(keysym)), - (SP->return_key_modifiers)); + if (key) + XCursesSendKeyToCurses((unsigned long)key, NULL); + return; + } - if (event->type == KeyPress - && keysym != compose_key - && IsModifierKey(keysym) - && SP->return_key_modifiers) - { - save_keysym = keysym; - return; - } + /* translate keysym into curses key code */ -printf("%d: %ld %d %d %d %d %d\n",__LINE__,keysym, - (event->type == KeyRelease), - (keysym != compose_key), - (IsModifierKey(keysym)), - (SP->return_key_modifiers), - (keysym == save_keysym) - ); -#endif + PDC_LOG(("%s:Key mask: %x\n", XCLOGMSG, event->xkey.state)); - if (event->type == KeyPress - && keysym != compose_key - && IsModifierKey(keysym) - && SP->return_key_modifiers) - { - key = 0; - if (keysym == XK_Shift_L) { key = KEY_SHIFT_L; } - else if (keysym == XK_Shift_R) { key = KEY_SHIFT_R; } - else if (keysym == XK_Control_L) { key = KEY_CONTROL_L; } - else if (keysym == XK_Control_R) { key = KEY_CONTROL_R; } - else if (keysym == XK_Alt_L) { key = KEY_ALT_L; } - else if (keysym == XK_Alt_R) { key = KEY_ALT_R; } - if (key) - XCursesSendKeyToCurses( (unsigned long)key, NULL ); - return; - } - -/* translate keysym into curses key code */ #ifdef PDCDEBUG - PDC_debug("%s:Key mask: %x\n",(XCursesProcess)?" X":"CURSES",event->xkey.state); - for (key=0;key<4;key++) - PDC_debug("%s:Keysym %x %d\n",(XCursesProcess)?" X":"CURSES",XKeycodeToKeysym(XCURSESDISPLAY,event->xkey.keycode,key),key); + for (key = 0; key < 4; key++) + PDC_debug("%s:Keysym %x %d\n", XCLOGMSG, + XKeycodeToKeysym(XCURSESDISPLAY, + event->xkey.keycode, key), key); #endif + key = 0; -/* fprintf(stderr,"KEY: %d %s\n",keysym,XKeysymToString(keysym));*/ - key = 0; - /* - * Check if the key just pressed is the user-specified compose key - * If it is, set the compose state and exit. - */ - if (keysym == compose_key) - { -/* fprintf(stderr,"Compose key pressed\n");*/ - /* - * Change the shape of the cursor to an outline rectangle - * to indicate we are in "compose" status - */ - save_visibility = SP->visibility; - SP->visibility = 0; - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); - SP->visibility = save_visibility;; - makeXY(SP->curscol,SP->cursrow,XCursesFontWidth,XCursesFontHeight,&xpos,&ypos); - ch = (chtype *)(Xcurscr+XCURSCR_Y_OFF(SP->cursrow)+((SP->curscol)*sizeof(chtype))); - SetCursorColor(ch,&fore,&back); - XSetForeground(XCURSESDISPLAY, rect_cursor_gc, colors[back]); - XDrawRectangle(XCURSESDISPLAY,XCURSESWIN,rect_cursor_gc,(xpos+1),(ypos-XCursesFontHeight+(XCURSESNORMALFONTINFO->descent)+1),(XCursesFontWidth-2),(XCursesFontHeight-2)); -/* fprintf(stderr,"Descent:%d Ascent:%d\n",XCURSESNORMALFONTINFO->descent,XCURSESNORMALFONTINFO->ascent);*/ - compose_state = STATE_COMPOSE; - return; - } -#if 0 - /* - * If the key just pressed is just a modifier, ignore it. - */ - if (IsModifierKey(keysym)) - { - return; - } -#endif - switch(compose_state) - { - case STATE_COMPOSE: - if (event->xkey.state & compose_mask) - { -/* fprintf(stderr,"STATE_COMPOSE: char has compose_mask\n");*/ - compose_state = STATE_NORMAL; - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); - break; - } - if (buffer[0] != 0 - && count == 1) - key = (int)buffer[0]; -/* fprintf(stderr,"STATE_COMPOSE: state %x %x\n",event->xkey.state,compose_mask);*/ - compose_index = (-1); - for (i=0;i<(int)strlen(compose_chars);i++) - { - if ((int)compose_chars[i] == key) - { - compose_index = i; - break; - } - } -/* fprintf(stderr,"STATE_COMPOSE: %d - compose_index\n",compose_index);*/ - if (compose_index == (-1)) - { - compose_state = STATE_NORMAL; - compose_index = 0; - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); - break; - } - compose_state = STATE_CHAR; - return; - break; - case STATE_CHAR: - if (event->xkey.state & compose_mask) - { -/* fprintf(stderr,"STATE_COMPOSE: char has compose_state\n");*/ - compose_state = STATE_NORMAL; - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); - break; - } - if (buffer[0] != 0 - && count == 1) - key = (int)buffer[0]; - char_idx = (-1); -/* fprintf(stderr,"STATE_CHAR: %d - compose_index\n",compose_index);*/ - for (i=0;icursrow,SP->curscol, - SP->cursrow,SP->curscol); - break; - } -/* fprintf(stderr,"STATE_CHAR: %d %c - key\n",compose_keys[compose_index][char_idx],compose_keys[compose_index][char_idx]);*/ - XCursesSendKeyToCurses( (unsigned long)compose_keys[compose_index][char_idx], NULL ); - compose_state = STATE_NORMAL; - compose_index = 0; - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); - return; - break; - default: - break; - } - /* - * To get here we are procesing "normal" keys - */ + /* Check if the key just pressed is the user-specified compose + key; if it is, set the compose state and exit. */ - PDC_LOG(("%s:Keysym %x %d\n",(XCursesProcess)?" X":"CURSES",XKeycodeToKeysym(XCURSESDISPLAY,event->xkey.keycode,key),key)); + if (keysym == compose_key) + { - if (SP->save_key_modifiers) - { - if (event->xkey.state & Mod2Mask) /* 0x10: usually, numlock modifier */ - { - modifier |= PDC_KEY_MODIFIER_NUMLOCK; - } - if (event->xkey.state & ShiftMask) /* 0x01: shift modifier */ - { - modifier |= PDC_KEY_MODIFIER_SHIFT; - } - if (event->xkey.state & ControlMask) /* 0x04: control modifier */ - { - modifier |= PDC_KEY_MODIFIER_CONTROL; - } - if (event->xkey.state & Mod1Mask) /* 0x08: usually, alt modifier */ - { - modifier |= PDC_KEY_MODIFIER_ALT; - } - } - for (i=0;XCursesKeys[i].keycode != 0;i++) - { - if (XCursesKeys[i].keycode == keysym) - { - PDC_LOG(("%s:State %x\n",(XCursesProcess)?" X":"CURSES",event->xkey.state)); + /* Change the shape of the cursor to an outline rectangle + to indicate we are in "compose" status */ - if (XCursesKeys[i].numkeypad) - { - if (event->xkey.state & Mod2Mask /* 0x10: usually, numlock modifier */ - || event->xkey.state & ShiftMask) /* or 0x01: shift modifier */ - { - key = XCursesKeys[i].shifted; - break; - } - } - if (event->xkey.state & ShiftMask) /* 0x01: shift modifier */ - { - key = XCursesKeys[i].shifted; - break; - } - if (event->xkey.state & ControlMask) /* 0x04: control modifier */ - { - key = XCursesKeys[i].control; - break; - } - if (event->xkey.state & Mod1Mask) /* 0x08: usually, alt modifier */ - { - key = XCursesKeys[i].alt; - break; - } -/*---------------------------------------------------------------------*/ -/* To get here, we ignore all other modifiers. */ -/*---------------------------------------------------------------------*/ - key = XCursesKeys[i].normal; - break; - } - } - if (key == 0 - && buffer[0] != 0 - && count == 1) - key = (int)buffer[0]; + save_visibility = SP->visibility; + SP->visibility = 0; - PDC_LOG(("%s:Key: %s pressed - %x Mod: %x\n",(XCursesProcess)?" X":"CURSES",XKeysymToString(keysym),key,event->xkey.state)); + XCursesDisplayCursor(SP->cursrow, SP->curscol, + SP->cursrow, SP->curscol); -/*---------------------------------------------------------------------*/ -/* Handle ALT letters and numbers... */ -/*---------------------------------------------------------------------*/ - if (event->xkey.state == Mod1Mask) - { - if (key >= (int)'A' - && key <= (int)'Z') - key = ALT_A + (key - (int)('A')); - if (key >= (int)'a' - && key <= (int)'z') - key = ALT_A + (key - (int)('a')); - if (key >= (int)'0' - && key <= (int)'9') - key = ALT_0 + (key - (int)('0')); - } -/*---------------------------------------------------------------------*/ -/* After all that, send the key back to the application if is NOT zero.*/ -/*---------------------------------------------------------------------*/ - if (key) - { - key = key | modifier << 24; /* (sizeof(unsigned long) - sizeof(unsigned char)); */ - XCursesSendKeyToCurses( (unsigned long)key, NULL ); - } - return; + SP->visibility = save_visibility; + makeXY(SP->curscol, SP->cursrow, XCursesFontWidth, + XCursesFontHeight, &xpos, &ypos); + + ch = (chtype *)(Xcurscr + XCURSCR_Y_OFF(SP->cursrow) + + (SP->curscol * sizeof(chtype))); + + SetCursorColor(ch, &fore, &back); + + XSetForeground(XCURSESDISPLAY, rect_cursor_gc, colors[back]); + + XDrawRectangle(XCURSESDISPLAY, XCURSESWIN, rect_cursor_gc, + xpos + 1, ypos - XCursesFontHeight + + XCURSESNORMALFONTINFO->descent + 1, + XCursesFontWidth - 2, XCursesFontHeight - 2); + + compose_state = STATE_COMPOSE; + return; + } + + switch(compose_state) + { + case STATE_COMPOSE: + if (event->xkey.state & compose_mask) + { + compose_state = STATE_NORMAL; + XCursesDisplayCursor(SP->cursrow, SP->curscol, + SP->cursrow, SP->curscol); + break; + } + + if (buffer[0] != 0 && count == 1) + key = (int)buffer[0]; + + compose_index = -1; + + + for (i = 0; i < (int)strlen(compose_chars); i++) + if ((int)compose_chars[i] == key) + { + compose_index = i; + break; + } + + if (compose_index == -1) + { + compose_state = STATE_NORMAL; + compose_index = 0; + XCursesDisplayCursor(SP->cursrow, SP->curscol, + SP->cursrow, SP->curscol); + break; + } + + compose_state = STATE_CHAR; + return; + + case STATE_CHAR: + if (event->xkey.state & compose_mask) + { + compose_state = STATE_NORMAL; + XCursesDisplayCursor(SP->cursrow, SP->curscol, + SP->cursrow, SP->curscol); + break; + } + + if (buffer[0] != 0 && count == 1) + key = (int)buffer[0]; + + char_idx = -1; + + for (i = 0; i < MAX_COMPOSE_CHARS; i++) + if (compose_lookups[compose_index][i] == key) + { + char_idx = i; + break; + } + + if (char_idx == -1) + { + compose_state = STATE_NORMAL; + compose_index = 0; + XCursesDisplayCursor(SP->cursrow, SP->curscol, + SP->cursrow, SP->curscol); + break; + } + + XCursesSendKeyToCurses( + (unsigned long)compose_keys[compose_index][char_idx], + NULL); + + compose_state = STATE_NORMAL; + compose_index = 0; + + XCursesDisplayCursor(SP->cursrow, SP->curscol, + SP->cursrow, SP->curscol); + + return; + } + + /* To get here we are procesing "normal" keys */ + + PDC_LOG(("%s:Keysym %x %d\n", XCLOGMSG, + XKeycodeToKeysym(XCURSESDISPLAY, event->xkey.keycode, key), + key)); + + if (SP->save_key_modifiers) + { + /* 0x10: usually, numlock modifier */ + + if (event->xkey.state & Mod2Mask) + modifier |= PDC_KEY_MODIFIER_NUMLOCK; + + /* 0x01: shift modifier */ + + if (event->xkey.state & ShiftMask) + modifier |= PDC_KEY_MODIFIER_SHIFT; + + /* 0x04: control modifier */ + + if (event->xkey.state & ControlMask) + modifier |= PDC_KEY_MODIFIER_CONTROL; + + /* 0x08: usually, alt modifier */ + + if (event->xkey.state & Mod1Mask) + modifier |= PDC_KEY_MODIFIER_ALT; + } + + for (i = 0; XCursesKeys[i].keycode != 0; i++) + { + if (XCursesKeys[i].keycode == keysym) + { + PDC_LOG(("%s:State %x\n", XCLOGMSG, event->xkey.state)); + + /* ControlMask: 0x04: control modifier + Mod1Mask: 0x08: usually, alt modifier + Mod2Mask: 0x10: usually, numlock modifier + ShiftMask: 0x01: shift modifier */ + + if (XCursesKeys[i].numkeypad && (event->xkey.state & + Mod2Mask || event->xkey.state & ShiftMask)) + { + key = XCursesKeys[i].shifted; + break; + } + + if (event->xkey.state & ShiftMask) + { + key = XCursesKeys[i].shifted; + break; + } + + if (event->xkey.state & ControlMask) + { + key = XCursesKeys[i].control; + break; + } + + if (event->xkey.state & Mod1Mask) + { + key = XCursesKeys[i].alt; + break; + } + + /* To get here, we ignore all other modifiers */ + + key = XCursesKeys[i].normal; + break; + } + } + + if (key == 0 && buffer[0] != 0 && count == 1) + key = (int)buffer[0]; + + PDC_LOG(("%s:Key: %s pressed - %x Mod: %x\n", XCLOGMSG, + XKeysymToString(keysym), key, event->xkey.state)); + + /* Handle ALT letters and numbers */ + + if (event->xkey.state == Mod1Mask) + { + if (key >= (int)'A' && key <= (int)'Z') + key = ALT_A + (key - (int)('A')); + + if (key >= (int)'a' && key <= (int)'z') + key = ALT_A + (key - (int)('a')); + + if (key >= (int)'0' && key <= (int)'9') + key = ALT_0 + (key - (int)('0')); + } + + /* After all that, send the key back to the application if is + NOT zero. */ + + if (key) + { + key = key | modifier << 24; + + XCursesSendKeyToCurses((unsigned long)key, NULL); + } } + /***********************************************************************/ #ifdef HAVE_PROTO -void XCursesHandleString(Widget w, XEvent *event, String *params, Cardinal *nparams) +void XCursesHandleString(Widget w, XEvent *event, String *params, + Cardinal *nparams) #else void XCursesHandleString(w, event, params, nparams) Widget w; @@ -2002,69 +2080,72 @@ Cardinal *nparams; #endif /***********************************************************************/ { - register int i=0; - unsigned char *ptr=NULL; + int i = 0; + unsigned char *ptr = NULL; - if (*nparams != 1) - return; + if (*nparams != 1) + return; - if ((*params)[0] == '0' - && (*params)[1] == 'x' - && (*params)[2] != '\0') - { - unsigned char c; - int total=0; - char *p; - for (p = *params+2; (c = *p); p++) - { - total *= 16; - if (isupper(c)) c = tolower(c); - if (c >= '0' && c <= '9') - total += c - '0'; - else - { - if (c >= 'a' && c <= 'f') - total += c - 'a' + 10; - else - break; - } - } - if (c == '\0') - XCursesSendKeyToCurses( (unsigned long)total, NULL ); - } - else - { - ptr = (unsigned char *)*params; - for (i=0;i<(int)strlen((char *)ptr);i++) - { - XCursesSendKeyToCurses( (unsigned long)*(ptr+i), NULL ); - } - } - return; + if ((*params)[0] == '0' && (*params)[1] == 'x' && (*params)[2] != '\0') + { + unsigned char c; + int total = 0; + char *p; + + for (p = *params + 2; (c = *p); p++) + { + total *= 16; + + if (isupper(c)) + c = tolower(c); + + if (c >= '0' && c <= '9') + total += c - '0'; + else + if (c >= 'a' && c <= 'f') + total += c - 'a' + 10; + else + break; + } + + if (c == '\0') + XCursesSendKeyToCurses((unsigned long)total, NULL); + } + else + { + ptr = (unsigned char *)*params; + + for (i = 0; i < (int)strlen((char *)ptr); i++) + XCursesSendKeyToCurses((unsigned long)(ptr[i]), NULL); + } } + /***********************************************************************/ #ifdef HAVE_PROTO -void XCursesPasteSelection(Widget w,XButtonEvent *button_event) +void XCursesPasteSelection(Widget w, XButtonEvent *button_event) #else -void XCursesPasteSelection(w,button_event) +void XCursesPasteSelection(w, button_event) Widget w; XButtonEvent *button_event; #endif /***********************************************************************/ { - PDC_LOG(("%s:XCursesPasteSelection() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesPasteSelection() - called\n", XCLOGMSG)); - XtGetSelectionValue(w,XA_PRIMARY,XA_STRING,XCursesRequestorCallbackForPaste,(XtPointer)button_event,button_event->time); - return; + XtGetSelectionValue(w, XA_PRIMARY, XA_STRING, + XCursesRequestorCallbackForPaste, + (XtPointer)button_event, button_event->time); } /***********************************************************************/ #ifdef HAVE_PROTO -void XCursesRequestorCallbackForPaste(Widget w,XtPointer data, Atom *selection, - Atom *type, XtPointer value, - unsigned long *length, int *format) +void XCursesRequestorCallbackForPaste(Widget w, XtPointer data, + Atom *selection, Atom *type, + XtPointer value, + unsigned long *length, int *format) #else -void XCursesRequestorCallbackForPaste(w,data,selection,type,value,length,format) +void XCursesRequestorCallbackForPaste(w, data, selection, type, value, + length, format) Widget w; XtPointer data; Atom *selection; @@ -2075,32 +2156,34 @@ int *format; #endif /***********************************************************************/ { - unsigned long i=0,key=0; - char *string=(char *)value; + unsigned long i, key; + char *string = (char *)value; - PDC_LOG(("%s:XCursesRequestorCallbackForPaste() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesRequestorCallbackForPaste() - called\n", + XCLOGMSG)); - if ((value == NULL) && (*length == 0)) - return; + if ((value == NULL) && (*length == 0)) + return; - for (i=0;i<(*length);i++) - { - key = (unsigned long)(*(string+i)); - if (key == 10) /* new line - convert to ^M */ - key = 13; - XCursesSendKeyToCurses( key, NULL ); - } - return; + for (i = 0; i < (*length); i++) + { + key = (unsigned long)(string[i]); + + if (key == 10) /* new line - convert to ^M */ + key = 13; + + XCursesSendKeyToCurses(key, NULL); + } } /***********************************************************************/ #ifdef HAVE_PROTO Boolean XCursesConvertProc(Widget w,Atom *selection, Atom *target, - Atom *type_return, XtPointer *value_return, - unsigned long *length_return, int *format_return) + Atom *type_return, XtPointer *value_return, + unsigned long *length_return, int *format_return) #else -Boolean XCursesConvertProc(w,selection,target,type_return,value_return, - length_return,format_return) +Boolean XCursesConvertProc(w, selection, target, type_return, value_return, + length_return, format_return) Widget w; Atom *selection; Atom *target; @@ -2111,123 +2194,138 @@ int *format_return; #endif /***********************************************************************/ { - PDC_LOG(("%s:XCursesConvertProc() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesConvertProc() - called\n", XCLOGMSG)); - if (*target == XA_TARGETS(XtDisplay(topLevel))) - { - XSelectionRequestEvent *req = XtGetSelectionRequest(w, *selection, (XtRequestId)NULL); - Atom *targetP; - XPointer std_targets; - unsigned long std_length; - XmuConvertStandardSelection(topLevel, req->time, selection, - target, type_return, &std_targets, &std_length, - format_return); - *value_return = XtMalloc(sizeof(Atom)*(std_length + 1)); - targetP = *(Atom**)value_return; - *length_return = std_length + 1; - *targetP++ = XA_STRING; - bcopy((char *)std_targets, (char *)targetP, sizeof(Atom)*std_length); - XtFree((char *)std_targets); - *type_return = XA_ATOM; - *format_return = sizeof(Atom) * 8; - return True; - } - else if (*target == XA_STRING) - { - char *data = XtMalloc(tmpsel_length+1); - memcpy(data,tmpsel,tmpsel_length); - *value_return = data; - *length_return = tmpsel_length; - *format_return = 8; - *type_return = XA_STRING; - return True; - } - else - { - if (XmuConvertStandardSelection(topLevel, CurrentTime, selection, target, type_return, - (XPointer*)value_return, length_return, format_return)) - return True; - else - return False; - } - return False; + if (*target == XA_TARGETS(XtDisplay(topLevel))) + { + XSelectionRequestEvent *req = XtGetSelectionRequest(w, + *selection, (XtRequestId)NULL); + + Atom *targetP; + XPointer std_targets; + unsigned long std_length; + + XmuConvertStandardSelection(topLevel, req->time, + selection, target, type_return, &std_targets, + &std_length, format_return); + + *value_return = XtMalloc(sizeof(Atom) * (std_length + 1)); + targetP = *(Atom**)value_return; + *length_return = std_length + 1; + *targetP++ = XA_STRING; + + bcopy((char *)std_targets, (char *)targetP, + sizeof(Atom) * std_length); + + XtFree((char *)std_targets); + *type_return = XA_ATOM; + *format_return = sizeof(Atom) * 8; + + return True; + } + else if (*target == XA_STRING) + { + char *data = XtMalloc(tmpsel_length + 1); + + memcpy(data, tmpsel, tmpsel_length); + *value_return = data; + *length_return = tmpsel_length; + *format_return = 8; + *type_return = XA_STRING; + + return True; + } + else + { + if (XmuConvertStandardSelection(topLevel, CurrentTime, + selection, target, type_return, + (XPointer*)value_return, length_return, format_return)) + return True; + else + return False; + } + + return False; } /***********************************************************************/ #ifdef HAVE_PROTO void XCursesLoseOwnership(Widget w, Atom *type) #else -void XCursesLoseOwnership(w,type) +void XCursesLoseOwnership(w, type) Widget w; Atom *type; #endif /***********************************************************************/ { - PDC_LOG(("%s:XCursesLoseOwnership() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesLoseOwnership() - called\n", XCLOGMSG)); - if (tmpsel) free(tmpsel); - tmpsel = NULL; - tmpsel_length = 0; - SelectionOff(); - return; + if (tmpsel) + free(tmpsel); + + tmpsel = NULL; + tmpsel_length = 0; + SelectionOff(); } /***********************************************************************/ #ifdef HAVE_PROTO -void ShowSelection( int start_x, int start_y, int end_x, int end_y, bool highlight ) +void ShowSelection(int start_x, int start_y, int end_x, int end_y, + bool highlight) #else -void ShowSelection( start_x, start_y, end_x, end_y, highlight ) +void ShowSelection(start_x, start_y, end_x, end_y, highlight) int start_x, start_y, end_x, end_y; bool highlight; #endif /***********************************************************************/ { - int i,num_cols,start_col,row; + int i, num_cols, start_col, row; - PDC_LOG(("%s:ShowSelection() - called StartX: %d StartY: %d EndX: %d EndY: %d Highlight: %d\n",(XCursesProcess)?" X":"CURSES", start_x, start_y, end_x, end_y, highlight )); + PDC_LOG(("%s:ShowSelection() - called StartX: %d StartY: %d EndX: %d EndY: %d Highlight: %d\n", + XCLOGMSG, start_x, start_y, end_x, end_y, highlight)); - for (i=0; i< (end_y-start_y)+1; i++) - { - if (start_y == end_y) /* all one one line */ - { - start_col = start_x; - num_cols = end_x - start_x + 1; - row = start_y; - } - else if (i == 0) /* first line of multi-line stream */ - { - start_col = start_x; - num_cols = COLS - start_x; - row = start_y; - } - else if (start_y+i == end_y) /* last line of multi-line stream */ - { - start_col = 0; - num_cols = end_x + 1; - row = end_y; - } - else /* full line */ - { - start_col = 0; - num_cols = COLS; - row = start_y+i; - } - while(*(Xcurscr+XCURSCR_FLAG_OFF+row)) - /* - * Patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 - */ - dummy_function(); /* loop until we can write to the line */ - /* - * End of patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 - */ + for (i = 0; i < end_y - start_y + 1; i++) + { - *(Xcurscr+XCURSCR_FLAG_OFF+row) = 1; - XCursesDisplayText((chtype *)(Xcurscr+XCURSCR_Y_OFF(row)+(start_col*sizeof(chtype))),row,start_col,num_cols,highlight); - *(Xcurscr+XCURSCR_FLAG_OFF+row) = 0; - } - return; + if (start_y == end_y) /* only one line */ + { + start_col = start_x; + num_cols = end_x - start_x + 1; + row = start_y; + } + else if (i == 0) /* first line */ + { + start_col = start_x; + num_cols = COLS - start_x; + row = start_y; + } + else if (start_y + i == end_y) /* last line */ + { + start_col = 0; + num_cols = end_x + 1; + row = end_y; + } + else /* full line */ + { + start_col = 0; + num_cols = COLS; + row = start_y + i; + } + + /* loop until we can write to the line - Patch by: Georg + Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 */ + + while (*(Xcurscr + XCURSCR_FLAG_OFF + row)) + dummy_function(); + + *(Xcurscr + XCURSCR_FLAG_OFF + row) = 1; + + XCursesDisplayText((chtype *)(Xcurscr + XCURSCR_Y_OFF(row) + + (start_col * sizeof(chtype))), row, start_col, + num_cols, highlight); + + *(Xcurscr + XCURSCR_FLAG_OFF + row) = 0; + } } /***********************************************************************/ @@ -2238,306 +2336,373 @@ void SelectionOff() #endif /***********************************************************************/ { - PDC_LOG(("%s:SelectionOff() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:SelectionOff() - called\n", XCLOGMSG)); - XCursesDisplayScreen(FALSE); - selection_start_x = selection_start_y = selection_end_x = selection_end_y = 0; - mouse_selection = False; + XCursesDisplayScreen(FALSE); + + selection_start_x = selection_start_y = selection_end_x = + selection_end_y = 0; + + mouse_selection = False; } /***********************************************************************/ #ifdef HAVE_PROTO -void SelectionOn(int x,int y) +void SelectionOn(int x, int y) #else -void SelectionOn(x,y) -int x,y; +void SelectionOn(x, y) +int x, y; #endif /***********************************************************************/ { - PDC_LOG(("%s:SelectionOn() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:SelectionOn() - called\n", XCLOGMSG)); - selection_start_x = selection_end_x = x; - selection_start_y = selection_end_y = y; + selection_start_x = selection_end_x = x; + selection_start_y = selection_end_y = y; } /***********************************************************************/ #ifdef HAVE_PROTO -void SelectionExtend(int x,int y) +void SelectionExtend(int x, int y) #else -void SelectionExtend(x,y) -int x,y; +void SelectionExtend(x, y) +int x, y; #endif /***********************************************************************/ { - int temp; - int current_start,current_end,current_start_x,current_end_x,current_start_y,current_end_y; - int new_start,new_end,new_start_x,new_end_x,new_start_y,new_end_y; + int temp, current_start, current_end, current_start_x, + current_end_x, current_start_y, current_end_y, + new_start, new_end, new_start_x, new_end_x, new_start_y, + new_end_y; - PDC_LOG(("%s:SelectionExtend() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:SelectionExtend() - called\n", XCLOGMSG)); - mouse_selection = True; + mouse_selection = True; - /* convert x/y coordinates into start/stop */ - current_start = (selection_start_y * COLS) + selection_start_x; - current_end = (selection_end_y * COLS) + selection_end_x; - if (current_start > current_end) - { - current_start_x = selection_end_x; - current_start_y = selection_end_y; - current_end_x = selection_start_x; - current_end_y = selection_start_y; - temp = current_start; - current_start = current_end; - current_end = temp; - } - else - { - current_end_x = selection_end_x; - current_end_y = selection_end_y; - current_start_x = selection_start_x; - current_start_y = selection_start_y; - } - /* - * Now we have the current selection as a linear expression. - * Convert the new position to a linear expression. - */ - selection_end_x = x; - selection_end_y = y; + /* convert x/y coordinates into start/stop */ - /* convert x/y coordinates into start/stop */ - new_start = (selection_start_y * COLS) + selection_start_x; - new_end = (selection_end_y * COLS) + selection_end_x; - if (new_start > new_end) - { - new_start_x = selection_end_x; - new_start_y = selection_end_y; - new_end_x = selection_start_x; - new_end_y = selection_start_y; - temp = new_start; - new_start = new_end; - new_end = temp; - } - else - { - new_end_x = selection_end_x; - new_end_y = selection_end_y; - new_start_x = selection_start_x; - new_start_y = selection_start_y; - } - if (new_end > current_end) - ShowSelection(current_end_x, current_end_y, new_end_x, new_end_y, TRUE ); - else if (new_end < current_end) - ShowSelection(new_end_x, new_end_y, current_end_x, current_end_y, FALSE ); - else if (new_start < current_start) - ShowSelection(new_start_x, new_start_y, current_start_x, current_start_y, TRUE ); - else if (new_start > current_start) - ShowSelection(current_start_x, current_start_y, new_start_x, new_start_y, FALSE ); - else - ShowSelection(current_start_x, current_start_y, new_start_x, new_start_y, TRUE ); + current_start = (selection_start_y * COLS) + selection_start_x; + current_end = (selection_end_y * COLS) + selection_end_x; + + if (current_start > current_end) + { + current_start_x = selection_end_x; + current_start_y = selection_end_y; + current_end_x = selection_start_x; + current_end_y = selection_start_y; + temp = current_start; + current_start = current_end; + current_end = temp; + } + else + { + current_end_x = selection_end_x; + current_end_y = selection_end_y; + current_start_x = selection_start_x; + current_start_y = selection_start_y; + } + + /* Now we have the current selection as a linear expression. + Convert the new position to a linear expression. */ + + selection_end_x = x; + selection_end_y = y; + + /* convert x/y coordinates into start/stop */ + + new_start = (selection_start_y * COLS) + selection_start_x; + new_end = (selection_end_y * COLS) + selection_end_x; + + if (new_start > new_end) + { + new_start_x = selection_end_x; + new_start_y = selection_end_y; + new_end_x = selection_start_x; + new_end_y = selection_start_y; + temp = new_start; + new_start = new_end; + new_end = temp; + } + else + { + new_end_x = selection_end_x; + new_end_y = selection_end_y; + new_start_x = selection_start_x; + new_start_y = selection_start_y; + } + + if (new_end > current_end) + ShowSelection(current_end_x, current_end_y, new_end_x, + new_end_y, TRUE); + else if (new_end < current_end) + ShowSelection(new_end_x, new_end_y, current_end_x, + current_end_y, FALSE); + else if (new_start < current_start) + ShowSelection(new_start_x, new_start_y, current_start_x, + current_start_y, TRUE); + else if (new_start > current_start) + ShowSelection(current_start_x, current_start_y, + new_start_x, new_start_y, FALSE); + else + ShowSelection(current_start_x, current_start_y, + new_start_x, new_start_y, TRUE); } /***********************************************************************/ #ifdef HAVE_PROTO -void SelectionSet( void ) +void SelectionSet(void) #else void SelectionSet() #endif /***********************************************************************/ { - int i,j,start,end,start_x,end_x,start_y,end_y,num_cols,start_col,row,num_chars; - int ch,last_nonblank,length; - chtype *ptr=NULL; + int i, j, start, end, start_x, end_x, start_y, end_y, num_cols, + start_col, row, num_chars, ch, last_nonblank, length; + chtype *ptr = NULL; - PDC_LOG(("%s:SelectionSet() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:SelectionSet() - called\n", XCLOGMSG)); -/* convert x/y coordinates into start/stop */ - start = (selection_start_y * COLS) + selection_start_x; - end = (selection_end_y * COLS) + selection_end_x; - if (start == end) - { - if (tmpsel) free(tmpsel); - tmpsel = NULL; - tmpsel_length = 0; - return; - } - if (start > end) - { - start_x = selection_end_x; - start_y = selection_end_y; - end_x = selection_start_x; - end_y = selection_start_y; - length = start - end +1; - } - else - { - end_x = selection_end_x; - end_y = selection_end_y; - start_x = selection_start_x; - start_y = selection_start_y; - length = end - start +1; - } - if (length > tmpsel_length) - { - if (tmpsel_length == 0) - tmpsel = (char *)malloc(length+1+end_y-start_y+1); - else - tmpsel = (char *)realloc(tmpsel,length+1+end_y-start_y+1); - } - if (!tmpsel) - { - tmpsel_length = 0; - return; - } - tmpsel_length = length; - num_chars = 0; - for (i=0; i< (end_y-start_y)+1; i++) - { - if (start_y == end_y) /* all one one line */ - { - start_col = start_x; - num_cols = end_x - start_x + 1; - row = start_y; - } - else if (i == 0) /* first line of multi-line stream */ - { - start_col = start_x; - num_cols = COLS - start_x; - row = start_y; - } - else if (start_y+i == end_y) /* last line of multi-line stream */ - { - start_col = 0; - num_cols = end_x + 1; - row = end_y; - } - else /* full line */ - { - start_col = 0; - num_cols = COLS; - row = start_y+i; - } - while(*(Xcurscr+XCURSCR_FLAG_OFF+row)) - /* - * Patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 - */ - dummy_function(); /* loop until we can write to the line */ - /* - * End of patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 - */ + /* convert x/y coordinates into start/stop */ - *(Xcurscr+XCURSCR_FLAG_OFF+row) = 1; - ptr = (chtype *)(Xcurscr+XCURSCR_Y_OFF(row)+(start_col*sizeof(chtype))); - if ( i < end_y-start_y ) - { - last_nonblank = 0; - for (j=0; j end) + { + start_x = selection_end_x; + start_y = selection_end_y; + end_x = selection_start_x; + end_y = selection_start_y; + length = start - end + 1; + } + else + { + end_x = selection_end_x; + end_y = selection_end_y; + start_x = selection_start_x; + start_y = selection_start_y; + length = end - start + 1; + } + + if (length > tmpsel_length) + { + if (tmpsel_length == 0) + tmpsel = (char *)malloc(length + 1 + + end_y - start_y + 1); + else + tmpsel = (char *)realloc(tmpsel, length + 1 + + end_y - start_y + 1); + } + + if (!tmpsel) + { + tmpsel_length = 0; + return; + } + + tmpsel_length = length; + num_chars = 0; + + for (i = 0; i < end_y - start_y + 1; i++) + { + + if (start_y == end_y) /* only one line */ + { + start_col = start_x; + num_cols = end_x - start_x + 1; + row = start_y; + } + else if (i == 0) /* first line */ + { + start_col = start_x; + num_cols = COLS - start_x; + row = start_y; + } + else if (start_y + i == end_y) /* last line */ + { + start_col = 0; + num_cols = end_x + 1; + row = end_y; + } + else /* full line */ + { + start_col = 0; + num_cols = COLS; + row = start_y + i; + } + + /* loop until we can write to the line -- Patch by: + Georg Fuchs, georg.fuchs@rz.uni-regensburg.de */ + + while (*(Xcurscr + XCURSCR_FLAG_OFF + row)) + dummy_function(); + + *(Xcurscr + XCURSCR_FLAG_OFF + row) = 1; + + ptr = (chtype *)(Xcurscr + XCURSCR_Y_OFF(row) + + start_col * sizeof(chtype)); + + if (i < end_y-start_y) + { + last_nonblank = 0; + + for (j = 0; j < num_cols; j++) + { + ch = (int)(ptr[j] & A_CHARTEXT); + if (ch != (int)' ') + last_nonblank = j; + } + } + else + last_nonblank = num_cols - 1; + + for (j = 0; j <= last_nonblank; j++) + tmpsel[num_chars++] = (int)(ptr[j] & A_CHARTEXT); + + *(Xcurscr + XCURSCR_FLAG_OFF + row) = 0; + + if (i < end_y - start_y) + tmpsel[num_chars++] = '\n'; + } + + tmpsel[num_chars] = '\0'; + tmpsel_length = num_chars; } /***********************************************************************/ #ifdef HAVE_PROTO -void XCursesDisplayCursor(int old_row,int old_x,int new_row,int new_x) +void XCursesDisplayCursor(int old_row, int old_x, int new_row, int new_x) #else -void XCursesDisplayCursor(old_row,old_x,new_row,new_x) -int old_row,old_x,new_row,new_x; +void XCursesDisplayCursor(old_row, old_x, new_row, new_x) +int old_row, old_x, new_row, new_x; #endif /***********************************************************************/ { - int xpos,ypos,i; - char buf[2]; - chtype *ch; - short fore=0,back=0; + int xpos, ypos, i; + char buf[2]; + chtype *ch; + short fore = 0, back = 0; - PDC_LOG(("%s:XCursesDisplayCursor() - draw char at row: %d col %d\n",(XCursesProcess)?" X":"CURSES",old_row,old_x)); + PDC_LOG(("%s:XCursesDisplayCursor() - draw char at row: %d col %d\n", + XCLOGMSG, old_row, old_x)); - /* - * If the cursor position is outside the boundary of the screen, ignore - * request. - */ - if (old_row >= XCursesLINES - || old_x >= COLS - || new_row >= XCursesLINES - || new_x >= COLS) - return; + /* if the cursor position is outside the boundary of the screen, + ignore the request */ - /* display the character at the current cursor position */ + if (old_row >= XCursesLINES || old_x >= COLS || + new_row >= XCursesLINES || new_x >= COLS) + return; - PDC_LOG(("%s:XCursesDisplayCursor() - draw char at row: %d col %d\n",(XCursesProcess)?" X":"CURSES",old_row,old_x)); + /* display the character at the current cursor position */ - XCursesDisplayText( (chtype *)(Xcurscr+(XCURSCR_Y_OFF(old_row)+(old_x*sizeof(chtype)))), old_row, old_x, 1, FALSE ); - /* display the cursor at the new cursor position */ + PDC_LOG(("%s:XCursesDisplayCursor() - draw char at row: %d col %d\n", + XCLOGMSG, old_row, old_x)); - switch( SP->visibility ) - { - case 0: /* cursor not displayed, no more to do */ - break; - case 1: /* cursor visibility normal */ - makeXY( new_x, new_row, XCursesFontWidth, XCursesFontHeight, &xpos, &ypos ); - ch = (chtype *)(Xcurscr+XCURSCR_Y_OFF(new_row)+(new_x*sizeof(chtype))); - SetCursorColor( ch, &fore, &back ); - XSetForeground( XCURSESDISPLAY, rect_cursor_gc, colors[back] ); - if ( vertical_cursor ) - { - XDrawLine( XCURSESDISPLAY, XCURSESWIN, rect_cursor_gc, - xpos+1, ypos-XCURSESNORMALFONTINFO->ascent, xpos+1, ypos-XCURSESNORMALFONTINFO->ascent+XCursesFontHeight-1 ); - } - else - { - for ( i = 0; i < XCURSESNORMALFONTINFO->descent + 2; i++ ) - XDrawLine( XCURSESDISPLAY, XCURSESWIN, rect_cursor_gc, (xpos), (ypos-2+i), (xpos+XCursesFontWidth), (ypos-2+i) ); - } + XCursesDisplayText((chtype *)(Xcurscr + (XCURSCR_Y_OFF(old_row) + + (old_x * sizeof(chtype)))), old_row, old_x, 1, FALSE); - PDC_LOG(("%s:XCursesDisplayCursor() - draw line at row %d col %d\n",(XCursesProcess)?" X":"CURSES",new_row,new_x)); - break; - default: /* cursor visibility high */ - makeXY( new_x, new_row, XCursesFontWidth, XCursesFontHeight, &xpos, &ypos ); - ch = (chtype *)(Xcurscr+XCURSCR_Y_OFF(new_row)+(new_x*sizeof(chtype))); - SetCursorColor( ch, &fore, &back ); - if ( vertical_cursor ) - { - XSetForeground( XCURSESDISPLAY, rect_cursor_gc, colors[back] ); - XDrawLine( XCURSESDISPLAY, XCURSESWIN, rect_cursor_gc, - xpos+1, ypos-XCURSESNORMALFONTINFO->ascent, xpos+1, ypos-XCURSESNORMALFONTINFO->ascent+XCursesFontHeight-1 ); - XDrawLine( XCURSESDISPLAY, XCURSESWIN, rect_cursor_gc, - xpos+2, ypos-XCURSESNORMALFONTINFO->ascent, xpos+2, ypos-XCURSESNORMALFONTINFO->ascent+XCursesFontHeight-1 ); - } - else - { - buf[0] = (char)(*ch & A_CHARTEXT); - buf[1] = '\0'; - XSetForeground( XCURSESDISPLAY, block_cursor_gc, colors[fore] ); - XSetBackground( XCURSESDISPLAY, block_cursor_gc, colors[back] ); - XDrawImageString( XCURSESDISPLAY, XCURSESWIN, block_cursor_gc, xpos, ypos, buf, 1 ); - } - PDC_LOG(("%s:XCursesDisplayCursor() - draw cursor at row: %d col %d char <%s>\n",(XCursesProcess)?" X":"CURSES",new_row,new_x,buf)); - break; - } - return; + /* display the cursor at the new cursor position */ + + switch(SP->visibility) + { + case 0: /* cursor not displayed, no more to do */ + break; + + case 1: /* cursor visibility normal */ + + makeXY(new_x, new_row, XCursesFontWidth, + XCursesFontHeight, &xpos, &ypos); + + ch = (chtype *)(Xcurscr + XCURSCR_Y_OFF(new_row) + + new_x * sizeof(chtype)); + + SetCursorColor(ch, &fore, &back); + XSetForeground(XCURSESDISPLAY, rect_cursor_gc, colors[back]); + + if (vertical_cursor) + XDrawLine(XCURSESDISPLAY, XCURSESWIN, rect_cursor_gc, + xpos + 1, + ypos - XCURSESNORMALFONTINFO->ascent, + xpos + 1, + ypos - XCURSESNORMALFONTINFO->ascent + + XCursesFontHeight - 1); + else + for (i = 0; i < XCURSESNORMALFONTINFO->descent + 2; i++) + XDrawLine(XCURSESDISPLAY, XCURSESWIN, rect_cursor_gc, + xpos, + ypos - 2 + i, + xpos + XCursesFontWidth, + ypos - 2 + i); + + PDC_LOG(("%s:XCursesDisplayCursor() - draw line at row %d col %d\n", + XCLOGMSG, new_row, new_x)); + + break; + + default: /* cursor visibility high */ + + makeXY(new_x, new_row, XCursesFontWidth, + XCursesFontHeight, &xpos, &ypos); + + ch = (chtype *)(Xcurscr + XCURSCR_Y_OFF(new_row) + + new_x * sizeof(chtype)); + + SetCursorColor(ch, &fore, &back); + + if (vertical_cursor) + { + XSetForeground(XCURSESDISPLAY, rect_cursor_gc, + colors[back]); + + XDrawLine(XCURSESDISPLAY, XCURSESWIN, rect_cursor_gc, + xpos + 1, + ypos - XCURSESNORMALFONTINFO->ascent, + xpos + 1, + ypos - XCURSESNORMALFONTINFO->ascent + + XCursesFontHeight - 1); + + XDrawLine(XCURSESDISPLAY, XCURSESWIN, rect_cursor_gc, + xpos + 2, + ypos - XCURSESNORMALFONTINFO->ascent, + xpos + 2, + ypos - XCURSESNORMALFONTINFO->ascent + + XCursesFontHeight - 1); + } + else + { + buf[0] = (char)(*ch & A_CHARTEXT); + buf[1] = '\0'; + + XSetForeground(XCURSESDISPLAY, block_cursor_gc, + colors[fore]); + XSetBackground(XCURSESDISPLAY, block_cursor_gc, + colors[back]); + XDrawImageString(XCURSESDISPLAY, XCURSESWIN, + block_cursor_gc, xpos, ypos, buf, 1); + } + + PDC_LOG(("%s:XCursesDisplayCursor() - draw cursor at row: %d col %d char <%s>\n", + XCLOGMSG, new_row, new_x, buf)); + } } /***********************************************************************/ #ifdef HAVE_PROTO -void XCursesEnterLeaveWindow(Widget w,XtPointer client_data,XEvent *event,Boolean *continue_to_dispatch) +void XCursesEnterLeaveWindow(Widget w, XtPointer client_data, XEvent *event, + Boolean *continue_to_dispatch) #else -void XCursesEnterLeaveWindow(w,client_data,event,continue_to_dispatch) +void XCursesEnterLeaveWindow(w, client_data, event, continue_to_dispatch) Widget w; XtPointer client_data; XEvent *event; @@ -2545,33 +2710,34 @@ Boolean *continue_to_dispatch; #endif /***********************************************************************/ { - PDC_LOG(("%s:XCursesEnterLeaveWindow called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesEnterLeaveWindow called\n", XCLOGMSG)); - switch(event->type) - { - case EnterNotify: + switch(event->type) + { + case EnterNotify: #ifdef PDCDEBUG - say("EnterNotify received\n"); + say("EnterNotify received\n"); #endif - windowEntered = TRUE; - break; - case LeaveNotify: + windowEntered = TRUE; + break; + + case LeaveNotify: #ifdef PDCDEBUG - say("LeaveNotify received\n"); + say("LeaveNotify received\n"); #endif - windowEntered = FALSE; - /* - * Display the cursor so it stays on while the window - * is not current - */ - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); - break; - default: - PDC_LOG(("%s:XCursesEnterleaveWindow - unknown event %d\n",(XCursesProcess)?" X":"CURSES",event->type)); - break; - } - return; + windowEntered = FALSE; + + /* Display the cursor so it stays on while the window is + not current */ + + XCursesDisplayCursor(SP->cursrow, SP->curscol, + SP->cursrow, SP->curscol); + break; + + default: + PDC_LOG(("%s:XCursesEnterleaveWindow - unknown event %d\n", + XCLOGMSG, event->type)); + } } /***********************************************************************/ @@ -2582,8 +2748,9 @@ int XCurses_get_rows() #endif /***********************************************************************/ { - return(XCursesLINES); + return XCursesLINES; } + /***********************************************************************/ #ifdef HAVE_PROTO int XCurses_get_cols(void) @@ -2592,8 +2759,9 @@ int XCurses_get_cols() #endif /***********************************************************************/ { - return(XCursesCOLS); + return XCursesCOLS; } + /***********************************************************************/ #ifdef HAVE_PROTO unsigned long XCurses_get_key_modifiers(void) @@ -2602,8 +2770,9 @@ unsigned long XCurses_get_key_modifiers() #endif /***********************************************************************/ { - return(pdc_key_modifier); + return pdc_key_modifier; } + /***********************************************************************/ #ifdef HAVE_PROTO int XCursesSendKeyToCurses(unsigned long key, MOUSE_STATUS *ms) @@ -2614,24 +2783,32 @@ MOUSE_STATUS *ms; #endif /***********************************************************************/ { - char buf[100]; /* enough for MOUSE_STATUS */ + char buf[100]; /* enough for MOUSE_STATUS */ - PDC_LOG(("%s:XCursesSendKeyToCurses() - called: sending %d\n",(XCursesProcess)?" X":"CURSES",key)); + PDC_LOG(("%s:XCursesSendKeyToCurses() - called: sending %d\n", + XCLOGMSG, key)); - memcpy(buf,(char *)&key,sizeof(unsigned long)); - if (write_socket(key_sock,buf,sizeof(unsigned long)) < 0) - XCursesExitXCursesProcess(1,SIGKILL,"exiting from XCursesSendKeyToCurses"); - if ( ms != NULL ) - { - memcpy(buf,(char *)&Mouse_status,sizeof(MOUSE_STATUS)); -# ifdef MOUSE_DEBUG1 - printf("%s:writing mouse stuff\n",(XCursesProcess)?" X":"CURSES"); -# endif - if ( write_socket(key_sock,buf,sizeof(MOUSE_STATUS) ) < 0 ) - XCursesExitXCursesProcess(1,SIGKILL,"exiting from XCursesSendKeyToCurses"); - } - return(0); + memcpy(buf, (char *)&key, sizeof(unsigned long)); + + if (write_socket(key_sock, buf, sizeof(unsigned long)) < 0) + XCursesExitXCursesProcess(1, SIGKILL, + "exiting from XCursesSendKeyToCurses"); + + if (ms != NULL) + { + memcpy(buf, (char *)&Mouse_status, sizeof(MOUSE_STATUS)); + +#ifdef MOUSE_DEBUG1 + printf("%s:writing mouse stuff\n", XCLOGMSG); +#endif + if (write_socket(key_sock, buf, sizeof(MOUSE_STATUS)) < 0) + XCursesExitXCursesProcess(1, SIGKILL, + "exiting from XCursesSendKeyToCurses"); + } + + return 0; } + /***********************************************************************/ #ifdef HAVE_PROTO void XCursesCursorBlink(XtPointer unused, XtIntervalId *id) @@ -2642,41 +2819,42 @@ XtIntervalId *id; #endif /***********************************************************************/ { - PDC_LOG(("%s:XCursesCursorBlink() - called:\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesCursorBlink() - called:\n", XCLOGMSG)); - if ( windowEntered ) - { - if ( visible_cursor ) - { - /* - * Cursor currently ON, turn it off - */ - int save_visibility = SP->visibility; - SP->visibility = 0; - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); - SP->visibility = save_visibility; - visible_cursor = 0; - } - else - { - /* - * Cursor currently OFF, turn it on - */ - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); - visible_cursor = 1; - } - } + if (windowEntered) + { - XtAppAddTimeOut( app_context, XCURSESCURSORBLINKRATE, XCursesCursorBlink, NULL ); - return; + if (visible_cursor) + { + /* Cursor currently ON, turn it off */ + + int save_visibility = SP->visibility; + SP->visibility = 0; + XCursesDisplayCursor(SP->cursrow, SP->curscol, + SP->cursrow, SP->curscol); + SP->visibility = save_visibility; + visible_cursor = 0; + } + else + { + /* Cursor currently OFF, turn it on */ + + XCursesDisplayCursor(SP->cursrow, SP->curscol, + SP->cursrow, SP->curscol); + visible_cursor = 1; + } + + } + + XtAppAddTimeOut(app_context, XCURSESCURSORBLINKRATE, + XCursesCursorBlink, NULL); } + /***********************************************************************/ #ifdef HAVE_PROTO -void XCursesButton(Widget w,XEvent *event, String *params, Cardinal *nparams) +void XCursesButton(Widget w, XEvent *event, String *params, Cardinal *nparams) #else -void XCursesButton(w,event,params,nparams) +void XCursesButton(w, event, params, nparams) Widget w; XEvent *event; String *params; @@ -2684,402 +2862,403 @@ Cardinal *nparams; #endif /***********************************************************************/ { - int button_no=0; - static int last_button_no; - static Time last_button_press_time=0; - MOUSE_STATUS save_mouse_status; - bool send_key=TRUE; - static bool remove_release; - static bool handle_real_release; + int button_no = 0; + static int last_button_no; + static Time last_button_press_time = 0; + MOUSE_STATUS save_mouse_status; + bool send_key=TRUE; + static bool remove_release; + static bool handle_real_release; - PDC_LOG(("%s:XCursesButton called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesButton called\n", XCLOGMSG)); - save_mouse_status=Mouse_status; - button_no = event->xbutton.button; - /*---------------------------------------------------------------------*/ - /* It appears that under X11R6 (at least on Linux), that an event_type */ - /* of ButtonMotion does not include the mouse button in the event. The */ - /* following code is designed to cater for this situation. */ - /*---------------------------------------------------------------------*/ - if (button_no == 0) - button_no = last_button_no; - last_button_no = button_no; + save_mouse_status = Mouse_status; + button_no = event->xbutton.button; + + /* It appears that under X11R6 (at least on Linux), that an + event_type of ButtonMotion does not include the mouse button + in the event. The following code is designed to cater for + this situation. */ + + if (button_no == 0) + button_no = last_button_no; + + last_button_no = button_no; + + Mouse_status.changes = 0; + + switch(event->type) + { + case ButtonPress: + + /* Handle button 4 and 5, which are normally mapped to + the wheel mouse scroll up and down */ + + if ((SP->_trap_mbe & MOUSE_WHEEL_SCROLL) + && (button_no == 4 || button_no == 5)) + { + /* Send the KEY_MOUSE to curses program */ + + memset(&Mouse_status, 0, sizeof(Mouse_status)); + + Mouse_status.changes = (button_no == 5) ? + PDC_MOUSE_WHEEL_DOWN : PDC_MOUSE_WHEEL_UP; + + MOUSE_X_POS = MOUSE_Y_POS = -1; + + XCursesSendKeyToCurses((unsigned long)KEY_MOUSE, + &Mouse_status); + return; + } + + remove_release = False; + handle_real_release = False; - Mouse_status.changes = 0; - switch(event->type) - { - /* - * ButtonPress - */ - case ButtonPress: - /* - * Handle button 4 and 5, which are normally mapped to the wheel mouse - * scroll up and down - */ - if ( (SP->_trap_mbe & MOUSE_WHEEL_SCROLL ) - && ( button_no == 4 || button_no == 5 ) ) - { - /* - * Send the KEY_MOUSE to curses program... - */ - memset( &Mouse_status, 0, sizeof(Mouse_status) ); - Mouse_status.changes = (button_no == 5) ? PDC_MOUSE_WHEEL_DOWN : PDC_MOUSE_WHEEL_UP ; - MOUSE_X_POS = MOUSE_Y_POS = -1; - XCursesSendKeyToCurses( (unsigned long)KEY_MOUSE, &Mouse_status ); - return; - } - remove_release = False; - handle_real_release = False; #ifdef MOUSE_DEBUG - printf("\nButtonPress\n"); + printf("\nButtonPress\n"); #endif - if ((event->xbutton.time - last_button_press_time) < XCURSESDOUBLECLICKPERIOD) - { - MOUSE_X_POS = save_mouse_status.x; - MOUSE_Y_POS = save_mouse_status.y; - BUTTON_STATUS(button_no) = BUTTON_DOUBLE_CLICKED; - SelectionOff(); - if (!(SP->_trap_mbe & BUTTON1_DOUBLE_CLICKED) - && button_no == 1) - send_key = FALSE; - if (!(SP->_trap_mbe & BUTTON2_DOUBLE_CLICKED) - && button_no == 2) - send_key = FALSE; - if (!(SP->_trap_mbe & BUTTON3_DOUBLE_CLICKED) - && button_no == 3) - send_key = FALSE; - if (send_key) - remove_release = True; - } - else - { + if ((event->xbutton.time - last_button_press_time) < + XCURSESDOUBLECLICKPERIOD) + { + MOUSE_X_POS = save_mouse_status.x; + MOUSE_Y_POS = save_mouse_status.y; + BUTTON_STATUS(button_no) = BUTTON_DOUBLE_CLICKED; + + SelectionOff(); + + if (!(SP->_trap_mbe & BUTTON1_DOUBLE_CLICKED) + && button_no == 1) + send_key = FALSE; + if (!(SP->_trap_mbe & BUTTON2_DOUBLE_CLICKED) + && button_no == 2) + send_key = FALSE; + if (!(SP->_trap_mbe & BUTTON3_DOUBLE_CLICKED) + && button_no == 3) + send_key = FALSE; + + if (send_key) + remove_release = True; + } + else + { #if 0 - MOUSE_X_POS = (event->xbutton.x-XCURSESBORDERWIDTH) / XCursesFontWidth; - MOUSE_Y_POS = (event->xbutton.y-XCURSESBORDERWIDTH) / XCursesFontHeight; - BUTTON_STATUS(button_no) = BUTTON_PRESSED; - if (!(SP->_trap_mbe & BUTTON1_PRESSED) - && button_no == 1) - send_key = FALSE; - if (!(SP->_trap_mbe & BUTTON2_PRESSED) - && button_no == 2) - send_key = FALSE; - if (!(SP->_trap_mbe & BUTTON3_PRESSED) - && button_no == 3) - send_key = FALSE; - if (button_no == 1 - && !(event->xbutton.state & ShiftMask) - && !(event->xbutton.state & ControlMask) - && !(event->xbutton.state & Mod1Mask)) - { - SelectionOff(); - SelectionOn(MOUSE_X_POS,MOUSE_Y_POS); - } + MOUSE_X_POS = (event->xbutton.x - + XCURSESBORDERWIDTH) / XCursesFontWidth; + MOUSE_Y_POS = (event->xbutton.y - + XCURSESBORDERWIDTH) / XCursesFontHeight; + BUTTON_STATUS(button_no) = BUTTON_PRESSED; + + if (!(SP->_trap_mbe & BUTTON1_PRESSED) + && button_no == 1) + send_key = FALSE; + if (!(SP->_trap_mbe & BUTTON2_PRESSED) + && button_no == 2) + send_key = FALSE; + if (!(SP->_trap_mbe & BUTTON3_PRESSED) + && button_no == 3) + send_key = FALSE; + + if (button_no == 1 + && !(event->xbutton.state & ShiftMask) + && !(event->xbutton.state & ControlMask) + && !(event->xbutton.state & Mod1Mask)) + { + SelectionOff(); + SelectionOn(MOUSE_X_POS, MOUSE_Y_POS); + } #else - napms( XCURSESCLICKPERIOD ); - event->type = ButtonRelease; - XSendEvent(event->xbutton.display, event->xbutton.window, True, - 0, event); - last_button_press_time = event->xbutton.time; -#ifdef PDCDEBUG -printf("Pressed at: %ld\n",last_button_press_time); + napms(XCURSESCLICKPERIOD); + event->type = ButtonRelease; + XSendEvent(event->xbutton.display, + event->xbutton.window, True, 0, event); + last_button_press_time = event->xbutton.time; + + return; #endif - return; -#endif - } - last_button_press_time = event->xbutton.time; -#ifdef PDCDEBUG -printf("Pressed at: %ld\n",last_button_press_time); -#endif - break; - /* - * MotionNotify - */ - case MotionNotify: + } + + last_button_press_time = event->xbutton.time; + break; + + case MotionNotify: #ifdef MOUSE_DEBUG - printf("\nMotionNotify: y: %d x: %d Width: %d Height: %d\n",event->xbutton.y, - event->xbutton.x, - XCursesFontWidth, - XCursesFontHeight); + printf("\nMotionNotify: y: %d x: %d Width: %d Height: %d\n", + event->xbutton.y, event->xbutton.x, + XCursesFontWidth, XCursesFontHeight); #endif - if (button_no == 1 - && !(event->xbutton.state & ShiftMask) - && !(event->xbutton.state & ControlMask) - && !(event->xbutton.state & Mod1Mask)) - { - MOUSE_X_POS = (event->xbutton.x-XCURSESBORDERWIDTH) / XCursesFontWidth; - MOUSE_Y_POS = (event->xbutton.y-XCURSESBORDERWIDTH) / XCursesFontHeight; - SelectionExtend(MOUSE_X_POS,MOUSE_Y_POS); - send_key = FALSE; - } - else - SelectionOff(); - /* - * Throw away mouse movements if they are in the same character position - * as the last mouse event, or if we are currently in the middle of - * a double click event. - */ - MOUSE_X_POS = (event->xbutton.x-XCURSESBORDERWIDTH) / XCursesFontWidth; - MOUSE_Y_POS = (event->xbutton.y-XCURSESBORDERWIDTH) / XCursesFontHeight; - if ((MOUSE_X_POS == save_mouse_status.x - && MOUSE_Y_POS == save_mouse_status.y) - || save_mouse_status.button[button_no-1] == BUTTON_DOUBLE_CLICKED) - { - send_key = FALSE; - break; - } - MOUSE_X_POS = (event->xbutton.x-XCURSESBORDERWIDTH) / XCursesFontWidth; - MOUSE_Y_POS = (event->xbutton.y-XCURSESBORDERWIDTH) / XCursesFontHeight; - Mouse_status.changes |= 8; - if (!(SP->_trap_mbe & BUTTON1_MOVED) - && button_no == 1) - send_key = FALSE; - if (!(SP->_trap_mbe & BUTTON2_MOVED) - && button_no == 2) - send_key = FALSE; - if (!(SP->_trap_mbe & BUTTON3_MOVED) - && button_no == 3) - send_key = FALSE; + if (button_no == 1 && !(event->xbutton.state & ShiftMask) + && !(event->xbutton.state & ControlMask) + && !(event->xbutton.state & Mod1Mask)) + { + MOUSE_X_POS = (event->xbutton.x - + XCURSESBORDERWIDTH) / XCursesFontWidth; + MOUSE_Y_POS = (event->xbutton.y - + XCURSESBORDERWIDTH) / XCursesFontHeight; + + SelectionExtend(MOUSE_X_POS, MOUSE_Y_POS); + send_key = FALSE; + } + else + SelectionOff(); + + /* Throw away mouse movements if they are in the same + character position as the last mouse event, or if we + are currently in the middle of a double click event. */ + + MOUSE_X_POS = (event->xbutton.x - XCURSESBORDERWIDTH) / + XCursesFontWidth; + MOUSE_Y_POS = (event->xbutton.y - XCURSESBORDERWIDTH) / + XCursesFontHeight; + + if ((MOUSE_X_POS == save_mouse_status.x && + MOUSE_Y_POS == save_mouse_status.y) || + save_mouse_status.button[button_no - 1] == + BUTTON_DOUBLE_CLICKED) + { + send_key = FALSE; + break; + } + + MOUSE_X_POS = (event->xbutton.x - XCURSESBORDERWIDTH) / + XCursesFontWidth; + MOUSE_Y_POS = (event->xbutton.y - XCURSESBORDERWIDTH) / + XCursesFontHeight; + + Mouse_status.changes |= 8; + + if (!(SP->_trap_mbe & BUTTON1_MOVED) && button_no == 1) + send_key = FALSE; + if (!(SP->_trap_mbe & BUTTON2_MOVED) && button_no == 2) + send_key = FALSE; + if (!(SP->_trap_mbe & BUTTON3_MOVED) && button_no == 3) + send_key = FALSE; #if 0 - if (button_no == 1 - && !(event->xbutton.state & ShiftMask) - && !(event->xbutton.state & ControlMask) - && !(event->xbutton.state & Mod1Mask)) - { - SelectionExtend(MOUSE_X_POS,MOUSE_Y_POS); - send_key = FALSE; - } - else - SelectionOff(); + if (button_no == 1 && !(event->xbutton.state & ShiftMask) + && !(event->xbutton.state & ControlMask) + && !(event->xbutton.state & Mod1Mask)) + { + SelectionExtend(MOUSE_X_POS, MOUSE_Y_POS); + send_key = FALSE; + } + else + SelectionOff(); #endif - break; - /* - * ButtonRelease - */ + break; + case ButtonRelease: #if 0 - MOUSE_X_POS = (event->xbutton.x-XCURSESBORDERWIDTH) / XCursesFontWidth; - MOUSE_Y_POS = (event->xbutton.y-XCURSESBORDERWIDTH) / XCursesFontHeight; - BUTTON_STATUS(button_no) = BUTTON_RELEASED; - if (!(SP->_trap_mbe & BUTTON1_RELEASED) - && button_no == 1) - send_key = FALSE; - if (!(SP->_trap_mbe & BUTTON2_RELEASED) - && button_no == 2) - send_key = FALSE; - if (!(SP->_trap_mbe & BUTTON3_RELEASED) - && button_no == 3) - send_key = FALSE; - if (button_no == 1 - && !(event->xbutton.state & ShiftMask) - && !(event->xbutton.state & ControlMask) - && !(event->xbutton.state & Mod1Mask) - && mouse_selection) - { - send_key = FALSE; - if (XtOwnSelection(topLevel, - XA_PRIMARY, - event->xbutton.time, - XCursesConvertProc, - XCursesLoseOwnership, - NULL) == False) - { - SelectionOff(); - } - SelectionSet(); - } - else - SelectionOff(); - break; -#else - if (remove_release) - { -#ifdef PDCDEBUG - printf("Release at: %ld - removed\n",event->xbutton.time); -#endif - return; - } - else - { - if (!handle_real_release) - { - if ((event->xbutton.time - last_button_press_time) < 100 - && (event->xbutton.time != last_button_press_time)) - { - /* - * The "real" release was shorter than usleep() time - * therefore generate a click event - */ -#ifdef PDCDEBUG - printf("Release at: %ld - click\n",event->xbutton.time); -#endif - MOUSE_X_POS = (event->xbutton.x-XCURSESBORDERWIDTH) / XCursesFontWidth; - MOUSE_Y_POS = (event->xbutton.y-XCURSESBORDERWIDTH) / XCursesFontHeight; - BUTTON_STATUS(button_no) = BUTTON_CLICKED; - if (!(SP->_trap_mbe & BUTTON1_RELEASED) - && button_no == 1) - send_key = FALSE; - if (!(SP->_trap_mbe & BUTTON2_RELEASED) - && button_no == 2) - send_key = FALSE; - if (!(SP->_trap_mbe & BUTTON3_RELEASED) - && button_no == 3) - send_key = FALSE; - if (button_no == 1 - && !(event->xbutton.state & ShiftMask) - && !(event->xbutton.state & ControlMask) - && !(event->xbutton.state & Mod1Mask) - && mouse_selection) - { - send_key = FALSE; - if (XtOwnSelection(topLevel, - XA_PRIMARY, - event->xbutton.time, - XCursesConvertProc, - XCursesLoseOwnership, - NULL) == False) - { - SelectionOff(); - } - } - else - SelectionOff(); - /* - * Ensure the "pseudo" release event is ignored - */ - remove_release = True; - handle_real_release = False; - break; - } - else - { - /* - * Button release longer than usleep() time - * therefore generate a press and wait for the - * real release to occur later. - */ -#ifdef PDCDEBUG - printf("Generated Release at: %ld - press & release\n",event->xbutton.time); -#endif - MOUSE_X_POS = (event->xbutton.x-XCURSESBORDERWIDTH) / XCursesFontWidth; - MOUSE_Y_POS = (event->xbutton.y-XCURSESBORDERWIDTH) / XCursesFontHeight; - BUTTON_STATUS(button_no) = BUTTON_PRESSED; - if (!(SP->_trap_mbe & BUTTON1_PRESSED) - && button_no == 1) - send_key = FALSE; - if (!(SP->_trap_mbe & BUTTON2_PRESSED) - && button_no == 2) - send_key = FALSE; - if (!(SP->_trap_mbe & BUTTON3_PRESSED) - && button_no == 3) - send_key = FALSE; - if (button_no == 1 - && !(event->xbutton.state & ShiftMask) - && !(event->xbutton.state & ControlMask) - && !(event->xbutton.state & Mod1Mask)) - { - SelectionOff(); - SelectionOn(MOUSE_X_POS,MOUSE_Y_POS); - } - handle_real_release = True; - break; - } - } - else - { -#ifdef PDCDEBUG - printf("Release at: %ld - released\n",event->xbutton.time); -#endif - } - } -#ifdef PDCDEBUG -printf("\nButtonRelease\n"); -#endif - MOUSE_X_POS = (event->xbutton.x-XCURSESBORDERWIDTH) / XCursesFontWidth; - MOUSE_Y_POS = (event->xbutton.y-XCURSESBORDERWIDTH) / XCursesFontHeight; - BUTTON_STATUS(button_no) = BUTTON_RELEASED; - if (!(SP->_trap_mbe & BUTTON1_RELEASED) - && button_no == 1) - send_key = FALSE; - if (!(SP->_trap_mbe & BUTTON2_RELEASED) - && button_no == 2) - send_key = FALSE; - if (!(SP->_trap_mbe & BUTTON3_RELEASED) - && button_no == 3) - send_key = FALSE; - if (button_no == 1 - && !(event->xbutton.state & ShiftMask) - && !(event->xbutton.state & ControlMask) - && !(event->xbutton.state & Mod1Mask) - && mouse_selection) - { - send_key = FALSE; - if (XtOwnSelection(topLevel, - XA_PRIMARY, - event->xbutton.time, - XCursesConvertProc, - XCursesLoseOwnership, - NULL) == False) - { - SelectionOff(); - } - SelectionSet(); - } - else - SelectionOff(); - break; -#endif - } - /* - * Set up the mouse status fields in preparation for sending... - */ - Mouse_status.changes |= (1 << (button_no-1)); - if (event->xbutton.state & ShiftMask) - BUTTON_STATUS(button_no) |= BUTTON_SHIFT; - if (event->xbutton.state & ControlMask) - BUTTON_STATUS(button_no) |= BUTTON_CONTROL; - if (event->xbutton.state & Mod1Mask) - BUTTON_STATUS(button_no) |= BUTTON_ALT; - /* - * If we are ignoring the event, or the mouse position is outside the - * bounds of the screen (because of the border), return here... - */ -#ifdef PDCDEBUG - printf("Button: %d x: %d y: %d Button status: %x Mouse status: %x\n",button_no, - MOUSE_X_POS, - MOUSE_Y_POS, - BUTTON_STATUS(button_no), - Mouse_status.changes); - printf("Send: %d Button1: %x Button2: %x Button3: %x %d %d\n", - send_key, - BUTTON_STATUS(1), - BUTTON_STATUS(2), - BUTTON_STATUS(3), - XCursesLINES,XCursesCOLS); -#endif + MOUSE_X_POS = (event->xbutton.x-XCURSESBORDERWIDTH) / + XCursesFontWidth; + MOUSE_Y_POS = (event->xbutton.y-XCURSESBORDERWIDTH) / + XCursesFontHeight; + BUTTON_STATUS(button_no) = BUTTON_RELEASED; - if (!send_key - || MOUSE_X_POS < 0 - || MOUSE_X_POS >= XCursesCOLS - || MOUSE_Y_POS < 0 - || MOUSE_Y_POS >= XCursesLINES) - return; + if (!(SP->_trap_mbe & BUTTON1_RELEASED) && button_no == 1) + send_key = FALSE; + if (!(SP->_trap_mbe & BUTTON2_RELEASED) && button_no == 2) + send_key = FALSE; + if (!(SP->_trap_mbe & BUTTON3_RELEASED) && button_no == 3) + send_key = FALSE; + + if (button_no == 1 && !(event->xbutton.state & ShiftMask) + && !(event->xbutton.state & ControlMask) + && !(event->xbutton.state & Mod1Mask) && mouse_selection) + { + send_key = FALSE; + + if (XtOwnSelection(topLevel, XA_PRIMARY, + event->xbutton.time, XCursesConvertProc, + XCursesLoseOwnership, NULL) == False) + SelectionOff(); + + SelectionSet(); + } + else + SelectionOff(); + break; +#else + if (remove_release) + { +#ifdef MOUSE_DEBUG + printf("Release at: %ld - removed\n", + event->xbutton.time); +#endif + return; + } + else + { + if (!handle_real_release) + { + if ((event->xbutton.time - + last_button_press_time) < 100 && + (event->xbutton.time != + last_button_press_time)) + { + /* The "real" release was shorter than + usleep() time therefore generate a click + event */ +#ifdef MOUSE_DEBUG + printf("Release at: %ld - click\n", + event->xbutton.time); +#endif + MOUSE_X_POS = (event->xbutton.x - + XCURSESBORDERWIDTH) / XCursesFontWidth; + MOUSE_Y_POS = (event->xbutton.y - + XCURSESBORDERWIDTH) / XCursesFontHeight; + BUTTON_STATUS(button_no) = BUTTON_CLICKED; + + if (!(SP->_trap_mbe & BUTTON1_RELEASED) + && button_no == 1) + send_key = FALSE; + + if (!(SP->_trap_mbe & BUTTON2_RELEASED) + && button_no == 2) + send_key = FALSE; + + if (!(SP->_trap_mbe & BUTTON3_RELEASED) + && button_no == 3) + send_key = FALSE; + + if (button_no == 1 + && !(event->xbutton.state & ShiftMask) + && !(event->xbutton.state & ControlMask) + && !(event->xbutton.state & Mod1Mask) + && mouse_selection) + { + send_key = FALSE; + + if (XtOwnSelection(topLevel, XA_PRIMARY, + event->xbutton.time, XCursesConvertProc, + XCursesLoseOwnership, NULL) == False) + SelectionOff(); + } + else + SelectionOff(); + + /* Ensure the "pseudo" release event is ignored */ + + remove_release = True; + handle_real_release = False; + break; + } + else + { + /* Button release longer than usleep() time + therefore generate a press and wait for + the real release to occur later. */ +#ifdef MOUSE_DEBUG + printf("Generated Release at: %ld - press & release\n", + event->xbutton.time); +#endif + MOUSE_X_POS = (event->xbutton.x - + XCURSESBORDERWIDTH) / XCursesFontWidth; + MOUSE_Y_POS = (event->xbutton.y - + XCURSESBORDERWIDTH) / XCursesFontHeight; + BUTTON_STATUS(button_no) = BUTTON_PRESSED; + + if (!(SP->_trap_mbe & BUTTON1_PRESSED) + && button_no == 1) + send_key = FALSE; + + if (!(SP->_trap_mbe & BUTTON2_PRESSED) + && button_no == 2) + send_key = FALSE; + + if (!(SP->_trap_mbe & BUTTON3_PRESSED) + && button_no == 3) + send_key = FALSE; + + if (button_no == 1 + && !(event->xbutton.state & ShiftMask) + && !(event->xbutton.state & ControlMask) + && !(event->xbutton.state & Mod1Mask)) + { + SelectionOff(); + SelectionOn(MOUSE_X_POS, MOUSE_Y_POS); + } + + handle_real_release = True; + break; + } + } + else + { +#ifdef MOUSE_DEBUG + printf("Release at: %ld - released\n", + event->xbutton.time); +#endif + } + } #ifdef MOUSE_DEBUG - printf("Button: %d x: %d y: %d Button status: %x Mouse status: %x\n",button_no, - MOUSE_X_POS, - MOUSE_Y_POS, - BUTTON_STATUS(button_no), - Mouse_status.changes); - printf("Send: %d Button1: %x Button2: %x Button3: %x\n",send_key, - BUTTON_STATUS(1), - BUTTON_STATUS(2), - BUTTON_STATUS(3)); + printf("\nButtonRelease\n"); #endif - /* - * Send the KEY_MOUSE to curses program... - */ - XCursesSendKeyToCurses( (unsigned long)KEY_MOUSE, &Mouse_status ); - return; + MOUSE_X_POS = (event->xbutton.x - XCURSESBORDERWIDTH) / + XCursesFontWidth; + MOUSE_Y_POS = (event->xbutton.y - XCURSESBORDERWIDTH) / + XCursesFontHeight; + BUTTON_STATUS(button_no) = BUTTON_RELEASED; + + if (!(SP->_trap_mbe & BUTTON1_RELEASED) && button_no == 1) + send_key = FALSE; + + if (!(SP->_trap_mbe & BUTTON2_RELEASED) && button_no == 2) + send_key = FALSE; + + if (!(SP->_trap_mbe & BUTTON3_RELEASED) && button_no == 3) + send_key = FALSE; + + if (button_no == 1 && !(event->xbutton.state & ShiftMask) + && !(event->xbutton.state & ControlMask) + && !(event->xbutton.state & Mod1Mask) && mouse_selection) + { + send_key = FALSE; + + if (XtOwnSelection(topLevel, XA_PRIMARY, + event->xbutton.time, XCursesConvertProc, + XCursesLoseOwnership, NULL) == False) + SelectionOff(); + + SelectionSet(); + } + else + SelectionOff(); + + break; +#endif + } + + /* Set up the mouse status fields in preparation for sending */ + + Mouse_status.changes |= 1 << (button_no - 1); + + if (event->xbutton.state & ShiftMask) + BUTTON_STATUS(button_no) |= BUTTON_SHIFT; + if (event->xbutton.state & ControlMask) + BUTTON_STATUS(button_no) |= BUTTON_CONTROL; + if (event->xbutton.state & Mod1Mask) + BUTTON_STATUS(button_no) |= BUTTON_ALT; + + /* If we are ignoring the event, or the mouse position is + outside the bounds of the screen (because of the border), + return here */ + +#ifdef MOUSE_DEBUG + printf("Button: %d x: %d y: %d Button status: %x Mouse status: %x\n", + button_no, MOUSE_X_POS, MOUSE_Y_POS, + BUTTON_STATUS(button_no), Mouse_status.changes); + + printf("Send: %d Button1: %x Button2: %x Button3: %x %d %d\n", + send_key, BUTTON_STATUS(1), BUTTON_STATUS(2), + BUTTON_STATUS(3), XCursesLINES, XCursesCOLS); +#endif + if (!send_key || MOUSE_X_POS < 0 || MOUSE_X_POS >= XCursesCOLS || + MOUSE_Y_POS < 0 || MOUSE_Y_POS >= XCursesLINES) + return; + + /* Send the KEY_MOUSE to curses program */ + + XCursesSendKeyToCurses((unsigned long)KEY_MOUSE, &Mouse_status); } /***********************************************************************/ @@ -3093,35 +3272,33 @@ XtPointer call_data; #endif /***********************************************************************/ { - int pixels = (long) call_data; - int total_y=(SP->sb_total_y*XCursesFontHeight); - int viewport_y=(SP->sb_viewport_y*XCursesFontHeight); - int cur_y=(SP->sb_cur_y*XCursesFontHeight); + int pixels = (long) call_data; + int total_y = SP->sb_total_y * XCursesFontHeight; + int viewport_y = SP->sb_viewport_y * XCursesFontHeight; + int cur_y = SP->sb_cur_y * XCursesFontHeight; - /* - * When pixels is negative, right button pressed, move data down, - * thumb moves up. Otherwise, left button pressed, pixels - * positive, move data up, thumb down. - */ - cur_y += pixels; + /* When pixels is negative, right button pressed, move data + down, thumb moves up. Otherwise, left button pressed, pixels + positive, move data up, thumb down. */ - /* limit panning to size of overall */ - if (cur_y < 0) - cur_y = 0; - else - { - if (cur_y > (total_y - viewport_y)) - cur_y = (total_y - viewport_y); - } - SP->sb_cur_y = cur_y / XCursesFontHeight; - XawScrollbarSetThumb(w,(double)((double)cur_y/(double)total_y),(double)((double)viewport_y/(double)total_y)); - /* - * Send a key: if pixels negative, send KEY_SCROLL_DOWN - */ - XCursesSendKeyToCurses( (unsigned long)KEY_SF, NULL ); -#if 0 -fprintf(stderr,"Scroll_up_down: pixels %d cur_y %d\n",pixels,SP->sb_cur_y); -#endif + cur_y += pixels; + + /* limit panning to size of overall */ + + if (cur_y < 0) + cur_y = 0; + else + if (cur_y > (total_y - viewport_y)) + cur_y = total_y - viewport_y; + + SP->sb_cur_y = cur_y / XCursesFontHeight; + + XawScrollbarSetThumb(w, (double)((double)cur_y / (double)total_y), + (double)((double)viewport_y / (double)total_y)); + + /* Send a key: if pixels negative, send KEY_SCROLL_DOWN */ + + XCursesSendKeyToCurses((unsigned long)KEY_SF, NULL); } /***********************************************************************/ @@ -3135,36 +3312,35 @@ XtPointer call_data; #endif /***********************************************************************/ { - int pixels = (long) call_data; - int total_x=(SP->sb_total_x*XCursesFontWidth); - int viewport_x=(SP->sb_viewport_x*XCursesFontWidth); - int cur_x=(SP->sb_cur_x*XCursesFontWidth); + int pixels = (long) call_data; + int total_x = SP->sb_total_x * XCursesFontWidth; + int viewport_x = SP->sb_viewport_x * XCursesFontWidth; + int cur_x = SP->sb_cur_x * XCursesFontWidth; - /* - * When pixels is negative, right button pressed, move data down, - * thumb moves up. Otherwise, left button pressed, pixels - * positive, move data up, thumb down. - */ - cur_x += pixels; + /* When pixels is negative, right button pressed, move data + down, thumb moves up. Otherwise, left button pressed, pixels + positive, move data up, thumb down. */ - /* limit panning to size of overall */ - if (cur_x < 0) - cur_x = 0; - else - { - if (cur_x > (total_x - viewport_x)) - cur_x = (total_x - viewport_x); - } - SP->sb_cur_x = cur_x / XCursesFontWidth; - XawScrollbarSetThumb(w,(double)((double)cur_x/(double)total_x),(double)((double)viewport_x/(double)total_x)); - /* - * Send a key: if pixels negative, send KEY_SCROLL_DOWN - */ - XCursesSendKeyToCurses( (unsigned long)KEY_SR, NULL ); -#if 0 -fprintf(stderr,"Scroll_left_right: pixels %d cur_x %d\n",pixels,SP->sb_cur_x); -#endif + cur_x += pixels; + + /* limit panning to size of overall */ + + if (cur_x < 0) + cur_x = 0; + else + if (cur_x > (total_x - viewport_x)) + cur_x = total_x - viewport_x; + + SP->sb_cur_x = cur_x / XCursesFontWidth; + + XawScrollbarSetThumb(w, (double)((double)cur_x / (double)total_x), + (double)((double)viewport_x / (double)total_x)); + + /* Send a key: if pixels negative, send KEY_SCROLL_DOWN */ + + XCursesSendKeyToCurses((unsigned long)KEY_SR, NULL); } + /***********************************************************************/ #ifdef HAVE_PROTO void Thumb_up_down(Widget w, XtPointer client_data, XtPointer call_data) @@ -3176,33 +3352,29 @@ XtPointer call_data; #endif /***********************************************************************/ { - double percent = *(double *) call_data; - double total_y=(double)(SP->sb_total_y); - double viewport_y=(double)(SP->sb_viewport_y); - int cur_y=SP->sb_cur_y; + double percent = *(double *) call_data; + double total_y = (double)SP->sb_total_y; + double viewport_y = (double)SP->sb_viewport_y; + int cur_y = SP->sb_cur_y; -#if 0 -fprintf(stderr,"Thumb_up_down: percent %f\n",percent); -#endif - /* - * If the size of the viewport is > overall area - * simply return, as no scrolling is permitted. - */ - if (SP->sb_viewport_y >= SP->sb_total_y) - return; - if ((SP->sb_cur_y = (int)((double)total_y * percent)) >= (total_y - viewport_y)) - SP->sb_cur_y = total_y - viewport_y; + /* If the size of the viewport is > overall area simply return, + as no scrolling is permitted. */ - /* SP->sb_cur_y = cur_y;*/ - XawScrollbarSetThumb(w,(double)(cur_y/total_y),(double)(viewport_y/total_y)); - /* - * Send a key: if pixels negative, send KEY_SCROLL_DOWN - */ -#if 0 -fprintf(stderr,"Thumb_up_down: percent %f cur_y %d\n",percent,SP->sb_cur_y); -#endif - XCursesSendKeyToCurses( (unsigned long)KEY_SF, NULL ); + if (SP->sb_viewport_y >= SP->sb_total_y) + return; + + if ((SP->sb_cur_y = (int)((double)total_y * percent)) >= + (total_y - viewport_y)) + SP->sb_cur_y = total_y - viewport_y; + + XawScrollbarSetThumb(w, (double)(cur_y / total_y), + (double)(viewport_y / total_y)); + + /* Send a key: if pixels negative, send KEY_SCROLL_DOWN */ + + XCursesSendKeyToCurses((unsigned long)KEY_SF, NULL); } + /***********************************************************************/ #ifdef HAVE_PROTO void Thumb_left_right(Widget w, XtPointer client_data, XtPointer call_data) @@ -3214,31 +3386,25 @@ XtPointer call_data; #endif /***********************************************************************/ { - double percent = *(double *) call_data; - double total_x=(double)(SP->sb_total_x); - double viewport_x=(double)(SP->sb_viewport_x); - int cur_x=SP->sb_cur_x; + double percent = *(double *) call_data; + double total_x = (double)SP->sb_total_x; + double viewport_x = (double)SP->sb_viewport_x; + int cur_x = SP->sb_cur_x; -#if 0 -fprintf(stderr,"Thumb_up_down: percent %f\n",percent); -#endif - /* - * If the size of the viewport is > overall area - * simply return, as no scrolling is permitted. - */ - if (SP->sb_viewport_x >= SP->sb_total_x) - return; - if ((SP->sb_cur_x = (int)((float)total_x * percent)) >= (total_x - viewport_x)) - SP->sb_cur_x = total_x - viewport_x; + /* If the size of the viewport is > overall area simply return, + as no scrolling is permitted. */ - /* SP->sb_cur_x = cur_x;*/ - XawScrollbarSetThumb(w,(double)(cur_x/total_x),(double)(viewport_x/total_x)); - /* - * Send a key: if pixels negative, send KEY_SCROLL_DOWN - */ -#if 0 -fprintf(stderr,"Thumb_up_down: percent %f cur_x %d\n",percent,SP->sb_cur_x); -#endif - XCursesSendKeyToCurses( (unsigned long)KEY_SR, NULL ); + if (SP->sb_viewport_x >= SP->sb_total_x) + return; + + if ((SP->sb_cur_x = (int)((float)total_x * percent)) >= + (total_x - viewport_x)) + SP->sb_cur_x = total_x - viewport_x; + + XawScrollbarSetThumb(w, (double)(cur_x / total_x), + (double)(viewport_x / total_x)); + + /* Send a key: if pixels negative, send KEY_SCROLL_DOWN */ + + XCursesSendKeyToCurses((unsigned long)KEY_SR, NULL); } -#endif diff --git a/x11/pdcx11.h b/x11/pdcx11.h index e3adc478..a5206c8e 100644 --- a/x11/pdcx11.h +++ b/x11/pdcx11.h @@ -23,11 +23,11 @@ #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H -# include +# include #endif #ifdef HAVE_UNISTD_H -#include +# include #endif #include @@ -35,9 +35,8 @@ #include #include -/* - * #includes specific to running XCurses with seperate processes - */ +/* #includes specific to running XCurses with seperate processes */ + #ifdef USE_PROCESSES # include # include @@ -55,13 +54,6 @@ typedef char * XPointer; #endif -/* - * #includes specific to running XCurses with threads - */ -#ifdef USE_THREADS -# include -#endif - #ifdef TIME_WITH_SYS_TIME # include # include @@ -82,14 +74,14 @@ #include #ifdef USE_XAW3D -#include -#include +# include +# include #elif defined(USE_NEXTAW) -#include -#include +# include +# include #else -#include -#include +# include +# include #endif #include "x11/ScrollBox.h" @@ -103,11 +95,11 @@ #endif #ifdef HAVE_DECKEYSYM_H -#include +# include #endif #ifdef HAVE_SUNKEYSYM_H -#include +# include #endif #ifdef HAVE_XPM_H @@ -193,50 +185,50 @@ #define XtCColorBoldWhite "ColorBoldWhite" #ifndef MAX_PATH -# define MAX_PATH 256 +# define MAX_PATH 256 #endif typedef struct { - int lines; - int cols; - Pixel cursorColor; - Pixel colorBlack; - Pixel colorRed; - Pixel colorGreen; - Pixel colorYellow; - Pixel colorBlue; - Pixel colorMagenta; - Pixel colorCyan; - Pixel colorWhite; - Pixel colorBoldBlack; - Pixel colorBoldRed; - Pixel colorBoldGreen; - Pixel colorBoldYellow; - Pixel colorBoldBlue; - Pixel colorBoldMagenta; - Pixel colorBoldCyan; - Pixel colorBoldWhite; - Pixel pointerForeColor; - Pixel pointerBackColor; - XFontStruct *normalfont; - XFontStruct *italicfont; - char *bitmapFile; + int lines; + int cols; + Pixel cursorColor; + Pixel colorBlack; + Pixel colorRed; + Pixel colorGreen; + Pixel colorYellow; + Pixel colorBlue; + Pixel colorMagenta; + Pixel colorCyan; + Pixel colorWhite; + Pixel colorBoldBlack; + Pixel colorBoldRed; + Pixel colorBoldGreen; + Pixel colorBoldYellow; + Pixel colorBoldBlue; + Pixel colorBoldMagenta; + Pixel colorBoldCyan; + Pixel colorBoldWhite; + Pixel pointerForeColor; + Pixel pointerBackColor; + XFontStruct *normalfont; + XFontStruct *italicfont; + char *bitmapFile; #ifdef HAVE_XPM_H - char *pixmapFile; + char *pixmapFile; #endif - char *composeKey; - Cursor pointer; - int shmmin; - int borderWidth; - int borderColor; - int clickPeriod; - int doubleClickPeriod; - int scrollbarWidth; - int cursorBlinkRate; - char *textCursor; + char *composeKey; + Cursor pointer; + int shmmin; + int borderWidth; + int borderColor; + int clickPeriod; + int doubleClickPeriod; + int scrollbarWidth; + int cursorBlinkRate; + char *textCursor; #if 0 - XtWidgetGeometry geometry; + XtWidgetGeometry geometry; #endif } AppData; @@ -263,28 +255,31 @@ typedef struct #define XCURSESGEOMETRY app_data.geometry #define XCURSESTEXTCURSOR app_data.textCursor -#define XCURSESDISPLAY (XtDisplay(drawing)) -#define XCURSESWIN (XtWindow(drawing)) +#define XCURSESDISPLAY (XtDisplay(drawing)) +#define XCURSESWIN (XtWindow(drawing)) + +#define XCLOGMSG (XCursesProcess ? " X" : "CURSES") #define MAX_COLORS 8 /* maximum of "normal" colours */ -#define COLOR_CURSOR 16 /* colour of cursor - 1 more than 2*MAX_COLORS */ -#define COLOR_BORDER 17 /* colour of border - 2 more than 2*MAX_COLORS */ +#define COLOR_CURSOR 16 /* colour of cursor - 1 more than 2 * MAX_COLORS */ +#define COLOR_BORDER 17 /* colour of border - 2 more than 2 * MAX_COLORS */ + #ifdef HAVE_XPM_H # define PDC_NUMBER_OPTIONS 33 #define PDC_NUMBER_APP_RESOURCES 35 #else # define PDC_NUMBER_OPTIONS 32 -#define PDC_NUMBER_APP_RESOURCES 34 +# define PDC_NUMBER_APP_RESOURCES 34 #endif #define PDC_NUMBER_XCURSES_ACTIONS 5 #include "x11.h" -extern GC normal_gc,block_cursor_gc,rect_cursor_gc,italic_gc,border_gc; -extern int XCursesFontHeight,XCursesFontWidth; -extern int XCursesFontAscent,XCursesFontDescent; -extern int XCursesWindowWidth,XCursesWindowHeight; -extern int resizeXCursesWindowWidth,resizeXCursesWindowHeight; +extern GC normal_gc, block_cursor_gc, rect_cursor_gc, italic_gc, border_gc; +extern int XCursesFontHeight, XCursesFontWidth; +extern int XCursesFontAscent, XCursesFontDescent; +extern int XCursesWindowWidth, XCursesWindowHeight; +extern int resizeXCursesWindowWidth, resizeXCursesWindowHeight; extern char *bitmap_file; #ifdef HAVE_XPM_H extern char *pixmap_file; @@ -300,7 +295,7 @@ extern char *defaultTranslations; extern XtActionsRec XCursesActions[PDC_NUMBER_XCURSES_ACTIONS]; extern char *XCursesClassName; extern XtAppContext app_context; -extern Widget topLevel,drawing,d1,scrollBox,scrollVert,scrollHoriz; +extern Widget topLevel, drawing, d1, scrollBox, scrollVert, scrollHoriz; extern int ReceivedMapNotify; extern Boolean mouse_selection; extern char *tmpsel; @@ -319,7 +314,7 @@ extern XrmOptionDescRec options[PDC_NUMBER_OPTIONS]; extern char global_display_name[100]; extern Bool after_first_curses_request; /* extern char *XCursesProgramName; */ -extern int colors[(2*MAX_COLORS)+2]; +extern int colors[(2 * MAX_COLORS) + 2]; extern int windowEntered; extern int visible_cursor; extern Bool vertical_cursor; @@ -327,13 +322,15 @@ extern Bool vertical_cursor; typedef RETSIGTYPE (*signal_handler)(); #ifdef HAVE_PROTO -void XCursesNonmaskable(Widget w,XtPointer client_data,XEvent *event,Boolean *continue_to_dispatch); -void XCursesExpose(Widget w,XtPointer client_data,XEvent *event,Boolean *continue_to_dispatch); -signal_handler XCursesSetSignal(int,signal_handler); +void XCursesNonmaskable(Widget w, XtPointer client_data, XEvent *event, + Boolean *continue_to_dispatch); +void XCursesExpose(Widget w, XtPointer client_data, XEvent *event, + Boolean *continue_to_dispatch); +signal_handler XCursesSetSignal(int, signal_handler); void XCursesGetIcon(void); int XCursesRefreshScrollbar(void); int XCursesSendKeyToCurses(unsigned long, MOUSE_STATUS *); -void XCursesButton(Widget,XEvent *,String *,Cardinal *); +void XCursesButton(Widget, XEvent *, String *, Cardinal *); void XCursesCursorBlink(XtPointer unused, XtIntervalId *id); void Scroll_up_down(Widget w, XtPointer client_data, XtPointer call_data); void Scroll_left_right(Widget w, XtPointer client_data, XtPointer call_data); diff --git a/x11/process/x11.c b/x11/process/x11.c index 1d55546e..be04e3d9 100644 --- a/x11/process/x11.c +++ b/x11/process/x11.c @@ -24,7 +24,7 @@ #include "pdcx11.h" extern AppData app_data; -int visible_cursor=0; +int visible_cursor = 0; int windowEntered = 1; static char *XCursesProgramName; @@ -36,31 +36,43 @@ extern void say(); /***********************************************************************/ #ifdef HAVE_PROTO -void XCursesExitXCursesProcess(int rc,int sig,char *msg) +void XCursesExitXCursesProcess(int rc, int sig, char *msg) #else -void XCursesExitXCursesProcess(rc,sig,msg) -int rc,sig; +void XCursesExitXCursesProcess(rc, sig, msg) +int rc, sig; char *msg; #endif /***********************************************************************/ { - if ( rc | sig ) - fprintf( stderr, "%s:XCursesExitXCursesProcess() - called: rc:%d sig:%d <%s>\n",(XCursesProcess)?" X":"CURSES",rc,sig,msg); - shmdt((char *)SP); - shmdt((char *)Xcurscr); - shmctl(shmidSP,IPC_RMID,0); - shmctl(shmid_Xcurscr,IPC_RMID,0); - XCursesEndwin(); - shutdown(display_sock,2); - close(display_sock); - shutdown(exit_sock,2); - close(exit_sock); - shutdown(key_sock,2); - close(key_sock); - if (sig) - kill(otherpid,sig); /* to kill parent process */ - _exit(rc); + if (rc || sig) + fprintf(stderr, + "%s:XCursesExitXCursesProcess() - called: rc:%d sig:%d <%s>\n", + XCLOGMSG, rc, sig, msg); + + shmdt((char *)SP); + shmdt((char *)Xcurscr); + shmctl(shmidSP, IPC_RMID, 0); + shmctl(shmid_Xcurscr, IPC_RMID, 0); + + XCursesEndwin(); + + shutdown(display_sock, 2); + close(display_sock); + + shutdown(exit_sock, 2); + close(exit_sock); + + shutdown(key_sock, 2); + close(key_sock); + + if (sig) + kill(otherpid, sig); /* to kill parent process */ + + _exit(rc); } + +/* This function redraws the entire screen. */ + /***********************************************************************/ #ifdef HAVE_PROTO void XCursesDisplayScreen(bool highlight) @@ -69,45 +81,41 @@ void XCursesDisplayScreen(highlight) bool highlight; #endif /***********************************************************************/ -/*---------------------------------------------------------------------*/ -/* This function re-draws the entire screen. */ -/*---------------------------------------------------------------------*/ { - int row=0; + int row; - PDC_LOG(("%s:XCursesDisplayScreen() - called:\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesDisplayScreen() - called:\n", XCLOGMSG)); - for (row=0;rowcursrow,SP->curscol, - SP->cursrow,SP->curscol); - /* - * Draw the border if required - */ - if (XCURSESBORDERWIDTH) - XDrawRectangle(XCURSESDISPLAY,XCURSESWIN,border_gc, - (XCURSESBORDERWIDTH/2),(XCURSESBORDERWIDTH/2), - (XCursesWindowWidth-XCURSESBORDERWIDTH), - (XCursesWindowHeight-XCURSESBORDERWIDTH)); - return; + for (row = 0; row < XCursesLINES; row++) + { + /* loop until we can write to the line -- Patch by: + Georg Fuchs, georg.fuchs@rz.uni-regensburg.de */ + + while (*(Xcurscr + XCURSCR_FLAG_OFF + row)) + dummy_function(); + + *(Xcurscr + XCURSCR_FLAG_OFF + row) = 1; + + XCursesDisplayText((chtype *)(Xcurscr + XCURSCR_Y_OFF(row)), + row, 0, COLS, highlight); + + *(Xcurscr + XCURSCR_FLAG_OFF + row) = 0; + } + + XCursesDisplayCursor(SP->cursrow, SP->curscol, SP->cursrow, + SP->curscol); + + /* Draw the border if required */ + + if (XCURSESBORDERWIDTH) + XDrawRectangle(XCURSESDISPLAY, XCURSESWIN, border_gc, + XCURSESBORDERWIDTH / 2, XCURSESBORDERWIDTH / 2, + XCursesWindowWidth - XCURSESBORDERWIDTH, + XCursesWindowHeight - XCURSESBORDERWIDTH); } +/* This function draws those portions of the screen that have changed. */ + /***********************************************************************/ #ifdef HAVE_PROTO int XCursesRefreshScreen(void) @@ -115,820 +123,822 @@ int XCursesRefreshScreen(void) int XCursesRefreshScreen() #endif /***********************************************************************/ -/*---------------------------------------------------------------------*/ -/* This function draws those portions of the screen that have changed. */ -/*---------------------------------------------------------------------*/ { - int row=0,start_col=0,num_cols=0; + int row, start_col, num_cols; - PDC_LOG(("%s:XCursesRefreshScreen() - called:\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesRefreshScreen() - called:\n", XCLOGMSG)); - for (row=0;rowcursrow,SP->curscol, - SP->cursrow,SP->curscol); - return(0); + for (row = 0; row < XCursesLINES; row++) + { + num_cols = (int)*(Xcurscr + XCURSCR_LENGTH_OFF + row); + + if (num_cols != 0) + { + while (*(Xcurscr + XCURSCR_FLAG_OFF + row)) + dummy_function(); + + *(Xcurscr + XCURSCR_FLAG_OFF + row) = 1; + + start_col = (int)*(Xcurscr + XCURSCR_START_OFF + row); + + XCursesDisplayText((chtype *)(Xcurscr + + XCURSCR_Y_OFF(row) + (start_col * + sizeof(chtype))), row, start_col, + num_cols, FALSE); + + *(Xcurscr + XCURSCR_LENGTH_OFF + row) = 0; + *(Xcurscr + XCURSCR_FLAG_OFF + row) = 0; + } + } + + if (mouse_selection) + SelectionOff(); + + XCursesDisplayCursor(SP->cursrow, SP->curscol, SP->cursrow, + SP->curscol); + + return 0; } /***********************************************************************/ #ifdef HAVE_PROTO -void XCursesProcessRequestsFromCurses(XtPointer client_data,int *fid,XtInputId *id) +void XCursesProcessRequestsFromCurses(XtPointer client_data, int *fid, + XtInputId *id) #else -void XCursesProcessRequestsFromCurses(client_data,fid,id) +void XCursesProcessRequestsFromCurses(client_data, fid, id) XtPointer client_data; int *fid; XtInputId *id; #endif /***********************************************************************/ { - int s,idx; - int old_row,new_row; - int old_x,new_x; - int pos,num_cols; - long length; - char buf[12]; /* big enough for 2 integers */ - char title[1024]; /* big enough for window title */ - unsigned char save_atrtab[MAX_ATRTAB]; - - PDC_LOG(("%s:XCursesProcessRequestsFromCurses()\n",(XCursesProcess)?" X":"CURSES")); - - if (!ReceivedMapNotify) - return; - FD_ZERO ( &readfds ); - FD_SET ( display_sock, &readfds ); - - if ( ( s = select ( FD_SETSIZE, (FD_SET_CAST)&readfds, NULL, NULL, &socket_timeout ) ) < 0 ) - XCursesExitXCursesProcess(2,SIGKILL,"exiting from XCursesProcessRequestsFromCurses - select failed"); - - if ( s == 0 ) /* no requests pending - should never happen!*/ - return; - - if ( FD_ISSET ( display_sock, &readfds ) ) - { -/* read first integer to determine total message has been received */ + int s, idx; + int old_row, new_row; + int old_x, new_x; + int pos, num_cols; - PDC_LOG(("%s:XCursesProcessRequestsFromCurses() - before read_socket()\n",(XCursesProcess)?" X":"CURSES")); + long length; - if (read_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(3,SIGKILL,"exiting from XCursesProcessRequestsFromCurses - first read"); + char buf[12]; /* big enough for 2 integers */ + char title[1024]; /* big enough for window title */ - PDC_LOG(("%s:XCursesProcessRequestsFromCurses() - after read_socket()\n",(XCursesProcess)?" X":"CURSES")); + unsigned char save_atrtab[MAX_ATRTAB]; - memcpy((char *)&num_cols,buf,sizeof(int)); - after_first_curses_request = True; - - switch(num_cols) - { - case 0: break; - case CURSES_EXIT: /* request from curses to stop */ - say("CURSES_EXIT received from child\n"); - XCursesExitXCursesProcess(0,0,"XCursesProcess requested to exit by child"); - break; - case CURSES_BELL: /* request from curses to beep */ - say("CURSES_BELL received from child\n"); - XBell(XCURSESDISPLAY,50); - break; - case CURSES_CLEAR: /* request from curses to clear window */ - say("CURSES_CLEAR received from child\n"); - XClearWindow(XCURSESDISPLAY,XCURSESWIN); - break; - case CURSES_FLASH: /* request from curses to beep */ - say("CURSES_FLASH received from child\n"); + PDC_LOG(("%s:XCursesProcessRequestsFromCurses()\n", XCLOGMSG)); + + if (!ReceivedMapNotify) + return; + + FD_ZERO(&readfds); + FD_SET(display_sock, &readfds); + + if ((s = select(FD_SETSIZE, (FD_SET_CAST)&readfds, NULL, + NULL, &socket_timeout)) < 0) + XCursesExitXCursesProcess(2, SIGKILL, + "exiting from XCursesProcessRequestsFromCurses - select failed"); + + if (s == 0) /* no requests pending - should never happen!*/ + return; + + if (FD_ISSET(display_sock, &readfds)) + { + /* read first integer to determine total message has + been received */ + + PDC_LOG(("%s:XCursesProcessRequestsFromCurses() - before read_socket()\n", + XCLOGMSG)); + + if (read_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitXCursesProcess(3, SIGKILL, + "exiting from XCursesProcessRequestsFromCurses - first read"); + + PDC_LOG(("%s:XCursesProcessRequestsFromCurses() - after read_socket()\n", + XCLOGMSG)); + + memcpy((char *)&num_cols, buf, sizeof(int)); + after_first_curses_request = True; + + switch(num_cols) + { + case 0: + break; + + case CURSES_EXIT: /* request from curses to stop */ + say("CURSES_EXIT received from child\n"); + XCursesExitXCursesProcess(0, 0, + "XCursesProcess requested to exit by child"); + break; + + case CURSES_BELL: + say("CURSES_BELL received from child\n"); + XBell(XCURSESDISPLAY, 50); + break; + + case CURSES_CLEAR: + say("CURSES_CLEAR received from child\n"); + XClearWindow(XCURSESDISPLAY, XCURSESWIN); + break; + + case CURSES_FLASH: + say("CURSES_FLASH received from child\n"); #if 0 - XFillRectangle(XCURSESDISPLAY,XCURSESWIN,normal_highlight_gc,10,10,XCursesWindowWidth-10,XCursesWindowHeight-10); - napms(50); - XFillRectangle(XCURSESDISPLAY,XCURSESWIN,normal_highlight_gc,10,10,XCursesWindowWidth-10,XCursesWindowHeight-10); - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); + XFillRectangle(XCURSESDISPLAY, XCURSESWIN, + normal_highlight_gc, 10, 10, + XCursesWindowWidth - 10, XCursesWindowHeight - 10); + + napms(50); + + XFillRectangle(XCURSESDISPLAY, XCURSESWIN, + normal_highlight_gc, 10, 10, + XCursesWindowWidth - 10, XCursesWindowHeight - 10); + + XCursesDisplayCursor(SP->cursrow, SP->curscol, + SP->cursrow, SP->curscol); #endif - old_x = CURSES_CONTINUE; - memcpy(buf,(char *)&old_x,sizeof(int)); - if (write_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); - break; - case CURSES_REFRESH: /* request from curses to confirm completion of display */ - say("CURSES_REFRESH received from child\n"); - visible_cursor = 1; - XCursesRefreshScreen(); - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); - old_x = CURSES_CONTINUE; - memcpy(buf,(char *)&old_x,sizeof(int)); - if (write_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); - break; - case CURSES_REFRESH_SCROLLBAR: /* request from curses draw scrollbar */ - XCursesRefreshScrollbar(); - break; - case CURSES_CURSOR: /* display cursor */ - say("CURSES_CURSOR received from child\n"); - if (read_socket(display_sock,buf,sizeof(int)*2) < 0) - XCursesExitXCursesProcess(5,SIGKILL,"exiting from CURSES_CURSOR XCursesProcessRequestsFromCurses"); - memcpy((char *)&pos,buf,sizeof(int)); - old_row = pos & 0xFF; - old_x = pos >> 8; - idx = sizeof(int); - memcpy((char *)&pos,buf+idx,sizeof(int)); - new_row = pos & 0xFF; - new_x = pos >> 8; - visible_cursor = 1; - XCursesDisplayCursor(old_row,old_x,new_row,new_x); - break; - case CURSES_DISPLAY_CURSOR: /* display cursor */ - say("CURSES_DISPLAY_CURSOR received from child. Vis now: "); - say(visible_cursor ? "1\n" : "0\n"); - /* - * If the window is not active, ignore this command. The - * cursor will stay solid. - */ - if ( windowEntered ) - { - if ( visible_cursor ) - { - /* - * Cursor currently ON, turn it off - */ - int save_visibility = SP->visibility; - SP->visibility = 0; - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); - SP->visibility = save_visibility; - visible_cursor = 0; - } - else - { - /* - * Cursor currently OFF, turn it on - */ - XCursesDisplayCursor(SP->cursrow,SP->curscol, - SP->cursrow,SP->curscol); - visible_cursor = 1; - } - } - break; - case CURSES_TITLE: /* display window title */ - say("CURSES_TITLE received from child\n"); - if (read_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(5,SIGKILL,"exiting from CURSES_TITLE XCursesProcessRequestsFromCurses"); - memcpy((char *)&pos,buf,sizeof(int)); - if (read_socket(display_sock,title,pos) < 0) - XCursesExitXCursesProcess(5,SIGKILL,"exiting from CURSES_TITLE XCursesProcessRequestsFromCurses"); - XtVaSetValues(topLevel, XtNtitle, title, NULL); - break; - case CURSES_RESIZE: /* resize window */ - after_first_curses_request = False; - say("CURSES_RESIZE received from child\n"); - SP->lines = XCursesLINES = ((resizeXCursesWindowHeight-(2*XCURSESBORDERWIDTH)) / XCursesFontHeight); - LINES = XCursesLINES - SP->linesrippedoff - SP->slklines; - SP->cols = COLS = XCursesCOLS = ((resizeXCursesWindowWidth-(2*XCURSESBORDERWIDTH)) / XCursesFontWidth); - XCursesWindowWidth = resizeXCursesWindowWidth; - XCursesWindowHeight = resizeXCursesWindowHeight; - visible_cursor = 1; - /* - * Draw the border if required - */ - if (XCURSESBORDERWIDTH) - XDrawRectangle(XCURSESDISPLAY,XCURSESWIN,border_gc, - (XCURSESBORDERWIDTH/2),(XCURSESBORDERWIDTH/2), - (XCursesWindowWidth-XCURSESBORDERWIDTH), - (XCursesWindowHeight-XCURSESBORDERWIDTH)); -/* - * detach and drop the current shared memory segment and create and attach - * to a new segment. - */ - memcpy(save_atrtab,atrtab,sizeof(save_atrtab)); - SP->XcurscrSize = XCURSCR_SIZE; - shmdt((char *)Xcurscr); - shmctl(shmid_Xcurscr,IPC_RMID,0); - if ((shmid_Xcurscr = shmget(shmkey_Xcurscr,SP->XcurscrSize+XCURSESSHMMIN,0700|IPC_CREAT)) < 0) - { - perror("Cannot allocate shared memory for curscr"); - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); - } - Xcurscr = (unsigned char*)shmat(shmid_Xcurscr,0,0); - memset(Xcurscr, 0, SP->XcurscrSize); - atrtab = (unsigned char *)(Xcurscr+XCURSCR_ATRTAB_OFF); - memcpy(atrtab,save_atrtab,sizeof(save_atrtab)); + old_x = CURSES_CONTINUE; + memcpy(buf, (char *)&old_x, sizeof(int)); + + if (write_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitXCursesProcess(4, SIGKILL, + "exiting from XCursesProcessRequestsFromCurses"); + break; + + /* request from curses to confirm completion of display */ + + case CURSES_REFRESH: + say("CURSES_REFRESH received from child\n"); + visible_cursor = 1; + XCursesRefreshScreen(); + XCursesDisplayCursor(SP->cursrow, SP->curscol, + SP->cursrow, SP->curscol); + + old_x = CURSES_CONTINUE; + memcpy(buf, (char *)&old_x, sizeof(int)); + + if (write_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitXCursesProcess(4, SIGKILL, + "exiting from XCursesProcessRequestsFromCurses"); + break; + + case CURSES_REFRESH_SCROLLBAR: + XCursesRefreshScrollbar(); + break; + + case CURSES_CURSOR: + say("CURSES_CURSOR received from child\n"); + if (read_socket(display_sock, buf, sizeof(int) * 2) < 0) + XCursesExitXCursesProcess(5, SIGKILL, + "exiting from CURSES_CURSOR XCursesProcessRequestsFromCurses"); + + memcpy((char *)&pos, buf, sizeof(int)); + + old_row = pos & 0xFF; + old_x = pos >> 8; + idx = sizeof(int); + memcpy((char *)&pos, buf + idx, sizeof(int)); + + new_row = pos & 0xFF; + new_x = pos >> 8; + visible_cursor = 1; + XCursesDisplayCursor(old_row, old_x, new_row, new_x); + break; + + case CURSES_DISPLAY_CURSOR: + say("CURSES_DISPLAY_CURSOR received from child. Vis now: "); + say(visible_cursor ? "1\n" : "0\n"); + + /* If the window is not active, ignore this + command. The cursor will stay solid. */ + + if (windowEntered) + { + if (visible_cursor) + { + /* Cursor currently ON, turn it off */ + + int save_visibility = SP->visibility; + SP->visibility = 0; + + XCursesDisplayCursor(SP->cursrow, SP->curscol, + SP->cursrow, SP->curscol); + + SP->visibility = save_visibility; + visible_cursor = 0; + } + else + { + /* Cursor currently OFF, turn it on */ + + XCursesDisplayCursor(SP->cursrow, SP->curscol, + SP->cursrow, SP->curscol); + + visible_cursor = 1; + } + } + + break; + + case CURSES_TITLE: + say("CURSES_TITLE received from child\n"); + + if (read_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitXCursesProcess(5, SIGKILL, + "exiting from CURSES_TITLE XCursesProcessRequestsFromCurses"); + + memcpy((char *)&pos, buf, sizeof(int)); + + if (read_socket(display_sock, title, pos) < 0) + XCursesExitXCursesProcess(5, SIGKILL, + "exiting from CURSES_TITLE XCursesProcessRequestsFromCurses"); + + XtVaSetValues(topLevel, XtNtitle, title, NULL); + break; + + case CURSES_RESIZE: + after_first_curses_request = False; + say("CURSES_RESIZE received from child\n"); + + SP->lines = XCursesLINES = ((resizeXCursesWindowHeight - + (2 * XCURSESBORDERWIDTH)) / XCursesFontHeight); + + LINES = XCursesLINES - SP->linesrippedoff - SP->slklines; + + SP->cols = COLS = XCursesCOLS = ((resizeXCursesWindowWidth - + (2 * XCURSESBORDERWIDTH)) / XCursesFontWidth); + + XCursesWindowWidth = resizeXCursesWindowWidth; + XCursesWindowHeight = resizeXCursesWindowHeight; + visible_cursor = 1; + + /* Draw the border if required */ + + if (XCURSESBORDERWIDTH) + XDrawRectangle(XCURSESDISPLAY, XCURSESWIN, border_gc, + XCURSESBORDERWIDTH / 2, XCURSESBORDERWIDTH / 2, + XCursesWindowWidth - XCURSESBORDERWIDTH, + XCursesWindowHeight - XCURSESBORDERWIDTH); + + /* Detach and drop the current shared memory segment and + create and attach to a new segment */ + + memcpy(save_atrtab, atrtab, sizeof(save_atrtab)); + + SP->XcurscrSize = XCURSCR_SIZE; + shmdt((char *)Xcurscr); + shmctl(shmid_Xcurscr, IPC_RMID, 0); + + if ((shmid_Xcurscr = shmget(shmkey_Xcurscr, + SP->XcurscrSize + XCURSESSHMMIN, 0700 | IPC_CREAT)) < 0) + { + perror("Cannot allocate shared memory for curscr"); + XCursesExitXCursesProcess(4, SIGKILL, + "exiting from XCursesProcessRequestsFromCurses"); + } + + Xcurscr = (unsigned char*)shmat(shmid_Xcurscr, 0, 0); + memset(Xcurscr, 0, SP->XcurscrSize); + atrtab = (unsigned char *)(Xcurscr + XCURSCR_ATRTAB_OFF); + memcpy(atrtab, save_atrtab, sizeof(save_atrtab)); - old_x = CURSES_CONTINUE; - memcpy(buf,(char *)&old_x,sizeof(int)); - if (write_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); - break; - case CURSES_GET_SELECTION: /* request selection contents */ - say("CURSES_GET_SELECTION received from child\n"); - old_x = CURSES_CONTINUE; - memcpy(buf,(char *)&old_x,sizeof(int)); - if (write_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); - XtGetSelectionValue(topLevel,XA_PRIMARY,XA_STRING,XCursesRequestorCallbackForGetSelection,(XtPointer)NULL,0); - break; - case CURSES_SET_SELECTION: /* set the selection contents */ - say("CURSES_SET_SELECTION received from child\n"); - if (read_socket(display_sock,buf,sizeof(long)) < 0) - XCursesExitXCursesProcess(5,SIGKILL,"exiting from CURSES_TITLE XCursesProcessRequestsFromCurses"); - memcpy((char *)&length,buf,sizeof(long)); - if (length > tmpsel_length) - { - if (tmpsel_length == 0) - tmpsel = (char *)malloc(length+1); - else - tmpsel = (char *)realloc(tmpsel,length+1); - } - if (!tmpsel) - { - old_x = PDC_CLIP_MEMORY_ERROR; - memcpy(buf,(char *)&old_x,sizeof(int)); - if (write_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); - break; - } - if (read_socket(display_sock,tmpsel,length) < 0) - XCursesExitXCursesProcess(5,SIGKILL,"exiting from CURSES_TITLE XCursesProcessRequestsFromCurses"); - tmpsel_length = length; - *(tmpsel+length) = '\0'; - if (XtOwnSelection(topLevel, - XA_PRIMARY, - CurrentTime, - XCursesConvertProc, - XCursesLoseOwnership, - NULL) == False) - { - old_x = PDC_CLIP_ACCESS_ERROR; - free(tmpsel); - tmpsel = NULL; - tmpsel_length = 0; - } - else - old_x = PDC_CLIP_SUCCESS; - SelectionOff(); - memcpy(buf,(char *)&old_x,sizeof(int)); - if (write_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); - break; - case CURSES_CLEAR_SELECTION: /* request clear of selection */ - say("CURSES_CLEAR_SELECTION received from child\n"); - old_x = CURSES_CONTINUE; - memcpy(buf,(char *)&old_x,sizeof(int)); - if (write_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesProcessRequestsFromCurses"); - SelectionOff(); - break; - default: - PDC_LOG(("%s:Unknown request %d\n",(XCursesProcess)?" X":"CURSES",num_cols)); - break; - } - } - return; + old_x = CURSES_CONTINUE; + memcpy(buf, (char *)&old_x, sizeof(int)); + + if (write_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitXCursesProcess(4, SIGKILL, + "exiting from XCursesProcessRequestsFromCurses"); + break; + + case CURSES_GET_SELECTION: + say("CURSES_GET_SELECTION received from child\n"); + old_x = CURSES_CONTINUE; + memcpy(buf, (char *)&old_x, sizeof(int)); + + if (write_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitXCursesProcess(4, SIGKILL, + "exiting from XCursesProcessRequestsFromCurses"); + + XtGetSelectionValue(topLevel, XA_PRIMARY, XA_STRING, + XCursesRequestorCallbackForGetSelection, + (XtPointer)NULL, 0); + + break; + + case CURSES_SET_SELECTION: + say("CURSES_SET_SELECTION received from child\n"); + + if (read_socket(display_sock,buf,sizeof(long)) < 0) + XCursesExitXCursesProcess(5, SIGKILL, + "exiting from CURSES_TITLE XCursesProcessRequestsFromCurses"); + + memcpy((char *)&length, buf, sizeof(long)); + + if (length > tmpsel_length) + { + if (tmpsel_length == 0) + tmpsel = (char *)malloc(length + 1); + else + tmpsel = (char *)realloc(tmpsel, length + 1); + } + + if (!tmpsel) + { + old_x = PDC_CLIP_MEMORY_ERROR; + + memcpy(buf, (char *)&old_x, sizeof(int)); + + if (write_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitXCursesProcess(4, SIGKILL, + "exiting from XCursesProcessRequestsFromCurses"); + break; + } + + if (read_socket(display_sock, tmpsel, length) < 0) + XCursesExitXCursesProcess(5, SIGKILL, + "exiting from CURSES_TITLE XCursesProcessRequestsFromCurses"); + + tmpsel_length = length; + tmpsel[length] = '\0'; + + if (XtOwnSelection(topLevel, XA_PRIMARY, CurrentTime, + XCursesConvertProc, XCursesLoseOwnership, NULL) == False) + { + old_x = PDC_CLIP_ACCESS_ERROR; + free(tmpsel); + tmpsel = NULL; + tmpsel_length = 0; + } + else + old_x = PDC_CLIP_SUCCESS; + + SelectionOff(); + memcpy(buf, (char *)&old_x, sizeof(int)); + + if (write_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitXCursesProcess(4, SIGKILL, + "exiting from XCursesProcessRequestsFromCurses"); + break; + + case CURSES_CLEAR_SELECTION: + say("CURSES_CLEAR_SELECTION received from child\n"); + old_x = CURSES_CONTINUE; + memcpy(buf, (char *)&old_x, sizeof(int)); + + if (write_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitXCursesProcess(4, SIGKILL, + "exiting from XCursesProcessRequestsFromCurses"); + + SelectionOff(); + break; + + default: + PDC_LOG(("%s:Unknown request %d\n", XCLOGMSG, num_cols)); + } + } } /***********************************************************************/ #ifdef HAVE_PROTO -int XCursesSetupX(char *display_name,int argc, char *argv[]) +int XCursesSetupX(char *display_name, int argc, char *argv[]) #else -int XCursesSetupX(display_name,argc,argv) +int XCursesSetupX(display_name, argc, argv) char *display_name; int arc; char *argv[]; #endif /***********************************************************************/ { - extern bool sb_started; + static char *myargv[] = {"PDCurses", NULL}; + extern bool sb_started; - int italic_font_valid; - XColor pointerforecolor,pointerbackcolor; - XrmValue rmfrom,rmto; - XWMHints wmhints; - char wait_buf[5]; - int wait_value=0,i=0; - int minwidth=0,minheight=0; - int myargc; - char *myargv[2]; + int italic_font_valid; + XColor pointerforecolor, pointerbackcolor; + XrmValue rmfrom, rmto; + XWMHints wmhints; + char wait_buf[5]; + int wait_value = 0, i = 0; + int minwidth = 0, minheight = 0; - PDC_LOG(("%s:XCursesSetupX called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesSetupX called\n", XCLOGMSG)); - /* - * The following kludge is to force XtVaAppInitialize() to recognize the - * name of the program. Without it, a default value of "main" is used. - */ - if (argv) - { -/* argv[0] = XCursesProgramName; */ - XCursesProgramName = argv[0]; -#ifdef PDCDEBUG1 - for (i=0;i %s\n",i,argv[i]); -#endif - } - else - { - /* - * initscr() called rather than initscrX() - */ - XCursesProgramName = myargv[0] = "main"; - myargv[1] = NULL; - myargc=1; - } + /* The following kludge is to force XtVaAppInitialize() to + recognize the name of the program. Without it, a default + value of "PDCurses" is used. */ + + if (!argv) + { + argv = myargv; + argc = 1; + } + + XCursesProgramName = argv[0]; + + /* Keep open the 'write' end of the socket so the XCurses + process can send a CURSES_EXIT to itself from within the + signal handler */ + + exit_sock = display_sockets[0]; + display_sock = display_sockets[1]; + + close(key_sockets[0]); + key_sock = key_sockets[1]; + + /* Trap all signals when XCurses is the child process, but only + if they haven't already been ignored by the application. */ + + for (i = 0; i < PDC_MAX_SIGNALS; i++) + if (XCursesSetSignal(i, XCursesSignalHandler) == SIG_IGN) + XCursesSetSignal(i, SIG_IGN); + + /* Start defining X Toolkit things */ - /* - * Keep open the 'write' end of the socket so the XCurses process can - * send a CURSES_EXIT to itself from within the signal handler... - */ -#if 0 - close ( display_sockets[0] ); -#else - exit_sock = display_sockets[0]; -#endif - display_sock = display_sockets[1]; - close ( key_sockets[0] ); - key_sock = key_sockets[1]; - /* - * Trap all signals when XCurses is the child process... - * ...but only if they haven't already been ignored by the - * application. - */ - for ( i = 0; i < PDC_MAX_SIGNALS; i++ ) - { - if ( XCursesSetSignal( i, XCursesSignalHandler) == SIG_IGN ) - XCursesSetSignal( i, SIG_IGN ); - } - /* - * Start defining X Toolkit things... - */ #if XtSpecificationRelease > 4 - XtSetLanguageProc(NULL, (XtLanguageProc)NULL,NULL); -#endif - /* - * If a DISPLAY value has been supplied, set the env variable DISPLAY. - */ - if (display_name) - { - strcpy(global_display_name,"DISPLAY="); - strcat(global_display_name,display_name); - putenv(global_display_name); - } - /* - * Exit if no DISPLAY variable set... - */ - if (getenv("DISPLAY") == NULL) - { - fprintf(stderr,"Error: no DISPLAY variable set\n"); - kill(otherpid,SIGKILL); - return(ERR); - } - /* - * Initialise the top level widget... - */ - if (argv) - { - topLevel = XtVaAppInitialize( &app_context, - XCursesClassName, - options, - XtNumber(options), - &argc, - argv, - NULL, -/* - XtNinput, (XtArgVal)True, - XtNtitle,XCursesProgramName, - XtNname,"xcurses", -*/ - NULL); - } - else - { - topLevel = XtVaAppInitialize( &app_context, - XCursesClassName, - options, - XtNumber(options), - &myargc, - myargv, - NULL, -/* - XtNinput, (XtArgVal)True, - XtNtitle,XCursesProgramName, - XtNname,"xcurses", -*/ - NULL); - } -#if 0 - for (i=0;i %s\n",i,argv[i]); + XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL); #endif - XtVaGetApplicationResources(topLevel,&app_data,app_resources,XtNumber(app_resources),NULL); - /* check application resource values here... */ + /* If a DISPLAY value has been supplied, set the env variable + DISPLAY */ -#if 0 -printf("Width %d Height %d\n",XCURSESGEOMETRY.width,XCURSESGEOMETRY.height); -#endif + if (display_name) + { + strcpy(global_display_name, "DISPLAY="); + strcat(global_display_name, display_name); + putenv(global_display_name); + } - XCursesFontWidth = XCURSESNORMALFONTINFO->max_bounds.rbearing - XCURSESNORMALFONTINFO->min_bounds.lbearing; - XCursesFontHeight = XCURSESNORMALFONTINFO->max_bounds.ascent + XCURSESNORMALFONTINFO->max_bounds.descent; - XCursesFontAscent = XCURSESNORMALFONTINFO->max_bounds.ascent; - XCursesFontDescent = XCURSESNORMALFONTINFO->max_bounds.descent; + /* Exit if no DISPLAY variable set */ - /* - * Check that the italic font and normal fonts are the same size... - */ - if (XCursesFontWidth != XCURSESITALICFONTINFO->max_bounds.rbearing - XCURSESITALICFONTINFO->min_bounds.lbearing - || XCursesFontHeight != XCURSESITALICFONTINFO->max_bounds.ascent + XCURSESITALICFONTINFO->max_bounds.descent) - { - italic_font_valid = 1; - } - else - { - italic_font_valid = 0; - } + if (getenv("DISPLAY") == NULL) + { + fprintf(stderr, "Error: no DISPLAY variable set\n"); + kill(otherpid, SIGKILL); + return ERR; + } + + /* Initialise the top level widget */ + + topLevel = XtVaAppInitialize(&app_context, XCursesClassName, + options, XtNumber(options), &argc, argv, NULL, NULL); + + XtVaGetApplicationResources(topLevel, &app_data, app_resources, + XtNumber(app_resources), NULL); + + /* Check application resource values here */ + + XCursesFontWidth = XCURSESNORMALFONTINFO->max_bounds.rbearing - + XCURSESNORMALFONTINFO->min_bounds.lbearing; + + XCursesFontHeight = XCURSESNORMALFONTINFO->max_bounds.ascent + + XCURSESNORMALFONTINFO->max_bounds.descent; + + XCursesFontAscent = XCURSESNORMALFONTINFO->max_bounds.ascent; + XCursesFontDescent = XCURSESNORMALFONTINFO->max_bounds.descent; + + /* Check that the italic font and normal fonts are the same size */ + /* This appears backwards */ + + italic_font_valid = XCursesFontWidth != + XCURSESITALICFONTINFO->max_bounds.rbearing - + XCURSESITALICFONTINFO->min_bounds.lbearing || + XCursesFontHeight != + XCURSESITALICFONTINFO->max_bounds.ascent + + XCURSESITALICFONTINFO->max_bounds.descent; + + /* Calculate size of display window */ + + XCursesCOLS = XCURSESCOLS; + XCursesLINES = XCURSESLINES; + + XCursesWindowWidth = XCursesFontWidth * XCursesCOLS + + 2 * XCURSESBORDERWIDTH; + + XCursesWindowHeight = XCursesFontHeight * XCursesLINES + + 2 * XCURSESBORDERWIDTH; + + minwidth = XCursesFontWidth * 2 + XCURSESBORDERWIDTH * 2; + minheight = XCursesFontHeight * 2 + XCURSESBORDERWIDTH * 2; + + /* Set up the icon for the application; the default is an + internal one for XCurses. Then set various application level + resources. */ + + XCursesGetIcon(); - /* - * Calculate size of display window... - */ - XCursesCOLS = XCURSESCOLS; - XCursesLINES = XCURSESLINES; - XCursesWindowWidth = (XCursesFontWidth * XCursesCOLS) + (2 * XCURSESBORDERWIDTH); - XCursesWindowHeight = (XCursesFontHeight * XCursesLINES) + (2 * XCURSESBORDERWIDTH); - minwidth = (XCursesFontWidth*2)+(XCURSESBORDERWIDTH*2); - minheight = (XCursesFontHeight*2)+(XCURSESBORDERWIDTH*2); - /* - * Set up the icon for the application. The default is an internal one - * for XCurses. Then set various application level resources... - */ - XCursesGetIcon(); - #ifdef HAVE_XPM_H - if (XCURSESPIXMAPFILE != NULL) - { - XtVaSetValues( topLevel, - XtNminWidth,minwidth, - XtNminHeight,minheight, - XtNiconPixmap,icon_pixmap, - XtNiconMask,icon_pixmap_mask, - NULL); - } - else - { - XtVaSetValues( topLevel, - XtNminWidth,minwidth, - XtNminHeight,minheight, - XtNiconPixmap,icon_bitmap, - NULL); - } -#else - XtVaSetValues( topLevel, - XtNminWidth,minwidth, - XtNminHeight,minheight, - XtNiconPixmap,icon_bitmap, - NULL); + if (XCURSESPIXMAPFILE != NULL) + XtVaSetValues(topLevel, XtNminWidth, minwidth, + XtNminHeight, minheight, XtNiconPixmap, + icon_pixmap, XtNiconMask, icon_pixmap_mask, NULL); + else #endif - /* - * Create a BOX widget in which to draw... - */ -#if 0 - fprintf(stderr,"SB Width: %d Width: %d Height: %d sb_started: %d\n", - XCURSESSCROLLBARWIDTH, - XCursesWindowWidth+XCURSESSCROLLBARWIDTH, - XCursesWindowHeight+XCURSESSCROLLBARWIDTH, - sb_started); -#endif - if (XCURSESSCROLLBARWIDTH != 0 - && sb_started) - { - scrollBox = XtVaCreateManagedWidget(XCursesProgramName,scrollBoxWidgetClass,topLevel, - XtNwidth,XCursesWindowWidth+XCURSESSCROLLBARWIDTH, - XtNheight,XCursesWindowHeight+XCURSESSCROLLBARWIDTH, - XtNwidthInc,XCursesFontWidth, - XtNheightInc,XCursesFontHeight, - NULL); - drawing = XtVaCreateManagedWidget(XCursesProgramName,boxWidgetClass, - scrollBox, - XtNwidth,XCursesWindowWidth, - XtNheight,XCursesWindowHeight, - XtNwidthInc,XCursesFontWidth, - XtNheightInc,XCursesFontHeight, - NULL); - scrollVert = XtVaCreateManagedWidget("scrollVert", scrollbarWidgetClass, - scrollBox, - XtNorientation, XtorientVertical, - XtNheight, XCursesWindowHeight, - XtNwidth, XCURSESSCROLLBARWIDTH, - NULL); - XtAddCallback(scrollVert, XtNscrollProc, Scroll_up_down, drawing); - XtAddCallback(scrollVert, XtNjumpProc, Thumb_up_down, drawing); - scrollHoriz = XtVaCreateManagedWidget("scrollHoriz", scrollbarWidgetClass, - scrollBox, - XtNorientation, XtorientHorizontal, - XtNwidth, XCursesWindowWidth, - XtNheight, XCURSESSCROLLBARWIDTH, - NULL); - XtAddCallback(scrollHoriz, XtNscrollProc, Scroll_left_right, drawing); - XtAddCallback(scrollHoriz, XtNjumpProc, Thumb_left_right, drawing); - } - else - { - drawing = XtVaCreateManagedWidget(XCursesProgramName,boxWidgetClass,topLevel, - XtNwidth,XCursesWindowWidth, - XtNheight,XCursesWindowHeight, - XtNwidthInc,XCursesFontWidth, - XtNheightInc,XCursesFontHeight, - NULL); - XtVaSetValues( topLevel, - XtNwidthInc,XCursesFontWidth, - XtNheightInc,XCursesFontHeight, - NULL); - } + XtVaSetValues(topLevel, XtNminWidth, minwidth, + XtNminHeight, minheight, XtNiconPixmap, + icon_bitmap, NULL); -#if 0 - fprintf(stderr,"Width: %d Height: %d FontWidth: %d FontHeight: %d\n",XCursesWindowWidth+XCURSESSCROLLBARWIDTH, - XCursesWindowHeight+XCURSESSCROLLBARWIDTH, - XCursesFontWidth, - XCursesFontHeight); -#endif -/* - XtVaSetValues(drawing, - XtNwidth,XCursesWindowWidth, - XtNheight,XCursesWindowHeight, - XtNwidthInc,XCursesFontWidth, - XtNheightInc,XCursesFontHeight, - XtNminWidth,XCursesFontWidth*2, - XtNminHeight,XCursesFontHeight*2, - XtNborderWidth,20, - NULL); -*/ - /* - * Process any default translations... - */ - XCursesTranslations = XtParseTranslationTable(defaultTranslations); - XtAugmentTranslations(drawing,XCursesTranslations); - XtAppAddActions(app_context,XCursesActions,XtNumber(XCursesActions)); - /* - * Process the supplied colors... - */ - if (get_colors() == ERR) - { - kill(otherpid,SIGKILL); - return(ERR); - } - /* - * Determine text cursor alignment from resources - */ - if ( strcmp( XCURSESTEXTCURSOR, "vertical" ) == 0 ) - vertical_cursor = True; - /* - * Now have LINES and COLS. Set these in the shared SP so the - * curses program can find them... - */ - LINES = XCursesLINES; - COLS = XCursesCOLS; - if ((shmidSP = shmget(shmkeySP,sizeof(SCREEN)+XCURSESSHMMIN,0700|IPC_CREAT)) < 0) - { - perror("Cannot allocate shared memory for SCREEN"); - kill(otherpid,SIGKILL); - return(ERR); - } - SP = (SCREEN*)shmat(shmidSP,0,0); - memset(SP, 0, sizeof(SCREEN)); - SP->XcurscrSize = XCURSCR_SIZE; - SP->lines = XCursesLINES; - SP->cols = XCursesCOLS; + /* Create a BOX widget in which to draw */ - PDC_LOG(("%s:SHM size for curscr %d\n",(XCursesProcess)?" X":"CURSES",SP->XcurscrSize)); + if (XCURSESSCROLLBARWIDTH != 0 && sb_started) + { + scrollBox = XtVaCreateManagedWidget(XCursesProgramName, + scrollBoxWidgetClass, topLevel, XtNwidth, + XCursesWindowWidth + XCURSESSCROLLBARWIDTH, + XtNheight, XCursesWindowHeight + + XCURSESSCROLLBARWIDTH, XtNwidthInc, + XCursesFontWidth, XtNheightInc, + XCursesFontHeight, NULL); - if ((shmid_Xcurscr = shmget(shmkey_Xcurscr,SP->XcurscrSize+XCURSESSHMMIN,0700|IPC_CREAT)) < 0) - { - perror("Cannot allocate shared memory for curscr"); - kill(otherpid,SIGKILL); - shmdt((char *)SP); - shmctl(shmidSP,IPC_RMID,0); - return(ERR); - } - Xcurscr = (unsigned char *)shmat(shmid_Xcurscr,0,0); - memset(Xcurscr, 0, SP->XcurscrSize); - atrtab = (unsigned char *)(Xcurscr+XCURSCR_ATRTAB_OFF); - PDC_init_atrtab(); + drawing = XtVaCreateManagedWidget(XCursesProgramName, + boxWidgetClass, scrollBox, XtNwidth, + XCursesWindowWidth, XtNheight, + XCursesWindowHeight, XtNwidthInc, + XCursesFontWidth, XtNheightInc, + XCursesFontHeight, NULL); - PDC_LOG(("%s:shmid_Xcurscr %d shmkey_Xcurscr %d LINES %d COLS %d\n",(XCursesProcess)?" X":"CURSES",shmid_Xcurscr,shmkey_Xcurscr,LINES,COLS)); + scrollVert = XtVaCreateManagedWidget("scrollVert", + scrollbarWidgetClass, scrollBox, XtNorientation, + XtorientVertical, XtNheight, + XCursesWindowHeight, XtNwidth, + XCURSESSCROLLBARWIDTH, NULL); + + XtAddCallback(scrollVert, XtNscrollProc, + Scroll_up_down, drawing); + + XtAddCallback(scrollVert, XtNjumpProc, + Thumb_up_down, drawing); + + scrollHoriz = XtVaCreateManagedWidget("scrollHoriz", + scrollbarWidgetClass, scrollBox, XtNorientation, + XtorientHorizontal, XtNwidth, + XCursesWindowWidth, XtNheight, + XCURSESSCROLLBARWIDTH, NULL); + + XtAddCallback(scrollHoriz, XtNscrollProc, + Scroll_left_right, drawing); + + XtAddCallback(scrollHoriz, XtNjumpProc, + Thumb_left_right, drawing); + } + else + { + drawing = XtVaCreateManagedWidget(XCursesProgramName, + boxWidgetClass, topLevel, XtNwidth, + XCursesWindowWidth, XtNheight, + XCursesWindowHeight, XtNwidthInc, + XCursesFontWidth, XtNheightInc, + XCursesFontHeight, NULL); + + XtVaSetValues(topLevel, XtNwidthInc, XCursesFontWidth, + XtNheightInc, XCursesFontHeight, NULL); + } + + /* Process any default translations */ + + XCursesTranslations = XtParseTranslationTable(defaultTranslations); + XtAugmentTranslations(drawing, XCursesTranslations); + XtAppAddActions(app_context, XCursesActions, XtNumber(XCursesActions)); + + /* Process the supplied colors */ + + if (get_colors() == ERR) + { + kill(otherpid, SIGKILL); + return ERR; + } + + /* Determine text cursor alignment from resources */ + + if (strcmp(XCURSESTEXTCURSOR, "vertical") == 0) + vertical_cursor = True; + + /* Now have LINES and COLS. Set these in the shared SP so the + curses program can find them. */ + + LINES = XCursesLINES; + COLS = XCursesCOLS; + + if ((shmidSP = shmget(shmkeySP, sizeof(SCREEN) + XCURSESSHMMIN, + 0700 | IPC_CREAT)) < 0) + { + perror("Cannot allocate shared memory for SCREEN"); + kill(otherpid, SIGKILL); + return ERR; + } + + SP = (SCREEN*)shmat(shmidSP, 0, 0); + memset(SP, 0, sizeof(SCREEN)); + SP->XcurscrSize = XCURSCR_SIZE; + SP->lines = XCursesLINES; + SP->cols = XCursesCOLS; + + PDC_LOG(("%s:SHM size for curscr %d\n", XCLOGMSG, SP->XcurscrSize)); + + if ((shmid_Xcurscr = shmget(shmkey_Xcurscr, SP->XcurscrSize + + XCURSESSHMMIN, 0700 | IPC_CREAT)) < 0) + { + perror("Cannot allocate shared memory for curscr"); + kill(otherpid, SIGKILL); + shmdt((char *)SP); + shmctl(shmidSP, IPC_RMID, 0); + return ERR; + } + + Xcurscr = (unsigned char *)shmat(shmid_Xcurscr, 0, 0); + memset(Xcurscr, 0, SP->XcurscrSize); + atrtab = (unsigned char *)(Xcurscr + XCURSCR_ATRTAB_OFF); + PDC_init_atrtab(); + + PDC_LOG(("%s:shmid_Xcurscr %d shmkey_Xcurscr %d LINES %d COLS %d\n", + XCLOGMSG, shmid_Xcurscr, shmkey_Xcurscr, LINES, COLS)); + + /* Add Event handlers to the drawing widget */ + + XtAddEventHandler(drawing, ExposureMask, False, XCursesExpose, NULL); + XtAddEventHandler(drawing, StructureNotifyMask, False, + XCursesStructureNotify, NULL); + XtAddEventHandler(drawing, EnterWindowMask | LeaveWindowMask, + False, XCursesEnterLeaveWindow, NULL); + + XtAddEventHandler(topLevel, 0, True, XCursesNonmaskable, NULL); + + /* Add input handler from display_sock (requests from curses + program) */ + + XtAppAddInput(app_context, display_sock, + (XtPointer)XtInputReadMask, + XCursesProcessRequestsFromCurses, NULL); + + /* If there is a cursorBlink resource, start the Timeout event */ + + if (XCURSESCURSORBLINKRATE) + XtAppAddTimeOut(app_context, XCURSESCURSORBLINKRATE, + XCursesCursorBlink, NULL); + + /* Leave telling the curses process that it can start to here so + that when the curses process makes a request, the Xcurses + process can service the request.*/ + + wait_value = CURSES_CHILD; + memcpy(wait_buf, (char *)&wait_value, sizeof(int)); + write_socket(display_sock, wait_buf, sizeof(int)); + + XtRealizeWidget(topLevel); + + /* Handle trapping of the WM_DELETE_WINDOW property */ + + wm_atom[0] = XInternAtom(XtDisplay(topLevel), + "WM_DELETE_WINDOW", False); + + XSetWMProtocols(XtDisplay(topLevel), XtWindow(topLevel), + wm_atom, 1); + + /* Create the Graphics Context for drawing. This MUST be done + AFTER the associated widget has been realized. */ - /* - * Add Event handlers to the drawing widget... - */ - XtAddEventHandler(drawing,ExposureMask,False,XCursesExpose,NULL); - /* XtAddEventHandler(drawing,KeyPressMask|KeyReleaseMask,False,XCursesKeyPressKeyRelease,NULL); */ - /* XtAddEventHandler(drawing,ButtonPressMask|ButtonReleaseMask,False,XCursesButtonPressButtonRelease,NULL);*/ - XtAddEventHandler(drawing,StructureNotifyMask,False,XCursesStructureNotify,NULL); - XtAddEventHandler(drawing,EnterWindowMask|LeaveWindowMask,False,XCursesEnterLeaveWindow,NULL); -#if 0 - XtAddEventHandler(drawing,0,True,XCursesNonmaskable,NULL); -#endif - XtAddEventHandler(topLevel,0,True,XCursesNonmaskable,NULL); - /* - * Add input handler from display_sock (requests from curses program) - */ - XtAppAddInput( app_context, display_sock, (XtPointer)XtInputReadMask, XCursesProcessRequestsFromCurses, NULL ); - /* - * If there is a cursorBlink resource, start the Timeout event... - */ - if ( XCURSESCURSORBLINKRATE ) - { - XtAppAddTimeOut( app_context, XCURSESCURSORBLINKRATE, XCursesCursorBlink, NULL ); - } - /* - * Leave telling the curses process that it can start to here so that - * when the curses process makes a request, the Xcurses process can - * service the request... - */ - wait_value = CURSES_CHILD; - memcpy(wait_buf,(char *)&wait_value,sizeof(int)); - (void)write_socket(display_sock,wait_buf,sizeof(int)); - /* - * Realize the widget... - */ - XtRealizeWidget(topLevel); - /* - * Handle trapping of the WM_DELETE_WINDOW property... - */ - wm_atom[0] = XInternAtom(XtDisplay(topLevel),"WM_DELETE_WINDOW",False); -/* wm_atom[1] = XInternAtom(XtDisplay(topLevel),"WM_SAVE_YOURSELF",False); */ - /* (void)XSetWMProtocols(XtDisplay(topLevel),RootWindowOfScreen(XtScreen(topLevel)),&wm_delete_window_atom,1);*/ - /* (void)XSetWMProtocols(XtDisplay(topLevel),XCURSESWIN,&wm_delete_window_atom,1);*/ - (void)XSetWMProtocols(XtDisplay(topLevel),XtWindow(topLevel),wm_atom,1); /* was 2 with WM_SAVE_YOURSELF included */ - /* - * Create the Graphics Context for drawing. This MUST be done AFTER the - * associated widget has been realized... - */ #ifdef PDCDEBUG - say("before get_GC\n"); + say("before get_GC\n"); #endif - get_GC(XCURSESDISPLAY,XCURSESWIN,&normal_gc,XCURSESNORMALFONTINFO,COLOR_WHITE,COLOR_BLACK,FALSE); - if ( italic_font_valid ) - { - get_GC(XCURSESDISPLAY,XCURSESWIN,&italic_gc,XCURSESITALICFONTINFO,COLOR_WHITE,COLOR_BLACK,FALSE); - } - else - { - get_GC(XCURSESDISPLAY,XCURSESWIN,&italic_gc,XCURSESNORMALFONTINFO,COLOR_WHITE,COLOR_BLACK,FALSE); - } - get_GC(XCURSESDISPLAY,XCURSESWIN,&block_cursor_gc,XCURSESNORMALFONTINFO,COLOR_BLACK,COLOR_CURSOR,FALSE); - get_GC(XCURSESDISPLAY,XCURSESWIN,&rect_cursor_gc,XCURSESNORMALFONTINFO,COLOR_CURSOR,COLOR_BLACK,FALSE); - get_GC(XCURSESDISPLAY,XCURSESWIN,&border_gc,XCURSESNORMALFONTINFO,COLOR_BORDER,COLOR_BLACK,FALSE); - /* - XSetLineAttributes(XCURSESDISPLAY,normal_gc,2,LineSolid,CapButt,JoinMiter); - */ - XSetLineAttributes(XCURSESDISPLAY,rect_cursor_gc,2,LineSolid,CapButt,JoinMiter); - XSetLineAttributes(XCURSESDISPLAY,border_gc,XCURSESBORDERWIDTH,LineSolid,CapButt,JoinMiter); - /* - * Set the cursor for the application... - */ - XDefineCursor(XCURSESDISPLAY,XCURSESWIN,XCURSESPOINTER); - rmfrom.size = sizeof(Pixel); - rmto.size = sizeof(XColor); -#if XtSpecificationRelease > 4 - rmto.addr = (XPointer)&pointerforecolor; - rmfrom.addr = (XPointer)&(XCURSESPOINTERFORECOLOR); - XtConvertAndStore(drawing,XtRPixel,&rmfrom,XtRColor,&rmto); -#else - rmto.addr = (char *)&pointerforecolor; - rmfrom.addr = (char *)&(XCURSESPOINTERFORECOLOR); - XtConvert(drawing,XtRPixel,&rmfrom,XtRColor,&rmto); -#endif - rmfrom.size = sizeof(Pixel); - rmto.size = sizeof(XColor); -#if XtSpecificationRelease > 4 - rmfrom.addr = (XPointer)&(XCURSESPOINTERBACKCOLOR); - rmto.addr = (XPointer)&pointerbackcolor; - XtConvertAndStore(drawing,XtRPixel,&rmfrom,XtRColor,&rmto); -#else - rmfrom.addr = (char *)&(XCURSESPOINTERBACKCOLOR); - rmto.addr = (char *)&pointerbackcolor; - XtConvert(drawing,XtRPixel,&rmfrom,XtRColor,&rmto); -#endif - XRecolorCursor(XCURSESDISPLAY,XCURSESPOINTER,&pointerforecolor,&pointerbackcolor); - /* - * Convert the supplied compose key to a Keysym... - */ - compose_key = XStringToKeysym(XCURSESCOMPOSEKEY); - if (compose_key - && IsModifierKey(compose_key)) - { - register int i=0,j=0; - KeyCode *kcp; - XModifierKeymap *map; - KeyCode compose_keycode=XKeysymToKeycode(XCURSESDISPLAY,compose_key); - map = XGetModifierMapping(XCURSESDISPLAY); - kcp = map->modifiermap; - for (i=0;i<8;i++) - { - for (j=0;jmax_keypermod;j++,kcp++) - { - if (!*kcp) - continue; - if (compose_keycode == *kcp) - { - compose_mask = state_mask[i]; - break; - } - } - if (compose_mask) - break; - } - XFreeModifiermap(map); - } - /* fprintf(stderr,"COMPOSE KEY: %d %s STATE: %d\n",compose_key,XCURSESCOMPOSEKEY,compose_mask);*/ - -#ifdef FOREIGN - sleep(20); - if ((Xim = XOpenIM(XCURSESDISPLAY,NULL,NULL,NULL)) == NULL) - { - perror("Cannot open Input Method"); - kill(otherpid,SIGKILL); - shmdt((char *)SP); - shmdt((char *)Xcurscr); - shmctl(shmidSP,IPC_RMID,0); - shmctl(shmid_Xcurscr,IPC_RMID,0); - return(ERR); - } - XGetIMValues(Xim,XNQueryInputStyle, &im_supported_styles, NULL); - my_style = XIMPreeditNone|XIMStatusNone; - /* call XtCvtStringToFontSet ??? */ - if ((Xic = XCreateIC(Xim, XNInputStyle, my_style, - /* - - */ - NULL)) == NULL) - { - perror("ERROR: Cannot create input context"); - kill(otherpid,SIGKILL); - shmdt((char *)SP); - shmdt((char *)Xcurscr); - shmctl(shmidSP,IPC_RMID,0); - shmctl(shmid_Xcurscr,IPC_RMID,0); - return(ERR); - } - XFree(im_supported_styles); - XGetICValues(Xic, XNFilterEvents, &im_event_mask, NULL); - XtAddEventHandler(drawing,im_event_mask,False,NULL,NULL); - XSetICFocus(Xic); -#endif - /* - * Keep focus on Click-to-front window managers - * Change courtesy of Jean-Pierre Demailly - */ - wmhints.flags = InputHint; - wmhints.input = True; - XSetWMHints(XtDisplay(topLevel), XtWindow(topLevel), &wmhints); -#if 0 - XSetInputFocus(XtDisplay(topLevel), XtWindow(topLevel), - RevertToNone, CurrentTime); + get_GC(XCURSESDISPLAY, XCURSESWIN, &normal_gc, + XCURSESNORMALFONTINFO, COLOR_WHITE, COLOR_BLACK, FALSE); - XSetInputFocus(XtDisplay(drawing), XtWindow(drawing), - RevertToNone, CurrentTime); + if (italic_font_valid) + get_GC(XCURSESDISPLAY, XCURSESWIN, &italic_gc, + XCURSESITALICFONTINFO, COLOR_WHITE, COLOR_BLACK, + FALSE); + else + get_GC(XCURSESDISPLAY, XCURSESWIN, &italic_gc, + XCURSESNORMALFONTINFO, COLOR_WHITE, COLOR_BLACK, + FALSE); + + get_GC(XCURSESDISPLAY, XCURSESWIN, &block_cursor_gc, + XCURSESNORMALFONTINFO, COLOR_BLACK, COLOR_CURSOR, FALSE); + + get_GC(XCURSESDISPLAY, XCURSESWIN, &rect_cursor_gc, + XCURSESNORMALFONTINFO, COLOR_CURSOR, COLOR_BLACK, FALSE); + + get_GC(XCURSESDISPLAY, XCURSESWIN, &border_gc, + XCURSESNORMALFONTINFO, COLOR_BORDER, COLOR_BLACK, FALSE); + + XSetLineAttributes(XCURSESDISPLAY, rect_cursor_gc, 2, LineSolid, + CapButt, JoinMiter); + + XSetLineAttributes(XCURSESDISPLAY, border_gc, + XCURSESBORDERWIDTH, LineSolid, CapButt, JoinMiter); + + /* Set the cursor for the application */ + + XDefineCursor(XCURSESDISPLAY, XCURSESWIN, XCURSESPOINTER); + rmfrom.size = sizeof(Pixel); + rmto.size = sizeof(XColor); + +#if XtSpecificationRelease > 4 + rmto.addr = (XPointer)&pointerforecolor; + rmfrom.addr = (XPointer)&(XCURSESPOINTERFORECOLOR); + XtConvertAndStore(drawing, XtRPixel, &rmfrom, XtRColor, &rmto); +#else + rmto.addr = (char *)&pointerforecolor; + rmfrom.addr = (char *)&(XCURSESPOINTERFORECOLOR); + XtConvert(drawing, XtRPixel, &rmfrom, XtRColor, &rmto); #endif - /* - * Wait for events... - */ - XtAppMainLoop(app_context); - return(OK); /* won't get here */ + + rmfrom.size = sizeof(Pixel); + rmto.size = sizeof(XColor); + +#if XtSpecificationRelease > 4 + rmfrom.addr = (XPointer)&(XCURSESPOINTERBACKCOLOR); + rmto.addr = (XPointer)&pointerbackcolor; + XtConvertAndStore(drawing, XtRPixel, &rmfrom, XtRColor, &rmto); +#else + rmfrom.addr = (char *)&(XCURSESPOINTERBACKCOLOR); + rmto.addr = (char *)&pointerbackcolor; + XtConvert(drawing, XtRPixel, &rmfrom, XtRColor, &rmto); +#endif + + XRecolorCursor(XCURSESDISPLAY, XCURSESPOINTER, + &pointerforecolor, &pointerbackcolor); + + /* Convert the supplied compose key to a Keysym */ + + compose_key = XStringToKeysym(XCURSESCOMPOSEKEY); + + if (compose_key && IsModifierKey(compose_key)) + { + int i, j; + KeyCode *kcp; + XModifierKeymap *map; + KeyCode compose_keycode = + XKeysymToKeycode(XCURSESDISPLAY, compose_key); + + map = XGetModifierMapping(XCURSESDISPLAY); + kcp = map->modifiermap; + + for (i = 0; i < 8; i++) + { + for (j = 0; j < map->max_keypermod; j++, kcp++) + { + if (!*kcp) + continue; + + if (compose_keycode == *kcp) + { + compose_mask = state_mask[i]; + break; + } + } + + if (compose_mask) + break; + } + + XFreeModifiermap(map); + } + +#ifdef FOREIGN + sleep(20); + + if ((Xim = XOpenIM(XCURSESDISPLAY,NULL,NULL,NULL)) == NULL) + { + perror("Cannot open Input Method"); + kill(otherpid, SIGKILL); + shmdt((char *)SP); + shmdt((char *)Xcurscr); + shmctl(shmidSP, IPC_RMID, 0); + shmctl(shmid_Xcurscr, IPC_RMID, 0); + return ERR; + } + + XGetIMValues(Xim,XNQueryInputStyle, &im_supported_styles, NULL); + my_style = XIMPreeditNone | XIMStatusNone; + + if ((Xic = XCreateIC(Xim, XNInputStyle, my_style, NULL)) == NULL) + { + perror("ERROR: Cannot create input context"); + kill(otherpid, SIGKILL); + shmdt((char *)SP); + shmdt((char *)Xcurscr); + shmctl(shmidSP, IPC_RMID, 0); + shmctl(shmid_Xcurscr, IPC_RMID, 0); + return ERR; + } + + XFree(im_supported_styles); + XGetICValues(Xic, XNFilterEvents, &im_event_mask, NULL); + XtAddEventHandler(drawing, im_event_mask, False, NULL, NULL); + XSetICFocus(Xic); +#endif + + /* Keep focus on Click-to-front window managers. Change courtesy + of Jean-Pierre Demailly. */ + + wmhints.flags = InputHint; + wmhints.input = True; + + XSetWMHints(XtDisplay(topLevel), XtWindow(topLevel), &wmhints); + + /* Wait for events */ + + XtAppMainLoop(app_context); + return OK; /* won't get here */ } + /***********************************************************************/ #ifdef HAVE_PROTO RETSIGTYPE XCursesSignalHandler(int signo) @@ -938,51 +948,61 @@ int signo; #endif /***********************************************************************/ { - char buf[10]; - int flag = CURSES_EXIT; + char buf[10]; + int flag = CURSES_EXIT; - PDC_LOG(("%s:XCursesSignalHandler() - called: %d\n",(XCursesProcess)?" X":"CURSES",signo)); + PDC_LOG(("%s:XCursesSignalHandler() - called: %d\n", XCLOGMSG, signo)); + + /* Patch by: Georg Fuchs */ + + XCursesSetSignal(signo, XCursesSignalHandler); - /* - * Patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 04-Dec-1998 - */ - XCursesSetSignal(signo,XCursesSignalHandler); #ifdef SIGTSTP - if (signo == SIGTSTP) { pause(); return; } + if (signo == SIGTSTP) + { + pause(); + return; + } #endif #ifdef SIGCONT - if (signo == SIGCONT) return; + if (signo == SIGCONT) + return; #endif #ifdef SIGCLD - if (signo == SIGCLD) return; + if (signo == SIGCLD) + return; #endif #ifdef SIGTTIN - if (signo == SIGTTIN) return; + if (signo == SIGTTIN) + return; #endif #ifdef SIGWINCH - if (signo == SIGWINCH) return; + if (signo == SIGWINCH) + return; #endif - /* - * End of patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 04-Dec-1998 - */ - XCursesSetSignal(signo,SIG_IGN); - /* - * Send a CURSES_EXIT to myself... - */ - memcpy(buf,(char *)&flag,sizeof(int)); - if (write_socket(exit_sock,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(7,signo,"exitting from XCursesSignalHandler"); + + /* End of patch by: Georg Fuchs */ + + XCursesSetSignal(signo, SIG_IGN); + + /* Send a CURSES_EXIT to myself */ + + memcpy(buf, (char *)&flag, sizeof(int)); + + if (write_socket(exit_sock, buf, sizeof(int)) < 0) + XCursesExitXCursesProcess(7, signo, + "exiting from XCursesSignalHandler"); } /***********************************************************************/ #ifdef HAVE_PROTO -void XCursesRequestorCallbackForGetSelection(Widget w,XtPointer data, Atom *selection, - Atom *type, XtPointer value, - unsigned long *length, int *format) +void XCursesRequestorCallbackForGetSelection(Widget w, XtPointer data, + Atom *selection, Atom *type, + XtPointer value, + unsigned long *length, int *format) #else -void XCursesRequestorCallbackForGetSelection(w,data,selection,type,value,length,format) +void XCursesRequestorCallbackForGetSelection(w, data, selection, type, + value, length, format) Widget w; XtPointer data; Atom *selection; @@ -993,43 +1013,50 @@ int *format; #endif /***********************************************************************/ { - int rc; - char buf[12]; /* big enough for 2 integers */ - char *string=(char *)value; + int rc; + char buf[12]; /* big enough for 2 integers */ + char *string = (char *)value; - PDC_LOG(("%s:XCursesRequestorCallbackForSelection() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesRequestorCallbackForSelection() - called\n", + XCLOGMSG)); - if ((value == NULL) && (*length == 0)) - { - rc = PDC_CLIP_EMPTY; - memcpy(buf,(char *)&rc,sizeof(int)); - if (write_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesRequestorCallbackForGetSelection"); - return; - } - /* - * Here all is OK, send PDC_CLIP_SUCCESS, then length, then contents - */ - rc = PDC_CLIP_SUCCESS; - memcpy(buf,(char *)&rc,sizeof(int)); - if (write_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesRequestorCallbackForGetSelection"); + if ((value == NULL) && (*length == 0)) + { + rc = PDC_CLIP_EMPTY; + memcpy(buf, (char *)&rc, sizeof(int)); - rc = *(length); - memcpy(buf,(char *)&rc,sizeof(int)); - if (write_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesRequestorCallbackForGetSelection"); + if (write_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitXCursesProcess(4, SIGKILL, + "exiting from XCursesRequestorCallbackForGetSelection"); + return; + } - if (write_socket(display_sock,string,*length) < 0) - XCursesExitXCursesProcess(4,SIGKILL,"exiting from XCursesRequestorCallbackForGetSelection"); + /* Here all is OK, send PDC_CLIP_SUCCESS, then length, then + contents */ - return; + rc = PDC_CLIP_SUCCESS; + memcpy(buf, (char *)&rc, sizeof(int)); + if (write_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitXCursesProcess(4, SIGKILL, + "exiting from XCursesRequestorCallbackForGetSelection"); + + rc = *(length); + memcpy(buf, (char *)&rc, sizeof(int)); + if (write_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitXCursesProcess(4, SIGKILL, + "exiting from XCursesRequestorCallbackForGetSelection"); + + if (write_socket(display_sock, string, *length) < 0) + XCursesExitXCursesProcess(4, SIGKILL, + "exiting from XCursesRequestorCallbackForGetSelection"); } + /***********************************************************************/ #ifdef HAVE_PROTO -void XCursesStructureNotify(Widget w,XtPointer client_data,XEvent *event,Boolean *continue_to_dispatch) +void XCursesStructureNotify(Widget w, XtPointer client_data, XEvent *event, + Boolean *continue_to_dispatch) #else -void XCursesStructureNotify(w,client_data,event,continue_to_dispatch) +void XCursesStructureNotify(w, client_data, event, continue_to_dispatch) Widget w; XtPointer client_data; XEvent *event; @@ -1037,57 +1064,50 @@ Boolean *continue_to_dispatch; #endif /***********************************************************************/ { - PDC_LOG(("%s:XCursesStructureNotify called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesStructureNotify called\n", XCLOGMSG)); -#if 0 -printf("Notify: %d\n",event->type); -#endif - switch(event->type) - { - case ConfigureNotify: + switch(event->type) + { + case ConfigureNotify: #ifdef PDCDEBUG - say("ConfigureNotify received\n"); + say("ConfigureNotify received\n"); #endif - /* window has been resized, change width and - * height to send to place_text and place_graphics - * in next Expose. - * Also will need to kill (SIGWINCH) curses process if screen - * size changes - */ - resizeXCursesWindowWidth = (event->xconfigure.width); - resizeXCursesWindowHeight = (event->xconfigure.height); - - after_first_curses_request = False; + /* Window has been resized, change width and height to + send to place_text and place_graphics in next Expose. + Also will need to kill (SIGWINCH) curses process if + screen size changes. */ + + resizeXCursesWindowWidth = (event->xconfigure.width); + resizeXCursesWindowHeight = (event->xconfigure.height); + + after_first_curses_request = False; + #ifdef SIGWINCH -# ifdef BEFORE_CHANGE_BY_G_FUCHS -/* - * Patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 - */ -# else - SP->resized = 1; -# endif - kill(otherpid,SIGWINCH); + SP->resized = 1; + + kill(otherpid, SIGWINCH); #endif - XCursesSendKeyToCurses( (unsigned long)KEY_RESIZE, NULL ); - break; - case MapNotify: + XCursesSendKeyToCurses((unsigned long)KEY_RESIZE, NULL); + break; + + case MapNotify: #ifdef PDCDEBUG - say("MapNotify received\n"); + say("MapNotify received\n"); #endif - ReceivedMapNotify=1; - /* - * Draw the window border - */ - if (XCURSESBORDERWIDTH) - XDrawRectangle(XCURSESDISPLAY,XCURSESWIN,border_gc, - (XCURSESBORDERWIDTH/2),(XCURSESBORDERWIDTH/2), - (XCursesWindowWidth-XCURSESBORDERWIDTH), - (XCursesWindowHeight-XCURSESBORDERWIDTH)); - break; - default: - PDC_LOG(("%s:XCursesStructureNotify - unknown event %d\n",(XCursesProcess)?" X":"CURSES",event->type)); - break; - } - return; + ReceivedMapNotify = 1; + + /* Draw the window border */ + + if (XCURSESBORDERWIDTH) + XDrawRectangle(XCURSESDISPLAY, XCURSESWIN, + border_gc, XCURSESBORDERWIDTH / 2, + XCURSESBORDERWIDTH / 2, + XCursesWindowWidth - XCURSESBORDERWIDTH, + XCursesWindowHeight - XCURSESBORDERWIDTH); + break; + + default: + PDC_LOG(("%s:XCursesStructureNotify - unknown event %d\n", + XCLOGMSG, event->type)); + } } diff --git a/x11/process/x11.h b/x11/process/x11.h index b635656b..e1d7e647 100644 --- a/x11/process/x11.h +++ b/x11/process/x11.h @@ -1,41 +1,51 @@ #ifdef HAVE_PROTO + void dummy_function(void); -void get_GC(Display *,Window, GC *, XFontStruct *,int ,int, bool ); -void makeXY(int ,int ,int ,int ,int *,int *); +void get_GC(Display *, Window, GC *, XFontStruct *, int, int, bool); +void makeXY(int, int, int, int, int *, int *); int get_colors(void); void start_event_handler(void); -int XCursesTransformLine(int ,int ,chtype ,int ,int,int,char *); -int XCursesDisplayText(chtype *, int, int, int,bool); -void XCursesDisplayScreen(bool); -void XCursesDisplayCursor( int ,int ,int ,int ); -void XCursesStructureNotify(Widget,XtPointer ,XEvent *,Boolean *); -void XCursesEnterLeaveWindow(Widget,XtPointer ,XEvent *,Boolean *); -void XCursesPasteSelection(Widget,XButtonEvent *); -void XCursesHandleString(Widget,XEvent *,String *,Cardinal *); -void XCursesKeyPress(Widget,XEvent *,String *,Cardinal *); -void XCursesModifierPress(Widget,XEvent *,String *,Cardinal *); -void XCursesButton(Widget,XEvent *,String *,Cardinal *); -Boolean XCursesConvertProc(Widget,Atom *,Atom *,Atom *,XtPointer *,unsigned long *,int *); -void XCursesLoseOwnership(Widget,Atom *); -void XCursesRequestorCallbackForPaste(Widget,XtPointer,Atom *,Atom *,XtPointer,unsigned long *,int *); -void XCursesRequestorCallbackForGetSelection(Widget,XtPointer,Atom *,Atom *,XtPointer,unsigned long *,int *); -RETSIGTYPE XCursesSignalHandler(int); -void XCursesExitXCursesProcess(int,int,char *); -void SelectionOff(void); -void SelectionOn(int,int); -void SelectionExtend(int,int); -void SelectionSet( void ); -int write_socket(int,char *,int); -int read_socket(int,char *,int); -int XCursesSetupX(char *display_name,int argc, char *argv[]); +int XCursesTransformLine(int, int, chtype, int, int, int, char *); +int XCursesDisplayText(chtype *, int, int, int, bool); +void XCursesDisplayScreen(bool); +void XCursesDisplayCursor(int, int, int, int); +void XCursesStructureNotify(Widget, XtPointer, XEvent *, Boolean *); +void XCursesEnterLeaveWindow(Widget, XtPointer, XEvent *, Boolean *); +void XCursesPasteSelection(Widget, XButtonEvent *); +void XCursesHandleString(Widget, XEvent *, String *, Cardinal *); +void XCursesKeyPress(Widget, XEvent *, String *, Cardinal *); +void XCursesModifierPress(Widget, XEvent *, String *, Cardinal *); +void XCursesButton(Widget, XEvent *, String *, Cardinal *); +Boolean XCursesConvertProc(Widget, Atom *, Atom *, Atom *, XtPointer *, + unsigned long *, int *); +void XCursesLoseOwnership(Widget, Atom *); +void XCursesRequestorCallbackForPaste(Widget, XtPointer, Atom *, Atom *, + XtPointer, unsigned long *, int *); +void XCursesRequestorCallbackForGetSelection(Widget, XtPointer, Atom *, Atom *, + XtPointer, unsigned long *, int *); +RETSIGTYPE XCursesSignalHandler(int); +void XCursesExitXCursesProcess(int, int, char *); + +void SelectionOff(void); +void SelectionOn(int, int); +void SelectionExtend(int, int); +void SelectionSet(void); + +int write_socket(int, char *, int); +int read_socket(int, char *, int); + +int XCursesSetupX(char *display_name, int argc, char *argv[]); RETSIGTYPE XCursesSigwinchHandler(int signo); + #else + void dummy_function(void); void get_GC(); void makeXY(); int get_colors(); void start_event_handler(); + int XCursesTransformLine(); int XCursesDisplayText(); void XCursesDisplayScreen(); @@ -53,6 +63,7 @@ void XCursesRequestorCallbackForPaste(); void XCursesRequestorCallbackForGetSelection(); RETSIGTYPE XCursesSignalHandler(); void XCursesExitXCursesProcess(); + void SelectionOff(); void SelectionOn(); void SelectionExtend(); @@ -60,8 +71,10 @@ void SelectionSet(); int write_socket(); int read_socket(); + int XCursesSetupX(); RETSIGTYPE XCursesSigwinchHandler(); + #endif #ifdef _HPUX_SOURCE @@ -69,6 +82,7 @@ RETSIGTYPE XCursesSigwinchHandler(); #else # define FD_SET_CAST fd_set * #endif + extern fd_set readfds; extern fd_set writefds; extern struct timeval socket_timeout; diff --git a/x11/process/x11common.c b/x11/process/x11common.c index 1ef26d09..8492d04e 100644 --- a/x11/process/x11common.c +++ b/x11/process/x11common.c @@ -22,18 +22,19 @@ */ #include "pdcx11.h" -/* - * Variables specific to process port - */ + +/* Variables specific to process port */ + unsigned char *Xcurscr; -int XCursesProcess=1; + +int XCursesProcess = 1; int shmidSP; int shmid_Xcurscr; int shmkeySP; int shmkey_Xcurscr; int otherpid; -int XCursesLINES=24; -int XCursesCOLS=80; +int XCursesLINES = 24; +int XCursesCOLS = 80; int display_sock; int key_sock; int display_sockets[2]; @@ -42,102 +43,88 @@ int exit_sock; fd_set readfds; fd_set writefds; + struct timeval socket_timeout; /***********************************************************************/ #ifdef HAVE_PROTO -int write_socket(int sock_num,char *buf,int len) +int write_socket(int sock_num, char *buf, int len) #else -int write_socket(sock_num,buf,len) +int write_socket(sock_num, buf, len) int sock_num; char *buf; int len; #endif /***********************************************************************/ { - int start=0,length=len,rc; + int start = 0, rc; - PDC_LOG(("%s:write_socket called: sock_num %d len %d\n",(XCursesProcess)?" X":"CURSES",sock_num,len)); + PDC_LOG(("%s:write_socket called: sock_num %d len %d\n", + XCLOGMSG, sock_num, len)); #ifdef MOUSE_DEBUG1 -if (sock_num == key_sock) - printf("%s:write_socket(key) len: %d\n",(XCursesProcess)?" X":"CURSES",len); + if (sock_num == key_sock) + printf("%s:write_socket(key) len: %d\n", XCLOGMSG, len); #endif - while(1) - { - rc = write(sock_num,buf+start,length); - if (rc < 0 - || rc == length) - return(rc); - length -= rc; - start = rc; - } + while(1) + { + rc = write(sock_num, buf + start, len); + + if (rc < 0 || rc == len) + return rc; + + len -= rc; + start = rc; + } } + /***********************************************************************/ #ifdef HAVE_PROTO -int read_socket(int sock_num,char *buf,int len) +int read_socket(int sock_num, char *buf, int len) #else -int read_socket(sock_num,buf,len) +int read_socket(sock_num, buf, len) int sock_num; char *buf; int len; #endif /***********************************************************************/ { - int start=0,length=len,rc; + int start = 0, length = len, rc; - PDC_LOG(("%s:read_socket called: sock_num %d len %d\n",(XCursesProcess)?" X":"CURSES",sock_num,len)); + PDC_LOG(("%s:read_socket called: sock_num %d len %d\n", + XCLOGMSG, sock_num, len)); - while(1) - { - rc = read(sock_num,buf+start,length); -#ifdef MOUSE_DEBUG1 - if (sock_num == key_sock) - printf("%s:read_socket(key) rc %d errno %d resized: %d\n",(XCursesProcess)?" X":"CURSES", - rc,errno,SP->resized); -#endif - if (rc < 0 - && sock_num == key_sock - && errno == EINTR -#ifdef BEFORE_CHANGE_BY_G_FUCHS -/* - * Patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 - */ - && SP->resized == TRUE) - { -#ifdef MOUSE_DEBUG1 - printf("%s:continuing\n",(XCursesProcess)?" X":"CURSES"); -#endif - rc = 0; -#else - && SP->resized != FALSE) - { -#ifdef MOUSE_DEBUG1 - printf("%s:continuing\n",(XCursesProcess)?" X":"CURSES"); -#endif - rc = 0; - if (SP->resized > 1) - SP->resized = TRUE; - else - SP->resized = FALSE; -#endif - memcpy(buf,(char *)&rc,sizeof(int)); - return(0); /* must be >= 0 to avoid error */ - } + while(1) + { + rc = read(sock_num, buf + start, length); -#ifdef BEFORE_CHANGE_BY_G_FUCHS -/* - * Patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 - */ - if (rc < 0 -#else - if (rc <= 0 +#ifdef MOUSE_DEBUG1 + if (sock_num == key_sock) + printf("%s:read_socket(key) rc %d errno %d resized: %d\n", + XCLOGMSG, rc, errno, SP->resized); #endif - || rc == length) - return(rc); - length -= rc; - start = rc; - } + if (rc < 0 && sock_num == key_sock && errno == EINTR + && SP->resized != FALSE) + { +#ifdef MOUSE_DEBUG1 + printf("%s:continuing\n", XCLOGMSG); +#endif + rc = 0; + + if (SP->resized > 1) + SP->resized = TRUE; + else + SP->resized = FALSE; + + memcpy(buf, (char *)&rc, sizeof(int)); + + return 0; + } + + if (rc <= 0 || rc == length) + return rc; + + length -= rc; + start = rc; + } } diff --git a/x11/process/x11curses.c b/x11/process/x11curses.c index 8a50caa6..152f9c05 100644 --- a/x11/process/x11curses.c +++ b/x11/process/x11curses.c @@ -21,10 +21,8 @@ *************************************************************************** */ -/* - * This file contains functions that are called by the "curses" process; - * ie the parent process. - */ +/* This file contains functions that are called by the "curses" process; + i.e., the parent process. */ #include "pdcx11.h" extern AppData app_data; @@ -40,71 +38,85 @@ static void XCursesExitCursesProcess(); int XCursesResizeScreen(int nlines, int ncols) #else int XCursesResizeScreen(nlines, ncols) -int nlines,ncols; +int nlines, ncols; #endif /***********************************************************************/ { - PDC_LOG(("%s:XCursesResizeScreen() - called: Lines: %d Cols: %d\n",(XCursesProcess)?" X":"CURSES",nlines,ncols)); + PDC_LOG(("%s:XCursesResizeScreen() - called: Lines: %d Cols: %d\n", + XCLOGMSG, nlines, ncols)); - shmdt((char *)Xcurscr); - XCursesInstructAndWait(CURSES_RESIZE); - if ((shmid_Xcurscr = shmget(shmkey_Xcurscr,SP->XcurscrSize+XCURSESSHMMIN,0700)) < 0) - { - perror("Cannot allocate shared memory for curscr"); - kill(otherpid,SIGKILL); - return(ERR); - } - XCursesLINES = SP->lines; - XCursesCOLS = SP->cols; + shmdt((char *)Xcurscr); + XCursesInstructAndWait(CURSES_RESIZE); - PDC_LOG(("%s:shmid_Xcurscr %d shmkey_Xcurscr %d SP->lines %d SP->cols %d\n",(XCursesProcess)?" X":"CURSES",shmid_Xcurscr,shmkey_Xcurscr,SP->lines,SP->cols)); + if ((shmid_Xcurscr = shmget(shmkey_Xcurscr, + SP->XcurscrSize + XCURSESSHMMIN, 0700)) < 0) + { + perror("Cannot allocate shared memory for curscr"); + kill(otherpid, SIGKILL); + return ERR; + } - Xcurscr = (unsigned char*)shmat(shmid_Xcurscr,0,0); - atrtab = (unsigned char *)(Xcurscr+XCURSCR_ATRTAB_OFF); - SP->resized=FALSE; - return(OK); + XCursesLINES = SP->lines; + XCursesCOLS = SP->cols; + + PDC_LOG(("%s:shmid_Xcurscr %d shmkey_Xcurscr %d SP->lines %d SP->cols %d\n", + XCLOGMSG, shmid_Xcurscr, shmkey_Xcurscr, SP->lines, SP->cols)); + + Xcurscr = (unsigned char*)shmat(shmid_Xcurscr, 0, 0); + atrtab = (unsigned char *)(Xcurscr + XCURSCR_ATRTAB_OFF); + + SP->resized = FALSE; + + return OK; } + /***********************************************************************/ #ifdef HAVE_PROTO -int XCurses_display_cursor(int oldrow, int oldcol, int newrow,int newcol,int visibility) +int XCurses_display_cursor(int oldrow, int oldcol, int newrow, int newcol, + int visibility) #else -int XCurses_display_cursor(oldrow,oldcol,newrow,newcol,visibility) -int oldrow,oldcol,newrow,newcol,visibility; +int XCurses_display_cursor(oldrow, oldcol, newrow, newcol, visibility) +int oldrow, oldcol, newrow, newcol, visibility; #endif /***********************************************************************/ { - char buf[30]; - int idx,pos; + char buf[30]; + int idx, pos; - PDC_LOG(("%s:XCurses_display_cursor() - called: NEW row %d col %d, vis %d\n", (XCursesProcess)?"X":"CURSES",newrow,newcol,visibility)); + PDC_LOG(("%s:XCurses_display_cursor() - called: NEW row %d col %d, vis %d\n", + XCLOGMSG, newrow, newcol, visibility)); - if ( visibility == -1 ) - { - /* - * Only send the CURSES_DISPLAY_CURSOR message, no data - */ - idx = CURSES_DISPLAY_CURSOR; - memcpy(buf,(char *)&idx,sizeof(int)); - idx = sizeof(int); - } - else - { - idx = CURSES_CURSOR; - memcpy(buf,(char *)&idx,sizeof(int)); - idx = sizeof(int); - pos = oldrow + (oldcol << 8); - memcpy(buf+idx,(char *)&pos,sizeof(int)); - idx += sizeof(int); - pos = newrow + (newcol << 8); - memcpy(buf+idx,(char *)&pos,sizeof(int)); - idx += sizeof(int); - } + if (visibility == -1) + { + /* Only send the CURSES_DISPLAY_CURSOR message, no data */ - if (write_socket(display_sock,buf,idx) < 0) - XCursesExitCursesProcess(1,"exitting from XCurses_display_cursor"); + idx = CURSES_DISPLAY_CURSOR; + memcpy(buf, (char *)&idx, sizeof(int)); + idx = sizeof(int); + } + else + { + idx = CURSES_CURSOR; + memcpy(buf, (char *)&idx, sizeof(int)); - return(OK); + idx = sizeof(int); + pos = oldrow + (oldcol << 8); + memcpy(buf + idx, (char *)&pos, sizeof(int)); + + idx += sizeof(int); + pos = newrow + (newcol << 8); + memcpy(buf + idx, (char *)&pos, sizeof(int)); + + idx += sizeof(int); + } + + if (write_socket(display_sock, buf, idx) < 0) + XCursesExitCursesProcess(1, + "exitting from XCurses_display_cursor"); + + return OK; } + /***********************************************************************/ #ifdef HAVE_PROTO void XCurses_set_title(char *title) @@ -114,25 +126,26 @@ char *title; #endif /***********************************************************************/ { - char buf[30]; - int idx,len; + char buf[30]; + int idx, len; - PDC_LOG(("%s:XCurses_set_title() - called: TITLE: %s\n", (XCursesProcess)?"X":"CURSES",title)); + PDC_LOG(("%s:XCurses_set_title() - called: TITLE: %s\n", + XCLOGMSG, title)); - idx = CURSES_TITLE; - memcpy(buf,(char *)&idx,sizeof(int)); - idx = sizeof(int); - len = strlen(title)+1; /* write nul character */ - memcpy(buf+idx,(char *)&len,sizeof(int)); - idx += sizeof(int); + idx = CURSES_TITLE; + memcpy(buf, (char *)&idx, sizeof(int)); - if (write_socket(display_sock,buf,idx) < 0) - XCursesExitCursesProcess(1,"exiting from XCurses_set_title"); + idx = sizeof(int); + len = strlen(title) + 1; /* write nul character */ + memcpy(buf + idx, (char *)&len, sizeof(int)); - if (write_socket(display_sock,title,len) < 0) - XCursesExitCursesProcess(1,"exiting from XCurses_set_title"); + idx += sizeof(int); - return; + if (write_socket(display_sock, buf, idx) < 0) + XCursesExitCursesProcess(1, "exiting from XCurses_set_title"); + + if (write_socket(display_sock, title, len) < 0) + XCursesExitCursesProcess(1, "exiting from XCurses_set_title"); } /***********************************************************************/ @@ -143,93 +156,93 @@ int XCurses_refresh_scrollbar() #endif /***********************************************************************/ { - char buf[30]; - int idx; + char buf[30]; + int idx; - PDC_LOG(("%s:XCurses_refresh_scrollbar() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCurses_refresh_scrollbar() - called\n", XCLOGMSG)); - idx = CURSES_REFRESH_SCROLLBAR; - memcpy(buf,(char *)&idx,sizeof(int)); - idx = sizeof(int); + idx = CURSES_REFRESH_SCROLLBAR; + memcpy(buf, (char *)&idx, sizeof(int)); + idx = sizeof(int); - if (write_socket(display_sock,buf,idx) < 0) - XCursesExitCursesProcess(1,"exiting from XCurses_refresh_scrollbar"); + if (write_socket(display_sock, buf, idx) < 0) + XCursesExitCursesProcess(1, + "exiting from XCurses_refresh_scrollbar"); - return(OK); + return OK; } /***********************************************************************/ #ifdef HAVE_PROTO -int XCurses_rawgetch( int delaytenths) +int XCurses_rawgetch(int delaytenths) #else -int XCurses_rawgetch( delaytenths ) +int XCurses_rawgetch(delaytenths) int delaytenths; #endif /***********************************************************************/ { - unsigned long newkey=0; - int key=0; - char buf[100]; /* big enough for MOUSE_STATUS struct */ + unsigned long newkey = 0; + int key = 0; + char buf[100]; /* big enough for MOUSE_STATUS struct */ - PDC_LOG(("%s:XCurses_rawgetch() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCurses_rawgetch() - called\n", XCLOGMSG)); - while(1) - { - if ( delaytenths && !XCurses_kbhit() ) - { - key = -1; - } - else - { - if (read_socket(key_sock,buf,sizeof(unsigned long)) < 0) - XCursesExitCursesProcess(2,"exiting from XCurses_rawchar"); /* what else ?? */ - memcpy((char *)&newkey,buf,sizeof(unsigned long)); - pdc_key_modifier = (newkey >> 24) & 0xFF; /*(sizeof(unsigned long) - sizeof(unsigned char)); */ - key = (int)(newkey & 0x00FFFFFF); - } -#if 0 - printf("%s:reading %d mod %ld\n",(XCursesProcess)?" X":"CURSES",key,pdc_key_modifier); -#endif - if (key == KEY_MOUSE) - { - if (read_socket(key_sock,buf,sizeof(MOUSE_STATUS)) < 0) - XCursesExitCursesProcess(2,"exitting from XCurses_rawchar"); /* what else ?? */ - memcpy((char *)&Trapped_Mouse_status,buf,sizeof(MOUSE_STATUS)); - /* - * Check if the mouse has been clicked on a slk area. If the return - * value is > 0 (indicating the - * label number, return with the KEY_F(key) value. - */ -/*fprintf(stderr,"%d %d %x\n",TRAPPED_MOUSE_Y_POS,TRAPPED_MOUSE_X_POS,SP->slk_winptr);*/ - if ((newkey = PDC_mouse_in_slk(TRAPPED_MOUSE_Y_POS,TRAPPED_MOUSE_X_POS))) - { - if (TRAPPED_BUTTON_STATUS(1) & BUTTON_PRESSED) - { - key = KEY_F(newkey); - break; - } - } - break; + while(1) + { + if (delaytenths && !XCurses_kbhit()) + key = -1; + else + { + if (read_socket(key_sock, buf, sizeof(unsigned long)) < 0) + XCursesExitCursesProcess(2, + "exiting from XCurses_rawchar"); + + memcpy((char *)&newkey, buf, sizeof(unsigned long)); + pdc_key_modifier = (newkey >> 24) & 0xFF; + key = (int)(newkey & 0x00FFFFFF); + } + + if (key == KEY_MOUSE) + { + if (read_socket(key_sock, buf, sizeof(MOUSE_STATUS)) < 0) + XCursesExitCursesProcess(2, + "exiting from XCurses_rawchar"); + + memcpy((char *)&Trapped_Mouse_status, buf, + sizeof(MOUSE_STATUS)); + + /* Check if the mouse has been clicked on a slk area. If + the return value is > 0 (indicating the label number), + return with the KEY_F(key) value. */ + + if ((newkey = PDC_mouse_in_slk(TRAPPED_MOUSE_Y_POS, + TRAPPED_MOUSE_X_POS))) + { + if (TRAPPED_BUTTON_STATUS(1) & BUTTON_PRESSED) + { + key = KEY_F(newkey); + break; + } + } + + break; #ifdef MOUSE_DEBUG - printf("rawgetch-x: %d y: %d Mouse status: %x\n", - MOUSE_X_POS, - MOUSE_Y_POS, - Mouse_status.changes); - printf("rawgetch-Button1: %x Button2: %x Button3: %x\n", - BUTTON_STATUS(1), - BUTTON_STATUS(2), - BUTTON_STATUS(3)); + printf("rawgetch-x: %d y: %d Mouse status: %x\n", + MOUSE_X_POS, MOUSE_Y_POS, Mouse_status.changes); + printf("rawgetch-Button1: %x Button2: %x Button3: %x\n", + BUTTON_STATUS(1), BUTTON_STATUS(2), BUTTON_STATUS(3)); #endif - } - else - break; - } + } + else + break; + } - PDC_LOG(("%s:XCurses_rawgetch() - key %d returned\n",(XCursesProcess)?" X":"CURSES",key)); + PDC_LOG(("%s:XCurses_rawgetch() - key %d returned\n", XCLOGMSG, key)); - return(key); + return key; } + /***********************************************************************/ #ifdef HAVE_PROTO int XCurses_get_input_fd(void) @@ -238,8 +251,9 @@ int XCurses_get_input_fd() #endif /***********************************************************************/ { - PDC_LOG(("%s:XCurses_get_input_fd() - called\n",(XCursesProcess)?" X":"CURSES")); - PDC_LOG(("%s:XCurses_get_input_fd() - returning %i\n",(XCursesProcess)?" X":"CURSES",key_sock)); + PDC_LOG(("%s:XCurses_get_input_fd() - called\n", XCLOGMSG)); + PDC_LOG(("%s:XCurses_get_input_fd() - returning %i\n", XCLOGMSG, + key_sock)); return key_sock; } @@ -252,24 +266,29 @@ bool XCurses_kbhit() #endif /***********************************************************************/ { - int s; + int s; - PDC_LOG(("%s:XCurses_kbhit() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCurses_kbhit() - called\n", XCLOGMSG)); - /* - * Is something ready to be read on the socket ? Must be a key. - */ - FD_ZERO( &readfds ); - FD_SET( key_sock, &readfds ); - if ( ( s = select ( FD_SETSIZE, (FD_SET_CAST)&readfds, NULL, NULL, &socket_timeout ) ) < 0 ) - XCursesExitCursesProcess(3,"child - exiting from XCurses_kbhit select failed"); - - PDC_LOG(("%s:XCurses_kbhit() - returning %s\n",(XCursesProcess)?" X":"CURSES",(s == 0) ? "FALSE" : "TRUE")); + /* Is something ready to be read on the socket ? Must be a key. */ - if ( s == 0 ) - return(FALSE); - return(TRUE); + FD_ZERO(&readfds); + FD_SET(key_sock, &readfds); + + if ((s = select(FD_SETSIZE, (FD_SET_CAST)&readfds, NULL, + NULL, &socket_timeout)) < 0) + XCursesExitCursesProcess(3, + "child - exiting from XCurses_kbhit select failed"); + + PDC_LOG(("%s:XCurses_kbhit() - returning %s\n", XCLOGMSG, + (s == 0) ? "FALSE" : "TRUE")); + + if (s == 0) + return FALSE; + + return TRUE; } + /***********************************************************************/ #ifdef HAVE_PROTO int XCursesInstruct(int flag) @@ -279,18 +298,20 @@ int flag; #endif /***********************************************************************/ { - char buf[10]; + char buf[10]; - PDC_LOG(("%s:XCursesInstruct() - called flag %d\n",(XCursesProcess)?" X":"CURSES",flag)); + PDC_LOG(("%s:XCursesInstruct() - called flag %d\n", XCLOGMSG, flag)); - /* - * Send a request to X... - */ - memcpy(buf,(char *)&flag,sizeof(int)); - if (write_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitCursesProcess(4,"exitting from XCursesInstruct"); - return(OK); + /* Send a request to X */ + + memcpy(buf, (char *)&flag, sizeof(int)); + + if (write_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitCursesProcess(4, "exiting from XCursesInstruct"); + + return OK; } + /***********************************************************************/ #ifdef HAVE_PROTO int XCursesInstructAndWait(int flag) @@ -300,25 +321,30 @@ int flag; #endif /***********************************************************************/ { - int result; - char buf[10]; + int result; + char buf[10]; - PDC_LOG(("%s:XCursesInstructAndWait() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesInstructAndWait() - called\n", XCLOGMSG)); - /* - * Tell X we want to do something... - */ - XCursesInstruct(flag); - /* - * ... wait for X to say the refresh has occurred. - */ - if (read_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitCursesProcess(5,"exiting from XCursesInstructAndWait"); - memcpy((char *)&result,buf,sizeof(int)); - if (result != CURSES_CONTINUE) - XCursesExitCursesProcess(6,"exitting from XCursesInstructAndWait - synchronization error"); - return(OK); + /* tell X we want to do something */ + + XCursesInstruct(flag); + + /* wait for X to say the refresh has occurred*/ + + if (read_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitCursesProcess(5, + "exiting from XCursesInstructAndWait"); + + memcpy((char *)&result, buf, sizeof(int)); + + if (result != CURSES_CONTINUE) + XCursesExitCursesProcess(6, + "exiting from XCursesInstructAndWait - synchronization error"); + + return OK; } + /***********************************************************************/ #ifdef HAVE_PROTO int XCurses_transform_line(chtype *ch, int row, int start_col, int num_cols) @@ -329,35 +355,28 @@ int row,start_col,num_cols; #endif /***********************************************************************/ { - PDC_LOG(("%s:XCurses_transform_line() called: row %d start_col %d num_cols %d flag %d\n", (XCursesProcess)?"X":"CURSES",row,start_col,num_cols,*(Xcurscr+XCURSCR_FLAG_OFF+row))); + PDC_LOG(("%s:XCurses_transform_line() called: row %d start_col %d num_cols %d flag %d\n", + XCLOGMSG, row, start_col, num_cols, + *(Xcurscr + XCURSCR_FLAG_OFF + row))); - while(*(Xcurscr+XCURSCR_FLAG_OFF+row)) - /* - * Patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 - */ - dummy_function(); /* loop until we can write to the line */ - /* - * End of patch by: - * Georg Fuchs, georg.fuchs@rz.uni-regensburg.de 02-Feb-1999 - */ + /* loop until we can write to the line */ - *(Xcurscr+XCURSCR_FLAG_OFF+row) = 1; - memcpy(Xcurscr+XCURSCR_Y_OFF(row)+(start_col*sizeof(chtype)),ch,num_cols*sizeof(chtype)); -#if 0 - *((int*)(Xcurscr+XCURSCR_START_OFF+row)) = start_col; - *((int*)(Xcurscr+XCURSCR_LENGTH_OFF+row)) = num_cols; - if ( (int)*(Xcurscr+XCURSCR_START_OFF+row) != start_col ) - printf("%d difference: start_col %d mem: %d\n",__LINE__,start_col,(int)*(Xcurscr+XCURSCR_START_OFF+row) ); - if ( (int)*(Xcurscr+XCURSCR_LENGTH_OFF+row) != num_cols ) - printf("%d difference: num_cols %d mem: %d\n",__LINE__,num_cols,(int)*(Xcurscr+XCURSCR_LENGTH_OFF+row) ); -#else - *(Xcurscr+XCURSCR_START_OFF+row) = start_col; - *(Xcurscr+XCURSCR_LENGTH_OFF+row) = num_cols; -#endif - *(Xcurscr+XCURSCR_FLAG_OFF+row) = 0; - return(0); + while (*(Xcurscr + XCURSCR_FLAG_OFF + row)) + dummy_function(); + + *(Xcurscr + XCURSCR_FLAG_OFF + row) = 1; + + memcpy(Xcurscr + XCURSCR_Y_OFF(row) + (start_col * sizeof(chtype)), + ch, num_cols * sizeof(chtype)); + + *(Xcurscr + XCURSCR_START_OFF + row) = start_col; + *(Xcurscr + XCURSCR_LENGTH_OFF + row) = num_cols; + + *(Xcurscr + XCURSCR_FLAG_OFF + row) = 0; + + return 0; } + /***********************************************************************/ #ifdef HAVE_PROTO static int XCursesSetupCurses(void) @@ -366,229 +385,267 @@ static int XCursesSetupCurses() #endif /***********************************************************************/ { - char wait_buf[5]; - int wait_value; + char wait_buf[5]; + int wait_value; - PDC_LOG(("%s:XCursesSetupCurses called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesSetupCurses called\n", XCLOGMSG)); - close ( display_sockets[1] ); - close ( key_sockets[1] ); - display_sock = display_sockets[0]; - key_sock = key_sockets[0]; - FD_ZERO ( &readfds ); - FD_ZERO ( &writefds ); - read_socket(display_sock,wait_buf,sizeof(int)); - memcpy((char *)&wait_value,wait_buf,sizeof(int)); - if (wait_value != CURSES_CHILD) - return(ERR); - /* - * Set LINES and COLS now so that the size of the - * shared memory segment can be allocated - */ - if ((shmidSP = shmget(shmkeySP,sizeof(SCREEN)+XCURSESSHMMIN,0700)) < 0) - { - perror("Cannot allocate shared memory for SCREEN"); - kill(otherpid,SIGKILL); - return(ERR); - } - SP = (SCREEN*)shmat(shmidSP,0,0); - XCursesLINES = SP->lines; - LINES = XCursesLINES - SP->linesrippedoff - SP->slklines; - XCursesCOLS = COLS = SP->cols; - if ((shmid_Xcurscr = shmget(shmkey_Xcurscr,SP->XcurscrSize+XCURSESSHMMIN,0700)) < 0) - { - perror("Cannot allocate shared memory for curscr"); - kill(otherpid,SIGKILL); - return(ERR); - } + close(display_sockets[1]); + close(key_sockets[1]); - PDC_LOG(("%s:shmid_Xcurscr %d shmkey_Xcurscr %d LINES %d COLS %d\n",(XCursesProcess)?" X":"CURSES",shmid_Xcurscr,shmkey_Xcurscr,LINES,COLS)); + display_sock = display_sockets[0]; + key_sock = key_sockets[0]; + + FD_ZERO(&readfds); + FD_ZERO(&writefds); + + read_socket(display_sock, wait_buf, sizeof(int)); + memcpy((char *)&wait_value, wait_buf, sizeof(int)); + + if (wait_value != CURSES_CHILD) + return ERR; + + /* Set LINES and COLS now so that the size of the shared memory + segment can be allocated */ + + if ((shmidSP = shmget(shmkeySP, sizeof(SCREEN) + XCURSESSHMMIN, + 0700)) < 0) + { + perror("Cannot allocate shared memory for SCREEN"); + kill(otherpid, SIGKILL); + return ERR; + } + + SP = (SCREEN*)shmat(shmidSP, 0, 0); + + XCursesLINES = SP->lines; + LINES = XCursesLINES - SP->linesrippedoff - SP->slklines; + XCursesCOLS = COLS = SP->cols; + + if ((shmid_Xcurscr = shmget(shmkey_Xcurscr, + SP->XcurscrSize + XCURSESSHMMIN, 0700)) < 0) + { + perror("Cannot allocate shared memory for curscr"); + kill(otherpid, SIGKILL); + return ERR; + } + + PDC_LOG(("%s:shmid_Xcurscr %d shmkey_Xcurscr %d LINES %d COLS %d\n", + XCLOGMSG, shmid_Xcurscr, shmkey_Xcurscr, LINES, COLS)); + + Xcurscr = (unsigned char *)shmat(shmid_Xcurscr, 0, 0); + atrtab = (unsigned char *)(Xcurscr + XCURSCR_ATRTAB_OFF); + PDC_init_atrtab(); - Xcurscr = (unsigned char *)shmat(shmid_Xcurscr,0,0); - atrtab = (unsigned char *)(Xcurscr+XCURSCR_ATRTAB_OFF); - PDC_init_atrtab(); #ifdef PDCDEBUG - say ("cursesprocess exiting from Xinitscr\n"); + say ("cursesprocess exiting from Xinitscr\n"); #endif - /* - * Always trap SIGWINCH if the C library supports SIGWINCH... - */ - XCursesSetSignal(SIGWINCH, XCursesSigwinchHandler ); - return(OK); + /* Always trap SIGWINCH if the C library supports SIGWINCH */ + + XCursesSetSignal(SIGWINCH, XCursesSigwinchHandler); + + return OK; } + /***********************************************************************/ #ifdef HAVE_PROTO int XCursesInitscr(char *display_name, int argc, char *argv[]) #else -int XCursesInitscr(display_name,argc,argv) +int XCursesInitscr(display_name, argc,argv) char *display_name; int argc; char *argv[]; #endif /***********************************************************************/ { - int pid,rc; + int pid, rc; - PDC_LOG(("%s:XCursesInitscr() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesInitscr() - called\n", XCLOGMSG)); #if defined FOREIGN - if (setlocale(LC_ALL, "") == NULL) - { - fprintf(stderr, "ERROR: cannot set locale\n"); - return(ERR); - } - if (!XSupportsLocale()) - { - fprintf(stderr, "ERROR: X does not support locale\n"); - return(ERR); - } - if (XSetLocaleModifiers("") == NULL) - fprintf(stderr, "WARNING: Cannot set locale modifiers\n"); -#endif + if (setlocale(LC_ALL, "") == NULL) + { + fprintf(stderr, "ERROR: cannot set locale\n"); + return ERR; + } - shmkeySP = getpid(); - memset ( &socket_timeout, '\0', sizeof ( socket_timeout ) ); - - if ( socketpair ( AF_UNIX, SOCK_STREAM, 0, display_sockets ) < 0 ) - { - fprintf(stderr, "ERROR: cannot create display socketpair\n"); - return(ERR); - } - - if ( socketpair ( AF_UNIX, SOCK_STREAM, 0, key_sockets ) < 0 ) - { - fprintf(stderr, "ERROR: cannot create key socketpair\n"); - return(ERR); - } + if (!XSupportsLocale()) + { + fprintf(stderr, "ERROR: X does not support locale\n"); + return ERR; + } - pid = fork(); - switch(pid) - { - case (-1): - fprintf(stderr,"ERROR: cannot fork()\n"); - return(ERR); - break; - case 0: /* child */ - shmkey_Xcurscr = getpid(); -#ifdef XISPARENT - XCursesProcess=0; - rc = XCursesSetupCurses(); -#else - XCursesProcess=1; - otherpid = getppid(); - rc = XCursesSetupX(display_name,argc,argv); + if (XSetLocaleModifiers("") == NULL) + fprintf(stderr, "WARNING: Cannot set locale modifiers\n"); #endif - break; - default: /* parent */ - shmkey_Xcurscr = pid; + shmkeySP = getpid(); + memset(&socket_timeout, '\0', sizeof(socket_timeout)); + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, display_sockets) < 0) + { + fprintf(stderr, "ERROR: cannot create display socketpair\n"); + return ERR; + } + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, key_sockets) < 0) + { + fprintf(stderr, "ERROR: cannot create key socketpair\n"); + return ERR; + } + + pid = fork(); + + switch(pid) + { + case -1: + fprintf(stderr, "ERROR: cannot fork()\n"); + return ERR; + break; + + case 0: /* child */ + shmkey_Xcurscr = getpid(); #ifdef XISPARENT - XCursesProcess=1; - otherpid = pid; - rc = XCursesSetupX(display_name,argc,argv); + XCursesProcess = 0; + rc = XCursesSetupCurses(); #else - XCursesProcess=0; - rc = XCursesSetupCurses(); + XCursesProcess = 1; + otherpid = getppid(); + rc = XCursesSetupX(display_name, argc, argv); #endif - break; - } - return(rc); + break; + + default: /* parent */ + shmkey_Xcurscr = pid; +#ifdef XISPARENT + XCursesProcess = 1; + otherpid = pid; + rc = XCursesSetupX(display_name, argc, argv); +#else + XCursesProcess = 0; + rc = XCursesSetupCurses(); +#endif + } + + return rc; } /***********************************************************************/ #ifdef HAVE_PROTO -int XCurses_getclipboard( char **contents, long *length ) +int XCurses_getclipboard(char **contents, long *length) #else -int XCurses_getclipboard( contents, length ) +int XCurses_getclipboard(contents, length) char **contents; long *length; #endif /***********************************************************************/ { - int result=0; - int len; - char buf[12]; + int result = 0; + int len; + char buf[12]; - PDC_LOG(("%s:XCurses_getclipboard() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCurses_getclipboard() - called\n", XCLOGMSG)); - XCursesInstructAndWait(CURSES_GET_SELECTION); + XCursesInstructAndWait(CURSES_GET_SELECTION); - if (read_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitCursesProcess(5,"exiting from XCurses_getclipboard"); - memcpy((char *)&result,buf,sizeof(int)); - if (result == PDC_CLIP_SUCCESS) - { - if (read_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitCursesProcess(5,"exiting from XCurses_getclipboard"); - memcpy((char *)&len,buf,sizeof(int)); - if (len != 0) - { - *contents = (char *)malloc(len+1); - if (!*contents) - XCursesExitCursesProcess(6,"exitting from XCurses_getclipboard - synchronization error"); - if (read_socket(display_sock,*contents,len) < 0) - XCursesExitCursesProcess(5,"exiting from XCurses_getclipboard"); - *length = len; - } - } - return result; + if (read_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitCursesProcess(5, + "exiting from XCurses_getclipboard"); + + memcpy((char *)&result, buf, sizeof(int)); + + if (result == PDC_CLIP_SUCCESS) + { + if (read_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitCursesProcess(5, + "exiting from XCurses_getclipboard"); + + memcpy((char *)&len, buf, sizeof(int)); + + if (len != 0) + { + *contents = (char *)malloc(len + 1); + + if (!*contents) + XCursesExitCursesProcess(6, + "exiting from XCurses_getclipboard - synchronization error"); + + if (read_socket(display_sock, *contents, len) < 0) + XCursesExitCursesProcess(5, + "exiting from XCurses_getclipboard"); + + *length = len; + } + } + + return result; } /***********************************************************************/ #ifdef HAVE_PROTO -int XCurses_setclipboard( char *contents, long length ) +int XCurses_setclipboard(char *contents, long length) #else -int XCurses_setclipboard( contents, length ) +int XCurses_setclipboard(contents, length) char *contents; long length; #endif /***********************************************************************/ { - int rc=0; - char buf[12]; /* big enough for 2 integers */ - long len=length; + int rc; + char buf[12]; /* big enough for 2 integers */ + long len = length; - PDC_LOG(("%s:XCurses_setclipboard() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCurses_setclipboard() - called\n", XCLOGMSG)); - XCursesInstruct(CURSES_SET_SELECTION); - memcpy(buf,(char *)&len,sizeof(long)); - if (write_socket(display_sock,buf,sizeof(long)) < 0) - XCursesExitCursesProcess(5,"exiting from XCurses_setclipboard"); - if (write_socket(display_sock,contents,length) < 0) - XCursesExitCursesProcess(5,"exiting from XCurses_setclipboard"); - /* - * Wait for X to do its stuff. Now expect return code... - */ - if (read_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitCursesProcess(5,"exiting from XCurses_setclipboard"); - memcpy((char *)&rc,buf,sizeof(int)); - return rc; + XCursesInstruct(CURSES_SET_SELECTION); + memcpy(buf, (char *)&len, sizeof(long)); + + if (write_socket(display_sock, buf, sizeof(long)) < 0) + XCursesExitCursesProcess(5, + "exiting from XCurses_setclipboard"); + + if (write_socket(display_sock, contents, length) < 0) + XCursesExitCursesProcess(5, + "exiting from XCurses_setclipboard"); + + /* Wait for X to do its stuff. Now expect return code. */ + + if (read_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitCursesProcess(5, + "exiting from XCurses_setclipboard"); + + memcpy((char *)&rc, buf, sizeof(int)); + return rc; } /***********************************************************************/ #ifdef HAVE_PROTO -int XCurses_clearclipboard( void ) +int XCurses_clearclipboard(void) #else -int XCurses_clearclipboard( ) +int XCurses_clearclipboard() #endif /***********************************************************************/ { - int rc=0; - char buf[12]; /* big enough for 2 integers */ - long len; + int rc; + char buf[12]; /* big enough for 2 integers */ + long len = 0; - PDC_LOG(("%s:XCurses_clearclipboard() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCurses_clearclipboard() - called\n", XCLOGMSG)); - XCursesInstruct(CURSES_CLEAR_SELECTION); - memcpy(buf,(char *)&len,sizeof(long)); - if (write_socket(display_sock,buf,sizeof(long)) < 0) - XCursesExitCursesProcess(5,"exiting from XCurses_setclipboard"); - /* - * Wait for X to do its stuff. Now expect return code... - */ - if (read_socket(display_sock,buf,sizeof(int)) < 0) - XCursesExitCursesProcess(5,"exiting from XCurses_clearclipboard"); - memcpy((char *)&rc,buf,sizeof(int)); - return rc; + XCursesInstruct(CURSES_CLEAR_SELECTION); + memcpy(buf, (char *)&len, sizeof(long)); + + if (write_socket(display_sock, buf, sizeof(long)) < 0) + XCursesExitCursesProcess(5, + "exiting from XCurses_setclipboard"); + + /* Wait for X to do its stuff. Now expect return code. */ + + if (read_socket(display_sock, buf, sizeof(int)) < 0) + XCursesExitCursesProcess(5, + "exiting from XCurses_clearclipboard"); + + memcpy((char *)&rc, buf, sizeof(int)); + return rc; } /***********************************************************************/ @@ -600,35 +657,39 @@ int rc; #endif /***********************************************************************/ { - PDC_LOG(("%s:XCursesCleanupCursesProcess() - called: %d\n",(XCursesProcess)?" X":"CURSES",rc)); + PDC_LOG(("%s:XCursesCleanupCursesProcess() - called: %d\n", + XCLOGMSG, rc)); - shutdown(display_sock,2); - close(display_sock); - shutdown(key_sock,2); - close(key_sock); - shmdt((char *)SP); - shmdt((char *)Xcurscr); - if (rc) - _exit(rc); - else - return; + shutdown(display_sock, 2); + close(display_sock); + + shutdown(key_sock, 2); + close(key_sock); + + shmdt((char *)SP); + shmdt((char *)Xcurscr); + + if (rc) + _exit(rc); } + /***********************************************************************/ #ifdef HAVE_PROTO -static void XCursesExitCursesProcess(int rc,char *msg) +static void XCursesExitCursesProcess(int rc, char *msg) #else -static void XCursesExitCursesProcess(rc,msg) +static void XCursesExitCursesProcess(rc, msg) int rc; char *msg; #endif /***********************************************************************/ { - PDC_LOG(("%s:XCursesExitCursesProcess() - called: %d %s\n",(XCursesProcess)?" X":"CURSES",rc,msg)); + PDC_LOG(("%s:XCursesExitCursesProcess() - called: %d %s\n", + XCLOGMSG, rc, msg)); - endwin(); - XCursesCleanupCursesProcess(rc); - return; + endwin(); + XCursesCleanupCursesProcess(rc); } + /***********************************************************************/ #ifdef HAVE_PROTO void XCursesExit(void) @@ -637,9 +698,8 @@ void XCursesExit() #endif /***********************************************************************/ { - PDC_LOG(("%s:XCursesExit() - called\n",(XCursesProcess)?" X":"CURSES")); + PDC_LOG(("%s:XCursesExit() - called\n", XCLOGMSG)); - XCursesInstruct(CURSES_EXIT); - XCursesCleanupCursesProcess(0); - return; + XCursesInstruct(CURSES_EXIT); + XCursesCleanupCursesProcess(0); } diff --git a/x11/sb.c b/x11/sb.c index fd957876..078b47ca 100644 --- a/x11/sb.c +++ b/x11/sb.c @@ -19,7 +19,7 @@ */ #define CURSES_LIBRARY 1 #ifdef HAVE_CONFIG_H -# include +# include #endif #include @@ -36,7 +36,7 @@ #endif #ifdef PDCDEBUG -char *rcsid_sb = "$Id: sb.c,v 1.3 2006/01/03 07:34:43 wmcbrine Exp $"; +char *rcsid_sb = "$Id: sb.c,v 1.4 2006/01/11 06:46:24 wmcbrine Exp $"; #endif /*man-start********************************************************************* @@ -44,19 +44,18 @@ char *rcsid_sb = "$Id: sb.c,v 1.3 2006/01/03 07:34:43 wmcbrine Exp $"; Name: sb Synopsis: - - int sb_init(void) - int sb_set_horz(int total, int viewport, int cur) - int sb_set_vert(int total, int viewport, int cur) - int sb_get_horz(int *total, int *viewport, int *cur) - int sb_get_vert(int *total, int *viewport, int *cur) - int sb_refresh(void); + int sb_init(void) + int sb_set_horz(int total, int viewport, int cur) + int sb_set_vert(int total, int viewport, int cur) + int sb_get_horz(int *total, int *viewport, int *cur) + int sb_get_vert(int *total, int *viewport, int *cur) + int sb_refresh(void); PDCurses Description: - These functions manipulate the scrollbar... + These functions manipulate the scrollbar. PDCurses Return Value: - All functions return OK on success and ERR on error. + All functions return OK on success and ERR on error. Portability X/Open BSD SYS V Dec '88 @@ -71,11 +70,10 @@ char *rcsid_sb = "$Id: sb.c,v 1.3 2006/01/03 07:34:43 wmcbrine Exp $"; bool sb_started = FALSE; +/* sb_init() is the sb initialization routine. + This must be called before initscr(). */ + /***********************************************************************/ -/* - sb_init() is the sb initialization routine. - This must be called before initscr(). - */ #ifdef HAVE_PROTO int PDC_CDECL sb_init(void) #else @@ -86,20 +84,20 @@ int PDC_CDECL sb_init() PDC_LOG(("sb_init() - called\n")); if (SP) - return (ERR); + return ERR; sb_started = TRUE; - return(OK); + + return OK; } -/***********************************************************************/ -/* - sb_set_horz() Used to set horizontal scrollbar. +/* sb_set_horz() - Used to set horizontal scrollbar. total = total number of columns viewport = size of viewport in columns - cur = current column in total - */ + cur = current column in total */ + +/***********************************************************************/ #ifdef HAVE_PROTO int PDC_CDECL sb_set_horz(int total, int viewport, int cur) #else @@ -108,25 +106,26 @@ int total, viewport, cur; #endif /***********************************************************************/ { - PDC_LOG(("sb_set_horz() - called: total %d viewport %d cur %d\n",total, viewport, cur)); + PDC_LOG(("sb_set_horz() - called: total %d viewport %d cur %d\n", + total, viewport, cur)); if (!SP) - return(ERR); + return ERR; SP->sb_total_x = total; SP->sb_viewport_x = viewport; SP->sb_cur_x = cur; - return( OK ); + + return OK; } -/***********************************************************************/ -/* - sb_set_vert() Used to set vertical scrollbar. +/* sb_set_vert() - Used to set vertical scrollbar. total = total number of columns on line viewport = size of viewport in columns - cur = current column in total - */ + cur = current column in total */ + +/***********************************************************************/ #ifdef HAVE_PROTO int PDC_CDECL sb_set_vert(int total, int viewport, int cur) #else @@ -135,25 +134,26 @@ int total, viewport, cur; #endif /***********************************************************************/ { - PDC_LOG(("sb_set_vert() - called: total %d viewport %d cur %d\n",total, viewport, cur)); + PDC_LOG(("sb_set_vert() - called: total %d viewport %d cur %d\n", + total, viewport, cur)); if (!SP) - return(ERR); + return ERR; SP->sb_total_y = total; SP->sb_viewport_y = viewport; SP->sb_cur_y = cur; - return( OK ); + + return OK; } -/***********************************************************************/ -/* - sb_get_horz() Used to get horizontal scrollbar. +/* sb_get_horz() - Used to get horizontal scrollbar. total = total number of lines viewport = size of viewport in lines - cur = current line in total - */ + cur = current line in total */ + +/***********************************************************************/ #ifdef HAVE_PROTO int PDC_CDECL sb_get_horz(int *total, int *viewport, int *cur) #else @@ -165,22 +165,25 @@ int *total, *viewport, *cur; PDC_LOG(("sb_get_horz() - called\n")); if (!SP) - return(ERR); + return ERR; - if (total) *total = SP->sb_total_x; - if (viewport) *viewport = SP->sb_viewport_x; - if (cur) *cur = SP->sb_cur_x; - return( OK ); + if (total) + *total = SP->sb_total_x; + if (viewport) + *viewport = SP->sb_viewport_x; + if (cur) + *cur = SP->sb_cur_x; + + return OK; } -/***********************************************************************/ -/* - sb_get_vert() Used to get vertical scrollbar. +/* sb_get_vert() - Used to get vertical scrollbar. total = total number of lines viewport = size of viewport in lines - cur = current line in total - */ + cur = current line in total */ + +/***********************************************************************/ #ifdef HAVE_PROTO int PDC_CDECL sb_get_vert(int *total, int *viewport, int *cur) #else @@ -192,18 +195,21 @@ int *total, *viewport, *cur; PDC_LOG(("sb_get_vert() - called\n")); if (!SP) - return(ERR); + return ERR; - if (total) *total = SP->sb_total_y; - if (viewport) *viewport = SP->sb_viewport_y; - if (cur) *cur = SP->sb_cur_y; - return( OK ); + if (total) + *total = SP->sb_total_y; + if (viewport) + *viewport = SP->sb_viewport_y; + if (cur) + *cur = SP->sb_cur_y; + + return OK; } +/* sb_refresh() - Used to draw the scrollbars. */ + /***********************************************************************/ -/* - sb_refresh() Used to draw the scrollbars. - */ #ifdef HAVE_PROTO int PDC_CDECL sb_refresh(void) #else @@ -214,7 +220,7 @@ int PDC_CDECL sb_refresh() PDC_LOG(("sb_refresh() - called\n")); if (!SP) - return(ERR); + return ERR; - return(XCurses_refresh_scrollbar()); + return XCurses_refresh_scrollbar(); }