Skip to content

Commit

Permalink
wp8: native menu & toolbar implemented (draft)
Browse files Browse the repository at this point in the history
  • Loading branch information
timashev committed Dec 29, 2012
1 parent cc3b8a9 commit 60245d3
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 44 deletions.
7 changes: 7 additions & 0 deletions platform/wp8/rhodes/App.xaml.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -104,24 +104,31 @@ public void CopyResourceFiles()
// This code will not execute when the application is reactivated // This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e) 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) // Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched // This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e) 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) // Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing // This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e) 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) // Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated // This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e) private void Application_Closing(object sender, ClosingEventArgs e)
{ {
// TODO: add onActivate call ?
//rhoruntime.CRhoRuntime.getInstance().onActivate(0);
} }


// Code to execute if a navigation fails // Code to execute if a navigation fails
Expand Down
7 changes: 5 additions & 2 deletions platform/wp8/rhodes/MainPage.xaml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
FontSize="{StaticResource PhoneFontSizeNormal}" FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}" Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait" 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--> <!--LayoutRoot is the root grid where all page content is placed-->
<ScrollViewer x:Name="LayoutRoot" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> <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> </ScrollViewer>


</phone:PhoneApplicationPage> </phone:PhoneApplicationPage>
132 changes: 108 additions & 24 deletions platform/wp8/rhodes/MainPage.xaml.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,26 +25,32 @@
*------------------------------------------------------------------------*/ *------------------------------------------------------------------------*/


using System; using System;
using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
using Microsoft.Devices; using Microsoft.Devices;
using Microsoft.Phone.Controls; using Microsoft.Phone.Controls;
using rhodes.Resources; using rhodes.Resources;
using rhoruntime; using rhoruntime;
using Microsoft.Phone.Shell;


namespace rhodes namespace rhodes
{ {
public partial class MainPage : PhoneApplicationPage, IMainPage public partial class MainPage : PhoneApplicationPage
{ {
// saved id of the UI thread // saved id of the UI thread
private int _uiThreadID = -1; private int _uiThreadID = -1;
// rhodes main thread // rhodes main thread
private Thread _rhoruntimeThread; private Thread _rhoruntimeThread;
// internal variables // internal variables
double _screenWidth; private double _screenWidth;
double _screenHeight; private double _screenHeight;
double _screenPhysicalWidth; private double _screenPhysicalWidth;
double _screenPhysicalHeight; 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 private bool isUIThread
{ {
Expand All @@ -60,17 +66,17 @@ public MainPage()
_screenPhysicalWidth = ( _screenPhysicalHeight / _screenHeight ) * _screenWidth; // assuming square pixels _screenPhysicalWidth = ( _screenPhysicalHeight / _screenHeight ) * _screenWidth; // assuming square pixels


InitializeComponent(); InitializeComponent();

ApplicationBar.IsVisible = false;
try try
{ {
// create rhodes runtime object // create rhodes runtime object
var rhoruntime = CRhoRuntime.getInstance(this); var _rhoruntime = CRhoRuntime.getInstance(new MainPageWrapper(this));
// create and start rhodes main thread // create and start rhodes main thread
_rhoruntimeThread = new Thread(rhoruntime.Execute); _rhoruntimeThread = new Thread(_rhoruntime.Execute);
_rhoruntimeThread.Start(); _rhoruntimeThread.Start();


Thread.Sleep(5000); Thread.Sleep(5000);
rhoruntime.onActivate(0); _rhoruntime.onActivate(0);
} }
catch (Exception e) catch (Exception e)
{ {
Expand All @@ -93,7 +99,22 @@ public void bringToFront()
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { bringToFront(); }); return; } if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { bringToFront(); }); return; }
this.bringToFront(); 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 *** // *** WEBVIEW ***


Expand Down Expand Up @@ -132,7 +153,7 @@ public void Refresh(int index)


public bool isStarted() public bool isStarted()
{ {
// TODO: implement // TODO: implement WebView->isStarted
return true; return true;
} }


Expand All @@ -141,51 +162,100 @@ public string getCurrentURL(int index)
return RhodesWebBrowser.Source.AbsoluteUri.ToString(); 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 *** // *** TOOLBAR ***


public void toolbarRemoveAllButtons() public void toolbarRemoveAllButtons()
{ {
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { toolbarRemoveAllButtons(); }); return; } if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { toolbarRemoveAllButtons(); }); return; }
// TODO: implement ApplicationBar.Buttons.Clear();
toolbarItems.Clear();
ApplicationBar.IsVisible = ApplicationBar.MenuItems.Count > 0;
} }


public void toolbarShow() public void toolbarShow()
{ {
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { toolbarShow(); }); return; } if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { toolbarShow(); }); return; }
// TODO: implement ApplicationBar.IsVisible = true;
} }


public void toolbarHide() public void toolbarHide()
{ {
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { toolbarHide(); }); return; } if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { toolbarHide(); }); return; }
// TODO: implement ApplicationBar.IsVisible = false; // ?? ApplicationBar.MenuItems.Count > 0
} }


public int toolbarGetHeight() public int toolbarGetHeight()
{ {
// TODO: implement // TODO: implement toolbarGetHeight
return 0; return ApplicationBar.IsVisible ? 30 : 0;
} }


public void toolbarAddAction(string text) public void toolbarAddAction(string text)
{ {
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { toolbarAddAction(text); }); return; } 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() public void toolbarAddSeparator()
{ {
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { toolbarAddSeparator(); }); return; } 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) public void setToolbarStyle(bool border, string background)
{ {
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { setToolbarStyle(border, background); }); return; } 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]);
} }




Expand All @@ -194,19 +264,33 @@ public void setToolbarStyle(bool border, string background)
public void menuClear() public void menuClear()
{ {
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { menuClear(); }); return; } 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) public void menuAddAction(string text, int item)
{ {
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { menuAddAction(text, item); }); return; } 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() public void menuAddSeparator()
{ {
if (!isUIThread) { Dispatcher.BeginInvoke(delegate() { menuAddSeparator(); }); return; } 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]);
} }




Expand Down
70 changes: 70 additions & 0 deletions platform/wp8/rhodes/MainPageWrapper.cs
Original file line number Original file line Diff line number Diff line change
@@ -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); }
}
}
1 change: 1 addition & 0 deletions platform/wp8/rhodes/rhodes.csproj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
<Compile Include="MainPage.xaml.cs"> <Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon> <DependentUpon>MainPage.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="MainPageWrapper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\AppResources.Designer.cs"> <Compile Include="Resources\AppResources.Designer.cs">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
Expand Down
4 changes: 0 additions & 4 deletions platform/wp8/rhoruntime/FakeDefs.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ RHO_GLOBAL void rho_appmanager_load( void* /*httpContext*/, const char* /*szQuer
// Nothing // Nothing
} }


RHO_GLOBAL void rho_sys_app_exit()
{
}

RHO_GLOBAL void rho_sys_report_app_started() RHO_GLOBAL void rho_sys_report_app_started()
{ {
} }
Expand Down
Loading

0 comments on commit 60245d3

Please sign in to comment.