ecere/Window: Complimentary fix to last commit for Display mismatching rootWindow...
[sdk] / ecere / src / gui / Window.ec
index 2f7ee6f..26591e7 100644 (file)
@@ -39,12 +39,17 @@ import "WindowList"
 import "i18n"
 
 // Had to define this here for native decorations support, because the menu bar is part of total decoration's size, but not part of the system decorations
+#ifdef HIGH_DPI
+define skinMenuHeight = 40;
+define statusBarHeight = 30;
+#else
 define skinMenuHeight = 25;
 define statusBarHeight = 18;
+#endif
 
 default extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
 
-public enum DialogResult { cancel, yes, no, ok };
+public enum DialogResult : int64 { cancel, yes, no, ok };
 
 public class MouseButtons
 {
@@ -498,7 +503,13 @@ private:
 
    Window()
    {
-      if(guiApp) guiApp.Initialize(true);
+      bool switchMode = true;
+#if defined(__ANDROID__)
+      switchMode = false;
+      fullRender = true;
+#endif
+      if(guiApp)
+         guiApp.Initialize(switchMode);
 
       if(guiApp && guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
       {
@@ -732,7 +743,7 @@ private:
       {
          int x = absPosition.x + clientStart.x;
          int y = absPosition.y + clientStart.y;
-         if(rootWindow.nativeDecorations)
+         if(rootWindow.nativeDecorations && rootWindow.windowHandle)
          {
             x -= rootWindow.clientStart.x;
             y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
@@ -780,7 +791,7 @@ private:
       {
          int x = absPosition.x;
          int y = absPosition.y;
-         if(rootWindow.nativeDecorations)
+         if(rootWindow.nativeDecorations && rootWindow.windowHandle)
          {
             x -= rootWindow.clientStart.x;
             y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
@@ -1025,7 +1036,7 @@ private:
       }
 
       // This is required to get proper initial decoration size using native decorations on Windows
-      if(nativeDecorations && guiApp && guiApp.interfaceDriver && !visible)
+      if(nativeDecorations && windowHandle && guiApp && guiApp.interfaceDriver && !visible)
          guiApp.interfaceDriver.PositionRootWindow(this, x, y, Max(1, size.w), Max(1, size.h), true, true);
       GetDecorationsSize(&ew, &eh);
 
@@ -1629,7 +1640,7 @@ private:
       SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
 
       clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
-      if(clientResized && this == rootWindow && nativeDecorations)
+      if(clientResized && this == rootWindow && nativeDecorations && rootWindow.windowHandle)
          windowResized = true;
 
       if(display && rootWindow != this)
@@ -1699,14 +1710,17 @@ private:
                y -= guiApp.desktop.absPosition.y;
             }*/
             //guiApp.Log("Position %s\n", caption);
-            if(windowResized || windowMoved)
-               if(display && !display.flags.memBackBuffer && changeRootWindow)
-                  guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
+            if(windowHandle)
+            {
+               if(windowResized || windowMoved)
+                  if(display && !display.flags.memBackBuffer && changeRootWindow)
+                     guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
 
-            if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved))
-               for(child = parent.children.first; child && child != this; child = child.next)
-                  if(child.rootWindow)
-                     guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
+               if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved))
+                  for(child = parent.children.first; child && child != this; child = child.next)
+                     if(child.rootWindow)
+                        guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
+            }
 
             if(display)
             {
@@ -1720,7 +1734,7 @@ private:
                if(windowResized)
                {
                   // result = realResized ? display.Resize(size.w, size.h) : true;
-                  if(nativeDecorations)
+                  if(nativeDecorations && rootWindow.windowHandle)
                   {
                      int w = clientSize.w, h = clientSize.h;
                      if(hasMenuBar) h += skinMenuHeight;
@@ -1748,7 +1762,7 @@ private:
                   display.Unlock();
                }
             }
-            if(guiApp.driver && changeRootWindow)
+            if(guiApp.driver && changeRootWindow && windowHandle)
             {
                if(windowResized || windowMoved)
                   if(!display || display.flags.memBackBuffer)
@@ -1834,12 +1848,19 @@ private:
             }
             else
             {
+               int oldHRange = sbh ? sbh.range : 0;
+               int oldVRange = sbv ? sbv.range : 0;
                // Then start off with horizontal scrollbar range
                if(sbh)
                {
                   positionH = sbh.thumbPosition;
+
+                  /*
                   sbh.seen = cw;
                   sbh.total = rvw;
+                  */
+                  SBSetSeen(sbh, cw);
+                  SBSetTotal(sbh, rvw);
                   rangeH = sbh.range;
                   if(rangeH > 1)
                      ch -= guiApp.currentSkin.HorizontalSBH();
@@ -1849,8 +1870,12 @@ private:
                if(sbv)
                {
                   positionV = sbv.thumbPosition;
+                  /*
                   sbv.seen = ch;
                   sbv.total = rvh;
+                  */
+                  SBSetSeen(sbv, ch);
+                  SBSetTotal(sbv, rvh);
                   rangeV = sbv.range;
                   if(rangeV > 1)
                   {
@@ -1858,20 +1883,30 @@ private:
                      // Maybe we need to set the range on the horizontal scrollbar again
                      if(sbh)
                      {
+                        /*
                         sbh.seen = cw;
                         sbh.total = rvw;
-                        sbh.Action(setRange, positionH, 0);
+                        */
+                        SBSetSeen(sbh, cw);
+                        SBSetTotal(sbh, rvw);
+                        //sbh.Action(setRange, positionH, 0);
                         if(rangeH <= 1 && sbh.range > 1)
                         {
                            ch -= guiApp.currentSkin.HorizontalSBH();
+                           /*
                            sbv.seen = ch;
                            sbv.total = rvh;
+                           */
+                           SBSetSeen(sbv, ch);
+                           SBSetTotal(sbv, rvh);
                            rangeV = sbv.range;
-                           sbv.Action(setRange, positionV, 0);
+                           //sbv.Action(setRange, positionV, 0);
                         }
                         rangeH = sbh.range;
                      }
                   }
+                  if(sbh && sbh.range != oldHRange) sbh.Action(setRange, positionH, 0);
+                  if(sbv && sbv.range != oldVRange) sbv.Action(setRange, positionV, 0);
                }
 
                // Update the scrollbar visibility
@@ -2033,7 +2068,8 @@ private:
 
       if(sbh) // && !sbh.style.hidden
       {
-         sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
+         if(!sbh.anchored)
+            sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
          // Need to set the range again (should improve...) since the scrollbars didn't have
          // the right size when UpdateScrollArea set the range on it
          if(flag)
@@ -2044,7 +2080,8 @@ private:
       }
       if(sbv) // && !sbv.state.hidden
       {
-         sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
+         if(!sbv.anchored)
+            sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
          // Need to set the range again (should improve...) since the scrollbars didn't have
          // the right size when UpdateScrollArea set the range on it
          if(flag)
@@ -2160,17 +2197,16 @@ private:
 
    Window GetParentMenuBar()
    {
+      Window result = this;
+      bool notActiveClient = false;
       Window menuBarParent;
       for(menuBarParent = this; menuBarParent; menuBarParent = menuBarParent.parent)
       {
-         if(menuBarParent.menuBar) break;
+         if(menuBarParent.menuBar) { result = notActiveClient ? null : menuBarParent.menuBar; break; }
          if(menuBarParent.parent && /*menuBarParent != */!menuBarParent.parent.activeClient)
-         {
-            menuBarParent = null;
-            break;
-         }
+            notActiveClient = true;
       }
-      return menuBarParent ? menuBarParent.menuBar : null;
+      return result;
    }
 
    void CreateSystemChildren(void)
@@ -2650,7 +2686,7 @@ private:
       bool opaque = IsOpaque();
       Window child;
       int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
-      if(rootWindow.nativeDecorations)
+      if(rootWindow.nativeDecorations && rootWindow.windowHandle)
       {
          offsetX -= rootWindow.clientStart.x;
          offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
@@ -2669,7 +2705,7 @@ private:
                Extent * renderArea = &rootWindow.tempExtents[1];
 
                int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
-               if(child.rootWindow.nativeDecorations)
+               if(child.rootWindow.nativeDecorations && rootWindow.windowHandle)
                {
                   offsetX -= child.rootWindow.clientStart.x;
                   offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
@@ -2723,7 +2759,7 @@ private:
       Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
       Window child;
       int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
-      if(rootWindow.nativeDecorations)
+      if(rootWindow.nativeDecorations && rootWindow.windowHandle)
       {
          offsetX -= rootWindow.clientStart.x;
          offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
@@ -2920,7 +2956,7 @@ private:
       Window child;
       Window rootWindow = this.rootWindow;
       int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
-      if(rootWindow.nativeDecorations)
+      if(rootWindow.nativeDecorations && rootWindow.windowHandle)
       {
          offsetX -= rootWindow.clientStart.x;
          offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
@@ -3521,7 +3557,7 @@ private:
                   bool real = parent.activeChild != this;
 
                   // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
-                  if(/*activateParent && */guiApp.interimWindow && 
+                  if(!style.inactive && /*activateParent && */guiApp.interimWindow && 
                      !IsDescendantOf(guiApp.interimWindow) && 
                      !IsSlaveOf(guiApp.interimWindow))
                   {
@@ -4449,7 +4485,7 @@ private:
                      case tab: case shiftTab:
                      {
                         Window cycleParent = this;
-                        if(this == guiApp.interimWindow && !master.style.interim && !cycleParent.style.tabCycle)
+                        if(this == guiApp.interimWindow && master && !master.style.interim && !cycleParent.style.tabCycle && master.parent)
                            cycleParent = master.parent;
                         
                         if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
@@ -4633,9 +4669,12 @@ private:
             Window hotKeyWindow = hotKey.window;
             Window parent = hotKeyWindow.parent;
             Window prevActiveWindow = activeChild;
+            // For when sys buttons are placed inside the menu bar
+            if(parent && parent._class == class(PopupMenu))
+               parent = parent.parent;
 
-            // Don't process non-visible buttons, but make an exception for the Alt-F4 with Native Decorations turned on
-            if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1] )))
+            // Don't process non-visible buttons, but make an exception for the Alt-F4 with Native Decorations turned on; This handles alt+enter as well
+            if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1])))
                continue;
 
             if(prevActiveWindow) incref prevActiveWindow;
@@ -4691,7 +4730,7 @@ private:
 
       // Setup relationship with outside world (bb root || !bb)
       if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop || 
-         (_displayDriver && dispDriver != parent.dispDriver))
+         (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))
       {
          rootWindow = this;
          if(!tempExtents)
@@ -4723,7 +4762,7 @@ private:
       bool result = false;
       Window child;
 
-      if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && dispDriver != parent.dispDriver))))
+      if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))))
       {
          subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
          DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
@@ -4751,7 +4790,8 @@ private:
                delete display;
             }
          }
