Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit f38ddf1

Browse files
committed
[[ Bug 21465 ]] Implement keyboardType field property
This patch implements `keyboardType` as a field property. If set the `keyboardType` will override the keyboard type set with `mobileSetKeyboardType` for the field.
1 parent e814677 commit f38ddf1

File tree

19 files changed

+258
-75
lines changed

19 files changed

+258
-75
lines changed

docs/dictionary/command/mobileSetKeyboardType.lcdoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ The keyboard type setting takes affect the next time the keyboard is
4444
shown. It does not affect the current keyboard, if it is being
4545
displayed.
4646

47+
>**Note:** If a field has a non-empty <keyboardType> that value will override
48+
> the the value set by <mobileSetKeyboardType>.
49+
4750
References: mobileSetKeyboardReturnKey (command),
48-
keyboardDeactivated (message), keyboardActivated (message)
51+
keyboardDeactivated (message), keyboardActivated (message),
52+
keyboardType (property)
4953

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Name: keyboardType
2+
3+
Type: property
4+
5+
Syntax: set the keyboardType of <field> to <type>
6+
Syntax: get the keyboardType of <field>
7+
8+
Summary:
9+
Configures the type of keyboard that is to be displayed.
10+
11+
Introduced: 9.5
12+
13+
Associations: field
14+
15+
OS: ios, android
16+
17+
Platforms: mobile
18+
19+
Example:
20+
set the keyboardType of field "cost" to "alphabet"
21+
22+
Example:
23+
set the keyboardType of field "name" to empty
24+
25+
Parameters:
26+
type (enum):
27+
The type of keyboard to use. One of:
28+
29+
- "": use the global value from mobileSetKeyboardType
30+
- "default": the alphabetic keyboard
31+
- "numeric": the numeric keyboard with punctuation
32+
- "url": the url entry keyboard (iOS only)
33+
- "number": the number pad keyboard
34+
- "phone": the phone number pad keyboard
35+
- "contact": the phone contact pad keyboard (iOS only)
36+
- "email": the email keyboard
37+
38+
Description:
39+
Use the <keyboardType> command to configure the type of keyboard that is to be
40+
displayed for a field. If set to empty which is the default the type set by the
41+
<mobileSetKeyboardType> command is used to configure the type of keyboard that
42+
is to be displayed.
43+
44+
The keyboard type setting takes affect the next time the keyboard is
45+
shown. It does not affect the current keyboard, if it is being displayed.
46+
47+
References: mobileSetKeyboardType (command),
48+
keyboardDeactivated (message), keyboardActivated (message)
49+

docs/notes/bugfix-21465.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# New keyboardType field property
2+
3+
A new property has been added to fields to control the keyboard type displayed
4+
on the mobile keyboard.

engine/src/exec-interface-field.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,29 @@ static MCExecEnumTypeInfo _kMCInterfaceTextDirectionTypeInfo =
101101
_kMCInterfaceTextDirectionElementInfo
102102
};
103103

104+
static MCExecEnumTypeElementInfo _kMCInterfaceKeyboardTypeElementInfo[] =
105+
{
106+
{ "", kMCInterfaceKeyboardTypeNone, false},
107+
{ "default", kMCInterfaceKeyboardTypeDefault, false},
108+
{ "alphabet", kMCInterfaceKeyboardTypeAlphabet, false},
109+
{ "numeric", kMCInterfaceKeyboardTypeNumeric, false},
110+
{ "decimal", kMCInterfaceKeyboardTypeDecimal, false},
111+
{ "number", kMCInterfaceKeyboardTypeNumber, false},
112+
{ "phone", kMCInterfaceKeyboardTypePhone, false},
113+
{ "email", kMCInterfaceKeyboardTypeEmail, false},
114+
{ "url", kMCInterfaceKeyboardTypeUrl, false},
115+
{ "contact", kMCInterfaceKeyboardTypeContact, false}
116+
};
117+
118+
static MCExecEnumTypeInfo _kMCInterfaceKeyboardTypeTypeInfo =
119+
{
120+
"Interface.KeyboardType",
121+
sizeof(_kMCInterfaceKeyboardTypeElementInfo) / sizeof(MCExecEnumTypeElementInfo),
122+
_kMCInterfaceKeyboardTypeElementInfo
123+
};
124+
125+
MCExecEnumTypeInfo* kMCInterfaceKeyboardTypeTypeInfo = &_kMCInterfaceKeyboardTypeTypeInfo;
126+
104127
//////////
105128

