Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit a575342

Browse filesBrowse files
committed
[[ CrossPlatformButton ]] Add cross platform button
1 parent 6694ace commit a575342
Copy full SHA for a575342

File tree

Expand file treeCollapse file tree

8 files changed

+786
-0
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+786
-0
lines changed

‎extensions/extensions.gyp

Copy file name to clipboardExpand all lines: extensions/extensions.gyp
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@
188188
'widgets/gradientrampeditor/gradientrampeditor.lcb',
189189
'widgets/tile/tile.lcb',
190190
'widgets/spinner/spinner.lcb',
191+
192+
'widgets/button/button.lcb',
191193
],
192194

193195
'actions':
+120Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
Copyright (C) 2018 LiveCode Ltd.
3+
4+
This file is part of LiveCode.
5+
6+
LiveCode is free software; you can redistribute it and/or modify it under
7+
the terms of the GNU General Public License v3 as published by the Free
8+
Software Foundation.
9+
10+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
11+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
17+
18+
module com.livecode.widget.native.button.android
19+
20+
use com.livecode.widget.native.button.shared
21+
use com.livecode.canvas
22+
use com.livecode.foreign
23+
use com.livecode.java
24+
use com.livecode.library.androidutils
25+
26+
public handler Implementation_Android() returns Array
27+
return \
28+
{ \
29+
"HasImplementation": HasImplementation_Android, \
30+
"HasView": HasView_Android, \
31+
"SetLabel": SetLabel_Android, \
32+
"NativeView": NativeView_Android, \
33+
"UpdateView": UpdateView_Android, \
34+
"DestroyView": DestroyView_Android \
35+
}
36+
end handler
37+
38+
private variable mButtonView_Android as optional JObject
39+
40+
public handler HasImplementation_Android() returns Boolean
41+
return true
42+
end handler
43+
44+
public handler HasView_Android() returns Boolean
45+
return mButtonView_Android is not nothing
46+
end handler
47+
48+
__safe foreign handler _JNI_SetTextViewText(in pView as JObject, in pValue as JString) returns nothing \
49+
binds to "java:android.widget.TextView>setText(Ljava/lang/CharSequence;)V?ui"
50+
51+
public handler SetLabel_Android(in pLabel as String) returns nothing
52+
_JNI_SetTextViewText(mButtonView_Android, StringToJString(pLabel))
53+
end handler
54+
55+
__safe foreign handler _JNI_GetAndroidEngine() returns JObject \
56+
binds to "java:com.runrev.android.Engine>getEngine()Lcom/runrev/android/Engine;!static"
57+
__safe foreign handler _JNI_GetEngineContext(in pEngine as JObject) returns JObject \
58+
binds to "java:android.view.View>getContext()Landroid/content/Context;"
59+
60+
// Handlers for creating and attaching view
61+
__safe foreign handler _JNI_CreateButton(in pContext as JObject) returns JObject \
62+
binds to "java:android.widget.Button>new(Landroid/content/Context;)?ui"
63+
__safe foreign handler _JNI_AddButtonView(in pParentView as JObject, in pChildView as JObject) returns nothing \
64+
binds to "java:android.view.ViewGroup>addView(Landroid/view/View;)V?ui"
65+
66+
public handler ButtonActionCallback(in pView as JObject) returns nothing
67+
PostAction()
68+
end handler
69+
70+
// Handlers for adding click listener
71+
handler type ClickCallback(in pView as JObject) returns nothing
72+
__safe foreign handler _JNI_OnClickListener(in pHandler as ClickCallback) returns JObject \
73+
binds to "java:android.view.View$OnClickListener>interface()"
74+
__safe foreign handler _JNI_SetOnClickListener(in pButton as JObject, in pListener as JObject) returns nothing \
75+
binds to "java:android.view.View>setOnClickListener(Landroid/view/View$OnClickListener;)V?ui"
76+
public handler NativeView_Android() returns Pointer
77+
// Create an android button using the Engine Context
78+
variable tEngine as JObject
79+
put _JNI_GetAndroidEngine() into tEngine
80+
81+
variable tContext as JObject
82+
put _JNI_GetEngineContext(tEngine) into tContext
83+
put _JNI_CreateButton(tContext) into mButtonView_Android
84+
85+
// add an OnClick listener
86+
variable tListener as JObject
87+
put _JNI_OnClickListener(ButtonActionCallback) into tListener
88+
_JNI_SetOnClickListener(mButtonView_Android, tListener)
89+
90+
return PointerFromJObject(mButtonView_Android)
91+
end handler
92+
93+
public handler DestroyView_Android() returns nothing
94+
put nothing into mButtonView_Android
95+
end handler
96+
97+
__safe foreign handler _JNI_SetTextViewEnabled(in pView as JObject, in pValue as JBoolean) returns nothing \
98+
binds to "java:android.view.View>setEnabled(Z)V?ui"
99+
__safe foreign handler _JNI_SetTextViewTypeface(in pView as JObject, in pValue as JBoolean) returns nothing \
100+
binds to "java:android.widget.TextView>setTypeface(Landroid/graphics/Typeface;)V?ui"
101+
102+
__safe foreign handler _JNI_TextViewSetTextSize(in pObj as JObject, in pUnit as JInt, in pSize as JFloat) returns nothing \
103+
binds to "java:android.widget.TextView>setTextSize(IF)V?ui"
104+
105+
constant COMPLEX_UNIT_DIP is 1
106+
public handler UpdateView_Android(in pIntrinsicProps as Array) returns nothing
107+
if mButtonView_Android is nothing then
108+
return
109+
end if
110+
111+
_JNI_SetTextViewEnabled(mButtonView_Android, pIntrinsicProps["enabled"])
112+
113+
variable tTypeface as JObject
114+
variable tSize as Number
115+
put CanvasFontToTypeFace(pIntrinsicProps["font"]) into tTypeface
116+
put the size of pIntrinsicProps["font"] into tSize
117+
_JNI_TextViewSetTextSize(mButtonView_Android, COMPLEX_UNIT_DIP, tSize)
118+
end handler
119+
120+
end module
+126Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
Copyright (C) 2018 LiveCode Ltd.
3+
4+
This file is part of LiveCode.
5+
6+
LiveCode is free software; you can redistribute it and/or modify it under
7+
the terms of the GNU General Public License v3 as published by the Free
8+
Software Foundation.
9+
10+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
11+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
17+
18+
module com.livecode.widget.native.button.ios
19+
20+
use com.livecode.widget.native.button.shared
21+
use com.livecode.canvas
22+
use com.livecode.foreign
23+
use com.livecode.objc
24+
25+
public handler Implementation_Ios() returns Array
26+
return \
27+
{ \
28+
"HasImplementation": HasImplementation_Ios, \
29+
"HasView": HasView_Ios, \
30+
"SetLabel": SetLabel_Ios, \
31+
"NativeView": NativeView_Ios, \
32+
"UpdateView": UpdateView_Ios, \
33+
"DestroyView": DestroyView_Ios \
34+
}
35+
end handler
36+
37+
private variable mButtonView_Ios as optional ObjcObject
38+
private variable mButtonProxy_Ios as optional ObjcObject
39+
40+
public handler HasImplementation_Ios() returns Boolean
41+
return true
42+
end handler
43+
44+
public handler HasView_Ios() returns Boolean
45+
return mButtonView_Ios is not nothing
46+
end handler
47+
48+
private foreign handler ObjC_UIButtonSetTitleForState(in pObj as ObjcId, in pTitle as ObjcId, in pState as NSUInteger) returns nothing binds to "objc:UIButton.-setTitle:forState:?ui"
49+
public handler SetLabel_Ios(in pLabel as String) returns nothing
50+
unsafe
51+
_SetLabel_Ios(pLabel)
52+
end unsafe
53+
end handler
54+
55+
private unsafe handler _SetLabel_Ios(in pLabel as String) returns nothing
56+
/* We use UIControlStateNormal = 0 */
57+
ObjC_UIButtonSetTitleForState(mButtonView_Ios, StringToNSString(pLabel), 0)
58+
end handler
59+
60+
public handler NativeView_Ios() returns Pointer
61+
unsafe
62+
return _NativeView_Ios()
63+
end unsafe
64+
end handler
65+
66+
private handler ButtonActionCallback_Ios(in pSender as ObjcObject, in pContext as optional any) returns nothing
67+
PostAction()
68+
end handler
69+
70+
private foreign handler ObjC_UIButtonButtonWithType(in pType as NSUInteger) returns ObjcId binds to "objc:UIButton.+buttonWithType:?ui"
71+
private foreign handler ObjC_UIButtonSetEnabled(in pObj as ObjcId, in pEnabled as CBool) returns nothing binds to "objc:UIButton.-setEnabled:?ui"
72+
private foreign handler ObjC_UIButtonGetTitleLabel(in pObj as ObjcId) returns ObjcId binds to "objc:UIButton.-titleLabel?ui"
73+
private foreign handler ObjC_UILabelSetFont(in pObj as ObjcId, in pFont as ObjcId) returns nothing binds to "objc:UILabel.-setFont:?ui"
74+
private foreign handler ObjC_UIButtonAddTargetActionForControlEvents(in pObj as ObjcId, in pTarget as ObjcId, in pAction as UIntPtr, in pControlEvents as NSUInteger) returns nothing binds to "objc:UIButton.-addTarget:action:forControlEvents:?ui"
75+
76+
private unsafe handler _NativeView_Ios() returns Pointer
77+
variable tButtonView as ObjcObject
78+
79+
/* For a standard push button we need:
80+
* type to be UIButtonTypeSystem = 1 */
81+
put ObjC_UIButtonButtonWithType(1) into tButtonView
82+
put tButtonView into mButtonView_Ios
83+
84+
put ObjcProxyGetTarget(ButtonActionCallback_Ios, nothing) into mButtonProxy_Ios
85+
86+
/* For a push button action we need:
87+
* controlEvents to be UIControlEventTouchUpInside = 1 << 6 */
88+
ObjC_UIButtonAddTargetActionForControlEvents(mButtonView_Ios, mButtonProxy_Ios, ObjcProxyGetAction(), 1 shifted left by 6 bitwise)
89+
90+
return PointerFromObjcObject(tButtonView)
91+
end handler
92+
93+
public handler DestroyView_Ios() returns nothing
94+
unsafe
95+
_DestroyView_Ios()
96+
end unsafe
97+
end handler
98+
99+
private unsafe handler _DestroyView_Ios()
100+
put nothing into mButtonView_Ios
101+
put nothing into mButtonProxy_Ios
102+
end handler
103+
104+
public handler UpdateView_Ios(in pIntrinsicProps as Array) returns nothing
105+
unsafe
106+
_UpdateView_Ios(pIntrinsicProps)
107+
end unsafe
108+
end handler
109+
110+
private foreign handler GetFontHandle_Ios(in pFont as Font, out rHandle as ObjcId) returns nothing binds to "MCCanvasFontGetHandle"
111+
private unsafe handler _UpdateView_Ios(in pIntrinsicProps as Array)
112+
if mButtonView_Ios is nothing then
113+
return
114+
end if
115+
116+
/* Set the enabled state of the button to the host property. */
117+
ObjC_UIButtonSetEnabled(mButtonView_Ios, pIntrinsicProps["enabled"])
118+
119+
/* Set the font of the button to the host property. */
120+
variable tFontToUse as ObjcObject
121+
GetFontHandle_Ios(pIntrinsicProps["font"], tFontToUse)
122+
ObjC_UILabelSetFont(ObjC_UIButtonGetTitleLabel(mButtonView_Ios), \
123+
tFontToUse)
124+
end handler
125+
126+
end module
+61Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Copyright (C) 2018 LiveCode Ltd.
3+
4+
This file is part of LiveCode.
5+
6+
LiveCode is free software; you can redistribute it and/or modify it under
7+
the terms of the GNU General Public License v3 as published by the Free
8+
Software Foundation.
9+
10+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
11+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
17+
18+
module com.livecode.widget.native.button.linux
19+
20+
use com.livecode.widget.native.button.shared
21+
use com.livecode.foreign
22+
23+
public handler Implementation_Linux() returns Array
24+
return \
25+
{ \
26+
"HasImplementation": HasImplementation_Linux, \
27+
"HasView": HasView_Linux, \
28+
"SetLabel": SetLabel_Linux, \
29+
"NativeView": NativeView_Linux, \
30+
"UpdateView": UpdateView_Linux, \
31+
"DestroyView": DestroyView_Linux \
32+
}
33+
end handler
34+
35+
private variable mButtonView_Linux as optional Pointer
36+
37+
public handler HasImplementation_Linux() returns Boolean
38+
return false
39+
end handler
40+
41+
public handler HasView_Linux() returns Boolean
42+
return mButtonView_Linux is not nothing
43+
end handler
44+
45+
public handler SetLabel_Linux(in pLabel as String) returns nothing
46+
-- not implemented
47+
end handler
48+
49+
public handler NativeView_Linux() returns Pointer
50+
-- not implemented
51+
end handler
52+
53+
public handler DestroyView_Linux() returns nothing
54+
-- not implemented
55+
end handler
56+
57+
public handler UpdateView_Linux(in pIntrinsicProps as Array) returns nothing
58+
-- not implemented
59+
end handler
60+
61+
end module

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.