summaryrefslogtreecommitdiff
path: root/src/itextbox.cpp
blob: d28b7dd79ac5da8cc2758ff891235693d1006330 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**************************************************************************\
 ibtk (Insomnia's Basic ToolKit)

  By Insomnia (Steaphan Greene)
  (insomnia@core.binghamton.edu)

  Copyright (C) 1999 Steaphan Greene

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.

\**************************************************************************/

#include <string.h>

#include "itextbox.h"

ITextBox::~ITextBox()  {
  Win->RemoveClaim(this);
  }

ITextBox::ITextBox(char *txt, IWindow *w, int xp, int yp, int xs, int ys)  {
  if(txt != NULL) Init(txt, w, xp, yp, xs, ys);
  }

void ITextBox::Init(char *txt, IWindow *w, int xp, int yp, int xs, int ys)  {
  xpos = xp; ypos = yp; xsize = xs; ysize = ys;
  Win = w;
  Window wind = w->GetWindowBuffer();
  Display *disp = w->GetDisplay();
  unsigned int p, b, g, gl, gd;
  Img = XCreatePixmap(disp, wind, xs, ys, DefaultDepth(disp, 0));
  GC gc = Win->GetGC();

  p = w->GetPaperColor();
  b = w->GetFGColor();
  g = w->GetBGColor();
  gl = w->GetLBGColor();
  gd = w->GetDBGColor();

  XFontStruct *fs;
  XCharStruct cs;
  int dir, as, des;
  fs = Win->GetFontStruct();
  XTextExtents(fs, txt, strlen(txt), &dir, &as, &des, &cs);
  int len = cs.width;
  switch(Win->Appearance()) {
    case(IBTK_DEFAULT): {
      XSetForeground(disp, gc, g);
      XFillRectangle(disp, Img, gc, 0, 0, xs, ys);
      XSetBackground(disp, gc, g);
      XSetForeground(disp, gc, b);
      XDrawImageString(disp, Img, gc, (xs-(len-1))>>1, (ys+ys-(as+des-2))>>1,
	txt, strlen(txt));
      }break;
    case(IBTK_STEP): {
      XSetForeground(disp, gc, gl);
      XFillRectangle(disp, Img, gc, 0, 0, xsize, ysize);

      XSetForeground(disp, gc, p);
      XDrawLine(disp, Img,gc, 0,0, 0,ysize-2);
      XDrawLine(disp, Img,gc, 0,0, xsize-2,0);

      XSetForeground(disp, gc, b);
      XDrawLine(disp, Img,gc, 0,ysize-1, xsize-1,ysize-1);
      XDrawLine(disp, Img,gc, xsize-1,0, xsize-1,ysize-1);

      XSetBackground(disp, gc, gl);
      XSetForeground(disp, gc, b);
      XDrawImageString(disp, Img, gc, (xs-(len-1))>>1, (ys+ys-(as+des-2))>>1,
	txt, strlen(txt));
      }break;
    }
  parent=NULL;

  w->AddClaim(this, xp, yp, xs, ys);

  Redraw();
  }

void ITextBox::Rebuild()  {
  Redraw();
  }

void ITextBox::Redraw()  {
  if(!hidden) {
    XCopyArea(Win->GetDisplay(), Img, Win->GetWindowBuffer(), Win->GetGC(),
	0, 0, xsize, ysize, xpos, ypos);
    Win->Redraw(xpos, ypos, xsize, ysize);
    }
  else {
    Win->Rebuild(xpos, ypos, xsize, ysize);        
    }
  }

int ITextBox::Press(int b, int x, int y)  {
  if(parent!=NULL)  parent->Press(b, x, y);
  return 1;
  }

int ITextBox::Release(int b, int x, int y)  {
  if(parent!=NULL)  parent->Release(b, x, y);
  return 1;
  }