README.md edited online with Bitbucket
[gdash.git] / src / framework / inputtextactivity.hpp
blobabef29a37ca494781a04123bb8b0188771946535
1 /*
2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
19 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #ifndef INPUTTEXTACTIVITY_HPP_INCLUDED
25 #define INPUTTEXTACTIVITY_HPP_INCLUDED
27 #include <string>
28 #include <glib.h>
30 #include "framework/activity.hpp"
31 #include "framework/commands.hpp"
33 template <typename T> class Command1Param;
35 /** Ask the user to type one line of text, and when successful, call the Command parametrized with the text.
36 * See App::input_text_and_do_command() as well. */
37 class InputTextActivity: public Activity {
38 public:
39 /** Ctor.
40 * @param title_line The title of the window.
41 * @param default_text The default value of the text box.
42 * @param command_when_successful The command of one string parameter to be parametrized with the line
43 * typed and executed, if the user accepts the input. */
44 InputTextActivity(App *app, char const *title_line, const char *default_text, SmartPtr<Command1Param<std::string> > command_when_successful);
45 ~InputTextActivity();
46 virtual void keypress_event(KeyCode keycode, int gfxlib_keycode);
47 virtual void redraw_event(bool full) const;
48 virtual void timer_event(int ms_elapsed);
50 private:
51 std::string title;
52 SmartPtr<Command1Param<std::string> > command_when_successful;
53 GString *text;
54 int ms;
55 bool blink;
58 #endif