Back to index

texmacs  1.0.7.15
x_gui.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : x_gui.hpp
00004 * DESCRIPTION: Graphical user interface for X11
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #ifndef X_GUI_H
00013 #define X_GUI_H
00014 #include "timer.hpp"
00015 #include "gui.hpp"
00016 #include "widget.hpp"
00017 #include "array.hpp"
00018 #include "hashmap.hpp"
00019 
00020 class x_gui_rep;
00021 class x_drawable_rep;
00022 class x_window_rep;
00023 typedef x_gui_rep* x_gui;
00024 typedef x_window_rep* x_window;
00025 extern x_gui the_gui;
00026 
00027 #define XK_CYRILLIC
00028 
00029 #include <X11/Xlib.h>
00030 #include <X11/X.h>
00031 #include <X11/Xutil.h>
00032 #include <X11/Xos.h>
00033 #include <X11/Xatom.h>
00034 #include <X11/keysym.h>
00035 #include <X11/Sunkeysym.h>
00036 
00037 extern bool true_color;
00038 #define CONVERT(c) (true_color? (c & 0xffffff): gui->cmap [c & 0xffffff])
00039 color blend (color fg, color bg);
00040 
00041 /******************************************************************************
00042 * For anti aliasing of TeX fonts
00043 ******************************************************************************/
00044 
00045 struct x_character_rep: concrete_struct {
00046   int          c;
00047   font_glyphs  fng;
00048   int          sf;
00049   color        fg;
00050   color        bg;
00051   x_character_rep (int c, font_glyphs fng, int sf, color fg, color bg);
00052   friend class x_character;
00053 };
00054 
00055 class x_character {
00056   CONCRETE(x_character);
00057   x_character (int c=0, font_glyphs fng= font_glyphs (),
00058               int sf=1, color fg= 0, color bg= 1);
00059   operator tree ();
00060 };
00061 CONCRETE_CODE(x_character);
00062 
00063 bool operator == (x_character xc1, x_character xc2);
00064 bool operator != (x_character xc1, x_character xc2);
00065 int hash (x_character xc);
00066 
00067 /******************************************************************************
00068 * Delayed messages
00069 ******************************************************************************/
00070 
00071 struct message_rep: concrete_struct {
00072   widget wid;
00073   string s;
00074   time_t t;
00075   message_rep (widget wid, string s, time_t t);
00076   friend class message;
00077 };
00078 
00079 class message {
00080   CONCRETE(message);
00081   message (widget wid, string s, time_t t);
00082 };
00083 CONCRETE_CODE(message);
00084 
00085 tm_ostream& operator << (tm_ostream& out, message m);
00086 
00087 /******************************************************************************
00088 * The x_gui class
00089 ******************************************************************************/
00090 
00091 class x_gui_rep {
00092 public:
00093   Display*        dpy;
00094   GC              gc;
00095   GC              pixmap_gc;
00096   int             scr;
00097   Window          root;
00098   int             screen_width;
00099   int             screen_height;
00100   int             depth;
00101   Colormap        cols;
00102   color*          cmap;
00103   bool            im_ok;
00104   XIM             im;
00105   list<widget>    grab_ptr;
00106   list<widget>    grab_kbd;
00107   unsigned int    state;
00108   list<message>   messages;
00109   x_window_rep*   gswindow;
00110   int             argc;
00111   char**          argv;
00112   widget          balloon_wid;
00113   window          balloon_win;
00114   SI              balloon_x;
00115   SI              balloon_y;
00116   time_t          balloon_time;
00117   bool            interrupted;
00118   time_t          interrupt_time;
00119 
00120   hashmap<x_character,pointer> color_scale;       // for anti-aliasing
00121   hashmap<x_character,pointer> character_bitmap;  // bitmaps of all characters
00122   hashmap<x_character,pointer> character_pixmap;  // pixmaps of all characters
00123   hashmap<string,int>          xpm_bitmap;        // bitmaps of all xpms
00124   hashmap<string,int>          xpm_pixmap;        // pixmaps of all xpms
00125   hashmap<int,string>          lower_key;
00126   hashmap<int,string>          upper_key;
00127 
00128   list<Window>                 windows_l;
00129   hashmap<string,tree>         selection_t;
00130   hashmap<string,string>       selection_s;
00131   Window                       selection_w;
00132 
00133   Atom XA_CLIPBOARD;
00134   Atom XA_TARGETS;
00135 
00136 public:
00137   x_gui_rep (int& argc, char** argv);
00138   ~x_gui_rep ();
00139 
00140   /******************************* Colors ************************************/
00141   void prepare_color (int sfactor, color fg, color bg);
00142 
00143   /****************************** Keyboard ***********************************/
00144   void initialize_input_method ();
00145   void insert_keysym (array<int>& a, int i, int j);
00146   void get_xmodmap ();
00147   void map (int key, string s);
00148   void Map (int key, string s);
00149   void initialize_keyboard_pointer ();
00150   string look_up_key (XKeyEvent* ev);
00151   string look_up_mouse (XButtonEvent* ev);
00152   unsigned int get_button_mask (XButtonEvent* ev);
00153 
00154   /******************************** Fonts ************************************/
00155   void set_shrinking_factor (int sfactor);
00156   void set_default_font (string name);
00157   font default_font_sub (bool tt, bool mini, bool bold);
00158   font default_font (bool tt= false, bool mini= false, bool bold= false);
00159   void get_ps_char (Font fn, int c, metric& ex, glyph& gl);
00160   void load_system_font (string family, int size, int dpi,
00161                       font_metric& fnm, font_glyphs& fng);
00162 
00163   /********************* extents, grabbing, selections ***********************/
00164   void   get_extents (SI& width, SI& height);
00165   void   get_max_size (SI& width, SI& height);
00166   void   set_button_state (unsigned int state);
00167   void   emulate_leave_enter (widget old_widget, widget new_widget);
00168   void   obtain_mouse_grab (widget wid);
00169   void   release_mouse_grab ();
00170   bool   has_mouse_grab (widget w);
00171 
00172   /*********************** interclient communication *************************/
00173   void   created_window (Window win);
00174   void   deleted_window (Window win);
00175   void   focussed_window (Window win);
00176   bool   get_selection (string key, tree& t, string& s);
00177   bool   set_selection (string key, tree t, string s);
00178   void   clear_selection (string key);
00179 
00180   /**************************** miscellaneous ********************************/
00181   void   show_help_balloon (widget wid, SI x, SI y);
00182   void   map_balloon ();
00183   void   unmap_balloon ();
00184   void   image_auto_gc ();
00185   void   image_gc (string name);
00186   void   set_mouse_pointer (widget w, string name);
00187   void   set_mouse_pointer (widget w, string curs_name, string mask_name);
00188   void   show_wait_indicator (widget w, string message, string arg);
00189   void   external_event (string s, time_t t);
00190   bool   check_event (int type);
00191 
00192   /************************** Event processing *******************************/
00193   void process_event (x_window win, XEvent* ev);
00194   void event_loop ();
00195 
00196   /*************************** And our friends *******************************/
00197   friend class x_drawable_rep;
00198   friend class x_window_rep;
00199   friend class x_ps_font_rep;
00200   friend class x_tex_font_rep;
00201 };
00202 
00203 #endif // defined X_GUI_H