cwidget  0.5.17
statuschoice.h
1 // statuschoice.h -*-c++-*-
2 //
3 // Copyright 2000, 2004-2005 Daniel Burrows
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; see the file COPYING. If not, write to
17 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 // Boston, MA 02111-1307, USA.
19 //
20 // A single-line widget that lets the user choose between one of
21 // several options with a keystroke. The options should probably be
22 // typable characters (as opposed to, say, left-arrow)
23 //
24 // The options are given in a string, of which the first character
25 // should be the default value. This is the value chosen if the user
26 // presses Return. The string should be non-empty.
27 
28 #ifndef STATUSCHOICE_H
29 #define STATUSCHOICE_H
30 
31 #include <string>
32 #include <cwidget/generic/util/eassert.h>
33 
34 #include "widget.h"
35 
36 namespace cwidget
37 {
38  namespace config
39  {
40  class keybindings;
41  }
42 
43  namespace widgets
44  {
45  class statuschoice : public widget
46  {
47  std::wstring prompt;
48  std::wstring choices;
49  // A string containing all possible choices; the first one is considered
50  // to be the "default".
51 
52  protected:
53  bool handle_key(const config::key &k);
54 
55  statuschoice(const std::wstring &_prompt, const std::wstring &_choices)
56  : widget(), prompt(_prompt), choices(_choices)
57  {
58  eassert(choices.size()>0);
59  }
60 
61  public:
62  static util::ref_ptr<statuschoice> create(const std::wstring &prompt,
63  const std::wstring &choices)
64  {
65  util::ref_ptr<statuschoice> rval(new statuschoice(prompt, choices));
66  rval->decref();
67  return rval;
68  }
69 
70  int width_request();
71  int height_request(int w);
72 
73  bool get_cursorvisible();
74  point get_cursorloc();
75 
76  bool focus_me() {return true;}
77 
78  void paint(const style &st);
79 
80  sigc::signal1<void, int> chosen;
81  // Called when one of the choices is selected (the arguments is the
82  // position of the choice in the "choices" string)
83 
84  static config::keybindings *bindings;
85  static void init_bindings();
86  };
87 
89  }
90 }
91 
92 #endif
A "style" is a setting to be applied to a display element (widget, text, etc).
Definition: style.h:51
Stores the keys bound to various functions.
Definition: keybindings.h:87
Definition: widget.h:89
Definition: ref_ptr.h:19
The namespace containing everything defined by cwidget.
Definition: columnify.cc:26
The basic widget interface.
Definition: widget.h:107
Represents a keystroke as seen by curses.
Definition: keybindings.h:42
Definition: statuschoice.h:45