original 1.0.1 release
[xwelltris.git] / src / x11 / xwellinput.cxx
blob9d07d40120694ac883111729d178d1e6e184dead
1 // docm_prefix(///)
2 /****************************************************************************
3 * Copyright (C) 2002 by Leo Khramov
4 * email: leo@xnc.dubna.su
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 ****************************************************************************/
16 // $Id: xwellinput.cxx,v 1.1.1.1 2003/01/04 11:37:22 leo Exp $
18 /// module description
19 /// X11 implementation of WellInput class - make input text from user
20 /// display it through WellImageFont, convert X11 Key event to symbols
22 #include "xwellinput.h"
23 #include "xwellengine.h"
25 //===========================================================================
26 /// global XWellInput(char*)
27 /// constructor - fill name and get geometry
28 /// tags XWellInput
29 XWellInput::XWellInput(char* iname) : WellInput(iname)
31 xengine=(XWellEngine*) default_well_engine;
32 mainw=xengine->get_main_window();
33 maingc=xengine->get_main_gc();
36 //===========================================================================
37 /// global process_event(wEvent)
38 /// stub that process events
39 /// tags XWellInput
40 bool XWellInput::process_event(wEvent ev)
42 XEvent *xev=(XEvent*)ev.data;
43 switch(ev.type)
45 case eKeyPress:
46 process_key(xev);
47 return false;
50 return true;
53 //===========================================================================
54 /// global draw_text()
55 /// draw text on the screen
56 /// tags XWellInput
57 void XWellInput::draw_text()
59 unsigned long *colors=xengine->get_colors();
60 fnt->draw_text(buf,buflen,BackColor);
61 XSetForeground(disp,maingc,colors[BonusColor2]);
62 XFillRectangle(disp,mainw,maingc,geo[1].tox+buflen*FONT2_L,geo[1].toy,
63 FONT2_L,FONT2_H);
66 //===========================================================================
67 /// global process_key(XEvent)
68 /// draw text on the screen
69 /// tags XWellInput
70 void XWellInput::process_key(XEvent *xev)
72 KeySym ks;
73 XComposeStatus cs;
75 char sym[4]="";
76 XLookupString(&xev->xkey, sym, 4, &ks, &cs);
77 switch(ks)
79 case XK_Return:
80 if(buflen)
81 object_on_enter.call(wEvent(aInputDone,this));
82 break;
84 case XK_Delete:
85 case XK_BackSpace:
86 if(buflen>0)
88 buflen--;
89 buf[buflen]=0;
90 draw_text();
92 break;
93 default:
94 if(buflen<maxlen && sym[0]>=32 && sym[0]<127)
96 buf[buflen++]=sym[0];
97 buf[buflen]=0;
98 draw_text();