ecere/gui/Window: Only flashing top level windows
[sdk] / ecere / src / gui / Window.ec
index ac4c6c6..69289e2 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
 {
@@ -135,7 +140,7 @@ private struct FastList
       {
          int c;
          int newSize;
-               
+
          if(size)
          {
             newSize = (size + (size >> 1));
@@ -250,10 +255,10 @@ public /*private */struct Extent : OldList //FastList
 
       temp.Copy(this);
       Empty();
-      
+
       for(extentBox = (BoxItem)temp.first; extentBox; extentBox = (BoxItem)extentBox.next)
       {
-         if(extentBox.box.left < box.right && extentBox.box.right > box.left && 
+         if(extentBox.box.left < box.right && extentBox.box.right > box.left &&
             extentBox.box.top < box.bottom && extentBox.box.bottom > box.top)
          {
             // Top box
@@ -261,7 +266,7 @@ public /*private */struct Extent : OldList //FastList
             {
                Box newBox
                {
-                  extentBox.box.left, extentBox.box.top, 
+                  extentBox.box.left, extentBox.box.top,
                   extentBox.box.right, Min(extentBox.box.bottom, box.top -1)
                };
                AddBox(newBox);
@@ -319,14 +324,14 @@ public /*private */struct Extent : OldList //FastList
       // First pass: check if this box is not already covered by one of the extent's box
       for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
       {
-         if(extentBox.box.left <= box.left && extentBox.box.right >= box.right && 
+         if(extentBox.box.left <= box.left && extentBox.box.right >= box.right &&
             extentBox.box.top <= box.top && extentBox.box.bottom >= box.bottom)
          {
             // No change
             return;
          }
       }
-        
+
       // Second pass: only keep boxes not completely covered in the new box
       for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
       {
@@ -372,7 +377,7 @@ public /*private */struct Extent : OldList //FastList
                }
             }
          }
-         
+
          // Else, add it
          if(!extentBox)
             AddBox(box);
@@ -406,7 +411,7 @@ public /*private */struct Extent : OldList //FastList
 
    void Exclusion(Extent b, Extent temp)
    {
-      BoxItem extentBox;   
+      BoxItem extentBox;
       for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
          ExcludeBox(extentBox.box, temp);
    }
@@ -431,7 +436,7 @@ private define CASCADE_SPACE = 16;
 
 private class ScrollFlags
 {
-   bool snapX:1, snapY:1, dontHide:1;   
+   bool snapX:1, snapY:1, dontHide:1;
 };
 
 public class BorderBits { public: bool contour:1, fixed:1, sizable:1, deep:1, bevel:1, thin:1; };
@@ -485,12 +490,12 @@ private class HotKeySlot : struct
 public class Window
 {
 private:
-   class_data char * icon;
+   class_data const char * icon;
    class_no_expansion
    class_default_property caption;
    // class_initialize GuiApplication::Initialize;
    class_designer FormDesigner;
-   class_property char * icon
+   class_property const char * icon
    {
       set { class_data(icon) = value; }
       get { return class_data(icon); }
@@ -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)
       {
@@ -516,7 +527,7 @@ private:
             }
          }
       }
-      
+
       //tempExtents[0] = { /*first = -1, last = -1, free = -1*/ };
       //tempExtents[1] = { /*first = -1, last = -1, free = -1*/ };
       //tempExtents[2] = { /*first = -1, last = -1, free = -1*/ };
@@ -533,7 +544,7 @@ private:
       maxSize = Size { MAXINT, MAXINT };
       background = white;
       foreground = black;
-      
+
       //style.isActiveClient = true;
       mergeMenus = true;
       autoCreate = true;
@@ -557,6 +568,16 @@ private:
       OldLink slave;
       ResPtr ptr;
 
+      if(fileMonitor)
+      {
+         int i, lockCount = guiApp.lockMutex.lockCount;
+         for(i = 0; i < lockCount; i++)
+            guiApp.lockMutex.Release();
+         delete fileMonitor;
+         for(i = 0; i < lockCount; i++)
+            guiApp.lockMutex.Wait();
+      }
+
       if(parent)
       {
          stopwatching(parent, font);
@@ -567,7 +588,7 @@ private:
       }
 
       if(!destroyed)
-      { 
+      {
          // Prevent destructor from being called again...
          incref this;
          incref this;
@@ -595,7 +616,7 @@ private:
       delete order;
       /////////////////////////////////
 
-      while(ptr = resources.first)
+      while((ptr = resources.first))
       {
          delete ptr.resource;
          resources.Delete(ptr);
@@ -614,7 +635,7 @@ private:
          *&child.parent = null;
       }
 
-      while(slave = slaves.first)
+      while((slave = slaves.first))
       {
          // Don't want property here
          *&((Window)slave.data).master = null;
@@ -680,20 +701,20 @@ private:
    }
 
 //#if !defined(ECERE_VANILLA)
-   char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
+   const char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
    {
       if(this == activeDesigner)
          return "(Desktop)";
-      else 
+      else
       {
-         char * name = property::name;
+         const char * name = property::name;
          return name ? name : "";
       }
    }
 //#endif
 
 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
-   bool OnGetDataFromString(char * string)
+   bool OnGetDataFromString(const char * string)
    {
       FormDesigner designer = (FormDesigner)activeDesigner.classDesigner;
       if(string[0])
@@ -732,7 +753,7 @@ private:
       {
          int x = absPosition.x + clientStart.x;
          int y = absPosition.y + clientStart.y;
-         if(rootWindow.nativeDecorations)
+         if(rootWindow.nativeDecorations && rootWindow.windowHandle && !is3D)
          {
             x -= rootWindow.clientStart.x;
             y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
@@ -780,7 +801,7 @@ private:
       {
          int x = absPosition.x;
          int y = absPosition.y;
-         if(rootWindow.nativeDecorations)
+         if(rootWindow.nativeDecorations && rootWindow.windowHandle && !is3D)
          {
             x -= rootWindow.clientStart.x;
             y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
@@ -931,18 +952,19 @@ private:
    void ComputeAnchors(Anchor anchor, SizeAnchor sizeAnchor, int *ox, int *oy, int *ow, int *oh)
    {
       Window parent = this.parent ? this.parent : guiApp.desktop;
+      int xOffset = 0, yOffset = 0;
       int vpw = parent ? parent.clientSize.w : 0;
       int vph = parent ? parent.clientSize.h : 0;
       int pw = parent ? parent.clientSize.w : 0;
       int ph = parent ? parent.clientSize.h : 0;
       int w = sizeAnchor.size.w, h = sizeAnchor.size.h;
       int x = anchor.left.distance, y = anchor.top.distance;
-      float ex, ey;
+      float ex = 0, ey = 0;
       MinMaxValue ew = 0, eh = 0;
       int numCascade;
       float cascadeW, cascadeH;
       int numTiling;
-      int tilingW, tilingH, tilingSplit, tilingLastH;
+      int tilingW, tilingH, tilingSplit, tilingLastH = 0;
       int addX = 0, addY = 0;
 
       if(parent && rootWindow == this && guiApp && guiApp.interfaceDriver)
@@ -969,7 +991,7 @@ private:
             ph = vph = box.bottom - box.top + 1;
          }
       }
-      
+
       if(!parent)
       {
          *ow = w;
@@ -1016,7 +1038,7 @@ private:
 
          if(anchor.top.type)
          {
-            SNAPUP(y, textCellH);   
+            SNAPUP(y, textCellH);
          }
          else if(anchor.bottom.type)
          {
@@ -1025,13 +1047,47 @@ private:
       }
 
       // This is required to get proper initial decoration size using native decorations on Windows
-      if(nativeDecorations && guiApp && guiApp.interfaceDriver && !visible)
+#if defined(__WIN32__)
+      if(nativeDecorations && windowHandle && guiApp && guiApp.interfaceDriver && !visible)
          guiApp.interfaceDriver.PositionRootWindow(this, x, y, Max(1, size.w), Max(1, size.h), true, true);
+#endif
       GetDecorationsSize(&ew, &eh);
 
       if(anchor.left.type >= cascade && (state == normal /*|| state == Hidden*/))
       {
-         if(parent.sbv && !parent.sbv.style.hidden) 
+         // Leave room for non client windows (eventually dockable panels)
+         Window win;
+         int loX = 0, loY = 0, hiX = pw, hiY = ph;
+         for(win = parent.children.first; win; win = win.next)
+         {
+            if(!win.nonClient && !win.isActiveClient && win.visible)
+            {
+               Size size = win.size;
+               Point pos = win.position;
+               int left = pos.x, top = pos.y;
+               int right = pos.x + size.w, bottom = pos.y + size.h;
+               if(win.size.w > win.size.h)
+               {
+                  if(bottom < ph / 4)
+                     loY = Max(loY, bottom);
+                  else if(top > ph - ph / 4)
+                     hiY = Min(hiY, top);
+               }
+               else
+               {
+                  if(right < pw / 4)
+                     loX = Max(loX, right);
+                  else if(left > pw - pw / 4)
+                     hiX = Min(hiX, left);
+               }
+            }
+         }
+         xOffset = loX;
+         yOffset = loY;
+         pw = hiX - loX;
+         ph = hiY - loY;
+
+         if(parent.sbv && !parent.sbv.style.hidden)
             pw += guiApp.currentSkin.VerticalSBW();
          if(parent.sbh && !parent.sbh.style.hidden)
             ph += guiApp.currentSkin.HorizontalSBH();
@@ -1070,17 +1126,17 @@ private:
 
             if(positionID >= tilingSplit)
             {
-               x = pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
-               y = ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
-               x2 = pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
-               y2 = ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
+               x = xOffset + pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
+               y = yOffset + ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
+               x2 = xOffset + pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
+               y2 = yOffset + ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
             }
             else
             {
-               x = pw * (positionID / tilingH) / tilingW;
-               y = ph * (positionID % tilingH) / tilingH;
-               x2 = pw * (positionID / tilingH + 1) / tilingW;
-               y2 = ph * ((positionID % tilingH) + 1) / tilingH;
+               x = xOffset + pw * (positionID / tilingH) / tilingW;
+               y = yOffset + ph * (positionID % tilingH) / tilingH;
+               x2 = xOffset + pw * (positionID / tilingH + 1) / tilingW;
+               y2 = yOffset + ph * ((positionID % tilingH) + 1) / tilingH;
             }
             if(guiApp.textMode)
             {
@@ -1097,7 +1153,7 @@ private:
       {
          if(sizeAnchor.isClientW) w += ew;
          if(sizeAnchor.isClientH) h += eh;
-         
+
          if(anchor.left.type == offset)
             x = anchor.left.distance;
          else if(anchor.left.type == relative)
@@ -1122,8 +1178,8 @@ private:
          {
             switch(anchor.right.type)
             {
-               case relative: 
-                  ex = pw * (1.0f-anchor.right.percent); 
+               case relative:
+                  ex = pw * (1.0f-anchor.right.percent);
                   w = Max((int)(ex + 0.5) - x, 0);
                   break;
                case offset:
@@ -1149,7 +1205,7 @@ private:
       }
 
       w -= ew;
-      h -= eh; 
+      h -= eh;
 
       if(state == normal /*|| state == Hidden*/)
       {
@@ -1163,12 +1219,12 @@ private:
          w = Min(w, maxSize.w);
          h = Min(h, maxSize.h);
 
-         if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv) 
+         if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
          {
             if(w) w -= guiApp.currentSkin.VerticalSBW();
             addSbV = true;
          }
-         if((sizeAnchor.isClientH || !h ||  (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh) 
+         if((sizeAnchor.isClientH || !h ||  (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
          {
             if(h) h -= guiApp.currentSkin.HorizontalSBH();
             addSbH = true;
@@ -1180,7 +1236,7 @@ private:
             h = clientSize.h;
          }
 
-         if((addSbV)) // || reqScrollArea.h > h) && sbv) 
+         if((addSbV)) // || reqScrollArea.h > h) && sbv)
             w += guiApp.currentSkin.VerticalSBW();
          if((addSbH)) // || reqScrollArea.w > w) && sbh)
             h += guiApp.currentSkin.HorizontalSBH();
@@ -1195,7 +1251,7 @@ private:
       }
 
       w += ew;
-      h += eh; 
+      h += eh;
 
       if(guiApp.textMode)
       {
@@ -1208,9 +1264,9 @@ private:
          if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
 
          numCascade = Min(
-            (pw - w) / CASCADE_SPACE, 
+            (pw - w) / CASCADE_SPACE,
             (ph - h) / CASCADE_SPACE);
-         
+
          if(guiApp.textMode)
          {
                int cascW, cascH;
@@ -1229,8 +1285,8 @@ private:
             cascadeH = (float)(ph - h) / (numCascade-1);
          }
 
-         x = (int)((positionID % numCascade) * cascadeW);
-         y = (int)((positionID % numCascade) * cascadeH);
+         x = (int)((positionID % numCascade) * cascadeW) + xOffset;
+         y = (int)((positionID % numCascade) * cascadeH) + yOffset;
       }
       else if(anchor.left.type < vTiled)
       {
@@ -1256,7 +1312,7 @@ private:
                if(anchor.vert.type == middleRelative)
                   y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
                else
-                  y = vph / 2 + anchor.vert.distance - h / 2;      
+                  y = vph / 2 + anchor.vert.distance - h / 2;
             }
             else
                y = (int)(ey - h);
@@ -1302,13 +1358,13 @@ private:
          int y = caretPos.y - scroll.y;
 
          if((erase || this.caretSize) &&
-            x >= clientArea.left && x <= clientArea.right && 
+            x >= clientArea.left && x <= clientArea.right &&
             y >= clientArea.top  && y <= clientArea.bottom)
          {
             if(!erase)
             {
                guiApp.interfaceDriver.SetCaret(
-                  x + absPosition.x + clientStart.x, 
+                  x + absPosition.x + clientStart.x,
                   y + absPosition.y + clientStart.y, this.caretSize);
                guiApp.caretEnabled = true;
             }
@@ -1407,7 +1463,7 @@ private:
                //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
                {
                   int stepX = sbStep.x, stepY = sbStep.y;
-                  // Needed to make snapped down position match the skin's check of client area 
+                  // Needed to make snapped down position match the skin's check of client area
                   // against realvirtual
                   if(guiApp.textMode)
                   {
@@ -1437,7 +1493,7 @@ private:
       // Automatic MDI Client Scrolling Area Adjustment
       if(parent && !parent.noAutoScrollArea)
       {
-         if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) && 
+         if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
             !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
          {
             Window parent = this.parent;
@@ -1453,12 +1509,12 @@ private:
             else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
                h = Max(h, Max(position.y, 0) + size.h);
 
-            if((w > parent.clientSize.w && w > parent.reqScrollArea.w) || 
+            if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
                (h > parent.clientSize.h && h > parent.reqScrollArea.h))
             {
                /*bool resize = false;
                int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
-               // Needed to make snapped down position match the skin's check of client area 
+               // Needed to make snapped down position match the skin's check of client area
                // against realvirtual
                if(guiApp.textMode)
                {
@@ -1477,12 +1533,12 @@ private:
                   parent.reqScrollArea.h = h;*/
 
                  // parent.UpdateScrollBars(true, true);
-                  parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h, 
+                  parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
                      false, true, true, true, false, false);
                   return;
                //}
             }
-            else 
+            else
                GetRidOfVirtualArea();
          }
       }
@@ -1556,6 +1612,8 @@ private:
       {
          if(!parent.noAutoScrollArea)
          {
+            // TODO: Review the logic of all this? Each child is going to reposition the parent?
+            /*
             Window child;
             bool found = false;
             for(child = children.first; child; child = child.next)
@@ -1570,11 +1628,12 @@ private:
                   }
                }
             }
-            //if(!found)
+            if(!found)
+            */
             {
                Window parent = this.parent;
                parent.Position(
-                  parent.position.x, parent.position.y, parent.size.w, parent.size.h, 
+                  parent.position.x, parent.position.y, parent.size.w, parent.size.h,
                   false, true, true, true, false, false);
                /*
                parent.SetScrollArea(0,0,true);
@@ -1596,7 +1655,7 @@ private:
       int oldCW = clientSize.w, oldCH = clientSize.h;
       bool clientResized, windowResized, windowMoved;
       Window child;
-      bool realResized = size.w != w || size.h != h;
+      //bool realResized = size.w != w || size.h != h;
 
       // TOCHECK: This wasn't in ecere.dll
       //if(!parent) return true;
@@ -1606,16 +1665,16 @@ private:
 
       // windowResized = realResized || force;
       windowResized = size.w != w || size.h != h || force;
-     
+
       if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
       {
          if(style.nonClient)
          {
             Box box
-            { 
-               scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top, 
+            {
+               scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
                scrolledPos.x - parent.clientStart.x + this.box.right,
-               scrolledPos.y - parent.clientStart.y + this.box.bottom 
+               scrolledPos.y - parent.clientStart.y + this.box.bottom
             };
             parent.Update(box);
          }
@@ -1629,7 +1688,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)
@@ -1660,7 +1719,7 @@ private:
                   int x,y,w,h;
                   for(child = children.first; child; child = child.next)
                   {
-                     if(child.created && 
+                     if(child.created &&
                      ((child.stateAnchor.left.type != offset ||
                        child.stateAnchor.top.type != offset ||
                        child.stateAnchor.right.type != none ||
@@ -1699,14 +1758,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 +1782,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;
@@ -1737,22 +1799,22 @@ private:
                else if(clientResized)
                   Update(clientArea);
                // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
-               
+
                /*
                if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
                   UpdateDisplay();
                */
-               
+
                if(windowMoved || windowResized)
                {
                   display.Unlock();
                }
             }
-            if(guiApp.driver && changeRootWindow)
+            if(guiApp.driver && changeRootWindow && windowHandle)
             {
                if(windowResized || windowMoved)
                   if(!display || display.flags.memBackBuffer)
-                     guiApp.interfaceDriver.PositionRootWindow(this, 
+                     guiApp.interfaceDriver.PositionRootWindow(this,
                         x, y, w, h, windowMoved, windowResized);
                guiApp.interfaceDriver.UpdateRootWindow(this);
             }
@@ -1791,8 +1853,8 @@ private:
       {
          MinMaxValue cw = 0, ch = 0;
          bool sbvVisible, sbhVisible;
-         int rangeH, rangeV;
-         int positionH, positionV;
+         int rangeH = 0, rangeV = 0;
+         int positionH = 0, positionV;
 
          // First get client area with no respect to scroll bars
 
@@ -1834,12 +1896,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 +1918,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 +1931,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
@@ -1903,7 +1986,7 @@ private:
             if(flag && (resizeH || resizeV) && fullThing)
             {
                Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
-               
+
                if(!positioned)
                {
                   positioned = true;
@@ -1911,7 +1994,7 @@ private:
                   positioned = false;
                }
             }
-      
+
             if(resizeH && sbh)
                sbh.visible = sbhVisible;
             if(resizeV && sbv)
@@ -2033,7 +2116,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 +2128,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)
@@ -2154,23 +2239,21 @@ private:
                Update(null);
                break;
             }
-         }         
+         }
       }
    }
 
    Window GetParentMenuBar()
    {
       Window menuBarParent;
-      for(menuBarParent = this; menuBarParent; menuBarParent = menuBarParent.parent)
+      if(formDesigner) return null;
+      for(menuBarParent = this ? parent : null; menuBarParent; menuBarParent = menuBarParent.parent)
       {
-         if(menuBarParent.menuBar) break;
-         if(menuBarParent.parent && /*menuBarParent != */!menuBarParent.parent.activeClient)
-         {
-            menuBarParent = null;
-            break;
-         }
+         if(menuBarParent.menuBar) return menuBarParent.menuBar;
+         if(menuBarParent && !menuBarParent.isActiveClient)
+            return null;
       }
-      return menuBarParent ? menuBarParent.menuBar : null;
+      return null;
    }
 
    void CreateSystemChildren(void)
@@ -2181,7 +2264,11 @@ private:
       Point scroll = this.scroll;
 
       if(state == maximized)
+      {
          parent = GetParentMenuBar();
+         if(!parent)
+            parent = this;
+      }
 
       if(parent)
       {
@@ -2213,7 +2300,7 @@ private:
       {
          if(!sysButtons[2])
          {
-            sysButtons[2] = 
+            sysButtons[2] =
                Button
                {
                   parent, master = this,
@@ -2231,25 +2318,25 @@ private:
                sysButtons[2].hotKey = ctrlF4;
             sysButtons[2].Create();
          }
-         
+
          sysButtons[2].symbol = 'X';
          sysButtons[2].disabled = !style.hasClose;
       }
 
       if(hasMaxMin && parent)
       {
-         SkinBitmap skin;
+         //SkinBitmap skin;
          unichar symbol;
          bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
-         if(state == maximized) 
+         if(state == maximized)
          {
-            skin = restore;
+            //skin = restore;
             method = RestoreButtonClicked;
             symbol = '\x12';
          }
          else
          {
-            skin = maximize;
+            //skin = maximize;
             method = MaximizeButtonClicked;
             symbol = '\x18';
          }
@@ -2271,18 +2358,18 @@ private:
 
       if(hasMaxMin && parent)
       {
-         SkinBitmap skin;
+         //SkinBitmap skin;
          unichar symbol;
          bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
-         if (state == minimized) 
+         if (state == minimized)
          {
-            skin = restore;
+            //skin = restore;
             method = RestoreButtonClicked;
             symbol = '\x12';
          }
          else
          {
-            skin = minimize;
+            //skin = minimize;
             method = MinimizeButtonClicked;
             symbol = '\x19';
          }
@@ -2348,9 +2435,9 @@ private:
       }
       if(scrollBarChanged)
       {
-         SetScrollLineStep(sbStep.x, sbStep.y);   
+         SetScrollLineStep(sbStep.x, sbStep.y);
          UpdateScrollBars(true, true);
-      }   
+      }
       UpdateNonClient();
 
       if(scrollBarChanged)
@@ -2366,16 +2453,23 @@ private:
       {
          char caption[2048];
          FigureCaption(caption);
-         guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
+         if(guiApp.interfaceDriver)
+            guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
       }
       UpdateDecorations();
       if(parent)
       {
-         if(parent.rootWindow == parent && parent.activeClient == this) // Added this last check
+         if(parent.activeClient == this) // Added this last check
          {
-            char caption[2048];
-            parent.FigureCaption(caption);
-            guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
+            if(parent.rootWindow == parent)
+            {
+               char caption[2048];
+               parent.FigureCaption(caption);
+               if(guiApp.interfaceDriver)
+                  guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
+            }
+            else
+               parent.UpdateCaption();
          }
          parent.UpdateDecorations();
       }
@@ -2400,7 +2494,7 @@ private:
       if(menu)
       {
          MenuItem item;
-         bool disabled;
+         //bool disabled;
 
          if(menu)
             menu.Clean(this);
@@ -2415,17 +2509,16 @@ private:
                int id;
                for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
                {
-                  MenuItem item;
                   Window document = cycle.data;
                   if(!document.style.nonClient && document.style.isActiveClient && document.visible)
                   {
                      char name[2048], caption[2048];
                      document.FigureCaption(caption);
                      sprintf(name, "%d %s", id+1, caption);
-                     windowMenu.AddDynamic(MenuItem 
-                        { 
-                           copyText = true, text = name, hotKey = Key { k1 + id }, id = id++, 
-                           NotifySelect = MenuWindowSelectWindow 
+                     windowMenu.AddDynamic(MenuItem
+                        {
+                           copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
+                           NotifySelect = MenuWindowSelectWindow
                         }, this, false);
                   }
                   cycle = cycle.next;
@@ -2433,13 +2526,13 @@ private:
                }
             }
          }
-         
+
          if((!previous && activeClient) || !activeClient)
          {
-            if(!activeClient)
+            /*if(!activeClient)
                disabled = true;
             else
-               disabled = false;
+               disabled = false;*/
             item = menu.FindItem(MenuWindowCloseAll, 0);
             if(item) item.disabled = false;
             item = menu.FindItem(MenuWindowNext, 0);
@@ -2456,7 +2549,7 @@ private:
             if(item) item.disabled = false;
             item = menu.FindItem(MenuWindowWindows, 0);
             if(item) item.disabled = false;
-         }      
+         }
 
          item = menu.FindItem(MenuFileClose, 0);
          if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
@@ -2486,7 +2579,7 @@ private:
 
    void _ShowDecorations(Box box, bool post)
    {
-      if(rootWindow == this && nativeDecorations) return;
+      if(rootWindow == this && nativeDecorations && !is3D) return;
       if(visible && this != guiApp.desktop)
       {
          Surface surface = RedrawFull(box);
@@ -2494,7 +2587,7 @@ private:
          {
             char caption[2048];
             FigureCaption(caption);
-            
+
             if(post)
                ShowDecorations(captionFont.font,
                   surface,
@@ -2507,7 +2600,7 @@ private:
                   caption,
                   active, //parent.activeClient == this
                   guiApp.windowMoving == this);
-               
+
             delete surface;
          }
       }
@@ -2520,9 +2613,9 @@ private:
       if(!manageDisplay) { OnRedraw(null);return; }
       _ShowDecorations(refresh, false);
 
-      surface = Redraw(refresh);               
+      surface = Redraw(refresh);
       // Opaque background: just fill before EW_REDRAW (clear?)
-      if(surface) 
+      if(surface)
       {
          surface.SetBackground(background);
          surface.SetForeground(foreground);
@@ -2584,8 +2677,8 @@ private:
 
    void DrawOverChildren(Box refresh)
    {
-      Surface surface = Redraw(refresh);               
-      if(surface) 
+      Surface surface = Redraw(refresh);
+      if(surface)
       {
          // Default Settings
          surface.DrawingChar(' ');
@@ -2609,12 +2702,12 @@ private:
       Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
 
       clipExtent.Copy(this.clipExtent);
-      
+
       for(child = children.last; child; child = child.prev)
       {
          if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
          {
-            bool opaque = child.IsOpaque(); // TODO: acess background directly 
+            bool opaque = child.IsOpaque(); // TODO: acess background directly
             int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
 
             child.clipExtent.Copy(clipExtent);
@@ -2629,7 +2722,7 @@ private:
                Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
                clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
             }
-            
+
          }
       }
       // ??? Only do this for overlapped window or if parent has with clip children flag
@@ -2642,10 +2735,9 @@ private:
 
    void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
    {
-      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);
@@ -2654,17 +2746,17 @@ private:
 
       for(child = children.last; child; child = child.prev)
       {
-         ColorAlpha background = *(ColorAlpha *)&child.background;
          bool opaque = child.IsOpaque();
          if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
          {
             if(!opaque)
             {
                // Adjust renderArea to the root window level
-               Extent * renderArea = &rootWindow.tempExtents[1];
+               Extent * renderArea = &rootWindow.tempExtents[3];
 
-               int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
-               if(child.rootWindow.nativeDecorations)
+               int offsetX = child.absPosition.x - rootWindow.absPosition.x;
+               int offsetY = child.absPosition.y - rootWindow.absPosition.y;
+               if(child.rootWindow.nativeDecorations && rootWindow.windowHandle)
                {
                   offsetX -= child.rootWindow.clientStart.x;
                   offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
@@ -2672,7 +2764,7 @@ private:
 
                /*
                Extent childRenderArea;
-               
+
                if(backBufferUpdate != null)
                {
                   childRenderArea.Copy(backBufferUpdate);
@@ -2692,7 +2784,12 @@ private:
                */
 
                renderArea->Copy(child.dirtyArea /*childRenderArea*/);
+
+               // This intersection with child clip extent was missing and causing #708 (Installer components list scrolling bug):
+               renderArea->Intersection(child.clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
+
                renderArea->Offset(offsetX, offsetY);
+
                dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
                // overDirtyExtent.Union(renderArea);
                renderArea->Empty();
@@ -2718,7 +2815,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);
@@ -2759,16 +2856,16 @@ private:
       {
          renderArea.Copy(backBufferUpdate);
          renderArea.Offset(-offsetX, -offsetY);
-         
+
          overRenderArea.Copy(backBufferUpdate);
          overRenderArea.Offset(-offsetX, -offsetY);
-         
-         
+
+
       }
       else
       {
          renderArea.Copy(dirtyArea);
-         
+
          overRenderArea.Copy(dirtyArea);
       }
 
@@ -2805,8 +2902,8 @@ private:
                FASTLIST_LOOP(renderArea, extentBox)
                {
       #ifdef _DEBUG
-                  printf("(%d, %d) - (%d, %d)\n", 
-                     extentBox.box.left, extentBox.box.top, 
+                  printf("(%d, %d) - (%d, %d)\n",
+                     extentBox.box.left, extentBox.box.top,
                      extentBox.box.right, extentBox.box.bottom);
       #endif
                }
@@ -2816,7 +2913,7 @@ private:
          }
       }
       */
-      
+
       // WHY WAS THIS COMMENTED ??
 
       // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
@@ -2827,7 +2924,7 @@ private:
 
       // Intersect with the clip extent
       overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
-      
+
 
       if(opaque)
       {
@@ -2880,17 +2977,17 @@ private:
          dirtyExtent.Union(renderArea);
          renderArea.Free();
       }*/
-      
-      
+
+
       {
          Extent renderArea { };
-         
+
          renderArea.Copy(overRenderArea);
          renderArea.Offset(offsetX, offsetY);
          overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
          renderArea.Empty();
       }
-      
+
 
       if(backBufferUpdate != null)
       {
@@ -2915,7 +3012,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);
@@ -2934,22 +3031,22 @@ private:
          foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
          */
 #endif
-            
+
 #ifdef _DEBUG
          /*if(renderArea.count)
             printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
 #endif
-            
+
          for(extentBox = (BoxItem)renderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
          {
             Box box = extentBox.box;
 
 #ifdef _DEBUG
-               /*printf("(%d, %d) - (%d, %d)\n", 
-                  extentBox.box.left, extentBox.box.top, 
+               /*printf("(%d, %d) - (%d, %d)\n",
+                  extentBox.box.left, extentBox.box.top,
                   extentBox.box.right, extentBox.box.bottom);*/
 #endif
-               
+
             UpdateExtent(box);
 
             box.left += offsetX;
@@ -2999,7 +3096,7 @@ private:
    public void UpdateDisplay(void)
    {
       if(!manageDisplay) { OnRedraw(null);return; }
-      if(rootWindow && this != rootWindow) 
+      if(rootWindow && this != rootWindow)
          rootWindow.UpdateDisplay();
       else if(display)
       {
@@ -3021,7 +3118,7 @@ private:
             ComputeRenderArea(dirtyExtent, overExtent, null);
          }
          else
-            clipExtent.Free(null);                     
+            clipExtent.Free(null);
 
          dirtyExtent.Free(null);
          overExtent.Free(null);
@@ -3039,22 +3136,22 @@ private:
             Render(updateExtent);
             if(fullRender)
                updateExtent.UnionBox(this.box, tempExtents[0]);
-            
+
 #ifdef _DEBUG
             //printf("\n\nUpdate:\n------------------------------------------\n");
 #endif
-            
+
             //FASTLIST_LOOP(updateExtent, extentBox)
             for(extentBox = (BoxItem)updateExtent.first; extentBox; extentBox = (BoxItem)extentBox.next)
             {
 #ifdef _DEBUG
-               /*printf("Updating (%d, %d) - (%d, %d)\n", 
-                  extentBox.box.left, extentBox.box.top, 
+               /*printf("Updating (%d, %d) - (%d, %d)\n",
+                  extentBox.box.left, extentBox.box.top,
                   extentBox.box.right, extentBox.box.bottom);*/
 #endif
-               
+
                display.Update(extentBox.box);
-               
+
             }
             updateExtent.Free(null);
          }
@@ -3082,12 +3179,12 @@ private:
          {
             intersection.Copy(dirtyBack);
             intersection.IntersectBox(box);
-         
+
             dirtyExtent.Clear();
             overExtent.Clear();
 
             clipExtent.AddBox(box);
-         
+
             if(!rootWindow.fullRender)
             {
                ComputeClipExtents();
@@ -3165,18 +3262,22 @@ private:
             // If the window is disabled, stop looking in children (for acceptDisabled mode)
             if(!disabled)
             {
-               for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
+               bool isD = (last && last != this && last.IsDescendantOf(this)); //  Fix for WSMS (#844)
+               Window ancestor = null;
+               if(isD)
+                  for(ancestor = last; ancestor && ancestor.parent != this; ancestor = ancestor.parent);
+               for(child = (isD ? (last != ancestor ? ancestor : ancestor.previous) : children.last); child; child = child.prev)
                {
                   if(child != statusBar && child.rootWindow == rootWindow)
                   {
                      Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
-                     if(childResult) 
+                     if(childResult)
                         return childResult;
                   }
                }
                if(clickThru)
                {
-                  for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
+                  for(child = (isD ? (last != ancestor ? ancestor : ancestor.previous) : children.last); child; child = child.prev)
                   {
                      if(child != statusBar && child.rootWindow == rootWindow)
                      {
@@ -3186,6 +3287,9 @@ private:
                      }
                   }
                }
+
+               if(last && last != this && this.IsDescendantOf(last)) // Fix for installer lockup
+                  result = null;
             }
          }
       }
@@ -3206,7 +3310,7 @@ private:
          // TESTING THIS FOR DROPBOX...
          if(!rootWindow || !rootWindow.style.interim)
          {
-            for(check2 = check; check2.activeChild; check2 = check2.activeChild)
+            for(check2 = check; check2 /*.activeChild*/; check2 = check2.activeChild)
             {
                if(check2.modalSlave && check2.modalSlave.created)
                {
@@ -3264,7 +3368,7 @@ private:
       mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
 
       if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
-         guiApp.SetCurrentCursor(guiApp.systemCursors[moving]);
+         guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[moving]);
       else if(mouseWindow)
       {
          modalWindow = mouseWindow.FindModal();
@@ -3277,30 +3381,31 @@ private:
             rx = guiApp.resizeX;
             ry = guiApp.resizeY;
             if((rex && rey) || (rx && ry))
-               guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
+               guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNWSE]);
             else if((rex && ry) || (rx && rey))
-               guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
+               guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNESW]);
             else if((ry || rey) && (!rx && !rex))
-               guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
+               guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNS]);
             else if((rx || rex) && (!ry && !rey))
-               guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
+               guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeWE]);
          }
          else if(!modalWindow && !guiApp.windowCaptured &&
             mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
                &rx, &ry, &rex, &rey))
          {
             if((rex && rey) || (rx && ry))
-               guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
+               guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNWSE]);
             else if((rex && ry) || (rx && rey))
-               guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
+               guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNESW]);
             else if((ry || rey) && (!rx && !rex))
-               guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
+               guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNS]);
             else if((rx || rex) && (!ry && !rey))
-               guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
+               guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeWE]);
          }
          else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
          {
-            if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}))
+            if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}) &&
+               mouseWindow.rootWindow != mouseWindow)
                cursorWindow = mouseWindow.parent;
             else
                cursorWindow = mouseWindow;
@@ -3309,19 +3414,19 @@ private:
             cursorWindow = guiApp.windowCaptured;
          if(cursorWindow)
          {
-            for(; !cursorWindow.cursor && !cursorWindow.style.nonClient; cursorWindow = cursorWindow.parent);
-            guiApp.SetCurrentCursor(cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
+            for(; !cursorWindow.cursor && !cursorWindow.style.nonClient && cursorWindow.rootWindow != cursorWindow; cursorWindow = cursorWindow.parent);
+            guiApp.SetCurrentCursor(mouseWindow, cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
          }
          else if(modalWindow)
          {
-            guiApp.SetCurrentCursor(guiApp.systemCursors[arrow]);
+            guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[arrow]);
          }
          else if(guiApp.interimWindow)
          {
             if(guiApp.interimWindow.cursor)
-               guiApp.SetCurrentCursor(guiApp.interimWindow.cursor);
+               guiApp.SetCurrentCursor(mouseWindow, guiApp.interimWindow.cursor);
             else
-               guiApp.SetCurrentCursor(mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
+               guiApp.SetCurrentCursor(mouseWindow, mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
          }
       }
    }
@@ -3330,7 +3435,7 @@ private:
    bool AcquireInputEx(bool state)
    {
       bool result;
-      if(state) 
+      if(state)
       {
          guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
          guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
@@ -3341,7 +3446,7 @@ private:
       if(state && result)
       {
          SetMouseRangeToClient();
-         guiApp.interfaceDriver.SetMouseCursor((SystemCursor)-1);
+         guiApp.interfaceDriver.SetMouseCursor(guiApp.acquiredWindow, (SystemCursor)-1);
       }
       else
       {
@@ -3364,6 +3469,15 @@ private:
          if(rootWindow == this)
             Log(active ? "active\n" : "inactive\n");
          */
+         if(active && requireRemaximize)
+         {
+            if(state == maximized)
+            {
+               property::state = normal;
+               property::state = maximized;
+            }
+            requireRemaximize = false;
+         }
 
          // Testing this here...
          if(!parent || parent == guiApp.desktop || parent.active)
@@ -3373,7 +3487,7 @@ private:
 
          // TESTING THIS HERE
          UpdateDecorations();
-         if(result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master)
+         if((result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master))
             result = NotifyActivate(master, this, active, previous);
          else
          {
@@ -3387,17 +3501,17 @@ private:
                this.active = active;
                if(acquiredInput)
                   AcquireInputEx(active);
-               if(active)
+               if(active && isEnabled)
                {
                   if(caretSize)
                   {
                      if(guiApp.caretOwner)
                      {
-                        Box extent 
+                        Box extent
                         {
-                           guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1, 
+                           guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
                            guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
-                           guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2, 
+                           guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
                            guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
                         };
                         guiApp.caretOwner.Update(extent);
@@ -3465,7 +3579,8 @@ private:
             int x,y;
             if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
             {
-               guiApp.interfaceDriver.GetMousePosition(&x, &y);
+               if(guiApp.interfaceDriver)
+                  guiApp.interfaceDriver.GetMousePosition(&x, &y);
 
                if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
                   rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
@@ -3502,8 +3617,8 @@ private:
          {
             if(!active)
                StopMoving();
-            if(activateParent && 
-               (parent.activeChild != this || 
+            if(activateParent &&
+               (parent.activeChild != this ||
                (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
                active && _isModal &&
                parent != master && master)
@@ -3516,8 +3631,8 @@ private:
                   bool real = parent.activeChild != this;
 
                   // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
-                  if(/*activateParent && */guiApp.interimWindow && 
-                     !IsDescendantOf(guiApp.interimWindow) && 
+                  if(!style.inactive && /*activateParent && */guiApp.interimWindow &&
+                     !IsDescendantOf(guiApp.interimWindow) &&
                      !IsSlaveOf(guiApp.interimWindow))
                   {
                      Window interimWindow = guiApp.interimWindow;
@@ -3549,7 +3664,7 @@ private:
 
                   if(real)
                   {
-                     bool acquireInput = false;
+                     //bool acquireInput = false;
                      bool maximize =
                         parent.activeChild &&
                         parent.activeChild.state == maximized &&
@@ -3581,12 +3696,12 @@ private:
                         {
                            bool goOn = true;
                            result = PropagateActive(true, swap, &goOn, true);
-                           if(!result && !goOn) 
+                           if(!result && !goOn)
                            {
                               delete this;
                               return false;
                            }
-                           acquireInput = true;
+                           //acquireInput = true;
                         }
                      }
 
@@ -3649,14 +3764,14 @@ private:
                         }
                      }
                   }
-               
+
                   if(result && real && (!style.inactive || moveInactive) && parent)
                   {
                      Window last = parent.children.last;
 
                      if(!style.stayOnTop)
                         for(; last && last.style.stayOnTop; last = last.prev);
-                     
+
                      parent.children.Move(this, last);
 
                      // Definitely don't want that:   why not?
@@ -3667,7 +3782,7 @@ private:
                   }
                }
             }
-            else 
+            else
             {
                if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
                {
@@ -3724,9 +3839,9 @@ private:
       if(guiApp.windowScrolling && !consequential)
       {
          guiApp.windowScrolling.SetScrollPosition(
-            (guiApp.windowScrolling.sbh) ? 
+            (guiApp.windowScrolling.sbh) ?
                (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
-            (guiApp.windowScrolling.sbv) ? 
+            (guiApp.windowScrolling.sbv) ?
                (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
       }
       if(guiApp.windowMoving)
@@ -3819,7 +3934,7 @@ private:
                   h = guiApp.windowResizingBefore.h - ry;
                }
             }
-         
+
             // Position
             if(!guiApp.windowIsResizing || guiApp.resizeX)
                x = guiApp.windowMovingBefore.x + rx;
@@ -3873,7 +3988,7 @@ private:
 
             // Break the anchors for moveable/resizable windows
             // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
-            if(window.style.fixed) 
+            if(window.style.fixed)
             {
                if(window.state == normal)
                {
@@ -3913,7 +4028,7 @@ private:
          w = msgWindow;
          if(w) incref w;
          window = (w && !w.disabled) ? w : null;
-         
+
          if(trueWindow) incref trueWindow;
 
          if(consequential) mods->isSideEffect = true;
@@ -3938,9 +4053,9 @@ private:
             {
                Window moved = trueWindow;
                for(moved = trueWindow; moved; moved = moved.parent)
-                  if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized)) 
+                  if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
                      break;
-               if(moved) 
+               if(moved)
                {
                   window = moved;
                   windowDragged = true;
@@ -3963,9 +4078,9 @@ private:
             {
                Window moved = window;
                for(moved = window; moved; moved = moved.parent)
-                  if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized)) 
+                  if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
                      break;
-               if(moved) 
+               if(moved)
                {
                   window = moved;
                   windowDragged = true;
@@ -3999,7 +4114,7 @@ private:
                      doActivation = false;
                   */
 
-                  if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) || 
+                  if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
                      (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
                   {
                      // Let the OnLeftButtonDown do the activating instead
@@ -4025,6 +4140,8 @@ private:
                            return false;
                         }
                         delete activateWindow;
+                        // Trouble with clickThrough, siblings and activation (Fix for nicktick scrolling, siblings/activation endless loops, #844)
+                        activate = false;
                      }
                      mods->isActivate = true;
                   }
@@ -4066,7 +4183,7 @@ private:
                   else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
                   {
                      if(window.style.fixed &&
-                        (windowDragged || 
+                        (windowDragged ||
                         window.IsMouseMoving(
                            x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
                      {
@@ -4088,8 +4205,8 @@ private:
                   }
                   else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
                   {
-                     if(window.style.hasMaximize && 
-                        window.IsMouseMoving( 
+                     if(window.style.hasMaximize &&
+                        window.IsMouseMoving(
                            x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
                      {
                         window.SetState(
@@ -4101,7 +4218,7 @@ private:
             }
             else
                window = null;
-            if(guiApp.windowMoving) 
+            if(guiApp.windowMoving)
             {
                if(guiApp.windowMoving.parent)
                {
@@ -4138,7 +4255,7 @@ private:
 
          if(trueWindow && trueWindow.FindModal())
             delete trueWindow;
-         
+
          /*if(trueWindow)
             incref trueWindow;
          */
@@ -4152,14 +4269,37 @@ private:
          if(guiApp.windowCaptured || trueWindow)
          {
             Window prevWindow = guiApp.prevWindow;
-            if(guiApp.prevWindow && trueWindow != guiApp.prevWindow)
+            List<Window> overWindows = guiApp.overWindows;
+            Iterator<Window> it { overWindows };
+
+            while(it.Next())
+            {
+               Window w = it.data;
+               if(trueWindow != w && !trueWindow.IsDescendantOf(w))
+               {
+                  it.pointer = null;
+                  result = w.OnMouseLeave(*mods);
+                  if(!result) break;
+                  overWindows.TakeOut(w);
+               }
+            }
+
+            if(result && guiApp.prevWindow && trueWindow != guiApp.prevWindow)
             {
                guiApp.prevWindow.mouseInside = false;
                guiApp.prevWindow = null;
 
-               // Eventually fix this not to include captured?
-               if(!prevWindow.OnMouseLeave(*mods))
-                  result = false;
+               if(result)
+               {
+                  if(trueWindow.IsDescendantOf(prevWindow))
+                  {
+                     if(!overWindows.Find(prevWindow))
+                        overWindows.Add(prevWindow);
+                  }
+                  // Eventually fix this not to include captured?
+                  else if(!prevWindow.OnMouseLeave(*mods))
+                     result = false;
+               }
             }
             if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
             {
@@ -4183,13 +4323,22 @@ private:
                }
             }
             if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
+            {
+               for(w : guiApp.overWindows; w == trueWindow)
+               {
+                  OnMouseLeave(0);
+                  guiApp.overWindows.TakeOut(w);
+                  break;
+               }
                guiApp.prevWindow = trueWindow;
+            }
             else
                guiApp.prevWindow = null;
          }
          SelectMouseCursor();
 
-         if(window && !guiApp.windowMoving && !wasMoving && !wasScrolling)
+         if(window && ((!guiApp.windowMoving && !wasMoving) ||
+            (wasMoving && guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp)) && !wasScrolling)
          {
             int clientX = x - (window.absPosition.x + window.clientStart.x);
             int clientY = y - (window.absPosition.y + window.clientStart.y);
@@ -4262,7 +4411,7 @@ private:
          if(status && !destroyed && menuBar && state != minimized)
          {
             // Disable the ALT
-            if((SmartKey)key != alt) 
+            if((SmartKey)key != alt)
                menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
             if(menuBar.focus)
             {
@@ -4335,7 +4484,7 @@ private:
 
                         if(!guiApp.windowIsResizing || guiApp.resizeY)
                            y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
-                        else                           
+                        else
                            y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
 
                         guiApp.interfaceDriver.SetMousePosition(x, y);
@@ -4351,7 +4500,7 @@ private:
                      {
                         guiApp.windowMoving.StopMoving();
                         ConsequentialMouseMove(false);
-                  
+
                         status = false;
                      }
                      break;
@@ -4393,7 +4542,7 @@ private:
                   if((defaultControl.active ||
                      defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
                      defaultControl.KeyMessage(method, defaultKey, character);
-                  status = false;                       
+                  status = false;
                }
             }
          }
@@ -4444,21 +4593,21 @@ 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)
                         {
                            if(cycleParent.CycleChildren(!key.shift, false, false, true))
                            {
+                              /*
                               Window child = cycleParent.activeChild;
 
                               // Scroll the window to include the active control
-                              /*
                               if(cycleParent.sbh && !child.style.dontScrollHorz)
                               {
                                  if(child.scrolledPos.x < 0)
-                                    cycleParent.sbh.Action(Position, 
+                                    cycleParent.sbh.Action(Position,
                                        cycleParent.scroll.x + child.scrolledPos.x, 0);
                                  else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
                                     cycleParent.sbh.Action(Position,
@@ -4467,7 +4616,7 @@ private:
                               if(cycleParent.sbv && !child.style.dontScrollVert)
                               {
                                  if(child.scrolledPos.y < 0)
-                                    cycleParent.sbv.Action(Position, 
+                                    cycleParent.sbv.Action(Position,
                                        cycleParent.scroll.y + child.scrolledPos.y, 0);
                                  else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
                                     cycleParent.sbv.Action(Position,
@@ -4537,7 +4686,7 @@ private:
                               }
                            }
                         }
-                        break;            
+                        break;
                      }
                      */
                   }
@@ -4628,14 +4777,17 @@ 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;
             incref hotKeyWindow;
-            if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient)
+            if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient && !hotKeyWindow.inactive)
                if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
                {
                   status = false;
@@ -4685,8 +4837,8 @@ private:
       Window child;
 
       // Setup relationship with outside world (bb root || !bb)
-      if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop || 
-         (_displayDriver && dispDriver != parent.dispDriver))
+      if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
+         (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))
       {
          rootWindow = this;
          if(!tempExtents)
@@ -4718,12 +4870,13 @@ 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;
 
-         windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
+         if(!windowHandle)
+            windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
 
          // This was here, is it really needed?
          //guiApp.interfaceDriver.ActivateRootWindow(this);
@@ -4746,7 +4899,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)
       {
@@ -4762,7 +4916,10 @@ private:
       for(child = children.first; child; child = child.next)
       {
          if(child.created && !child.Setup(false))
-            result = false; 
+            result = false;
+
+         if(guiApp.modeSwitching && guiApp.fullScreen && child.rootWindow == child)
+            child.UpdateCaption();
       }
       return result;
    }
@@ -4770,8 +4927,8 @@ private:
    bool SetupDisplay(void)
    {
 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
-      if(is3D) return Window3D_SetupDisplay(this); else 
-#endif   
+      if(is3D) return Window3D_SetupDisplay(this); else
+#endif
       if(SetupRoot())
          return Setup(true);
       return false;
@@ -4786,11 +4943,6 @@ private:
       Window child;
       WindowState stateBackup = state;
 
-      /*
-      if(!rootWindow.created)
-         printf("");
-      */
-      
       if(((subclass(Window))_class).pureVTbl)
       {
          if(_vTbl == _class._vTbl)
@@ -4823,7 +4975,7 @@ private:
             }
          }
       }
-      
+
       if(guiApp.fullScreenMode || this != guiApp.desktop)
       {
          SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
@@ -4862,7 +5014,7 @@ private:
                      }
                   for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
                   {
-                     cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null, 
+                     cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
                         cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
                      if(cursor.bitmap)
                         cursor.bitmap.paletteShades = cursor.paletteShades;
@@ -4879,7 +5031,7 @@ private:
             }
 
             // Load Window Graphic Resources
-            
+
             /*
             if(usedFont == setFont || usedFont == window.systemFont)
                RemoveResource(usedFont);
@@ -4889,13 +5041,14 @@ private:
 
             if(systemFont)
                RemoveResource(systemFont);
-            
+
             if(captionFont)
                RemoveResource(captionFont);
 
             for(ptr = resources.first; ptr; ptr = ptr.next)
             {
-               ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
+               if(!ptr.loaded)   // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
+                  ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
             }
             if(setFont)
                AddResource(setFont);
@@ -4931,7 +5084,7 @@ private:
             }
             */
 
-            captionFont = guiApp.currentSkin.CaptionFont();
+            captionFont = guiApp.currentSkin ? guiApp.currentSkin.CaptionFont() : null;
             AddResource(captionFont);
 
             if(OnLoadGraphics())
@@ -4941,7 +5094,7 @@ private:
                display.Unlock();
 
                //SetScrollLineStep(sbStep.x, sbStep.y);
-               
+
                if(this != guiApp.desktop)
                {
                   if(resetAnchors)
@@ -4965,22 +5118,22 @@ private:
                   switch(state)
                   {
                      case maximized:
-                     
+
                         stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
                         stateSizeAnchor = SizeAnchor {};
                         break;
-                     
+
                      case minimized:
                      {
                         int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
 
-                        stateAnchor = 
-                           Anchor 
+                        stateAnchor =
+                           Anchor
                            {
                               left = (iconID % maxIcons) * MINIMIZED_WIDTH,
                               bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
                            };
-                        
+
                         stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
                         break;
                      }
@@ -5055,15 +5208,11 @@ private:
          if(activeChild)
             guiApp.interfaceDriver.ActivateRootWindow(activeChild);
       }
-      /*
-      TODO:
       if(!success)
-         //guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, caption);
-         guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, class.name);
-      */
+         LogErrorCode(graphicsLoadingFailed, _class.name);
 
       // Do this here to avoid problems on Windows
-      if(stateBackup == maximized)
+      if(rootWindow == this && parent && stateBackup == maximized)
          property::state = maximized;
       return result;
    }
@@ -5216,7 +5365,7 @@ private:
       if(interimWindow && interimWindow.master)
          interimMaster = interimWindow.master.rootWindow;
 
-      if(active && state == minimized) // && (!window.nativeDecorations || window.rootWindow != window)
+      if(active && state == minimized && window.parent) // && (!window.nativeDecorations || window.rootWindow != window)
          // SetState(normal, false, 0);
          SetState(lastState, false, 0);
 
@@ -5227,7 +5376,7 @@ private:
       /* WTH is this doing here?
       while(swap && swap.activeChild)
       {
-         swap = swap.activeChild;         
+         swap = swap.activeChild;
       }
       */
       // TESTING THIS BEFORE...
@@ -5269,7 +5418,7 @@ private:
       return result;
    }
 
-   bool DestroyEx(int returnCode)
+   bool DestroyEx(int64 returnCode)
    {
       OldLink slave;
       Timer timer, nextTimer;
@@ -5277,7 +5426,7 @@ private:
       OldLink prevOrder = null;
       Window client = null;
 
-      if(parent) stopwatching(parent, font); 
+      if(parent) stopwatching(parent, font);
 
       // if(window.modalSlave) return false;
       if(destroyed || !created)
@@ -5313,7 +5462,16 @@ private:
          guiApp.prevWindow = null;
          OnMouseLeave(0);
       }
-      if(guiApp.caretOwner == this) 
+      else
+      {
+         for(w : guiApp.overWindows; w == this)
+         {
+            OnMouseLeave(0);
+            guiApp.overWindows.TakeOut(w);
+            break;
+         }
+      }
+      if(guiApp.caretOwner == this)
       {
          guiApp.interfaceDriver.SetCaret(0,0,0);
          UpdateCaret(false, true);
@@ -5353,7 +5511,7 @@ private:
                if(client == this) { client = null; break; }
                if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
                   tmpPrev = client.order.prev;
-               else 
+               else
                {
                   if(client)
                      prevOrder = tmpPrev;
@@ -5385,6 +5543,8 @@ private:
          if(master.defaultControl == this)
             master.defaultControl = null;
       }
+      if(parent)
+         parent.OnChildAddedOrRemoved(this, true);
       if(parent && !parent.destroyed /*&&
          rootWindow && rootWindow.display && !rootWindow.destroyed*/)
       {
@@ -5401,7 +5561,7 @@ private:
                   parent.UpdateActiveDocument(null);
                }
             }
-            else 
+            else
             {
                if(guiApp.interimWindow == this)
                {
@@ -5635,7 +5795,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--;
@@ -5692,7 +5852,7 @@ private:
 
          Position(x, y, w, h, true, true, true, true, false, true);
 
-         if(!style.inactive && !style.interim && this == parent.activeClient)
+         if(!style.inactive && !style.interim && parent && this == parent.activeClient)
             parent.UpdateActiveDocument(null);
       }
 
@@ -5761,7 +5921,7 @@ private:
          if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
          {
             DataRow row = listBox.AddRow();
-            row.tag = (int)child;
+            row.tag = (int64)(intptr)child;
             child.FigureCaption(caption);
             row.SetData(null, caption);
          }
@@ -5776,7 +5936,7 @@ private:
          {
             guiApp.desktop.mutex.Wait();
             guiApp.desktop.display.Lock(true);
-         
+
             Update(extent);
             if(guiApp.desktop.active)
             {
@@ -5796,7 +5956,7 @@ private:
                   guiApp.RestoreCursorBackground();
                }
             }
-         
+
             guiApp.desktop.display.Unlock();
             guiApp.desktop.mutex.Release();
          }
@@ -5805,7 +5965,7 @@ private:
             Window rootWindow = this.rootWindow;
             rootWindow.mutex.Wait();
             display.Lock(true);
-         
+
             Update(extent);
             if(guiApp.waiting)
                guiApp.SignalEvent();
@@ -5859,7 +6019,7 @@ private:
          isForegroundWindow = true;
          ActivateEx(active, active, false, false, null, null);
          isForegroundWindow = false;
-      }  
+      }
    }
    */
 
@@ -5929,7 +6089,7 @@ private:
          guiApp.windowMovingBefore = scrolledPos;
          guiApp.windowResizingBefore = size;
          guiApp.windowMoving.UpdateDecorations();
-         if(guiApp.windowIsResizing) 
+         if(guiApp.windowIsResizing)
             guiApp.resizeEndX = guiApp.resizeEndY = true;
 
          if(setCursorPosition)
@@ -5940,7 +6100,7 @@ private:
             guiApp.interfaceDriver.GetMousePosition(&x, &y);
             guiApp.windowMovingStart.x += x - absPosition.x;
             guiApp.windowMovingStart.y += y - absPosition.y;
-         } 
+         }
 
          if(guiApp.windowMoving)
          {
@@ -5957,6 +6117,28 @@ private:
       }
    }
 
+   void SetupFileMonitor()
+   {
+      if(!fileMonitor)
+      {
+         fileMonitor = FileMonitor
+         {
+            this, FileChange { modified = true };
+
+            bool OnFileNotify(FileChange action, const char * param)
+            {
+               incref this;
+               fileMonitor.StopMonitoring();
+               if(OnFileModified(action, param))
+                  fileMonitor.StartMonitoring();
+               delete this;
+               return true;
+            }
+         };
+         incref fileMonitor;
+      }
+   }
+
 public:
    // normal Methods
    bool Create()
@@ -5967,12 +6149,11 @@ public:
          result = true;
       else if(guiApp && guiApp.driver != null)
       {
-         void * systemParent = null;
          OldLink slaveHolder;
          Window last;
          bool visible = !style.hidden;
 
-         if(style.embedded) 
+         if(style.embedded)
          {
             systemParent = parent;
             parent = guiApp.desktop;
@@ -5983,6 +6164,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;
@@ -6049,7 +6233,7 @@ public:
 
             this.visible = false;
             style.hidden = true;
-    
+
             //created = true;
             // autoCreate = true;
             wasCreated = true;
@@ -6079,7 +6263,7 @@ public:
 
                      if(style.hasMenuBar /*&& menu*/)
                      {
-                        menuBar = 
+                        menuBar =
                            PopupMenu
                            {
                               this,
@@ -6091,7 +6275,7 @@ public:
 
                      if(statusBar)
                         statusBar.Create();
-                     
+
                      // Create the system buttons
                      CreateSystemChildren();
 
@@ -6136,11 +6320,11 @@ public:
                            next = link.next;
                            if(!slave.created && (slave.autoCreate || slave.wasCreated))
                            {
-                              slave.Create();
-                              // Things might have happened that invalidated 'next'...
-                              // Start over the search for slaves to create.
-                              // (Added this to fix crash with Stacker & Toolbar)
-                              next = slaves.first;
+                              if(slave.Create())
+                                 // Things might have happened that invalidated 'next'...
+                                 // Start over the search for slaves to create.
+                                 // (Added this to fix crash with Stacker & Toolbar)
+                                 next = slaves.first;
                            }
                         }
                      }
@@ -6159,9 +6343,14 @@ public:
                         if(state == minimized) parent.numIcons--;
                      }
 
+                     parent.OnChildAddedOrRemoved(this, false);
+
+                     if(rootWindow == this && visible)   // So that X11 windows don't show as 'unknown'
+                        UpdateCaption();
                      // Real set state & activate for proper display & activation
                      property::visible = visible;
                      //  SetState(state & 0x00000003, true, 0);
+                     guiApp.interfaceDriver.SetIcon(this, icon);
 
                      if(visible)
                      {
@@ -6169,10 +6358,14 @@ public:
                         /*if(rootWindow == this)
                            guiApp.interfaceDriver.ActivateRootWindow(this);
                         else*/
-                        if(creationActivation == activate)
+                        if(creationActivation == activate && guiApp.desktop.active)
                            ActivateEx(true, false, true, true, null, null);
-                        else if(creationActivation == flash)
-                           Flash();
+                        else if(creationActivation == activate || creationActivation == flash)
+                        {
+                           MakeActive();
+                           if(this == rootWindow)
+                              Flash();
+                        }
                      }
 
                      if(!destroyed)
@@ -6224,7 +6417,7 @@ public:
          {
             Window child;
             Box realBox;
-            
+
             // Testing this to avoid repetitve full update to take time...
             if(dirtyArea.count == 1)
             {
@@ -6249,7 +6442,7 @@ public:
                   return;
                }
             }
-            
+
             rootWindow.dirty = true;
 
             if(region != null)
@@ -6264,7 +6457,7 @@ public:
             else
                realBox = box;
 
-            if(realBox.right >= realBox.left && 
+            if(realBox.right >= realBox.left &&
                realBox.bottom >= realBox.top)
             {
                // if(!rootWindow.fullRender)
@@ -6313,7 +6506,7 @@ public:
                      childBox.top     -= window.absPosition.y - guiApp.desktop.absPosition.y;
                      childBox.right   -= window.absPosition.x - guiApp.desktop.absPosition.x;
                      childBox.bottom  -= window.absPosition.y - guiApp.desktop.absPosition.y;
-       
+
                      window.Update(childBox);
                   }
                   else
@@ -6343,7 +6536,7 @@ public:
       return result;
    }
 
-   bool Destroy(int code)
+   bool Destroy(int64 code)
    {
       //if(created)
       if(this)
@@ -6394,11 +6587,10 @@ public:
 
    void SetScrollArea(int width, int height, bool snapToStep)
    {
-      bool resize = false;
       if(snapToStep)
       {
          int stepX = sbStep.x, stepY = sbStep.y;
-         // Needed to make snapped down position match the skin's check of client area 
+         // Needed to make snapped down position match the skin's check of client area
          // against realvirtual
          if(guiApp.textMode)
          {
@@ -6506,7 +6698,7 @@ public:
       {
          if(state == newState || OnStateChange(newState, mods))
          {
-            WindowState prevState = state;
+            //WindowState prevState = state;
 
             StopMoving();
 
@@ -6514,7 +6706,7 @@ public:
             // This has the effect of activating the window through the system...
             if(rootWindow == this)
                guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
-      
+
             SetStateEx(newState, activate);
 
             if(rootWindow == this && !rootWindow.nativeDecorations)
@@ -6545,15 +6737,15 @@ public:
                parent.UpdateScrollBars(true, true);
 
             /*
-            // Do we really need this stuff here? 
-            // Shouldn't the Activate stuff take care of it?              
+            // Do we really need this stuff here?
+            // Shouldn't the Activate stuff take care of it?
             if(parent.rootWindow == parent && style)
             {
                char caption[2048];
                parent.FigureCaption(caption);
                guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
                parent.UpdateDecorations();
-            }         
+            }
             */
 
             rootWindow.ConsequentialMouseMove(false);
@@ -6621,32 +6813,32 @@ public:
       PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
       MenuItem
       {
-         menu, $"Restore", r, NotifySelect = MenuWindowRestore, 
+         menu, $"Restore", r, NotifySelect = MenuWindowRestore,
          disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
       };
       MenuItem
       {
-         menu, $"Move", m, NotifySelect = MenuWindowMove, 
+         menu, $"Move", m, NotifySelect = MenuWindowMove,
          disabled = !style.fixed || state == maximized
       };
       MenuItem
       {
-         menu, $"Size", s, NotifySelect = MenuWindowSize, 
+         menu, $"Size", s, NotifySelect = MenuWindowSize,
          disabled = !style.sizable || state != normal
       };
       MenuItem
       {
-         menu, $"Minimize", n, NotifySelect = MenuWindowMinimize, 
+         menu, $"Minimize", n, NotifySelect = MenuWindowMinimize,
          disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
       };
       MenuItem
       {
-         menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize, 
+         menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
          disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
       };
       MenuItem
       {
-         menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop, 
+         menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
          disabled = !style.fixed, checkable = true, checked = style.stayOnTop
       };
       MenuDivider { menu };
@@ -6673,7 +6865,11 @@ public:
       if(guiApp.desktop.active)
          Activate();
       else if(!active)
-         Flash();
+      {
+         MakeActive();
+         if(this == rootWindow)
+            Flash();
+      }
    }
 
    void Deactivate(void)
@@ -6717,7 +6913,7 @@ public:
             }
          }
          /*
-         if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) && 
+         if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
             parent.tabCycle && parent.CycleChildren(backward, false, false))
             return true;
          */
@@ -6784,7 +6980,8 @@ public:
          if(/*created && */display)
          {
             display.Lock(false);
-            ptr.loaded = display.displaySystem.LoadResource(resource);
+            if(!ptr.loaded)   // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
+               ptr.loaded = display.displaySystem.LoadResource(resource);
             display.Unlock();
          }
          /*
@@ -6836,7 +7033,7 @@ public:
          caretPos.x = x;
          caretPos.y = y;
          caretSize = size;
-         if(active && !style.interim)
+         if(active && !style.interim && isEnabled)
          {
             if(visible || !guiApp.caretOwner)
                guiApp.caretOwner = size ? this : null;
@@ -6908,7 +7105,7 @@ public:
       }
    }
 
-   void SetText(char * format, ...)
+   private void _SetCaption(const char * format, va_list args)
    {
       if(this)
       {
@@ -6916,22 +7113,34 @@ public:
          if(format)
          {
             char caption[MAX_F_STRING];
-            va_list args;
-            va_start(args, format);
-            vsprintf(caption, format, args);
-            va_end(args);
+            vsnprintf(caption, sizeof(caption), format, args);
+            caption[sizeof(caption)-1] = 0;
 
-            this.caption = new char[strlen(caption)+1];
-            if(this.caption)
-               strcpy(this.caption, caption);
+            this.caption = CopyString(caption);
          }
          if(created)
             UpdateCaption();
 
-         firewatchers text;
+         firewatchers caption;
       }
    }
 
+   /*deprecated*/ void SetText(const char * format, ...)
+   {
+      va_list args;
+      va_start(args, format);
+      _SetCaption(format, args);
+      va_end(args);
+   }
+
+   void SetCaption(const char * format, ...)
+   {
+      va_list args;
+      va_start(args, format);
+      _SetCaption(format, args);
+      va_end(args);
+   }
+
    bool Grab(Bitmap bitmap, Box box, bool decorations)
    {
       bool result = false;
@@ -6970,12 +7179,12 @@ public:
          {
             Window window { };
             window.Create();
-            result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top, 
+            result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
                clip.right - clip.left + 1, clip.bottom - clip.top + 1);
             delete window;
          }
          else
-            result = display.Grab(bitmap, clip.left, clip.top, 
+            result = display.Grab(bitmap, clip.left, clip.top,
                clip.right - clip.left + 1, clip.bottom - clip.top + 1);
 
          if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
@@ -7103,7 +7312,7 @@ public:
          return false;
       if(terminateX > 1)
          return true;
-         
+
       closing = true;
 
       if(!OnClose(parentClosing))
@@ -7135,19 +7344,28 @@ public:
          for(slave = slaves.first; slave; slave = slave.next)
          {
             Window w = slave.data;
-            if((w.parent == this || !w.IsDescendantOf(this)) && !w.CloseConfirmation(true))
+            if(w.parent != this && !w.IsDescendantOf(this) && !w.CloseConfirmation(true))
             {
-               // ((Window)slave.data).CloseConfirmation(true);
                result = false;
                break;
             }
          }
       }
 
+      // Confirm closure of active clients first (We use OnClose() to hide instead of destroy in the IDE)
       if(result)
       {
          for(child = children.first; child; child = child.next)
-            if(child.master != this && !child.CloseConfirmation(true))
+            if(child.isActiveClient && !child.CloseConfirmation(true))
+            {
+               result = false;
+               break;
+            }
+      }
+      if(result)
+      {
+         for(child = children.first; child; child = child.next)
+            if(!child.isActiveClient && !child.CloseConfirmation(true))
             {
                result = false;
                break;
@@ -7186,6 +7404,7 @@ public:
 
    bool MenuFileSave(MenuItem selection, Modifiers mods)
    {
+      SetupFileMonitor();
       if(fileName)
       {
          fileMonitor.fileName = null;
@@ -7216,6 +7435,8 @@ public:
       DialogResult result = (DialogResult)bool::true;
       FileDialog fileDialog = saveDialog;
 
+      SetupFileMonitor();
+
       if(!fileDialog)
          fileDialog = FileDialog {};
       if(fileDialog)
@@ -7239,7 +7460,7 @@ public:
             fileDialog.master = master.parent ? master : this;
             if(fileDialog.Modal() == ok)
             {
-               char * filePath = fileDialog.filePath;
+               const char * filePath = fileDialog.filePath;
                saving = true;
                if(OnSaveFile(filePath))
                {
@@ -7253,7 +7474,7 @@ public:
                   MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
                   DialogResult answer = dialog.Modal();
                   saving = false;
-                  if(answer != yes) 
+                  if(answer != yes)
                   {
                      result = answer;
                      break;
@@ -7386,7 +7607,7 @@ public:
 
       for(document = children.first; document; document = next)
       {
-         for(next = document.next; next && !(next.style.isActiveClient; next = next.next);
+         for(next = document.next; next && !next.style.isActiveClient; next = next.next);
          if(document.style.isActiveClient)
             if(!document.Destroy(0) && !document.style.hidden)
                return false;
@@ -7445,7 +7666,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++);
@@ -7462,7 +7683,7 @@ public:
       }
       document = cycle.data;
       document.Activate();
-      
+
       //if(activeChild.state == maximized)
       //  document.SetState(maximized, false, mods);
       //else if(document.state == minimized)
@@ -7607,7 +7828,7 @@ public:
    bool MenuWindowWindows(MenuItem selection, Modifiers mods)
    {
       WindowList dialog { master = this };
-      Window document = (Window)dialog.Modal();
+      Window document = (Window)(intptr)dialog.Modal();
       if(document)
       {
          if(activeChild.state == maximized)
@@ -7658,8 +7879,8 @@ public:
    virtual void OnHScroll(ScrollBarAction action, int position, Key key);
    virtual void OnVScroll(ScrollBarAction action, int position, Key key);
    virtual void OnDrawOverChildren(Surface surface);
-   virtual bool OnFileModified(FileChange fileChange, char * param);
-   virtual bool OnSaveFile(char * fileName);
+   virtual bool OnFileModified(FileChange fileChange, const char * param);
+   virtual bool OnSaveFile(const char * fileName);
 
    // Virtual Methods -- Children management (To support Stacker, for lack of built-in auto-layout)
    // Note: A 'client' would refer to isActiveClient, rather than
@@ -7674,14 +7895,20 @@ public:
    virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
    {
       *cw = *w;
-      *ch = *h;      
+      *ch = *h;
+   }
+   virtual void ShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
+   virtual void PreShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
+   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 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 void UpdateNonClient();
-   virtual void SetBox(Box box);
+   virtual void SetBox(Box box);    // This is used in the MySkin skin
    virtual bool IsInside(int x, int y)
    {
       return box.IsPointInside({x, y});
@@ -7694,7 +7921,7 @@ public:
    // Notifications
    virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
    virtual void Window::NotifyDestroyed(Window window, DialogResult result);
-   virtual void Window::NotifySaved(Window window, char * filePath);
+   virtual void Window::NotifySaved(Window window, const char * filePath);
 
    // Public Methods
 
@@ -7719,11 +7946,10 @@ public:
 
             if(!master || (master == this.parent && master == guiApp.desktop))
                property::master = value;
-            
+
             if(parent)
             {
                parent.children.Remove(this);
-               parent.OnChildAddedOrRemoved(this, true);
 
                parent.Update(
                {
@@ -7764,18 +7990,24 @@ 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)
             {
                if(created)
                {
                   int x = position.x, y = position.y, w = size.w, h = size.h;
-                  
+
                   int vpw, vph;
 
                   x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
                   y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
-                  
+
                   vpw = value.clientSize.w;
                   vph = value.clientSize.h;
                   if(style.nonClient)
@@ -7823,10 +8055,12 @@ public:
                {
                   if(!style.noCycle)
                      parent.childrenCycle.Insert(
-                        (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null, 
+                        // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
+                        //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
+                        null,
                         cycle = OldLink { data = this });
                   parent.childrenOrder.Insert(
-                     (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last, 
+                     (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
                      order = OldLink { data = this });
                }
 
@@ -7838,7 +8072,7 @@ public:
                }
 
                // *** FONT INHERITANCE ***
-               if(!setFont && oldParent) 
+               if(!setFont && oldParent)
                   stopwatching(oldParent, font);
 
                if(systemFont)
@@ -7871,21 +8105,22 @@ public:
                         Update(null);
                      }
                   };
-               
+
                firewatchers font;
 
 
                if(value.rootWindow && value.rootWindow.display && rootWindow)
                {
-                  bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) || 
+                  bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
                         (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
-                  
+
                   if(reloadGraphics)
                      UnloadGraphics(false);
-                  SetupDisplay();
+                  if(created)
+                     SetupDisplay();
                   if(reloadGraphics)
                      LoadGraphics(false, false);
-                     
+
                   /*
                   if(value.rootWindow != rootWindow)
                      DisplayModeChanged();
@@ -7893,7 +8128,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;
@@ -7907,6 +8146,8 @@ public:
 
             }
             // else parent = value;
+            if(oldParent)
+               oldParent.OnChildAddedOrRemoved(this, true);
          }
       }
       get { return parent; }
@@ -7956,7 +8197,7 @@ public:
       get { return master ? master : parent; }
    };
 
-   property char * caption
+   property const char * caption
    {
       property_category $"Appearance"
       watchable
@@ -8026,7 +8267,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; }
    };
@@ -8067,7 +8308,7 @@ public:
             CreateSystemChildren();
          }
       }
-      get { return (BorderStyle)style.borderBits; } 
+      get { return (BorderStyle)style.borderBits; }
    };
 
    property Size minClientSize
@@ -8144,7 +8385,7 @@ public:
       }
       get { return style.hasClose; }
    };
-   
+
    property bool nonClient
    {
       property_category $"Layout"
@@ -8162,7 +8403,7 @@ public:
       property_category $"Behavior"
       set
       {
-         if(value) 
+         if(value)
          {
             // *** NEW HERE: ***
             if(!style.inactive)
@@ -8191,7 +8432,9 @@ public:
                if(!style.noCycle)
                {
                   parent.childrenCycle.Insert(
-                     (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null, 
+                     // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
+                     //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
+                     null,
                      cycle = OldLink { data = this });
                }
                parent.childrenOrder.Insert(
@@ -8245,7 +8488,7 @@ public:
       set { style.tabCycle = value; }
       get { return style.tabCycle; }
    };
-     
+
    property bool isDefault
    {
       property_category $"Behavior"
@@ -8255,8 +8498,8 @@ public:
          {
             if(value)
             {
-               Window sibling;
-               /*for(sibling = parent.children.first; sibling; sibling = sibling.next)
+               /*Window sibling;
+               for(sibling = parent.children.first; sibling; sibling = sibling.next)
                   if(sibling != this && sibling.style.isDefault)
                      sibling.style.isDefault = false;*/
                if(master.defaultControl)
@@ -8287,7 +8530,7 @@ public:
       property_category $"Window Style"
       set
       {
-         if(value) 
+         if(value)
          {
             if(!menu)
             {
@@ -8297,13 +8540,13 @@ public:
             if(created && !menuBar)
             {
                menuBar =
-                  PopupMenu 
+                  PopupMenu
                   {
                      this, menu = menu,
                      isMenuBar = true,
                      anchor = Anchor { top = 23, left = 1, right = 1 },
                      size.h = 24,
-                     inactive = true, nonClient = true                            
+                     inactive = true, nonClient = true
                   };
                menuBar.Create();
             }
@@ -8370,14 +8613,14 @@ public:
                   if(order)
                   {
                      OldLink order;
-                     for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev; 
+                     for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
                          order && ((Window)order.data).style.stayOnTop;
                          order = (order == parent.childrenOrder.first) ? null : order.prev);
                       last = order ? order.data : null;
                   }
                   else
                   {
-                     for(last = parent.children.last; 
+                     for(last = parent.children.last;
                          last && last.style.stayOnTop;
                          last = last.prev);
                   }
@@ -8414,9 +8657,9 @@ public:
             if(!menuBar && style.hasMenuBar && value)
             {
                menuBar = PopupMenu
-                         { 
-                            this, menu = value, isMenuBar = true, 
-                            anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24, 
+                         {
+                            this, menu = value, isMenuBar = true,
+                            anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
                             inactive = true, nonClient = true
                          };
                 menuBar.Create();
@@ -8489,7 +8732,7 @@ public:
       property_category $"Layout"
       isset
       {
-         return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) || 
+         return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
                 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
             sizeAnchor.isClientW != sizeAnchor.isClientH;
       }
@@ -8525,12 +8768,7 @@ public:
       property_category $"Layout"
       isset
       {
-         Anchor thisAnchor = anchor;
-         SizeAnchor thisSizeAnchor = sizeAnchor;
-         bool leftRight = (anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none);
-         bool topBottom = (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none);
-         bool isClient = !sizeAnchor.isClientW && !sizeAnchor.isClientH;
-         return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) || 
+         return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
                 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
             !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
       }
@@ -8562,7 +8800,7 @@ public:
       property_category $"Layout"
       isset
       {
-         return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) || 
+         return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
                 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
             sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
       }
@@ -8582,9 +8820,10 @@ public:
 
             ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
             Position(x,y, w, h, true, true, true, true, false, true);
+            if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
          }
       }
-      get { value = clientSize; }
+      get { value = this ? clientSize : { 0, 0 }; }
    };
 
    property Size initSize { get { value = sizeAnchor.size; } };
@@ -8610,7 +8849,7 @@ public:
             }
             anchor = value;
 
-            if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type)) 
+            if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
             {
                anchor.left.distance = 0;
                anchor.horz.type = 0;
@@ -8628,7 +8867,7 @@ public:
                int x, y, w, h;
 
                normalAnchor = anchor;
-               
+
                // Break the anchors for moveable/resizable windows
                /*if(style.fixed ) //&& value.left.type == cascade)
                {
@@ -8807,7 +9046,7 @@ public:
                         {
                            tmpPrev = client.order.prev;
                         }
-                        else 
+                        else
                         {
                            if(client)
                               prevOrder = tmpPrev;
@@ -8847,7 +9086,7 @@ public:
                cycle = null;
                order = null;
                */
-               
+
                SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
             }
 
@@ -8879,7 +9118,7 @@ public:
                   if(!(style.noCycle))
                   {
                      cycle = parent.childrenCycle.AddAfter(
-                        (parent.activeChild && parent.activeChild.cycle) ? 
+                        (parent.activeChild && parent.activeChild.cycle) ?
                            parent.activeChild.cycle.prev : null, sizeof(OldLink));
                      cycle.data = this;
                   }
@@ -8889,15 +9128,19 @@ public:
                   order.data = this;
                }
                */
-     
+
                /*
                if(true || !parent.activeChild)
                   ActivateEx(true, false, true, true, null, null);
                */
-               if(creationActivation == activate)
+               if(creationActivation == activate && guiApp.desktop.active)
                   ActivateEx(true, false, true, true, null, null);
-               else if(creationActivation == flash && !object)
-                  Flash();               
+               else if((creationActivation == activate || creationActivation == flash) && !object)
+               {
+                  MakeActive();
+                  if(this == rootWindow)
+                     Flash();
+               }
 
                //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
                Update(null);
@@ -8914,11 +9157,11 @@ public:
 
       get { return (style.hidden || !setVisible) ? false : true; }
    };
-    
+
    property bool isDocument
    {
       property_category $"Document"
-      set { style.isDocument = value; }
+      set { style.isDocument = value; if(value) SetupFileMonitor(); }
       get { return style.isDocument; }
    };
 
@@ -8938,7 +9181,7 @@ public:
          {
             if(!style.hasHorzScroll && created)
             {
-               CreateSystemChildren();         
+               CreateSystemChildren();
                Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
             }
          }
@@ -9036,12 +9279,7 @@ public:
    property Point scroll
    {
       property_category $"Behavior"
-      set
-      {
-         // scroll = value;
-         // TESTING THIS IMPLEMENTATION:
-         SetScrollPosition(value.x, value.y);
-      }
+      set { if(this) SetScrollPosition(value.x, value.y); }
       get { value = scroll; }
    };
 
@@ -9052,11 +9290,21 @@ public:
       get { return (bool)modifyVirtArea; }
    };
 
-   property char * fileName
+   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 const char * fileName
    {
       property_category $"Document"
       set
       {
+         SetupFileMonitor();
+
          if(menu && ((!fileName && value) || (fileName && !value)))
          {
             MenuItem item = menu.FindItem(MenuFileSave, 0);
@@ -9080,7 +9328,7 @@ public:
       get { return fileName; }
    };
 
-   property int id
+   property int64 id
    {
       property_category $"Data"
       set { id = value; }
@@ -9115,13 +9363,29 @@ public:
    {
       property_category $"Window Style"
       set { style.showInTaskBar = value; }
-      get { return (style.showInTaskBar; }
+      get { return style.showInTaskBar; }
    };
    property FileDialog saveDialog { set { saveDialog = value; } };
    property bool isActiveClient
    {
       property_category $"Behavior"
-      set { style.isActiveClient = value; }
+      set
+      {
+         if(parent && style.isActiveClient != value && !style.hidden)
+         {
+            if(value)
+            {
+               if(state == minimized) parent.numIcons++;
+               parent.numPositions++;
+            }
+            else
+            {
+               if(state == minimized) parent.numIcons--;
+               parent.numPositions--;
+            }
+         }
+         style.isActiveClient = value;
+      }
       get { return style.isActiveClient; }
    };
 
@@ -9134,10 +9398,10 @@ public:
          SelectMouseCursor();
       }
       get { return cursor; }
-   };      
+   };
 
 //#if !defined(ECERE_VANILLA)
-   property char * name
+   property const char * name
    {
       property_category $"Design"
       get
@@ -9151,7 +9415,7 @@ public:
       }
    };
 //#endif
-   property char * displayDriver
+   property const char * displayDriver
    {
       property_category $"Behavior"
       set
@@ -9191,19 +9455,19 @@ public:
    };
 
    // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
-                                                                                                            
+
    // Will be merged with font later
    property Font fontObject { get { return usedFont ? usedFont.font : null; } };
    property Point clientStart { get { value = clientStart; } };
    property Point absPosition { get { value = absPosition; } };
-   property Anchor normalAnchor { get {value = normalAnchor; } };
+   property Anchor normalAnchor { get { value = normalAnchor; } };
    // property Size normalSizeAnchor { get { value = normalSizeAnchor; } };
    property bool active { get { return (bool)active; } };
    property bool created { get { return (bool)created; } };
    property bool destroyed { get { return (bool)destroyed; } };
    property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
-   property Window firstChild { get { return children.first; } };   
-   property Window lastChild { get { return children.last; } };   
+   property Window firstChild { get { return children.first; } };
+   property Window lastChild { get { return children.last; } };
    property Window activeClient { get { return activeClient; } };
    property Window activeChild { get { return activeChild; } };
    property Display display  { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
@@ -9211,7 +9475,7 @@ public:
    property ScrollBar horzScroll { get { return sbh; } };
    property ScrollBar vertScroll { get { return sbv; } };
    property StatusBar statusBar { get { return statusBar; } };
-   property Window rootWindow { get { return rootWindow; } };   
+   property Window rootWindow { get { return rootWindow; } };
    property bool closing { get { return (bool)closing; } set { closing = value; } };
    property int documentID { get { return documentID; } };
    property Window previous { get { return prev; } }
@@ -9223,7 +9487,7 @@ public:
    property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
    property void * systemHandle { get { return windowHandle; } }
    property Button minimizeButton { get { return sysButtons[0]; } };
-   property Button maximizeButton { get { return sysButtons[1]; } };   
+   property Button maximizeButton { get { return sysButtons[1]; } };
    property Button closeButton { get { return sysButtons[2]; } };
    property BitmapResource icon
    {
@@ -9244,13 +9508,33 @@ 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; } };
 
-   property char * text
+   property const char * text
    {
       property_category $"Deprecated"
       watchable
@@ -9280,7 +9564,7 @@ private:
    Size scrollArea;        // Virtual Scroll area size
    Size reqScrollArea;     // Requested virtual area size
    Point scroll;           // Virtual area scrolling position
-   public ScrollBar sbh, sbv;        // Scrollbar window handles
+   ScrollBar sbh, sbv;        // Scrollbar window handles
    Cursor cursor;        // Mouse cursor used for this window
    WindowState state;
    PopupMenu menuBar;
@@ -9294,7 +9578,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;
@@ -9309,7 +9593,7 @@ private:
    void * windowHandle;    // System window handle
 
    DialogResult returnCode;// Return code for modal windows
-  
+
    Point sbStep;           // Scrollbar line scrolling steps
 
    Anchor stateAnchor;
@@ -9350,20 +9634,8 @@ private:
    Mutex mutex;
    WindowState lastState;
 
-   FileMonitor fileMonitor
-   {
-      this, FileChange { modified = true };
+   FileMonitor fileMonitor;
 
-      bool OnFileNotify(FileChange action, char * param)
-      {
-         incref this;
-         fileMonitor.StopMonitoring();
-         if(OnFileModified(action, param))
-            fileMonitor.StartMonitoring();
-         delete this;
-         return true;
-      }
-   };
    FontResource setFont, systemFont;
    FontResource usedFont;
    FontResource captionFont;
@@ -9411,7 +9683,8 @@ private:
       bool nativeDecorations:1;
       bool manageDisplay:1;
       bool formDesigner:1; // True if we this is running in the form editor
-   }; 
+      bool requireRemaximize:1;
+   };
 
    // Checks used internally for them not to take effect in FormDesigner
    property bool _isModal        { get { return !formDesigner ? style.modal : false; } }
@@ -9426,7 +9699,7 @@ public class CommonControl : Window
    // creationActivation = doNothing;
 
    ToolTip toolTip;
-   public property String toolTip
+   public property const String toolTip
    {
       property_category $"Appearance"
       set
@@ -9463,7 +9736,7 @@ public class CommonControl : Window
 
 public class Percentage : float
 {
-   char * OnGetString(char * string, float * fieldData, bool * needClass)
+   const char * OnGetString(char * string, float * fieldData, bool * needClass)
    {
       int c;
       int last = 0;
@@ -9471,7 +9744,7 @@ public class Percentage : float
       c = strlen(string)-1;
       for( ; c >= 0; c--)
       {
-         if(string[c] != '0') 
+         if(string[c] != '0')
             last = Max(last, c);
          if(string[c] == '.')
          {
@@ -9486,7 +9759,7 @@ public class Percentage : float
    }
 };
 
-public void ApplySkin(Class c, char * name, void ** vTbl)
+public void ApplySkin(Class c, const char * name, void ** vTbl)
 {
    char className[1024];
    Class sc;
@@ -9501,7 +9774,7 @@ public void ApplySkin(Class c, char * name, void ** vTbl)
    c._vTbl = new void *[c.vTblSize];
    memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
    sc = eSystem_FindClass(c.module.application, className);
-   
+
    if(vTbl)
    {
       for(m = 0; m < c.base.vTblSize; m++)
@@ -9518,7 +9791,7 @@ public void ApplySkin(Class c, char * name, void ** vTbl)
             c._vTbl[m] = sc._vTbl[m];
       }
    }
-      
+
    for(d = c.derivatives.first; d; d = d.next)
    {
       ApplySkin(d.data, name, c._vTbl);
@@ -9527,10 +9800,7 @@ public void ApplySkin(Class c, char * name, void ** vTbl)
 
 public void UnapplySkin(Class c)
 {
-   char className[1024];
-   Class sc;
    subclass(Window) wc = (subclass(Window))c;
-   subclass(Window) base = (subclass(Window))c.base;
    OldLink d;
 
    if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
@@ -9574,127 +9844,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 = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
+         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 = ((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>
@@ -9753,9 +10037,11 @@ 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)();   
+   int (** windowVTbl)();
    V controlled;
    Window window;