It's necessary for implementing keyboard navigation and virtual keyboards.
void Dropdown::init()
{
+ // Necessary to have the parent container raise the dropdown on click
+ input_type = INPUT_TEXT;
+
dropped = false;
add(list);
slider(0),
got_key_press(false)
{
+ input_type = INPUT_TEXT;
set_text(t);
}
image(i),
keep_aspect(true)
{
- focusable = false;
}
void Image::autosize_special(const Part &part, Geometry &ageom) const
namespace Msp {
namespace GLtk {
-Indicator::Indicator()
-{
- focusable = false;
-}
-
void Indicator::set_active(bool a)
{
set_state(ACTIVE, (a ? ACTIVE : NORMAL));
class Indicator: public Widget
{
public:
- Indicator();
-
virtual const char *get_class() const { return "indicator"; }
void set_active(bool);
--- /dev/null
+#include "inputmethod.h"
+
+namespace Msp {
+namespace GLtk {
+
+InputMethod::InputMethod(Root &r):
+ root(r)
+{ }
+
+} // namespace GLtk
+} // namespace Msp
--- /dev/null
+#ifndef INPUTMETHOD_H_
+#define INPUTMETHOD_H_
+
+namespace Msp {
+namespace GLtk {
+
+class Root;
+
+enum InputType
+{
+ INPUT_NONE,
+ INPUT_TEXT
+};
+
+class InputMethod
+{
+protected:
+ Root &root;
+
+ InputMethod(Root &);
+public:
+ virtual ~InputMethod() { }
+};
+
+} // namespace GLtk
+} // namespace Msp
+
+#endif
Label::Label(const string &t)
{
- focusable = false;
set_text(t);
}
Panel::Panel():
layout(0)
-{ }
+{
+ input_type = INPUT_TEXT;
+}
Panel::~Panel()
{
#include "label.h"
#include "style.h"
#include "root.h"
+#include "systemkeyboardinput.h"
namespace Msp {
namespace GLtk {
Root::Root(const Resources &r, Graphics::Window &window):
resources(r),
keyboard(new Input::Keyboard(window)),
+ input_method(0),
mouse(new Input::Mouse(window)),
touchscreen(0),
own_input(true)
Root::Root(const Resources &r, Graphics::Window *window, Input::Keyboard *k, Input::Mouse *m, Input::Touchscreen *t):
resources(r),
keyboard(k),
+ input_method(0),
mouse(m),
touchscreen(t),
own_input(false)
mouse->signal_axis_motion.connect(sigc::mem_fun(this, &Root::axis_motion_event));
}
- if(keyboard)
- {
- keyboard->signal_button_press.connect(sigc::mem_fun(this, &Root::key_press_event));
- keyboard->signal_button_release.connect(sigc::mem_fun(this, &Root::key_release_event));
- keyboard->signal_character.connect(sigc::mem_fun(this, &Root::character_event));
- }
+ if(keyboard && !input_method)
+ input_method = new SystemKeyboardInput(*this, *keyboard);
if(touchscreen)
{
Root::~Root()
{
delete shprog;
+ delete input_method;
if(own_input)
{
delete keyboard;
return false;
}
-bool Root::key_press_event(unsigned key)
-{
- // XXX Modifiers
- if(visible)
- return key_press(key, 0);
-
- return false;
-}
-
-bool Root::key_release_event(unsigned key)
-{
- if(visible)
- return key_release(key, 0);
-
- return false;
-}
-
-bool Root::character_event(StringCodec::unichar ch)
-{
- if(visible)
- return character(ch);
-
- return false;
-}
-
bool Root::touch_press_event(unsigned finger)
{
if(visible)
private:
const Resources &resources;
Input::Keyboard *keyboard;
+ InputMethod *input_method;
Input::Mouse *mouse;
Input::Touchscreen *touchscreen;
bool own_input;
bool button_press_event(unsigned);
bool button_release_event(unsigned);
bool axis_motion_event(unsigned, float, float);
- bool key_press_event(unsigned);
- bool key_release_event(unsigned);
- bool character_event(StringCodec::unichar);
bool touch_press_event(unsigned);
bool touch_release_event(unsigned);
bool touch_motion_event(unsigned, float, float);
--- /dev/null
+#include <msp/input/keys.h>
+#include "root.h"
+#include "systemkeyboardinput.h"
+
+namespace Msp {
+namespace GLtk {
+
+SystemKeyboardInput::SystemKeyboardInput(Root &r, Input::Keyboard &k):
+ InputMethod(r),
+ keyboard(k)
+{
+ keyboard.signal_button_press.connect(sigc::mem_fun(this, &SystemKeyboardInput::key_press));
+ keyboard.signal_button_release.connect(sigc::mem_fun(this, &SystemKeyboardInput::key_release));
+ keyboard.signal_character.connect(sigc::mem_fun(this, &SystemKeyboardInput::character));
+}
+
+bool SystemKeyboardInput::key_press(unsigned key)
+{
+ // TODO modifiers
+ if(root.key_press(key, 0))
+ return true;
+
+ return false;
+}
+
+bool SystemKeyboardInput::key_release(unsigned key)
+{
+ return root.key_release(key, 0);
+}
+
+bool SystemKeyboardInput::character(StringCodec::unichar ch)
+{
+ return root.character(ch);
+}
+
+} // namespace GLtk
+} // namespace Msp
--- /dev/null
+#ifndef MSP_GLTK_SYSTEMKEYBOARDINPUT_H_
+#define MSP_GLTK_SYSTEMKEYBOARDINPUT_H_
+
+#include <msp/input/keyboard.h>
+#include "inputmethod.h"
+
+namespace Msp {
+namespace GLtk {
+
+class SystemKeyboardInput: public InputMethod, public sigc::trackable
+{
+private:
+ Input::Keyboard &keyboard;
+
+public:
+ SystemKeyboardInput(Root &, Input::Keyboard &);
+
+private:
+ bool key_press(unsigned);
+ bool key_release(unsigned);
+ bool character(StringCodec::unichar);
+};
+
+} // namespace GLtk
+} // namespace Msp
+
+#endif
style(0),
state(NORMAL),
visible(true),
- focusable(true),
+ input_type(INPUT_NONE),
parent(0)
{ }
void Widget::set_focusable(bool f)
{
- focusable = f;
+ input_type = (f ? INPUT_TEXT : INPUT_NONE);
}
void Widget::set_focus()
#include <msp/datafile/objectloader.h>
#include <msp/gl/renderer.h>
#include "geometry.h"
+#include "inputmethod.h"
#include "partcache.h"
#include "state.h"
const Style *style;
State state;
bool visible;
- bool focusable;
+ InputType input_type;
Container *parent;
std::string tooltip;
PartCache part_cache;
void set_visible(bool);
bool is_visible() const { return visible; }
- void set_focusable(bool);
- bool is_focusable() const { return focusable; }
+ InputType get_input_type() const { return input_type; }
+ bool is_focusable() const { return visible && input_type!=INPUT_NONE; }
void set_focus();
void set_enabled(bool);
bool is_enabled() const { return !(state&DISABLED); }
+ // Deprecated
+ void set_focusable(bool);
+
protected:
void set_state(State s) { set_state(s, s); }
void clear_state(State s) { set_state(s, NORMAL); }