Laxkit  0.0.7.1
anxapp.h
1 //
2 //
3 // The Laxkit, a windowing toolkit
4 // Please consult http://laxkit.sourceforge.net about where to send any
5 // correspondence about this software.
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //
21 // Copyright (C) 2004-2013 by Tom Lechner
22 //
23 #ifndef _LAX_ANXAPP_H
24 #define _LAX_ANXAPP_H
25 
26 #include <lax/configured.h>
27 
28 #ifdef _LAX_PLATFORM_XLIB
29 #include <X11/Xlib.h>
30 //#include <X11/Xft/Xft.h>
31 #include <X11/Xutil.h>
32 #include <X11/extensions/Xdbe.h>
33 #endif //_LAX_PLATFORM_XLIB
34 
35 
36 #include <sys/times.h>
37 #include <pthread.h>
38 
39 #include <lax/anobject.h>
40 #include <lax/dump.h>
41 #include <lax/lists.h>
42 #include <lax/laxdefs.h>
43 #include <lax/laxdevices.h>
44 #include <lax/events.h>
45 #include <lax/fontmanager.h>
46 #include <lax/attributes.h>
47 #include <lax/misc.h>
48 #include <lax/tagged.h>
49 #include <lax/laxdevices.h>
50 #include <lax/shortcuts.h>
51 #include <lax/laximages.h>
52 
53 namespace Laxkit {
54 
55 class anXWindow;
56 class anXApp;
57 class DeviceManager;
58 class Displayer;
59 
60 //----------------------------- Misc ------------------------------
61 
62 anXWindow *TopWindow(anXWindow *win);
63 int IsWindowChild(anXWindow *top,anXWindow *check);
64 
65 #ifdef _LAX_PLATFORM_XLIB
66 unsigned int filterkeysym(KeySym keysym,unsigned int *state);
67 const char *xlib_event_name(int e_type);
68 const char *xlib_extension_event_name(int e_type);
69 #endif //_LAX_PLATFORM_XLIB
70 
71 
72 //----------------------- Styling functions ----------------------------
73 //---------------------- WindowColors
74 class WindowColors : public anObject
75 {
76  public:
77  unsigned long fg; //8 bit argb
78  unsigned long bg;
79  unsigned long hfg;
80  unsigned long hbg;
81  unsigned long moverfg; // (assume highlighted irrelevant)
82  unsigned long moverbg;
83  unsigned long grayedfg; //assume bg is same as normal bg
84  unsigned long color1;
85  unsigned long color2;
86 
87  WindowColors();
88  WindowColors(const WindowColors &l);
90 };
91 
93 //class WindowFonts : public anObject
94 //{
95 // public:
96 // //fonts for normal use in menus, panels, and messages
97 // LaxFont *normal;
98 // LaxFont *bold;
99 // LaxFont *italic;
100 //
101 // //default font in simple edits
102 // LaxFont *edit;
103 //
104 // WindowFonts();
105 // ~WindowFonts();
106 //};
107 //
108 //WindowFonts::WindowFonts()
109 //{ normal=bold=italic=edit=NULL; }
110 //
111 //WindowFonts::~WindowFonts()
112 //{
113 // if (normal) normal->dec_count();
114 // if (bold) bold->dec_count();
115 // if (italic) italic->dec_count();
116 // if (edit) edit->dec_count();
117 //}
118 
119 
120 //-------------------------- aDrawable ----------------------------------------
122 {
123  public:
124 #ifdef _LAX_PLATFORM_XLIB
125  XdbeBackBuffer xlib_backbuffer;
126  Window xlib_window;
127  Drawable xlibDrawable(int which=-1);
128 #endif
129 
130  aDrawable(Drawable d=0) { xlib_window=d; xlib_backbuffer=None; };
131  virtual ~aDrawable() {}
132  virtual int DrawableType() { return 1; }
133  virtual int ValidDrawable() { if (xlib_window) return 1; else return 0; }
134 };
135 
136 //-------------------------- anXWindow ----------------------------------------
137 
138 #define ANXWIN_MASK (0xffff)
139 #define ANXWIN_TRANSIENT (1<<0)
140 #define ANXWIN_NOT_DELETEABLE (1<<1)
141 #define ANXWIN_GRAYED (1<<2)
142 #define ANXWIN_REMEMBER (1<<3)
143 #define ANXWIN_XDND_AWARE (1<<4)
144 #define ANXWIN_HOVER_FOCUS (1<<5)
145 #define ANXWIN_NO_INPUT (1<<6)
146 #define ANXWIN_BARE (1<<7)
147 //center window when initially mapped
148 #define ANXWIN_CENTER (1<<8)
149 //make fullscreen on initial map
150 #define ANXWIN_FULLSCREEN (1<<9)
151 //works with deletenow()
152 #define ANXWIN_ESCAPABLE (1<<10)
153 #define ANXWIN_DOUBLEBUFFER (1<<11)
154 #define ANXWIN_DOOMED (1<<12)
155 #define ANXWIN_OUT_CLICK_DESTROYS (1<<13)
156 //-------------------
157 
158  // note that care must be taken here, are these defines constant across Xlibs?
159  // should be KeyPress/KeyRelease/ButtonPress/ButtonRelease/MotionNotify/Enter/Leave/FocusIn/Out/GraphicsExpose/Expose
160 #define LAX_DIALOG_ALL_MASK (1|2|4|8|16|32|64|(1<<15)|(1<<21))
161  // INPUTS blocks pointer/key/enter/leave/focusin/out events, lets Expose through
162 #define LAX_DIALOG_INPUTS (1|2|4|8|16|32|64|(1<<21))
163 
164 class anXWindow : virtual public EventReceiver,
165  virtual public Tagged,
166  virtual public LaxFiles::DumpUtility,
167  virtual public aDrawable
168 {
169  friend class anXApp;
170 
171 #ifdef _LAX_PLATFORM_XLIB
172  protected:
173  // double buffer specific stuff:
174 
175  //drag and drop helper functions
176  virtual int selectionDropped(const unsigned char *data,unsigned long len,Atom actual_type,Atom which);
177  virtual int selectionPaste(char mid, Atom targettype);
178  virtual int selectionCopy(char mid);
179  virtual char *getSelectionData(int *len,Atom property,Atom targettype,Atom selection);
180  public:
181  // Very X specific stuff about window status and event capture.
182  XWMHints *xlib_win_hints;
183  XSizeHints *xlib_win_sizehints;
184  XSetWindowAttributes xlib_win_xatts;
185  unsigned long xlib_win_xattsmask;
186 
187  virtual int event(XEvent *e);
188 #endif //_LAX_PLATFORM_XLIB
189 
190 
191  protected:
192  char *win_tooltip;
193  int needtodraw;
194 
196  virtual int deletekid(anXWindow *w);
197 
198  // double buffer specific stuff:
199  virtual void SwapBuffers();
200  virtual void SetupBackBuffer();
201  public:
202 
203  WindowColors *win_colors;
204  anXApp *app;
205  char *win_name;
206  char *win_title;
207  anXWindow *win_parent;
208  int win_screen;
209  unsigned long win_style;
210  int win_x,win_y,win_w,win_h;
211  unsigned int win_border;
213  char win_on;
215 
216  //core functions needed by anXApp
217  anXWindow(anXWindow *parnt, const char *nname, const char *ntitle,
218  unsigned long nstyle,
219  int xx,int yy,int ww,int hh,int brder,
220  anXWindow *prev,unsigned long nowner,const char *nsend);
221  virtual ~anXWindow();
222  virtual const char *whattype() { return "anXWindow"; }
223  virtual const char *WindowTitle(int which=0);
224  virtual void WindowTitle(const char *newtitle);
225  virtual const char *tooltip(int mouseid=0);
226  virtual const char *tooltip(const char *newtooltip);
227  virtual anXWindow *findChildWindowByTitle(const char *title);
228  virtual anXWindow *findChildWindowByName(const char *name);
229  virtual int Grayed();
230  virtual int Grayed(int g);
231  virtual int preinit();
232  virtual int init() { return 0; }
233  virtual int close();
234  virtual int Idle(int tid=0) { return 1; }
235  virtual void Refresh() { Needtodraw(0); }
236  virtual Displayer *MakeCurrent();
237  virtual int Needtodraw() { return needtodraw; }
238  virtual void Needtodraw(int nntd) { needtodraw=nntd; }
239  virtual int deletenow() { return 1; }
240 
241  //style functions
242  virtual int setWinStyle(unsigned int stylebit, int newvalue);
243  virtual int getWinStyle(unsigned int stylebit);
244  virtual void installColors(WindowColors *newcolors);
245  virtual ShortcutHandler *GetShortcuts();
246  virtual int PerformAction(int action_number);
247 
248  //event dispatching functions
249  virtual int Event(const EventData *data,const char *mes);
250  virtual int ExposeChange(ScreenEventData *e) { Needtodraw(1); return 0; }
251 
252  virtual int DeviceChange(const DeviceEventData *e) { return 1; }
253  virtual int CharInput(unsigned int ch, const char *buffer,int len,unsigned int state, const LaxKeyboard *kb);
254  virtual int KeyUp(unsigned int ch,unsigned int state, const LaxKeyboard *kb) { return 1; }
255  virtual int MouseMove (int x,int y,unsigned int state, const LaxMouse *m) { return 1; }
256  virtual int ButtonDown(int button, int x,int y,unsigned int state,int count, const LaxMouse *m) { return 1; }
257  virtual int ButtonUp (int button, int x,int y,unsigned int state, const LaxMouse *m) { return 1; }
258  virtual int LBDown(int x,int y,unsigned int state,int count,const LaxMouse *d) { return 1; }
259  virtual int LBUp(int x,int y,unsigned int state,const LaxMouse *d) { return 1; }
260  virtual int MBDown(int x,int y,unsigned int state,int count,const LaxMouse *d) { return 1; }
261  virtual int MBUp(int x,int y,unsigned int state,const LaxMouse *d) { return 1; }
262  virtual int RBDown(int x,int y,unsigned int state,int count,const LaxMouse *d) { return 1; }
263  virtual int RBUp(int x,int y,unsigned int state,const LaxMouse *d) { return 1; }
264  virtual int WheelUp(int x,int y,unsigned int state,int count,const LaxMouse *d) { return 1; }
265  virtual int WheelDown(int x,int y,unsigned int state,int count,const LaxMouse *d) { return 1; }
266 
267  virtual int FocusOn(const FocusChangeData *e);
268  virtual int FocusOff(const FocusChangeData *e);
269 
270  virtual int MoveResize(int nx,int ny,int nw,int nh);
271  virtual int Resize(int nw,int nh);
272 
273  public:
274  //control related stuff
275  unsigned long win_owner;
276  unsigned int win_owner_send_mask;
278 
279  virtual void contentChanged(); //this sends a ContentChange message to owners
280  virtual void selectionChanged(); //calling this sends a SelectionChange message to owners
281 
282  anXWindow *nextcontrol,*prevcontrol;
283  virtual anXWindow *GetController();
284  virtual int SelectNextControl(const LaxDevice *d);
285  virtual int SelectPrevControl(const LaxDevice *d);
286  virtual void ControlActivation(int on);
287  virtual int AddPrevControl(anXWindow *prev) { return ConnectControl(prev,0); }
288  virtual int AddNextControl(anXWindow *next) { return ConnectControl(next,1); }
289  virtual int ConnectControl(anXWindow *towhat, int after=1);
290  virtual int CloseControlLoop();
291  virtual void SetOwner(anXWindow *nowner,const char *mes=NULL, unsigned int send_mask=0);
292  virtual void SetOwner(unsigned long nowner_id,const char *mes=NULL, unsigned int send_mask=0);
293 
294  //serializing aids
295  virtual void dump_out(FILE *f,int indent,int what,anObject *context);
296  virtual LaxFiles::Attribute *dump_out_atts(LaxFiles::Attribute *att,int what,anObject *context);
297  virtual void dump_in_atts(LaxFiles::Attribute *att,int flag,anObject *context);
298 };
299 
300 //-------------------------- TimerInfo ----------------------------------------
301 struct TimerInfo
302 {
303  int id;
304  long info;
305  clock_t endtime,firsttick,ticktime;
306  clock_t nexttime;
307  anXWindow *win;
308 
309  TimerInfo() { info=0; id=0; endtime=firsttick=ticktime=nexttime=0; win=NULL; }
310  TimerInfo(anXWindow *nwin,int duration,int firstt,int tickt,int nid,long ninfo);
311  int checktime(clock_t tm);
312 };
313 
314 //--------------------------- ScreenInformation -------------------------------
316 {
317  public:
318  int screen; //screen number
319  int x,y, width,height;
320  double mmwidth,mmheight;
321  int depth;
322  int virtualscreen; //id of virtual screen, if screen is part of a larger setup
323 };
324 
325 //---------------------------- anXApp --------------------------------------
326 class anXApp : virtual public anObject
327 {
328 
329 #ifdef _LAX_PLATFORM_XLIB
330  protected:
331  //X specific protected functions
332  virtual void settimeout(struct timeval *timeout);
333  virtual void processXevent(XEvent *event);
334 
335  public:
336  //X specific variables
337  char donotusex;
338  char use_xinput;
339  Display *dpy;
340  int screen;
341  int *xscreeninfo;
342  Visual *vis;
343  Window bump_xid;
344 
345  //x input method variables *** not mpx compliant, fix me!!
346  LaxDevice *xim_current_device;
347  unsigned long xim_current_window;
348  char xic_is_over_the_spot;
349  XIM xim;
350  XIC xim_ic;
351  XFontSet xim_fontset;
352  unsigned int xim_deadkey;
353  int filterKeyEvents(LaxKeyboard *kb, anXWindow *win,
354  XEvent *e,unsigned int &key, char *&buffer, int &len, unsigned int &state);
355 
356 
357  //X specific public functions
358  virtual XIC CreateXInputContext();
359  virtual GC gc(int scr=0, int id=0);
360  virtual anXWindow *findwindow_xlib(Window win);
361  virtual anXWindow *findsubwindow_xlib(anXWindow *w,Window win);
362  virtual int xlib_ScreenInfo(int screen,int *width,int *height,int *mmwidth,int *mmheight,int *depth);
363  virtual void reselectForXEvents(anXWindow *win);
364 #endif //_LAX_PLATFORM_XLIB
365 
366  virtual anXWindow *findwindow_by_id(unsigned long id);
367  virtual anXWindow *find_subwindow_by_id(anXWindow *w,unsigned long id);
368 
369  private:
370  protected:
372  LaxImage *default_icon;
373  char *default_icon_file;
374  char *copybuffer;
375 
376  char dontstop;
377  unsigned long dialog_mask;
381  RefPtrStack<anXWindow> outclickwatch;
383  PtrStack<EventReceiver> eventreceivers;
384  EventData *dataevents,*dataevente;
386  pthread_mutex_t event_mutex;
388  //int bump_fd;
389 
390  int ttcount;
391  void newToolTip(const char *text,int mouseid);
392 
393  //initialization helpers
394  virtual void setupdefaultcolors();
395  virtual int getlaxrc(const char *filename,const char *profile);
396  virtual void dump_in_rc(LaxFiles::Attribute *att, const char *profile);
397  virtual void dump_out_rc(FILE *f, const char *profile, int indent, int what);
398  virtual void dump_in_colors(LaxFiles::Attribute *att);
399 
400  //event loop helper functions
401  virtual void destroyqueued();
402  virtual void resetkids(anXWindow *w);
403  virtual void deactivatekids(anXWindow *ww);
404  virtual void idle(anXWindow *w);
405  virtual int refresh(anXWindow *w);
406  virtual int processdataevents();
407  virtual int processSingleDataEvent(EventReceiver *obj,EventData *ee);
408  virtual int checkOutClicks(EventReceiver *obj,MouseEventData *ee);
409  virtual int managefocus(anXWindow *ww, EventData *ev);
410  virtual void tooltipcheck(EventData *event, anXWindow *ww);
411 
412  public:
413 
414  //Other public variables
415  anXWindow *currentfocus;
416  static anXApp *app;
417  const char *backend;
418  char *app_profile;
420  FontManager *fontmanager;
421  LaxFont *defaultlaxfont;
423  char *textfontstr;
424  DeviceManager *devicemanager;
425 
426  int tooltips;
427  PtrStack<LaxDevice> tooltipmaybe;
428 
429  //default Styling
430  WindowColors *color_panel, *color_menu, *color_edits, *color_buttons;
431  unsigned long color_tooltip_bg, color_tooltip_fg;
432  unsigned long color_activeborder, color_inactiveborder;
433  int default_border_width;
434  int default_padx;
435  int default_pady;
436  int default_bevel;
437 
438  unsigned int dblclk,firstclk,idleclk;
439 
440  char *load_dir;
441  char *save_dir;
442 
443  //Other functions
444  anXApp();
445  virtual ~anXApp();
446  virtual const char *whattype() { return "anXApp"; }
447 
448  //app main operational functions
449  virtual int Theme(const char *theme);
450  virtual int Backend(const char *which);
451  virtual int init(int argc,char **argv);
452  virtual int initX(int argc,char **argv);
453  virtual int initNoX(int argc,char **argv);
454  virtual int run();
455  virtual int close();
456  virtual void quit() { dontstop=0; }
457 
458  //resources
459  virtual int Tooltips(int on);
460  virtual int has(int what);
461  virtual LaxFiles::Attribute *Resource(const char *name);
462  virtual int Resource(LaxFiles::Attribute *resource);
463  virtual int DefaultIcon(const char *file);
464  virtual int DefaultIcon(LaxImage *image, int absorb_count);
465  virtual int ScreenInfo(int screen,int *x,int *y, int *width,int *height,int *mmwidth,int *mmheight,int *depth,int *virt);
466  virtual const char *Locale() const { return default_language; }
467  virtual void Locale(const char *);
468 
469  //special event functions
470  virtual void bump();
471  virtual EventReceiver *findEventObj(unsigned long id);
472  virtual int RegisterEventReceiver(EventReceiver *e);
473  virtual int UnregisterEventReceiver(EventReceiver *e);
474  virtual int SendMessage(EventData *data, unsigned long toobj=0,
475  const char *mes=0, unsigned long fromobj=0);
476 
477  //window management functions
478  virtual int rundialog(anXWindow *ndialog,anXWindow *wingroup=NULL,char absorb_count=1);
479  virtual int addwindow(anXWindow *w,char mapit=1,char absorb_count=1);
480  virtual int mapwindow(anXWindow *w);
481  virtual int unmapwindow(anXWindow *w);
482  virtual int reparent(anXWindow *kid,anXWindow *newparent);
483  virtual int setfocus(anXWindow *win,clock_t t=0,const LaxKeyboard *kb=NULL);
484  virtual int destroywindow(anXWindow *w);
485 
486  //drag-n-drop, cutting and pasting helpers
487  virtual void postmessage(const char *str);
488  virtual int CopytoBuffer(const char *stuff,int len);
489  virtual char *GetBuffer();
490  virtual anXWindow *findDropCandidate(anXWindow *ref,int x,int y,anXWindow **drop, Window *xlib_window_ret);
491 
492  //timer management
493  virtual int SetMaxTimeout(int timeoutmax);
494  virtual int addtimer(anXWindow *win,int strt,int next,int duration);
495  virtual int addmousetimer(anXWindow *win);
496  virtual int removetimer(anXWindow *w,int timerid);
497 };
498 
499 } // namespace Laxkit
500 
501 #endif
502 

Mon Feb 17 2014 11:52:56, Laxkit