File: inputwidget.h

package info (click to toggle)
yapet 0.6-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 6,012 kB
  • ctags: 2,913
  • sloc: ansic: 13,661; cpp: 11,384; sh: 4,814; makefile: 847; yacc: 291; sed: 16
file content (141 lines) | stat: -rw-r--r-- 4,656 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// -*- c++ -*-
//
// $Id: inputwidget.h 2719 2009-08-20 01:30:25Z rafi $
//
// Copyright (C) 2008, 2009  Rafael Ostertag
//
// This file is part of YAPET.
//
// YAPET is free software: you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// YAPET is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// YAPET.  If not, see <http://www.gnu.org/licenses/>.
//

#ifndef _INPUTWIDGET_H
#define _INPUTWIDGET_H

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#ifdef HAVE_NCURSES_H
# include <ncurses.h>
#else // HAVE_NCURSES_H
# ifdef HAVE_CURSES_H
#  include <curses.h>
# else
#  error "Neither curses.h nor ncurses.h available"
# endif // HAVE_CURSES_H
#endif // HAVE_NCURSES_H
#include "curswa.h" // Leave this here. It depends on the above includes.

#ifdef HAVE_STRING
# include <string>
#endif

#include "uiexception.h"
#include "secstring.h"

namespace YAPET {
    namespace UI {
        /**
         * @brief A widget where text can be entered.
         *
         * A single line widget where text can be entered. The text
         * entered can be obtained by calling \c getText().
         *
         * The text is stored in a \c secstring.
         *
         * To activate the widget, call \c focus().
         *
         * @sa secstring
         */
        class InputWidget {
            private:
                WINDOW* window;
                secstring buffer;

                int max_length;
                int start_pos;
                int pos;
                int width;
                bool text_changed;

                inline InputWidget (const InputWidget&) {}
                inline const InputWidget& operator= (const InputWidget&) {
                    return *this;
                }

                void moveBackward() throw (UIException);
                void moveForward() throw (UIException);
                void moveHome() throw (UIException);
                void moveEnd() throw (UIException);

            protected:
                virtual void processBackspace() throw (UIException);
                virtual void processDelete() throw (UIException);
                virtual void processInput (int ch) throw (UIException);
                virtual void createWindow (int sx, int sy, int w) throw (UIException);
                virtual inline const WINDOW* getWindow() const {
                    return window;
                }
                virtual inline WINDOW* getWindow() {
                    return window;
                }
                virtual inline int getStartPos() const {
                    return start_pos;
                }
                virtual inline int getPos() const {
                    return pos;
                }
                virtual inline int getWidth() const {
                    return width;
                }
                virtual inline secstring& getBuffer() {
                    return buffer;
                }
                virtual inline const secstring& getBuffer() const {
                    return buffer;
                }

            public:
                InputWidget (int sx, int sy, int w, int ml = 512) throw (UIException);
                virtual ~InputWidget();

                virtual int focus() throw (UIException);
                virtual void refresh() throw (UIException);
                virtual void resize (int sx, int sy, int w) throw (UIException);
                virtual void setText (secstring t) throw (UIException);
                virtual inline secstring getText() const {
                    return buffer;
                }
                virtual void clearText();
                /**
                 * setText() does not change that flag, so we can tank
                 * inputwidgets with data, without having to fear to ask the
                 * user whether or not to save changes by mistake.
                 */
                inline void setTextChanged (bool b) {
                    text_changed = b;
                }
                inline bool isTextChanged() const {
                    return text_changed;
                }
                inline bool hasText() const {
                    return !buffer.empty();
                }

        };

    }
}
#endif // _INPUTWIDGET_H