1 // ---------------------------------------------------------------------------------
2 //
3 //  Copyright (C) 2003-2013 Fons Adriaensen <fons@linuxaudio.org>
4 //
5 //  This program is free software; you can redistribute it and/or modify
6 //  it under the terms of the GNU Lesser General Public License as published
7 //  by the Free Software Foundation; either version 2 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU Lesser General Public License for more details.
14 //
15 //  You should have received a copy of the GNU Lesser General Public
16 //  License along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //
19 // ---------------------------------------------------------------------------------
20 
21 
22 #ifndef __CLXCLIENT_H
23 #define __CLXCLIENT_H
24 
25 
26 #include <X11/Xos.h>
27 #include <X11/Xlib.h>
28 #include <X11/Xutil.h>
29 #include <X11/Xatom.h>
30 #include <X11/Xresource.h>
31 #include <X11/Xft/Xft.h>
32 #include <clthreads.h>
33 
34 
35 // -------------------------------------------------------------------------------------------
36 
37 const char *clxclient_version (void);
38 
39 // -------------------------------------------------------------------------------------------
40 
41 
42 class X_display
43 {
44 public:
45 
46     X_display (const char *dispname);
47     ~X_display (void);
48 
blackpixel(void)49     unsigned long blackpixel (void) const { return BlackPixel (_dpy, _dsn); }
whitepixel(void)50     unsigned long whitepixel (void) const { return WhitePixel (_dpy, _dsn); }
51 
dpy(void)52     Display *dpy (void) const { return _dpy; }
dsn(void)53     int      dsn (void) const { return _dsn; }
dcm(void)54     Colormap dcm (void) const { return _dcm; }
dgc(void)55     GC       dgc (void) const { return _dgc; }
dvi(void)56     Visual  *dvi (void) const { return _dvi; }
xft(void)57     XftDraw *xft (void) const { return _xft; }
xim(void)58     XIM      xim (void) const { return _xim; }
59 
depth(void)60     int depth (void) const { return DefaultDepth (_dpy, _dsn); }
xsize(void)61     int xsize (void) const { return WidthOfScreen  (ScreenOfDisplay (_dpy, _dsn)); }
ysize(void)62     int ysize (void) const { return HeightOfScreen (ScreenOfDisplay (_dpy, _dsn)); }
gray(void)63     int gray  (void) const { return 0; }
64 
65     unsigned long alloc_color (const char *name, unsigned long d);
66     unsigned long alloc_color (float r, float g, float b);
67     XftColor *alloc_xftcolor (const char *name, XftColor *D);
68     XftColor *alloc_xftcolor (float r, float g, float b, float a);
69     void free_xftcolor (XftColor *C);
70 
71     XFontStruct *alloc_font  (const char *name);
72     XftFont *alloc_xftfont (const char *name);
73     void free_xftfont (XftFont *F);
74 
75     enum { IMG_LT, IMG_RT, IMG_UP, IMG_DN, IMG_PL, IMG_MI, IMG_SQ, IMG_PT, N_IMG1515 };
76 
nofocus(void)77     void nofocus (void) { XSetInputFocus (_dpy, PointerRoot, PointerRoot, CurrentTime); }
78 
79     XImage *image1515 (unsigned int i);
80 
81 private:
82 
83     friend class X_rootwin;
84     friend class X_window;
85     friend class X_handler;
86 
87     Display     *_dpy;
88     int          _dsn;
89     Colormap     _dcm;
90     GC           _dgc;
91     Visual      *_dvi;
92     XftDraw     *_xft;
93     XIM          _xim;
94 
95     static unsigned char  _imgdef1515 [N_IMG1515 * 30];
96     XImage               *_imgptr1515 [N_IMG1515];
97 };
98 
99 
100 // -------------------------------------------------------------------------------------------
101 
102 
103 class X_hints
104 {
105 public:
106 
X_hints(void)107     X_hints (void) { _sh.flags = 0; _mh.flags = 0; _ch.res_name = 0; _ch.res_class = 0; }
108 
109     void position (int x, int y);
110     void size (int x, int y);
111     void minsize  (int x, int y);
112     void maxsize  (int x, int y);
113     void sizeinc (int x, int y);
114     void input (int input);
115     void state (int state);
116     void group (Window group);
rname(const char * rname)117     void rname (const char *rname) { _ch.res_name  = (char *) rname; }
rclas(const char * rclas)118     void rclas (const char *rclas) { _ch.res_class = (char *) rclas; }
119 
120     friend class X_window;
121 
122 private:
123 
124     XSizeHints  _sh;
125     XWMHints    _mh;
126     XClassHint  _ch;
127 
128 };
129 
130 
131 // -------------------------------------------------------------------------------------------
132 
133 
134 class X_window
135 {
136 public:
137 
138     X_window (X_window *pwin, int xpos, int ypos, int xsize, int ysize,
139 	      unsigned long bgcol, unsigned long bdcol = 0, int bdpix = 0);
140 
141     virtual ~X_window (void);
142 
disp(void)143     X_display*  disp (void) const { return _disp; }
144 
dpy(void)145     Display   *dpy (void) const { return _disp->_dpy; }
dsn(void)146     int        dsn (void) const { return _disp->_dsn; }
dcm(void)147     Colormap   dcm (void) const { return _disp->_dcm; }
dgc(void)148     GC         dgc (void) const { return _disp->_dgc; }
dvi(void)149     Visual    *dvi (void) const { return _disp->_dvi; }
xft(void)150     XftDraw   *xft (void) const { return _disp->_xft; }
xim(void)151     XIM        xim (void) const { return _disp->_xim; }
win(void)152     Window     win (void) const { return _wind; }
153 
handle_event(XEvent * E)154     virtual void handle_event (XEvent *E) {}
155 
x_map(void)156     int  x_map (void) const { return XMapWindow   (_disp->_dpy, _wind); }
x_mapraised(void)157     int  x_mapraised (void) const { return XMapRaised (_disp->_dpy, _wind); }
x_unmap(void)158     int  x_unmap (void) const { return XUnmapWindow (_disp->_dpy, _wind); }
x_clear(void)159     int  x_clear (void) const { return XClearWindow (_disp->_dpy, _wind); }
x_raise(void)160     int  x_raise (void) const { return XRaiseWindow (_disp->_dpy, _wind); }
161     int  x_move (int xp, int yp) const;
162     int  x_resize (int xs, int ys) const;
163     int  x_moveresize (int xp, int yp, int xs, int ys) const;
164     int  x_set_attrib (unsigned long mask, XSetWindowAttributes *attr) const;
165     int  x_set_win_gravity (int gravity) const;
166     int  x_set_bit_gravity (int gravity) const;
167     int  x_add_events (unsigned long events);
168     int  x_rem_events (unsigned long events);
169     int  x_set_title (const char *title);
170     int  x_set_background (unsigned long color);
171     void x_apply (X_hints *hints);
172 
pwin(void)173     X_window *pwin (void) { return _pwin; }
174 
175     friend class X_rootwin;
176 
177 private:
178 
179     X_window (X_display *disp);
180     X_window (const X_window&);
181     X_window& operator=(const X_window&);
182     X_window      *find (Window w);
183 
184     unsigned long _ebits;
185     X_display     *_disp;
186     X_window      *_pwin;
187     X_window      *_next;
188     X_window      *_list;
189     Window         _wind;
190 };
191 
192 
193 // -------------------------------------------------------------------------------------------
194 
195 
196 class X_subwin : public X_window
197 {
198 public:
199 
200     X_subwin (X_window *pwin, int xpos, int ypos, int xsize, int ysize,
201 	      unsigned long bgcol, unsigned long bdcol = 0, int bdpix = 0) :
X_window(pwin,xpos,ypos,xsize,ysize,bgcol,bdcol,bdpix)202         X_window (pwin, xpos, ypos, xsize, ysize, bgcol, bdcol, bdpix)
203         {}
204 
handle_event(XEvent * E)205     virtual void handle_event (XEvent *E) { pwin ()->handle_event (E); }
206 };
207 
208 
209 // -------------------------------------------------------------------------------------------
210 
211 
212 class X_rootwin : public X_window
213 {
214 public:
215 
216     X_rootwin (X_display *disp);
217     virtual ~X_rootwin (void);
218 
219     void handle_event (void);
220     void handle_event (XEvent *E);
check_done(void)221     bool check_done (void) const { return _list == 0; }
222 
223 private:
224 
225     Window    _window;
226     X_window *_object;
227 };
228 
229 
230 // -------------------------------------------------------------------------------------------
231 
232 
233 class X_resman
234 {
235 public:
236 
237     enum { NDEFOPT = 13 };
238 
239     X_resman (void);
240     ~X_resman (void);
241     X_resman (const X_resman&);
242     X_resman& operator=(const X_resman&);
243 
244     void init (int *argc, char *argv [], char *name, XrmOptionDescRec *opt, int nopt);
245 
246     const char *get (const char *res, const char *def) const;
247     int   getb (const char *res, int def) const;
248     void  geometry (const char *res, int xd, int yd, int bd,
249 		    int &xp, int &yp, int &xs, int &ys);
250 
rname(void)251     const char *rname (void) { return _rname; }
rclas(void)252     const char *rclas (void) { return _rclas; }
253 
254 private:
255 
256     char         _rname [64];
257     char         _rclas [64];
258     char        *_home;
259     XrmDatabase  _xrmdata;
260 
261     static XrmOptionDescRec defopt [X_resman::NDEFOPT];
262 };
263 
264 
265 
266 // -------------------------------------------------------------------------------------------
267 
268 
269 extern "C" int x_handler_error (Display *dpy, XErrorEvent *err);
270 
271 
272 class X_handler : public H_thread
273 {
274 public:
275 
276     X_handler (X_display *disp, Edest *dest, int ipid);
277     ~X_handler (void);
278 
279     void thr_main (void);
next_event(void)280     void next_event (void) { put_event (ITC_ip1q::N_MQ, 1); }
281 
282 private:
283 
284     int  _conn;
285 };
286 
287 
288 // -------------------------------------------------------------------------------------------
289 
290 
291 class X_callback
292 {
293 public:
294 
~X_callback(void)295     virtual ~X_callback (void) {}
296 
297     enum
298     {
299 	BUTTON    = 0x010000,
300 	TEXTIP    = 0x010100,
301 	ENUMIP    = 0x010200,
302 	ROTARY    = 0x010300,
303 	SLIDER    = 0x010400,
304         SCROLL    = 0x010500,
305 	MENU      = 0x010600,
306 	MCLIST    = 0x010700
307     };
308 
309     virtual void handle_callb (int /*type*/, X_window */*W*/, XEvent */*E*/) = 0;
cb_class(int k)310     static int cb_class (int k) { return k & 0xFFFFFF00; }
cb_event(int k)311     static int cb_event (int k) { return k & 0x000000FF; }
312 };
313 
314 
315 // -------------------------------------------------------------------------------------------
316 
317 
318 class X_draw
319 {
320 public:
321 
322     X_draw (Display *dpy, Drawable drw, GC gct, XftDraw *xft);
~X_draw(void)323     ~X_draw (void) {}
324 
setfont(XFontStruct * font)325     void setfont (XFontStruct *font) { _xft_font = 0; _x11_font = font; XSetFont (_dpy, _gct, font->fid); }
setfont(XftFont * font)326     void setfont (XftFont     *font) { _x11_font = 0; _xft_font = font; }
setcolor(unsigned long c)327     void setcolor (unsigned long c) { _xft_color = 0;  XSetForeground (_dpy, _gct, c); }
setcolor(XftColor * c)328     void setcolor (XftColor     *c) { _xft_color = c;  XSetForeground (_dpy, _gct, c->pixel); }
setfunc(int f)329     void setfunc (int f) { XSetFunction (_dpy, _gct, f); }
330     void setline (int d, int f = LineSolid, int c = CapButt, int j = JoinBevel) { XSetLineAttributes (_dpy, _gct, d, f, c, j); }
331     void setdash (char *v, int n, int i = 0) { XSetDashes (_dpy, _gct, i, v, n); }
move(int x,int y)332     void move (int x, int y) { _xx = x; _yy = y; }
rmove(int x,int y)333     void rmove (int x, int y) { _xx += x; _yy += y; }
draw(int x,int y)334     void draw (int x, int y) { XDrawLine (_dpy, _drw, _gct, _xx, _yy, x, y); _xx = x; _yy = y; }
rdraw(int x,int y)335     void rdraw (int x, int y) { XDrawLine (_dpy, _drw, _gct, _xx, _yy, _xx + x, _yy + y); _xx += x; _yy += y; }
drawline(int x0,int y0,int x1,int y1)336     void drawline (int x0, int y0, int x1, int y1) { XDrawLine (_dpy, _drw, _gct, x0, y0, x1, y1); }
drawrect(int x0,int y0,int x1,int y1)337     void drawrect (int x0, int y0, int x1, int y1) { XDrawRectangle (_dpy, _drw, _gct, x0, y0, x1 - x0, y1 - y0); }
fillrect(int x0,int y0,int x1,int y1)338     void fillrect (int x0, int y0, int x1, int y1) { XFillRectangle (_dpy, _drw, _gct, x0, y0, x1 - x0, y1 - y0); }
drawrect(int dx,int dy)339     void drawrect (int dx, int dy) { XDrawRectangle (_dpy, _drw, _gct, _xx, _yy, dx, dy); }
fillrect(int dx,int dy)340     void fillrect (int dx, int dy) { XFillRectangle (_dpy, _drw, _gct, _xx, _yy, dx, dy); }
drawarc(int dx,int dy,int a1,int a2)341     void drawarc (int dx, int dy, int a1, int a2)  { XDrawArc (_dpy, _drw, _gct, _xx, _yy, dx, dy, a1, a2); }
fillarc(int dx,int dy,int a1,int a2)342     void fillarc (int dx, int dy, int a1, int a2)  { XFillArc (_dpy, _drw, _gct, _xx, _yy, dx, dy, a1, a2); }
343     void movepix (int dx, int dy, int xs, int ys);
344     void setclip (int x0, int y0, int x1, int y1);
noclip(void)345     void noclip (void) { XSetClipMask (_dpy, _gct, None); }
346     void drawpoints (int n, XPoint *P);
347     void drawlines (int n, XPoint *P);
348     void drawsegments (int n, XSegment *S);
putimage(XImage * I)349     void putimage (XImage *I) { XPutImage (_dpy, _drw, _gct, I, 0, 0, _xx, _yy, I->width, I->height); }
clearwin(void)350     void clearwin (void) { XClearWindow (_dpy, _drw); }
351 
352     int  textwidth (const char *str);
textascent(void)353     int  textascent  (void) { return _xft_font ? _xft_font->ascent  : (_x11_font ? _x11_font->ascent  : 0); }
textdescent(void)354     int  textdescent (void) { return _xft_font ? _xft_font->descent : (_x11_font ? _x11_font->descent : 0); }
355     void drawstring (const char *str, int xal);
356 
357 private:
358 
359     Display      *_dpy;
360     Drawable      _drw;
361     GC            _gct;
362     XftDraw      *_xft_draw;
363     XftColor     *_xft_color;
364     XftFont      *_xft_font;
365     XFontStruct  *_x11_font;
366     int           _xx;
367     int           _yy;
368 };
369 
370 
371 // -------------------------------------------------------------------------------------------
372 
373 
374 class X_linked
375 {
376 private:
377 
X_linked(X_linked * back,X_linked * forw)378     X_linked (X_linked *back, X_linked *forw) :
379 	_back (back),
380 	_forw (forw)
381 	{
382 	    if (back) back->_forw = this;
383 	    if (forw) forw->_back = this;
384 	}
385 
~X_linked(void)386     virtual ~X_linked (void)
387 	{
388 	    if (_back) _back->_forw = _forw;
389 	    if (_forw) _forw->_back = _back;
390 	}
391 
392     virtual void select (void) = 0;
393 
394     friend class X_textip;
395     friend class X_enumip;
396 
397     X_linked *_back;
398     X_linked *_forw;
399 };
400 
401 
402 // -------------------------------------------------------------------------------------------
403 
404 
405 class X_button_style
406 {
407 public:
408 
409     enum { PLAIN = 0, BORDER = 1, RAISED = 2, ALEFT = 4, ARIGHT = 8, HOLDPTR = 16 };
410 
411     XftFont *font;
412     struct
413     {
414 	unsigned long bg [4];
415 	XftColor     *fg [4];
416 	struct
417 	{
418 	    unsigned long bgnd;
419 	    unsigned long lite;
420 	    unsigned long dark;
421 	} shadow;
422     } color;
423     struct
424     {
425 	int x;
426 	int y;
427     } size;
428     int type;
429 };
430 
431 
432 class X_button : public X_window
433 {
434 public:
435 
436     enum { MOVE, PRESS, RELSE };
437 
cbid(void)438     int  cbid (void) const { return _cbid; }
stat(void)439     int  stat (void) const { return _stat; }
set_cbid(int cbid)440     void set_cbid (int cbid) { _cbid = cbid; }
441     void release (void);
442     virtual void set_stat (int stat);
443     virtual void redraw (void);
444 
445 protected:
446 
447     X_button (X_window       *parent,
448 	      X_callback     *callb,
449 	      X_button_style *style,
450 	      int xp,
451 	      int yp,
452 	      int cbid);
453 
454     ~X_button (void);
455 
456     void handle_event (XEvent *E);
457     void expose (XExposeEvent *E);
458     void bpress (XButtonEvent *E);
459     void brelease (XButtonEvent *E);
460 
461     const X_button_style *_style;
462     X_callback     *_callb;
463     int             _xs;
464     int             _ys;
465     int             _cbid;
466     int             _down;
467     int             _stat;
468 };
469 
470 
471 class X_tbutton : public X_button
472 {
473 public:
474 
475     enum { MAXLEN = 24 };
476 
477     X_tbutton (X_window       *parent,
478 	       X_callback     *callb,
479 	       X_button_style *style,
480 	       int             xp,
481 	       int             yp,
482 	       const char     *text1 = 0,
483 	       const char     *text2 = 0,
484 	       int             cbid = 0);
485 
486     ~X_tbutton (void);
487 
488     virtual void redraw (void);
489 
set_col(unsigned long bg,XftColor * fg)490     void set_col (unsigned long bg, XftColor *fg) { _bg = bg, _fg = fg; }
491     void set_text (const char *txt1, const char *txt2);
text1(void)492     const char   *text1 (void) const { return _text1; }
text2(void)493     const char   *text2 (void) const { return _text2; }
494 
495 private:
496 
497     unsigned long   _bg;
498     XftColor       *_fg;
499     int             _len1;
500     int             _len2;
501     char            _text1 [MAXLEN];
502     char            _text2 [MAXLEN];
503 };
504 
505 
506 class X_ibutton : public X_button
507 {
508 public:
509 
510     enum { MAXLEN = 24 };
511 
512     X_ibutton (X_window       *parent,
513 	       X_callback     *callb,
514 	       X_button_style *style,
515 	       int             xp,
516 	       int             yp,
517                XImage         *image,
518 	       int             cbid = 0);
519 
520     ~X_ibutton (void);
521 
522     virtual void redraw (void);
523 
set_col(unsigned long bg,unsigned long fg)524     void set_col (unsigned long bg, unsigned long fg) { _bg = bg, _fg = fg; }
set_image(XImage * image)525     void set_image (XImage *image) { _image = image; }
image(void)526     const XImage *image (void) const { return _image; }
527 
528 private:
529 
530     unsigned long   _bg;
531     unsigned long   _fg;
532     XImage         *_image;
533 };
534 
535 
536 class X_pbutton : public X_button
537 {
538 public:
539 
540     X_pbutton (X_window       *parent,
541 	       X_callback     *callb,
542 	       X_button_style *style,
543 	       int             xp,
544 	       int             yp,
545                Pixmap          map0,
546                Pixmap          map1,
547  	       int             cbid = 0);
548 
549     ~X_pbutton (void);
550 
551     virtual void set_stat (bool stat);
552 
map0(void)553     const Pixmap map0 (void) const { return _map0; }
map1(void)554     const Pixmap map1 (void) const { return _map1; }
555 
556 private:
557 
558     Pixmap _map0;
559     Pixmap _map1;
560 };
561 
562 
563 // -------------------------------------------------------------------------------------------
564 
565 
566 class X_scroll : public X_window, public X_callback
567 {
568 public:
569 
570     enum { ENDGAP = 1, PLUSMIN = 2, MIDGAP = 4, ARROWS = 8 };
571     enum { MOVE, STOP, C1LU, C3LU, C1RD, C3RD, B1LU, B3LU, B1RD, B3RD, B1PL, B3PL, B1MI, B3MI, MB4, MB5 };
572 
573     void redraw (void);
574 
575     X_scroll (X_window       *parent,
576 	      X_callback     *callb,
577 	      X_button_style *style,
578 	      int xp,
579 	      int yp,
580               int xs,
581               int ys,
582               int opts);
583 
584     ~X_scroll (void);
585 
offs(void)586     float offs (void) const { return _offs; }
frac(void)587     float frac (void) const { return _frac; }
588     void  geom (float offs, float frac, int size = 0);
589     void  move (float drel);
590 
591 private:
592 
593     void handle_event (XEvent *E);
594     void bpress (XButtonEvent *E);
595     void brelease (XButtonEvent *E);
596     void bmotion (XMotionEvent *E);
597     void expose (XExposeEvent *E);
598 
599     virtual void handle_callb (int type, X_window *W, XEvent *E);
600 
601     const X_button_style *_style;
602     X_callback           *_callb;
603     int             _xs;
604     int             _ys;
605     int             _km;
606     int             _k0;
607     int             _dk;
608     int             _dw;
609     int             _zz;
610     float           _offs;
611     float           _frac;
612 };
613 
614 
615 // -------------------------------------------------------------------------------------------
616 
617 
618 class X_textln_style
619 {
620 
621 public:
622 
623     XftFont   *font;
624     struct
625     {
626 	struct
627 	{
628 	    unsigned long bgnd;
629 	    XftColor     *text;
630 	} normal;
631 	struct
632 	{
633 	    unsigned long bgnd;
634 	    XftColor     *text;
635 	    unsigned long line;
636 	} focus;
637 	struct
638 	{
639 	    unsigned long bgnd;
640 	    unsigned long lite;
641 	    unsigned long dark;
642 	} shadow;
643     } color;
644 };
645 
646 
647 // -------------------------------------------------------------------------------------------
648 
649 
650 class X_textln : public X_window
651 {
652 public:
653 
654     X_textln (X_window         *parent,
655 	      X_textln_style   *style,
656 	      int xp,
657               int yp,
658 	      int xs,
659               int ys,
660               const char *text,
661               int xal);
662 
663     ~X_textln (void);
664 
base(void)665     int base (void) const { return _y0; };
666 
667 private:
668 
669     void handle_event (XEvent *xe);
670     void expose (XExposeEvent *e);
671 
672     X_textln_style  *_style;
673     const char      *_text;
674     int              _len;
675     int              _x0;
676     int              _y0;
677 };
678 
679 
680 // -------------------------------------------------------------------------------------------
681 
682 
683 class X_textip : public X_window, public X_linked
684 {
685 public:
686 
687     enum { KEY, BUT, MODIF };
688 
689     X_textip (X_window         *parent,
690 	      X_callback       *callb,
691 	      X_textln_style   *style,
692 	      int xp,
693               int yp,
694 	      int xs,
695               int ys,
696 	      int max,
697 	      X_linked    *back = 0,
698 	      X_linked    *forw = 0);
699 
700     ~X_textip (void);
701 
702     void set_text (const char *txt);
703     void set_color (unsigned long bg, XftColor *fg);
704     void set_align (int xal);
705     void enable (void);
clear_modified(void)706     void clear_modified (void) { _flags |= CLEAR; }
callb_modified(void)707     void callb_modified (void) { if (_callb) _flags |= CALLB; }
708 
text(void)709     const char *text (void) { _txt [_i1] = 0; return (char *) _txt; }
base(void)710     int  base (void) const { return _y0; };
key(void)711     int  key  (void) const { return _key; }
forw(void)712     X_linked *forw (void) const { return _forw; }
back(void)713     X_linked *back (void) const { return _back; }
714 
715 private:
716 
717     enum { FOCUS = 1, CLEAR = 2, CALLB = 4, RIGHT = 8, CENTER = 16 };
718 
719     int  test_utf8 (int k, const unsigned char *t);
720     void insert (int k, const unsigned char *t);
721     void go_sol (void);
722     void go_lt (void);
723     void del_rt (void);
724     void go_eol (void);
725     void go_rt (void);
726     void del_eol (void);
727     void del_all (void);
728     void del_lt (void);
729     void spkey (XKeyEvent *e);
730     void cbkey (int k, XKeyEvent *e);
731 
732     void handle_event (XEvent *xe);
733     void expose (XExposeEvent *e);
734     void bpress (XButtonEvent *e);
735     void keypress (XKeyEvent *e);
736     void paste (XSelectionEvent *e);
737     void setfocus (XFocusChangeEvent *e);
738     void remfocus (XFocusChangeEvent *e);
739     void update (bool f);
740     void redraw (void);
741     void xorcursor (void);
742     void checkclear (void);
743     void checkcallb (void);
744     void select (void);
745     int  findindex (int x);
746     int  textwidth (int i, int n);
747 
748     X_callback     *_callb;
749     X_textln_style *_style;
750     unsigned long   _bg;
751     XftColor       *_fg;
752     int             _flags;
753     int             _xs;
754     int             _ys;
755     unsigned char  *_txt;
756     int             _max;
757     int             _key;
758     int             _ic;
759     int             _i1;
760     int             _xc;
761     int             _x0;
762     int             _x1;
763     int             _y0;
764 
765     static           XIC _xic;
766     static unsigned char _utf8mark [6];
767 };
768 
769 
770 // -------------------------------------------------------------------------------------------
771 
772 
773 class X_enip_item
774 {
775 public:
776     int         _code;
777     const char *_text;
778 };
779 
780 
781 class X_enumip : public X_window, public X_linked
782 {
783 public:
784 
785     enum { KEY, BUT };
786 
787     X_enumip (X_window *parent,
788 	      X_callback      *callb,
789 	      X_textln_style  *style,
790 	      int xp,
791               int yp,
792 	      int xs,
793               int ys,
794 	      X_enip_item     *list,
795 	      X_linked    *back = 0,
796 	      X_linked    *forw = 0);
797 
798     ~X_enumip (void);
799 
800     void set_ind (int ind);
base(void)801     int  base (void) const { return _y0; };
key(void)802     int  key  (void) const { return _key; }
ind(void)803     int  ind  (void) const { return _ind; }
804 
805     virtual void handle_event (XEvent *xe);
806 
807 private:
808 
809     void spkey (XKeyEvent *e);
810     void cbkey (int k);
811 
812     void expose (XExposeEvent *e);
813     void bpress (XButtonEvent *e);
814     void keypress (XKeyEvent *e);
815     void setfocus (XFocusChangeEvent *e);
816     void remfocus (XFocusChangeEvent *e);
817     void redraw (void);
818     int  textwidth (int i, int n);
819 
820     virtual void select (void);
821 
822     X_callback     *_callb;
823     X_textln_style *_style;
824     X_enip_item    *_list;
825     unsigned long   _bg;
826     XftColor       *_fg;
827     char           *_txt;
828     int             _ind;
829     int             _max;
830     int             _len;
831     int             _foc;
832     int             _key;
833     int             _xs;
834     int             _ys;
835     int             _x0;
836     int             _y0;
837 
838     static           XIC _xic;
839     static unsigned char _utf8mark [6];
840 };
841 
842 
843 // -------------------------------------------------------------------------------------------
844 
845 
846 class X_menuwin_style
847 {
848 public:
849 
850     enum { PLAIN = 0, BORDER = 1, RAISED = 2, PDOWN = 256 };
851 
852     XftFont       *font;
853     int            step;
854     int            type;
855     struct
856     {
857 	XftColor     *bg;
858 	XftColor     *fg [4];
859 	XftColor     *mm;
860 	struct
861 	{
862 	    unsigned long bgnd;
863 	    unsigned long lite;
864 	    unsigned long dark;
865 	} shadow;
866     } color;
867 };
868 
869 
870 class X_menuwin_item
871 {
872 public:
873 
874     enum { COLMASK = 3, TITLE = 0x010000, SPACE = 0x020000, LAST = 0x040000, MARK = 0x080000, MASKED = 0x100000 };
875 
876     const char      *_text;
877     int              _bits;
878     X_menuwin_item  *_link;
879 };
880 
881 
882 
883 class X_menuwin : public X_window
884 {
885 public:
886 
887     enum { OPEN, SEL, CAN };
888     enum { MAXITEM = 32, DL = 6, DR = 6 };
889 
890     X_menuwin (X_window         *parent,
891 	       X_callback       *callb,
892 	       X_menuwin_style  *style,
893 	       int xp,
894 	       int yp,
895 	       X_menuwin_item   *items);
896 
897     ~X_menuwin (void);
898 
899     void show (void);
900     void hide (void);
901     void set_mask (unsigned m);
902     void clr_mask (unsigned m);
xs(void)903     int xs (void) { return _xs; }
ys(void)904     int ys (void) { return _ys; }
selection(void)905     int selection (void) { return _isel; }
906 
907 
908 private:
909 
910     void handle_event (XEvent *E);
911     void expose (XExposeEvent *E);
912     void enter (XEnterWindowEvent *E);
913     void leave (XLeaveWindowEvent *E);
914     void motion (XPointerMovedEvent *E);
915     void bpress (XButtonEvent *E);
916     void brelse (XButtonEvent *E);
917     void redraw (bool clear);
918     void drawit (int k, bool inv);
919     void select (int k);
920     int  findit (int x, int y);
921 
922     const X_menuwin_style *_style;
923     X_callback            *_callb;
924     X_menuwin_item        *_items;
925     int             _xs;
926     int             _ys;
927     int             _nit;
928     int             _isel;
929     int             _open;
930     int             _ypos [MAXITEM];
931     int             _tlen [MAXITEM];
932 };
933 
934 
935 // -------------------------------------------------------------------------------------------
936 
937 
938 class X_scale_style
939 {
940 
941 public:
942 
943     enum { SEGMAX = 20 };
944 
945     int             marg;
946     int             nseg;
947     int             pix  [SEGMAX + 1];
948     float           val  [SEGMAX + 1];
949     const char     *text [SEGMAX + 1];
950     XftFont        *font;
951     unsigned long   bg;
952     XftColor       *fg;
953 
set_tick(int i,int p,float v,const char * t)954     void   set_tick (int i, int p, float v, const char *t) { pix [i] = p; val [i] = v; text [i] = t; }
set_text(int i,const char * t)955     void   set_text (int i, const char *t) { text [i] = t; }
pixlen(void)956     int    pixlen (void) const { return pix [0] + pix [nseg] + 1; }
length(void)957     int    length (void) const { return 2 * marg + pixlen (); }
958     int    limit (int i);
959     int    calcpix (float x);
960     float  calcval (int p);
961 };
962 
963 
964 class X_hscale : public X_window
965 {
966 public:
967 
968     X_hscale (X_window       *parent,
969 	      X_scale_style  *style,
970 	      int xp,
971 	      int yp,
972 	      int h,
973 	      int d = 0);
974 
975 private:
976 
977     void handle_event (XEvent *xe);
978     void expose (XExposeEvent *e);
979 
980     X_scale_style  *_style;
981     int      _h;
982     int      _d;
983 };
984 
985 
986 class X_vscale : public X_window
987 {
988 public:
989 
990     X_vscale (X_window       *parent,
991 	      X_scale_style  *style,
992 	      int xp,
993 	      int yp,
994 	      int w,
995 	      int d = 0);
996 
997 private:
998 
999     void handle_event (XEvent *xe);
1000     void expose (XExposeEvent *e);
1001 
1002     X_scale_style  *_style;
1003     int      _w;
1004     int      _d;
1005 };
1006 
1007 
1008 // -------------------------------------------------------------------------------------------
1009 
1010 
1011 class X_meter_style
1012 {
1013 public:
1014 
1015     unsigned long bg;
1016     struct
1017     {
1018         unsigned long c0;
1019         unsigned long c1;
1020         unsigned long mk;
1021     } off;
1022     struct
1023     {
1024         unsigned long c0;
1025         unsigned long c1;
1026         unsigned long mk;
1027     } act;
1028 };
1029 
1030 
1031 class X_meter : public X_window
1032 {
1033 public:
1034 
1035     X_meter (X_window *parent, X_meter_style *style, X_scale_style *scale, int xp, int yp, int xs, int ys);
1036 
1037     void handle_event (XEvent *xe);
1038     void set_val (float v);
1039     void set_ref (float v);
1040 
1041     friend class X_hmeter;
1042     friend class X_vmeter;
1043 
1044 private:
1045 
1046     void expose (XExposeEvent *e);
1047     void plotsect (int i0, int i1, int imin, int imax, int cl, int cr);
1048     void plotmarks (int a, int b, unsigned long c);
1049 
1050     virtual void psect (GC g, int a, int b) = 0;
1051     virtual void pmark (GC g, int a) = 0;
1052 
1053     X_meter_style  *_style;
1054     X_scale_style  *_scale;
1055 
1056     int      _x;
1057     int      _y;
1058     int      _d;
1059     int      _i;
1060     int      _s;
1061     int      _d0;
1062     int      _d1;
1063     int      _d2;
1064 };
1065 
1066 
1067 class X_hmeter : public X_meter
1068 {
1069 public:
1070 
1071     X_hmeter (X_window *parent, X_meter_style *style, X_scale_style *scale, int xp, int yp, int h);
1072 
1073 private:
1074 
1075     virtual void psect (GC g, int a, int b);
1076     virtual void pmark (GC g, int a);
1077 };
1078 
1079 
1080 class X_vmeter : public X_meter
1081 {
1082 public:
1083 
1084     X_vmeter (X_window *parent, X_meter_style *style, X_scale_style *scale, int xp, int yp, int w);
1085 
1086 private:
1087 
1088     virtual void psect (GC g, int a, int b);
1089     virtual void pmark (GC g, int a);
1090 };
1091 
1092 
1093 // -------------------------------------------------------------------------------------------
1094 
1095 
1096 class X_slider_style
1097 {
1098 public:
1099 
1100   unsigned long bg;
1101   unsigned long lite;
1102   unsigned long dark;
1103   unsigned long knob;
1104   unsigned long mark;
1105   int           w;
1106   int           h;
1107 };
1108 
1109 
1110 class X_slider : public X_window
1111 {
1112 public:
1113 
1114     enum { MOVE, STOP };
1115 
1116     X_slider (X_window *parent,
1117               X_callback *callb,
1118               X_slider_style *style,
1119               X_scale_style *scale,
1120               int xp, int yp,
1121               int xs, int ys,
1122               int cbid = 0);
1123 
1124     virtual void set_val (float v) = 0;
1125     virtual void set_color (unsigned long knob, unsigned long mark) = 0;
get_val(void)1126     float get_val (void) { return _scale->calcval (_i); }
cbid(void)1127     int   cbid (void) const { return _cbid; }
1128 
1129     friend class X_hslider;
1130     friend class X_vslider;
1131 
1132 private:
1133 
1134     void brelease (XButtonEvent *E);
1135 
1136     X_callback      *_callb;
1137     X_slider_style  *_style;
1138     X_scale_style   *_scale;
1139 
1140     int      _x;
1141     int      _y;
1142     int      _i;
1143     int      _d;
1144     int      _cbid;
1145     unsigned long  _knob;
1146     unsigned long  _mark;
1147 };
1148 
1149 
1150 class X_hslider : public X_slider
1151 {
1152 public:
1153 
1154     X_hslider (X_window *parent,
1155                X_callback *callb,
1156                X_slider_style *style,
1157                X_scale_style *scale,
1158                int xp, int yp,
1159                int h,
1160                int cbid);
1161 
1162     virtual void handle_event (XEvent *E);
1163     virtual void set_color (unsigned long knob, unsigned long mark);
1164     virtual void set_val (float v);
1165 
1166 private:
1167 
1168     bool domove (int i);
1169     void plines (void);
1170     void plknob (int i);
1171     void erase (int i);
1172 };
1173 
1174 
1175 class X_vslider : public X_slider
1176 {
1177 public:
1178 
1179     X_vslider (X_window *parent,
1180                X_callback *callb,
1181                X_slider_style *style,
1182                X_scale_style *scale,
1183                int xp, int yp,
1184                int w,
1185                int cbid);
1186 
1187     virtual void handle_event (XEvent *E);
1188     virtual void set_color (unsigned long knob, unsigned long mark);
1189     virtual void set_val (float v);
1190 
1191 private:
1192 
1193     bool domove (int i);
1194     void plines (void);
1195     void plknob (int i);
1196     void erase (int i);
1197 };
1198 
1199 
1200 // -------------------------------------------------------------------------------------------
1201 
1202 
1203 class X_mclist_style
1204 {
1205 public:
1206 
1207     unsigned long   bg;
1208     XftColor       *fg [4];
1209     XftFont        *font;
1210     int             dy;
1211 };
1212 
1213 
1214 class X_mclist : public X_window
1215 {
1216 public:
1217 
1218     enum { OPEN, SEL, CAN, MB4, MB5 };
1219 
1220     X_mclist (X_window        *parent,
1221 	      X_callback      *callb,
1222 	      X_mclist_style  *style,
1223 	      int             xp,
1224 	      int             yp,
1225 	      int             xs,
1226 	      int             ys,
1227 	      int             max_item,
1228 	      int             max_char);
1229 
1230     ~X_mclist (void);
1231 
reset(void)1232     void reset (void) { _n_item = _n_char = 0; _sel = -1; }
1233     int  item (const char *txt, int col, int len = 0);
1234     void sort (void);
1235     void show (void);
1236     void move (int offs);
1237     void resize (int xs, int ys);
1238     void forw (void);
1239     void back (void);
1240 
xs(void)1241     int  xs (void) const { return _xs; }
ys(void)1242     int  ys (void) const { return _ys; }
span(void)1243     int  span (void) const { return _span; }
offs(void)1244     int  offs (void) const { return _offs; }
ptr(void)1245     const char *ptr (void) const { return _ptr [_sel]; }
col(void)1246     int col (void) const { return _col [_sel]; }
len(void)1247     int len (void) const { return _len [_sel]; }
1248 
1249 private:
1250 
1251     void handle_event (XEvent *xE);
1252     void expose (XExposeEvent *E);
1253     void bpress (XButtonEvent *E);
1254     void update (int xx, int yy, int ww, int hh);
1255     int  find (int x, int y);
1256     void enter (XEnterWindowEvent * E);
1257     void leave (XLeaveWindowEvent * E);
1258     void motion (XPointerMovedEvent * E);
1259     void hilite (int ind);
1260     void drawhl (int ind);
1261 
1262     X_mclist_style  *_style;
1263     X_callback      *_callb;
1264     int      _max_item;
1265     int      _max_char;
1266     int      _n_item;
1267     int      _n_char;
1268     int      _xs;
1269     int      _ys;
1270     int      _offs;
1271     int      _span;
1272     int      _nrow;
1273     int      _nclm;
1274     int      _sel;
1275     char    *_buff;
1276     char   **_ptr;
1277     short   *_len;
1278     short   *_ext;
1279     short   *_col;
1280     int     *_ind;
1281     int     *_dxc;
1282 };
1283 
1284 
1285 // -------------------------------------------------------------------------------------------
1286 
1287 
1288 #endif
1289 
1290