Mercurial > projects > mde
diff mde/gui/widget/Window.d @ 65:891211f034f2
Changes to widgets: widgets may now get strings as creation data. Strings for TextWidgets can be set in files (in a temporary mannor).
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sun, 29 Jun 2008 15:40:37 +0100 |
parents | d43523ed4b62 |
children | f54ae4fc2b2f |
line wrap: on
line diff
--- a/mde/gui/widget/Window.d Sun Jun 29 11:55:55 2008 +0100 +++ b/mde/gui/widget/Window.d Sun Jun 29 15:40:37 2008 +0100 @@ -69,7 +69,10 @@ // Create the primary widget (and indirectly all sub-widgets), throwing on error: // Note: GridLayoutWidget's this relies on rend.layoutSpacing. widget = makeWidget (0); // primary widget always has ID 0. - widgetData = null; // data is no longer needed: allow GC to collect (cannot safely delete) + // This data is no longer needed by Window, although its sub-arrays may still be used, so + // let the GC collect what it can: + widgetData = null; + widgetStrings = null; // get border sizes: border = rend.setSizable (isWSizable, isHSizable); // depends on widget @@ -98,10 +101,14 @@ //BEGIN Mergetag code void addTag (char[] tp, mt.ID id, char[] dt) { // Priority is HIGH_LOW, so don't overwrite data which has already been loaded. - if (tp == INTAA) { + if (tp == INTAINT) { if (id == WDGD && widgetData == null) { widgetData = cast(int[][widgetID]) parseTo!(int[][int]) (dt); } + } else if (tp == CHARAINT) { + if (id == WS && widgetStrings == null) { + widgetStrings = parseTo!(char[][int]) (dt); + } } else if (tp == INTA) { if (id == MD && mutableData == null) { mutableData = parseTo!(int[]) (dt); @@ -121,7 +128,8 @@ /+ NOTE: currently editing is impossible... if (edited) { // only save the widget creation data if it's been adjusted: addCreationData (widget); // generate widget save data - dlg (INTAA, WDGD, parseFrom!(int[][int]) (widgetData)); + dlg (INTAINT, WDGD, parseFrom!(int[][int]) (widgetData)); + dlg (CHARAINT, WS, parseFrom!(char[][int]) (widgetStrings)); }+/ // Save mutable data: dlg (INTA, MD, parseFrom!(int[]) (widget.getMutableData)); @@ -130,11 +138,13 @@ dlg (INT, Y, parseFrom!(int) (y)); } private static const { - auto INTAA = "int[][int]"; + auto CHARAINT = "char[][int]"; + auto INTAINT = "int[][int]"; auto INTA = "int[]"; auto INT = "int"; auto WDGD = "widgetData"; auto MD = "mutableData"; + auto WS = "widgetStrings"; auto X = "x"; auto Y = "y"; } @@ -161,6 +171,20 @@ return createWidget (this, *d); } + char[] getWidgetString (int i) + in { + // widgetStrings is freed at same time as widgetData + // but widgetData is guaranteed to be read + assert (widgetData !is null, "getWidgetString called after widget creation finished"); + } body { + char[]* p; + if (widgetStrings is null || + (p = i in widgetStrings) is null ) + throw new WindowLoadException ("Needed widgetStrings not set for Window"); + + return *p; + } + /** Add this widget's data to that to be saved, returning it's widgetID. */ widgetID addCreationData (IWidget widget) { @@ -170,12 +194,31 @@ else i = widgetData.keys[$-1] + 1; + /+ Doesn't this have no effect except when getCreationData throws, in which case the data + + isn't used anyway? I'm sure it was added for a reason... FIXME and below widgetData[i] = null; // Make sure the same ID doesn't get used by a recursive call + +/ widgetData[i] = widget.getCreationData; return i; } + int addWidgetString (char[] str) + { + int i; + if (widgetStrings is null) + i = 0; + else + i = widgetStrings.keys[$-1] + 1; + + /+ See above. FIXME + widgetStrings[i] = null; // Make sure the same ID doesn't get used by a recursive call + +/ + widgetStrings[i] = str; + + return i; + } + IGui gui () { return gui_; } @@ -356,6 +399,7 @@ // Data used for saving and loading (null in between): int[][widgetID] widgetData = null;// Data for all widgets under this window int[] mutableData = null; // Widget's mutable data (adjusted sizes, etc.) + char[][int] widgetStrings = null;// Strings by ID; string-typed creation data IGui gui_; // The gui managing this window IRenderer rend; // The window's renderer