]> ncurses.scripts.mit.edu Git - ncurses.git/blob - c++/cursesp.cc
ncurses 4.1
[ncurses.git] / c++ / cursesp.cc
1 // * this is for making emacs happy: -*-Mode: C++;-*-
2 /*
3   written and
4   Copyright (C) 1993 by Anatoly Ivasyuk (anatoly@nick.csh.rit.edu)
5
6   Modified by Juergen Pfeifer, April 1997
7 */
8
9 #include "internal.h"
10
11 MODULE_ID("$Id: cursesp.cc,v 1.6 1997/05/04 01:02:08 tom Exp $")
12
13 #pragma  implementation
14 #include "cursesp.h"
15
16 NCursesPanel::NCursesPanel(int lines,
17                            int cols,
18                            int begin_y,
19                            int begin_x)
20   : NCursesWindow(lines, cols, begin_y, begin_x) {
21     
22     p = ::new_panel(w);
23     if (!p)
24       OnError(ERR);
25     
26     UserHook* hook = new UserHook;
27     hook->m_user  = NULL;
28     hook->m_back  = this;
29     hook->m_owner = p;
30     ::set_panel_userptr(p, (const void *)hook);
31 }
32
33
34 NCursesPanel::~NCursesPanel() {
35   UserHook* hook = (UserHook*)::panel_userptr(p);
36   assert(hook && hook->m_back==this && hook->m_owner==p);
37   delete hook;
38   ::del_panel(p);
39   ::update_panels();
40   ::doupdate();
41 }
42
43 void
44 NCursesPanel::redraw() {
45   PANEL *pan;
46   
47   pan = ::panel_above(NULL);
48   while (pan) {
49     ::touchwin(panel_window(pan));
50     pan = ::panel_above(pan);
51   }
52   ::update_panels();
53   ::doupdate();
54 }
55
56 void
57 NCursesPanel::refresh() {
58   ::update_panels();
59   ::doupdate();
60 }
61
62 void
63 NCursesPanel::boldframe(const char *title, const char* btitle) {
64   standout();
65   frame(title, btitle);
66   standend();
67 }
68
69 void
70 NCursesPanel::frame(const char *title,const char *btitle) {
71   int err = OK;
72   if (!title && !btitle) {
73     err = box();
74   } 
75   else {
76     err = box();
77     if (err==OK)
78       label(title,btitle); 
79   }
80   OnError(err);
81 }
82
83 void
84 NCursesPanel::label(const char *tLabel, const char *bLabel) {
85   if (tLabel) 
86     centertext(0,tLabel);
87   if (bLabel) 
88     centertext(maxy(),bLabel);
89 }
90
91 void
92 NCursesPanel::centertext(int row,const char *label) {
93   if (label) 
94     OnError(addstr(row,(maxx() - strlen(label)) / 2, label));
95 }