-         guiApp.interfaceDriver.SetIcon(this, icon);
+         // Sometimes icon does not show up on Windows XP if we set here...
+         // guiApp.interfaceDriver.SetIcon(this, icon);
       }
       else if(this != guiApp.desktop)
       {
@@ -4791,11 +4831,6 @@ private:
       Window child;
       WindowState stateBackup = state;
 
-      /*
-      if(!rootWindow.created)
-         printf("");
-      */
-      
       if(((subclass(Window))_class).pureVTbl)
       {
          if(_vTbl == _class._vTbl)
@@ -4936,7 +4971,7 @@ private:
             }
             */
 
-            captionFont = guiApp.currentSkin.CaptionFont();
+            captionFont = guiApp.currentSkin ? guiApp.currentSkin.CaptionFont() : null;
             AddResource(captionFont);
 
             if(OnLoadGraphics())
@@ -5274,7 +5309,7 @@ private:
       return result;
    }
 
-   bool DestroyEx(int returnCode)
+   bool DestroyEx(int64 returnCode)
    {
       OldLink slave;
       Timer timer, nextTimer;
@@ -5390,6 +5425,8 @@ private:
          if(master.defaultControl == this)
             master.defaultControl = null;
       }
+      if(parent)
+         parent.OnChildAddedOrRemoved(this, true);
       if(parent && !parent.destroyed /*&&
          rootWindow && rootWindow.display && !rootWindow.destroyed*/)
       {
@@ -5640,7 +5677,7 @@ private:
       if(prevState != newState)
          lastState = prevState;
 
-      if(rootWindow != this || !nativeDecorations)
+      if(rootWindow != this || !nativeDecorations || !windowHandle)
       {
          if(style.isActiveClient && !style.hidden && prevState == minimized)
             parent.numIcons--;
@@ -5766,7 +5803,7 @@ private:
          if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
          {
             DataRow row = listBox.AddRow();
-            row.tag = (int)child;
+            row.tag = (int64)child;
             child.FigureCaption(caption);
             row.SetData(null, caption);
          }
@@ -5988,6 +6025,9 @@ public:
             (master && master != guiApp.desktop && !master.created))
             return false;
 
+         if(parent)
+            stopwatching(parent, font);
+
          if(!parent)
             property::parent = guiApp.desktop;
          if(!master) master = parent;
@@ -6164,9 +6204,12 @@ public:
                         if(state == minimized) parent.numIcons--;
                      }
 
