diff --git a/haxe/ui/backend/ComponentBase.hx b/haxe/ui/backend/ComponentBase.hx index a15653b..cd3a662 100644 --- a/haxe/ui/backend/ComponentBase.hx +++ b/haxe/ui/backend/ComponentBase.hx @@ -204,6 +204,33 @@ class ComponentBase { } } + setupWindow(); + } + + private function replaceWindow(replacement:Window) { + if (replacement == null) { + return; + } + __children = []; + + cast(this, Component).invalidateStyle(false); + window.destroy(); + window = replacement; + + setupWindow(); + } + + private function setupWindow() { + var platform:PlatformInfo = new PlatformInfo(); + if (Std.is(window, Notebook)) { + if (platform.isWindows) { + var n:Notebook = cast window; + n.padding = new hx.widgets.Size(6, 6); + //n.backgroundColour = 0xF0F0F0; + //n.refresh(); + } + } + if (Std.is(window, ScrollBar)) { var scrollbar:ScrollBar = cast window; scrollbar.setScrollbar(0, 5, 100, 5); @@ -232,7 +259,7 @@ class ComponentBase { window.bind(EventType.ERASE_BACKGROUND, function(e) { }); - } + } } private var _paintStyle:Style = null; @@ -741,4 +768,4 @@ class ComponentBase { } } } -} \ No newline at end of file +} diff --git a/haxe/ui/backend/TextInputBase.hx b/haxe/ui/backend/TextInputBase.hx index 7773a82..bbde1c6 100644 --- a/haxe/ui/backend/TextInputBase.hx +++ b/haxe/ui/backend/TextInputBase.hx @@ -10,4 +10,5 @@ class TextInputBase extends TextDisplayBase { public var multiline:Bool; public var password:Bool; public var wordWrap:Bool; + public var readOnly:Bool; } diff --git a/haxe/ui/backend/hxwidgets/StyleParser.hx b/haxe/ui/backend/hxwidgets/StyleParser.hx index d59fd9d..b48a318 100644 --- a/haxe/ui/backend/hxwidgets/StyleParser.hx +++ b/haxe/ui/backend/hxwidgets/StyleParser.hx @@ -31,10 +31,11 @@ class StyleParser { case "ScrollBarStyle.VERTICAL": return ScrollBarStyle.VERTICAL; case "TextCtrlStyle.MULTILINE": return TextCtrlStyle.MULTILINE; case "TextCtrlStyle.HSCROLL": return TextCtrlStyle.HSCROLL; + case "TextCtrlStyle.READONLY": return TextCtrlStyle.READONLY; default: trace('WARNING: hxWidgets style "${style}" not recognised'); } return 0; } -} \ No newline at end of file +} diff --git a/haxe/ui/backend/hxwidgets/behaviours/ControlReadOnly.hx b/haxe/ui/backend/hxwidgets/behaviours/ControlReadOnly.hx new file mode 100644 index 0000000..a8ae8eb --- /dev/null +++ b/haxe/ui/backend/hxwidgets/behaviours/ControlReadOnly.hx @@ -0,0 +1,63 @@ +package haxe.ui.backend.hxwidgets.behaviours; + +import haxe.ui.util.Variant; +import haxe.ui.components.TextArea; +import hx.widgets.Bitmap; +import hx.widgets.Control; +import hx.widgets.Button; +import hx.widgets.StaticText; +import hx.widgets.TextCtrl; +import hx.widgets.styles.TextCtrlStyle; + +@:keep +@:access(haxe.ui.core.Component) +class ControlReadOnly extends HxWidgetsBehaviour { + public override function set(value:Variant) { + super.set(value); + if (_component.window == null) { + return; + } + + var ctrl:Control = cast _component.window; + if (value.isNull == false) { + if (Std.is(_component.window, TextCtrl)) { + var textctrl:TextCtrl = cast _component.window; + var style = textctrl.windowStyle; + + if (value == false && (style & TextCtrlStyle.READONLY > 0)) { + style -= TextCtrlStyle.READONLY; + } + if (value == true) { + style |= TextCtrlStyle.READONLY; + } + + var text = textctrl.value; + var parent = textctrl.parent; + var id = textctrl.id; + + var replacement = new TextCtrl(parent, text, style, id); + replacement.size = textctrl.size; + replacement.position = textctrl.position; + _component.replaceWindow(replacement); + } + _component.invalidateLayout(); + } + + + var textArea:TextArea = cast _component; + textArea.getTextInput().readOnly = value; + } + + public override function get():Variant { + if (_component.window == null) { + return null; + } + + if (Std.is(_component.window, TextCtrl)) { + var textctrl:TextCtrl = cast _component.window; + return (textctrl.windowStyle & TextCtrlStyle.READONLY) > 0; + } + + return null; + } +} diff --git a/haxe/ui/backend/hxwidgets/behaviours/ControlWrap.hx b/haxe/ui/backend/hxwidgets/behaviours/ControlWrap.hx new file mode 100644 index 0000000..b9507c1 --- /dev/null +++ b/haxe/ui/backend/hxwidgets/behaviours/ControlWrap.hx @@ -0,0 +1,63 @@ +package haxe.ui.backend.hxwidgets.behaviours; + +import haxe.ui.util.Variant; +import haxe.ui.components.TextArea; +import hx.widgets.Bitmap; +import hx.widgets.Control; +import hx.widgets.Button; +import hx.widgets.StaticText; +import hx.widgets.TextCtrl; +import hx.widgets.styles.TextCtrlStyle; + +@:keep +@:access(haxe.ui.core.Component) +class ControlWrap extends HxWidgetsBehaviour { + public override function set(value:Variant) { + super.set(value); + if (_component.window == null) { + return; + } + + var ctrl:Control = cast _component.window; + if (value.isNull == false) { + if (Std.is(_component.window, TextCtrl)) { + var textctrl:TextCtrl = cast _component.window; + var style = textctrl.windowStyle; + if (value == true && (style & TextCtrlStyle.DONTWRAP > 0)) { + style -= TextCtrlStyle.DONTWRAP; + } + else if (value == false && (style & TextCtrlStyle.BESTWRAP > 0)) { + style -= TextCtrlStyle.BESTWRAP; + } + style |= (value == true) ? TextCtrlStyle.BESTWRAP : TextCtrlStyle.DONTWRAP; + var text = textctrl.value; + var parent = textctrl.parent; + var id = textctrl.id; + + var replacement = new TextCtrl(parent, text, style, id); + replacement.size = textctrl.size; + replacement.position = textctrl.position; + _component.replaceWindow(replacement); + } + _component.invalidateLayout(); + } + + + var textArea:TextArea = cast _component; + textArea.getTextInput().wordWrap = value; + textArea.checkScrolls(); + } + + public override function get():Variant { + if (_component.window == null) { + return null; + } + + if (Std.is(_component.window, TextCtrl)) { + var textctrl:TextCtrl = cast _component.window; + return !((textctrl.windowStyle & TextCtrlStyle.DONTWRAP) > 0); + } + + return null; + } +} diff --git a/haxe/ui/backend/native.xml b/haxe/ui/backend/native.xml index 0e38527..43990c3 100644 --- a/haxe/ui/backend/native.xml +++ b/haxe/ui/backend/native.xml @@ -33,6 +33,8 @@ + +