Reputation: 6025
I'd like to know and understand the code which ultimately calls the actual IOS/Android/WP native widgets, when a NativeUI C++ class is used within the MoSync code base.
I've taken a quick look at a few classes on GitHub, like Button.cpp etc, but I can't readily see how the real native device widgets are being referenced.
I'm not a C/C++ dev (Java) but I was kind of expecting some #ifdefs or something to 'switch' out the respective underlying implementation. If that's not the case, then that's fine by me, just please indulge my curiosity.
Upvotes: 0
Views: 281
Reputation: 19
The C++ Widget classes like the Button.cpp mentioned have their base class in Widget.cpp which creates any widget based on a string argument. Also, any widget properties are effectively set through through string arguments.
my_button = new NativeUI::Widget("button")
my_button->setProperty("text", "OK");
MoSync implements an "IDL" interface for Native UI widgets in WidgetFunctions.idl:
typedef int MAWidgetHandle;
MAWidgetHandle maWidgetCreate(in MAString widgetType);
int maWidgetSetProperty(in MAWidgetHandle widget, in MAString property, in MAString value);
This is a language-independent description of the functions which get called from the NativeUI::Widget through a C call interface:
handle = maWidgetCreate("button");
maWidgetSetProperty(handle,"text","OK");
Until here we are on the MoSync C/C++ layer, which is kind of a VM with a system call interface. From here it is translated to the languages of the other platforms (Java, C#, etc.) by different methods:
It can use Java Native Interface (JNI) to call the corresponding functions in the Android runtime in MoSyncNativeUI.java:
public int maWidgetCreate(String type)
public int maWidgetSetProperty(int widgetHandle, String key, String value)
Or it is compiled into the intermediate "PIPE language", a pseudo assembler dialect, this language is then translated into Visual Studio C# for Windows Phone 7, or into an XCode project for iOS.
All platforms implement an UI engine in the "runtime" which is bundled with every app package. This runtime is prebuilt in the corresponding SDK and implements those Native UI calls.
Upvotes: 1