166963Speter/****************************************************************************
2262685Sdelphij * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
366963Speter *                                                                          *
466963Speter * Permission is hereby granted, free of charge, to any person obtaining a  *
566963Speter * copy of this software and associated documentation files (the            *
666963Speter * "Software"), to deal in the Software without restriction, including      *
766963Speter * without limitation the rights to use, copy, modify, merge, publish,      *
866963Speter * distribute, distribute with modifications, sublicense, and/or sell       *
966963Speter * copies of the Software, and to permit persons to whom the Software is    *
1066963Speter * furnished to do so, subject to the following conditions:                 *
1166963Speter *                                                                          *
1266963Speter * The above copyright notice and this permission notice shall be included  *
1366963Speter * in all copies or substantial portions of the Software.                   *
1466963Speter *                                                                          *
1566963Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1666963Speter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
1766963Speter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
1866963Speter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
1966963Speter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2066963Speter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2166963Speter * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2266963Speter *                                                                          *
2366963Speter * Except as contained in this notice, the name(s) of the above copyright   *
2466963Speter * holders shall not be used in advertising or otherwise to promote the     *
2566963Speter * sale, use or other dealings in this Software without prior written       *
2666963Speter * authorization.                                                           *
2766963Speter ****************************************************************************/
2850276Speter
29262685Sdelphij/* $Id: panel.priv.h,v 1.25 2012/12/15 23:57:43 tom Exp $ */
3066963Speter
3176726Speter#ifndef NCURSES_PANEL_PRIV_H
3276726Speter#define NCURSES_PANEL_PRIV_H 1
3350276Speter
3450276Speter#if HAVE_CONFIG_H
3550276Speter#  include <ncurses_cfg.h>
3650276Speter#endif
3750276Speter
3850276Speter#include <stdlib.h>
3950276Speter#include <string.h>
4050276Speter#include <assert.h>
4150276Speter
42262629Sdelphijstruct screen;              /* forward declaration */
43262629Sdelphij
44262629Sdelphij#include "curses.priv.h"    /* includes nc_panel.h */
4576726Speter#include "panel.h"
4650276Speter
47262629Sdelphij
4866963Speter#if USE_RCS_IDS
4950276Speter#  define MODULE_ID(id) static const char Ident[] = id;
5050276Speter#else
5150276Speter#  define MODULE_ID(id) /*nothing*/
5250276Speter#endif
5350276Speter
5450276Speter
5550276Speter#ifdef TRACE
5676726Speter   extern NCURSES_EXPORT(const char *) _nc_my_visbuf (const void *);
5750276Speter#  ifdef TRACE_TXT
5850276Speter#    define USER_PTR(ptr) _nc_visbuf((const char *)ptr)
5950276Speter#  else
6050276Speter#    define USER_PTR(ptr) _nc_my_visbuf((const char *)ptr)
6150276Speter#  endif
6250276Speter
63166124Srafan#  define returnPanel(code)	TRACE_RETURN(code,panel)
64166124Srafan
65166124Srafan   extern NCURSES_EXPORT(PANEL *) _nc_retrace_panel (PANEL *);
6676726Speter   extern NCURSES_EXPORT(void) _nc_dPanel (const char*, const PANEL*);
6776726Speter   extern NCURSES_EXPORT(void) _nc_dStack (const char*, int, const PANEL*);
6876726Speter   extern NCURSES_EXPORT(void) _nc_Wnoutrefresh (const PANEL*);
6976726Speter   extern NCURSES_EXPORT(void) _nc_Touchpan (const PANEL*);
7076726Speter   extern NCURSES_EXPORT(void) _nc_Touchline (const PANEL*, int, int);
7150276Speter
7250276Speter#  define dBug(x) _tracef x
7350276Speter#  define dPanel(text,pan) _nc_dPanel(text,pan)
7450276Speter#  define dStack(fmt,num,pan) _nc_dStack(fmt,num,pan)
7550276Speter#  define Wnoutrefresh(pan) _nc_Wnoutrefresh(pan)
7650276Speter#  define Touchpan(pan) _nc_Touchpan(pan)
7750276Speter#  define Touchline(pan,start,count) _nc_Touchline(pan,start,count)
7850276Speter#else /* !TRACE */
79166124Srafan#  define returnPanel(code)	return code
8050276Speter#  define dBug(x)
8150276Speter#  define dPanel(text,pan)
8250276Speter#  define dStack(fmt,num,pan)
8350276Speter#  define Wnoutrefresh(pan) wnoutrefresh((pan)->win)
8450276Speter#  define Touchpan(pan) touchwin((pan)->win)
8550276Speter#  define Touchline(pan,start,count) touchline((pan)->win,start,count)
8650276Speter#endif
8750276Speter
88262629Sdelphij#if NCURSES_SP_FUNCS
89262629Sdelphij#define GetScreenHook(sp) \
90262629Sdelphij			struct panelhook* ph = NCURSES_SP_NAME(_nc_panelhook)(sp)
91262629Sdelphij#define GetPanelHook(pan) \
92262685Sdelphij			GetScreenHook(pan ? _nc_screen_of((pan)->win) : 0)
93262629Sdelphij#define GetWindowHook(win) \
94262629Sdelphij			SCREEN* sp = _nc_screen_of(win); \
95262629Sdelphij			GetScreenHook(sp)
96262629Sdelphij#define GetHook(pan)	SCREEN* sp = _nc_screen_of(pan->win); \
97262629Sdelphij			GetScreenHook(sp)
98262629Sdelphij
99262629Sdelphij#define _nc_stdscr_pseudo_panel ((ph)->stdscr_pseudo_panel)
100262629Sdelphij#define _nc_top_panel           ((ph)->top_panel)
101262629Sdelphij#define _nc_bottom_panel        ((ph)->bottom_panel)
102262629Sdelphij
103262629Sdelphij#else	/* !NCURSES_SP_FUNCS */
104262629Sdelphij
105262629Sdelphij#define GetScreenHook(sp) /* nothing */
106262629Sdelphij#define GetPanelHook(pan) /* nothing */
107262629Sdelphij#define GetWindowHook(win) /* nothing */
108262629Sdelphij#define GetHook(pan) /* nothing */
109262629Sdelphij
11050276Speter#define _nc_stdscr_pseudo_panel _nc_panelhook()->stdscr_pseudo_panel
111262629Sdelphij#define _nc_top_panel           _nc_panelhook()->top_panel
112262629Sdelphij#define _nc_bottom_panel        _nc_panelhook()->bottom_panel
11350276Speter
114262629Sdelphij#endif	/* NCURSES_SP_FUNCS */
11550276Speter
116262629Sdelphij#define EMPTY_STACK() (_nc_top_panel == _nc_bottom_panel)
117262629Sdelphij#define Is_Bottom(p)  (((p) != (PANEL*)0) && !EMPTY_STACK() && (_nc_bottom_panel->above == (p)))
118262629Sdelphij#define Is_Top(p)     (((p) != (PANEL*)0) && !EMPTY_STACK() && (_nc_top_panel == (p)))
119262629Sdelphij#define Is_Pseudo(p)  (((p) != (PANEL*)0) && ((p) == _nc_bottom_panel))
120262629Sdelphij
12156639Speter/*+-------------------------------------------------------------------------
12262449Speter	IS_LINKED(pan) - check to see if panel is in the stack
12356639Speter--------------------------------------------------------------------------*/
12456639Speter/* This works! The only case where it would fail is, when the list has
12556639Speter   only one element. But this could only be the pseudo panel at the bottom */
12662449Speter#define IS_LINKED(p) (((p)->above || (p)->below ||((p)==_nc_bottom_panel)) ? TRUE : FALSE)
12756639Speter
12856639Speter#define PSTARTX(pan) ((pan)->win->_begx)
12962449Speter#define PENDX(pan)   ((pan)->win->_begx + getmaxx((pan)->win) - 1)
13056639Speter#define PSTARTY(pan) ((pan)->win->_begy)
13162449Speter#define PENDY(pan)   ((pan)->win->_begy + getmaxy((pan)->win) - 1)
13256639Speter
13356639Speter/*+-------------------------------------------------------------------------
13456639Speter	PANELS_OVERLAPPED(pan1,pan2) - check panel overlapped
13556639Speter---------------------------------------------------------------------------*/
13656639Speter#define PANELS_OVERLAPPED(pan1,pan2) \
13756639Speter(( !(pan1) || !(pan2) || \
13862449Speter       PSTARTY(pan1) > PENDY(pan2) || PENDY(pan1) < PSTARTY(pan2) ||\
13962449Speter       PSTARTX(pan1) > PENDX(pan2) || PENDX(pan1) < PSTARTX(pan2) ) \
14056639Speter     ? FALSE : TRUE)
14156639Speter
14256639Speter
14362449Speter/*+-------------------------------------------------------------------------
14462449Speter	Compute the intersection rectangle of two overlapping rectangles
14562449Speter---------------------------------------------------------------------------*/
14662449Speter#define COMPUTE_INTERSECTION(pan1,pan2,ix1,ix2,iy1,iy2)\
14762449Speter   ix1 = (PSTARTX(pan1) < PSTARTX(pan2)) ? PSTARTX(pan2) : PSTARTX(pan1);\
14862449Speter   ix2 = (PENDX(pan1)   < PENDX(pan2))   ? PENDX(pan1)   : PENDX(pan2);\
14962449Speter   iy1 = (PSTARTY(pan1) < PSTARTY(pan2)) ? PSTARTY(pan2) : PSTARTY(pan1);\
15062449Speter   iy2 = (PENDY(pan1)   < PENDY(pan2))   ? PENDY(pan1)   : PENDY(pan2);\
151262629Sdelphij   assert((ix1<=ix2) && (iy1<=iy2))
15262449Speter
15362449Speter
15462449Speter/*+-------------------------------------------------------------------------
15562449Speter	Walk through the panel stack starting at the given location and
15662449Speter        check for intersections; overlapping panels are "touched", so they
157166124Srafan        are incrementally overwriting cells that should be hidden.
15862449Speter        If the "touch" flag is set, the panel gets touched before it is
159166124Srafan        updated.
16062449Speter---------------------------------------------------------------------------*/
16176726Speter#define PANEL_UPDATE(pan,panstart)\
16262449Speter{  PANEL* pan2 = ((panstart) ? (panstart) : _nc_bottom_panel);\
163262685Sdelphij   while(pan2 && pan2->win) {\
16456639Speter      if ((pan2 != pan) && PANELS_OVERLAPPED(pan,pan2)) {\
165262629Sdelphij        int y, ix1, ix2, iy1, iy2;\
166262629Sdelphij        COMPUTE_INTERSECTION(pan, pan2, ix1, ix2, iy1, iy2);\
16762449Speter	for(y = iy1; y <= iy2; y++) {\
16862449Speter	  if (is_linetouched(pan->win,y - PSTARTY(pan))) {\
16962449Speter            struct ldat* line = &(pan2->win->_line[y - PSTARTY(pan2)]);\
170262629Sdelphij            CHANGED_RANGE(line, ix1 - PSTARTX(pan2), ix2 - PSTARTX(pan2));\
17162449Speter          }\
17256639Speter	}\
17356639Speter      }\
17456639Speter      pan2 = pan2->above;\
17562449Speter   }\
17656639Speter}
17762449Speter
17862449Speter/*+-------------------------------------------------------------------------
17962449Speter	Remove panel from stack.
18062449Speter---------------------------------------------------------------------------*/
18162449Speter#define PANEL_UNLINK(pan,err) \
18262449Speter{  err = ERR;\
18362449Speter   if (pan) {\
18462449Speter     if (IS_LINKED(pan)) {\
18562449Speter       if ((pan)->below)\
18662449Speter         (pan)->below->above = (pan)->above;\
18762449Speter       if ((pan)->above)\
18862449Speter         (pan)->above->below = (pan)->below;\
18962449Speter       if ((pan) == _nc_bottom_panel) \
19062449Speter         _nc_bottom_panel = (pan)->above;\
19162449Speter       if ((pan) == _nc_top_panel) \
19262449Speter         _nc_top_panel = (pan)->below;\
19362449Speter       err = OK;\
19462449Speter     }\
19562449Speter     (pan)->above = (pan)->below = (PANEL*)0;\
19662449Speter   }\
19762449Speter}
19862449Speter
19962449Speter#define HIDE_PANEL(pan,err,err_if_unlinked)\
20062449Speter  if (IS_LINKED(pan)) {\
20176726Speter    Touchpan(pan);\
20276726Speter    PANEL_UPDATE(pan,(PANEL*)0);\
20362449Speter    PANEL_UNLINK(pan,err);\
20462449Speter  } \
20562449Speter  else {\
20676726Speter      err = err_if_unlinked;\
20762449Speter  }
20862449Speter
209262629Sdelphij#if NCURSES_SP_FUNCS
210262629Sdelphij/* These may become later renamed and part of panel.h and the public API */
211262629Sdelphijextern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_update_panels)(SCREEN*);
212262629Sdelphij#endif
213262629Sdelphij
21476726Speter#endif /* NCURSES_PANEL_PRIV_H */
215