+                     parent.OnChildAddedOrRemoved(this, false);
+
                      // Real set state & activate for proper display & activation
                      property::visible = visible;
                      //  SetState(state & 0x00000003, true, 0);
+                     guiApp.interfaceDriver.SetIcon(this, icon);
 
                      if(visible)
                      {
@@ -6348,7 +6391,7 @@ public:
       return result;
    }
 
-   bool Destroy(int code)
+   bool Destroy(int64 code)
    {
       //if(created)
       if(this)
@@ -6923,12 +6966,11 @@ public:
             char caption[MAX_F_STRING];
             va_list args;
             va_start(args, format);
-            vsprintf(caption, format, args);
+            vsnprintf(caption, sizeof(caption), format, args);
+            caption[sizeof(caption)-1] = 0;
             va_end(args);
 
-            this.caption = new char[strlen(caption)+1];
-            if(this.caption)
-               strcpy(this.caption, caption);
+            this.caption = CopyString(caption);
          }
          if(created)
             UpdateCaption();
@@ -7450,7 +7492,7 @@ public:
    bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
    {
       Window document;
-      int id = selection.id;
+      int64 id = selection.id;
       OldLink cycle = activeClient.cycle;
       int c = 0;
       //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
@@ -7683,8 +7725,14 @@ public:
    }
    virtual void ShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
    virtual void PreShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
