File: windowbase.h

package info (click to toggle)
yapet 2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,920 kB
  • sloc: cpp: 32,397; sh: 5,032; makefile: 880; ansic: 36; sed: 16
file content (191 lines) | stat: -rw-r--r-- 4,501 bytes parent folder | download | duplicates (4)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// -*- mode: c++ -*-
//
// This file is part of libyacurs.
// Copyright (C) 2013  Rafael Ostertag
//
// This program 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.
//
// This program 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 this program.  If not, see
// <http://www.gnu.org/licenses/>.
//
//
// $Id$

#ifndef WINDOWBASE_H
#define WINDOWBASE_H 1

#include "curswin.h"
#include "event.h"
#include "margin.h"
#include "realizeable.h"
#include "yacurscurses.h"

namespace YACURS {
/**
 * Base class for Windows.
 *
 * WindowBase has the following properties:
 *
 * - curses window uses entire screen, unless a margin is given
 *
 * - positioning is achieved by using margins
 *
 * - can have a visible frame
 *
 * - connect to EVT_REFRESH, EVT_FORCEREFRESH and EVT_RESIZE
 *
 * - allocates only one instance of curses Windows across
 *   assignments.
 *
 * - tracks the number of WindowBase instances created by copying and
 *   assigning and frees curses window only upon destruction of
 *   last instance.
 *
 * Users of this class are expected to call show()/close() in order to
 * show and hide the window. Calling realize()/unrealize() is
 * discouraged.
 *
 * Events will be connected upon call to show() and disconnected upon
 * call to close().
 *
 * Derived classes do not need to connect to EVT_REFRESH, or
 * EVT_RESIZE. The Event handler of WindowBase call refresh() or
 * resize() which can be implemented by derived classes.
 */
class WindowBase : public Realizeable {
   private:
    /**
     * The dimension of the screen. Used as cache to avoid calls
     * to Curses::inquiry_screensize().
     */
    Area _area;

    /**
     * margin of the screen object.
     */
    Margin _margin;

    /**
     * Curses window
     */
    YACURS::INTERNAL::CursWin* _curses_window;

    /**
     * Whether or not the window has a border
     */
    bool _frame;

    /**
     * Flag whether or not Window is shown.
     */
    bool _shown;

    /**
     * Default color of window.
     */
    COLOROBJ _color;

   protected:
    YACURS::INTERNAL::CursWin* curses_window() const;

    const Area& area() const;

    /**
     * Gets the area that can be used by widgets
     *
     * @return the area in with absolute coordinates that can be
     * used by widgets.
     */
    Area widget_area() const;

    void unrealize();

    /**
     * Called on close.
     *
     * Will be called before dialog closes.
     * To be implemented by user if needed.
     *
     * @param st state. See STATE for possible values.
     *
     * @return @c false prevents window from being closed.
     */
    virtual bool on_close();

   public:
    /**
     * @param m margin to be used.
     */
    WindowBase(const Margin& m = Margin());
    WindowBase(const WindowBase&) = delete;
    WindowBase& operator=(const WindowBase&) = delete;
    WindowBase(WindowBase&&) = delete;
    WindowBase& operator=(WindowBase&&) = delete;
    virtual ~WindowBase();

    /**
     * @todo when setting margin and window is realized, resize
     * it.
     */
    void margin(const Margin& m);

    const Margin& margin() const;

    bool frame() const;

    void color(COLOROBJ c);

    COLOROBJ color() const;

    /**
     * @todo make setting/removing frame take effect immediately,
     * if window is realized.
     */
    void frame(bool b);

    /**
     * Show the window.
     *
     * This is supposed to be called by the user.
     */
    virtual void show();

    /**
     * Hide the window.
     *
     * This is supposed to be called by the user.
     */
    virtual void close();

    bool shown() const;

    // Those handlers must be public, so that LockScreen can
    // suspend them.

    virtual void redraw_handler(Event& e);

    virtual void force_refresh_handler(Event& e);

    virtual void refresh_handler(Event& e);

    virtual void resize_handler(Event& e);

    // Those are from Realizable
    void refresh(bool immediate);

    void resize(const Area& a);

    void realize();
};
}  // namespace YACURS

#endif  // WINDOWBASE_H