panel.priv.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /****************************************************************************
  2. * Copyright (c) 1998-2005,2008 Free Software Foundation, Inc. *
  3. * *
  4. * Permission is hereby granted, free of charge, to any person obtaining a *
  5. * copy of this software and associated documentation files (the *
  6. * "Software"), to deal in the Software without restriction, including *
  7. * without limitation the rights to use, copy, modify, merge, publish, *
  8. * distribute, distribute with modifications, sublicense, and/or sell *
  9. * copies of the Software, and to permit persons to whom the Software is *
  10. * furnished to do so, subject to the following conditions: *
  11. * *
  12. * The above copyright notice and this permission notice shall be included *
  13. * in all copies or substantial portions of the Software. *
  14. * *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
  16. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
  18. * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  19. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  20. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
  21. * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
  22. * *
  23. * Except as contained in this notice, the name(s) of the above copyright *
  24. * holders shall not be used in advertising or otherwise to promote the *
  25. * sale, use or other dealings in this Software without prior written *
  26. * authorization. *
  27. ****************************************************************************/
  28. /* $Id: panel.priv.h,v 1.22 2008/09/27 22:36:11 tom Exp $ */
  29. #ifndef NCURSES_PANEL_PRIV_H
  30. #define NCURSES_PANEL_PRIV_H 1
  31. #if HAVE_CONFIG_H
  32. # include <ncurses_cfg.h>
  33. #endif
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <assert.h>
  37. #include "curses.priv.h"
  38. #include "panel.h"
  39. #include <nc_panel.h>
  40. #if USE_RCS_IDS
  41. # define MODULE_ID(id) static const char Ident[] = id;
  42. #else
  43. # define MODULE_ID(id) /*nothing*/
  44. #endif
  45. #ifdef TRACE
  46. extern NCURSES_EXPORT(const char *) _nc_my_visbuf (const void *);
  47. # ifdef TRACE_TXT
  48. # define USER_PTR(ptr) _nc_visbuf((const char *)ptr)
  49. # else
  50. # define USER_PTR(ptr) _nc_my_visbuf((const char *)ptr)
  51. # endif
  52. # define returnPanel(code) TRACE_RETURN(code,panel)
  53. extern NCURSES_EXPORT(PANEL *) _nc_retrace_panel (PANEL *);
  54. extern NCURSES_EXPORT(void) _nc_dPanel (const char*, const PANEL*);
  55. extern NCURSES_EXPORT(void) _nc_dStack (const char*, int, const PANEL*);
  56. extern NCURSES_EXPORT(void) _nc_Wnoutrefresh (const PANEL*);
  57. extern NCURSES_EXPORT(void) _nc_Touchpan (const PANEL*);
  58. extern NCURSES_EXPORT(void) _nc_Touchline (const PANEL*, int, int);
  59. # define dBug(x) _tracef x
  60. # define dPanel(text,pan) _nc_dPanel(text,pan)
  61. # define dStack(fmt,num,pan) _nc_dStack(fmt,num,pan)
  62. # define Wnoutrefresh(pan) _nc_Wnoutrefresh(pan)
  63. # define Touchpan(pan) _nc_Touchpan(pan)
  64. # define Touchline(pan,start,count) _nc_Touchline(pan,start,count)
  65. #else /* !TRACE */
  66. # define returnPanel(code) return code
  67. # define dBug(x)
  68. # define dPanel(text,pan)
  69. # define dStack(fmt,num,pan)
  70. # define Wnoutrefresh(pan) wnoutrefresh((pan)->win)
  71. # define Touchpan(pan) touchwin((pan)->win)
  72. # define Touchline(pan,start,count) touchline((pan)->win,start,count)
  73. #endif
  74. #define _nc_stdscr_pseudo_panel _nc_panelhook()->stdscr_pseudo_panel
  75. #define _nc_top_panel _nc_panelhook()->top_panel
  76. #define _nc_bottom_panel _nc_panelhook()->bottom_panel
  77. #define EMPTY_STACK() (_nc_top_panel==_nc_bottom_panel)
  78. #define Is_Bottom(p) (((p)!=(PANEL*)0) && !EMPTY_STACK() && (_nc_bottom_panel->above==(p)))
  79. #define Is_Top(p) (((p)!=(PANEL*)0) && !EMPTY_STACK() && (_nc_top_panel==(p)))
  80. #define Is_Pseudo(p) ((p) && ((p)==_nc_bottom_panel))
  81. /*+-------------------------------------------------------------------------
  82. IS_LINKED(pan) - check to see if panel is in the stack
  83. --------------------------------------------------------------------------*/
  84. /* This works! The only case where it would fail is, when the list has
  85. only one element. But this could only be the pseudo panel at the bottom */
  86. #define IS_LINKED(p) (((p)->above || (p)->below ||((p)==_nc_bottom_panel)) ? TRUE : FALSE)
  87. #define PSTARTX(pan) ((pan)->win->_begx)
  88. #define PENDX(pan) ((pan)->win->_begx + getmaxx((pan)->win) - 1)
  89. #define PSTARTY(pan) ((pan)->win->_begy)
  90. #define PENDY(pan) ((pan)->win->_begy + getmaxy((pan)->win) - 1)
  91. /*+-------------------------------------------------------------------------
  92. PANELS_OVERLAPPED(pan1,pan2) - check panel overlapped
  93. ---------------------------------------------------------------------------*/
  94. #define PANELS_OVERLAPPED(pan1,pan2) \
  95. (( !(pan1) || !(pan2) || \
  96. PSTARTY(pan1) > PENDY(pan2) || PENDY(pan1) < PSTARTY(pan2) ||\
  97. PSTARTX(pan1) > PENDX(pan2) || PENDX(pan1) < PSTARTX(pan2) ) \
  98. ? FALSE : TRUE)
  99. /*+-------------------------------------------------------------------------
  100. Compute the intersection rectangle of two overlapping rectangles
  101. ---------------------------------------------------------------------------*/
  102. #define COMPUTE_INTERSECTION(pan1,pan2,ix1,ix2,iy1,iy2)\
  103. ix1 = (PSTARTX(pan1) < PSTARTX(pan2)) ? PSTARTX(pan2) : PSTARTX(pan1);\
  104. ix2 = (PENDX(pan1) < PENDX(pan2)) ? PENDX(pan1) : PENDX(pan2);\
  105. iy1 = (PSTARTY(pan1) < PSTARTY(pan2)) ? PSTARTY(pan2) : PSTARTY(pan1);\
  106. iy2 = (PENDY(pan1) < PENDY(pan2)) ? PENDY(pan1) : PENDY(pan2);\
  107. assert((ix1<=ix2) && (iy1<=iy2));\
  108. /*+-------------------------------------------------------------------------
  109. Walk through the panel stack starting at the given location and
  110. check for intersections; overlapping panels are "touched", so they
  111. are incrementally overwriting cells that should be hidden.
  112. If the "touch" flag is set, the panel gets touched before it is
  113. updated.
  114. ---------------------------------------------------------------------------*/
  115. #define PANEL_UPDATE(pan,panstart)\
  116. { PANEL* pan2 = ((panstart) ? (panstart) : _nc_bottom_panel);\
  117. while(pan2) {\
  118. if ((pan2 != pan) && PANELS_OVERLAPPED(pan,pan2)) {\
  119. int y,ix1,ix2,iy1,iy2;\
  120. COMPUTE_INTERSECTION(pan,pan2,ix1,ix2,iy1,iy2);\
  121. for(y = iy1; y <= iy2; y++) {\
  122. if (is_linetouched(pan->win,y - PSTARTY(pan))) {\
  123. struct ldat* line = &(pan2->win->_line[y - PSTARTY(pan2)]);\
  124. CHANGED_RANGE(line,ix1-PSTARTX(pan2),ix2-PSTARTX(pan2));\
  125. }\
  126. }\
  127. }\
  128. pan2 = pan2->above;\
  129. }\
  130. }
  131. /*+-------------------------------------------------------------------------
  132. Remove panel from stack.
  133. ---------------------------------------------------------------------------*/
  134. #define PANEL_UNLINK(pan,err) \
  135. { err = ERR;\
  136. if (pan) {\
  137. if (IS_LINKED(pan)) {\
  138. if ((pan)->below)\
  139. (pan)->below->above = (pan)->above;\
  140. if ((pan)->above)\
  141. (pan)->above->below = (pan)->below;\
  142. if ((pan) == _nc_bottom_panel) \
  143. _nc_bottom_panel = (pan)->above;\
  144. if ((pan) == _nc_top_panel) \
  145. _nc_top_panel = (pan)->below;\
  146. err = OK;\
  147. }\
  148. (pan)->above = (pan)->below = (PANEL*)0;\
  149. }\
  150. }
  151. #define HIDE_PANEL(pan,err,err_if_unlinked)\
  152. if (IS_LINKED(pan)) {\
  153. Touchpan(pan);\
  154. PANEL_UPDATE(pan,(PANEL*)0);\
  155. PANEL_UNLINK(pan,err);\
  156. } \
  157. else {\
  158. err = err_if_unlinked;\
  159. }
  160. #endif /* NCURSES_PANEL_PRIV_H */