Check if a configuration file exists before feeding it to the XML parser.
[AXE.git] / src / edit.h
1
2 /**************************************************************************
3 **  (c) Copyright 1998, Andromeda Technology & Automation
4 ***************************************************************************
5 ** MODULE INFORMATION *
6 ***********************
7 **      FILE NAME      : edit.h
8 **      SYSTEM NAME    : AXE - Andromeda X-windows Encapsulation
9 **      VERSION NUMBER : $Revision: 1.1 $
10 **
11 **  DESCRIPTION      :  Definition of text editor classes
12 **
13 **  EXPORTED OBJECTS : 
14 **  LOCAL    OBJECTS : 
15 **  MODULES  USED    :
16 ***************************************************************************
17 **  ADMINISTRATIVE INFORMATION *
18 ********************************
19 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
20 **      CREATION DATE   : Mar 13, 1998
21 **      LAST UPDATE     : Jun 18, 1998
22 **      MODIFICATIONS   : 
23 **************************************************************************/
24
25 /*****************************
26    $Log: edit.h,v $
27    Revision 1.1  2002-07-25 08:01:26  arjen
28    First checkin, AXE release 0.2
29
30 *****************************/
31
32 /* static const char *RCSID = "$Id: edit.h,v 1.1 2002-07-25 08:01:26 arjen Exp $"; */
33
34 #ifndef AXE_EDIT_H
35 #define AXE_EDIT_H
36
37 #include "xappl.h"
38
39 #include "String.h"
40
41 /*
42 ///////////////////////////////////////////////////////////////////////////
43 //  NAME           : edit
44 //  BASECLASS      : window
45 //  MEMBERS        : cursor_position : Index in the text string where edit
46 //                         operations occur. A visible cursor is drawn before
47 //                         that character when we have the focus.
48 //                   selected_until  : If text is selected, this is the index
49 //                         in the text string that marks the end of the selec-
50 //                         ted text. Characters are selected from the
51 //                         cursor_position until here or vice versa.
52 //  OPERATORS      :
53 //  METHODS        :
54 //
55 //  DESCRIPTION    :
56 //
57 //  RELATIONS      :
58 //  SEE ALSO       :
59 //  LAST MODIFIED  : Jun 18, 1998
60 ///////////////////////////////////////////////////////////////////////////
61 */
62
63 class edit : public window
64 {
65    int        selected_until;    //  End of selected text
66    int        text_position;     //  Graphical position in window.
67
68    enum       { No_Focus, Implicit_Focus, Explicit_Focus } focus_state;
69
70
71    int  map_to_textposition(int x);
72    int  map_to_pixelposition(int tp);
73    void toggle_cursor(void);
74
75 protected:
76
77    String     text;
78    int        cursor_position;   //  Text cursor in String
79
80    virtual int EV_KeyPress(XKeyEvent ev);
81    virtual int EV_ButtonPress(XButtonEvent ev);
82    virtual int EV_ButtonRelease(XButtonEvent ev);
83    virtual int EV_MotionNotify(XMotionEvent ev);
84    virtual int EV_FocusIn(XFocusChangeEvent ev);
85    virtual int EV_FocusOut(XFocusChangeEvent ev);
86    virtual int EV_EnterNotify(XCrossingEvent ev);
87    virtual int EV_LeaveNotify(XCrossingEvent ev);
88
89 public:
90
91    edit(window &par, int x, int y, const String &txt)
92                  : window(par, x, y, 100, 20)
93    {
94       text = txt;
95       cursor_position = 0;
96       selected_until = -1;
97       text_position = 2;
98       focus_state = No_Focus;
99       SelectInput(ExposureMask|KeyPressMask, 1);
100       SelectInput(EnterWindowMask|LeaveWindowMask|FocusChangeMask, 1);
101       SelectInput(ButtonPressMask|Button1MotionMask|ButtonReleaseMask, 1);
102       XDefineCursor(stddpy, ID(), text_cursor);
103    }
104
105    edit & operator =(const String &s)
106    {
107       text = s;
108       redraw();
109
110       return *this;
111    }
112
113    operator String &()
114    {
115       return text;
116    }
117
118    void redraw(void);
119
120    virtual int EV_Expose(XExposeEvent ev)
121    {
122       redraw();
123       return 1;
124    }
125
126    virtual void enter(void);
127    virtual void focuslost(void);
128
129    void SelectAll(void);
130    int  ClearSelection(void);
131    int  DeleteSelection(void);
132 };
133
134 #endif /* AXE_EDIT_H */