Permalink
Browse files

wp8: native menu & toolbar implemented (draft)

  • Loading branch information...
1 parent cc3b8a9 commit 60245d3dcbf94d2492ba390a24f527fd23e646d4 @timashev timashev committed Dec 29, 2012
@@ -104,24 +104,31 @@ public void CopyResourceFiles()
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
+ // TODO: add app init code here ?
}
// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
+ // TODO: add onActivate call
+ //rhoruntime.CRhoRuntime.getInstance().onActivate(1);
}
// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
+ // TODO: add onActivate call
+ //rhoruntime.CRhoRuntime.getInstance().onActivate(0);
}
// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
+ // TODO: add onActivate call ?
+ //rhoruntime.CRhoRuntime.getInstance().onActivate(0);
}
// Code to execute if a navigation fails
@@ -11,11 +11,14 @@
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
- shell:SystemTray.IsVisible="True">
+ shell:SystemTray.IsVisible="True" BackKeyPress="PhoneApplicationPage_BackKeyPress" OrientationChanged="PhoneApplicationPage_OrientationChanged" SizeChanged="PhoneApplicationPage_SizeChanged">
+ <phone:PhoneApplicationPage.ApplicationBar>
+ <shell:ApplicationBar/>
+ </phone:PhoneApplicationPage.ApplicationBar>
<!--LayoutRoot is the root grid where all page content is placed-->
<ScrollViewer x:Name="LayoutRoot" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
- <phone:WebBrowser x:Name="RhodesWebBrowser" Source="about:blank" Height="Auto" Width="Auto"/>
+ <phone:WebBrowser x:Name="RhodesWebBrowser" Source="about:blank" Height="Auto" Width="Auto" IsScriptEnabled="True" SizeChanged="RhodesWebBrowser_SizeChanged" Navigated="RhodesWebBrowser_Navigated" NavigationFailed="RhodesWebBrowser_NavigationFailed" LoadCompleted="RhodesWebBrowser_LoadCompleted" Loaded="RhodesWebBrowser_Loaded" Unloaded="RhodesWebBrowser_Unloaded"/>
</ScrollViewer>
</phone:PhoneApplicationPage>
@@ -25,26 +25,32 @@
*------------------------------------------------------------------------*/
using System;
+using System.Collections.Generic;
using System.Threading;
using System.Windows;
using Microsoft.Devices;
using Microsoft.Phone.Controls;
using rhodes.Resources;
using rhoruntime;
+using Microsoft.Phone.Shell;
namespace rhodes
{
- public partial class MainPage : PhoneApplicationPage, IMainPage
+ public partial class MainPage : PhoneApplicationPage
{
// saved id of the UI thread
private int _uiThreadID = -1;
// rhodes main thread
private Thread _rhoruntimeThread;
// internal variables
- double _screenWidth;
- double _screenHeight;
- double _screenPhysicalWidth;
- double _screenPhysicalHeight;
+ private double _screenWidth;
+ private double _screenHeight;
+ private double _screenPhysicalWidth;
+ private double _screenPhysicalHeight;
+ // menu items hash table
+ private Dictionary<string, int> menuItems = new Dictionary<string, int>();
+ // toolbar items hash table
+ private Dictionary<string, string> toolbarItems = new Dictionary<string, string>();
private bool isUIThread
{
@@ -60,17 +66,17 @@ public MainPage()
_screenPhysicalWidth = ( _screenPhysicalHeight / _screenHeight ) * _screenWidth; // assuming square pixels
InitializeComponent();
-
+ ApplicationBar.IsVisible = false;
try
{
// create rhodes runtime object
- var rhoruntime = CRhoRuntime.getInstance(this);
+ var _rhoruntime = CRhoRuntime.getInstance(new MainPageWrapper(this));
// create and start rhodes main thread
- _rhoruntimeThread = new Thread(rhoruntime.Execute);
+ _rhoruntimeThread = new Thread(_rhoruntime.Execute);
_rhoruntimeThread.Start();
Thread.Sleep(5000);
- rhoruntime.onActivate(0);
+ _rhoruntime.onActivate(0);
}
catch (Exception e)
{
@@ -93,7 +99,22 @@ public void bringToFront()
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { bringToFront(); }); return; }
this.bringToFront();
}
-
+
+ private void PhoneApplicationPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
+ {
+ e.Cancel = CRhoRuntime.getInstance().onBackKeyPress();
+ }
+
+ private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
+ {
+ // TODO: implement OrientationChanged handler
+ }
+
+ private void PhoneApplicationPage_SizeChanged(object sender, SizeChangedEventArgs e)
+ {
+ // TODO: implement application window size changed event hanlder ?
+ }
+
// *** WEBVIEW ***
@@ -132,7 +153,7 @@ public void Refresh(int index)
public bool isStarted()
{
- // TODO: implement
+ // TODO: implement WebView->isStarted
return true;
}
@@ -141,51 +162,100 @@ public string getCurrentURL(int index)
return RhodesWebBrowser.Source.AbsoluteUri.ToString();
}
-
+ private void RhodesWebBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
+ {
+ CRhoRuntime.getInstance().onWebViewUrlChanged(RhodesWebBrowser.Source.AbsoluteUri.ToString());
+ }
+
+ private void RhodesWebBrowser_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e)
+ {
+ // TODO: WebView NavigationFailed - do we need this?
+ }
+
+ private void RhodesWebBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
+ {
+ CRhoRuntime.getInstance().onWebViewUrlChanged(RhodesWebBrowser.Source.AbsoluteUri.ToString());
+ }
+
+ private void RhodesWebBrowser_Loaded(object sender, RoutedEventArgs e)
+ {
+ CRhoRuntime.getInstance().onWebViewUrlChanged(RhodesWebBrowser.Source.AbsoluteUri.ToString());
+ }
+
+ private void RhodesWebBrowser_Unloaded(object sender, RoutedEventArgs e)
+ {
+ CRhoRuntime.getInstance().onWebViewUrlChanged(RhodesWebBrowser.Source.AbsoluteUri.ToString());
+ }
+
+ private void RhodesWebBrowser_SizeChanged(object sender, SizeChangedEventArgs e)
+ {
+ // TODO: webview size changed event handler ?
+ }
+
+
// *** TOOLBAR ***
public void toolbarRemoveAllButtons()
{
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { toolbarRemoveAllButtons(); }); return; }
- // TODO: implement
+ ApplicationBar.Buttons.Clear();
+ toolbarItems.Clear();
+ ApplicationBar.IsVisible = ApplicationBar.MenuItems.Count > 0;
}
public void toolbarShow()
{
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { toolbarShow(); }); return; }
- // TODO: implement
+ ApplicationBar.IsVisible = true;
}
public void toolbarHide()
{
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { toolbarHide(); }); return; }
- // TODO: implement
+ ApplicationBar.IsVisible = false; // ?? ApplicationBar.MenuItems.Count > 0
}
public int toolbarGetHeight()
{
- // TODO: implement
- return 0;
+ // TODO: implement toolbarGetHeight
+ return ApplicationBar.IsVisible ? 30 : 0;
}
public void toolbarAddAction(string text)
{
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { toolbarAddAction(text); }); return; }
- // TODO: implement
+ ApplicationBarIconButton toolbarButton = new ApplicationBarIconButton();
+ // TODO: icon
+ toolbarButton.IconUri = new Uri("/rho/public/images/cancel.png", UriKind.Relative);
+ toolbarButton.Text = text;
+ toolbarItems.Add(text, text);
+ ApplicationBar.Buttons.Add(toolbarButton);
+ toolbarButton.Click += new EventHandler(toolbarButton_Click);
+ ApplicationBar.IsVisible = true;
}
- //void toolbarAddAction(const Icon^ icon, const String^ text, const char* action, bool rightAlign /*= false*/) { }
+ public void toolbarAddAction(Icon icon, string text, string action, bool rightAlign)
+ {
+ // TODO: implement custom toolbar action
+ toolbarAddAction(text);
+ //toolbarItems.Add(text, action);
+ }
public void toolbarAddSeparator()
{
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { toolbarAddSeparator(); }); return; }
- // TODO: implement
+ CRhoRuntime.getInstance().logEvent("Toolbar separator is unimplemented on WP8");
}
public void setToolbarStyle(bool border, string background)
{
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { setToolbarStyle(border, background); }); return; }
- // TODO: implement
+ // TODO: implement setToolbarStyle
+ }
+
+ private void toolbarButton_Click(object sender, EventArgs e)
+ {
+ CRhoRuntime.getInstance().onToolbarAction(toolbarItems[(sender as ApplicationBarIconButton).Text]);
}
@@ -194,19 +264,33 @@ public void setToolbarStyle(bool border, string background)
public void menuClear()
{
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { menuClear(); }); return; }
- // TODO: implement
+ ApplicationBar.MenuItems.Clear();
+ menuItems.Clear();
+ ApplicationBar.IsVisible = ApplicationBar.Buttons.Count > 0;
+ ApplicationBar.IsMenuEnabled = false;
+
}
public void menuAddAction(string text, int item)
{
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { menuAddAction(text, item); }); return; }
- // TODO: implement
+ ApplicationBarMenuItem menuItem = new ApplicationBarMenuItem(text);
+ ApplicationBar.MenuItems.Add(menuItem);
+ menuItems.Add(text, item);
+ menuItem.Click += new EventHandler(menuItem_Click);
+ ApplicationBar.IsVisible = true;
+ ApplicationBar.IsMenuEnabled = true;
}
public void menuAddSeparator()
{
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { menuAddSeparator(); }); return; }
- // TODO: implement
+ CRhoRuntime.getInstance().logEvent("Menu separator is unimplemented on WP8");
+ }
+
+ private void menuItem_Click(object sender, EventArgs e)
+ {
+ CRhoRuntime.getInstance().onCustomMenuItemCommand(menuItems[(sender as ApplicationBarMenuItem).Text]);
}
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace rhodes
+{
+ public class MainPageWrapper : rhoruntime.IMainPage
+ {
+ private MainPage _mainPage;
+ public MainPageWrapper(MainPage mainPage) { _mainPage = mainPage; }
+
+ public int getLogicalDpiX() { return _mainPage.getLogicalDpiX(); }
+ public int getLogicalDpiY() { return _mainPage.getLogicalDpiY(); }
+ public void bringToFront() { _mainPage.bringToFront(); }
+
+ // webview
+ public void navigate(string url, int index) { _mainPage.navigate(url, index); }
+ public void executeScript(string script, int index) { _mainPage.executeScript(script, index); }
+ public void GoBack() { _mainPage.GoBack(); }
+ public void GoForward() { _mainPage.GoForward(); }
+ public void Refresh(int index) { _mainPage.Refresh(index); }
+ public bool isStarted() { return _mainPage.isStarted(); }
+ public string getCurrentURL(int index) { return _mainPage.getCurrentURL(index); }
+ // toolbar
+ public void toolbarRemoveAllButtons() { _mainPage.toolbarRemoveAllButtons(); }
+ public void toolbarShow() { _mainPage.toolbarShow(); }
+ public void toolbarHide() { _mainPage.toolbarHide(); }
+ public int toolbarGetHeight() { return _mainPage.toolbarGetHeight(); }
+ public void toolbarAddAction(string text) { _mainPage.toolbarAddAction(text); }
+ //public void toolbarAddAction(Icon^ icon, String^ text, char* action, bool rightAlign /= false/);
+ public void toolbarAddSeparator() { _mainPage.toolbarAddSeparator(); }
+ public void setToolbarStyle(bool border, string background) { _mainPage.setToolbarStyle(border, background); }
+ // menu
+ public void menuClear() { _mainPage.menuClear(); }
+ public void menuAddAction(string text, int item) { _mainPage.menuAddAction(text, item); }
+ public void menuAddSeparator() { _mainPage.menuAddSeparator(); }
+ // tabbar
+ public void tabbarInitialize() { _mainPage.tabbarInitialize(); }
+ public void tabbarRemoveAllTabs(bool restore) { _mainPage.tabbarRemoveAllTabs(restore); }
+ public void tabbarShow() { _mainPage.tabbarShow(); }
+ public void tabbarHide() { _mainPage.tabbarHide(); }
+ public int tabbarGetHeight() { return _mainPage.tabbarGetHeight(); }
+ public void tabbarSwitch(int index) { _mainPage.tabbarSwitch(index); }
+ public int tabbarGetCurrent() { return _mainPage.tabbarGetCurrent(); }
+ //public int tabbarAddTab(String^ label, char* icon, bool disabled, Color^ web_bkg_color, QTabBarRuntimeParams& tbri);
+ public void tabbarSetBadge(int index, string badge) { _mainPage.tabbarSetBadge(index, badge); }
+ public void exitCommand() { _mainPage.exitCommand(); }
+ public void navigateBackCommand() { _mainPage.navigateBackCommand(); }
+ public void navigateForwardCommand() { _mainPage.navigateForwardCommand(); }
+ public void logCommand() { _mainPage.logCommand(); }
+ public void refreshCommand(int tab_index) { _mainPage.refreshCommand(tab_index); }
+ //public void navigateCommand(TNavigateData* nd);
+ public void takePicture(string callbackUrl) { _mainPage.takePicture(callbackUrl); }
+ public void selectPicture(string callbackUrl) { _mainPage.selectPicture(callbackUrl); }
+ //public void alertShowPopup(CAlertParams *);
+ public void alertHidePopup() { _mainPage.alertHidePopup(); }
+ //public void dateTimePicker(CDateTimeMessage *);
+ //public void executeCommand(RhoNativeViewRunnable*);
+ //public void executeRunnable(rho::common::IRhoRunnable* pTask);
+ //public void takeSignature(void*); //TODO: Signature::Params*
+ public void fullscreenCommand(int fullScreen) { _mainPage.fullscreenCommand(fullScreen); }
+ public void setCookie(string url, string cookie) { _mainPage.setCookie(url, cookie); }
+
+ // misc
+ public void DoWait(int timeout) { _mainPage.DoWait(timeout); }
+ public void DisplayMessage(string msg) { _mainPage.DisplayMessage(msg); }
+ }
+}
@@ -135,6 +135,7 @@
<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
+ <Compile Include="MainPageWrapper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\AppResources.Designer.cs">
<AutoGen>True</AutoGen>
@@ -15,10 +15,6 @@ RHO_GLOBAL void rho_appmanager_load( void* /*httpContext*/, const char* /*szQuer
// Nothing
}
-RHO_GLOBAL void rho_sys_app_exit()
-{
-}
-
RHO_GLOBAL void rho_sys_report_app_started()
{
}
Oops, something went wrong.

0 comments on commit 60245d3

Please sign in to comment.