home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / WINCURSO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-08  |  4.8 KB  |  189 lines

  1. /*
  2.     wincurso.c
  3.  
  4.     10/30/88 by Ted.
  5.  
  6.     % functions control the position and shape of a window's text cursor.
  7.     Consolidated from other files.
  8.  
  9.     OWL 1.2
  10.     Copyright (c) 1988, by Oakland Group, Inc.
  11.     ALL RIGHTS RESERVED.
  12.  
  13.     Revision History:
  14.     -----------------
  15.      3/24/89 ted    Made macro out of win_GetCursorType.
  16.  
  17.     12/04/89 jmd    added cursor color
  18.      3/28/90 ted    Moved code for show/hide cursor methods into functions.
  19.      3/28/90 ted    Optimized hiding/showing for text modes.
  20.      3/28/90 ted    Ansified.
  21.      5/07/90 ted    Added ugly cc_before/after macros to fix cursor-obscuring
  22.                     case that optimization busted.
  23. */
  24.  
  25. #include "oakhead.h"
  26. #include "disppriv.h"
  27.  
  28. OSTATIC void    cc_show(win_type win, boolean wasshown);
  29. OSTATIC boolean cc_hide(win_type win);
  30. OSTATIC void    _cc_fixafter(win_type win, opcoord oldx, opcoord oldy);
  31.  
  32. #define cc_checkbefore(win, wasdrawn, oldx, oldy)    \
  33.     (((wasdrawn = win_cudrawn(win)) != FALSE) ? (oldx = win_GetCursx(win), oldy = win_GetCursy(win)) : 0)
  34.  
  35. #define cc_fixafter(win, wasdrawn, oldx, oldy)        \
  36.     if (wasdrawn && !win_cudrawn(win)) _cc_fixafter(win, oldx, oldy)
  37. /* -------------------------------------------------------------------------- */
  38.  
  39. void win_GetCursorPixBox(win_type win, opbox *cursboxp)
  40. {
  41.     cursboxp->xmin = win_GetCursx(win);
  42.     cursboxp->ymax = win_GetCursy(win);
  43.     cursboxp->xmax = cursboxp->xmin + win_GetFontWidth(win);
  44.     cursboxp->ymin = cursboxp->ymax - win_GetFontHeight(win);
  45. }
  46. /* -------------------------------------------------------------------------- */
  47.  
  48. boolean win_HideCursor(win_type win)
  49. {
  50.     if (win != NULL) {
  51.         if (win_curshide(win) == 0) {    /* first hide */
  52.             win_inccurshide(win);
  53.             win_paintcursor(win);
  54.             return(TRUE);    /* Return TRUE for did something */    
  55.         }
  56.     }
  57.     return(FALSE);
  58. }
  59. /* -------------------------------------------------------------------------- */
  60.  
  61. boolean win_ShowCursor(win_type win)
  62. {
  63.     if (win != NULL) {
  64.         if (win_curshide(win) == 1) {    /* first show */
  65.             win_deccurshide(win);
  66.             win_paintcursor(win);
  67.             return(TRUE);    /* Return TRUE for did something */    
  68.         }
  69.     }
  70.     return(FALSE);
  71. }
  72. /* -------------------------------------------------------------------------- */
  73.  
  74. void win_SetPixCursorPos(win_type win, opcoord cursx, opcoord cursy)
  75. {
  76.     boolean wasshown;
  77.     boolean wasdrawn;
  78.     opcoord oldx, oldy;
  79.  
  80.     if (win != NULL && (cursx != win_GetCursx(win) || cursy != win_GetCursy(win))) {
  81.         wasshown = cc_hide(win);
  82.  
  83.         if (disp_hardcursor()) {
  84.             cc_checkbefore(win, wasdrawn, oldx, oldy);
  85.         }
  86.         win_setcursx(win, cursx);
  87.         win_setcursy(win, cursy);
  88.  
  89.         cc_show(win, wasshown);
  90.  
  91.         if (disp_hardcursor()) {
  92.             cc_fixafter(win, wasdrawn, oldx, oldy);
  93.         }
  94.     }
  95. }
  96. /* -------------------------------------------------------------------------- */
  97.  
  98. void win_SetCursorType(win_type win, cursortype ctype)
  99. {
  100.     boolean wasshown;
  101.  
  102.     if (win != NULL && ctype != win_GetCursorType(win)) {
  103.         wasshown = cc_hide(win);
  104.  
  105.         win_setcurstype(win, ctype);
  106.  
  107.         cc_show(win, wasshown);
  108.     }
  109. }
  110. /* -------------------------------------------------------------------------- */
  111.  
  112. void win_SetCursorColor(win_type win, opixval color)
  113. /*
  114.     Set the color used to diplay the window's cursor in graphics mode.
  115. */
  116. {
  117.     boolean wasshown;
  118.  
  119.     if (win != NULL && color != win_curscolor(win) && !disp_hardcursor()) {
  120.         wasshown = cc_hide(win);
  121.  
  122.         win_setcurscolor(win, color);
  123.  
  124.         cc_show(win, wasshown);
  125.     }
  126. }
  127. /* -------------------------------------------------------------------------- */
  128.  
  129. static boolean cc_hide(win_type win)
  130. /*
  131.     Hide a window's text cursor if it's shown and not a hardware cursor.
  132. */
  133. {
  134.     boolean wasshown;
  135.  
  136.     wasshown = (win_curshide(win) == 0);
  137.  
  138.     if (wasshown && !disp_hardcursor()) {
  139.         win_HideCursor(win);
  140.     }
  141.     return(wasshown);
  142. }
  143. /* -------------------------------------------------------------------------- */
  144.  
  145. static void cc_show(win_type win, boolean wasshown)
  146. /*
  147.     Maybe show the cursor in a window that had cc_hide called on it
  148.     to maybe hide the cursor.
  149. */
  150. {
  151.     if (wasshown) {
  152.         if (!disp_hardcursor()) {
  153.             win_ShowCursor(win);
  154.         }
  155.         else {
  156.             win_setcudrawn(win, FALSE);    /* Fool window into repainting text cursor */
  157.             win_paintcursor(win);
  158.         }
  159.     }
  160. }
  161. /* -------------------------------------------------------------------------- */
  162. /* -------------------------------------------------------------------------- */
  163.  
  164. static void _cc_fixafter(win_type win, opcoord oldx, opcoord oldy)
  165. /*
  166.     This is a nasty bit of business to hide the cursor when you move it under
  167.     an obscuring window.
  168. */
  169. {
  170.     opcoord newx, newy;
  171.  
  172.     win_setcudrawn(win, TRUE);
  173.  
  174.     newx = win_GetCursx(win);
  175.     newy = win_GetCursy(win);
  176.  
  177.     win_setcursx(win, oldx);
  178.     win_setcursy(win, oldy);
  179.  
  180.     win_HideCursor(win);
  181.  
  182.     win_setcursx(win, newx);
  183.     win_setcursy(win, newy);
  184.  
  185.     win_ShowCursor(win);
  186. }
  187. /* -------------------------------------------------------------------------- */
  188.  
  189.