Mercurial > projects > mde
diff mde/gui/widget/Ifaces.d @ 174:3d58adc17d20
Temporary commit to allow backup
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Mon, 31 Aug 2009 13:54:23 +0200 |
parents | 0dd49f333189 |
children | 1cbde9807293 |
line wrap: on
line diff
--- a/mde/gui/widget/Ifaces.d Sat Aug 08 15:53:10 2009 +0200 +++ b/mde/gui/widget/Ifaces.d Mon Aug 31 13:54:23 2009 +0200 @@ -26,6 +26,11 @@ * * It's recommended that widgets inherit one of the A*Widget classes rather * than impement I*Widget directly. + * + * Protection: please keep it as tight as possible. List it explicitly for + * every function in this module; then the compiler checks overridden functions + * have the correct protection attribute. + * BUG: currently it's a bit of a mess, because of a compiler bug. *****************************************************************************/ module mde.gui.widget.Ifaces; @@ -49,13 +54,19 @@ * * Actually the return value is ignored; I think widgets still return it * correctly though. */ - bool saveChanges (); + public bool saveChanges (); + + /** Draw, using the stored values of x and y. + * + * Maybe later enforce clipping of all sub-widget drawing, particularly for cases where only + * part of the widget is visible: scroll bars or a hidden window. */ + public void draw (); /** Called on a widget when something is dragged onto it. * * Generally, content editing widgets should implement this as: * --- - override bool dropContent (IContent content) { + public override bool dropContent (IContent content) { if (content_.setContent (content)) return true; return parent.dropContent (content); @@ -68,7 +79,7 @@ * * Returns: true if the content was received (false if it reaches the * WidgetManager and is still not used). */ - bool dropContent (IContent content); + public bool dropContent (IContent content); } /****************************************************************************** @@ -83,7 +94,10 @@ *****************************************************************************/ interface IParentWidget : IWidget { - /** Checks for recursion of unsafe widgets to prevent infinite recursion. */ + /** Checks for recursion of unsafe widgets to prevent infinite recursion. + * + * Only called by makeWidget() when creating child widgets and recursively + * from the same method in a child widget. */ void recursionCheck (widgetID, IContent); /** IPPWs return self, other widgets recurse call on parent. */ @@ -93,9 +107,13 @@ * changes, since they cannot properly resize themselves. * * Parents $(I must) increase their child's size if the child is too small. - * Parents $(I must not) decrease their own size, even if they are not - * sizable; they may only decrease their childrens' sizes if it does not - * affect their own (i.e. WidgetManager and FloatingAreaWidget). + * Parents $(I must not) change their own size, even if they are not + * sizable; they may only change their childrens' sizes if it does not + * affect their own (i.e. WidgetManager and floating / popup widgets). + * + * (Hence most parents need to call this function on their parents to change + * size. In this case they also must propegate setWidth/setHeight calls on + * the child originally calling min[WH]Change.) * * Child widgets may depend on setPosition being called afterwards. * @@ -114,7 +132,7 @@ * * Note: ANY_SUBWIDGETS can cause problems like enlarging a menu bar containing a resizable * blank instead of the main part of a window. */ - enum SIZABILITY_ENUM { + protected enum SIZABILITY_ENUM { NEVER = 0, /// Parents are never resizable ALL_SUBWIDGETS = 3, /// Parents are only resizable if all sub-widgets are ANY_SUBWIDGETS = 2, /// Parents are resizable if any sub-widgets are @@ -122,7 +140,7 @@ START_TRUE = 1, /// Flag set by ALWAYS and ALL_SUBWIDGETS SUBWIDGETS = 2, /// Flag set by ALL_SUBWIDGETS and ANY_SUBWIDGETS } - static const SIZABILITY = SIZABILITY_ENUM.ANY_SUBWIDGETS; /// ditto + protected static const SIZABILITY = SIZABILITY_ENUM.ANY_SUBWIDGETS; /// ditto } /****************************************************************************** @@ -332,7 +350,7 @@ * during their creation. *****************************************************************************/ //NOTE: add another this() without the data for default initialization, for the GUI editor? -interface IChildWidget : IWidget +abstract class IChildWidget : IWidget { //BEGIN Load and save /** 2nd stage of initialization for widgets; also called on some changes. @@ -351,7 +369,7 @@ * Returns: * The method must return true on initial setup and if its dimensions * (may) have changed. */ - bool setup (uint n, uint flags); + bool setup (uint n, uint flags) {return 0;} /+ Use when widget editing is available? Requires widgets to know their parents. /** Called when a child widget's size has changed. @@ -369,22 +387,22 @@ * * Parents normally take their resizability from sub-widgets; see SIZABILITY for how they do * this. */ - bool isWSizable (); - bool isHSizable (); /// ditto + bool isWSizable () {return 0;} + bool isHSizable () {return 0;} /// ditto /** The minimal size the widget could be shrunk to (or its fixed size). * * Takes into account child-widgets and any other contents. */ - wdim minWidth (); - wdim minHeight (); /// ditto + wdim minWidth () {return 0;} + wdim minHeight() {return 0;} /// ditto /** Get the current size of the widget. */ - wdim width (); - wdim height(); /// ditto + wdim width () {return 0;} + wdim height() {return 0;} /// ditto /** (Smallest) coordinates of widget. */ - wdabs xPos (); - wdabs yPos (); /// ditto + wdabs xPos () {return 0;} + wdabs yPos () {return 0;} /// ditto /** Used to adjust the size. * @@ -400,21 +418,21 @@ * A "fixed" size widget should enlarge itself as requested. * * setPosition must be called after calling either setWidth or setHeight. */ - void setWidth (wdim nw, int dir); - void setHeight (wdim nh, int dir); /// ditto + void setWidth (wdim nw, int dir) {} + void setHeight (wdim nh, int dir) {} /// ditto /** Set the current position (called after setup and to move widget). */ - void setPosition (wdim x, wdim y); + void setPosition (wdim x, wdim y) {} //END Size and position //BEGIN Content /** Return the widget's content, or null. */ - IContent content (); + IContent content () {return null;} /** Set the widget's content, if the widget takes content and changing it * at this stage is feasible. (Also pass to sub-widgets, where the * constructor normally does so.) */ - void setContent (IContent); + void setContent (IContent) {} //END Content //BEGIN Events @@ -427,10 +445,10 @@ * (cx,cy). * * Note: use global coordinates (cx,cy) not coordinates relative to the widget. */ - IChildWidget getWidget (wdabs cx, wdabs cy); + IChildWidget getWidget (wdabs cx, wdabs cy) {return null;} /** Return true if (cx,cy) is on self's box (doesn't matter if actually on a subwidget). */ - bool onSelf (wdabs cx, wdabs cy); + bool onSelf (wdabs cx, wdabs cy) {return 0;} /** Receive a mouse click event at cx,cy from button b (1-5 correspond to L,M,B, wheel up,down) * which is a down-click if state is true. @@ -443,14 +461,14 @@ * $(TR $(TD 2) $(TD Request the functions dragMotion and dragRelease are called)) * $(TR $(TD 4) $(TD Display the widget's content while dragging (requires 2))) * ) */ - int clickEvent (wdabs cx, wdabs cy, ubyte b, bool state); + int clickEvent (wdabs cx, wdabs cy, ubyte b, bool state) {return 0;} /** Called when dragging motion occurs, originating from this widget. * * Params: target = The widget under the mouse * * Only called if requested by clickEvent. */ - void dragMotion (wdabs cx, wdabs cy, IChildWidget target); + void dragMotion (wdabs cx, wdabs cy, IChildWidget target) {} /** Called at the end of a drag which originated from this widget. * @@ -460,24 +478,24 @@ * clickEvent on the relevent widget. * * Only called if requested by clickEvent. */ - bool dragRelease (wdabs cx, wdabs cy, IChildWidget target); + bool dragRelease (wdabs cx, wdabs cy, IChildWidget target) {return 0;} /** Receives keyboard events when requested. * * Params: * sym SDLKey key sym, useful for keys with no character code such as arrow keys * letter The character input, in UTF-8 */ - void keyEvent (ushort sym, char[] letter); + public void keyEvent (ushort sym, char[] letter); /** Called when keyboard input focus is lost. */ - void keyFocusLost (); + public void keyFocusLost (); /** Called on all widgets when the mouse moves over it (state == true) and * when it leaves (state == false). */ - void underMouse (bool state); + void underMouse (bool state) {} /** When a pop-up is closed the manager calls requestRedraw and this function on its parent. */ - void popupClose (); + protected void popupClose (); /** When a click is on the parent of a popup, this function is called instead of the usual * clickEvent. * @@ -485,16 +503,10 @@ * true to close the popup. * * Note: this means the parent can't receive text input without code changes. */ - bool popupParentClick (); + protected bool popupParentClick (); //END Events - /** Draw, using the stored values of x and y. - * - * Maybe later enforce clipping of all sub-widget drawing, particularly for cases where only - * part of the widget is visible: scroll bars or a hidden window. */ - void draw (); - /// Logs the current and minimal size of every widget. - debug void logWidgetSize (); + debug public void logWidgetSize (); }