Skip to content

Commit

Permalink
Run Haxe formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
jgranick committed May 20, 2024
1 parent b08f2f2 commit ea3ac3a
Show file tree
Hide file tree
Showing 70 changed files with 698 additions and 678 deletions.
101 changes: 54 additions & 47 deletions lib/draft-api/src/openfl/display/NativeMenu.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import haxe.ds.IntMap;
@:access(openfl.display.NativeMenuItem)
class NativeMenu extends EventDispatcher
{
private static var __hasContextMenuListener:Bool = false;
private static var __hasContextMenuListener:Bool = false;

public static var isSupported(get, never):Bool;

private static inline function get_isSupported():Bool
Expand All @@ -33,21 +33,20 @@ class NativeMenu extends EventDispatcher
public var items(get, set):Array<NativeMenuItem>;
public var numItems(get, never):Int;
public var parent(get, never):NativeMenu;

public var name:String = "";

private var __items:Array<NativeMenuItem>;
private var __parent:NativeMenu;
private var __contextMenuData:ContextMenuData;


public function new()
{
super();
__items = [];
__contextMenuData = new ContextMenuData();
}

private function get_parent():NativeMenu
{
return __parent;
Expand All @@ -60,31 +59,31 @@ class NativeMenu extends EventDispatcher
__contextMenuData.items.push(item.__contextMenuItemData);

__update();

return item;
}

public function addItemAt(item:NativeMenuItem, index:Int):NativeMenuItem
{
item.__setMenu(this);
__items.insert(index, item);
__contextMenuData.items.insert(index, item.__contextMenuItemData);
__contextMenuData.items.insert(index, item.__contextMenuItemData);

__update();

return item;
}

public function addSubmenu(submenu:NativeMenu, label:String):NativeMenuItem
{
var item:NativeMenuItem = new NativeMenuItem(label);
var item:NativeMenuItem = new NativeMenuItem(label);
item.submenu = submenu;

item.__setMenu(this);
__items.push(item);

__update();

return item;
}

Expand All @@ -93,12 +92,11 @@ class NativeMenu extends EventDispatcher
var item:NativeMenuItem = new NativeMenuItem(label);
item.submenu = submenu;
item.__setMenu(this);



__items.insert(index, item);

__update();

return item;
}

Expand Down Expand Up @@ -147,7 +145,7 @@ class NativeMenu extends EventDispatcher
public function removeAllItems():Void
{
__contextMenuData.removeAllItems();

__update();
}

Expand All @@ -157,33 +155,36 @@ class NativeMenu extends EventDispatcher
__contextMenuData.removeItem(item.__contextMenuItemData);

__update();

return item;
}

public function removeItemAt(index:Int):NativeMenuItem
{
var item:NativeMenuItem = __items.splice(index, 1)[0];
item.__setMenu(null);

__contextMenuData.items.splice(index, 1);

__update();

return item;
}

