7 import "GuiApplication"
28 #if defined(__WIN32__)
29 import "Win32Interface"
32 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
36 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
45 // 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
47 define skinMenuHeight = 40;
48 define statusBarHeight = 30;
50 define skinMenuHeight = 25;
51 define statusBarHeight = 18;
54 default extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
56 public enum DialogResult : int64 { cancel, yes, no, ok };
58 public class MouseButtons
61 bool left:1, right:1, middle:1;
64 public struct SizeAnchor
67 bool isClientW, isClientH;
72 #define SNAPDOWN(x, d) \
75 if(x < 0) x -= ((d) - Abs(x) % (d)); else x -= x % (d); \
78 #define SNAPUP(x, d) \
81 if(x > 0) x += ((d) - Abs(x) % (d)); else x += x % (d); \
84 /*static */define MAX_DIRTY_BACK = 10;
86 /////////////////////////////////////////////////////////////////////////////
87 ////////// EXTENT MANIPULATION //////////////////////////////////////////////
88 /////////////////////////////////////////////////////////////////////////////
90 #define ACCESS_ITEM(l, id) \
93 #define FASTLIST_LOOP(l, v) \
94 for(v = (BoxItem)l.first; v; v = (BoxItem)v.next)
96 #define FASTLIST_LOOPN(l, v, n) \
97 for(v = (BoxItem)l.first, n = (BoxItem)(v ? v.next : null); v; v = (BoxItem)next, n = (BoxItem)(v ? v.next : null))
100 #define ACCESS_ITEM(l, id) \
101 ((FastItem)(((id) == -1) ? null : (((byte *)((l).items)) + (id) * (l).itemSize)))
103 #define FASTLIST_LOOP(l, v) \
104 for(v = (void *)ACCESS_ITEM((l), (l).first); v; v = (void *)ACCESS_ITEM((l), v.next))
106 #define FASTLIST_LOOPN(l, v, n) \
107 for( v = (void *)ACCESS_ITEM((l), (l).first), \
108 n = v ? ((void *)ACCESS_ITEM((l), v.next)): null; \
109 v; v = n, n = n ? (void *)ACCESS_ITEM((l), n.next) : null)
112 private class FastItem : struct
117 private struct FastList
122 int count, size, itemSize;
129 first = last = free = -1;
137 // FASTLIST_LOOPN(this, item, next) { Delete(item); };
140 FastItem Add(uint itemSize)
143 if(free == -1 || !size)
150 newSize = (size + (size >> 1));
151 items = (FastItem)renew items byte[newSize * itemSize];
156 this.itemSize = itemSize;
157 items = (FastItem)new byte[newSize * itemSize];
160 for(c = size; c<newSize-1; c++)
162 ACCESS_ITEM(this, c).prev = -1;
163 ACCESS_ITEM(this, c).next = c+1;
165 ACCESS_ITEM(this, c).prev = -1;
166 ACCESS_ITEM(this, c).next = -1;
170 item = ACCESS_ITEM(this, free);
173 ACCESS_ITEM(this, item.prev).next = free;
183 void Delete(FastItem item)
186 ACCESS_ITEM(this, item.prev).next = item.next;
188 ACCESS_ITEM(this, item.next).prev = item.prev;
190 if(ACCESS_ITEM(this, first) == item)
192 if(ACCESS_ITEM(this, last) == item)
197 free = ((byte *)item - (byte *)items) / itemSize;
205 free = first = last = -1;
209 private class BoxItem : Item //FastItem
214 public /*private */struct Extent : OldList //FastList
223 //BoxItem extentBox = (BoxItem)Add(sizeof(class BoxItem));
224 Add(BoxItem { box = box });
227 void Copy(Extent source)
233 //FASTLIST_LOOP(source, extentBox)
234 for(extentBox = (BoxItem)source.first; extentBox; extentBox = (BoxItem)extentBox.next)
235 AddBox(extentBox.box);
238 void IntersectBox(Box box)
240 // Clip all boxes of extent against inside of the new box
241 BoxItem extentBox, next;
243 //FASTLIST_LOOPN(this, extentBox, next) // Macros still mess up the parser!
244 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
246 next = (BoxItem)extentBox.next;
247 if(box.left > extentBox.box.left) extentBox.box.left = box.left;
248 if(box.top > extentBox.box.top) extentBox.box.top = box.top;
249 if(box.right < extentBox.box.right) extentBox.box.right = box.right;
250 if(box.bottom < extentBox.box.bottom) extentBox.box.bottom = box.bottom;
251 if(extentBox.box.right < extentBox.box.left || extentBox.box.bottom < extentBox.box.top)
256 void ExcludeBox(Box box, Extent temp)
263 for(extentBox = (BoxItem)temp.first; extentBox; extentBox = (BoxItem)extentBox.next)
265 if(extentBox.box.left < box.right && extentBox.box.right > box.left &&
266 extentBox.box.top < box.bottom && extentBox.box.bottom > box.top)
269 if(extentBox.box.top < box.top && extentBox.box.bottom >= box.top)
273 extentBox.box.left, extentBox.box.top,
274 extentBox.box.right, Min(extentBox.box.bottom, box.top -1)
280 if(extentBox.box.bottom > box.bottom && extentBox.box.top <= box.bottom)
284 extentBox.box.left, Max(extentBox.box.top,box.bottom +1),
285 extentBox.box.right, extentBox.box.bottom
291 if(extentBox.box.bottom >= box.top && extentBox.box.top <= box.bottom)
294 if(extentBox.box.left < box.left && extentBox.box.right >= box.left)
298 extentBox.box.left, Max(extentBox.box.top, box.top),
299 Min(extentBox.box.right, box.left-1), Min(extentBox.box.bottom, box.bottom)
305 if(extentBox.box.right > box.right && extentBox.box.left <= box.right)
309 Max(extentBox.box.left, box.right+1), Max(extentBox.box.top, box.top),
310 extentBox.box.right, Min(extentBox.box.bottom, box.bottom)
318 AddBox(extentBox.box);
324 void UnionBox(Box box, Extent temp)
326 BoxItem extentBox, next;
328 // First pass: check if this box is not already covered by one of the extent's box
329 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
331 if(extentBox.box.left <= box.left && extentBox.box.right >= box.right &&
332 extentBox.box.top <= box.top && extentBox.box.bottom >= box.bottom)
339 // Second pass: only keep boxes not completely covered in the new box
340 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
342 next = (BoxItem)extentBox.next;
343 if(extentBox.box.left >= box.left && extentBox.box.right <= box.right &&
344 extentBox.box.top >= box.top && extentBox.box.bottom <= box.bottom)
348 // Add the exclusion to the extent
349 ExcludeBox(box, temp);
352 if(box.bottom >= box.top && box.right >= box.left)
354 // Optimization: if the resulting boxes touch, add them smarter
355 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
357 if(box.top == extentBox.box.top && box.bottom == extentBox.box.bottom)
359 if(Abs(box.right - extentBox.box.left) <= 1)
361 extentBox.box.left = box.left;
364 else if(Abs(box.left - extentBox.box.right) <= 1)
366 extentBox.box.right = box.right;
370 else if(box.left == extentBox.box.left && box.right == extentBox.box.right)
372 if(Abs(box.bottom - extentBox.box.top) <= 1)
374 extentBox.box.top = box.top;
377 else if(Abs(box.top - extentBox.box.bottom) <= 1)
379 extentBox.box.bottom = box.bottom;
391 void Union(Extent b, Extent temp)
395 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
396 UnionBox(extentBox.box, temp);
399 void Intersection(Extent b, Extent temp, Extent temp2, Extent temp3)
406 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
409 temp2.IntersectBox(extentBox.box);
416 void Exclusion(Extent b, Extent temp)
419 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
420 ExcludeBox(extentBox.box, temp);
423 void Offset(int x, int y)
426 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
428 extentBox.box.left += x;
429 extentBox.box.top += y;
430 extentBox.box.right += x;
431 extentBox.box.bottom += y;
436 private define MINIMIZED_WIDTH = 160;
437 private define CASCADE_SPACE = 16;
439 // namespace Windows;
441 private class ScrollFlags
443 bool snapX:1, snapY:1, dontHide:1;
446 public class BorderBits { public: bool contour:1, fixed:1, sizable:1, deep:1, bevel:1, thin:1; };
448 class WindowBits : BorderBits
450 BorderBits borderBits:6:0;
451 bool hidden:1, isActiveClient:1, hasHorzScroll:1, hasVertScroll:1, stayOnTop:1, modal:1, isDefault:1, inactive:1, isRemote:1, drawBehind:1;
452 bool interim:1, tabCycle:1, noCycle:1, dontScrollHorz:1, dontScrollVert:1, hasMaximize:1, hasMinimize:1, hasClose:1;
453 bool embedded:1, hasMenuBar:1, isDocument:1, showInTaskBar:1, hasStatusBar:1, nonClient:1, clickThrough:1;
456 public enum BorderStyle : BorderBits
459 contour = BorderBits { contour = true },
460 fixed = BorderBits { fixed = true } | contour,
461 sizable = BorderBits { sizable = true } | fixed,
462 thin = BorderBits { fixed = true, thin = true } | contour,
463 sizableThin = BorderBits { sizable = true } | thin,
464 deep = BorderBits { deep = true },
465 bevel = BorderBits { bevel = true },
466 sizableDeep = sizable|deep,
467 sizableBevel = sizable|bevel,
468 fixedDeep = fixed|deep,
469 fixedBevel = fixed|bevel,
470 deepContour = deep|contour
473 public enum CreationActivationOption
475 activate, flash, doNothing
478 public enum WindowState { normal, minimized, maximized };
480 private class ResPtr : struct
487 private class HotKeySlot : struct
489 HotKeySlot prev, next;
494 public struct TouchPointerInfo
498 float size, pressure;
501 public enum TouchPointerEvent { move, up, down, pointerUp, pointerDown };
506 class_data const char * icon;
508 class_default_property caption;
509 // class_initialize GuiApplication::Initialize;
510 class_designer FormDesigner;
511 class_property const char * icon
513 set { class_data(icon) = value; }
514 get { return class_data(icon); }
519 bool switchMode = true;
520 #if defined(__ANDROID__)
525 guiApp.Initialize(switchMode);
527 if(guiApp && guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
529 if(_vTbl == ((subclass(Window))_class).pureVTbl)
531 _vTbl = _class._vTbl;
533 else if(_vTbl != _class._vTbl)
536 for(m = 0; m < _class.vTblSize; m++)
538 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
539 _vTbl[m] = _class._vTbl[m];
544 //tempExtents[0] = { /*first = -1, last = -1, free = -1*/ };
545 //tempExtents[1] = { /*first = -1, last = -1, free = -1*/ };
546 //tempExtents[2] = { /*first = -1, last = -1, free = -1*/ };
547 //tempExtents[3] = { /*first = -1, last = -1, free = -1*/ };
551 // caption = CopyString(class.name);
553 children.offset = (byte*)&prev - (byte*)this;
554 childrenOrder.circ = true;
555 childrenCycle.circ = true;
557 maxSize = Size { MAXINT, MAXINT };
561 //style.isActiveClient = true;
564 modifyVirtArea = true;
565 manageDisplay = true;
566 nativeDecorations = true;
568 // scrollFlags = ScrollFlags { snapX = true, snapY = true };
569 sbStep.x = sbStep.y = 8;
571 if(guiApp) // dynamic_cast<GuiApplication>(thisModule)
573 cursor = guiApp.GetCursor(arrow);
574 property::parent = guiApp.desktop;
586 int i, lockCount = guiApp.lockMutex.lockCount;
587 for(i = 0; i < lockCount; i++)
588 guiApp.lockMutex.Release();
590 for(i = 0; i < lockCount; i++)
591 guiApp.lockMutex.Wait();
596 stopwatching(parent, font);
597 if(parent.activeChild == this)
598 parent.activeChild = null;
599 if(parent.activeClient == this)
600 parent.activeClient = null;
605 // Prevent destructor from being called again...
611 /////////////////////////////////
614 OldLink slave = master.slaves.FindLink(this);
615 master.slaves.Delete(slave);
622 parent.childrenCycle.Remove(cycle);
624 parent.childrenOrder.Remove(order);
625 parent.children.Remove(this);
630 /////////////////////////////////
632 while((ptr = resources.first))
635 resources.Delete(ptr);
642 for(child = children.first; child; child = child.next)
644 // child.stopwatching(this, font);
646 eInstance_StopWatching(this, __ecereProp___ecereNameSpace__ecere__gui__Window_font, child);
647 // Don't want property here
648 *&child.parent = null;
651 while((slave = slaves.first))
653 // Don't want property here
654 *&((Window)slave.data).master = null;
655 slaves.Delete(slave);
658 // Because we do a decref in DestroyEx...
666 // Why was this commented?
667 //if(this != guiApp.desktop)
680 if(((subclass(Window))_class).pureVTbl)
682 if(_vTbl == _class._vTbl)
684 _vTbl = ((subclass(Window))_class).pureVTbl;
689 for(m = 0; m < _class.vTblSize; m++)
691 if(_vTbl[m] == _class._vTbl[m])
692 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
696 if(_vTbl == ((subclass(Window))_class).pureVTbl || _vTbl == _class._vTbl)
699 dirtyArea.Free(null);
700 renderArea.Free(null);
701 overRenderArea.Free(null);
702 clipExtent.Free(null);
703 scrollExtent.Free(null);
704 dirtyBack.Free(null);
708 tempExtents[0].Free(null);
709 tempExtents[1].Free(null);
710 tempExtents[2].Free(null);
711 tempExtents[3].Free(null);
718 //#if !defined(ECERE_VANILLA)
719 const char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
721 if(this == activeDesigner)
725 const char * name = property::name;
726 return name ? name : "";
731 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
732 bool OnGetDataFromString(const char * string)
734 FormDesigner designer = (FormDesigner)activeDesigner.classDesigner;
737 if(!strcmp(string, "this") || !strcmp(string, designer.form.name))
738 this = designer.form;
739 else if(!strcmpi(string, "(Desktop)"))
740 this = activeDesigner;
742 return activeDesigner.FindObject(&this, string);
748 // --- Window updates system ---
750 // Setup a bitmap for Redrawing on client area of Window
751 Surface Redraw(Box box)
753 Surface surface = null;
755 Box clientArea = this.clientArea;
759 mox.left -= clientStart.x;
760 mox.top -= clientStart.y;
761 mox.right -= clientStart.x;
762 mox.bottom -= clientStart.y;
764 mox.Clip(clientArea);
765 // mox.ClipOffset(against, scrolledPos.x, scrolledPos.y);
767 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && mox.right >= mox.left && mox.bottom >= mox.top)
769 int x = absPosition.x + clientStart.x;
770 int y = absPosition.y + clientStart.y;
771 if(rootWindow.nativeDecorations && rootWindow.windowHandle && !is3D)
773 x -= rootWindow.clientStart.x;
774 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
776 if(!guiApp.fullScreenMode || is3D)
778 x -= rootWindow.absPosition.x;
779 y -= rootWindow.absPosition.y;
783 int dx = rootWindow.parent.parent.clientStart.x;
784 int dy = rootWindow.parent.parent.clientStart.y;
785 if(!rootWindow.parent.nativeDecorations)
787 dx += rootWindow.parent.clientStart.x;
788 dy += rootWindow.parent.clientStart.y;
802 surface = display.GetSurface(x, y, mox);
805 surface.width = clientSize.w;
806 surface.height = clientSize.h;
812 // Setup a bitmap for Redrawing on full Window
813 Surface RedrawFull(Box box)
815 Surface surface = null;
823 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && box.right >= box.left && box.bottom >= box.top)
825 int x = absPosition.x;
826 int y = absPosition.y;
827 if(rootWindow.nativeDecorations && rootWindow.windowHandle && !is3D)
829 x -= rootWindow.clientStart.x;
830 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
832 if(!guiApp.fullScreenMode || is3D)
834 x -= rootWindow.absPosition.x;
835 y -= rootWindow.absPosition.y;
838 int dx = rootWindow.parent.parent.clientStart.x;
839 int dy = rootWindow.parent.parent.clientStart.y;
840 if(!rootWindow.parent.nativeDecorations)
842 dx += rootWindow.parent.clientStart.x;
843 dy += rootWindow.parent.clientStart.y;
857 surface = display.GetSurface(x, y, mox);
860 surface.width = size.w;
861 surface.height = size.h;
867 void FigureCaption(char * caption)
869 Window activeClient = null;
873 strcpy(caption, this.caption);
874 if(style.isDocument || fileName)
876 if(caption[0]) strcat(caption, " - ");
878 strcat(caption, fileName);
882 sprintf(title, "Untitled %d", documentID);
883 strcat(caption, title);
886 strcat(caption, " *");
891 for(activeClient = this.activeClient; activeClient && !((BorderBits)activeClient.borderStyle).fixed; activeClient = activeClient.activeClient);
893 if(activeClient && activeClient.state == maximized)
895 if(activeClient.caption)
897 if(caption[0]) strcat(caption, " - ");
898 strcat(caption, activeClient.caption);
900 if(activeClient.style.isDocument || activeClient.fileName)
902 if(caption[0]) strcat(caption, " - ");
903 strcat(caption, "[");
904 if(activeClient.fileName)
905 strcat(caption, activeClient.fileName);
909 sprintf(title, "Untitled %d", activeClient.documentID);
910 strcat(caption, title);
912 if(activeClient.modifiedDocument)
913 strcat(caption, " *");
914 strcat(caption, "]");
919 // Code for returning dirty from ScrollDisplay:
921 for(d = 0; d<scrollExtent.count; d++)
923 Box * box = &scrollExtent.boxes[d];
929 Min(box.right, box.left-scroll.x),box.bottom
931 dirtyArea.UnionBox(update);
937 Max(box.left, box.right-scroll.x), box.top,
938 box.right, box.bottom
940 dirtyArea.UnionBox(update);
948 box.right, Min(box.bottom, box.top-scroll.y),
950 dirtyArea.UnionBox(update);
956 box.left, Max(box.top, box.bottom-scroll.y),
957 box.right, box.bottom
959 dirtyArea.UnionBox(update);
964 void UpdateDecorations(void)
966 // TODO: *** TEMPORARY HACK ***
973 Update({ -clientStart.x, -clientStart.y, -clientStart.x + size.w-1, 0 });
975 Update({ -clientStart.x, clientSize.h, -clientStart.x + size.w-1, -clientStart.y + size.h-1 });
977 Update({ -clientStart.x,0, -1, clientSize.h-1 });
979 Update({ clientSize.w, 0, -clientStart.x + size.w-1, clientSize.h-1 });
982 // Returns w & h for Position
983 void ComputeAnchors(Anchor anchor, SizeAnchor sizeAnchor, int *ox, int *oy, int *ow, int *oh)
985 Window parent = this.parent ? this.parent : guiApp.desktop;
986 int xOffset = 0, yOffset = 0;
987 int vpw = parent ? parent.clientSize.w : 0;
988 int vph = parent ? parent.clientSize.h : 0;
989 int pw = parent ? parent.clientSize.w : 0;
990 int ph = parent ? parent.clientSize.h : 0;
991 int w = sizeAnchor.size.w, h = sizeAnchor.size.h;
992 int x = anchor.left.distance, y = anchor.top.distance;
993 float ex = 0, ey = 0;
994 MinMaxValue ew = 0, eh = 0;
996 float cascadeW, cascadeH;
998 int tilingW, tilingH, tilingSplit, tilingLastH = 0;
999 int addX = 0, addY = 0;
1001 if(parent && rootWindow == this && guiApp && guiApp.interfaceDriver)
1003 Window masterWindow = this;
1004 Box box { addX, addY, addX + vpw - 1, addY + vph - 1 };
1007 if(master == guiApp.desktop)
1008 masterWindow = guiApp.desktop.activeChild;
1010 masterWindow = master.rootWindow;
1011 if(!masterWindow) masterWindow = this;
1013 guiApp.interfaceDriver.GetScreenArea(masterWindow, box);
1014 if((anchor.left.type == offset && anchor.right.type == offset) || anchor.left.type == none)
1017 pw = vpw = box.right - box.left + 1;
1019 if((anchor.top.type == offset && anchor.bottom.type == offset) || anchor.top.type == none)
1022 ph = vph = box.bottom - box.top + 1;
1038 vpw = pw = parent.size.w;
1039 vph = ph = parent.size.h;
1041 else if(!style.fixed /*|| style.isDocument*/)
1043 if(!style.dontScrollHorz && parent.scrollArea.w) vpw = parent.scrollArea.w;
1044 if(!style.dontScrollVert && parent.scrollArea.h) vph = parent.scrollArea.h;
1046 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
1049 Desktop3D_FixSize(&pw, &ph);
1050 Desktop3D_FixSize(&vpw, &vph);
1053 if(pw < skinMinSize.w) pw = skinMinSize.w;
1054 if(ph < skinMinSize.h) ph = skinMinSize.h;
1055 if(vpw < skinMinSize.w) vpw = skinMinSize.w;
1056 if(vph < skinMinSize.h) vph = skinMinSize.h;
1058 // TODO: Must fix what we're snapping
1061 if(anchor.left.type)
1063 SNAPUP(x, textCellW);
1065 else if(anchor.right.type)
1067 SNAPDOWN(x, textCellW);
1072 SNAPUP(y, textCellH);
1074 else if(anchor.bottom.type)
1076 SNAPDOWN(y, textCellH);
1080 // This is required to get proper initial decoration size using native decorations on Windows
1081 #if defined(__WIN32__)
1082 if(nativeDecorations && windowHandle && guiApp && guiApp.interfaceDriver && !visible)
1083 guiApp.interfaceDriver.PositionRootWindow(this, x, y, Max(1, size.w), Max(1, size.h), true, true);
1085 GetDecorationsSize(&ew, &eh);
1087 if(anchor.left.type >= cascade && (state == normal /*|| state == Hidden*/))
1089 // Leave room for non client windows (eventually dockable panels)
1091 int loX = 0, loY = 0, hiX = pw, hiY = ph;
1092 for(win = parent.children.first; win; win = win.next)
1094 if(!win.nonClient && !win.isActiveClient && win.visible)
1096 Size size = win.size;
1097 Point pos = win.position;
1098 int left = pos.x, top = pos.y;
1099 int right = pos.x + size.w, bottom = pos.y + size.h;
1100 if(win.size.w > win.size.h)
1103 loY = Max(loY, bottom);
1104 else if(top > ph - ph / 4)
1105 hiY = Min(hiY, top);
1110 loX = Max(loX, right);
1111 else if(left > pw - pw / 4)
1112 hiX = Min(hiX, left);
1121 if(parent.sbv && !parent.sbv.style.hidden)
1122 pw += guiApp.currentSkin.VerticalSBW();
1123 if(parent.sbh && !parent.sbh.style.hidden)
1124 ph += guiApp.currentSkin.HorizontalSBH();
1126 if(anchor.left.type == cascade)
1128 w = (int)(pw * 0.80);
1129 h = (int)(ph * 0.80);
1131 else if(anchor.left.type >= vTiled)
1136 numTiling = parent.numPositions - parent.numIcons;
1137 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1138 if(anchor.left.type == vTiled)
1142 tilingH = (int)sqrt(numTiling);
1143 tilingW = numTiling / tilingH;
1146 tilingH = tilingW = 0;
1152 tilingW = (int)sqrt(numTiling);
1153 tilingH = numTiling / tilingW;
1156 tilingH = tilingW = 0;
1159 leftOver = numTiling - tilingH * tilingW;
1162 tilingSplit = (tilingW - leftOver) * tilingH;
1163 tilingLastH = tilingH+1;
1166 tilingSplit = numTiling;
1168 if(tilingW && tilingH)
1170 if(positionID >= tilingSplit)
1172 x = xOffset + pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
1173 y = yOffset + ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
1174 x2 = xOffset + pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
1175 y2 = yOffset + ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
1179 x = xOffset + pw * (positionID / tilingH) / tilingW;
1180 y = yOffset + ph * (positionID % tilingH) / tilingH;
1181 x2 = xOffset + pw * (positionID / tilingH + 1) / tilingW;
1182 y2 = yOffset + ph * ((positionID % tilingH) + 1) / tilingH;
1187 // How can this happen? From ec2 parsing test
1195 SNAPDOWN(x, textCellW);
1196 SNAPDOWN(y, textCellH);
1197 SNAPDOWN(x2, textCellW);
1198 SNAPDOWN(y2, textCellH);
1206 if(sizeAnchor.isClientW) w += ew;
1207 if(sizeAnchor.isClientH) h += eh;
1209 if(anchor.left.type == offset)
1210 x = anchor.left.distance;
1211 else if(anchor.left.type == relative)
1212 x = (anchor.left.percent < 0) ? ((int)(vpw * anchor.left.percent - 0.5)) : (int)(vpw * anchor.left.percent + 0.5);
1213 else if(anchor.right.type == relative)
1214 // ex = (anchor.right.percent < 0) ? ((int)(vpw * anchor.right.percent + 0)) : ((int)(vpw * anchor.right.percent + 0));
1215 ex = (anchor.right.percent < 0) ? ((int)(vpw * (1.0-anchor.right.percent) + 0)) : ((int)(vpw * (1.0-anchor.right.percent) + 0));
1216 else if(anchor.right.type == offset)
1217 ex = vpw - anchor.right.distance;
1219 if(anchor.top.type == offset)
1220 y = anchor.top.distance;
1221 else if(anchor.top.type == relative)
1222 y = (anchor.top.percent < 0) ? ((int)(vph * anchor.top.percent - 0.5)) : ((int)(vph * anchor.top.percent + 0.5));
1223 else if(anchor.bottom.type == relative)
1224 //ey = (anchor.bottom.percent < 0) ? ((int)(vph * anchor.bottom.percent + 0)) : ((int)(vph * anchor.bottom.percent + 0));
1225 ey = (anchor.bottom.percent < 0) ? ((int)(vph * (1.0-anchor.bottom.percent) + 0)) : ((int)(vph * (1.0-anchor.bottom.percent) + 0));
1226 else if(anchor.bottom.type == offset)
1227 ey = vph - anchor.bottom.distance;
1229 if(anchor.left.type && anchor.right.type)
1231 switch(anchor.right.type)
1234 ex = pw * (1.0f-anchor.right.percent);
1235 w = Max((int)(ex + 0.5) - x, 0);
1238 ex = vpw - anchor.right.distance;
1239 w = Max((int)(ex + 0.5) - x, 0);
1243 if(anchor.top.type && anchor.bottom.type)
1245 switch(anchor.bottom.type)
1248 ey = ph * (1.0f-anchor.bottom.percent);
1249 h = Max((int)(ey + 0.5) - y, 0);
1252 ey = vph - anchor.bottom.distance;
1253 h = Max((int)(ey + 0.5) - y, 0);
1262 if(state == normal /*|| state == Hidden*/)
1264 bool addSbV = false, addSbH = false;
1266 if(sizeAnchor.isClientW || (anchor.left.type && anchor.right.type)) w = Max(w, 1); else w = Max(w, 0);
1267 if(sizeAnchor.isClientH || (anchor.top.type && anchor.bottom.type)) h = Max(h, 1); else h = Max(h, 0);
1269 w = Max(w, minSize.w);
1270 h = Max(h, minSize.h);
1271 w = Min(w, maxSize.w);
1272 h = Min(h, maxSize.h);
1274 if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
1276 if(w) w -= guiApp.currentSkin.VerticalSBW();
1279 if((sizeAnchor.isClientH || !h || (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
1281 if(h) h -= guiApp.currentSkin.HorizontalSBH();
1285 if(!OnResizing(&w, &h))
1291 if((addSbV)) // || reqScrollArea.h > h) && sbv)
1292 w += guiApp.currentSkin.VerticalSBW();
1293 if((addSbH)) // || reqScrollArea.w > w) && sbh)
1294 h += guiApp.currentSkin.HorizontalSBH();
1296 w = Max(w, skinMinSize.w);
1297 h = Max(h, skinMinSize.h);
1310 SNAPDOWN(w, textCellW);
1311 SNAPDOWN(h, textCellH);
1314 if(anchor.left.type == cascade && (state == normal /*|| state == Hidden*/))
1316 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1319 (pw - w) / CASCADE_SPACE,
1320 (ph - h) / CASCADE_SPACE);
1326 cascW = (pw - w) / (numCascade-1);
1327 cascH = (ph - h) / (numCascade-1);
1328 SNAPDOWN(cascW, textCellW);
1329 SNAPDOWN(cascH, textCellH);
1330 cascadeW = (float)cascW;
1331 cascadeH = (float)cascH;
1335 numCascade = Max(numCascade, 2);
1336 cascadeW = (float)(pw - w) / (numCascade-1);
1337 cascadeH = (float)(ph - h) / (numCascade-1);
1340 x = (int)((positionID % numCascade) * cascadeW) + xOffset;
1341 y = (int)((positionID % numCascade) * cascadeH) + yOffset;
1343 else if(anchor.left.type < vTiled)
1345 if(!anchor.left.type || anchor.horz.type == middleRelative)
1347 if(!anchor.right.type)
1349 if(anchor.horz.type == middleRelative)
1350 x = (int)(vpw * (0.5 + anchor.horz.percent) - w / 2);
1352 x = vpw / 2 + anchor.horz.distance - w / 2;
1358 // case A_EDGE: x = x - w; break;
1360 if(!anchor.top.type || anchor.vert.type == middleRelative)
1362 if(!anchor.bottom.type)
1364 if(anchor.vert.type == middleRelative)
1365 y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
1367 y = vph / 2 + anchor.vert.distance - h / 2;
1373 // case A_EDGE: y = y - h; break;
1376 if((state == normal /*|| state == Hidden*/) && !OnMoving(&x, &y, w, h))
1384 SNAPDOWN(x, textCellW);
1385 SNAPDOWN(y, textCellH);
1397 if(anchored && style.fixed && style.isActiveClient)
1402 void UpdateCaret(bool forceUpdate, bool erase)
1404 static Window lastWindow = null;
1405 static int caretX, caretY, caretSize;
1407 if(guiApp && guiApp.caretOwner == this)
1409 int x = caretPos.x - scroll.x;
1410 int y = caretPos.y - scroll.y;
1412 if((erase || this.caretSize) &&
1413 x >= clientArea.left && x <= clientArea.right &&
1414 y >= clientArea.top && y <= clientArea.bottom)
1418 guiApp.interfaceDriver.SetCaret(
1419 x + absPosition.x + clientStart.x,
1420 y + absPosition.y + clientStart.y, this.caretSize);
1421 guiApp.caretEnabled = true;
1423 if(erase || lastWindow != this || caretX != x || caretY != y || caretSize != this.caretSize || forceUpdate)
1427 if(lastWindow != this)
1429 updateBox.left = x + 1;
1431 updateBox.right = x + 2;
1432 updateBox.bottom = y + this.caretSize - 1;
1436 updateBox.left = Min(x + 1, caretX + 1);
1437 updateBox.top = Min(y, caretY);
1438 updateBox.right = Max(x + 2, caretX + 2);
1439 updateBox.bottom = Max(y + this.caretSize - 1, caretY + caretSize - 1);
1442 guiApp.caretOwner.Update(updateBox);
1449 caretSize = this.caretSize;
1455 guiApp.interfaceDriver.SetCaret(0,0,0);
1456 guiApp.caretEnabled = false;
1462 void SetPosition(int x, int y, int w, int h, bool modifyArea, bool modifyThisArea, bool modifyClientArea)
1467 scrolledPos.x = position.x = x;
1468 scrolledPos.y = position.y = y;
1470 clientSize.w = size.w = w;
1471 clientSize.h = size.h = h;
1473 if(parent && !style.nonClient)
1475 //if(!style.fixed || style.isDocument)
1477 if(!style.dontScrollHorz) scrolledPos.x -= parent.scroll.x;
1478 if(!style.dontScrollVert) scrolledPos.y -= parent.scroll.y;
1482 clientStart.x = clientStart.y = 0;
1484 SetWindowArea(&clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1486 //if(!activeClient || activeClient.state != maximized)
1487 if(!noAutoScrollArea)
1489 // Check if scroll area must be modified
1490 if(guiApp && !guiApp.modeSwitching && (sbv || sbh))
1492 bool foundChild = false;
1494 int cw = clientSize.w;// + ((!sbv || sbv.range > 1) ? guiApp.currentSkin.VerticalSBW() : 0);
1495 int ch = clientSize.h;// + ((!sbh || sbh.rangw > 1) ? guiApp.currentSkin.HorizontalSBH() : 0);
1496 for(child = children.first; child; child = child.next)
1498 if(child.modifyVirtArea && !child.style.hidden && child.created && /*!child.anchored &&*/
1499 !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1501 if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == offset)
1502 w = Max(w, child.position.x + child.size.w);
1503 else if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == none)
1504 w = Max(w, Max(child.position.x, 0) + child.size.w);
1505 if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == offset)
1506 h = Max(h, child.position.y + child.size.h);
1507 else if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == none)
1508 h = Max(h, Max(child.position.y, 0) + child.size.h);
1513 if(foundChild && (w > cw || h > ch))
1515 //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
1517 int stepX = sbStep.x, stepY = sbStep.y;
1518 // Needed to make snapped down position match the skin's check of client area
1519 // against realvirtual
1522 SNAPDOWN(stepX, textCellW);
1523 SNAPDOWN(stepY, textCellH);
1524 stepX = Max(stepX, textCellW);
1525 stepY = Max(stepY, textCellH);
1527 if(scrollFlags.snapX)
1529 if(scrollFlags.snapY)
1532 reqScrollArea.w = w;
1533 reqScrollArea.h = h;
1536 else if(reqScrollArea.w || reqScrollArea.h)
1538 reqScrollArea.w = 0;
1539 reqScrollArea.h = 0;
1540 SetScrollPosition(0,0);
1545 // Automatic MDI Client Scrolling Area Adjustment
1546 if(parent && !parent.noAutoScrollArea)
1548 if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
1549 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
1551 Window parent = this.parent;
1552 int w = parent.reqScrollArea.w;
1553 int h = parent.reqScrollArea.h;
1555 if(stateAnchor.right.type == none && stateAnchor.left.type == offset)
1556 w = Max(w, position.x + size.w);
1557 else if(stateAnchor.right.type == none && stateAnchor.left.type == none)
1558 w = Max(w, Max(position.x, 0) + size.w);
1559 if(stateAnchor.bottom.type == none && stateAnchor.top.type == offset)
1560 h = Max(h, position.y + size.h);
1561 else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
1562 h = Max(h, Max(position.y, 0) + size.h);
1564 if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
1565 (h > parent.clientSize.h && h > parent.reqScrollArea.h))
1567 /*bool resize = false;
1568 int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
1569 // Needed to make snapped down position match the skin's check of client area
1570 // against realvirtual
1573 SNAPDOWN(stepX, textCellW);
1574 SNAPDOWN(stepY, textCellH);
1575 stepX = Max(stepX, textCellW);
1576 stepY = Max(stepY, textCellH);
1578 if(parent.scrollFlags.snapX)
1580 if(parent.scrollFlags.snapY)
1582 if(parent.reqScrollArea.w != w || parent.reqScrollArea.h != h)
1584 parent.reqScrollArea.w = w;
1585 parent.reqScrollArea.h = h;*/
1587 // parent.UpdateScrollBars(true, true);
1588 parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1589 false, true, true, true, false, false);
1594 GetRidOfVirtualArea();
1598 UpdateScrollBars(modifyThisArea, false);
1599 else if(guiApp.currentSkin)
1602 &clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1604 if(sbv && (scrollFlags.dontHide || sbv.range > 1))
1605 clientSize.w -= guiApp.currentSkin.VerticalSBW();
1606 if(sbh && (scrollFlags.dontHide || sbh.range > 1))
1607 clientSize.h -= guiApp.currentSkin.HorizontalSBH();
1610 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1611 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1613 absPosition = scrolledPos;
1614 if(guiApp && guiApp.driver != null && guiApp.interfaceDriver)
1615 guiApp.interfaceDriver.OffsetWindow(this, &absPosition.x, &absPosition.y);
1617 if(this != guiApp.desktop && parent)
1619 absPosition.x += parent.absPosition.x;
1620 absPosition.y += parent.absPosition.y;
1621 if(!style.nonClient && this != guiApp.desktop)
1623 absPosition.x += parent.clientStart.x;
1624 absPosition.y += parent.clientStart.y;
1628 box = Box { 0, 0, size.w - 1, size.h - 1 };
1633 // Clip against parent's client area
1634 box.ClipOffset(against, scrolledPos.x, scrolledPos.y);
1636 // Compute client area in this window coordinate system
1637 clientArea.left = 0;
1639 clientArea.right = clientSize.w - 1;
1640 clientArea.bottom = clientSize.h - 1;
1642 // Clip against parent's client area
1644 clientArea.ClipOffset(against, scrolledPos.x + clientStart.x, scrolledPos.y + clientStart.y);
1648 //absPosition.x -= parent.clientStart.x;
1649 //absPosition.y -= parent.clientStart.y;
1652 // Adjust all children
1653 for(child = children.first; child; child = child.next)
1654 child.SetPosition(child.position.x, child.position.y, child.size.w, child.size.h, false, true, true);
1656 UpdateCaret(false, false);
1659 void GetRidOfVirtualArea(void)
1661 if(parent && !parent.destroyed && style.fixed &&
1662 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient &&
1663 parent.reqScrollArea.w && parent.reqScrollArea.h)
1665 if(!parent.noAutoScrollArea)
1667 // TODO: Review the logic of all this? Each child is going to reposition the parent?
1671 for(child = children.first; child; child = child.next)
1673 if(child.modifyVirtArea && !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1675 if(child.position.x + child.size.w > parent.clientSize.w + ((!parent.sbv || parent.sbv.style.hidden) ? 0 : guiApp.currentSkin.VerticalSBW()) ||
1676 child.position.y + child.size.h > parent.clientSize.h + ((!parent.sbh || parent.sbh.style.hidden) ? 0 : guiApp.currentSkin.HorizontalSBH()))
1686 Window parent = this.parent;
1688 parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1689 false, true, true, true, false, false);
1691 parent.SetScrollArea(0,0,true);
1692 parent.SetScrollPosition(0,0);
1698 public void ExternalPosition(int x, int y, int w, int h)
1700 Position(x, y, w, h, false, true, true, true, false, false);
1703 // (w, h): Full window size
1704 bool Position(int x, int y, int w, int h, bool force, bool processAnchors, bool modifyArea, bool updateScrollBars, bool thisOnly, bool changeRootWindow)
1706 bool result = false;
1707 int oldCW = clientSize.w, oldCH = clientSize.h;
1708 bool clientResized, windowResized, windowMoved;
1710 //bool realResized = size.w != w || size.h != h;
1712 // TOCHECK: This wasn't in ecere.dll
1713 //if(!parent) return true;
1714 if(destroyed) return false;
1716 windowMoved = position.x != x || position.y != y || force;
1718 // windowResized = realResized || force;
1719 windowResized = size.w != w || size.h != h || force;
1721 if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
1727 scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
1728 scrolledPos.x - parent.clientStart.x + this.box.right,
1729 scrolledPos.y - parent.clientStart.y + this.box.bottom
1735 Box box { scrolledPos.x + this.box.left, scrolledPos.y + this.box.top, scrolledPos.x + this.box.right, scrolledPos.y + this.box.bottom};
1740 SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
1742 clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
1743 if(clientResized && this == rootWindow && nativeDecorations && rootWindow.windowHandle)
1744 windowResized = true;
1746 if(display && rootWindow != this)
1749 if(guiApp && guiApp.windowMoving)
1751 if(guiApp.windowMoving.style.nonClient)
1752 guiApp.windowMoving.parent.SetMouseRangeToWindow();
1754 guiApp.windowMoving.parent.SetMouseRangeToClient();
1764 // Buttons bitmap resources crash if we do this while switching mode
1765 if(!guiApp || !guiApp.modeSwitching)
1768 // Process Anchored Children
1772 for(child = children.first; child; child = child.next)
1775 ((child.stateAnchor.left.type != offset ||
1776 child.stateAnchor.top.type != offset ||
1777 child.stateAnchor.right.type != none ||
1778 child.stateAnchor.bottom.type != none) ||
1779 child.state == maximized || child.state == minimized))
1781 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1783 // child.Position(x, y, w, h, false, true, true, true, false);
1784 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1785 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1791 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1792 //if(updateScrollBars)
1794 OnResize(clientSize.w, clientSize.h);
1796 if((clientResized || windowMoved) && created)
1797 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1799 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1801 Window master = guiApp.interimWindow.master;
1802 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1805 if(rootWindow == this && !is3D)
1809 x -= guiApp.desktop.absPosition.x;
1810 y -= guiApp.desktop.absPosition.y;
1812 //guiApp.Log("Position %s\n", caption);
1815 if(windowResized || windowMoved)
1816 if(display && !display.flags.memBackBuffer && changeRootWindow)
1817 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1819 if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved))
1820 for(child = parent.children.first; child && child != this; child = child.next)
1821 if(child.rootWindow)
1822 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1827 if(windowMoved || windowResized)
1829 display.Lock(true /*false*/);
1832 display.Position(absPosition.x, absPosition.y);
1833 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1836 // result = realResized ? display.Resize(size.w, size.h) : true;
1837 if(nativeDecorations && rootWindow.windowHandle)
1839 int w = clientSize.w, h = clientSize.h;
1840 if(hasMenuBar) h += skinMenuHeight;
1841 if(hasStatusBar) h += statusBarHeight;
1842 if(sbv && sbv.visible) w += sbv.size.w;
1843 if(sbh && sbh.visible) h += sbh.size.h;
1844 result = manageDisplay ? display.Resize(w, h) : true;
1847 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1851 else if(clientResized)
1853 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1856 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1860 if(windowMoved || windowResized)
1865 if(guiApp.driver && changeRootWindow && windowHandle)
1867 if(windowResized || windowMoved)
1868 if(!display || display.flags.memBackBuffer)
1869 guiApp.interfaceDriver.PositionRootWindow(this,
1870 x, y, w, h, windowMoved, windowResized);
1871 guiApp.interfaceDriver.UpdateRootWindow(this);
1873 for(child = children.first; child; child = child.next)
1875 if(child.is3D && child.created)
1877 // Copy Display Content
1878 child.display.displaySystem = display.displaySystem;
1879 child.display.window = display.window;
1880 child.display.current = display.current;
1881 child.display.width = display.width;
1882 child.display.height = display.height;
1883 child.display.driverData = display.driverData;
1884 child.display.mutex = null;
1895 void UpdateScrollBars(bool flag, bool fullThing)
1898 bool resizeH = false, resizeV = false;
1899 bool scrolled = false;
1900 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1901 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1903 if(destroyed) return;
1904 if(guiApp.currentSkin)
1906 MinMaxValue cw = 0, ch = 0;
1907 bool sbvVisible = false, sbhVisible = false;
1908 int rangeH = 0, rangeV = 0;
1909 int positionH = 0, positionV;
1911 // First get client area with no respect to scroll bars
1916 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1918 if(scrollFlags.dontHide)
1921 cw -= guiApp.currentSkin.VerticalSBW();
1923 ch -= guiApp.currentSkin.HorizontalSBH();
1925 // Update the scrollbar visibility
1931 sbh.disabled = rangeH <= 1;
1932 if(sbh.style.hidden)
1942 sbv.disabled = rangeV <= 1;
1943 if(sbv.style.hidden)
1951 int oldHRange = sbh ? sbh.range : 0;
1952 int oldVRange = sbv ? sbv.range : 0;
1953 // Then start off with horizontal scrollbar range
1956 positionH = sbh.thumbPosition;
1963 SBSetTotal(sbh, rvw);
1966 ch -= guiApp.currentSkin.HorizontalSBH();
1969 // Do the same for vertical scrollbar
1972 positionV = sbv.thumbPosition;
1978 SBSetTotal(sbv, rvh);
1982 cw -= guiApp.currentSkin.VerticalSBW();
1983 // Maybe we need to set the range on the horizontal scrollbar again
1991 SBSetTotal(sbh, rvw);
1992 //sbh.Action(setRange, positionH, 0);
1993 if(rangeH <= 1 && sbh.range > 1)
1995 ch -= guiApp.currentSkin.HorizontalSBH();
2001 SBSetTotal(sbv, rvh);
2003 //sbv.Action(setRange, positionV, 0);
2008 if(sbh && sbh.range != oldHRange) sbh.Action(setRange, positionH, 0);
2009 if(sbv && sbv.range != oldVRange) sbv.Action(setRange, positionV, 0);
2012 // Update the scrollbar visibility
2013 if(!scrollFlags.dontHide)
2015 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
2019 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
2026 if(guiApp.currentSkin)
2033 sbhVisible = sbh.style.hidden ? true : false;
2035 sbvVisible = sbv.style.hidden ? true : false;
2037 // Do our resize here
2038 if(flag && (resizeH || resizeV) && fullThing)
2040 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
2045 OnResize(clientSize.w, clientSize.h);
2051 sbh.visible = sbhVisible;
2053 sbv.visible = sbvVisible;
2055 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
2056 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
2059 sbh.pageStep = clientSize.w;
2061 sbv.pageStep = clientSize.h;
2063 // Notify doesn't handle setRange anymore... process it here
2066 int positionH = sbh.thumbPosition;
2067 if(scroll.x != positionH)
2069 OnHScroll(setRange, positionH, 0);
2073 SNAPDOWN(positionH, textCellW);
2074 scroll.x = positionH;
2080 int seen = clientSize.w, total = reqScrollArea.w;
2083 if(scrollFlags.snapX)
2084 SNAPDOWN(seen, sbStep.x);
2086 if(!total) total = seen;
2087 range = total - seen + 1;
2089 range = Max(range, 1);
2091 if(x >= range) x = range - 1;
2093 if(scrollFlags.snapX)
2094 SNAPUP(x, sbStep.x);
2098 OnHScroll(setRange, x, 0);
2103 SNAPDOWN(x, textCellW);
2109 int positionV = sbv.thumbPosition;
2110 if(scroll.y != positionV)
2112 OnVScroll(setRange, positionV, 0);
2116 SNAPDOWN(positionV, textCellH);
2117 scroll.y = positionV;
2123 int seen = clientSize.h, total = reqScrollArea.h;
2126 if(scrollFlags.snapY)
2127 SNAPDOWN(seen, sbStep.y);
2129 if(!total) total = seen;
2130 range = total - seen + 1;
2131 range = Max(range, 1);
2133 if(y >= range) y = range - 1;
2135 if(scrollFlags.snapY)
2136 SNAPUP(y, sbStep.y);
2140 OnVScroll(setRange, y, 0);
2145 SNAPDOWN(y, textCellH);
2151 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2154 for(child = children.first; child; child = child.next)
2156 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2159 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2160 child.Position(x, y, w, h, false, true, false, true, false, false);
2167 // Process Scrollbars
2169 if(sbh) // && !sbh.style.hidden
2172 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2173 // Need to set the range again (should improve...) since the scrollbars didn't have
2174 // the right size when UpdateScrollArea set the range on it
2177 sbh.seen = clientSize.w;
2181 if(sbv) // && !sbv.state.hidden
2184 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2185 // Need to set the range again (should improve...) since the scrollbars didn't have
2186 // the right size when UpdateScrollArea set the range on it
2189 sbv.seen = clientSize.h;
2194 // TESTING THIS LOWER
2195 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2198 for(child = children.first; child; child = child.next)
2200 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2203 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2204 child.Position(x, y, w, h, false, true, false, true, false, false);
2210 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2212 SetState(maximized, false, mods);
2216 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2218 SetState(normal, false, mods);
2222 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2224 SetState(minimized, false, mods);
2225 parent.CycleChildren(false, true, false, true);
2229 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2232 // Scroll bar notifications
2233 if(action != setRange)
2235 bool changed = false;
2239 if(scroll.x != position)
2241 OnHScroll(action, position, keyFlags);
2246 SNAPDOWN(position, textCellW);
2248 scroll.x = position;
2252 if(scroll.y != position)
2254 OnVScroll(action, position, keyFlags);
2259 SNAPDOWN(position, textCellH);
2261 scroll.y = position;
2265 bool childMove = false;
2266 for(child = children.first; child; child = child.next)
2268 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2271 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2272 child.Position(x, y, w, h, false, true, false, true, false, false);
2276 // Testing this patch out to solve MDI workspace redraw bugs
2277 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2278 // Scroll offsets to blame?
2282 UpdateCaret(false, false);
2286 // Testing this patch out to solve MDI workspace redraw bugs
2287 for(child = children.first; child; child = child.next)
2289 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2298 Window GetParentMenuBar()
2300 Window menuBarParent;
2301 if(formDesigner) return null;
2302 for(menuBarParent = this ? parent : null; menuBarParent; menuBarParent = menuBarParent.parent)
2304 if(menuBarParent.menuBar) return menuBarParent.menuBar;
2305 if(menuBarParent && !menuBarParent.isActiveClient)
2311 void CreateSystemChildren(void)
2313 Window parent = this;
2314 bool scrollBarChanged = false;
2315 bool hasClose = false, hasMaxMin = false;
2316 Point scroll = this.scroll;
2318 if(state == maximized)
2320 parent = GetParentMenuBar();
2327 if(style.hasClose) hasClose = true;
2328 if(style.hasMaximize || style.hasMinimize)
2335 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2337 sysButtons[2].Destroy(0);
2338 sysButtons[2] = null;
2340 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2342 sysButtons[1].Destroy(0);
2343 sysButtons[1] = null;
2345 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2347 sysButtons[0].Destroy(0);
2348 sysButtons[0] = null;
2351 if(hasClose && parent)
2358 parent, master = this,
2359 inactive = true, nonClient = true, visible = false;
2361 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2367 if(this.parent == guiApp.desktop)
2368 sysButtons[2].hotKey = altF4;
2369 else if(style.isActiveClient)
2370 sysButtons[2].hotKey = ctrlF4;
2371 sysButtons[2].Create();
2374 sysButtons[2].symbol = 'X';
2375 sysButtons[2].disabled = !style.hasClose;
2378 if(hasMaxMin && parent)
2382 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2383 if(state == maximized)
2386 method = RestoreButtonClicked;
2392 method = MaximizeButtonClicked;
2400 parent, master = this,
2401 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2403 sysButtons[1].Create();
2405 sysButtons[1].NotifyClicked = method;
2407 sysButtons[1].symbol = symbol;
2408 sysButtons[1].disabled = !style.hasMaximize;
2411 if(hasMaxMin && parent)
2415 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2416 if (state == minimized)
2419 method = RestoreButtonClicked;
2425 method = MinimizeButtonClicked;
2433 parent, master = this,
2434 hotKey = altM, inactive = true, nonClient = true, visible = false
2436 sysButtons[0].Create();
2438 sysButtons[0].NotifyClicked = method;
2440 sysButtons[0].symbol = symbol;
2441 sysButtons[0].disabled = !style.hasMinimize;
2444 // Create the scrollbars
2445 if(style.hasHorzScroll && !sbh)
2451 direction = horizontal,
2455 snap = scrollFlags.snapX,
2456 NotifyScrolling = ScrollBarNotification
2459 scrollBarChanged = true;
2461 else if(sbh && !style.hasHorzScroll)
2467 if(style.hasVertScroll && !sbv)
2473 direction = vertical,
2477 snap = scrollFlags.snapY,
2478 NotifyScrolling = ScrollBarNotification
2481 scrollBarChanged = true;
2483 else if(sbv && !style.hasVertScroll)
2488 if(scrollBarChanged)
2490 SetScrollLineStep(sbStep.x, sbStep.y);
2491 UpdateScrollBars(true, true);
2495 if(scrollBarChanged)
2497 if(sbh) sbh.thumbPosition = scroll.x;
2498 if(sbv) sbv.thumbPosition = scroll.y;
2502 void UpdateCaption(void)
2504 if(rootWindow == this)
2507 FigureCaption(caption);
2508 if(guiApp.interfaceDriver)
2509 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2511 UpdateDecorations();
2514 if(parent.activeClient == this) // Added this last check
2516 if(parent.rootWindow == parent)
2519 parent.FigureCaption(caption);
2520 if(guiApp.interfaceDriver)
2521 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2524 parent.UpdateCaption();
2526 parent.UpdateDecorations();
2530 void UpdateActiveDocument(Window previous)
2532 Window activeClient = this.activeClient;
2533 Window activeChild = this.activeChild;
2540 activeClient.CreateSystemChildren();
2542 previous.CreateSystemChildren();
2554 // Build window list
2557 Menu windowMenu = menu.FindMenu("Window");
2562 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2564 Window document = cycle.data;
2565 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2567 char name[2048], caption[2048];
2568 document.FigureCaption(caption);
2569 sprintf(name, "%d %s", id+1, caption);
2570 windowMenu.AddDynamic(MenuItem
2572 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2573 NotifySelect = MenuWindowSelectWindow
2577 if(activeClient.cycle == cycle) break;
2582 if((!previous && activeClient) || !activeClient)
2588 item = menu.FindItem(MenuWindowCloseAll, 0);
2589 if(item) item.disabled = false;
2590 item = menu.FindItem(MenuWindowNext, 0);
2591 if(item) item.disabled = false;
2592 item = menu.FindItem(MenuWindowPrevious, 0);
2593 if(item) item.disabled = false;
2594 item = menu.FindItem(MenuWindowCascade, 0);
2595 if(item) item.disabled = false;
2596 item = menu.FindItem(MenuWindowTileHorz, 0);
2597 if(item) item.disabled = false;
2598 item = menu.FindItem(MenuWindowTileVert, 0);
2599 if(item) item.disabled = false;
2600 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2601 if(item) item.disabled = false;
2602 item = menu.FindItem(MenuWindowWindows, 0);
2603 if(item) item.disabled = false;
2606 item = menu.FindItem(MenuFileClose, 0);
2607 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2608 item = menu.FindItem(MenuFileSaveAll, 0);
2609 if(item) item.disabled = numDocuments < 1;
2611 if(activeClient && activeClient.menu && activeClient.state != minimized)
2615 //activeClient.menu.Clean(activeClient);
2616 menu.Merge(activeClient.menu, true, activeClient);
2620 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2623 menu.Merge(activeChild.menu, true, activeChild);
2626 // This is called again for a child window change, with same active client
2627 OnActivateClient(activeClient, previous);
2628 if(!menuBar && !((BorderBits)borderStyle).fixed && parent && parent.activeClient == this)
2629 parent.UpdateActiveDocument(null);
2632 void _ShowDecorations(Box box, bool post)
2634 if(rootWindow == this && nativeDecorations && !is3D) return;
2635 if(visible && this != guiApp.desktop)
2637 Surface surface = RedrawFull(box);
2641 FigureCaption(caption);
2644 ShowDecorations(captionFont.font,
2647 active, //parent.activeClient == this
2648 guiApp.windowMoving == this);
2650 PreShowDecorations(captionFont.font,
2653 active, //parent.activeClient == this
2654 guiApp.windowMoving == this);
2661 void UpdateExtent(Box refresh)
2663 Surface surface = null;
2665 if(!manageDisplay) { OnRedraw(null);return; }
2666 _ShowDecorations(refresh, false);
2668 surface = Redraw(refresh);
2669 // Opaque background: just fill before EW_REDRAW (clear?)
2672 surface.SetBackground(background);
2673 surface.SetForeground(foreground);
2674 surface.DrawingChar(' ');
2675 if(this == rootWindow)
2677 if(style.drawBehind || background.a)
2679 int a = background.a;
2680 // Premultiply alpha for clear color
2681 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2682 surface.Clear(colorBuffer);
2683 surface.SetBackground(background);
2686 else if(background.a)
2690 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2691 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2694 if(display.flags.alpha && background.a < 255 && background)
2696 surface.Area(0,0,clientSize.w, clientSize.h);
2697 /*if(style.clearDepthBuffer)
2698 surface.Clear(depthBuffer);*/
2700 else if(/*style.clearDepthBuffer || */background.a)
2702 int a = background.a;
2703 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2704 // Premultiply alpha for clear color
2705 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2706 surface.Clear(colorBuffer);
2707 surface.SetBackground(background);
2712 surface.TextFont(usedFont.font);
2713 surface.TextOpacity(false);
2714 surface.outlineColor = black;
2718 // Draw the caret ...
2719 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2721 // surface.SetBackground(0xFFFFFF - background.color);
2722 surface.SetBackground(~background.color);
2724 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2725 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2731 void DrawOverChildren(Box refresh)
2733 Surface surface = Redraw(refresh);
2737 surface.DrawingChar(' ');
2738 surface.SetBackground(background);
2739 surface.SetForeground(foreground);
2741 surface.TextFont(usedFont.font);
2742 surface.TextOpacity(false);
2743 surface.outlineColor = black;
2745 OnDrawOverChildren(surface);
2750 _ShowDecorations(refresh, true);
2753 void ComputeClipExtents(void)
2756 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2758 clipExtent.Copy(this.clipExtent);
2760 for(child = children.last; child; child = child.prev)
2762 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2764 bool opaque = child.IsOpaque(); // TODO: acess background directly
2765 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2767 child.clipExtent.Copy(clipExtent);
2768 child.clipExtent.Offset(-dx, -dy);
2769 child.clipExtent.IntersectBox(child.box);
2771 child.ComputeClipExtents();
2773 if(opaque && !child.style.nonClient)
2775 // Adjust the box for the parent:
2776 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2777 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2782 // ??? Only do this for overlapped window or if parent has with clip children flag
2784 // Do this if window has clip children flag on (default false?)
2785 // this.clipExtent = clipExtent;
2787 clipExtent.Free(null);
2790 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2793 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2794 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2796 offsetX -= rootWindow.clientStart.x;
2797 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2801 for(child = children.last; child; child = child.prev)
2803 bool opaque = child.IsOpaque();
2804 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2808 // Adjust renderArea to the root window level
2809 Extent * renderArea = &rootWindow.tempExtents[3];
2811 int offsetX = child.absPosition.x - rootWindow.absPosition.x;
2812 int offsetY = child.absPosition.y - rootWindow.absPosition.y;
2813 if(child.rootWindow.nativeDecorations && rootWindow.windowHandle)
2815 offsetX -= child.rootWindow.clientStart.x;
2816 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2820 Extent childRenderArea;
2822 if(backBufferUpdate != null)
2824 childRenderArea.Copy(backBufferUpdate);
2825 childRenderArea.Offset(-offsetX, -offsetY);
2828 childRenderArea.Copy(child.dirtyArea);
2830 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2831 renderArea.Copy(dirtyExtent);
2832 renderArea.Offset(-offsetX, -offsetY);
2833 childRenderArea.Union(renderArea);
2836 // Intersect with the clip extent
2837 childRenderArea.Intersection(child.clipExtent);
2840 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2842 // This intersection with child clip extent was missing and causing #708 (Installer components list scrolling bug):
2843 renderArea->Intersection(child.clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2845 renderArea->Offset(offsetX, offsetY);
2847 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2848 // overDirtyExtent.Union(renderArea);
2849 renderArea->Empty();
2850 // childRenderArea.Free();
2852 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2857 for(child = children.last; child; child = child.prev)
2859 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2861 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2866 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2868 bool opaque = IsOpaque();
2869 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2871 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2872 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2874 offsetX -= rootWindow.clientStart.x;
2875 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2879 for(child = children.last; child; child = child.prev)
2881 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2883 ColorAlpha background = *(ColorAlpha *)&child.background;
2884 bool opaque = child.IsOpaque();
2885 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2889 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2890 // Adjust renderArea to the root window level
2892 renderArea.Copy(child.dirtyArea);
2893 renderArea.Offset(offsetX, offsetY);
2894 dirtyExtent.Union(renderArea);
2895 overDirtyExtent.Union(renderArea);
2901 for(child = children.last; child; child = child.prev)
2903 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2905 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2909 if(backBufferUpdate != null)
2911 renderArea.Copy(backBufferUpdate);
2912 renderArea.Offset(-offsetX, -offsetY);
2914 overRenderArea.Copy(backBufferUpdate);
2915 overRenderArea.Offset(-offsetX, -offsetY);
2921 renderArea.Copy(dirtyArea);
2923 overRenderArea.Copy(dirtyArea);
2926 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2927 dirtyExtentWindow->Copy(dirtyExtent);
2928 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2929 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2930 dirtyExtentWindow->Empty();
2932 // Intersect with the clip extent
2933 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2936 if(renderArea.count > 10)
2939 printf("\nToo many extents (%d):\n", renderArea.count);
2941 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2942 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2947 for(c = 0; c<10; c++)
2950 FASTLIST_LOOP(renderArea, extentBox)
2952 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2954 renderArea.Copy(extent);
2956 FASTLIST_LOOP(renderArea, extentBox)
2959 printf("(%d, %d) - (%d, %d)\n",
2960 extentBox.box.left, extentBox.box.top,
2961 extentBox.box.right, extentBox.box.bottom);
2965 printf("\nNow %d\n", renderArea.count);
2971 // WHY WAS THIS COMMENTED ??
2973 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2974 dirtyExtentWindow->Copy(overDirtyExtent);
2975 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2976 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2977 dirtyExtentWindow->Empty();
2979 // Intersect with the clip extent
2980 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2986 if(scrollExtent.count)
2988 // Subtract render extent from scrolling extent
2989 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
2991 if(backBufferUpdate == null)
2993 Extent * dirty = &rootWindow.tempExtents[3];
2996 // Intersect scrolling extent with clip extent
2997 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2999 // offset this scroll to be at the root window level
3000 scrollExtent.Offset(offsetX, offsetY);
3001 // Add area that was scrolled to the dirty extents of the back buffer
3002 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
3006 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
3007 for(scrollBox = (BoxItem)scrollExtent.first; scrollBox; scrollBox = (BoxItem)scrollBox.next)
3008 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
3013 scrollExtent.Empty();
3015 // Add the exposed extent to the window render area
3016 dirty->Offset(-offsetX, -offsetY);
3017 renderArea.Union(dirty, rootWindow.tempExtents[0]);
3022 // Subtract the window's box from the transparency forced extent
3023 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
3029 renderArea.Copy(this.renderArea);
3030 renderArea.Offset(offsetX, offsetY);
3031 dirtyExtent.Union(renderArea);
3037 Extent renderArea { };
3039 renderArea.Copy(overRenderArea);
3040 renderArea.Offset(offsetX, offsetY);
3041 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
3046 if(backBufferUpdate != null)
3048 // Remove render area from dirty area
3049 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
3051 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
3058 // Remove the window render area from the dirty extents of the back buffer
3059 rootWindow.dirtyBack.Exclusion(renderArea);
3063 void Render(Extent updateExtent)
3067 Window rootWindow = this.rootWindow;
3068 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
3069 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
3071 offsetX -= rootWindow.clientStart.x;
3072 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
3075 if(rootWindow.fullRender)
3084 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
3085 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
3090 /*if(renderArea.count)
3091 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
3094 for(extentBox = (BoxItem)renderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
3096 Box box = extentBox.box;
3099 /*printf("(%d, %d) - (%d, %d)\n",
3100 extentBox.box.left, extentBox.box.top,
3101 extentBox.box.right, extentBox.box.bottom);*/
3106 box.left += offsetX;
3108 box.right += offsetX;
3109 box.bottom += offsetY;
3111 if(updateExtent != null)
3112 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
3116 for(child = children.first; child; child = child.next)
3117 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
3118 child.Render(updateExtent);
3120 if(rootWindow.fullRender)
3121 DrawOverChildren(box);
3124 // TO DO: There's an issue about draw over children...
3125 // TO DO: Don't wanna go through this if method isn't used
3126 for(extentBox = (BoxItem)overRenderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
3127 //FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
3129 Box box = extentBox.box;
3131 DrawOverChildren(box);
3133 box.left += offsetX;
3135 box.right += offsetX;
3136 box.bottom += offsetY;
3138 if(updateExtent != null)
3139 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
3142 for(child = children.first; child; child = child.next)
3143 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
3144 child.Render(updateExtent);
3147 overRenderArea.Empty();
3150 public void UpdateDisplay(void)
3152 if(!manageDisplay) { OnRedraw(null);return; }
3153 if(rootWindow && this != rootWindow)
3154 rootWindow.UpdateDisplay();
3157 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
3158 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
3161 dirtyExtent.Clear();
3164 clipExtent.AddBox(box);
3166 display.StartUpdate();
3168 if(!rootWindow.fullRender)
3170 ComputeClipExtents();
3171 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
3172 ComputeRenderArea(dirtyExtent, overExtent, null);
3175 clipExtent.Free(null);
3177 dirtyExtent.Free(null);
3178 overExtent.Free(null);
3180 if(display.flags.flipping)
3183 display.Update(null);
3187 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
3188 updateExtent.Clear();
3190 Render(updateExtent);
3192 updateExtent.UnionBox(this.box, tempExtents[0]);
3195 //printf("\n\nUpdate:\n------------------------------------------\n");
3198 //FASTLIST_LOOP(updateExtent, extentBox)
3199 for(extentBox = (BoxItem)updateExtent.first; extentBox; extentBox = (BoxItem)extentBox.next)
3202 /*printf("Updating (%d, %d) - (%d, %d)\n",
3203 extentBox.box.left, extentBox.box.top,
3204 extentBox.box.right, extentBox.box.bottom);*/
3207 display.Update(extentBox.box);
3210 updateExtent.Free(null);
3213 display.EndUpdate();
3221 void UpdateBackDisplay(Box box)
3227 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3229 //printf("UpdateBackDisplay going through!\n");
3230 display.StartUpdate();
3234 intersection.Copy(dirtyBack);
3235 intersection.IntersectBox(box);
3237 dirtyExtent.Clear();
3240 clipExtent.AddBox(box);
3242 if(!rootWindow.fullRender)
3244 ComputeClipExtents();
3245 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3248 clipExtent.Free(null);
3250 intersection.Free(null);
3251 dirtyExtent.Free(null);
3252 overExtent.Free(null);
3257 if(display.flags.flipping)
3258 display.Update(null);
3261 rootWindow.display.Update(box);
3264 display.EndUpdate();
3268 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3269 if(dirtyBack.count > MAX_DIRTY_BACK)
3271 BoxItem extentBox, next;
3272 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3273 for(extentBox = (BoxItem)dirtyBack.first; extentBox; extentBox = next)
3275 next = (BoxItem)extentBox.next;
3276 if(extentBox != first)
3278 if(extentBox.box.left < first.box.left)
3279 first.box.left = extentBox.box.left;
3280 if(extentBox.box.top < first.box.top)
3281 first.box.top = extentBox.box.top;
3282 if(extentBox.box.right > first.box.right)
3283 first.box.right = extentBox.box.right;
3284 if(extentBox.box.bottom > first.box.bottom)
3285 first.box.bottom = extentBox.box.bottom;
3286 dirtyBack.Delete(extentBox);
3295 // --- Window positioning ---
3296 // --- Window identification ---
3298 // Returns window at position "Position"
3299 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3301 Window child, result = null;
3303 box.left += absPosition.x;
3304 box.right += absPosition.x;
3305 box.top += absPosition.y;
3306 box.bottom += absPosition.y;
3308 if(!destroyed && visible && (acceptDisabled || !disabled))
3310 int lx = x - absPosition.x;
3311 int ly = y - absPosition.y;
3312 if(IsInside(lx, ly))
3313 // if(box.IsPointInside(Point{x, y}))
3315 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3316 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3319 bool isD = (last && last != this && last.IsDescendantOf(this)); // Fix for WSMS (#844)
3320 Window ancestor = null;
3322 for(ancestor = last; ancestor && ancestor.parent != this; ancestor = ancestor.parent);
3323 for(child = (isD ? (last != ancestor ? ancestor : ancestor.previous) : children.last); child; child = child.prev)
3325 if(child != statusBar && child.rootWindow == rootWindow)
3327 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3334 for(child = (isD ? (last != ancestor ? ancestor : ancestor.previous) : children.last); child; child = child.prev)
3336 if(child != statusBar && child.rootWindow == rootWindow)
3338 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3345 if(last && last != this && this.IsDescendantOf(last)) // Fix for installer lockup
3353 Window FindModal(void)
3355 Window modalWindow = this, check;
3356 Window check2 = null;
3357 for(check = this; check.master; check = check.master)
3359 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3361 modalWindow = check.master.modalSlave;
3362 check = modalWindow;
3364 // TESTING THIS FOR DROPBOX...
3365 if(!rootWindow || !rootWindow.style.interim)
3367 for(check2 = check; check2 /*.activeChild*/; check2 = check2.activeChild)
3369 if(check2.modalSlave && check2.modalSlave.created)
3371 modalWindow = check2.modalSlave;
3379 if(modalWindow == this)
3381 for(check = this; check.activeChild; check = check.activeChild)
3383 if(check.modalSlave)
3385 modalWindow = check.modalSlave;
3391 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3392 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3395 void StopMoving(void)
3397 if(this == guiApp.windowMoving)
3399 guiApp.windowMoving = null;
3400 UpdateDecorations();
3401 SetMouseRange(null);
3404 if(rootWindow.active)
3405 guiApp.interfaceDriver.StopMoving(rootWindow);
3407 guiApp.windowCaptured.ReleaseCapture();
3408 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3409 guiApp.windowIsResizing = false;
3413 void SelectMouseCursor(void)
3418 Window cursorWindow = null;
3419 bool rx, ry, rex, rey;
3421 guiApp.desktop.GetMousePosition(&x, &y);
3422 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3424 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3425 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[moving]);
3426 else if(mouseWindow)
3428 modalWindow = mouseWindow.FindModal();
3429 x -= mouseWindow.absPosition.x;
3430 y -= mouseWindow.absPosition.y;
3431 if(guiApp.windowIsResizing)
3433 rex = guiApp.resizeEndX;
3434 rey = guiApp.resizeEndY;
3435 rx = guiApp.resizeX;
3436 ry = guiApp.resizeY;
3437 if((rex && rey) || (rx && ry))
3438 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNWSE]);
3439 else if((rex && ry) || (rx && rey))
3440 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNESW]);
3441 else if((ry || rey) && (!rx && !rex))
3442 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNS]);
3443 else if((rx || rex) && (!ry && !rey))
3444 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeWE]);
3446 else if(!modalWindow && !guiApp.windowCaptured &&
3447 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3448 &rx, &ry, &rex, &rey))
3450 if((rex && rey) || (rx && ry))
3451 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNWSE]);
3452 else if((rex && ry) || (rx && rey))
3453 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNESW]);
3454 else if((ry || rey) && (!rx && !rex))
3455 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNS]);
3456 else if((rx || rex) && (!ry && !rey))
3457 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeWE]);
3459 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3461 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}) &&
3462 mouseWindow.rootWindow != mouseWindow)
3463 cursorWindow = mouseWindow.parent;
3465 cursorWindow = mouseWindow;
3467 else if(!guiApp.interimWindow)
3468 cursorWindow = guiApp.windowCaptured;
3471 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient && cursorWindow.rootWindow != cursorWindow; cursorWindow = cursorWindow.parent);
3472 guiApp.SetCurrentCursor(mouseWindow, cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3474 else if(modalWindow)
3476 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[arrow]);
3478 else if(guiApp.interimWindow)
3480 if(guiApp.interimWindow.cursor)
3481 guiApp.SetCurrentCursor(mouseWindow, guiApp.interimWindow.cursor);
3483 guiApp.SetCurrentCursor(mouseWindow, mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3488 // --- State based input ---
3489 bool AcquireInputEx(bool state)
3494 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3495 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3497 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3499 guiApp.acquiredWindow = state ? this : null;
3502 SetMouseRangeToClient();
3503 guiApp.interfaceDriver.SetMouseCursor(guiApp.acquiredWindow, (SystemCursor)-1);
3508 SelectMouseCursor();
3510 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3514 // --- Window activation ---
3515 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3518 if(!parent || !parent.style.inactive)
3520 Window parent = this.parent;
3523 if(rootWindow == this)
3524 Log(active ? "active\n" : "inactive\n");
3526 if(active && requireRemaximize)
3528 if(state == maximized)
3530 property::state = normal;
3531 property::state = maximized;
3533 requireRemaximize = false;
3536 // Testing this here...
3537 if(!parent || parent == guiApp.desktop || parent.active)
3539 this.active = active;
3542 // TESTING THIS HERE
3543 UpdateDecorations();
3544 if((result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master))
3545 result = NotifyActivate(master, this, active, previous);
3548 this.active = !active;
3553 if(!parent || parent == guiApp.desktop || parent.active)
3555 this.active = active;
3557 AcquireInputEx(active);
3558 if(active && isEnabled)
3562 if(guiApp.caretOwner)
3566 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3567 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3568 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3569 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3571 guiApp.caretOwner.Update(extent);
3574 if(visible || !guiApp.caretOwner)
3575 guiApp.caretOwner = this;
3576 UpdateCaret(false, false);
3582 this.active = false;
3584 AcquireInputEx(active);
3586 if(!active && guiApp.caretOwner == this)
3588 UpdateCaret(false, true);
3589 guiApp.caretOwner = null;
3590 guiApp.interfaceDriver.SetCaret(0,0,0);
3591 guiApp.caretEnabled = false;
3596 if(!active && parent && parent.activeChild && parent.activeChild != this)
3597 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3603 if(!active && menuBar)
3606 menuBar.OnActivate(false, null, &goOn, true);
3607 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3612 Window aChild = activeChild;
3614 if(!aChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3626 void ConsequentialMouseMove(bool kbMoving)
3628 if(rootWindow && !noConsequential)
3630 if(kbMoving || !guiApp.windowMoving)
3634 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3636 if(guiApp.interfaceDriver)
3637 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3639 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3640 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3646 bool IsDescendantOf(Window ancestor)
3649 for(window = this; window && window != ancestor; window = window.parent);
3650 return window == ancestor;
3653 bool IsSlaveOf(Window master)
3656 for(window = this; window && window != master; window = window.master);
3657 return window == master;
3660 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3664 if(this && !destroyed /*&& state != Hidden*/)
3666 Window swap = externalSwap;
3674 if(activateParent &&
3675 (parent.activeChild != this ||
3676 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3677 active && _isModal &&
3678 parent != master && master)
3679 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3685 bool real = parent.activeChild != this;
3687 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3688 if(!style.inactive && /*activateParent && */guiApp.interimWindow &&
3689 !IsDescendantOf(guiApp.interimWindow) &&
3690 !IsSlaveOf(guiApp.interimWindow))
3692 Window interimWindow = guiApp.interimWindow;
3693 while(interimWindow && interimWindow != this)
3695 Window master = interimWindow.master;
3697 guiApp.interimWindow = null;
3698 if(guiApp.caretOwner)
3699 guiApp.caretOwner.UpdateCaret(false, false);
3701 incref interimWindow;
3702 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3707 delete interimWindow;
3708 interimWindow = (master && master.style.interim) ? master : null;
3713 guiApp.interimWindow = this;
3714 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3715 guiApp.caretEnabled = false;*/
3716 UpdateCaret(false, true);
3721 //bool acquireInput = false;
3723 parent.activeChild &&
3724 parent.activeChild.state == maximized &&
3725 parent != guiApp.desktop;
3727 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3732 swap = parent.activeChild;
3733 if(swap && swap.destroyed) swap = null;
3734 if(swap && swap != this)
3737 if(!swap.PropagateActive(false, this, &goOn, true))
3738 swap = parent.activeChild;
3749 if(!parent || parent.activeChild != this || style.interim)
3752 result = PropagateActive(true, swap, &goOn, true);
3753 if(!result && !goOn)
3758 //acquireInput = true;
3762 if(style.hasMaximize && parent != guiApp.desktop)
3765 SetState(maximized, false, 0);
3766 else if(state != maximized)
3769 for(child = parent.children.first; child; child = child.next)
3771 if(this != child && child.state == maximized)
3772 child.SetState(normal, false, 0);
3779 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3781 Window previous = parent.activeClient;
3782 parent.activeChild = this;
3783 if(!style.nonClient /*&& style.isActiveClient*/)
3787 if(style.isActiveClient)
3788 parent.activeClient = this;
3789 // Moved UpdateActiveDocument inside hidden check
3790 // To prevent activating previous window while creating a new one
3791 // (It was messing up the privateModule in the CodeEditor)
3792 parent.UpdateActiveDocument(previous);
3798 //if(!style.isRemote)
3800 if(rootWindow != this)
3802 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3803 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3805 else if(!guiApp.fullScreenMode)
3807 Window modalRoot = FindModal();
3808 if(!modalRoot) modalRoot = this;
3809 if(!modalRoot.isForegroundWindow)
3811 modalRoot.isForegroundWindow = true;
3812 // To check : Why is parent null?
3813 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3815 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3817 modalRoot.isForegroundWindow = false;
3822 if(result && real && (!style.inactive || moveInactive) && parent)
3824 Window last = parent.children.last;
3826 if(!style.stayOnTop)
3827 for(; last && last.style.stayOnTop; last = last.prev);
3829 parent.children.Move(this, last);
3831 // Definitely don't want that: why not?
3835 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3841 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3848 parent.activeChild = null;
3849 if(!style.nonClient /*&& style.isActiveClient*/)
3851 Window previous = parent.activeClient;
3852 if(style.isActiveClient)
3853 parent.activeClient = null;
3854 parent.UpdateActiveDocument(previous);
3858 if(this == guiApp.interimWindow)
3860 guiApp.interimWindow = null;
3861 if(guiApp.caretOwner)
3862 guiApp.caretOwner.UpdateCaret(false, false);
3864 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3871 if(!active || !swap)
3872 UpdateDecorations();
3874 swap.UpdateDecorations();
3876 if(active && rootWindow != this)
3877 ConsequentialMouseMove(false);
3884 // --- Input Messages ---
3885 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3887 static bool reEntrancy = false;
3888 if(reEntrancy) return;
3892 guiApp.cursorUpdate = true;
3893 if(guiApp.windowScrolling && !consequential)
3895 guiApp.windowScrolling.SetScrollPosition(
3896 (guiApp.windowScrolling.sbh) ?
3897 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3898 (guiApp.windowScrolling.sbv) ?
3899 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3901 if(guiApp.windowMoving)
3903 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3905 Window window = guiApp.windowMoving;
3907 int w = window.size.w;
3908 int h = window.size.h;
3913 rx = mouseX - guiApp.windowMovingStart.x;
3914 ry = mouseY - guiApp.windowMovingStart.y;
3917 window.GetDecorationsSize(&ew, &eh);
3919 if(guiApp.windowIsResizing)
3921 x = window.scrolledPos.x;
3922 y = window.scrolledPos.y;
3926 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3927 rx = guiApp.windowResizingBefore.w - aw;
3928 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3929 w = guiApp.windowResizingBefore.w - rx;
3933 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3934 ry = guiApp.windowResizingBefore.h - ah;
3935 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3936 ry = Max(ry, -guiApp.windowMovingBefore.y);
3937 h = guiApp.windowResizingBefore.h - ry;
3939 if(guiApp.resizeEndX)
3941 w = guiApp.windowResizingBefore.w + rx;
3944 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3952 w = Max(w, window.minSize.w);
3953 h = Max(h, window.minSize.h);
3954 w = Min(w, window.maxSize.w);
3955 h = Min(h, window.maxSize.h);
3957 if(!window.OnResizing(&w, &h))
3959 w = window.clientSize.w;
3960 h = window.clientSize.h;
3963 w = Max(w, window.skinMinSize.w);
3964 h = Max(h, window.skinMinSize.h);
3971 SNAPDOWN(w, textCellW);
3972 SNAPDOWN(h, textCellH);
3977 aw = Max(w,window.skinMinSize.w);
3978 rx = guiApp.windowResizingBefore.w - aw;
3979 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3980 w = guiApp.windowResizingBefore.w - rx;
3984 ah = Max(h,window.skinMinSize.h);
3985 ry = guiApp.windowResizingBefore.h - ah;
3986 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3987 ry = Max(ry, -guiApp.windowMovingBefore.y);
3988 h = guiApp.windowResizingBefore.h - ry;
3993 if(!guiApp.windowIsResizing || guiApp.resizeX)
3994 x = guiApp.windowMovingBefore.x + rx;
3995 if(!guiApp.windowIsResizing || guiApp.resizeY)
3996 y = guiApp.windowMovingBefore.y + ry;
3998 if(!guiApp.windowIsResizing)
4001 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
4003 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
4004 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
4005 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
4006 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
4010 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
4011 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
4017 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
4019 if(!window.OnMoving(&x, &y, w, h))
4021 x = window.scrolledPos.x;
4022 y = window.scrolledPos.y;
4028 SNAPDOWN(x, textCellW);
4029 SNAPDOWN(y, textCellH);
4032 if(!window.style.nonClient)
4034 if(!window.style.fixed /*|| window.style.isDocument*/)
4036 if(!window.style.dontScrollHorz)
4037 x += window.parent.scroll.x;
4038 if(!window.style.dontScrollVert)
4039 y += window.parent.scroll.y;
4043 // Break the anchors for moveable/resizable windows
4044 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
4045 if(window.style.fixed)
4047 if(window.state == normal)
4049 window.normalAnchor = Anchor { left = x, top = y };
4050 window.normalSizeAnchor = SizeAnchor { { w, h } };
4051 window.anchored = false;
4055 window.stateAnchor = Anchor { left = x, top = y };
4056 window.stateSizeAnchor = SizeAnchor { { w, h } };
4058 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
4059 // TOCHECK: Investigate why the following only redraws the scrollbars
4060 //window.Position(x, y, w, h, false, true, true, true, false, true);
4062 guiApp.movingLast.x = mouseX;
4063 guiApp.movingLast.y = mouseY;
4069 public bool MultiTouchMessage(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers * mods, bool consequential, bool activate)
4075 while(result && w != this)
4077 // TODO: How to handle this?
4080 Window msgWindow = GetAtPosition(x,y, false, true, w);
4085 window = (w && !w.disabled) ? w : null;
4087 if(consequential) mods->isSideEffect = true;
4088 if(!result || (window && window.destroyed)) window = null;
4092 if(window.OnMultiTouch && !window.disabled)
4094 Array<TouchPointerInfo> in { size = infos.size };
4095 memcpy(in.array, infos.array, sizeof(TouchPointerInfo) * infos.size);
4099 i.x -= (window.absPosition.x + window.clientStart.x);
4100 i.y -= (window.absPosition.y + window.clientStart.y);
4102 i.x = Max(Min(i.x, 32767),-32768);
4103 i.y = Max(Min(i.y, 32767),-32768);
4107 if(!window.OnMultiTouch(event, in, *mods))
4114 if(!result || !w || !w.clickThrough)
4122 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
4125 bool wasMoving = guiApp.windowMoving ? true : false;
4126 bool wasScrolling = guiApp.windowScrolling ? true : false;
4127 bool firstPass = true;
4129 while(result && w != this)
4131 Window msgWindow = GetAtPosition(x,y, false, true, w);
4132 Window trueWindow = GetAtPosition(x,y, false, false, w);
4133 bool windowDragged = false;
4138 window = (w && !w.disabled) ? w : null;
4140 if(trueWindow) incref trueWindow;
4142 if(consequential) mods->isSideEffect = true;
4144 UpdateMouseMove(x, y, consequential);
4146 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
4148 if(!guiApp.windowCaptured.isEnabled)
4149 guiApp.windowCaptured.ReleaseCapture();
4151 window = guiApp.windowCaptured;
4154 if(trueWindow && activate &&
4155 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
4156 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
4157 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
4158 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
4160 if(mods->alt && !mods->ctrl && !mods->shift)
4162 Window moved = trueWindow;
4163 for(moved = trueWindow; moved; moved = moved.parent)
4164 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
4169 windowDragged = true;
4171 // Cancel the ALT menu toggling...
4172 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4177 if(window && activate &&
4178 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
4179 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
4180 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
4181 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
4183 Window modalWindow = window.FindModal();
4185 /*if(mods->alt && !mods->shift && !mods->ctrl)
4187 Window moved = window;
4188 for(moved = window; moved; moved = moved.parent)
4189 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
4194 windowDragged = true;
4196 // Cancel the ALT menu toggling...
4197 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
4203 Window activateWindow = modalWindow ? modalWindow : window;
4204 if(activateWindow && !activateWindow.isRemote)
4206 bool doActivation = true;
4207 //bool needToDoActivation = false;
4208 Window check = activateWindow;
4210 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
4212 if(!check.style.inactive)
4214 //needToDoActivation = true;
4216 doActivation = false;
4221 if(!needToDoActivation)
4222 doActivation = false;
4225 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
4226 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
4228 // Let the OnLeftButtonDown do the activating instead
4229 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4237 incref activateWindow;
4238 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
4240 delete activateWindow;
4244 if(activateWindow._refCount == 1)
4246 delete activateWindow;
4250 delete activateWindow;
4251 // Trouble with clickThrough, siblings and activation (Fix for nicktick scrolling, siblings/activation endless loops, #844)
4254 mods->isActivate = true;
4258 if(!modalWindow && window && !window.destroyed)
4260 if(!guiApp.windowCaptured || windowDragged)
4262 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
4264 bool moving = ((window.state != maximized &&
4265 window.IsMouseMoving(
4266 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4267 || (guiApp.windowMoving && !guiApp.windowIsResizing);
4269 if(!moving && window.IsMouseResizing(
4270 x - window.absPosition.x,
4271 y - window.absPosition.y,
4272 window.size.w, window.size.h,
4273 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
4275 guiApp.windowIsResizing = true;
4276 guiApp.windowResizingBefore.w = window.size.w;
4277 guiApp.windowResizingBefore.h = window.size.h;
4279 if(guiApp.windowIsResizing || windowDragged || moving)
4282 guiApp.windowMoving = window;
4283 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4284 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4285 guiApp.windowMovingBefore.x = window.position.x;//s;
4286 guiApp.windowMovingBefore.y = window.position.y;//s;
4287 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4288 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4291 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4293 if(window.style.fixed &&
4295 window.IsMouseMoving(
4296 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4298 window.ShowSysMenu(x, y);
4302 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4304 if(window.sbv || window.sbh)
4307 guiApp.windowScrolling = window;
4308 guiApp.windowScrollingStart.x = x;
4309 guiApp.windowScrollingStart.y = y;
4310 guiApp.windowScrollingBefore.x = window.scroll.x;
4311 guiApp.windowScrollingBefore.y = window.scroll.y;
4314 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4316 if(window.style.hasMaximize &&
4317 window.IsMouseMoving(
4318 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4321 (window.state == maximized) ? normal : maximized, false, *mods);
4329 if(guiApp.windowMoving)
4331 if(guiApp.windowMoving.parent)
4333 if(guiApp.windowMoving.style.nonClient)
4334 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4336 guiApp.windowMoving.parent.SetMouseRangeToClient();
4340 window.UpdateDecorations();
4343 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4345 // Log("\n*** LEFT BUTTON UP ***\n");
4346 if(guiApp.windowMoving)
4347 guiApp.windowMoving.StopMoving();
4349 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4351 if(guiApp.windowScrolling)
4353 Window windowScrolling = guiApp.windowScrolling;
4354 guiApp.windowScrolling = null;
4355 windowScrolling.ReleaseCapture();
4359 if(!result || (window && window.destroyed)) window = null;
4361 if(window && window.FindModal())
4364 if(trueWindow && trueWindow.FindModal())
4372 msgWindow = GetAtPosition(x,y, true, false);
4374 msgWindow.SelectMouseCursor();
4377 if(firstPass && (guiApp.windowCaptured || trueWindow))
4379 Window prevWindow = guiApp.prevWindow;
4380 List<Window> overWindows = guiApp.overWindows;
4381 Iterator<Window> it { overWindows };
4386 if(trueWindow != w && !trueWindow.IsDescendantOf(w))
4389 result = w.OnMouseLeave(*mods);
4391 overWindows.TakeOut(w);
4395 if(result && guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4397 guiApp.prevWindow.mouseInside = false;
4398 guiApp.prevWindow = null;
4402 if(trueWindow.IsDescendantOf(prevWindow))
4404 if(!overWindows.Find(prevWindow))
4405 overWindows.Add(prevWindow);
4407 // Eventually fix this not to include captured?
4408 else if(!prevWindow.OnMouseLeave(*mods))
4412 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4414 Box box = trueWindow.box;
4415 box.left += trueWindow.absPosition.x;
4416 box.right += trueWindow.absPosition.x;
4417 box.top += trueWindow.absPosition.y;
4418 box.bottom += trueWindow.absPosition.y;
4420 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4422 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4423 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4425 overX = Max(Min(overX, 32767),-32768);
4426 overY = Max(Min(overY, 32767),-32768);
4428 trueWindow.mouseInside = true;
4429 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4433 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4435 for(w : guiApp.overWindows; w == trueWindow)
4438 guiApp.overWindows.TakeOut(w);
4441 guiApp.prevWindow = trueWindow;
4444 guiApp.prevWindow = null;
4446 SelectMouseCursor();
4448 if(window && ((!guiApp.windowMoving && !wasMoving) ||
4449 (wasMoving && guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp)) && !wasScrolling)
4451 int clientX = x - (window.absPosition.x + window.clientStart.x);
4452 int clientY = y - (window.absPosition.y + window.clientStart.y);
4454 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4456 clientX = Max(Min(clientX, 32767),-32768);
4457 clientY = Max(Min(clientY, 32767),-32768);
4459 MouseMethod = (void *)window._vTbl[method];
4461 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4464 if(!MouseMethod(window, clientX, clientY, *mods))
4468 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4469 window.OnMouseLeave(*mods);
4476 if(result && w && w.clickThrough && w.parent)
4481 if(!result || !w || !w.clickThrough)
4489 // --- Mouse cursor management ---
4491 bool KeyMessage(uint method, Key key, unichar character)
4496 if(guiApp.interimWindow)
4497 this = guiApp.interimWindow;
4500 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4504 if(!style.inactive || rootWindow != this)
4506 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4507 Window modalWindow = FindModal();
4508 Window interimMaster = master ? master.rootWindow : null;
4512 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4513 status = OnSysKeyDown(key, character);
4514 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4515 status = OnSysKeyHit(key, character);
4516 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4517 status = OnSysKeyUp(key, character);
4524 // Process Key Message for Internal UI Keyboard actions
4525 if(status && !destroyed && menuBar && state != minimized)
4528 if((SmartKey)key != alt)
4529 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4532 SmartKey sk = (SmartKey) key;
4533 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4535 status = menuBar.KeyMessage(method, key, character);
4540 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4541 menuBar.OnKeyHit(escape, 0);
4543 if(!menuBar.focus && guiApp.caretOwner)
4544 guiApp.caretOwner.UpdateCaret(true, false);
4547 if(!destroyed && status)
4549 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4553 case left: case up: case right: case down:
4554 if(guiApp.windowMoving == this)
4557 int w = guiApp.windowMoving.size.w;
4558 int h = guiApp.windowMoving.size.h;
4559 int x = guiApp.windowMoving.scrolledPos.x;
4560 int y = guiApp.windowMoving.scrolledPos.y;
4564 if(key == down || key == up)
4565 step = Max(step, textCellH);
4567 step = Max(step, textCellW);
4570 if(guiApp.windowIsResizing)
4574 case left: w-=step; break;
4575 case right: w+=step; break;
4576 case up: h-=step; break;
4577 case down: h+=step; break;
4584 case left: x-=step; break;
4585 case right: x+=step; break;
4586 case up: y-=step; break;
4587 case down: y+=step; break;
4591 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4592 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4594 if(!guiApp.windowIsResizing || guiApp.resizeX)
4595 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4597 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4599 if(!guiApp.windowIsResizing || guiApp.resizeY)
4600 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4602 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4604 guiApp.interfaceDriver.SetMousePosition(x, y);
4605 ConsequentialMouseMove(true);
4613 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4615 guiApp.windowMoving.StopMoving();
4616 ConsequentialMouseMove(false);
4624 ShowSysMenu(absPosition.x, absPosition.y);
4632 if(!destroyed && status && state != minimized)
4634 // Process all the way down the children
4635 if(activeChild && !activeChild.disabled)
4637 status = activeChild.KeyMessage(method, key, character);
4639 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4640 key.code != left && key.code != right && key.code != up && key.code != down)
4642 status = activeClient.KeyMessage(method, key, character);
4646 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4648 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4649 // && defaultControl != activeChild)
4651 delete previousActive;
4652 previousActive = activeChild;
4653 if(previousActive) incref previousActive;
4655 ConsequentialMouseMove(false);
4656 if((defaultControl.active ||
4657 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4658 defaultControl.KeyMessage(method, defaultKey, character);
4664 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4666 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4673 ShowSysMenu(absPosition.x, absPosition.y);
4680 if(this != guiApp.desktop)
4682 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4684 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4686 MenuMoveOrSize(key.shift, true);
4690 else if(guiApp.windowMoving)
4692 guiApp.windowMoving.StopMoving();
4693 ConsequentialMouseMove(false);
4701 if(!destroyed && status && state != minimized)
4703 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4707 case tab: case shiftTab:
4709 Window cycleParent = this;
4710 if(this == guiApp.interimWindow && master && !master.style.interim && !cycleParent.style.tabCycle && master.parent)
4711 cycleParent = master.parent;
4713 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4715 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4718 Window child = cycleParent.activeChild;
4720 // Scroll the window to include the active control
4721 if(cycleParent.sbh && !child.style.dontScrollHorz)
4723 if(child.scrolledPos.x < 0)
4724 cycleParent.sbh.Action(Position,
4725 cycleParent.scroll.x + child.scrolledPos.x, 0);
4726 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4727 cycleParent.sbh.Action(Position,
4728 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4730 if(cycleParent.sbv && !child.style.dontScrollVert)
4732 if(child.scrolledPos.y < 0)
4733 cycleParent.sbv.Action(Position,
4734 cycleParent.scroll.y + child.scrolledPos.y, 0);
4735 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4736 cycleParent.sbv.Action(Position,
4737 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4740 cycleParent.ConsequentialMouseMove(false);
4746 case f6: case shiftF6:
4747 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4749 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4750 if(parent == guiApp.desktop)
4751 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4761 if(CycleChildren(key.shift, true, false, true))
4769 // mIRC Style Window Shortcuts
4770 case alt1: case alt2: case alt3: case alt4: case alt5:
4771 case alt6: case alt7: case alt8: case alt9: case alt0:
4776 for(document = children.first; document; document = document.next)
4778 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4780 if(document == activeChild)
4782 if(document.state == minimized)
4783 document.SetState(normal, false, key);
4786 document.SetState(minimized, false, key);
4787 CycleChildren(false, true, false);
4792 if(activeChild.state == maximized && document.style.hasMaximize)
4793 document.SetState(maximized, false, key);
4794 else if(document.state == minimized)
4795 document.SetState(normal, false, key);
4796 document.Activate();
4811 if(!destroyed && status)
4813 if(state == minimized)
4818 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4820 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4822 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4823 previousActive.ActivateEx(true, false, false, true, null, null);
4824 delete previousActive;
4830 if(!destroyed && status)
4832 status = ProcessHotKeys(method, key, character);
4834 if(!destroyed && status && !modalWindow && state != minimized)
4837 status = KeyMethod(this, key, character);
4838 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4839 status = OnKeyHit(key, character);
4840 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4842 bool result = false;
4845 case ctrlUp: case ctrlDown:
4846 if(sbv && !guiApp.windowScrolling)
4847 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4849 case wheelUp: case wheelDown:
4850 if(sbv && !guiApp.windowScrolling)
4852 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4853 // Do we want to do a consequential move regardless of result in this case?
4854 ConsequentialMouseMove(false);
4857 case ctrlPageUp: case ctrlPageDown:
4858 if(sbh && !guiApp.windowScrolling)
4859 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4864 ConsequentialMouseMove(false);
4869 if(status && !destroyed && menuBar && state != minimized)
4870 status = menuBar.KeyMessage(method, key, character);
4872 if(style.interim && /*destroyed && */status && interimMaster)
4874 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4875 status = interimMaster.KeyMessage(method, key, character);
4882 bool ProcessHotKeys(uint method, Key key, unichar character)
4887 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4888 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4889 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4891 Window hotKeyWindow = hotKey.window;
4892 Window parent = hotKeyWindow.parent;
4893 Window prevActiveWindow = activeChild;
4894 // For when sys buttons are placed inside the menu bar
4895 if(parent && parent._class == class(PopupMenu))
4896 parent = parent.parent;
4898 // 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
4899 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1])))
4902 if(prevActiveWindow) incref prevActiveWindow;
4903 incref hotKeyWindow;
4904 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient && !hotKeyWindow.inactive)
4905 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4908 delete hotKeyWindow;
4909 delete prevActiveWindow;
4913 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4914 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4915 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4917 // ********* WORKING ON THIS ***********
4918 if(prevActiveWindow && !guiApp.interimWindow)
4919 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4922 else if(hotKeyWindow.style.inactive)
4923 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4925 delete prevActiveWindow;
4926 delete hotKeyWindow;
4927 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4928 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4932 if(status && tabCycle)
4935 for(child = children.first; child; child = child.next)
4937 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4948 // --- Windows and graphics initialization / termination ---
4949 bool SetupRoot(void)
4953 // Setup relationship with outside world (bb root || !bb)
4954 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4955 (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))
4959 tempExtents = new0 Extent[4];
4964 /*if(guiApp.fullScreenMode)
4965 rootWindow = guiApp.desktop;
4967 //rootWindow = parent.created ? parent.rootWindow : null;
4968 rootWindow = parent.rootWindow;
4971 against = &parent.box;
4973 against = &parent.clientArea;
4976 for(child = children.first; child; child = child.next)
4979 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
4982 bool Setup(bool positionChildren)
4984 bool result = false;
4987 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))))
4989 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
4990 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
4993 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
4995 // This was here, is it really needed?
4996 //guiApp.interfaceDriver.ActivateRootWindow(this);
5000 displaySystem = DisplaySystem {};
5001 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
5003 delete displaySystem;
5008 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData };
5009 if(display.Create(displaySystem, windowHandle))
5016 // Sometimes icon does not show up on Windows XP if we set here...
5017 // guiApp.interfaceDriver.SetIcon(this, icon);
5019 else if(this != guiApp.desktop)
5021 display = rootWindow ? rootWindow.display : null;
5027 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
5028 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
5030 for(child = children.first; child; child = child.next)
5032 if(child.created && !child.Setup(false))
5035 if(guiApp.modeSwitching && guiApp.fullScreen && child.rootWindow == child)
5036 child.UpdateCaption();
5041 bool SetupDisplay(void)
5043 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
5044 if(is3D) return Window3D_SetupDisplay(this); else
5051 class_data void ** pureVTbl;
5053 bool LoadGraphics(bool creation, bool resetAnchors)
5055 bool result = false;
5056 bool success = false;
5058 WindowState stateBackup = state;
5060 if(((subclass(Window))_class).pureVTbl)
5062 if(_vTbl == _class._vTbl)
5064 _vTbl = ((subclass(Window))_class).pureVTbl;
5069 for(m = 0; m < _class.vTblSize; m++)
5071 if(_vTbl[m] == _class._vTbl[m])
5072 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5076 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
5078 if(_vTbl == ((subclass(Window))_class).pureVTbl)
5080 _vTbl = _class._vTbl;
5085 for(m = 0; m < _class.vTblSize; m++)
5087 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
5088 _vTbl[m] = _class._vTbl[m];
5093 if(guiApp.fullScreenMode || this != guiApp.desktop)
5095 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
5101 display.Lock(false);
5102 if(rootWindow == this)
5104 // Set Color Palette
5105 display.SetPalette(palette, true);
5109 if(guiApp.fullScreenMode && this == guiApp.desktop)
5114 for(c=0; c<SystemCursor::enumSize; c++)
5115 if(!guiApp.systemCursors[c].bitmap)
5117 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
5118 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
5119 if(guiApp.systemCursors[c].bitmapName)
5121 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
5122 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
5123 if(guiApp.systemCursors[c].bitmap)
5124 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
5129 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5131 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
5132 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
5134 cursor.bitmap.paletteShades = cursor.paletteShades;
5138 guiApp.cursorUpdate = true;
5141 ConsequentialMouseMove(false);
5147 // Load Window Graphic Resources
5150 if(usedFont == setFont || usedFont == window.systemFont)
5151 RemoveResource(usedFont);
5154 RemoveResource(setFont); // TESTING setFont instead of usedFont);
5157 RemoveResource(systemFont);
5160 RemoveResource(captionFont);
5162 for(ptr = resources.first; ptr; ptr = ptr.next)
5164 if(!ptr.loaded) // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
5165 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
5168 AddResource(setFont);
5170 AddResource(systemFont);
5172 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
5179 //if(master && master.font)
5180 if(parent && parent.font)
5184 faceName = parent.font.faceName,
5185 size = parent.font.size,
5186 bold = parent.font.bold,
5187 italic = parent.font.italic,
5188 underline = parent.font.underline
5190 //font = parent.font;
5191 watch(parent) { font { } };
5194 font = guiApp.currentSkin.SystemFont();
5201 captionFont = guiApp.currentSkin ? guiApp.currentSkin.CaptionFont() : null;
5202 AddResource(captionFont);
5204 if(OnLoadGraphics())
5210 //SetScrollLineStep(sbStep.x, sbStep.y);
5212 if(this != guiApp.desktop)
5216 normalAnchor = anchor;
5217 normalSizeAnchor = sizeAnchor;
5220 // Break the anchors for moveable/resizable windows
5222 if(style.fixed && style.isDocument)
5224 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
5236 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5237 stateSizeAnchor = SizeAnchor {};
5242 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5247 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
5248 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
5251 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5255 stateAnchor = normalAnchor;
5256 stateSizeAnchor = normalSizeAnchor;
5259 position = Point { };
5260 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5271 if(Position(x, y, w, h, true, false, true, true, true, true))
5273 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
5276 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
5293 success = result = true;
5296 if(!creation && result)
5298 // Load menu bar first because sys buttons are on it...
5301 if(!menuBar.LoadGraphics(false, resetAnchors))
5307 for(child = children.first; child; child = child.next)
5309 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
5316 CreateSystemChildren();
5320 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5323 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5326 LogErrorCode(graphicsLoadingFailed, _class.name);
5328 // Do this here to avoid problems on Windows
5329 if(rootWindow == this && parent && stateBackup == maximized)
5330 property::state = maximized;
5334 void UnloadGraphics(bool destroyWindows)
5338 // Free children's graphics
5339 for(child = children.first; child; child = child.next)
5340 child.UnloadGraphics(destroyWindows);
5343 display.Lock(false);
5346 if(guiApp.fullScreenMode && this == guiApp.desktop)
5351 for(c=0; c<SystemCursor::enumSize; c++)
5352 if(guiApp.systemCursors[c].bitmap)
5353 delete guiApp.systemCursors[c].bitmap;
5355 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5356 delete cursor.bitmap;
5358 guiApp.cursorBackground.Free();
5361 if(display && display.displaySystem)
5365 for(ptr = resources.first; ptr; ptr = ptr.next)
5369 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5374 // Free window graphics
5377 // Free skin graphics
5378 if(rootWindow == this)
5380 DisplaySystem displaySystem = display.displaySystem;
5383 display.driverData = null;
5384 display.displaySystem = null;
5388 if(displaySystem && !displaySystem.numDisplays && !is3D)
5389 delete displaySystem;
5398 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5399 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5401 if(this == guiApp.desktop || parent == guiApp.desktop)
5403 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5404 guiApp.interfaceDriver.DestroyRootWindow(this);
5408 // --- Window Hiding ---
5410 void SetVisibility(bool state)
5412 bool visible = (style.hidden || !created) ? false : state;
5413 if(visible != this.visible)
5417 this.visible = visible;
5418 for(child = children.first; child; child = child.next)
5419 child.SetVisibility(visible);
5421 ConsequentialMouseMove(false);
5422 if(parent && !nonClient) parent.OnChildVisibilityToggled(this, visible);
5426 // --- Windows and graphics initialization / termination ---
5428 bool DisplayModeChanged(void)
5430 bool result = false;
5431 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5433 guiApp.modeSwitching = true;
5434 UnloadGraphics(false);
5436 if(LoadGraphics(false, false))
5438 guiApp.modeSwitching = false;
5443 // --- Window updates system ---
5445 void UpdateDirty(Box updateBox)
5447 if(!manageDisplay) { OnRedraw(null);return; }
5450 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5453 if(display.flags.flipping)
5456 rootWindow.UpdateDisplay();
5459 UpdateBackDisplay(updateBox);
5461 if(guiApp.fullScreenMode)
5463 guiApp.cursorUpdate = true;
5464 guiApp.PreserveAndDrawCursor();
5466 if(guiApp.fullScreenMode)
5467 guiApp.RestoreCursorBackground();
5473 // This function is strictly called as a result of system window activation
5474 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5477 Window interimMaster = null;
5478 Window interimWindow = guiApp.interimWindow;
5479 if(interimWindow && interimWindow.master)
5480 interimMaster = interimWindow.master.rootWindow;
5482 if(active && state == minimized && window.parent) // && (!window.nativeDecorations || window.rootWindow != window)
5483 // SetState(normal, false, 0);
5484 SetState(lastState, false, 0);
5486 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5490 /* WTH is this doing here?
5491 while(swap && swap.activeChild)
5493 swap = swap.activeChild;
5496 // TESTING THIS BEFORE...
5497 if(interimWindow && this == interimMaster)
5501 // Window interimSwap = this;
5502 Window menuBar = this.menuBar;
5503 if(menuBar && interimWindow.master == menuBar)
5506 while(interimSwap && interimSwap.activeChild)
5507 interimSwap = interimSwap.activeChild;
5509 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5510 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5512 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5513 //result = ActivateEx(true, true, false, activateRoot, window, null);
5518 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5519 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5521 if(interimWindow == this && interimMaster && !active)
5523 while(interimMaster && interimMaster.interim && interimMaster.master)
5525 // printf("Going up one master %s\n", interimMaster._class.name);
5526 interimMaster = interimMaster.master.rootWindow;
5528 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5529 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5535 bool DestroyEx(int64 returnCode)
5538 Timer timer, nextTimer;
5540 OldLink prevOrder = null;
5541 Window client = null;
5543 if(parent) stopwatching(parent, font);
5545 // if(window.modalSlave) return false;
5546 if(destroyed || !created)
5553 OldLink slave = master.slaves.FindLink(this);
5554 master.slaves.Delete(slave);
5557 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5563 this.returnCode = (DialogResult)returnCode;
5565 AcquireInput(false);
5570 master.hotKeys.Delete(hotKey);
5574 if(guiApp.prevWindow == this)
5576 guiApp.prevWindow = null;
5581 for(w : guiApp.overWindows; w == this)
5584 guiApp.overWindows.TakeOut(w);
5588 if(guiApp.caretOwner == this)
5590 guiApp.interfaceDriver.SetCaret(0,0,0);
5591 UpdateCaret(false, true);
5592 guiApp.caretEnabled = false;
5597 parent.childrenCycle.Remove(cycle);
5601 OldLink tmpPrev = order.prev;
5602 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5603 prevOrder = tmpPrev;
5606 client = tmpPrev ? tmpPrev.data : null;
5607 if(client == this) { client = null; break; }
5608 if(client && (client.style.hidden || client.destroyed || !client.created))
5609 tmpPrev = client.order.prev;
5613 prevOrder = tmpPrev;
5618 // If this window can be an active client, make sure the next window we activate can also be one
5619 if(!style.nonClient && style.isActiveClient)
5621 tmpPrev = prevOrder;
5624 client = tmpPrev ? tmpPrev.data : null;
5625 if(client == this) { client = null; break; }
5626 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5627 tmpPrev = client.order.prev;
5631 prevOrder = tmpPrev;
5635 if(client && client.style.hidden) client = null;
5637 // parent.childrenOrder.Remove(order);
5640 if(parent && style.isActiveClient && visible)
5642 if(state == minimized) parent.numIcons--;
5643 parent.numPositions--;
5646 // TESTING THIS HERE!
5650 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5651 // to create a window inside a rootwindow that's being destroyed)
5652 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5654 if(master && !master.destroyed /*&&
5655 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5657 if(master.defaultControl == this)
5658 master.defaultControl = null;
5661 parent.OnChildAddedOrRemoved(this, true);
5662 if(parent && !parent.destroyed /*&&
5663 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5665 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5667 if(order && prevOrder && prevOrder.data != this && active)
5669 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5671 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5672 if(parent.activeClient == this)
5674 parent.activeClient = null;
5675 parent.UpdateActiveDocument(null);
5680 if(guiApp.interimWindow == this)
5683 PropagateActive(false, null, &goOn, true);
5687 //if(window.parent.activeChild == window)
5688 parent.activeChild = null;
5689 if(!style.nonClient /*&& style.isActiveClient*/)
5691 Window previous = parent.activeClient;
5692 if(style.isActiveClient)
5693 parent.activeClient = null;
5694 parent.UpdateActiveDocument(previous);
5699 else if(parent.activeClient == this)
5701 parent.activeClient = client;
5702 parent.UpdateActiveDocument(this);
5706 if(guiApp.interimWindow == this)
5708 guiApp.interimWindow = null;
5709 if(guiApp.caretOwner)
5711 Window desktop = guiApp.desktop;
5712 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5713 guiApp.caretOwner.UpdateCaret(false, false);
5718 if(_isModal && master && master.modalSlave == this)
5719 master.modalSlave = null;
5723 if(!guiApp.caretOwner && parent.caretSize)
5725 guiApp.caretOwner = parent;
5726 parent.UpdateCaret(false, false);
5727 parent.Update(null);
5730 // Why was this commented out?
5731 GetRidOfVirtualArea();
5737 dirtyArea.Free(null);
5738 dirtyBack.Free(null);
5739 scrollExtent.Free(null);
5741 /* ATTEMPTING TO MOVE THAT ABOVE
5750 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5751 for(;(child = window.children.first);)
5753 for(; child && (child.destroyed || !child.created); child = child.next);
5762 UnloadGraphics(true);
5765 delete previousActive;
5768 // statusBar = null;
5771 if(master && !master.destroyed)
5773 //master.NotifyDestroyed(this, this.returnCode);
5774 NotifyDestroyed(master, this, this.returnCode);
5777 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5779 nextTimer = timer.next;
5780 if(timer.window == this)
5782 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5783 // timer.window = null;
5789 if(this == guiApp.windowMoving)
5792 if(guiApp.windowCaptured == this)
5794 //guiApp.windowCaptured = null;
5796 if(rootWindow != this && rootWindow)
5797 rootWindow.ConsequentialMouseMove(false);
5805 //for(child = children.first; next = child ? child.next : null, child; child = next)
5806 for(;(child = children.first); )
5808 for(; child && (child.destroyed || !child.created); child = child.next);
5818 /* // MOVED THIS UP...
5821 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5822 for(;(child = window.children.first); )
5824 for(; child && (child.destroyed || !child.created); child = child.next);
5833 while((slave = slaves.first))
5835 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5837 ((Window)slave.data).DestroyEx(0);
5842 if(guiApp.caretOwner == this)
5843 guiApp.caretOwner = null;
5845 sysButtons[0] = null;
5846 sysButtons[1] = null;
5847 sysButtons[2] = null;
5850 if(rootWindow != this)
5852 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5855 box.left -= parent.clientStart.x;
5856 box.top -= parent.clientStart.y;
5857 box.right -= parent.clientStart.x;
5858 box.bottom -= parent.clientStart.y;
5860 if(parent) parent.Update(box);
5865 OldLink slave = master.slaves.FindVoid(this);
5866 master.slaves.Delete(slave);
5872 parent.children.Remove(this);
5877 //autoCreate = false;
5880 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5881 if(((subclass(Window))_class).pureVTbl)
5883 if(_vTbl == _class._vTbl)
5885 _vTbl = ((subclass(Window))_class).pureVTbl;
5890 for(m = 0; m < _class.vTblSize; m++)
5892 if(_vTbl[m] == _class._vTbl[m])
5893 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5902 void SetStateEx(WindowState newState, bool activate)
5905 WindowState prevState = state;
5909 if(prevState != newState)
5910 lastState = prevState;
5912 if(rootWindow != this || !nativeDecorations || !windowHandle)
5914 if(style.isActiveClient && !style.hidden && prevState == minimized)
5917 // This block used to be at the end of the function... moved it for flicker problem in X
5918 // ------------------------------------------------------
5922 stateAnchor = normalAnchor;
5923 stateSizeAnchor = normalSizeAnchor;
5926 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5927 stateSizeAnchor = SizeAnchor {};
5933 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5936 byte * idBuffer = new0 byte[size];
5938 for(child = parent.children.first; child; child = child.next)
5940 if(child != this && child.state == minimized)
5942 if(child.iconID > size - 2)
5944 idBuffer = renew0 idBuffer byte[size*2];
5945 memset(idBuffer + size, 0, size);
5948 idBuffer[child.iconID] = (byte)bool::true;
5951 for(c = 0; c<size; c++)
5956 if(style.isActiveClient && !style.hidden)
5959 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5960 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5965 // TOCHECK: Why was this here?
5966 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5967 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5968 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5970 if(state != minimized || hasMinimize)
5971 Position(x, y, w, h, true, true, true, true, false, true);
5973 if(!style.inactive && !style.interim && parent && this == parent.activeClient)
5974 parent.UpdateActiveDocument(null);
5977 if(state != minimized || hasMinimize)
5978 CreateSystemChildren();
5979 // ------------------------------------------------------
5982 int GetPositionID(Window forChild)
5986 byte * idBuffer = new0 byte[size];
5989 for(child = children.first; child; child = child.next)
5991 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
5993 if(child.positionID > size - 2)
5995 idBuffer = renew0 idBuffer byte[size*2];
5996 memset(idBuffer + size, 0, size);
5999 idBuffer[child.positionID] = (byte)bool::true;
6002 for(c = 0; c<size; c++)
6009 // --- Window related graphics ---
6011 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
6013 palette = newPalette;
6014 if(rootWindow.display)
6015 rootWindow.display.SetPalette(palette, colorMatch);
6018 public bool AcquireInput(bool acquired)
6021 if(acquiredInput != acquired)
6023 if(active || (!visible && creationActivation == activate))
6024 result = AcquireInputEx(acquired);
6029 acquiredInput = acquired ? result : !result;
6034 void ListChildren(ListBox listBox)
6038 for(child = children.first; child; child = child.next)
6040 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
6042 DataRow row = listBox.AddRow();
6043 row.tag = (int64)(intptr)child;
6044 child.FigureCaption(caption);
6045 row.SetData(null, caption);
6050 void UpdateVisual(Box extent)
6052 if(guiApp.driver != null)
6054 if(guiApp.fullScreenMode && guiApp.desktop.display)
6056 guiApp.desktop.mutex.Wait();
6057 guiApp.desktop.display.Lock(true);
6060 if(guiApp.desktop.active)
6062 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
6064 if(guiApp.desktop.display.flags.flipping)
6065 guiApp.desktop.Update(null);
6066 guiApp.desktop.UpdateDisplay();
6067 guiApp.cursorUpdate = true;
6069 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
6071 guiApp.PreserveAndDrawCursor();
6072 // guiApp.desktop.display.ShowScreen();
6073 guiApp.cursorUpdate = false;
6074 guiApp.desktop.dirty = false;
6075 guiApp.RestoreCursorBackground();
6079 guiApp.desktop.display.Unlock();
6080 guiApp.desktop.mutex.Release();
6084 Window rootWindow = this.rootWindow;
6085 rootWindow.mutex.Wait();
6090 guiApp.SignalEvent();
6093 guiApp.waitMutex.Wait();
6094 guiApp.interfaceDriver.Lock(rootWindow);
6095 if(!rootWindow.style.hidden && rootWindow.dirty)
6097 if(rootWindow.display)
6099 rootWindow.UpdateDisplay();
6100 //rootWindow.display.ShowScreen(null);
6102 rootWindow.dirty = false;
6104 guiApp.interfaceDriver.Unlock(rootWindow);
6105 guiApp.waitMutex.Release();
6108 rootWindow.mutex.Release();
6113 void UnlockDisplay(void)
6115 guiApp.interfaceDriver.Unlock(rootWindow);
6118 void LockDisplay(void)
6120 guiApp.interfaceDriver.Lock(rootWindow);
6123 Surface GetSurface(Box box)
6125 return Redraw((box == null) ? this.box : box);
6128 void SetMousePosition(int x, int y)
6130 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
6134 void IntegrationActivate(bool active)
6136 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
6138 isForegroundWindow = true;
6139 ActivateEx(active, active, false, false, null, null);
6140 isForegroundWindow = false;
6145 Window QueryCapture(void)
6147 return guiApp.windowCaptured;
6150 int GetDocumentID(void)
6154 byte * idBuffer = new0 byte[size];
6157 for(child = children.first; child; child = child.next)
6159 // TO CHECK: Do we want a documentID when we already have a file name?
6160 if(child.style.isDocument && !child.fileName)
6162 if(child.documentID-1 > size - 2)
6164 idBuffer = renew0 idBuffer byte[size*2];
6165 memset(idBuffer + size, 0, size);
6168 idBuffer[child.documentID-1] = 1;
6171 for(c = 0; c<size; c++)
6179 void SetInitSize(Size size)
6182 sizeAnchor.size = size;
6183 normalSizeAnchor = sizeAnchor;
6185 // Break the anchors for moveable/resizable windows
6186 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6188 stateAnchor = normalAnchor;
6189 stateSizeAnchor = normalSizeAnchor;
6191 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6192 Position(x,y, w, h, true, true, true, true, false, true);
6196 void MenuMoveOrSize(bool resize, bool setCursorPosition)
6198 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
6200 guiApp.windowIsResizing = resize;
6201 guiApp.windowMoving = this;
6202 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
6203 if(guiApp.windowIsResizing)
6205 guiApp.windowMovingStart.x += size.w - 1;
6206 guiApp.windowMovingStart.y += size.h - 1;
6208 guiApp.windowMovingBefore = scrolledPos;
6209 guiApp.windowResizingBefore = size;
6210 guiApp.windowMoving.UpdateDecorations();
6211 if(guiApp.windowIsResizing)
6212 guiApp.resizeEndX = guiApp.resizeEndY = true;
6214 if(setCursorPosition)
6215 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
6219 guiApp.interfaceDriver.GetMousePosition(&x, &y);
6220 guiApp.windowMovingStart.x += x - absPosition.x;
6221 guiApp.windowMovingStart.y += y - absPosition.y;
6224 if(guiApp.windowMoving)
6226 if(guiApp.windowMoving.style.nonClient)
6227 guiApp.windowMoving.parent.SetMouseRangeToWindow();
6229 guiApp.windowMoving.parent.SetMouseRangeToClient();
6234 if(this == rootWindow)
6235 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
6239 void SetupFileMonitor()
6243 fileMonitor = FileMonitor
6245 this, FileChange { modified = true };
6247 bool OnFileNotify(FileChange action, const char * param)
6250 fileMonitor.StopMonitoring();
6251 if(OnFileModified(action, param))
6252 fileMonitor.StartMonitoring();
6265 bool result = false;
6269 else if(guiApp && guiApp.driver != null)
6271 OldLink slaveHolder;
6273 bool visible = !style.hidden;
6277 systemParent = parent;
6278 parent = guiApp.desktop;
6280 last = parent ? parent.children.last : null;
6282 if((parent && parent != guiApp.desktop && !parent.created) ||
6283 (master && master != guiApp.desktop && !master.created))
6287 stopwatching(parent, font);
6290 property::parent = guiApp.desktop;
6291 if(!master) master = parent;
6293 if(_isModal && master.modalSlave)
6294 property::master = master.modalSlave;
6298 parent.children.Remove(this);
6301 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
6302 if(slaveHolder.data == this)
6304 master.slaves.Delete(slaveHolder);
6309 if(parent == guiApp.desktop && !mutex)
6312 if(style.isDocument)
6315 parent.numDocuments--;
6316 documentID = parent.GetDocumentID();
6319 if(!style.stayOnTop)
6320 for(; last && last.style.stayOnTop; last = last.prev);
6322 parent.children.Insert((last == this) ? null : last, this);
6323 //parent.children.Add(this);
6326 dispDriver = parent.dispDriver;
6329 master.modalSlave = this;
6331 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
6336 master.slaves.Add(slaveHolder = OldLink { data = this });
6341 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
6343 if(style.isDefault && !master.defaultControl)
6344 master.defaultControl = this;
6346 stateAnchor = normalAnchor = anchor;
6347 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
6349 // TOCHECK: Why is this here?
6350 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
6351 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
6353 this.visible = false;
6354 style.hidden = true;
6357 // autoCreate = true;
6365 if(parent == guiApp.desktop)
6366 Log("LoadGraphics %s\n", caption);
6368 if(LoadGraphics(true, false))
6376 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6383 if(style.hasMenuBar /*&& menu*/)
6389 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6390 interim = false, inactive = true, nonClient = true, size.h = 24
6398 // Create the system buttons
6399 CreateSystemChildren();
6401 UpdateActiveDocument(null);
6403 if(style.isDocument)
6407 MenuItem item = menu.FindItem(MenuFileSave, 0);
6408 if(item) item.disabled = !modifiedDocument && fileName;
6413 if(parent == guiApp.desktop)
6414 Log("Preemptive SetState %s\n", caption);
6417 // Preemptive Set State to ensure proper anchoring
6418 SetStateEx(state, false);
6420 style.hidden = true;
6426 for(child = children.first; child; child = next)
6429 if(!child.created && (child.autoCreate || child.wasCreated))
6436 for(link = slaves.first; link; link = next)
6438 Window slave = link.data;
6440 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6443 // Things might have happened that invalidated 'next'...
6444 // Start over the search for slaves to create.
6445 // (Added this to fix crash with Stacker & Toolbar)
6446 next = slaves.first;
6455 if(parent == guiApp.desktop)
6456 Log("Real SetState %s\n", caption);
6459 if(isActiveClient && visible)
6461 parent.numPositions--;
6462 if(state == minimized) parent.numIcons--;
6465 parent.OnChildAddedOrRemoved(this, false);
6467 if(rootWindow == this && visible) // So that X11 windows don't show as 'unknown'
6469 // Real set state & activate for proper display & activation
6470 property::visible = visible;
6471 // SetState(state & 0x00000003, true, 0);
6472 guiApp.interfaceDriver.SetIcon(this, icon);
6477 /*if(rootWindow == this)
6478 guiApp.interfaceDriver.ActivateRootWindow(this);
6480 if(creationActivation == activate && guiApp.desktop.active)
6481 ActivateEx(true, false, true, true, null, null);
6482 else if(creationActivation == activate || creationActivation == flash)
6485 if(this == rootWindow)
6490 if(!destroyed && !noConsequential)
6491 rootWindow.ConsequentialMouseMove(false);
6502 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6508 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6510 //style.hidden = true; // !visible;
6511 style.hidden = !visible;
6512 if(master.modalSlave == this)
6513 master.modalSlave = null;
6520 void WriteCaption(Surface surface, int x, int y)
6523 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6526 void Update(Box region)
6532 rootWindow = this.rootWindow;
6534 // rootWindow.mutex.Wait();
6535 if(!destroyed && visible && display)
6540 // Testing this to avoid repetitve full update to take time...
6541 if(rootWindow.fullRender)
6543 rootWindow.dirty = true;
6546 if(dirtyArea.count == 1)
6548 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6549 if(item.box.left <= box.left &&
6550 item.box.top <= box.top &&
6551 item.box.right >= box.right &&
6552 item.box.bottom >= box.bottom)
6554 rootWindow.dirty = true;
6559 if(display.flags.flipping && !rootWindow.dirty)
6561 if(this == rootWindow)
6565 rootWindow.Update(null);
6570 rootWindow.dirty = true;
6575 realBox.left += clientStart.x;
6576 realBox.top += clientStart.y;
6577 realBox.right += clientStart.x;
6578 realBox.bottom += clientStart.y;
6584 if(realBox.right >= realBox.left &&
6585 realBox.bottom >= realBox.top)
6587 // if(!rootWindow.fullRender)
6588 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6590 for(child = children.first; child; child = child.next)
6595 box.left -= child.absPosition.x - absPosition.x;
6596 box.top -= child.absPosition.y - absPosition.y;
6597 box.right -= child.absPosition.x - absPosition.x;
6598 box.bottom -= child.absPosition.y - absPosition.y;
6599 if(box.right >= child.box.left && box.left <= child.box.right &&
6600 box.bottom >= child.box.top && box.top <= child.box.bottom)
6602 box.left -= child.clientStart.x;
6603 box.top -= child.clientStart.y;
6604 box.right -= child.clientStart.x;
6605 box.bottom -= child.clientStart.y;
6611 realBox.left += absPosition.x - rootWindow.absPosition.x;
6612 realBox.top += absPosition.y - rootWindow.absPosition.y;
6613 realBox.right += absPosition.x - rootWindow.absPosition.x;
6614 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6615 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6618 else if(this == guiApp.desktop)
6621 for(window = children.first; window; window = window.next)
6627 Box childBox = region;
6629 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6630 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6631 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6632 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6634 window.Update(childBox);
6637 window.Update(null);
6642 // rootWindow.mutex.Release();
6649 if(guiApp.windowCaptured != this)
6651 if(guiApp.windowCaptured)
6655 //Logf("Captured %s (%s)\n", caption, class.name);
6656 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6657 guiApp.windowCaptured = this;
6663 bool Destroy(int64 code)
6668 if(!destroyed && !CloseConfirmation(false)) return false;
6672 // TOCHECK: Should autoCreate be set to false here?
6683 void Move(int x, int y, int w, int h)
6685 normalAnchor = Anchor { left = x, top = y };
6686 normalSizeAnchor = SizeAnchor { size = { w, h } };
6688 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6690 if(destroyed) return;
6692 stateAnchor = normalAnchor;
6693 stateSizeAnchor = normalSizeAnchor;
6695 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6696 Position(x,y, w, h, true, true, true, true, false, true);
6700 DialogResult Modal(void)
6706 // FIXES MEMORY LEAK IF Create() FAILED
6712 void SetScrollArea(int width, int height, bool snapToStep)
6716 int stepX = sbStep.x, stepY = sbStep.y;
6717 // Needed to make snapped down position match the skin's check of client area
6718 // against realvirtual
6721 SNAPDOWN(stepX, textCellW);
6722 SNAPDOWN(stepY, textCellH);
6723 stepX = Max(stepX, textCellW);
6724 stepY = Max(stepY, textCellH);
6726 if(scrollFlags.snapX)
6727 SNAPUP(width, stepX);
6728 if(scrollFlags.snapY)
6729 SNAPUP(height, stepY);
6732 reqScrollArea.w = width;
6733 reqScrollArea.h = height;
6734 noAutoScrollArea = (width > 0 || height > 0);
6736 UpdateScrollBars(true, true);
6739 void SetScrollPosition(int x, int y)
6742 sbh.Action(setPosition, x, 0);
6746 int seen = clientSize.w, total = reqScrollArea.w;
6748 if(scrollFlags.snapX)
6749 SNAPDOWN(seen, sbStep.x);
6751 if(!total) total = seen;
6752 range = total - seen + 1;
6753 range = Max(range, 1);
6755 if(x >= range) x = range - 1;
6757 if(scrollFlags.snapX)
6758 SNAPUP(x, sbStep.x);
6761 OnHScroll(setPosition, x, 0);
6765 SNAPDOWN(x, textCellW);
6771 sbv.Action(setPosition, y, 0);
6775 int seen = clientSize.h, total = reqScrollArea.h;
6778 if(scrollFlags.snapY)
6779 SNAPDOWN(seen, sbStep.y);
6781 if(!total) total = seen;
6782 range = total - seen + 1;
6783 range = Max(range, 1);
6785 if(y >= range) y = range - 1;
6787 if(scrollFlags.snapY)
6788 SNAPUP(y, sbStep.y);
6791 OnVScroll(setPosition, y, 0);
6794 SNAPDOWN(y, textCellH);
6799 UpdateCaret(false, false);
6802 void SetScrollLineStep(int stepX, int stepY)
6808 SNAPDOWN(stepX, textCellW);
6809 SNAPDOWN(stepY, textCellH);
6810 stepX = Max(stepX, textCellW);
6811 stepY = Max(stepY, textCellH);
6814 sbh.lineStep = stepX;
6816 sbv.lineStep = stepY;
6819 void SetState(WindowState newState, bool activate, Modifiers mods)
6823 if(state == newState || OnStateChange(newState, mods))
6825 //WindowState prevState = state;
6829 // This used to be at the end of the brackets... moved for X, testing...
6830 // This has the effect of activating the window through the system...
6831 if(rootWindow == this)
6832 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6834 SetStateEx(newState, activate);
6836 if(rootWindow == this && !rootWindow.nativeDecorations)
6838 int x = position.x, y = position.y;
6841 x -= guiApp.desktop.absPosition.x;
6842 y -= guiApp.desktop.absPosition.y;
6844 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6848 //state = prevState;
6850 if(state != maximized && style.hasMaximize)
6853 for(child = parent.children.first; child; child = child.next)
6855 if(child != this && child.state == maximized)
6856 child.SetStateEx(normal, false);
6860 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6861 parent.UpdateScrollBars(true, true);
6864 // Do we really need this stuff here?
6865 // Shouldn't the Activate stuff take care of it?
6866 if(parent.rootWindow == parent && style)
6869 parent.FigureCaption(caption);
6870 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6871 parent.UpdateDecorations();
6875 rootWindow.ConsequentialMouseMove(false);
6882 BitmapResource GetIcon(SkinBitmap iconID)
6884 return guiApp.currentSkin.GetBitmap(iconID);
6887 void SetMouseRange(Box range)
6889 if(range || guiApp.fullScreenMode)
6894 clip.left = range.left + absPosition.x + clientStart.x;
6895 clip.top = range.top + absPosition.y + clientStart.y;
6896 clip.right = range.right + absPosition.x + clientStart.x;
6897 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6901 clip.left = guiApp.desktop.box.left;
6902 clip.top = guiApp.desktop.box.top;
6903 clip.right = guiApp.desktop.box.right;
6904 clip.bottom = guiApp.desktop.box.bottom;
6906 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6909 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6912 void SetMouseRangeToClient(void)
6914 if(guiApp.fullScreenMode || this != guiApp.desktop)
6916 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6917 box.Clip(clientArea);
6921 SetMouseRange(null);
6924 void SetMouseRangeToWindow(void)
6926 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6927 if(this == guiApp.desktop)
6928 SetMouseRangeToClient();
6933 // x, y: Desktop Coordinates
6934 void ShowSysMenu(int x, int y)
6937 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6940 menu, $"Restore", r, NotifySelect = MenuWindowRestore,
6941 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6945 menu, $"Move", m, NotifySelect = MenuWindowMove,
6946 disabled = !style.fixed || state == maximized
6950 menu, $"Size", s, NotifySelect = MenuWindowSize,
6951 disabled = !style.sizable || state != normal
6955 menu, $"Minimize", n, NotifySelect = MenuWindowMinimize,
6956 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6960 menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6961 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6965 menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6966 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6968 MenuDivider { menu };
6971 menu, $"Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6972 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6974 windowMenu.Create();
6979 ActivateEx(true, true, true, true, null, null);
6982 void MakeActive(void)
6984 ActivateEx(true, false, true, false, null, null);
6987 void SoftActivate(void)
6989 if(guiApp.desktop.active)
6994 if(this == rootWindow)
6999 void Deactivate(void)
7001 ActivateEx(false, true, true, true, null, null);
7006 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
7009 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
7011 bool result = false;
7012 if(activeChild && activeChild.cycle)
7014 Window modalWindow, child = activeChild;
7015 if(!clientOnly /*&& parent.tabCycle*/)
7017 Window next = child;
7020 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
7024 if(parent && parent.CycleChildren(backward, false, true, true))
7032 next = next.cycle.prev.data;
7034 next = next.cycle.next.data;
7035 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
7040 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
7041 parent.tabCycle && parent.CycleChildren(backward, false, false))
7045 if(tabCycleOnly && !tabCycle) return false;
7052 child = child.cycle.prev.data;
7054 child = child.cycle.next.data;
7055 if(child == child.parent.activeChild)
7057 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
7060 modalWindow = child.FindModal();
7063 // Scroll the window to include the active control
7064 if(sbh && !child.style.dontScrollHorz)
7066 if(child.scrolledPos.x < 0)
7067 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
7068 else if(child.scrolledPos.x + child.size.w > clientSize.w)
7069 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
7071 if(sbv && !child.style.dontScrollVert)
7073 if(child.scrolledPos.y < 0)
7074 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
7075 else if(child.scrolledPos.y + child.size.h > clientSize.h)
7076 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
7080 child = modalWindow ? modalWindow : child;
7081 child.ActivateEx(true, true, true, true, null, null);
7082 if(child.tabCycle && child.childrenCycle.first)
7083 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
7091 ConsequentialMouseMove(false);
7095 void AddResource(Resource resource)
7099 ResPtr ptr { resource = resource };
7103 // Load Graphics here if window is created already
7104 if(/*created && */display)
7106 display.Lock(false);
7107 if(!ptr.loaded) // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
7108 ptr.loaded = display.displaySystem.LoadResource(resource);
7112 // Temporary hack to load font right away for listbox in dropbox ...
7113 else if(master && master.display)
7115 master.display.Lock(false);
7116 master.display.displaySystem.LoadResource(resource);
7117 master.display.Unlock();
7123 void RemoveResource(Resource resource)
7128 for(ptr = resources.first; ptr; ptr = ptr.next)
7130 if(ptr.resource == resource)
7136 // Unload Graphics here if window is created already
7137 if(/*created && */display)
7141 display.Lock(false);
7142 display.displaySystem.UnloadResource(resource, ptr.loaded);
7148 resources.Delete(ptr);
7153 void SetCaret(int x, int y, int size)
7160 if(active && !style.interim && isEnabled)
7162 if(visible || !guiApp.caretOwner)
7163 guiApp.caretOwner = size ? this : null;
7165 UpdateCaret(false, false);
7168 guiApp.interfaceDriver.SetCaret(0,0,0);
7169 UpdateCaret(false, true);
7170 guiApp.caretEnabled = false;
7173 else if(style.inactive && active)
7175 guiApp.interfaceDriver.SetCaret(0,0,0);
7176 UpdateCaret(false, true);
7177 guiApp.caretEnabled = false;
7182 void Scroll(int x, int y)
7184 bool opaque = !style.drawBehind || background.a;
7185 if(opaque && display && display.flags.scrolling)
7187 Box box = clientArea;
7188 box.left += clientStart.x;
7189 box.top += clientStart.y;
7190 box.right += clientStart.x;
7191 box.bottom += clientStart.y;
7193 //scrollExtent.Free(null);
7194 scrollExtent.AddBox(box);
7195 scrolledArea.x += x;
7196 scrolledArea.y += y;
7198 //scrollExtent.Free();
7199 //scrollExtent.AddBox(clientArea);
7200 //scrollExtent.Offset(clientStart.x, clientStart.y);
7201 //scrolledArea.x = x;
7202 //scrolledArea.y = y;
7208 rootWindow.dirty = true;
7211 void ReleaseCapture()
7213 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
7215 Window oldCaptured = guiApp.windowCaptured;
7216 guiApp.windowCaptured = null;
7217 guiApp.prevWindow = null;
7220 //guiApp.Log("Released Capture\n");
7222 guiApp.interfaceDriver.SetMouseCapture(null);
7224 //oldCaptured.OnMouseCaptureLost();
7227 oldCaptured.ConsequentialMouseMove(false);
7232 private void _SetCaption(const char * format, va_list args)
7239 char caption[MAX_F_STRING];
7240 vsnprintf(caption, sizeof(caption), format, args);
7241 caption[sizeof(caption)-1] = 0;
7243 this.caption = CopyString(caption);
7248 firewatchers caption;
7252 /*deprecated*/ void SetText(const char * format, ...)
7255 va_start(args, format);
7256 _SetCaption(format, args);
7260 void SetCaption(const char * format, ...)
7263 va_start(args, format);
7264 _SetCaption(format, args);
7268 bool Grab(Bitmap bitmap, Box box, bool decorations)
7270 bool result = false;
7271 if(display || this == guiApp.desktop)
7273 Box clip = {MININT, MININT, MAXINT, MAXINT};
7279 clip.Clip(clientArea);
7281 clip.Clip(this.box);
7283 if(rootWindow != this)
7285 clip.left += absPosition.y;
7286 clip.top += absPosition.y;
7287 clip.right += absPosition.x;
7288 clip.bottom += absPosition.y;
7291 if(!nativeDecorations)
7293 clip.left += decorations ? 0 : clientStart.x;
7294 clip.top += decorations ? 0 : clientStart.y;
7295 clip.right += decorations ? 0 : clientStart.x;
7296 clip.bottom += decorations ? 0 : clientStart.y;
7299 if(decorations && this == guiApp.desktop)
7300 clip = { 0, 0, guiApp.virtualScreen.w, guiApp.virtualScreen.h };
7302 if(display && display.flags.flipping)
7304 rootWindow.Update(null);
7305 rootWindow.UpdateDisplay();
7312 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
7313 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7317 result = display.Grab(bitmap, clip.left, clip.top,
7318 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7320 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
7322 if(!bitmap.Convert(null, pixelFormat888, null))
7329 void GetMousePosition(int * x, int * y)
7331 int mouseX = 0, mouseY = 0;
7332 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
7335 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
7336 if(this != guiApp.desktop)
7338 mouseX -= absPosition.x + clientStart.x;
7339 mouseY -= absPosition.y + clientStart.y;
7346 DialogResult DoModal()
7348 DialogResult returnCode = 0;
7349 int terminated = terminateX;
7352 while(!destroyed && guiApp.driver != null)
7354 if(terminateX != terminated)
7356 terminated = terminateX;
7357 guiApp.desktop.Destroy(0);
7358 if(guiApp.desktop.created)
7361 //printf("Resetting terminate X to 0\n");
7367 guiApp.UpdateDisplay();
7368 if(!guiApp.ProcessInput(false))
7371 returnCode = this.returnCode;
7384 return !destroyed && guiApp.driver != null && terminateX < 2;
7387 DialogResult DoModalEnd()
7389 DialogResult returnCode = this.returnCode;
7394 // --- Window manipulation ---
7395 /*bool GetDisabled()
7397 bool disabled = this.disabled;
7399 for(window = this; (window = window.master); )
7410 // --- Mouse Manipulation ---
7411 void GetNCMousePosition(int * x, int * y)
7413 GetMousePosition(x, y);
7414 if(x) *x += clientStart.x;
7415 if(y) *y += clientStart.y;
7418 // --- Carets manipulation ---
7419 void GetCaretPosition(Point caretPos)
7421 caretPos = this.caretPos;
7424 int GetCaretSize(void)
7429 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7435 bool CloseConfirmation(bool parentClosing)
7448 if(!OnClose(parentClosing))
7451 // If you want to skip this, simply set modifiedDocument to false in OnClose
7452 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7454 DialogResult dialogRes;
7457 sprintf(message, $"Save changes to %s?", fileName);
7459 sprintf(message, $"Save changes to Untitled %d?", documentID);
7461 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = message }.Modal();
7463 if(dialogRes == yes)
7465 // TOFIX: Precomp error if brackets are taken out
7466 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7468 else if(dialogRes == cancel)
7474 for(slave = slaves.first; slave; slave = slave.next)
7476 Window w = slave.data;
7477 if(w.parent != this && !w.IsDescendantOf(this) && !w.CloseConfirmation(true))
7485 // Confirm closure of active clients first (We use OnClose() to hide instead of destroy in the IDE)
7488 for(child = children.first; child; child = child.next)
7489 if(child.isActiveClient && !child.CloseConfirmation(true))
7497 for(child = children.first; child; child = child.next)
7498 if(!child.isActiveClient && !child.CloseConfirmation(true))
7508 // Static methods... move them somewhere else?
7509 void ::RestoreCaret()
7511 if(guiApp.caretOwner)
7512 guiApp.caretOwner.UpdateCaret(false, false);
7515 void ::FreeMouseRange()
7517 guiApp.interfaceDriver.SetMouseRange(null, null);
7521 bool MenuFileClose(MenuItem selection, Modifiers mods)
7523 Window document = activeChild;
7525 document.Destroy(0);
7529 bool MenuFileExit(MenuItem selection, Modifiers mods)
7535 bool MenuFileSave(MenuItem selection, Modifiers mods)
7540 fileMonitor.fileName = null;
7543 if(OnSaveFile(fileName))
7545 //if(OnFileModified != Window::OnFileModified)
7548 fileMonitor.fileName = fileName;
7554 MessageBox dialog { master = master, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7555 DialogResult answer = dialog.Modal();
7557 if(answer != yes) return (bool)answer;
7560 return MenuFileSaveAs(selection, mods);
7563 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7565 DialogResult result = (DialogResult)bool::true;
7566 FileDialog fileDialog = saveDialog;
7571 fileDialog = FileDialog {};
7576 fileDialog.filePath = fileName;
7579 char filePath[MAX_FILENAME];
7580 sprintf(filePath, "Untitled %d", documentID);
7581 fileDialog.filePath = filePath;
7583 fileMonitor.fileName = null;
7585 fileDialog.type = save;
7586 fileDialog.text = $"Save As";
7590 fileDialog.master = master.parent ? master : this;
7591 if(fileDialog.Modal() == ok)
7593 const char * filePath = fileDialog.filePath;
7595 if(OnSaveFile(filePath))
7598 property::fileName = filePath;
7599 NotifySaved(master, this, filePath);
7604 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7605 DialogResult answer = dialog.Modal();
7620 //if(OnFileModified != Window::OnFileModified && fileName)
7623 fileMonitor.fileName = fileName;
7627 return (bool)result; // Actually returning result from Yes/NoCancel message box
7630 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7632 Window document = activeChild;
7634 for(document = children.first; document; document = next)
7636 next = document.next;
7637 if(document.style.isDocument || document.fileName)
7638 document.MenuFileSave(selection, mods);
7643 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7647 for(document = children.first; document; document = document.next)
7648 //if(document.style.isDocument && document.state == minimized)
7649 if(document.style.isActiveClient && document.state == minimized)
7650 document.SetState(minimized, false, mods);
7654 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7656 Window document = activeChild;
7659 Window firstDocument = null;
7661 OldLink cycle = document.cycle.prev;
7666 if(child.style.isActiveClient && !child.style.hidden)
7670 firstDocument = child;
7671 if(child.state == minimized)
7672 child.SetState(minimized, false, mods);
7675 child.positionID = id++;
7676 child.SetState(normal, false, mods);
7677 child.anchor.left.type = cascade;
7680 child.normalSizeAnchor = *&child.sizeAnchor;
7681 child.normalAnchor = child.anchor;
7683 // Break the anchors for moveable/resizable windows
7684 if(child.style.fixed)
7686 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7688 (*&child.normalAnchor).left = x;
7689 (*&child.normalAnchor).top = y;
7690 (*&child.normalAnchor).right.type = none;
7691 (*&child.normalAnchor).bottom.type = none;
7692 (*&child.normalSizeAnchor).isClientW = false;
7693 (*&child.normalSizeAnchor).isClientH = false;
7694 (*&child.normalSizeAnchor).size.w = w;
7695 (*&child.normalSizeAnchor).size.h = h;
7696 child.anchored = false;
7699 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7701 child.stateAnchor = child.normalAnchor;
7702 child.stateSizeAnchor = child.normalSizeAnchor;
7704 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7705 child.Position(x, y, w, h, true, true, true, true, false, false);
7710 last = children.last;
7711 if(!child.style.stayOnTop)
7712 for(; last && last.style.stayOnTop; last = last.prev);
7713 children.Move(child, last);
7714 childrenOrder.Move(child.order, childrenOrder.last);
7716 if(cycle == document.cycle) break;
7720 firstDocument.Activate();
7725 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7732 // Close all closes all active clients, not all documents
7733 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7735 Window next, document;
7737 for(document = children.first; document; document = next)
7739 for(next = document.next; next && !next.style.isActiveClient; next = next.next);
7740 if(document.style.isActiveClient)
7741 if(!document.Destroy(0) && !document.style.hidden)
7747 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7749 if(style.hasMaximize && state != maximized)
7750 SetState(maximized, 0, 0);
7754 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7756 if(style.hasMinimize && state != minimized)
7758 SetState(minimized, 0, 0);
7759 parent.CycleChildren(false, true, false, true);
7764 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7766 MenuMoveOrSize(false, selection ? true : false);
7770 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7772 CycleChildren(false, true, false, true);
7776 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7778 CycleChildren(true, true, false, true);
7782 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7784 MenuMoveOrSize(true, true);
7788 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7791 SetState(normal, 0, 0);
7795 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7798 int64 id = selection.id;
7799 OldLink cycle = activeClient.cycle;
7801 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7804 Window sibling = cycle.data;
7805 if(sibling.style.isActiveClient && sibling.visible && !sibling.style.nonClient)
7813 document = cycle.data;
7814 document.Activate();
7816 //if(activeChild.state == maximized)
7817 // document.SetState(maximized, false, mods);
7818 //else if(document.state == minimized)
7819 // document.SetState(normal, false, mods);
7823 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7825 stayOnTop = !style.stayOnTop;
7829 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7831 Window document = activeChild;
7834 Window firstDocument = null;
7835 OldLink cycle = document.cycle;
7839 Window child = cycle.data;
7840 if(child.style.isActiveClient && !child.style.hidden)
7842 if(!firstDocument) firstDocument = child;
7843 if(child.state == minimized)
7844 child.SetState(minimized, false, mods);
7847 child.positionID = id++;
7848 child.SetState(normal, false, mods);
7849 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7851 child.anchor.left.type = hTiled;
7854 child.normalSizeAnchor = *&child.sizeAnchor;
7855 child.normalAnchor = child.anchor;
7857 // Break the anchors for moveable/resizable windows
7858 if(child.style.fixed)
7860 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7862 (*&child.normalAnchor).left = x;
7863 (*&child.normalAnchor).top = y;
7864 (*&child.normalAnchor).right.type = none;
7865 (*&child.normalAnchor).bottom.type = none;
7866 (*&child.normalSizeAnchor).isClientW = false;
7867 (*&child.normalSizeAnchor).isClientH = false;
7868 (*&child.normalSizeAnchor).size.w = w;
7869 (*&child.normalSizeAnchor).size.h = h;
7870 child.anchored = false;
7873 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7875 child.stateAnchor = child.normalAnchor;
7876 child.stateSizeAnchor = child.normalSizeAnchor;
7878 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7879 child.Position(x,y, w, h, true, true, true, true, false, true);
7884 if((cycle = cycle.next) == document.cycle) break;
7887 firstDocument.Activate();
7892 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7894 Window document = activeChild;
7897 Window firstDocument = null;
7899 OldLink cycle = document.cycle;
7904 //if(child.style.isDocument)
7905 if(child.style.isActiveClient && !child.style.hidden)
7907 if(!firstDocument) firstDocument = child;
7908 if(child.state == minimized)
7909 child.SetState(minimized, false, mods);
7912 child.positionID = id++;
7913 child.SetState(normal, false, mods);
7914 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7916 child.anchor.left.type = vTiled;
7919 child.normalSizeAnchor = *&child.sizeAnchor;
7920 child.normalAnchor = child.anchor;
7922 // Break the anchors for moveable/resizable windows
7923 if(child.style.fixed)
7925 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7927 (*&child.normalAnchor).left = x;
7928 (*&child.normalAnchor).top = y;
7929 (*&child.normalAnchor).right.type = none;
7930 (*&child.normalAnchor).bottom.type = none;
7931 (*&child.normalSizeAnchor).isClientW = false;
7932 (*&child.normalSizeAnchor).isClientH = false;
7933 (*&child.normalSizeAnchor).size.w = w;
7934 (*&child.normalSizeAnchor).size.h = h;
7935 child.anchored = false;
7938 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7940 child.stateAnchor = child.normalAnchor;
7941 child.stateSizeAnchor = child.normalSizeAnchor;
7943 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7944 child.Position(x,y, w, h, true, true, true, true, false, true);
7949 if((cycle = cycle.next) == document.cycle) break;
7952 firstDocument.Activate();
7957 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7959 WindowList dialog { master = this };
7960 Window document = (Window)(intptr)dialog.Modal();
7963 if(activeChild.state == maximized)
7964 document.SetState(maximized, false, mods);
7965 else if(document.state == minimized)
7966 document.SetState(normal, false, mods);
7967 document.Activate();
7973 virtual bool OnCreate(void);
7974 virtual void OnDestroy(void);
7975 virtual void OnDestroyed(void);
7976 virtual bool OnClose(bool parentClosing);
7977 virtual bool OnStateChange(WindowState state, Modifiers mods);
7978 virtual bool OnPostCreate(void);
7979 virtual bool OnMoving(int *x, int *y, int w, int h);
7980 virtual bool OnResizing(int *width, int *height);
7981 virtual void OnResize(int width, int height);
7982 virtual void OnPosition(int x, int y, int width, int height);
7983 virtual bool OnLoadGraphics(void);
7984 virtual void OnApplyGraphics(void);
7985 virtual void OnUnloadGraphics(void);
7986 virtual void OnRedraw(Surface surface);
7987 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7988 virtual void OnActivateClient(Window client, Window previous);
7989 virtual bool OnKeyDown(Key key, unichar ch);
7990 virtual bool OnKeyUp(Key key, unichar ch);
7991 virtual bool OnKeyHit(Key key, unichar ch);
7992 virtual bool OnSysKeyDown(Key key, unichar ch);
7993 virtual bool OnSysKeyUp(Key key, unichar ch);
7994 virtual bool OnSysKeyHit(Key key, unichar ch);
7995 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7996 virtual bool OnMouseLeave(Modifiers mods);
7997 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7998 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7999 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
8000 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
8001 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
8002 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
8003 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
8004 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
8005 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
8006 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
8007 virtual bool OnMultiTouch(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods);
8008 virtual void OnMouseCaptureLost(void);
8009 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
8010 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
8011 virtual void OnDrawOverChildren(Surface surface);
8012 virtual bool OnFileModified(FileChange fileChange, const char * param);
8013 virtual bool OnSaveFile(const char * fileName);
8015 // Virtual Methods -- Children management (To support Stacker, for lack of built-in auto-layout)
8016 // Note: A 'client' would refer to isActiveClient, rather than
8017 // being confined to the 'client area' (nonClient == false)
8018 virtual void OnChildAddedOrRemoved(Window child, bool removed);
8019 virtual void OnChildVisibilityToggled(Window child, bool visible);
8020 virtual void OnChildResized(Window child, int x, int y, int w, int h);
8022 // Skins Virtual Functions
8023 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
8024 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
8025 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
8030 virtual void ShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
8031 virtual void PreShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
8032 virtual bool IsMouseMoving(int x, int y, int w, int h)
8036 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY)
8040 virtual void UpdateNonClient();
8041 virtual void SetBox(Box box); // This is used in the MySkin skin
8042 virtual bool IsInside(int x, int y)
8044 return box.IsPointInside({x, y});
8046 virtual bool IsOpaque()
8048 return (!style.drawBehind || background.a == 255);
8052 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
8053 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
8054 virtual void Window::NotifySaved(Window window, const char * filePath);
8059 property Window parent
8061 property_category $"Layout"
8064 if(value || guiApp.desktop)
8067 Window oldParent = parent;
8068 Anchor anchor = this.anchor;
8070 if(value && value.IsDescendantOf(this)) return;
8071 if(value && value == this)
8073 if(!value) value = guiApp.desktop;
8075 if(value == oldParent) return;
8077 if(!master || (master == this.parent && master == guiApp.desktop))
8078 property::master = value;
8082 parent.children.Remove(this);
8086 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
8087 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
8088 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
8089 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
8093 last = value.children.last;
8095 if(style.isDocument)
8098 parent.numDocuments--;
8099 documentID = value.GetDocumentID();
8102 if(style.isActiveClient && !style.hidden)
8104 if(parent && parent != guiApp.desktop && !(style.hidden))
8106 if(state == minimized) parent.numIcons--;
8107 parent.numPositions--;
8111 if(!style.stayOnTop)
8112 for(; last && last.style.stayOnTop; last = last.prev);
8114 value.children.Insert(last, this);
8116 // *** NEW HERE: ***
8118 parent.childrenCycle.Delete(cycle);
8120 parent.childrenOrder.Delete(order);
8123 // *** TODO: Added this here to solve crash on setting parent to null before destroying/destructing ***
8124 // Should something else be done?
8125 if(parent && parent.activeChild == this)
8126 parent.activeChild = null;
8127 if(parent && parent.activeClient == this)
8128 parent.activeClient = null;
8134 int x = position.x, y = position.y, w = size.w, h = size.h;
8138 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
8139 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
8141 vpw = value.clientSize.w;
8142 vph = value.clientSize.h;
8148 else if(style.fixed)
8150 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
8151 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
8154 anchor = this.anchor;
8156 if(anchor.left.type == offset) anchor.left.distance = x;
8157 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
8158 if(anchor.top.type == offset) anchor.top.distance = y;
8159 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
8160 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
8161 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
8162 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
8163 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
8164 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
8165 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
8167 if(!anchor.left.type && !anchor.right.type)
8169 anchor.horz.distance = (x + w / 2) - (vpw / 2);
8170 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
8172 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
8173 if(!anchor.top.type && !anchor.bottom.type)
8175 anchor.vert.distance = (y + h / 2) - (vph / 2);
8176 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
8178 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
8181 parent.OnChildAddedOrRemoved(this, false);
8187 parent.childrenCycle.Insert(
8188 // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
8189 //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8191 cycle = OldLink { data = this });
8192 parent.childrenOrder.Insert(
8193 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8194 order = OldLink { data = this });
8197 if(!style.hidden && style.isActiveClient)
8199 positionID = parent.GetPositionID(this);
8200 parent.numPositions++;
8201 if(state == minimized) parent.numIcons--;
8204 // *** FONT INHERITANCE ***
8205 if(!setFont && oldParent)
8206 stopwatching(oldParent, font);
8210 RemoveResource(systemFont);
8213 // TESTING WITH WATCHERS:
8214 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8215 // usedFont = setFont ? setFont : (systemFont);
8219 if(guiApp.currentSkin)
8221 systemFont = guiApp.currentSkin.SystemFont();
8224 usedFont = systemFont;
8225 AddResource(systemFont);
8233 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8242 if(value.rootWindow && value.rootWindow.display && rootWindow && created)
8244 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
8245 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
8248 UnloadGraphics(false);
8251 LoadGraphics(false, false);
8254 if(value.rootWindow != rootWindow)
8255 DisplayModeChanged();
8259 scrolledPos.x = MININT; // Prevent parent update
8261 bool anchored = this.anchored;
8262 property::anchor = anchor;
8263 this.anchored = anchored;
8268 if(guiApp.currentSkin)
8269 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
8271 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8272 Position(x, y, w, h, true, true, true, true, false, true);
8277 // else parent = value;
8279 oldParent.OnChildAddedOrRemoved(this, true);
8282 get { return parent; }
8285 property Window master
8287 property_category $"Behavior"
8290 //if(this == value) return;
8291 if(value && value.IsSlaveOf(this)) return;
8297 OldLink slaveHolder;
8298 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
8299 if(slaveHolder.data == this)
8301 master.slaves.Delete(slaveHolder);
8308 value.slaves.Add(OldLink { data = this });
8313 master.hotKeys.Remove(hotKey);
8314 value.hotKeys.Add(hotKey);
8317 if(master && master.defaultControl == this)
8318 master.defaultControl = null;
8320 if(style.isDefault && !value.defaultControl)
8321 value.defaultControl = this;
8326 get { return master ? master : parent; }
8329 property const char * caption
8331 property_category $"Appearance"
8338 caption = new char[strlen(value)+1];
8340 strcpy(caption, value);
8345 get { return caption; }
8350 property_category $"Behavior"
8359 master.hotKeys.Add(hotKey = HotKeySlot { });
8363 hotKey.window = this;
8368 master.hotKeys.Delete(hotKey);
8373 get { return hotKey ? hotKey.key : 0; }
8376 property Color background
8378 property_category $"Appearance"
8381 background.color = value;
8386 if(this == rootWindow)
8387 guiApp.interfaceDriver.SetRootWindowColor(this);
8390 get { return background.color; }
8393 property Percentage opacity
8395 property_category $"Appearance"
8398 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
8399 drawBehind = (background.a == 255) ? false : true;
8401 get { return background.a / 255.0f; }
8404 property Color foreground
8406 property_category $"Appearance"
8414 get { return foreground; }
8417 property BorderStyle borderStyle
8419 property_category $"Appearance"
8422 if(!((BorderBits)value).fixed)
8424 style.hasClose = false;
8425 style.hasMaximize = false;
8426 style.hasMinimize = false;
8427 nativeDecorations = false;
8429 style.borderBits = value;
8433 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8435 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8436 Position(x, y, w, h, true, true, true, true, false, true);
8437 CreateSystemChildren();
8440 get { return (BorderStyle)style.borderBits; }
8443 property Size minClientSize
8445 property_category $"Layout"
8446 set { minSize = value; }
8447 get { value = minSize; }
8450 property Size maxClientSize
8452 property_category $"Layout"
8453 set { maxSize = value; }
8454 get { value = maxSize; }
8457 property bool hasMaximize
8459 property_category $"Window Style"
8462 style.hasMaximize = value;
8463 if(value) { style.fixed = true; style.contour = true; }
8467 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8469 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8470 Position(x, y, w, h, true, true, true, true, false, true);
8472 CreateSystemChildren();
8475 get { return style.hasMaximize; }
8478 property bool hasMinimize
8480 property_category $"Window Style"
8483 style.hasMinimize = value;
8484 if(value) { style.fixed = true; style.contour = true; }
8488 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8490 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8491 Position(x, y, w, h, true, true, true, true, false, true);
8493 CreateSystemChildren();
8496 get { return style.hasMinimize; }
8499 property bool hasClose
8501 property_category $"Window Style"
8504 style.hasClose = value;
8505 if(value) { style.fixed = true; style.contour = true; }
8509 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8510 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8511 Position(x, y, w, h, true, true, true, true, false, true);
8512 CreateSystemChildren();
8515 get { return style.hasClose; }
8518 property bool nonClient
8520 property_category $"Layout"
8523 style.nonClient = value;
8525 style.stayOnTop = true;
8527 get { return style.nonClient; }
8530 property bool inactive
8532 property_category $"Behavior"
8537 // *** NEW HERE: ***
8541 parent.childrenCycle.Delete(cycle);
8543 parent.childrenOrder.Delete(order);
8550 active = false; // true;
8551 if(parent.activeChild == this)
8552 parent.activeChild = null;
8553 if(parent.activeClient == this)
8554 parent.activeClient = null;
8563 parent.childrenCycle.Insert(
8564 // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
8565 //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8567 cycle = OldLink { data = this });
8569 parent.childrenOrder.Insert(
8570 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8571 order = OldLink { data = this });
8574 style.inactive = value;
8576 get { return style.inactive; }
8579 property bool clickThrough
8581 property_category $"Behavior"
8582 set { style.clickThrough = value; }
8583 get { return style.clickThrough; }
8586 property bool isRemote
8588 property_category $"Behavior"
8589 set { style.isRemote = value; }
8590 get { return style.isRemote; }
8593 property bool noCycle
8595 property_category $"Behavior"
8596 set { style.noCycle = value; }
8597 get { return style.noCycle; }
8600 property bool isModal
8602 property_category $"Behavior"
8603 set { style.modal = value; }
8604 get { return style.modal; }
8607 property bool interim
8609 property_category $"Behavior"
8610 set { style.interim = value; }
8611 get { return style.interim; }
8614 property bool tabCycle
8616 property_category $"Behavior"
8617 set { style.tabCycle = value; }
8618 get { return style.tabCycle; }
8621 property bool isDefault
8623 property_category $"Behavior"
8631 for(sibling = parent.children.first; sibling; sibling = sibling.next)
8632 if(sibling != this && sibling.style.isDefault)
8633 sibling.style.isDefault = false;*/
8634 if(master.defaultControl)
8635 master.defaultControl.style.isDefault = false;
8636 master.defaultControl = this;
8638 else if(master.defaultControl == this)
8639 master.defaultControl = null;
8643 style.isDefault = value;
8645 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8647 get { return style.isDefault; }
8650 property bool drawBehind
8652 property_category $"Window Style"
8653 set { style.drawBehind = value; }
8654 get { return style.drawBehind; }
8657 property bool hasMenuBar
8659 property_category $"Window Style"
8669 if(created && !menuBar)
8676 anchor = Anchor { top = 23, left = 1, right = 1 },
8678 inactive = true, nonClient = true
8683 else if(created && menuBar)
8688 style.hasMenuBar = value;
8690 get { return style.hasMenuBar; }
8693 property bool hasStatusBar
8695 property_category $"Window Style"
8702 statusBar = StatusBar { this };
8710 style.hasStatusBar = value;
8712 get { return style.hasStatusBar; }
8714 property bool stayOnTop
8716 property_category $"Window Style"
8721 if(created && !style.stayOnTop)
8723 if(rootWindow == this)
8724 guiApp.interfaceDriver.OrderRootWindow(this, true);
8725 else if(parent.children.last != this)
8727 parent.children.Move(this, parent.children.last);
8731 style.stayOnTop = true;
8735 if(created && style.stayOnTop)
8737 if(rootWindow == this)
8738 guiApp.interfaceDriver.OrderRootWindow(this, false);
8745 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8746 order && ((Window)order.data).style.stayOnTop;
8747 order = (order == parent.childrenOrder.first) ? null : order.prev);
8748 last = order ? order.data : null;
8752 for(last = parent.children.last;
8753 last && last.style.stayOnTop;
8757 parent.children.Move(this, last);
8761 style.stayOnTop = false;
8764 get { return style.stayOnTop; }
8769 property_category $"Window Style"
8779 if(menuBar && !value)
8786 if(!menuBar && style.hasMenuBar && value)
8790 this, menu = value, isMenuBar = true,
8791 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8792 inactive = true, nonClient = true
8796 UpdateActiveDocument(null);
8799 get { return menu; }
8802 property FontResource font
8804 property_category $"Appearance"
8806 isset { return setFont ? true : false; }
8811 if(value && !setFont) { stopwatching(parent, font); }
8812 else if(!value && setFont)
8818 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8827 RemoveResource(setFont);
8832 RemoveResource(systemFont);
8839 AddResource(setFont);
8842 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8845 systemFont = guiApp.currentSkin.SystemFont();
8847 usedFont = systemFont;
8848 AddResource(systemFont);
8856 get { return usedFont; }
8859 property SizeAnchor sizeAnchor
8861 property_category $"Layout"
8864 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8865 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8866 sizeAnchor.isClientW != sizeAnchor.isClientH;
8873 normalSizeAnchor = sizeAnchor;
8875 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8877 stateAnchor = normalAnchor;
8878 stateSizeAnchor = normalSizeAnchor;
8880 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8881 Position(x,y, w, h, true, true, true, true, false, true);
8888 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8889 sizeAnchor.isClientW,
8890 sizeAnchor.isClientH
8897 property_category $"Layout"
8900 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8901 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8902 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8908 sizeAnchor.isClientW = false;
8909 sizeAnchor.isClientH = false;
8910 sizeAnchor.size = value;
8912 normalSizeAnchor = sizeAnchor;
8914 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8916 stateAnchor = normalAnchor;
8917 stateSizeAnchor = normalSizeAnchor;
8919 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8920 Position(x, y, w, h, true, true, true, true, false, true);
8921 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
8924 get { value = size; }
8927 property Size clientSize
8929 property_category $"Layout"
8932 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8933 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8934 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8939 sizeAnchor.isClientW = true;
8940 sizeAnchor.isClientH = true;
8941 sizeAnchor.size = value;
8943 normalSizeAnchor = sizeAnchor;
8945 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8947 stateAnchor = normalAnchor;
8948 stateSizeAnchor = normalSizeAnchor;
8950 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8951 Position(x,y, w, h, true, true, true, true, false, true);
8952 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
8955 get { value = this ? clientSize : { 0, 0 }; }
8958 property Size initSize { get { value = sizeAnchor.size; } };
8960 property Anchor anchor
8962 property_category $"Layout"
8963 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8969 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8971 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8972 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8974 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8976 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8977 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8981 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8983 anchor.left.distance = 0;
8984 anchor.horz.type = 0;
8986 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8988 anchor.top.distance = 0;
8989 anchor.vert.type = 0;
8998 normalAnchor = anchor;
9000 // Break the anchors for moveable/resizable windows
9001 /*if(style.fixed ) //&& value.left.type == cascade)
9003 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
9005 this.anchor = normalAnchor = Anchor { left = x, top = y };
9006 normalSizeAnchor = SizeAnchor { { w, h } };
9009 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9011 stateAnchor = normalAnchor;
9012 stateSizeAnchor = normalSizeAnchor;
9014 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9015 Position(x, y, w, h, true, true, true, true, false, true);
9024 get { value = this ? anchor : Anchor { }; }
9027 property Point position
9029 property_category $"Layout"
9032 if(value == null) return;
9034 anchor.left = value.x;
9035 anchor.top = value.y;
9036 anchor.right.type = none;
9037 anchor.bottom.type = none;
9042 normalAnchor = anchor;
9044 // Break the anchors for moveable/resizable windows
9048 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9050 normalAnchor.left = x;
9051 normalAnchor.top = y;
9052 normalAnchor.right.type = none;
9053 normalAnchor.bottom.type = none;
9054 normalSizeAnchor.size.width = w;
9055 normalSizeAnchor.size.height = h;
9059 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9061 stateAnchor = normalAnchor;
9062 stateSizeAnchor = normalSizeAnchor;
9064 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9065 Position(x,y, w, h, true, true, true, true, false, true);
9069 get { value = position; }
9072 property bool disabled
9074 property_category $"Behavior"
9077 if(this && disabled != value)
9084 get { return (bool)disabled; }
9087 property bool isEnabled
9092 for(parent = this; parent; parent = parent.parent)
9099 property WindowState state
9101 property_category $"Behavior"
9102 set { SetState(value, false, 0); }
9103 get { return this ? state : 0; }
9106 property bool visible
9108 property_category $"Behavior"
9111 if(this && !value && !style.hidden && parent)
9113 bool wasActiveChild = parent.activeChild == this;
9114 Window client = null;
9116 style.hidden = true;
9117 if(style.isActiveClient)
9119 parent.numPositions--;
9120 if(state == minimized) parent.numIcons--;
9125 OldLink prevOrder = null;
9127 if(rootWindow == this)
9128 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
9131 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
9134 box.left -= parent.clientStart.x;
9135 box.top -= parent.clientStart.y;
9136 box.right -= parent.clientStart.x;
9137 box.bottom -= parent.clientStart.y;
9141 if(_isModal && master && master.modalSlave == this)
9142 master.modalSlave = null;
9146 OldLink tmpPrev = order.prev;
9147 client = tmpPrev ? tmpPrev.data : null;
9148 if(client && !client.style.hidden && !client.destroyed && client.created)
9149 prevOrder = tmpPrev;
9152 client = tmpPrev ? tmpPrev.data : null;
9153 if(client == this) { client = null; break; }
9154 if(client && ((client.style.hidden) || client.destroyed || !client.created))
9156 tmpPrev = client.order.prev;
9161 prevOrder = tmpPrev;
9166 // If this window can be an active client, make sure the next window we activate can also be one
9167 if(!style.nonClient && style.isActiveClient)
9169 tmpPrev = prevOrder;
9172 client = tmpPrev ? tmpPrev.data : null;
9173 if(client == this) { client = null; break; }
9174 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
9176 tmpPrev = client.order.prev;
9181 prevOrder = tmpPrev;
9185 if(client && client.style.hidden) client = null;
9189 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
9191 if(order && prevOrder && prevOrder.data != this)
9192 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
9194 ActivateEx(false, false, false, true, null, null);
9196 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
9197 if(parent.activeClient == this)
9199 parent.activeClient = null;
9200 parent.UpdateActiveDocument(null);
9203 else if(parent.activeClient == this)
9205 parent.activeClient = client;
9206 parent.UpdateActiveDocument(this);
9209 // *** Not doing this anymore ***
9212 parent.childrenCycle.Delete(cycle);
9214 parent.childrenOrder.Delete(order);
9219 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9224 else if(this && value && style.hidden)
9226 style.hidden = false;
9229 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9230 if(rootWindow == this)
9231 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
9233 if(_isModal && master)
9234 master.modalSlave = this;
9236 if(style.isActiveClient)
9238 positionID = parent.GetPositionID(this);
9239 parent.numPositions++;
9240 if(state == minimized) parent.numIcons++;
9243 // *** NOT DOING THIS ANYMORE ***
9245 if(!(style.inactive))
9247 if(!(style.noCycle))
9249 cycle = parent.childrenCycle.AddAfter(
9250 (parent.activeChild && parent.activeChild.cycle) ?
9251 parent.activeChild.cycle.prev : null, sizeof(OldLink));
9254 order = parent.childrenOrder.AddAfter(
9255 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
9262 if(true || !parent.activeChild)
9263 ActivateEx(true, false, true, true, null, null);
9265 if(creationActivation == activate && guiApp.desktop.active)
9266 ActivateEx(true, false, true, true, null, null);
9267 else if((creationActivation == activate || creationActivation == flash) && !object)
9270 if(this == rootWindow)
9274 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9278 ConsequentialMouseMove(false);
9284 style.hidden = !value;
9287 get { return (style.hidden || !setVisible) ? false : true; }
9290 property bool isDocument
9292 property_category $"Document"
9293 set { style.isDocument = value; if(value) SetupFileMonitor(); }
9294 get { return style.isDocument; }
9297 property bool mergeMenus
9299 property_category $"Window Style"
9300 set { mergeMenus = value; }
9301 get { return (bool)mergeMenus; }
9304 property bool hasHorzScroll
9306 property_category $"Window Style"
9311 if(!style.hasHorzScroll && created)
9313 CreateSystemChildren();
9314 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9317 else if(style.hasHorzScroll)
9321 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9323 style.hasHorzScroll = value;
9326 get { return style.hasHorzScroll; }
9329 property bool hasVertScroll
9331 property_category $"Window Style"
9336 if(!style.hasVertScroll && created)
9338 style.hasVertScroll = true;
9339 CreateSystemChildren();
9340 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9343 else if(style.hasVertScroll)
9347 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9349 style.hasVertScroll = value;
9351 get { return style.hasVertScroll; }
9354 property bool dontHideScroll
9356 property_category $"Behavior"
9359 scrollFlags.dontHide = value;
9362 //UpdateScrollBars(true, true);
9363 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9367 // UpdateScrollBars(true, true);
9368 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9371 get { return scrollFlags.dontHide; }
9374 property bool dontScrollVert
9376 property_category $"Behavior"
9377 set { style.dontScrollVert = value; }
9378 get { return style.dontScrollVert; }
9380 property bool dontScrollHorz
9382 property_category $"Behavior"
9383 set { style.dontScrollHorz = value; }
9384 get { return style.dontScrollHorz; }
9387 property bool snapVertScroll
9389 property_category $"Behavior"
9392 scrollFlags.snapY = value;
9393 if(sbv) sbv.snap = value;
9395 get { return scrollFlags.snapY; }
9397 property bool snapHorzScroll
9399 property_category $"Behavior"
9402 scrollFlags.snapX = value;
9403 if(sbh) sbh.snap = value;
9405 get { return scrollFlags.snapX; }
9408 property Point scroll
9410 property_category $"Behavior"
9411 set { if(this) SetScrollPosition(value.x, value.y); }
9412 get { value = scroll; }
9415 property bool modifyVirtualArea
9417 property_category $"Behavior"
9418 set { modifyVirtArea = value; }
9419 get { return (bool)modifyVirtArea; }
9422 property bool dontAutoScrollArea
9424 property_category $"Behavior"
9425 // Activating a child control out of view will automatically scroll to make it in view
9426 set { noAutoScrollArea = value; }
9427 get { return (bool)noAutoScrollArea; }
9430 property const char * fileName
9432 property_category $"Document"
9437 if(menu && ((!fileName && value) || (fileName && !value)))
9439 MenuItem item = menu.FindItem(MenuFileSave, 0);
9440 if(item) item.disabled = !modifiedDocument && value;
9445 if(value && value[0])
9446 fileName = CopyString(value);
9448 if(parent && this == parent.activeClient)
9449 parent.UpdateActiveDocument(null);
9453 // if(style.isDocument)
9455 fileMonitor.fileName = value;
9457 get { return fileName; }
9462 property_category $"Data"
9467 property bool modifiedDocument
9469 property_category $"Document"
9472 if(style.isDocument || fileName)
9476 MenuItem item = menu.FindItem(MenuFileSave, 0);
9477 if(item) item.disabled = !value && fileName;
9481 if(modifiedDocument != value)
9483 modifiedDocument = value;
9484 if(style.isDocument || fileName)
9488 get { return (bool)modifiedDocument; }
9491 property bool showInTaskBar
9493 property_category $"Window Style"
9496 style.showInTaskBar = value;
9497 #if defined(__WIN32__)
9498 Win32UpdateStyle(this);
9501 get { return style.showInTaskBar; }
9503 property FileDialog saveDialog { set { saveDialog = value; } };
9504 property bool isActiveClient
9506 property_category $"Behavior"
9509 if(parent && style.isActiveClient != value && !style.hidden)
9513 if(state == minimized) parent.numIcons++;
9514 parent.numPositions++;
9518 if(state == minimized) parent.numIcons--;
9519 parent.numPositions--;
9522 style.isActiveClient = value;
9524 get { return style.isActiveClient; }
9527 property Cursor cursor
9529 property_category $"Appearance"
9533 SelectMouseCursor();
9535 get { return cursor; }
9538 //#if !defined(ECERE_VANILLA)
9539 property const char * name
9541 property_category $"Design"
9544 return (this && object) ? object.name : null;
9549 activeDesigner.RenameObject(object, value);
9553 property const char * displayDriver
9555 property_category $"Behavior"
9558 dispDriver = GetDisplayDriver(value);
9559 //DisplayModeChanged();
9563 return dispDriver ? dispDriver.name : null;
9567 // RUNTIME PROPERTIES
9568 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9569 property Size scrollArea
9571 property_category $"Behavior"
9575 SetScrollArea(value.w, value.h, false);
9577 SetScrollArea(0,0, true);
9579 get { value = scrollArea; }
9582 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9587 property_category $"Layout"
9588 set { if(this) is3D = value; }
9589 get { return (bool)is3D; }
9592 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9594 // Will be merged with font later
9595 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9596 property Point clientStart { get { value = clientStart; } };
9597 property Point absPosition { get { value = absPosition; } };
9598 property Anchor normalAnchor { get { value = normalAnchor; } };
9599 property SizeAnchor normalSizeAnchor { get { value = normalSizeAnchor; } };
9600 property bool active { get { return (bool)active; } };
9601 property bool created { get { return (bool)created; } };
9602 property bool destroyed { get { return (bool)destroyed; } };
9603 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9604 property Window firstChild { get { return children.first; } };
9605 property Window lastChild { get { return children.last; } };
9606 property Window activeClient { get { return activeClient; } };
9607 property Window activeChild { get { return activeChild; } };
9608 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9609 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9610 property ScrollBar horzScroll { get { return sbh; } };
9611 property ScrollBar vertScroll { get { return sbv; } };
9612 property StatusBar statusBar { get { return statusBar; } };
9613 property Window rootWindow { get { return rootWindow; } };
9614 property bool closing { get { return (bool)closing; } set { closing = value; } };
9615 property int documentID { get { return documentID; } };
9616 property Window previous { get { return prev; } }
9617 property Window next { get { return next; } }
9618 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9619 property PopupMenu menuBar { get { return menuBar; } }
9620 property ScrollBar sbv { get { return sbv; } }
9621 property ScrollBar sbh { get { return sbh; } }
9622 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9623 property void * systemHandle { get { return windowHandle; } }
9624 property Button minimizeButton { get { return sysButtons[0]; } };
9625 property Button maximizeButton { get { return sysButtons[1]; } };
9626 property Button closeButton { get { return sysButtons[2]; } };
9627 property BitmapResource icon
9629 get { return icon; }
9633 if(icon) incref icon;
9635 guiApp.interfaceDriver.SetIcon(this, value);
9638 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9639 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; if(value) nativeDecorations = false; /* Native Decorations are not supported with alphaBlend */ } };
9640 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9641 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9642 property bool nativeDecorations
9644 get { return (bool)nativeDecorations; }
9645 set { nativeDecorations = value; }
9646 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
9649 //return (nativeDecorations && (rootWindow == this || (formDesigner && activeDesigner && ((FormDesigner)activeDesigner.classDesigner).form && parent == ((FormDesigner)activeDesigner.classDesigner).form.parent))) != style.fixed;
9650 bool result = false;
9651 if(nativeDecorations)
9653 if(rootWindow == this)
9657 if(formDesigner && activeDesigner)
9659 FormDesigner cd = (FormDesigner)activeDesigner.classDesigner;
9660 Window form = cd ? cd.form : null;
9661 if(form && parent == form.parent)
9666 return result != style.fixed;
9670 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9672 property const char * text
9674 property_category $"Deprecated"
9676 set { property::caption = value; }
9677 get { return property::caption; }
9683 WindowBits style; // Window Style
9684 char * caption; // Name / Caption
9685 Window parent; // Parent window
9686 OldList children; // List of children in Z order
9687 Window activeChild; // Child window having focus
9688 Window activeClient;
9689 Window previousActive; // Child active prior to activating the default child
9690 Window master; // Window owning and receiving notifications concerning this window
9691 OldList slaves; // List of windows belonging to this window
9692 Display display; // Display this window is drawn into
9694 Point position; // Position in parent window client area
9695 Point absPosition; // Absolute position
9696 Point clientStart; // Client area position from (0,0) in this window
9698 Size clientSize; // Client area size
9699 Size scrollArea; // Virtual Scroll area size
9700 Size reqScrollArea; // Requested virtual area size
9701 Point scroll; // Virtual area scrolling position
9702 ScrollBar sbh, sbv; // Scrollbar window handles
9703 Cursor cursor; // Mouse cursor used for this window
9706 StatusBar statusBar;
9707 Button sysButtons[3];
9709 Box clientArea; // Client Area box clipped to parent
9711 HotKeySlot hotKey; // HotKey for this window
9715 ScrollFlags scrollFlags;// Window Scrollbar Flags
9716 int64 id; // Control ID
9718 ColorAlpha background; // Background color used to draw the window area
9720 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9721 OldList childrenCycle; // Cycling order
9722 OldLink cycle; // Element of parent's cycling order
9723 OldList childrenOrder; // Circular Z-Order
9724 OldLink order; // Element of parent's circular Z-Order
9725 Window modalSlave; // Slave window blocking this window's interaction
9727 Window rootWindow; // Topmost system managed window
9728 void * windowHandle; // System window handle
9730 DialogResult returnCode;// Return code for modal windows
9732 Point sbStep; // Scrollbar line scrolling steps
9735 SizeAnchor stateSizeAnchor;
9737 Anchor normalAnchor;
9738 SizeAnchor normalSizeAnchor;
9740 Size skinMinSize; // Minimal window size based on style
9741 Point scrolledPos; // Scrolled position
9742 Box box; // Window box clipped to parent
9743 Box * against; // What to clip the box to
9745 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9746 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9747 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9748 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9749 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9750 Point scrolledArea; // Distance to scroll area by
9751 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9753 OldList hotKeys; // List of the hotkeys of all children
9754 Window defaultControl; // Default child control
9758 ColorAlpha * palette; // Color palette used for this window
9760 int caretSize; // Size of caret, non zero if a caret is present
9761 Point caretPos; // Caret position
9763 void * systemParent; // Parent System Window for embedded windows
9770 WindowState lastState;
9772 FileMonitor fileMonitor;
9774 FontResource setFont, systemFont;
9775 FontResource usedFont;
9776 FontResource captionFont;
9778 FileDialog saveDialog;
9780 SizeAnchor sizeAnchor;
9782 // FormDesigner data
9785 Extent * tempExtents; //[4];
9786 BitmapResource icon;
9788 CreationActivationOption creationActivation;
9791 bool active:1; // true if window and ancestors are active
9792 bool acquiredInput:1; // true if the window is processing state based input
9793 bool modifiedDocument:1;
9794 bool disabled:1; // true if window cannot interact
9795 bool isForegroundWindow:1;// true while a root window is being activated
9796 bool visible:1; // Visibility flag
9797 bool destroyed:1; // true if window is being destroyed
9798 bool anchored:1; // true if this window is repositioned when the parent resizes
9799 bool dirty:1; // Flag set to true if any descendant must be redrawn
9805 bool modifyVirtArea:1;
9806 bool noAutoScrollArea:1;
9809 bool setVisible:1; // FOR FORM DESIGNER
9815 bool useSharedMemory:1;
9818 bool nativeDecorations:1;
9819 bool manageDisplay:1;
9820 bool formDesigner:1; // True if we this is running in the form editor
9821 bool requireRemaximize:1;
9822 bool noConsequential:1;
9825 // Checks used internally for them not to take effect in FormDesigner
9826 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9827 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9829 WindowController controller;
9831 public property WindowController controller
9833 get { return controller; }
9837 controller.setWindow(null);
9843 controller.setWindow(this);
9848 public property bool noConsequential
9850 set { noConsequential = value; }
9851 get { return noConsequential; }
9855 public class CommonControl : Window
9857 // creationActivation = doNothing;
9860 public property const String toolTip
9862 property_category $"Appearance"
9865 if(created) CommonControl::OnDestroy();
9867 toolTip = value ? ToolTip { tip = value; } : null;
9869 if(created) CommonControl::OnCreate();
9871 get { return toolTip ? toolTip.tip : null; }
9877 // (Very) Ugly work around for the fact that the parent watcher
9878 // won't fire when it's already been disconnected...
9879 eInstance_FireSelfWatchers(toolTip,
9880 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
9886 toolTip.parent = this;
9895 public class Percentage : float
9897 const char * OnGetString(char * string, float * fieldData, bool * needClass)
9901 sprintf(string, "%.2f", this);
9902 c = strlen(string)-1;
9905 if(string[c] != '0')
9906 last = Max(last, c);
9907 if(string[c] == '.')
9920 public void ApplySkin(Class c, const char * name, void ** vTbl)
9922 char className[1024];
9927 subclass(Window) wc = (subclass(Window))c;
9928 subclass(Window) base = (subclass(Window))c.base;
9930 sprintf(className, "%sSkin_%s", name, c.name);
9931 wc.pureVTbl = c._vTbl;
9932 c._vTbl = new void *[c.vTblSize];
9933 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9934 sc = eSystem_FindClass(c.module.application, className);
9938 for(m = 0; m < c.base.vTblSize; m++)
9940 if(c._vTbl[m] == base.pureVTbl[m])
9941 c._vTbl[m] = vTbl[m];
9946 for(m = 0; m < c.vTblSize; m++)
9948 if(sc._vTbl[m] != wc.pureVTbl[m])
9949 c._vTbl[m] = sc._vTbl[m];
9953 for(d = c.derivatives.first; d; d = d.next)
9955 ApplySkin(d.data, name, c._vTbl);
9959 public void UnapplySkin(Class c)
9961 subclass(Window) wc = (subclass(Window))c;
9964 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9967 c._vTbl = wc.pureVTbl;
9971 for(d = c.derivatives.first; d; d = d.next)
9973 UnapplySkin(d.data);
9977 void CheckFontIntegrity(Window window)
9982 if(window.usedFont && window.usedFont.font == 0xecececec)
9984 FontResource uf = window.usedFont;
9985 char * className = window._class.name;
9986 char * text = window.text;
9989 for(c = window.firstChild; c; c = c.next)
9990 CheckFontIntegrity(c);
9994 public class ControllableWindow : Window
9996 /*WindowController controller;
9997 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9998 ~ControllableWindow() { delete controller; }*/
10001 class WindowControllerInterface : ControllableWindow
10003 bool OnKeyDown(Key key, unichar ch)
10005 bool result = controller.OnKeyDown ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyDown)((Window)controller.controlled, controller, key, ch) : true;
10008 bool (* onKeyDown)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown];
10010 result = onKeyDown(controller.window, key, ch);
10015 bool OnKeyUp(Key key, unichar ch)
10017 bool result = controller.OnKeyUp ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyUp)((Window)controller.controlled, controller, key, ch) : true;
10020 bool (* onKeyUp)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp];
10022 result = onKeyUp(controller.window, key, ch);
10027 bool OnKeyHit(Key key, unichar ch)
10029 bool result = controller.OnKeyHit ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyHit)((Window)controller.controlled, controller, key, ch) : true;
10032 bool (* onKeyHit)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit];
10034 result = onKeyHit(controller.window, key, ch);
10039 bool OnMouseMove(int x, int y, Modifiers mods)
10041 bool result = controller.OnMouseMove ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMouseMove)((Window)controller.controlled, controller, x, y, mods) : true;
10044 bool(* onMouseMove)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove];
10046 result = onMouseMove(controller.window, x, y, mods);
10051 bool OnLeftButtonDown(int x, int y, Modifiers mods)
10053 bool result = controller.OnLeftButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10056 bool(* onLeftButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown];
10057 if(onLeftButtonDown)
10058 result = onLeftButtonDown(controller.window, x, y, mods);
10063 bool OnLeftButtonUp(int x, int y, Modifiers mods)
10065 bool result = controller.OnLeftButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10068 bool(* onLeftButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp];
10070 result = onLeftButtonUp(controller.window, x, y, mods);
10075 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
10077 bool result = controller.OnLeftDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10080 bool(* onLeftDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick];
10081 if(onLeftDoubleClick)
10082 result = onLeftDoubleClick(controller.window, x, y, mods);
10087 bool OnRightButtonDown(int x, int y, Modifiers mods)
10089 bool result = controller.OnRightButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10092 bool(* onRightButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown];
10093 if(onRightButtonDown)
10094 result = onRightButtonDown(controller.window, x, y, mods);
10099 bool OnRightButtonUp(int x, int y, Modifiers mods)
10101 bool result = controller.OnRightButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10104 bool(* onRightButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp];
10105 if(onRightButtonUp)
10106 result = onRightButtonUp(controller.window, x, y, mods);
10111 bool OnRightDoubleClick(int x, int y, Modifiers mods)
10113 bool result = controller.OnRightDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10116 bool(* onRightDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick];
10117 if(onRightDoubleClick)
10118 result = onRightDoubleClick(controller.window, x, y, mods);
10123 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
10125 bool result = controller.OnMiddleButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10128 bool(* onMiddleButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown];
10129 if(onMiddleButtonDown)
10130 result = onMiddleButtonDown(controller.window, x, y, mods);
10135 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
10137 bool result = controller.OnMiddleButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10140 bool(* onMiddleButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp];
10141 if(onMiddleButtonUp)
10142 result = onMiddleButtonUp(controller.window, x, y, mods);
10147 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
10149 bool result = controller.OnMiddleDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10152 bool(* onMiddleDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick];
10153 if(onMiddleDoubleClick)
10154 onMiddleDoubleClick(controller.window, x, y, mods);
10159 bool OnMultiTouch(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods)
10161 bool result = controller.OnMultiTouch ? ((bool(*)(Window, WindowController, TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers))(void *)controller.OnMultiTouch)((Window)controller.controlled, controller, event, infos, mods) : true;
10164 bool(* onMultiTouch)(Window, TouchPointerEvent, Array<TouchPointerInfo>, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMultiTouch];
10166 onMultiTouch(controller.window, event, infos, mods);
10171 void OnResize(int width, int height)
10173 if(controller.OnResize)
10174 ((void(*)(Window, WindowController, int, int))(void *)controller.OnResize)((Window)controller.controlled, controller, width, height);
10176 void(* onResize)(Window, int, int) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize];
10178 onResize(controller.window, width, height);
10182 void OnRedraw(Surface surface)
10184 if(controller.OnRedraw)
10185 ((void(*)(Window, WindowController, Surface))(void *)controller.OnRedraw)((Window)controller.controlled, controller, surface);
10187 void(* onRedraw)(Window, Surface) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw];
10189 onRedraw(controller.window, surface);
10195 bool result = controller.OnCreate ? ((bool(*)(Window, WindowController))(void *)controller.OnCreate)((Window)controller.controlled, controller) : true;
10198 bool(* onCreate)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate];
10200 result = onCreate(controller.window);
10205 bool OnLoadGraphics()
10207 bool result = controller.OnLoadGraphics ? ((bool(*)(Window, WindowController))(void *)controller.OnLoadGraphics)((Window)controller.controlled, controller) : true;
10210 bool(* onLoadGraphics)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLoadGraphics];
10212 result = onLoadGraphics(controller.window);
10217 void OnUnloadGraphics()
10219 if(controller.OnUnloadGraphics)
10220 ((void(*)(Window, WindowController))(void *)controller.OnUnloadGraphics)((Window)controller.controlled, controller);
10222 void(* onUnloadGraphics)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnUnloadGraphics];
10223 if(onUnloadGraphics)
10224 onUnloadGraphics(controller.window);
10229 public class WindowController<class V>
10231 void setWindow(Window value)
10233 uint size = class(Window).vTblSize;
10237 windowVTbl = new void *[size];
10238 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
10239 if(value._vTbl == value._class._vTbl)
10241 value._vTbl = new void *[value._class.vTblSize];
10242 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
10246 for(c = 0; c < size; c++)
10248 void * function = class(WindowControllerInterface)._vTbl[c];
10249 if(function && function != DefaultFunction)
10250 value._vTbl[c] = function;
10252 value._vTbl[c] = windowVTbl[c];
10258 memcpy(window._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
10264 property Window window
10266 get { return window; }
10268 property V controlled
10270 set { controlled = value; }
10271 get { return controlled; }
10273 // TODO: Add OnStateChange so we can implement SavedConfigWindow as a WindowController instead
10274 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
10275 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
10276 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
10277 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
10278 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
10279 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
10280 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10281 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
10282 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
10283 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10284 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
10285 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
10286 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10287 virtual bool V::OnMultiTouch(WindowController controller, TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods);
10288 virtual void V::OnResize(WindowController controller, int width, int height);
10289 virtual void V::OnRedraw(WindowController controller, Surface surface);
10290 virtual bool V::OnCreate(WindowController controller);
10291 virtual bool V::OnLoadGraphics(WindowController controller);
10292 virtual void V::OnUnloadGraphics(WindowController controller);
10295 public int (** windowVTbl)();
10299 ~WindowController()