Skip to content

Commit

Permalink
Android: Widgets can now request the on-screen keyboard when they get…
Browse files Browse the repository at this point in the history
… focus. This may fail if visible_focus is disabled.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12804 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Matthias Melcher committed Mar 26, 2018
1 parent 20ed92f commit e8818e9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions FL/Fl_Widget.H
Expand Up @@ -23,6 +23,7 @@
#define Fl_Widget_H

#include "Enumerations.H"
#include "Fl.H"

class Fl_Widget;
class Fl_Window;
Expand Down Expand Up @@ -70,6 +71,7 @@ struct FL_EXPORT Fl_Label {
};



/** Fl_Widget is the base class for all widgets in FLTK.
You can't create one of these because the constructor is not public.
Expand All @@ -84,6 +86,7 @@ struct FL_EXPORT Fl_Label {
*/
class FL_EXPORT Fl_Widget {
friend class Fl_Group;
friend void Fl::focus(Fl_Widget*);

Fl_Group* parent_;
Fl_Callback* callback_;
Expand Down Expand Up @@ -158,6 +161,8 @@ protected:
FULLSCREEN = 1<<18, ///< a fullscreen window (Fl_Window)
MAC_USE_ACCENTS_MENU = 1<<19, ///< On the Mac OS platform, pressing and holding a key on the keyboard opens an accented-character menu window (Fl_Input_, Fl_Text_Editor)
// (space for more flags)
NEEDS_KEYBOARD = 1<<20, ///< set this on touch screen devices if a widget needs a keyboard when it gets Focus. @see Fl_Screen_Driver::request_keyboard()
// a tiny bit more space for new flags...
USERFLAG3 = 1<<29, ///< reserved for 3rd party extensions
USERFLAG2 = 1<<30, ///< reserved for 3rd party extensions
USERFLAG1 = 1<<31 ///< reserved for 3rd party extensions
Expand Down
13 changes: 11 additions & 2 deletions src/Fl.cxx
Expand Up @@ -863,9 +863,18 @@ Fl_Widget* fl_oldfocus; // kludge for Fl_Group...
\see Fl_Widget::take_focus()
*/
void Fl::focus(Fl_Widget *o) {
if (o && !o->visible_focus()) return;
void Fl::focus(Fl_Widget *o)
{
if (grab()) return; // don't do anything while grab is on

// request an on-screen keyboard on touch screen devices if needed
Fl_Widget *prevFocus = Fl::focus();
if ( prevFocus && (prevFocus->flags()&Fl_Widget::NEEDS_KEYBOARD) )
Fl::screen_driver()->release_keyboard();
if (o && (o->flags()&Fl_Widget::NEEDS_KEYBOARD))
Fl::screen_driver()->request_keyboard( /*o->type()*/ );

if (o && !o->visible_focus()) return;
Fl_Widget *p = focus_;
if (o != p) {
Fl::compose_reset();
Expand Down
1 change: 1 addition & 0 deletions src/Fl_Input_.cxx
Expand Up @@ -1128,6 +1128,7 @@ Fl_Input_::Fl_Input_(int X, int Y, int W, int H, const char* l)
shortcut_ = 0;
set_flag(SHORTCUT_LABEL);
set_flag(MAC_USE_ACCENTS_MENU);
set_flag(NEEDS_KEYBOARD);
tab_nav(1);
}

Expand Down
1 change: 1 addition & 0 deletions src/Fl_Text_Editor.cxx
Expand Up @@ -75,6 +75,7 @@ Fl_Text_Editor::Fl_Text_Editor(int X, int Y, int W, int H, const char* l)
insert_mode_ = 1;
key_bindings = 0;
set_flag(MAC_USE_ACCENTS_MENU);
set_flag(NEEDS_KEYBOARD);

// handle the default key bindings
add_default_key_bindings(&key_bindings);
Expand Down

0 comments on commit e8818e9

Please sign in to comment.