-   virtual bool IsMouseMoving(int x, int y, int w, int h);
-   virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY);
+   virtual bool IsMouseMoving(int x, int y, int w, int h)
+   {
+      return false;
+   }
+   virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY)
+   {
+      return false;
+   }
    virtual void UpdateNonClient();
    virtual void SetBox(Box box);
    virtual bool IsInside(int x, int y)
@@ -7728,7 +7776,6 @@ public:
             if(parent)
             {
                parent.children.Remove(this);
-               parent.OnChildAddedOrRemoved(this, true);
 
                parent.Update(
                {
@@ -7769,6 +7816,12 @@ public:
                parent.childrenOrder.Delete(order);
             cycle = null;
             order = null;
+            // *** TODO: Added this here to solve crash on setting parent to null before destroying/destructing ***
+            //           Should something else be done?
+            if(parent && parent.activeChild == this)
+               parent.activeChild = null;
+            if(parent && parent.activeClient == this)
+               parent.activeClient = null;
 
             //if(created)
             {
@@ -7898,7 +7951,11 @@ public:
                   */
                }
                scrolledPos.x = MININT; // Prevent parent update
-               property::anchor = anchor;
+               {
+                  bool anchored = this.anchored;
+                  property::anchor = anchor;
+                  this.anchored = anchored;
+               }
                /*
                {
                   int x, y, w, h;
@@ -7912,6 +7969,8 @@ public:
 
             }
             // else parent = value;
+            if(oldParent)
+               oldParent.OnChildAddedOrRemoved(this, true);
          }
       }
       get { return parent; }
@@ -8031,7 +8090,7 @@ public:
       set
       {
          background.a = (byte)Min(Max((int)(value * 255), 0), 255);
-         drawBehind = background.a ? false : true;
+         drawBehind = (background.a == 255) ? false : true;
       }
       get { return background.a / 255.0f; }
    };
@@ -9041,12 +9100,7 @@ public:
    property Point scroll
    {
       property_category $"Behavior"
-      set
-      {
-         // scroll = value;
-         // TESTING THIS IMPLEMENTATION:
-         SetScrollPosition(value.x, value.y);
-      }
+      set { SetScrollPosition(value.x, value.y); }
       get { value = scroll; }
    };
 
@@ -9057,6 +9111,14 @@ public:
       get { return (bool)modifyVirtArea; }
    };
 
+   property bool dontAutoScrollArea
+   {
+      property_category $"Behavior"
+      // Activating a child control out of view will automatically scroll to make it in view
+      set { noAutoScrollArea = value; }
+      get { return (bool)noAutoScrollArea; }
+   };
+
    property char * fileName
    {
       property_category $"Document"
@@ -9085,7 +9147,7 @@ public:
       get { return fileName; }
    };
 
-   property int id
+   property int64 id
    {
       property_category $"Data"
       set { id = value; }
@@ -9249,8 +9311,28 @@ public:
    {
       get { return (bool)nativeDecorations; }
       set { nativeDecorations = value; }
-#ifndef ECERE_VANILLA
-      isset { return (nativeDecorations && (rootWindow == this || (formDesigner && activeDesigner && ((FormDesigner)activeDesigner.classDesigner).form && parent == ((FormDesigner)activeDesigner.classDesigner).form.parent))) != style.fixed; }
+#if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
+      isset
+      {
+         //return (nativeDecorations && (rootWindow == this || (formDesigner && activeDesigner && ((FormDesigner)activeDesigner.classDesigner).form && parent == ((FormDesigner)activeDesigner.classDesigner).form.parent))) != style.fixed;
+         bool result = false;
+         if(nativeDecorations)
+         {
+            if(rootWindow == this)
+               result = true;
+            else
+            {
+               if(formDesigner && activeDesigner)
+               {
+                  FormDesigner cd = (FormDesigner)activeDesigner.classDesigner;
+                  Window form = cd ? cd.form : null;
+                  if(form && parent == form.parent)
+                     result = true;
+               }
+            }
+         }
+         return result != style.fixed;
+      }
 #endif
    };
    property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
@@ -9299,7 +9381,7 @@ private:
    int numPositions;
    Menu menu;
    ScrollFlags scrollFlags;// Window Scrollbar Flags
-   int id;                 // Control ID
+   int64 id;                 // Control ID
    int documentID;
    ColorAlpha background;  // Background color used to draw the window area
    Color foreground;
@@ -9579,127 +9661,141 @@ class WindowControllerInterface : ControllableWindow
 {
    bool OnKeyDown(Key key, unichar ch)
    {
-      bool result = ((int(*)())(void *)controller.OnKeyDown)((void *)controller.controlled, (void *)controller, key, ch);
+      bool result = ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyDown)((Window)controller.controlled, controller, key, ch);
       if(result)
-         result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown](controller.window, key, ch);
+         result = ((bool (*)(Window, Key, unichar))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown])(controller.window, key, ch);
       return result;
    }
 
    bool OnKeyUp(Key key, unichar ch)
    {
-      bool result = ((int(*)())(void *)controller.OnKeyUp)((void *)controller.controlled, (void *)controller, key, ch);
+      bool result = ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyUp)((Window)controller.controlled, controller, key, ch);
       if(result)
-         result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp](controller.window, key, ch);
+         result = ((bool(*)(Window, Key, unichar))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp])(controller.window, key, ch);
       return result;
    }
 
    bool OnKeyHit(Key key, unichar ch)
    {
-      bool result = ((int(*)())(void *)controller.OnKeyHit)((void *)controller.controlled, (void *)controller, key, ch);
+      bool result = ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyHit)((Window)controller.controlled, controller, key, ch);
       if(result)
-         result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit](controller.window, key, ch);
+         result = ((bool(*)(Window, Key, unichar))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit])(controller.window, key, ch);
       return result;
    }
 
    bool OnMouseMove(int x, int y, Modifiers mods)
    {
-      bool result = ((int(*)())(void *)controller.OnMouseMove)((void *)controller.controlled, (void *)controller, x, y, mods);
+      bool result = ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMouseMove)((Window)controller.controlled, controller, x, y, mods);
       if(result)
-         result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove](controller.window, x, y, mods);
+         result = ((bool(*)(Window, int, int, Modifiers))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove])(controller.window, x, y, mods);
       return result;
    }
 
    bool OnLeftButtonDown(int x, int y, Modifiers mods)
    {
-      bool result = ((int(*)())(void *)controller.OnLeftButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
+      bool result = ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonDown)((Window)controller.controlled, controller, x, y, mods);
       if(result)
-         result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown](controller.window, x, y, mods);
+         result = ((bool(*)(Window, int, int, Modifiers))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown])(controller.window, x, y, mods);
       return result;
    }
 
    bool OnLeftButtonUp(int x, int y, Modifiers mods)
    {
-      bool result = ((int(*)())(void *)controller.OnLeftButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
+      bool result = ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonUp)((Window)controller.controlled, controller, x, y, mods);
       if(result)
-         result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp](controller.window, x, y, mods);
+         result = ((bool(*)(Window, int, int, Modifiers))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp])(controller.window, x, y, mods);
       return result;
    }
 
    bool OnLeftDoubleClick(int x, int y, Modifiers mods)
    {
-      bool result = ((int(*)())(void *)controller.OnLeftDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
+      bool result = ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftDoubleClick)((Window)controller.controlled, controller, x, y, mods);
       if(result)
-         result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick](controller.window, x, y, mods);
+         result = ((bool(*)(Window, int, int, Modifiers))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick])(controller.window, x, y, mods);
       return result;
    }
 
    bool OnRightButtonDown(int x, int y, Modifiers mods)
    {
-      bool result = ((int(*)())(void *)controller.OnRightButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
+      bool result = ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonDown)((Window)controller.controlled, controller, x, y, mods);
       if(result)
-         result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown](controller.window, x, y, mods);
+         result = ((bool(*)(Window, int, int, Modifiers))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown])(controller.window, x, y, mods);
       return result;
    }
 
    bool OnRightButtonUp(int x, int y, Modifiers mods)
    {
-      bool result = ((int(*)())(void *)controller.OnRightButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
+      bool result = ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonUp)((Window)controller.controlled, controller, x, y, mods);
       if(result)
-         result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp](controller.window, x, y, mods);
+         result = ((bool(*)(Window, int, int, Modifiers))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp])(controller.window, x, y, mods);
       return result;
    }
 
    bool OnRightDoubleClick(int x, int y, Modifiers mods)
    {
-      bool result = ((int(*)())(void *)controller.OnRightDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
+      bool result = ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightDoubleClick)((Window)controller.controlled, controller, x, y, mods);
       if(result)
-         result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick](controller.window, x, y, mods);
+         result = ((bool(*)(Window, int, int, Modifiers))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick])(controller.window, x, y, mods);
       return result;
    }
 
    bool OnMiddleButtonDown(int x, int y, Modifiers mods)
    {
-      bool result = ((int(*)())(void *)controller.OnMiddleButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
+      bool result = ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonDown)((Window)controller.controlled, controller, x, y, mods);
       if(result)
-         result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown](controller.window, x, y, mods);
+         result = ((bool(*)(Window, int, int, Modifiers))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown])(controller.window, x, y, mods);
       return result;
    }
 
    bool OnMiddleButtonUp(int x, int y, Modifiers mods)
    {
-      bool result = ((int(*)())(void *)controller.OnMiddleButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
+      bool result = ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonUp)((Window)controller.controlled, controller, x, y, mods);
       if(result)
-         result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp](controller.window, x, y, mods);
+         result = ((bool(*)(Window, int, int, Modifiers))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp])(controller.window, x, y, mods);
       return result;
    }
 
    bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
    {
-      bool result = ((int(*)())(void *)controller.OnMiddleDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
+      bool result = ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleDoubleClick)((Window)controller.controlled, controller, x, y, mods);
       if(result)
-         result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick](controller.window, x, y, mods);
+         result = ((bool(*)(Window, int, int, Modifiers))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick])(controller.window, x, y, mods);
       return result;
    }
 
    void OnResize(int width, int height)
    {
-      ((int(*)())(void *)controller.OnResize)((void *)controller.controlled, (void *)controller, width, height);
-      controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize](controller.window, width, height);
+      ((void(*)(Window, WindowController, int, int))(void *)controller.OnResize)((Window)controller.controlled, controller, width, height);
+      ((void(*)(Window, int, int))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize])(controller.window, width, height);
    }
 
    void OnRedraw(Surface surface)
    {
-      ((int(*)())(void *)controller.OnRedraw)((void *)controller.controlled, (void *)controller, surface);
-      controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw](controller.window, surface);
+      ((void(*)(Window, WindowController, Surface))(void *)controller.OnRedraw)((Window)controller.controlled, controller, surface);
+      ((void(*)(Window, Surface))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw])(controller.window, surface);
    }
 
    bool OnCreate()
    {
-      bool result = ((int(*)())(void *)controller.OnCreate)((void *)controller.controlled, (void *)controller);
+      bool result = ((bool(*)(Window, WindowController))(void *)controller.OnCreate)((Window)controller.controlled, controller);
+      if(result)
+         result = ((bool(*)(Window))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate])(controller.window);
+      return result;
+   }
+
+   bool OnLoadGraphics()
+   {
+      bool result = ((bool(*)(Window, WindowController))(void *)controller.OnLoadGraphics)((Window)controller.controlled, controller);
       if(result)
-         result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
+         result = ((bool(*)(Window))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLoadGraphics])(controller.window);
       return result;
    }
+
+   void OnUnloadGraphics()
+   {
+      ((void(*)(Window, WindowController))(void *)controller.OnUnloadGraphics)((Window)controller.controlled, controller);
+      ((void(*)(Window))(void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnUnloadGraphics])(controller.window);
+   }
 }
 
 public class WindowController<class V>
@@ -9758,6 +9854,8 @@ public:
    virtual void V::OnResize(WindowController controller, int width, int height);
    virtual void V::OnRedraw(WindowController controller, Surface surface);
    virtual bool V::OnCreate(WindowController controller);
+   virtual bool V::OnLoadGraphics(WindowController controller);
+   virtual void V::OnUnloadGraphics(WindowController controller);
 
 private:
    int (** windowVTbl)();