Skip to content

Commit

Permalink
Initial WPF support
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasovg committed Oct 27, 2016
1 parent 8ce3721 commit 7ac8925
Show file tree
Hide file tree
Showing 26 changed files with 1,683 additions and 15 deletions.
7 changes: 7 additions & 0 deletions tns-core-modules/application/application.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ declare module "application" {
*/
export var ios: iOSApplication;

export var wpf: WPFApplication;

/**
* Data for the Android activity events.
*/
Expand Down Expand Up @@ -338,6 +340,11 @@ declare module "application" {
cancel: boolean;
}

export interface WPFApplication extends observable.Observable {
nativeApp: any; /* System.Windows.Application */
mainWindow: any /* System.Windows.Window */
}

/**
* The abstraction of an Android-specific application object.
*/
Expand Down
77 changes: 77 additions & 0 deletions tns-core-modules/application/application.wpf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import appModule = require("./application-common");
import definition = require("application");
import frame = require("ui/frame");
import observable = require("data/observable");
import * as typesModule from "utils/types";
import * as enumsModule from "ui/enums";
var presentation = requireAssembly("PresentationFramework");

let enums: typeof enumsModule;

global.moduleMerge(appModule, exports);
const typedExports: typeof definition = exports;

let started = false;
let mainWindow;
export function start(entry?: frame.NavigationEntry) {
if (started) {
throw new Error("Application is already started.");
}

started = true;
if (entry) {
typedExports.mainEntry = entry;
}

loadCss();
wpf.initialize();
}

function loadCss() {
//HACK: identical to application.ios.ts
typedExports.appSelectors = typedExports.loadCss(typedExports.cssFile) || [];
if (typedExports.appSelectors.length > 0) {
typedExports.mergeCssSelectors(typedExports);
}
}

export function addCss(cssText: string) {
//HACK: identical to application.ios.ts
const parsed = typedExports.parseCss(cssText);
if (parsed) {
typedExports.additionalSelectors.push.apply(typedExports.additionalSelectors, parsed);
typedExports.mergeCssSelectors(typedExports);
}
}

class WPFApp extends observable.Observable implements definition.WPFApplication {
public nativeApp;
public mainWindow;

public initialize() {
this.nativeApp = new presentation.System.Windows.Application();
var that = this;
this.nativeApp.Startup.connect(function(sender, e) {
var navParam = typedExports.mainEntry;
if (!navParam) {
navParam = {
moduleName: typedExports.mainModule
}
}

var rootFrame = new frame.Frame();

that.mainWindow = new presentation.System.Windows.Window();
that.mainWindow.Loaded.connect(function(s, e) {
rootFrame.onLoaded();
});
navParam.context = that.mainWindow;

rootFrame.navigate(navParam);
that.mainWindow.Show();
});
this.nativeApp.Run();
}
}

export var wpf = new WPFApp();
20 changes: 19 additions & 1 deletion tns-core-modules/color/color-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,32 @@ export class Color implements definition.Color {
return undefined;
}

public _argbFromString(hex: string): number {
get wpf(): any {
return undefined;
}

public _argbFromString(hex: string): number {
return Color.defaultArgbFromString(hex);
}

public equals(value: definition.Color): boolean {
return this.argb === value.argb;
}

public static defaultArgbFromString(hex: string) {
if (hex.charAt(0) === AMP) {
hex = hex.substr(1);
}

var intVal = parseInt(hex, 16);
if (hex.length === 6) {
// add the alpha component since the provided string is RRGGBB
intVal |= 255 << 24;
}

return intVal;
}

public static equals(value1: definition.Color, value2: definition.Color): boolean {
// both values are falsy
if (!value1 && !value2) {
Expand Down
2 changes: 2 additions & 0 deletions tns-core-modules/color/color.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ declare module "color" {
*/
ios: any /* UIColor */;

wpf: any /* System.Windows.Media.Color */

/**
* Specifies whether this Color is equal to the Color parameter.
* @param value The Color to test.
Expand Down
14 changes: 0 additions & 14 deletions tns-core-modules/color/color.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,4 @@ export class Color extends common.Color {
}
return this._ios;
}

public _argbFromString(hex: string): number {
if (hex.charAt(0) === AMP) {
hex = hex.substr(1);
}

var intVal = parseInt(hex, 16);
if (hex.length === 6) {
// add the alpha component since the provided string is RRGGBB
intVal |= 255 << 24;
}

return intVal;
}
}
14 changes: 14 additions & 0 deletions tns-core-modules/color/color.wpf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import common = require("./color-common");

let presentationCore = requireAssembly("PresentationCore");

export class Color extends common.Color {
private _wpf;

get wpf(): number {
if(!this._wpf) {
this._wpf = presentationCore.System.Windows.Media.Color.FromArgb(this.a, this.r, this.g, this.b);
}
return this._wpf;
}
}
1 change: 1 addition & 0 deletions tns-core-modules/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ interface Console {

declare var console: Console;
declare var require: NativeScriptRequire;
declare var requireAssembly: any;

// Global functions
declare function Deprecated(target: Object, key?: string | symbol, value?: any): void;
Expand Down
Loading

0 comments on commit 7ac8925

Please sign in to comment.