NEURON
field.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1991 Stanford University
3  * Copyright (c) 1991 Silicon Graphics, Inc.
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and
6  * its documentation for any purpose is hereby granted without fee, provided
7  * that (i) the above copyright notices and this permission notice appear in
8  * all copies of the software and related documentation, and (ii) the names of
9  * Stanford and Silicon Graphics may not be used in any advertising or
10  * publicity relating to the software without the specific, prior written
11  * permission of Stanford and Silicon Graphics.
12  *
13  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * IN NO EVENT SHALL STANFORD OR SILICON GRAPHICS BE LIABLE FOR
18  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22  * OF THIS SOFTWARE.
23  */
24 
25 /*
26  * FieldSEditor -- simple editor for text fields
27  */
28 
29 #pragma once
30 
31 #include <InterViews/input.h>
32 #include <InterViews/resource.h>
33 
34 class FieldSEditor;
35 class FieldSEditorImpl;
36 class String;
37 class Style;
38 class WidgetKit;
39 
41  protected:
44 
45  public:
46  virtual void accept(FieldSEditor*);
47  virtual void cancel(FieldSEditor*);
48 };
49 
50 #if defined(__STDC__) || defined(__ANSI_CPP__)
51 #define __FieldSEditorCallback(T) T##_FieldSEditorCallback
52 #define FieldSEditorCallback(T) __FieldSEditorCallback(T)
53 #define __FieldSEditorMemberFunction(T) T##_FieldSEditorMemberFunction
54 #define FieldSEditorMemberFunction(T) __FieldSEditorMemberFunction(T)
55 #else
56 #define __FieldSEditorCallback(T) T /**/ _FieldSEditorCallback
57 #define FieldSEditorCallback(T) __FieldSEditorCallback(T)
58 #define __FieldSEditorMemberFunction(T) T /**/ _FieldSEditorMemberFunction
59 #define FieldSEditorMemberFunction(T) __FieldSEditorMemberFunction(T)
60 #endif
61 
62 #define declareFieldSEditorCallback(T) \
63  typedef void (T::*FieldSEditorMemberFunction(T))(FieldSEditor*); \
64  class FieldSEditorCallback(T) \
65  : public FieldSEditorAction { \
66  public: \
67  FieldSEditorCallback( \
68  T)(T*, FieldSEditorMemberFunction(T) accept, FieldSEditorMemberFunction(T) cancel); \
69  virtual ~FieldSEditorCallback(T)(); \
70  \
71  virtual void accept(FieldSEditor*); \
72  virtual void cancel(FieldSEditor*); \
73  \
74  private: \
75  T* obj_; \
76  FieldSEditorMemberFunction(T) accept_; \
77  FieldSEditorMemberFunction(T) cancel_; \
78  };
79 
80 #define implementFieldSEditorCallback(T) \
81  FieldSEditorCallback(T)::FieldSEditorCallback( \
82  T)(T * obj, FieldSEditorMemberFunction(T) accept, FieldSEditorMemberFunction(T) cancel) { \
83  obj_ = obj; \
84  accept_ = accept; \
85  cancel_ = cancel; \
86  } \
87  \
88  FieldSEditorCallback(T)::~FieldSEditorCallback(T)() {} \
89  \
90  void FieldSEditorCallback(T)::accept(FieldSEditor* f) { \
91  (obj_->*accept_)(f); \
92  } \
93  void FieldSEditorCallback(T)::cancel(FieldSEditor* f) { \
94  (obj_->*cancel_)(f); \
95  }
96 
97 class FieldSEditor: public InputHandler {
98  public:
99  FieldSEditor(const String& sample, WidgetKit*, Style*, FieldSEditorAction* = NULL);
100  virtual ~FieldSEditor();
101 
102  virtual void undraw();
103 
104  virtual void press(const Event&);
105  virtual void drag(const Event&);
106  virtual void release(const Event&);
107  virtual void keystroke(const Event&);
108  virtual InputHandler* focus_in();
109  virtual void focus_out();
110 
111  virtual void field(const char*);
112  virtual void field(const String&);
113 
114  virtual void select(int pos);
115  virtual void select(int left, int right);
116 
117  virtual void selection(int& start, int& index) const;
118 
119  virtual void edit();
120  virtual void edit(const char*, int left, int right);
121  virtual void edit(const String&, int left, int right);
122 
123  virtual const String* text() const;
124 
125  private:
126  FieldSEditorImpl* impl_;
127 };
#define InputHandler
Definition: _defines.h:149
#define Style
Definition: _defines.h:278
#define WidgetKit
Definition: _defines.h:328
#define Event
Definition: _defines.h:105
virtual void cancel(FieldSEditor *)
virtual ~FieldSEditorAction()
virtual void accept(FieldSEditor *)
virtual void field(const String &)
FieldSEditorImpl * impl_
Definition: field.h:126
virtual void focus_out()
virtual void release(const Event &)
virtual void edit()
virtual void edit(const char *, int left, int right)
virtual const String * text() const
virtual void selection(int &start, int &index) const
virtual void press(const Event &)
virtual ~FieldSEditor()
virtual void undraw()
virtual void select(int pos)
virtual void keystroke(const Event &)
virtual void drag(const Event &)
virtual void select(int left, int right)
virtual InputHandler * focus_in()
virtual void edit(const String &, int left, int right)
FieldSEditor(const String &sample, WidgetKit *, Style *, FieldSEditorAction *=NULL)
virtual void field(const char *)
short index
Definition: cabvars.h:11
#define NULL
Definition: spdefs.h:105