/*----------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License.You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is Fever Framework code. The Initial Developer of the Original Code is Romain Ecarnot. Portions created by Initial Developer are Copyright (C) 2006 the Initial Developer. All Rights Reserved. Contributor(s): Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -----------------------------------------------------------------------------*/ import systools.Dialogs; /** * Fever context for Haxe / Screenweaver Hx application. * * @author Romain Ecarnot */ class HxFeverContext implements haxe.rtti.Infos { //------------------------------------------------------------------------- // Private properties //------------------------------------------------------------------------- private static var flash : swhx.Flash; private static var wnd : swhx.Window; private static var cnx : swhx.Connection; //------------------------------------------------------------------------- // Public Properties //------------------------------------------------------------------------- public static var GUI_ID : String = "feverhx"; //------------------------------------------------------------------------- // Public API //------------------------------------------------------------------------- /** * Need by Fever ContextSwitcher to retreive Haxe context. * * @param caption New title */ static public function isHaxe() : Bool { return true; } /** * Defines application tile. * * @param caption New title */ static public function setTitle( caption : String ) { wnd.title = caption; } /** * Returns application title. */ static public function getTitle() : String { return wnd.title; } /** * Sets new application position on user screen. * * @param x Position on X axis * @param y Position on X axis */ static public function setLocation( x : Int, y : Int ) { wnd.left = x; wnd.top = y; } /** * Returns application location. */ static public function getLocation() { return { x : wnd.left, y : wnd.top }; } /** * Sets new application size. * * @param width New application's width * @param height New application's height */ static public function setSize( width : Int, height : Int ) { wnd.width = width; wnd.height = height; } /** * Returns application size. */ static public function getSize() { return { width : wnd.width, height : wnd.height }; } /** * Sets application state to fullscreen mode. * * @param b 'true' to enable fullscreen */ static public function setFullScreen( enabled : Bool ) { wnd.fullscreen = enabled; } /** * Returns 'true' is application is in Fullscreen mode. */ static public function getFullScreen() : Bool { return wnd.fullscreen; } /** * Handler call by SWHX when user click on "close" container button, or by * Fever when user call the Fever.application.quit() method. * * @param force 'true' to disable user warning message * @param caption Dialog title * @param message Dialog message to warn the user */ static public function exit( force : Bool, caption : String, message : String ) { if( force == true ) wnd.destroy(); else { var b : Bool = systools.Dialogs.confirm( caption, message, false ); if( b ) wnd.destroy(); } } /** * Opens a 'confirm' dialog and returns user action as Boolean. */ static public function confirm( caption : String, title : String ) : Bool { return Dialogs.confirm( title, caption, false ); } /** * Opens a 'alert' dialog. * * @param caption Dialog message * @param title Dialog title * @param bError Is an error dialog or not */ static public function alert( caption : String, title : String, bError : Bool ) { Dialogs.message( title, caption, bError ); } /** * Opens a "OpenFile" dialog. * * @return The file or file(s) selected by the user.
* When the multipleSelect option is enabled and multiple files are returned, the list of files * will be separated by a ";" character.
* Returns {@code null} if no selection is available. */ static public function showFileOpenDialog( caption : String, filter, multipleSelect : Bool ) { if( !multipleSelect ) multipleSelect = false; var l : Int = filter.length; var descA : Array = filter.descriptions; var extA : Array = filter.extensions; var filters: FILEFILTERS = { count: l, descriptions: descA, extensions: extA }; var result : Array = Dialogs.openFile( caption, "", filters ); if( !multipleSelect ) return result[0]; else return result.join(";"); } /** * Opens a "SaveFile" dialog. * * @return The selected full qualified file path */ static public function showFileSaveDialog( caption : String ) { var result : String = Dialogs.saveFile( caption, "", "c:" ); return result; } /** * Opens a "Browse folder" dialog. * * @return The selected full qualified folder path */ static public function showBrowseFolderDialog( caption : String ) { var result : String = Dialogs.folder( caption, "" ); return result; } /** * Returns {@code true} if passed-in {@code path} is a valid * directory. */ static public function isDirectory( path : String ) : Bool { return neko.FileSystem.isDirectory( path ); } /** * Creates passed-in {@code path} directory on filesystem. * *

Returns {@code true} if operation ends successfully. * * @param path A fully qualified path */ static public function createDirectory( path : String ) { try { neko.FileSystem.createDirectory( path ); return true; } catch( e : Dynamic ) { return false; } } /** * Removes passed-in {@code path} directory from filesystem. * *

All files insides directory are also deleted. * *

Returns {@code true} if operation ends successfully. * * @param path A fully qualified path */ static public function deleteDirectory( path : String ) : Bool { try { neko.FileSystem.deleteDirectory( path ); return true; } catch( e : Dynamic ) { return false; } } /** * Renames passed-in {@code path} directory with new passed-in * {@code newName} name. * *

Returns {@code true} if operation ends successfully. * * @param path A fully qualified path * @param newName A fully qualified path */ static public function renameDirectory( path : String, newName : String ) : Bool { try { neko.FileSystem.rename( path, newName ); return true; } catch( e : Dynamic ) { return false; } } /** * Returns {@code true} if passed-in {@code path} is a valid file * on filesystem. * * @param path A fully qualified file path */ static public function isFile( path : String ) : Bool { return neko.FileSystem.exists( path ); } /** * Renames passed-in {@code path} file with new passed-in * {@code newName} name. * *

Returns {@code true} if operation ends successfully. * * @param path A fully qualified file path * @param newName A fully qualified file path */ static public function renameFile( path : String, newName : String ) : Bool { try { neko.FileSystem.rename( path, newName ); return true; } catch( e : Dynamic ) { return false; } } /** * Removes passed-in {@code path} file from filesystem. * * *

Returns {@code true} if operation ends successfully. * * @param path A fully qualified file path */ static public function deleteFile( path : String ) : Bool { try { neko.FileSystem.deleteFile( path ); return true; } catch( e : Dynamic ) { return false; } } /** * Reads and returns file content. * * @return The file content or 'null' */ static public function readFile( fullQualifiedPath : String ) : String { try { return neko.io.File.getContent( fullQualifiedPath ); } catch( e : Dynamic ) return null; } /** * Creates a file and save the content inside. * * @return true if process is ok */ static public function writeToFile( data : String, path : String ) : Bool { try { var f = neko.io.File.write( path, false ); if( f != null ) { f.write( data ); f.close(); return true; } return false; } catch( e : Dynamic ) return false; } /** * Appends content to a file. * * @return true if process is ok */ static public function appendToFile( data : String, path : String ) : Bool { try { var f = neko.io.File.append( path, false ); if( f != null ) { f.write( data ); f.close(); return true; } return false; } catch( e : Dynamic ) return false; } /** * Constructor */ public function new( swfFile : String, width : Int, height : Int ) { // Backend gateway var server = new neko.net.RemotingServer(); server.addObject( GUI_ID, HxFeverContext ); // Window creation wnd = new swhx.Window("", width, height ); // Flash creation flash = new swhx.Flash( wnd, server ); flash.setAttribute( "id","ui" ); flash.setAttribute( "src", swfFile ); flash.start(); // GUI gateway cnx = swhx.Connection.flashConnect( flash ); // application properties wnd.resizable = true; wnd.onClose = function() { cnx.onQuit.call( [] ); return false; } wnd.onMinimize = function () : Bool { cnx.onState.call( [ -1 ] ); return true; }; wnd.onRestore = function() { cnx.onState.call( [ 0 ] ); }; wnd.onMaximize = function () : Bool { cnx.onState.call( [ 1 ] ); return true; }; } /** * Allowing ( or not ) window resizing */ public function setResizable( b : Bool ) { wnd.resizable = b; } /** * Returns if window resizing is enabled */ public function isResizable() : Bool { return wnd.resizable; } public function start() { wnd.show( true ); } }