public function setItemIndex(item:NativeMenuItem, index:Int):Void
{
var currentItemIndex:Int = __items.indexOf(item);

if (currentItemIndex == -1){

if (currentItemIndex == -1)
{
__items.insert(index, item);
} else {
}
else
{
__items.splice(currentItemIndex, 1);
__items.insert(index, item);
}

__update();
}

Expand All @@ -196,40 +197,49 @@ class NativeMenu extends EventDispatcher
{
__items = value;
__update();

return value;
}

private function get_numItems():Int
{
return __items.length;
}

private function __update():Void{
if (__parent != null){

private function __update():Void
{
if (__parent != null)
{
__parent.__update();
} else {
for (window in NativeApplication.nativeApplication.openedWindows){
if (window.menu == this){
}
else
{
for (window in NativeApplication.nativeApplication.openedWindows)
{
if (window.menu == this)
{
__redrawNativeWindowMenu(window);
break;
}
}
}
}
}

private function __redrawNativeWindowMenu(window:NativeWindow):Void{

private function __redrawNativeWindowMenu(window:NativeWindow):Void
{
window.menu = this;
}

private function __setupNativeListener(hWnd:Int):Void{
if (!__hasContextMenuListener){

private function __setupNativeListener(hWnd:Int):Void
{
if (!__hasContextMenuListener)
{
WinMenuUtil.addContextMenuListener(hWnd, __onMenuItemSelect);

__hasContextMenuListener = true;
}
}
}

private static var __callbacks:IntMap<Function> = new IntMap();

private static function __onMenuItemSelect(id:UInt):Void
Expand All @@ -240,7 +250,4 @@ class NativeMenu extends EventDispatcher
callback();
}
}



}
}
18 changes: 10 additions & 8 deletions lib/draft-api/src/openfl/display/NativeMenuItem.hx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package openfl.display;

import _internal.native.menu.ContextMenuData.ContextMenuItemData;
import openfl.events.Event;
import openfl.events.EventType;
import openfl.utils.Object;
import openfl.events.EventDispatcher;


/**
* ...
* @author Christopher Speciale
Expand Down Expand Up @@ -49,7 +49,7 @@ class NativeMenuItem extends EventDispatcher

public function clone():NativeMenuItem
{
//TODO: clone has to recursively clone children, these hold references.
// TODO: clone has to recursively clone children, these hold references.
var item:NativeMenuItem = Type.createEmptyInstance(NativeMenuItem);
item.__contextMenuItemData = __contextMenuItemData.clone();
item.data = data;
Expand Down Expand Up @@ -173,12 +173,14 @@ class NativeMenuItem extends EventDispatcher
return value;
}

private function __dispatchSelectEvent():Void{
private function __dispatchSelectEvent():Void
{
dispatchEvent(new Event(Event.SELECT));
}

override public function addEventListener<T>(type:EventType<T>, listener:T->Void, useCapture:Bool = false, priority:Int = 0, useWeakReference:Bool = false):Void
{
}

override public function addEventListener<T>(type:EventType<T>, listener:T->Void, useCapture:Bool = false, priority:Int = 0,
useWeakReference:Bool = false):Void
{
super.addEventListener(type, listener, useCapture, priority, useWeakReference);

var menuId:UInt = Reflect.field(__contextMenuItemData, "_id");
Expand All @@ -192,4 +194,4 @@ class NativeMenuItem extends EventDispatcher
var menuId:UInt = Reflect.field(__contextMenuItemData, "_id");
NativeMenu.__callbacks.remove(menuId);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package _internal.native.desktop;

import _internal.native.desktop.extension.WinDesktopUtilExtern;

/**
* ...
* @author Christopher Speciale
*/

@:access(_internal.native.desktop.extension.WinDesktopUtilExtern)
class WinDesktopUtil
class WinDesktopUtil
{
public static function getCursorPos():Array<Int> {
public static function getCursorPos():Array<Int>
{
return WinDesktopUtilExtern.__getCursorPos();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ package _internal.native.desktop.extension;
* ...
* @author Christopher Speciale
*/

@:include('./WinDesktopUtilExtern.cpp')
extern class WinDesktopUtilExtern
extern class WinDesktopUtilExtern
{
@:native('desktopUtil_getCursorPos') private static function __getCursorPos():Array<Int>;
}
@:native('desktopUtil_getCursorPos') private static function __getCursorPos():Array<Int>;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package _internal.native.menu;

import openfl.utils.Object;

abstract ContextMenuData (Dynamic)
{
abstract ContextMenuData(Dynamic)
{
public var items(get, never):Array<ContextMenuItemData>;

public inline function new()
{
var menu:Dynamic = {};
menu.items = [];
this = menu;

this = menu;
}

public inline function addItem(item:ContextMenuItemData):ContextMenuItemData
Expand Down Expand Up @@ -99,11 +100,12 @@ abstract ContextMenuData (Dynamic)
abstract ContextMenuItemData(Dynamic)
{
private static var __idSpace:UInt = 0;

private static function __getId():UInt{

private static function __getId():UInt
{
return __idSpace++;
}

public var checked(get, set):Bool;
public var enabled(get, set):Bool;
public var isSeparator(get, set):Bool;
Expand Down Expand Up @@ -247,4 +249,3 @@ abstract ContextMenuItemData(Dynamic)
return this.submenu = value;
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package _internal.native.menu;

import _internal.native.menu.extension.WinMenuUtilExtern;
import openfl.Lib;

Expand All @@ -7,25 +8,25 @@ import openfl.Lib;
* @author Christopher Speciale
*/
@:access(_internal.native.menu.extension.WinMenuUtilExtern)
class WinMenuUtil
class WinMenuUtil
{

public static function showPopupMenu(id:Int, menuData:ContextMenuData, x:Int, y:Int):Bool
{
return WinMenuUtilExtern.__showPopupMenu(id, menuData, x, y);
}

public static function showPopupMenuAtCursorPos(id:Int, menuData:ContextMenuData):Bool
{
{
return WinMenuUtilExtern.__showPopupMenuAtCursorPos(id, menuData);
}

public static function addSystemMenu(id:Int, menuData:ContextMenuData):Bool{

public static function addSystemMenu(id:Int, menuData:ContextMenuData):Bool
{
return WinMenuUtilExtern.__addSystemMenu(id, menuData);
}

public static function addContextMenuListener(id:Int, callback:UInt->Void):Bool
{
return WinMenuUtilExtern.__addContextMenuListener(id, callback);
}
}
}
Loading

0 comments on commit ea3ac3a

Please sign in to comment.