106129
static void MCInterfaceFieldRangesParse(MCExecContext& ctxt, MCStringRef p_input, MCInterfaceFieldRanges& r_output)
@@ -1384,3 +1407,13 @@ void MCField::SetEffectiveRectangle(MCExecContext& ctxt, MCRectangle p_rect)
13841407
MCObject::SetEffectiveRectangle(ctxt, p_rect);
13851408
Redraw(true, textx, texty);
13861409
}
1410+
1411+
void MCField::GetKeyboardType(MCExecContext& ctxt, intenum_t& r_type)
1412+
{
1413+
r_type = static_cast<intenum_t>(keyboard_type);
1414+
}
1415+
1416+
void MCField::SetKeyboardType(MCExecContext& ctxt, intenum_t p_type)
1417+
{
1418+
keyboard_type = static_cast<MCInterfaceKeyboardType>(p_type);
1419+
}

engine/src/exec-interface.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,22 @@ void MCInterfaceStackFileVersionFree(MCExecContext& ctxt, MCInterfaceStackFileVe
231231

232232
void MCInterfaceTabStopsParse(MCExecContext& ctxt, bool p_is_relative, uinteger_t* p_tabs, uindex_t p_count, uint2*& r_new_stops, uindex_t& r_new_stop_count);
233233

234+
//////////
235+
236+
enum MCInterfaceKeyboardType : unsigned
237+
{
238+
kMCInterfaceKeyboardTypeNone,
239+
kMCInterfaceKeyboardTypeDefault,
240+
kMCInterfaceKeyboardTypeAlphabet,
241+
kMCInterfaceKeyboardTypeNumeric,
242+
kMCInterfaceKeyboardTypeDecimal,
243+
kMCInterfaceKeyboardTypeNumber,
244+
kMCInterfaceKeyboardTypePhone,
245+
kMCInterfaceKeyboardTypeEmail,
246+
kMCInterfaceKeyboardTypeUrl,
247+
kMCInterfaceKeyboardTypeContact
248+
};
249+
234250
#endif // EXEC_INTERFACE_H
235251

236252
//////////

engine/src/exec-misc.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,6 @@ static MCExecEnumTypeInfo _kMCMiscStatusBarStyleTypeInfo =
5757

5858
MCExecEnumTypeInfo* kMCMiscStatusBarStyleTypeInfo = &_kMCMiscStatusBarStyleTypeInfo;
5959

60-
static MCExecEnumTypeElementInfo _kMCMiscKeyboardTypeElementInfo[] =
61-
{
62-
{ "default", kMCMiscKeyboardTypeDefault, false},
63-
{ "alphabet", kMCMiscKeyboardTypeAlphabet, false},
64-
{ "numeric", kMCMiscKeyboardTypeNumeric, false},
65-
{ "decimal", kMCMiscKeyboardTypeDecimal, false},
66-
{ "number", kMCMiscKeyboardTypeNumber, false},
67-
{ "phone", kMCMiscKeyboardTypePhone, false},
68-
{ "email", kMCMiscKeyboardTypeEmail, false},
69-
{ "url", kMCMiscKeyboardTypeUrl, false},
70-
{ "contact", kMCMiscKeyboardTypeContact, false}
71-
};
72-
73-
static MCExecEnumTypeInfo _kMCMiscKeyboardTypeTypeInfo =
74-
{
75-
"Misc.KeyboardType",
76-
sizeof(_kMCMiscKeyboardTypeElementInfo) / sizeof(MCExecEnumTypeElementInfo),
77-
_kMCMiscKeyboardTypeElementInfo
78-
};
79-
80-
MCExecEnumTypeInfo* kMCMiscKeyboardTypeTypeInfo = &_kMCMiscKeyboardTypeTypeInfo;
81-
8260
static MCExecEnumTypeElementInfo _kMCMiscKeyboardReturnKeyElementInfo[] =
8361
{
8462
{ "default", kMCMiscKeyboardReturnKeyDefault, false},

engine/src/exec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2832,6 +2832,7 @@ extern MCExecCustomTypeInfo *kMCInterfaceFieldRangesTypeInfo;
28322832
extern MCExecEnumTypeInfo *kMCInterfaceFieldCursorMovementTypeInfo;
28332833
extern MCExecEnumTypeInfo *kMCInterfaceTextDirectionTypeInfo;
28342834
extern MCExecCustomTypeInfo *kMCInterfaceFieldTabAlignmentsTypeInfo;
2835+
extern MCExecEnumTypeInfo* kMCInterfaceKeyboardTypeTypeInfo;
28352836

28362837
///////////
28372838

@@ -3996,7 +3997,6 @@ void MCSoundSetAudioCategory(MCExecContext &ctxt, intenum_t p_category);
39963997

39973998
/////////////
39983999

3999-
extern MCExecEnumTypeInfo* kMCMiscKeyboardTypeTypeInfo;
40004000
extern MCExecEnumTypeInfo* kMCMiscKeyboardReturnTypeTypeInfo;
40014001
extern MCExecEnumTypeInfo* kMCMiscStatusBarStyleTypeInfo;
40024002

engine/src/field.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ MCPropertyInfo MCField::kProperties[] =
130130
DEFINE_RW_OBJ_LIST_PROPERTY(P_TAB_WIDTHS, ItemsOfLooseUInt, MCField, TabWidths)
131131
DEFINE_RO_OBJ_LIST_PROPERTY(P_PAGE_HEIGHTS, LinesOfLooseUInt, MCField, PageHeights)
132132
DEFINE_RO_OBJ_CUSTOM_PROPERTY(P_PAGE_RANGES, InterfaceFieldRanges, MCField, PageRanges)
133+
134+
DEFINE_RW_OBJ_ENUM_PROPERTY(P_KEYBOARD_TYPE, InterfaceKeyboardType, MCField, KeyboardType)
133135

134136
DEFINE_RW_OBJ_NON_EFFECTIVE_OPTIONAL_ENUM_PROPERTY(P_TEXT_ALIGN, InterfaceTextAlign, MCField, TextAlign)
135137
DEFINE_RO_OBJ_EFFECTIVE_ENUM_PROPERTY(P_TEXT_ALIGN, InterfaceTextAlign, MCField, TextAlign)
@@ -257,6 +259,8 @@ MCField::MCField()
257259

258260
// MM-2014-08-11: [[ Bug 13149 ]] Used to flag if a recompute is required during the next draw.
259261
m_recompute = false;
262+
263+
keyboard_type = kMCInterfaceKeyboardTypeNone;
260264
}
261265

262266
MCField::MCField(const MCField &fref) : MCControl(fref)
@@ -273,6 +277,8 @@ MCField::MCField(const MCField &fref) : MCControl(fref)
273277
foundlength = 0;
274278
cursor_movement = fref.cursor_movement;
275279
text_direction= fref.text_direction;
280+
keyboard_type = fref.keyboard_type;
281+
276282
if (fref.vscrollbar != NULL)
277283
{
278284
vscrollbar = new (nothrow) MCScrollbar(*fref.vscrollbar);
@@ -2560,6 +2566,7 @@ void MCField::draw(MCDC *dc, const MCRectangle& p_dirty, bool p_isolated, bool p
25602566
#define FIELD_EXTRA_TEXTDIRECTION (1 << 0)
25612567
// SN-2015-04-30: [[ Bug 15175 ]] TabAlignment flag added
25622568
#define FIELD_EXTRA_TABALIGN (1 << 1)
2569+
#define FIELD_EXTRA_KEYBOARDTYPE (1 << 2)
25632570

25642571
IO_stat MCField::extendedsave(MCObjectOutputStream& p_stream, uint4 p_part, uint32_t p_version)
25652572
{
@@ -2582,6 +2589,12 @@ IO_stat MCField::extendedsave(MCObjectOutputStream& p_stream, uint4 p_part, uint
25822589
t_size += sizeof(uint16_t);
25832590
t_size += sizeof(int8_t) * nalignments;
25842591
}
2592+
2593+
if (keyboard_type != kMCInterfaceKeyboardTypeNone)
2594+
{
2595+
t_flags |= FIELD_EXTRA_KEYBOARDTYPE;
2596+
t_size += sizeof(int8_t);
2597+
}
25852598

25862599
IO_stat t_stat;
25872600
t_stat = p_stream . WriteTag(t_flags, t_size);
@@ -2597,6 +2610,11 @@ IO_stat MCField::extendedsave(MCObjectOutputStream& p_stream, uint4 p_part, uint
25972610
t_stat = p_stream . WriteS8((int8_t)alignments[i]);
25982611
}
25992612

2613+
if (t_stat == IO_NORMAL && (t_flags & FIELD_EXTRA_KEYBOARDTYPE))
2614+
{
2615+
t_stat = p_stream . WriteS8((int8_t)keyboard_type);
2616+
}
2617+
26002618
if (t_stat == IO_NORMAL)
26012619
t_stat = MCObject::extendedsave(p_stream, p_part, p_version);
26022620

@@ -2656,6 +2674,16 @@ IO_stat MCField::extendedload(MCObjectInputStream& p_stream, uint32_t p_version,
26562674
}
26572675
}
26582676

2677+
if (t_stat == IO_NORMAL && (t_flags & FIELD_EXTRA_KEYBOARDTYPE) != 0)
2678+
{
2679+
int8_t t_value;
2680+
t_stat = checkloadstat(p_stream . ReadS8(t_value));
2681+
if (t_stat == IO_NORMAL)
2682+
{
2683+
keyboard_type = static_cast<MCInterfaceKeyboardType>(t_value);
2684+
}
2685+
}
2686+
26592687
if (t_stat == IO_NORMAL)
26602688
t_stat = checkloadstat(p_stream . Skip(t_length));
26612689

@@ -2681,7 +2709,9 @@ IO_stat MCField::save(IO_handle stream, uint4 p_part, bool p_force_ext, uint32_t
26812709
// AL-2014-09-12: [[ Bug 13315 ]] Force an extension if field has explicit textDirection.
26822710
// SN-2015-04-30: [[ Bug 15175 ]] Force an extension if field has tabalign.
26832711
bool t_has_extension;
2684-
t_has_extension = text_direction != kMCTextDirectionAuto || nalignments != 0;
2712+
t_has_extension = text_direction != kMCTextDirectionAuto ||
2713+
nalignments != 0 ||
2714+
keyboard_type != kMCInterfaceKeyboardTypeNone;
26852715

26862716
if ((stat = MCObject::save(stream, p_part, t_has_extension || p_force_ext, p_version)) != IO_NORMAL)
26872717
return stat;

engine/src/field.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2222

2323
#include "mccontrol.h"
2424
#include "exec.h"
25+
#include "exec-interface.h"
2526

2627
#define SCROLL_RATE 100
2728
#define MAX_PASTE_MESSAGES 32
@@ -239,7 +240,8 @@ class MCField : public MCControl, public MCMixinObjectHandle<MCField>
239240
MCStringRef label;
240241
MCTextDirection text_direction;
241242
MCInterfaceFieldCursorMovement cursor_movement;
242-
243+
MCInterfaceKeyboardType keyboard_type : 4;
244+
243245
// MM-2014-08-11: [[ Bug 13149 ]] Used to flag if a recompute is required during the next draw.
244246
bool m_recompute : 1;
245247

@@ -608,6 +610,8 @@ class MCField : public MCControl, public MCMixinObjectHandle<MCField>
608610
bool imagechanged(MCImage *p_image, bool p_deleting);
609611

610612
MCRectangle firstRectForCharacterRange(int32_t& si, int32_t& ei);
613+
614+
MCInterfaceKeyboardType getkeyboardtype() { return keyboard_type; }
611615

612616
////////// BIDIRECTIONAL SUPPORT
613617

@@ -721,6 +725,9 @@ class MCField : public MCControl, public MCMixinObjectHandle<MCField>
721725
void GetPageHeights(MCExecContext& ctxt, uindex_t& r_count, uinteger_t*& r_heights);
722726
void GetPageRanges(MCExecContext& ctxt, MCInterfaceFieldRanges& r_ranges);
723727

728+
void GetKeyboardType(MCExecContext& ctxt, intenum_t& r_type);
729+
void SetKeyboardType(MCExecContext& ctxt, intenum_t p_type);
730+
724731
virtual void SetShadow(MCExecContext& ctxt, const MCInterfaceShadow& p_shadow);
725732
virtual void SetShowBorder(MCExecContext& ctxt, bool setting);
726733
virtual void SetTextHeight(MCExecContext& ctxt, uinteger_t* height);

engine/src/java/com/runrev/android/Engine.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public class Engine extends View implements EngineApi
112112

113113
private boolean m_text_editor_visible;
114114
private int m_text_editor_mode;
115+
private int m_default_text_editor_mode;
115116

116117
private int m_default_ime_action;
117118

@@ -164,8 +165,9 @@ public void handleMessage(Message p_message) {
164165
// create our text editor
165166
// IM-2012-03-23: switch to monitoring the InputConnection to the EditText field to fix
166167
// bugs introduced by the previous method of checking for changes to the field
167-
m_text_editor_mode = 1;
168-
m_text_editor_visible = false;
168+
m_default_text_editor_mode = 1;
169+
m_text_editor_mode = 0;
170+
m_text_editor_visible = false;
169171

170172
m_default_ime_action = EditorInfo.IME_FLAG_NO_ENTER_ACTION | EditorInfo.IME_ACTION_DONE;
171173

@@ -675,17 +677,23 @@ public void resetKeyboard()
675677
imm.restartInput(this);
676678
}
677679

678-
public void setTextInputVisible(boolean p_visible)
680+
public void setTextInputVisible(boolean p_visible, int p_input_mode)
679681
{
680682
m_text_editor_visible = p_visible;
681683

682684
if (!s_running)
683685
return;
684686

685687
if (p_visible)
688+
{
689+
m_text_editor_mode = p_input_mode;
686690
showKeyboard();
691+
}
687692
else
693+
{
688694
hideKeyboard();
695+
m_text_editor_mode = 0;
696+
}
689697
}
690698

691699
public void setKeyboardReturnKey(int p_ime_action)
@@ -702,9 +710,9 @@ public void setTextInputMode(int p_mode)
702710
// 4 is phone
703711
// 5 is email
704712

705-
boolean t_reset = s_running && m_text_editor_visible && p_mode != m_text_editor_mode;
713+
boolean t_reset = s_running && m_text_editor_visible && p_mode != m_default_text_editor_mode;
706714

707-
m_text_editor_mode = p_mode;
715+
m_default_text_editor_mode = p_mode;
708716

709717
if (t_reset)
710718
resetKeyboard();
@@ -716,6 +724,11 @@ public int getInputType(boolean p_password)
716724
int t_type;
717725

718726
int t_mode = m_text_editor_mode;
727+
if (t_mode == 0)
728+
{
729+
t_mode = m_default_text_editor_mode;
730+
}
731+
719732
// the phone class does not support a password variant, so we switch this for one of the number types
720733
if (p_password && t_mode == 4)
721734
t_mode = 2;

0 commit comments

Comments
 (0)