statuschoice.h

00001 // statuschoice.h   -*-c++-*-
00002 //
00003 //  Copyright 2000, 2004-2005 Daniel Burrows
00004 //
00005 //  This program is free software; you can redistribute it and/or modify
00006 //  it under the terms of the GNU General Public License as published by
00007 //  the Free Software Foundation; either version 2 of the License, or
00008 //  (at your option) any later version.
00009 //
00010 //  This program is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //  GNU General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU General Public License
00016 //  along with this program; see the file COPYING.  If not, write to
00017 //  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018 //  Boston, MA 02111-1307, USA.
00019 //
00020 // A single-line widget that lets the user choose between one of
00021 // several options with a keystroke.  The options should probably be
00022 // typable characters (as opposed to, say, left-arrow)
00023 //
00024 // The options are given in a string, of which the first character
00025 // should be the default value.  This is the value chosen if the user
00026 // presses Return.  The string should be non-empty.
00027 
00028 #ifndef STATUSCHOICE_H
00029 #define STATUSCHOICE_H
00030 
00031 #include <string>
00032 #include <cwidget/generic/util/eassert.h>
00033 
00034 #include "widget.h"
00035 
00036 namespace cwidget
00037 {
00038   namespace config
00039   {
00040     class keybindings;
00041   }
00042 
00043   namespace widgets
00044   {
00045     class statuschoice : public widget
00046     {
00047       std::wstring prompt;
00048       std::wstring choices;
00049       // A string containing all possible choices; the first one is considered
00050       // to be the "default".
00051 
00052     protected:
00053       bool handle_key(const config::key &k);
00054 
00055       statuschoice(const std::wstring &_prompt, const std::wstring &_choices)
00056         : widget(), prompt(_prompt), choices(_choices)
00057       {
00058         eassert(choices.size()>0);
00059       }
00060 
00061     public:
00062       static util::ref_ptr<statuschoice> create(const std::wstring &prompt,
00063                                                    const std::wstring &choices)
00064       {
00065         util::ref_ptr<statuschoice> rval(new statuschoice(prompt, choices));
00066         rval->decref();
00067         return rval;
00068       }
00069 
00070       int width_request();
00071       int height_request(int w);
00072 
00073       bool get_cursorvisible();
00074       point get_cursorloc();
00075 
00076       bool focus_me() {return true;}
00077 
00078       void paint(const style &st);
00079 
00080       sigc::signal1<void, int> chosen;
00081       // Called when one of the choices is selected (the arguments is the
00082       // position of the choice in the "choices" string)
00083 
00084       static config::keybindings *bindings;
00085       static void init_bindings();
00086     };
00087 
00088     typedef util::ref_ptr<statuschoice> statuschoice_ref;
00089   }
00090 }
00091 
00092 #endif

Generated on Fri Feb 8 12:54:56 2008 for cwidget by  doxygen 1.5.4