20130313
[gdash.git] / src / framework / inputtextactivity.hpp
blobfa4788f7fcdf4dd48c4957d1a0553f3697e3791e
1 /*
2 * Copyright (c) 2007-2013, Czirkos Zoltan http://code.google.com/p/gdash/
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef _GD_INPUTTEXTAPPLET
18 #define _GD_INPUTTEXTAPPLET
20 #include <string>
21 #include <glib.h>
23 #include "framework/app.hpp"
24 #include "framework/commands.hpp"
26 template <typename T> class Command1Param;
28 /** Ask the user to type one line of text, and when successful, call the Command parametrized with the text.
29 * See App::input_text_and_do_command() as well. */
30 class InputTextActivity: public Activity {
31 public:
32 /** Ctor.
33 * @param title_line The title of the window.
34 * @param default_text The default value of the text box.
35 * @param command_when_successful The command of one string parameter to be parametrized with the line
36 * typed and executed, if the user accepts the input. */
37 InputTextActivity(App *app, char const *title_line, const char *default_text, SmartPtr<Command1Param<std::string> > command_when_successful);
38 ~InputTextActivity();
39 virtual void keypress_event(KeyCode keycode, int gfxlib_keycode);
40 virtual void redraw_event();
41 virtual void timer_event(int ms_elapsed);
43 private:
44 std::string title;
45 SmartPtr<Command1Param<std::string> > command_when_successful;
46 GString *text;
47 int ms;
48 bool blink;
51 #endif