home *** CD-ROM | disk | FTP | other *** search
- /*
- wincurso.c
-
- 10/30/88 by Ted.
-
- % functions control the position and shape of a window's text cursor.
- Consolidated from other files.
-
- OWL 1.2
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 3/24/89 ted Made macro out of win_GetCursorType.
-
- 12/04/89 jmd added cursor color
- 3/28/90 ted Moved code for show/hide cursor methods into functions.
- 3/28/90 ted Optimized hiding/showing for text modes.
- 3/28/90 ted Ansified.
- 5/07/90 ted Added ugly cc_before/after macros to fix cursor-obscuring
- case that optimization busted.
- */
-
- #include "oakhead.h"
- #include "disppriv.h"
-
- OSTATIC void cc_show(win_type win, boolean wasshown);
- OSTATIC boolean cc_hide(win_type win);
- OSTATIC void _cc_fixafter(win_type win, opcoord oldx, opcoord oldy);
-
- #define cc_checkbefore(win, wasdrawn, oldx, oldy) \
- (((wasdrawn = win_cudrawn(win)) != FALSE) ? (oldx = win_GetCursx(win), oldy = win_GetCursy(win)) : 0)
-
- #define cc_fixafter(win, wasdrawn, oldx, oldy) \
- if (wasdrawn && !win_cudrawn(win)) _cc_fixafter(win, oldx, oldy)
- /* -------------------------------------------------------------------------- */
-
- void win_GetCursorPixBox(win_type win, opbox *cursboxp)
- {
- cursboxp->xmin = win_GetCursx(win);
- cursboxp->ymax = win_GetCursy(win);
- cursboxp->xmax = cursboxp->xmin + win_GetFontWidth(win);
- cursboxp->ymin = cursboxp->ymax - win_GetFontHeight(win);
- }
- /* -------------------------------------------------------------------------- */
-
- boolean win_HideCursor(win_type win)
- {
- if (win != NULL) {
- if (win_curshide(win) == 0) { /* first hide */
- win_inccurshide(win);
- win_paintcursor(win);
- return(TRUE); /* Return TRUE for did something */
- }
- }
- return(FALSE);
- }
- /* -------------------------------------------------------------------------- */
-
- boolean win_ShowCursor(win_type win)
- {
- if (win != NULL) {
- if (win_curshide(win) == 1) { /* first show */
- win_deccurshide(win);
- win_paintcursor(win);
- return(TRUE); /* Return TRUE for did something */
- }
- }
- return(FALSE);
- }
- /* -------------------------------------------------------------------------- */
-
- void win_SetPixCursorPos(win_type win, opcoord cursx, opcoord cursy)
- {
- boolean wasshown;
- boolean wasdrawn;
- opcoord oldx, oldy;
-
- if (win != NULL && (cursx != win_GetCursx(win) || cursy != win_GetCursy(win))) {
- wasshown = cc_hide(win);
-
- if (disp_hardcursor()) {
- cc_checkbefore(win, wasdrawn, oldx, oldy);
- }
- win_setcursx(win, cursx);
- win_setcursy(win, cursy);
-
- cc_show(win, wasshown);
-
- if (disp_hardcursor()) {
- cc_fixafter(win, wasdrawn, oldx, oldy);
- }
- }
- }
- /* -------------------------------------------------------------------------- */
-
- void win_SetCursorType(win_type win, cursortype ctype)
- {
- boolean wasshown;
-
- if (win != NULL && ctype != win_GetCursorType(win)) {
- wasshown = cc_hide(win);
-
- win_setcurstype(win, ctype);
-
- cc_show(win, wasshown);
- }
- }
- /* -------------------------------------------------------------------------- */
-
- void win_SetCursorColor(win_type win, opixval color)
- /*
- Set the color used to diplay the window's cursor in graphics mode.
- */
- {
- boolean wasshown;
-
- if (win != NULL && color != win_curscolor(win) && !disp_hardcursor()) {
- wasshown = cc_hide(win);
-
- win_setcurscolor(win, color);
-
- cc_show(win, wasshown);
- }
- }
- /* -------------------------------------------------------------------------- */
-
- static boolean cc_hide(win_type win)
- /*
- Hide a window's text cursor if it's shown and not a hardware cursor.
- */
- {
- boolean wasshown;
-
- wasshown = (win_curshide(win) == 0);
-
- if (wasshown && !disp_hardcursor()) {
- win_HideCursor(win);
- }
- return(wasshown);
- }
- /* -------------------------------------------------------------------------- */
-
- static void cc_show(win_type win, boolean wasshown)
- /*
- Maybe show the cursor in a window that had cc_hide called on it
- to maybe hide the cursor.
- */
- {
- if (wasshown) {
- if (!disp_hardcursor()) {
- win_ShowCursor(win);
- }
- else {
- win_setcudrawn(win, FALSE); /* Fool window into repainting text cursor */
- win_paintcursor(win);
- }
- }
- }
- /* -------------------------------------------------------------------------- */
- /* -------------------------------------------------------------------------- */
-
- static void _cc_fixafter(win_type win, opcoord oldx, opcoord oldy)
- /*
- This is a nasty bit of business to hide the cursor when you move it under
- an obscuring window.
- */
- {
- opcoord newx, newy;
-
- win_setcudrawn(win, TRUE);
-
- newx = win_GetCursx(win);
- newy = win_GetCursy(win);
-
- win_setcursx(win, oldx);
- win_setcursy(win, oldy);
-
- win_HideCursor(win);
-
- win_setcursx(win, newx);
- win_setcursy(win, newy);
-
- win_ShowCursor(win);
- }
- /* -------------------------------------------------------------------------- */
-
-