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 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
46 #define property _property
51 #define Window X11Window
52 #define Cursor X11Cursor
54 #define Display X11Display
56 #define KeyCode X11KeyCode
57 #define Picture X11Picture
59 #include <X11/Xutil.h>
76 // 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
78 define skinMenuHeight = 40;
79 define statusBarHeight = 30;
81 define skinMenuHeight = 25;
82 define statusBarHeight = 18;
85 default extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
87 public enum DialogResult : int64 { cancel, yes, no, ok };
89 public class MouseButtons
92 bool left:1, right:1, middle:1;
95 public struct SizeAnchor
98 bool isClientW, isClientH;
103 #define SNAPDOWN(x, d) \
106 if(x < 0) x -= ((d) - Abs(x) % (d)); else x -= x % (d); \
109 #define SNAPUP(x, d) \
112 if(x > 0) x += ((d) - Abs(x) % (d)); else x += x % (d); \
115 /*static */define MAX_DIRTY_BACK = 10;
117 /////////////////////////////////////////////////////////////////////////////
118 ////////// EXTENT MANIPULATION //////////////////////////////////////////////
119 /////////////////////////////////////////////////////////////////////////////
121 #define ACCESS_ITEM(l, id) \
124 #define FASTLIST_LOOP(l, v) \
125 for(v = (BoxItem)l.first; v; v = (BoxItem)v.next)
127 #define FASTLIST_LOOPN(l, v, n) \
128 for(v = (BoxItem)l.first, n = (BoxItem)(v ? v.next : null); v; v = (BoxItem)next, n = (BoxItem)(v ? v.next : null))
131 #define ACCESS_ITEM(l, id) \
132 ((FastItem)(((id) == -1) ? null : (((byte *)((l).items)) + (id) * (l).itemSize)))
134 #define FASTLIST_LOOP(l, v) \
135 for(v = (void *)ACCESS_ITEM((l), (l).first); v; v = (void *)ACCESS_ITEM((l), v.next))
137 #define FASTLIST_LOOPN(l, v, n) \
138 for( v = (void *)ACCESS_ITEM((l), (l).first), \
139 n = v ? ((void *)ACCESS_ITEM((l), v.next)): null; \
140 v; v = n, n = n ? (void *)ACCESS_ITEM((l), n.next) : null)
143 private class FastItem : struct
148 private struct FastList
153 int count, size, itemSize;
160 first = last = free = -1;
168 // FASTLIST_LOOPN(this, item, next) { Delete(item); };
171 FastItem Add(uint itemSize)
174 if(free == -1 || !size)
181 newSize = (size + (size >> 1));
182 items = (FastItem)renew items byte[newSize * itemSize];
187 this.itemSize = itemSize;
188 items = (FastItem)new byte[newSize * itemSize];
191 for(c = size; c<newSize-1; c++)
193 ACCESS_ITEM(this, c).prev = -1;
194 ACCESS_ITEM(this, c).next = c+1;
196 ACCESS_ITEM(this, c).prev = -1;
197 ACCESS_ITEM(this, c).next = -1;
201 item = ACCESS_ITEM(this, free);
204 ACCESS_ITEM(this, item.prev).next = free;
214 void Delete(FastItem item)
217 ACCESS_ITEM(this, item.prev).next = item.next;
219 ACCESS_ITEM(this, item.next).prev = item.prev;
221 if(ACCESS_ITEM(this, first) == item)
223 if(ACCESS_ITEM(this, last) == item)
228 free = ((byte *)item - (byte *)items) / itemSize;
236 free = first = last = -1;
240 private class BoxItem : Item //FastItem
245 public /*private */struct Extent : OldList //FastList
254 //BoxItem extentBox = (BoxItem)Add(sizeof(class BoxItem));
255 Add(BoxItem { box = box });
258 void Copy(Extent source)
264 //FASTLIST_LOOP(source, extentBox)
265 for(extentBox = (BoxItem)source.first; extentBox; extentBox = (BoxItem)extentBox.next)
266 AddBox(extentBox.box);
269 void IntersectBox(Box box)
271 // Clip all boxes of extent against inside of the new box
272 BoxItem extentBox, next;
274 //FASTLIST_LOOPN(this, extentBox, next) // Macros still mess up the parser!
275 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
277 next = (BoxItem)extentBox.next;
278 if(box.left > extentBox.box.left) extentBox.box.left = box.left;
279 if(box.top > extentBox.box.top) extentBox.box.top = box.top;
280 if(box.right < extentBox.box.right) extentBox.box.right = box.right;
281 if(box.bottom < extentBox.box.bottom) extentBox.box.bottom = box.bottom;
282 if(extentBox.box.right < extentBox.box.left || extentBox.box.bottom < extentBox.box.top)
287 void ExcludeBox(Box box, Extent temp)
294 for(extentBox = (BoxItem)temp.first; extentBox; extentBox = (BoxItem)extentBox.next)
296 if(extentBox.box.left < box.right && extentBox.box.right > box.left &&
297 extentBox.box.top < box.bottom && extentBox.box.bottom > box.top)
300 if(extentBox.box.top < box.top && extentBox.box.bottom >= box.top)
304 extentBox.box.left, extentBox.box.top,
305 extentBox.box.right, Min(extentBox.box.bottom, box.top -1)
311 if(extentBox.box.bottom > box.bottom && extentBox.box.top <= box.bottom)
315 extentBox.box.left, Max(extentBox.box.top,box.bottom +1),
316 extentBox.box.right, extentBox.box.bottom
322 if(extentBox.box.bottom >= box.top && extentBox.box.top <= box.bottom)
325 if(extentBox.box.left < box.left && extentBox.box.right >= box.left)
329 extentBox.box.left, Max(extentBox.box.top, box.top),
330 Min(extentBox.box.right, box.left-1), Min(extentBox.box.bottom, box.bottom)
336 if(extentBox.box.right > box.right && extentBox.box.left <= box.right)
340 Max(extentBox.box.left, box.right+1), Max(extentBox.box.top, box.top),
341 extentBox.box.right, Min(extentBox.box.bottom, box.bottom)
349 AddBox(extentBox.box);
355 void UnionBox(Box box, Extent temp)
357 BoxItem extentBox, next;
359 // First pass: check if this box is not already covered by one of the extent's box
360 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
362 if(extentBox.box.left <= box.left && extentBox.box.right >= box.right &&
363 extentBox.box.top <= box.top && extentBox.box.bottom >= box.bottom)
370 // Second pass: only keep boxes not completely covered in the new box
371 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
373 next = (BoxItem)extentBox.next;
374 if(extentBox.box.left >= box.left && extentBox.box.right <= box.right &&
375 extentBox.box.top >= box.top && extentBox.box.bottom <= box.bottom)
379 // Add the exclusion to the extent
380 ExcludeBox(box, temp);
383 if(box.bottom >= box.top && box.right >= box.left)
385 // Optimization: if the resulting boxes touch, add them smarter
386 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
388 if(box.top == extentBox.box.top && box.bottom == extentBox.box.bottom)
390 if(Abs(box.right - extentBox.box.left) <= 1)
392 extentBox.box.left = box.left;
395 else if(Abs(box.left - extentBox.box.right) <= 1)
397 extentBox.box.right = box.right;
401 else if(box.left == extentBox.box.left && box.right == extentBox.box.right)
403 if(Abs(box.bottom - extentBox.box.top) <= 1)
405 extentBox.box.top = box.top;
408 else if(Abs(box.top - extentBox.box.bottom) <= 1)
410 extentBox.box.bottom = box.bottom;
422 void Union(Extent b, Extent temp)
426 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
427 UnionBox(extentBox.box, temp);
430 void Intersection(Extent b, Extent temp, Extent temp2, Extent temp3)
437 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
440 temp2.IntersectBox(extentBox.box);
447 void Exclusion(Extent b, Extent temp)
450 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
451 ExcludeBox(extentBox.box, temp);
454 void Offset(int x, int y)
457 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
459 extentBox.box.left += x;
460 extentBox.box.top += y;
461 extentBox.box.right += x;
462 extentBox.box.bottom += y;
467 private define MINIMIZED_WIDTH = 160;
468 private define CASCADE_SPACE = 16;
470 // namespace Windows;
472 private class ScrollFlags
474 bool snapX:1, snapY:1, dontHide:1;
477 public class BorderBits { public: bool contour:1, fixed:1, sizable:1, deep:1, bevel:1, thin:1; };
479 class WindowBits : BorderBits
481 BorderBits borderBits:6:0;
482 bool hidden:1, isActiveClient:1, hasHorzScroll:1, hasVertScroll:1, stayOnTop:1, modal:1, isDefault:1, inactive:1, isRemote:1, drawBehind:1;
483 bool interim:1, tabCycle:1, noCycle:1, dontScrollHorz:1, dontScrollVert:1, hasMaximize:1, hasMinimize:1, hasClose:1;
484 bool embedded:1, hasMenuBar:1, isDocument:1, showInTaskBar:1, hasStatusBar:1, nonClient:1, clickThrough:1;
487 public enum BorderStyle : BorderBits
490 contour = BorderBits { contour = true },
491 fixed = BorderBits { fixed = true } | contour,
492 sizable = BorderBits { sizable = true } | fixed,
493 thin = BorderBits { fixed = true, thin = true } | contour,
494 sizableThin = BorderBits { sizable = true } | thin,
495 deep = BorderBits { deep = true },
496 bevel = BorderBits { bevel = true },
497 sizableDeep = sizable|deep,
498 sizableBevel = sizable|bevel,
499 fixedDeep = fixed|deep,
500 fixedBevel = fixed|bevel,
501 deepContour = deep|contour
504 public enum CreationActivationOption
506 activate, flash, doNothing
509 public enum WindowState { normal, minimized, maximized };
511 private class ResPtr : struct
518 private class HotKeySlot : struct
520 HotKeySlot prev, next;
525 public struct TouchPointerInfo
529 float size, pressure;
532 public enum TouchPointerEvent { move, up, down, pointerUp, pointerDown };
537 class_data const char * icon;
539 class_default_property caption;
540 // class_initialize GuiApplication::Initialize;
541 class_designer FormDesigner;
542 class_property const char * icon
544 set { class_data(icon) = value; }
545 get { return class_data(icon); }
550 bool switchMode = true;
551 #if defined(__ANDROID__)
556 guiApp.Initialize(switchMode);
558 if(guiApp && guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
560 if(_vTbl == ((subclass(Window))_class).pureVTbl)
562 _vTbl = _class._vTbl;
564 else if(_vTbl != _class._vTbl)
567 for(m = 0; m < _class.vTblSize; m++)
569 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
570 _vTbl[m] = _class._vTbl[m];
575 //tempExtents[0] = { /*first = -1, last = -1, free = -1*/ };
576 //tempExtents[1] = { /*first = -1, last = -1, free = -1*/ };
577 //tempExtents[2] = { /*first = -1, last = -1, free = -1*/ };
578 //tempExtents[3] = { /*first = -1, last = -1, free = -1*/ };
582 // caption = CopyString(class.name);
584 children.offset = (byte*)&prev - (byte*)this;
585 childrenOrder.circ = true;
586 childrenCycle.circ = true;
588 maxSize = Size { MAXINT, MAXINT };
592 //style.isActiveClient = true;
595 modifyVirtArea = true;
596 manageDisplay = true;
597 nativeDecorations = true;
599 // scrollFlags = ScrollFlags { snapX = true, snapY = true };
600 sbStep.x = sbStep.y = 8;
602 if(guiApp) // dynamic_cast<GuiApplication>(thisModule)
604 cursor = guiApp.GetCursor(arrow);
605 property::parent = guiApp.desktop;
615 #if !defined(__EMSCRIPTEN__)
618 int i, lockCount = guiApp.lockMutex.lockCount;
619 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
621 XUnlockDisplay(xGlobalDisplay);
624 for(i = 0; i < lockCount; i++)
625 guiApp.lockMutex.Release();
627 for(i = 0; i < lockCount; i++)
628 guiApp.lockMutex.Wait();
629 #if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__)
631 XLockDisplay(xGlobalDisplay);
638 stopwatching(parent, font);
639 if(parent.activeChild == this)
640 parent.activeChild = null;
641 if(parent.activeClient == this)
642 parent.activeClient = null;
647 // Prevent destructor from being called again...
653 /////////////////////////////////
656 OldLink slave = master.slaves.FindLink(this);
657 master.slaves.Delete(slave);
664 parent.childrenCycle.Remove(cycle);
666 parent.childrenOrder.Remove(order);
667 parent.children.Remove(this);
672 /////////////////////////////////
674 while((ptr = resources.first))
677 resources.Delete(ptr);
684 for(child = children.first; child; child = child.next)
686 // child.stopwatching(this, font);
688 eInstance_StopWatching(this, __ecereProp___ecereNameSpace__ecere__gui__Window_font, child);
689 // Don't want property here
690 *&child.parent = null;
693 while((slave = slaves.first))
695 // Don't want property here
696 *&((Window)slave.data).master = null;
697 slaves.Delete(slave);
700 // Because we do a decref in DestroyEx...
708 // Why was this commented?
709 //if(this != guiApp.desktop)
719 #if !defined(__EMSCRIPTEN__)
724 if(((subclass(Window))_class).pureVTbl)
726 if(_vTbl == _class._vTbl)
728 _vTbl = ((subclass(Window))_class).pureVTbl;
733 for(m = 0; m < _class.vTblSize; m++)
735 if(_vTbl[m] == _class._vTbl[m])
736 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
740 if(_vTbl == ((subclass(Window))_class).pureVTbl || _vTbl == _class._vTbl)
743 dirtyArea.Free(null);
744 renderArea.Free(null);
745 overRenderArea.Free(null);
746 clipExtent.Free(null);
747 scrollExtent.Free(null);
748 dirtyBack.Free(null);
752 tempExtents[0].Free(null);
753 tempExtents[1].Free(null);
754 tempExtents[2].Free(null);
755 tempExtents[3].Free(null);
762 //#if !defined(ECERE_VANILLA)
763 const char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
765 if(this == activeDesigner)
769 const char * name = property::name;
770 return name ? name : "";
775 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
776 bool OnGetDataFromString(const char * string)
778 FormDesigner designer = (FormDesigner)activeDesigner.classDesigner;
781 if(!strcmp(string, "this") || !strcmp(string, designer.form.name))
782 this = designer.form;
783 else if(!strcmpi(string, "(Desktop)"))
784 this = activeDesigner;
786 return activeDesigner.FindObject(&this, string);
792 // --- Window updates system ---
794 // Setup a bitmap for Redrawing on client area of Window
795 Surface Redraw(Box box)
797 Surface surface = null;
799 Box clientArea = this.clientArea;
803 mox.left -= clientStart.x;
804 mox.top -= clientStart.y;
805 mox.right -= clientStart.x;
806 mox.bottom -= clientStart.y;
808 mox.Clip(clientArea);
809 // mox.ClipOffset(against, scrolledPos.x, scrolledPos.y);
811 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && mox.right >= mox.left && mox.bottom >= mox.top)
813 int x = absPosition.x + clientStart.x;
814 int y = absPosition.y + clientStart.y;
815 if(rootWindow.nativeDecorations && rootWindow.windowHandle && !is3D)
817 x -= rootWindow.clientStart.x;
818 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
820 if(!guiApp.fullScreenMode || is3D)
822 x -= rootWindow.absPosition.x;
823 y -= rootWindow.absPosition.y;
827 int dx = rootWindow.parent.parent.clientStart.x;
828 int dy = rootWindow.parent.parent.clientStart.y;
829 if(!rootWindow.parent.nativeDecorations)
831 dx += rootWindow.parent.clientStart.x;
832 dy += rootWindow.parent.clientStart.y;
846 surface = display.GetSurface(x, y, mox);
849 surface.width = clientSize.w;
850 surface.height = clientSize.h;
856 // Setup a bitmap for Redrawing on full Window
857 Surface RedrawFull(Box box)
859 Surface surface = null;
867 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && box.right >= box.left && box.bottom >= box.top)
869 int x = absPosition.x;
870 int y = absPosition.y;
871 if(rootWindow.nativeDecorations && rootWindow.windowHandle && !is3D)
873 x -= rootWindow.clientStart.x;
874 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
876 #if !defined(__EMSCRIPTEN__)
877 if(!guiApp.fullScreenMode || is3D)
880 x -= rootWindow.absPosition.x;
881 y -= rootWindow.absPosition.y;
884 int dx = rootWindow.parent.parent.clientStart.x;
885 int dy = rootWindow.parent.parent.clientStart.y;
886 if(!rootWindow.parent.nativeDecorations)
888 dx += rootWindow.parent.clientStart.x;
889 dy += rootWindow.parent.clientStart.y;
903 surface = display.GetSurface(x, y, mox);
906 surface.width = size.w;
907 surface.height = size.h;
913 void FigureCaption(char * caption)
915 Window activeClient = null;
919 strcpy(caption, this.caption);
920 if(style.isDocument || fileName)
922 if(caption[0]) strcat(caption, " - ");
924 strcat(caption, fileName);
928 sprintf(title, "Untitled %d", documentID);
929 strcat(caption, title);
932 strcat(caption, " *");
937 for(activeClient = this.activeClient; activeClient && !((BorderBits)activeClient.borderStyle).fixed; activeClient = activeClient.activeClient);
939 if(activeClient && activeClient.state == maximized)
941 if(activeClient.caption)
943 if(caption[0]) strcat(caption, " - ");
944 strcat(caption, activeClient.caption);
946 if(activeClient.style.isDocument || activeClient.fileName)
948 if(caption[0]) strcat(caption, " - ");
949 strcat(caption, "[");
950 if(activeClient.fileName)
951 strcat(caption, activeClient.fileName);
955 sprintf(title, "Untitled %d", activeClient.documentID);
956 strcat(caption, title);
958 if(activeClient.modifiedDocument)
959 strcat(caption, " *");
960 strcat(caption, "]");
965 // Code for returning dirty from ScrollDisplay:
967 for(d = 0; d<scrollExtent.count; d++)
969 Box * box = &scrollExtent.boxes[d];
975 Min(box.right, box.left-scroll.x),box.bottom
977 dirtyArea.UnionBox(update);
983 Max(box.left, box.right-scroll.x), box.top,
984 box.right, box.bottom
986 dirtyArea.UnionBox(update);
994 box.right, Min(box.bottom, box.top-scroll.y),
996 dirtyArea.UnionBox(update);
1002 box.left, Max(box.top, box.bottom-scroll.y),
1003 box.right, box.bottom
1005 dirtyArea.UnionBox(update);
1010 void UpdateDecorations(void)
1012 // TODO: *** TEMPORARY HACK ***
1015 parent.Update(null);
1019 Update({ -clientStart.x, -clientStart.y, -clientStart.x + size.w-1, 0 });
1021 Update({ -clientStart.x, clientSize.h, -clientStart.x + size.w-1, -clientStart.y + size.h-1 });
1023 Update({ -clientStart.x,0, -1, clientSize.h-1 });
1025 Update({ clientSize.w, 0, -clientStart.x + size.w-1, clientSize.h-1 });
1028 // Returns w & h for Position
1029 void ComputeAnchors(Anchor anchor, SizeAnchor sizeAnchor, int *ox, int *oy, int *ow, int *oh)
1031 Window parent = this.parent ? this.parent : guiApp.desktop;
1032 int xOffset = 0, yOffset = 0;
1033 int vpw = parent ? parent.clientSize.w : 0;
1034 int vph = parent ? parent.clientSize.h : 0;
1035 int pw = parent ? parent.clientSize.w : 0;
1036 int ph = parent ? parent.clientSize.h : 0;
1037 int w = sizeAnchor.size.w, h = sizeAnchor.size.h;
1038 int x = anchor.left.distance, y = anchor.top.distance;
1039 float ex = 0, ey = 0;
1040 MinMaxValue ew = 0, eh = 0;
1042 float cascadeW, cascadeH;
1044 int tilingW, tilingH, tilingSplit, tilingLastH = 0;
1045 int addX = 0, addY = 0;
1047 if(parent && rootWindow == this && guiApp && guiApp.interfaceDriver)
1049 Window masterWindow = this;
1050 Box box { addX, addY, addX + vpw - 1, addY + vph - 1 };
1053 if(master == guiApp.desktop)
1054 masterWindow = guiApp.desktop.activeChild;
1056 masterWindow = master.rootWindow;
1057 if(!masterWindow) masterWindow = this;
1059 guiApp.interfaceDriver.GetScreenArea(masterWindow, box);
1060 if((anchor.left.type == offset && anchor.right.type == offset) || anchor.left.type == none)
1063 pw = vpw = box.right - box.left + 1;
1065 if((anchor.top.type == offset && anchor.bottom.type == offset) || anchor.top.type == none)
1068 ph = vph = box.bottom - box.top + 1;
1084 vpw = pw = parent.size.w;
1085 vph = ph = parent.size.h;
1087 else if(!style.fixed /*|| style.isDocument*/)
1089 if(!style.dontScrollHorz && parent.scrollArea.w) vpw = parent.scrollArea.w;
1090 if(!style.dontScrollVert && parent.scrollArea.h) vph = parent.scrollArea.h;
1092 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
1095 Desktop3D_FixSize(&pw, &ph);
1096 Desktop3D_FixSize(&vpw, &vph);
1099 if(pw < skinMinSize.w) pw = skinMinSize.w;
1100 if(ph < skinMinSize.h) ph = skinMinSize.h;
1101 if(vpw < skinMinSize.w) vpw = skinMinSize.w;
1102 if(vph < skinMinSize.h) vph = skinMinSize.h;
1104 // TODO: Must fix what we're snapping
1107 if(anchor.left.type)
1109 SNAPUP(x, textCellW);
1111 else if(anchor.right.type)
1113 SNAPDOWN(x, textCellW);
1118 SNAPUP(y, textCellH);
1120 else if(anchor.bottom.type)
1122 SNAPDOWN(y, textCellH);
1126 // This is required to get proper initial decoration size using native decorations on Windows
1127 #if defined(__WIN32__)
1128 if(nativeDecorations && windowHandle && guiApp && guiApp.interfaceDriver && !visible)
1129 guiApp.interfaceDriver.PositionRootWindow(this, x, y, Max(1, size.w), Max(1, size.h), true, true);
1131 GetDecorationsSize(&ew, &eh);
1133 if(anchor.left.type >= cascade && (state == normal /*|| state == Hidden*/))
1135 // Leave room for non client windows (eventually dockable panels)
1137 int loX = 0, loY = 0, hiX = pw, hiY = ph;
1138 for(win = parent.children.first; win; win = win.next)
1140 if(!win.nonClient && !win.isActiveClient && win.visible)
1142 Size size = win.size;
1143 Point pos = win.position;
1144 int left = pos.x, top = pos.y;
1145 int right = pos.x + size.w, bottom = pos.y + size.h;
1146 if(win.size.w > win.size.h)
1149 loY = Max(loY, bottom);
1150 else if(top > ph - ph / 4)
1151 hiY = Min(hiY, top);
1156 loX = Max(loX, right);
1157 else if(left > pw - pw / 4)
1158 hiX = Min(hiX, left);
1167 if(parent.sbv && !parent.sbv.style.hidden)
1168 pw += guiApp.currentSkin.VerticalSBW();
1169 if(parent.sbh && !parent.sbh.style.hidden)
1170 ph += guiApp.currentSkin.HorizontalSBH();
1172 if(anchor.left.type == cascade)
1174 w = (int)(pw * 0.80);
1175 h = (int)(ph * 0.80);
1177 else if(anchor.left.type >= vTiled)
1182 numTiling = parent.numPositions - parent.numIcons;
1183 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1184 if(anchor.left.type == vTiled)
1188 tilingH = (int)sqrt(numTiling);
1189 tilingW = numTiling / tilingH;
1192 tilingH = tilingW = 0;
1198 tilingW = (int)sqrt(numTiling);
1199 tilingH = numTiling / tilingW;
1202 tilingH = tilingW = 0;
1205 leftOver = numTiling - tilingH * tilingW;
1208 tilingSplit = (tilingW - leftOver) * tilingH;
1209 tilingLastH = tilingH+1;
1212 tilingSplit = numTiling;
1214 if(tilingW && tilingH)
1216 if(positionID >= tilingSplit)
1218 x = xOffset + pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
1219 y = yOffset + ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
1220 x2 = xOffset + pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
1221 y2 = yOffset + ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
1225 x = xOffset + pw * (positionID / tilingH) / tilingW;
1226 y = yOffset + ph * (positionID % tilingH) / tilingH;
1227 x2 = xOffset + pw * (positionID / tilingH + 1) / tilingW;
1228 y2 = yOffset + ph * ((positionID % tilingH) + 1) / tilingH;
1233 // How can this happen? From ec2 parsing test
1241 SNAPDOWN(x, textCellW);
1242 SNAPDOWN(y, textCellH);
1243 SNAPDOWN(x2, textCellW);
1244 SNAPDOWN(y2, textCellH);
1252 if(sizeAnchor.isClientW) w += ew;
1253 if(sizeAnchor.isClientH) h += eh;
1255 if(anchor.left.type == offset)
1256 x = anchor.left.distance;
1257 else if(anchor.left.type == relative)
1258 x = (anchor.left.percent < 0) ? ((int)(vpw * anchor.left.percent - 0.5)) : (int)(vpw * anchor.left.percent + 0.5);
1259 else if(anchor.right.type == relative)
1260 // ex = (anchor.right.percent < 0) ? ((int)(vpw * anchor.right.percent + 0)) : ((int)(vpw * anchor.right.percent + 0));
1261 ex = (anchor.right.percent < 0) ? ((int)(vpw * (1.0-anchor.right.percent) + 0)) : ((int)(vpw * (1.0-anchor.right.percent) + 0));
1262 else if(anchor.right.type == offset)
1263 ex = vpw - anchor.right.distance;
1265 if(anchor.top.type == offset)
1266 y = anchor.top.distance;
1267 else if(anchor.top.type == relative)
1268 y = (anchor.top.percent < 0) ? ((int)(vph * anchor.top.percent - 0.5)) : ((int)(vph * anchor.top.percent + 0.5));
1269 else if(anchor.bottom.type == relative)
1270 //ey = (anchor.bottom.percent < 0) ? ((int)(vph * anchor.bottom.percent + 0)) : ((int)(vph * anchor.bottom.percent + 0));
1271 ey = (anchor.bottom.percent < 0) ? ((int)(vph * (1.0-anchor.bottom.percent) + 0)) : ((int)(vph * (1.0-anchor.bottom.percent) + 0));
1272 else if(anchor.bottom.type == offset)
1273 ey = vph - anchor.bottom.distance;
1275 if(anchor.left.type && anchor.right.type)
1277 switch(anchor.right.type)
1280 ex = pw * (1.0f-anchor.right.percent);
1281 w = Max((int)(ex + 0.5) - x, 0);
1284 ex = vpw - anchor.right.distance;
1285 w = Max((int)(ex + 0.5) - x, 0);
1289 if(anchor.top.type && anchor.bottom.type)
1291 switch(anchor.bottom.type)
1294 ey = ph * (1.0f-anchor.bottom.percent);
1295 h = Max((int)(ey + 0.5) - y, 0);
1298 ey = vph - anchor.bottom.distance;
1299 h = Max((int)(ey + 0.5) - y, 0);
1308 if(state == normal /*|| state == Hidden*/)
1310 bool addSbV = false, addSbH = false;
1312 if(sizeAnchor.isClientW || (anchor.left.type && anchor.right.type)) w = Max(w, 1); else w = Max(w, 0);
1313 if(sizeAnchor.isClientH || (anchor.top.type && anchor.bottom.type)) h = Max(h, 1); else h = Max(h, 0);
1315 w = Max(w, minSize.w);
1316 h = Max(h, minSize.h);
1317 w = Min(w, maxSize.w);
1318 h = Min(h, maxSize.h);
1320 if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
1322 if(w) w -= guiApp.currentSkin.VerticalSBW();
1325 if((sizeAnchor.isClientH || !h || (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
1327 if(h) h -= guiApp.currentSkin.HorizontalSBH();
1331 if(!OnResizing(&w, &h))
1337 if((addSbV)) // || reqScrollArea.h > h) && sbv)
1338 w += guiApp.currentSkin.VerticalSBW();
1339 if((addSbH)) // || reqScrollArea.w > w) && sbh)
1340 h += guiApp.currentSkin.HorizontalSBH();
1342 w = Max(w, skinMinSize.w);
1343 h = Max(h, skinMinSize.h);
1356 SNAPDOWN(w, textCellW);
1357 SNAPDOWN(h, textCellH);
1360 if(anchor.left.type == cascade && (state == normal /*|| state == Hidden*/))
1362 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1365 (pw - w) / CASCADE_SPACE,
1366 (ph - h) / CASCADE_SPACE);
1372 cascW = (pw - w) / (numCascade-1);
1373 cascH = (ph - h) / (numCascade-1);
1374 SNAPDOWN(cascW, textCellW);
1375 SNAPDOWN(cascH, textCellH);
1376 cascadeW = (float)cascW;
1377 cascadeH = (float)cascH;
1381 numCascade = Max(numCascade, 2);
1382 cascadeW = (float)(pw - w) / (numCascade-1);
1383 cascadeH = (float)(ph - h) / (numCascade-1);
1386 x = (int)((positionID % numCascade) * cascadeW) + xOffset;
1387 y = (int)((positionID % numCascade) * cascadeH) + yOffset;
1389 else if(anchor.left.type < vTiled)
1391 if(!anchor.left.type || anchor.horz.type == middleRelative)
1393 if(!anchor.right.type)
1395 if(anchor.horz.type == middleRelative)
1396 x = (int)(vpw * (0.5 + anchor.horz.percent) - w / 2);
1398 x = vpw / 2 + anchor.horz.distance - w / 2;
1404 // case A_EDGE: x = x - w; break;
1406 if(!anchor.top.type || anchor.vert.type == middleRelative)
1408 if(!anchor.bottom.type)
1410 if(anchor.vert.type == middleRelative)
1411 y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
1413 y = vph / 2 + anchor.vert.distance - h / 2;
1419 // case A_EDGE: y = y - h; break;
1422 if((state == normal /*|| state == Hidden*/) && !OnMoving(&x, &y, w, h))
1430 SNAPDOWN(x, textCellW);
1431 SNAPDOWN(y, textCellH);
1443 if(anchored && style.fixed && style.isActiveClient)
1448 void UpdateCaret(bool forceUpdate, bool erase)
1450 static Window lastWindow = null;
1451 static int caretX, caretY, caretSize;
1453 if(guiApp && guiApp.caretOwner == this)
1455 int x = caretPos.x - scroll.x;
1456 int y = caretPos.y - scroll.y;
1458 if((erase || this.caretSize) &&
1459 x >= clientArea.left && x <= clientArea.right &&
1460 y >= clientArea.top && y <= clientArea.bottom)
1464 guiApp.interfaceDriver.SetCaret(
1465 x + absPosition.x + clientStart.x,
1466 y + absPosition.y + clientStart.y, this.caretSize);
1467 guiApp.caretEnabled = true;
1469 if(erase || lastWindow != this || caretX != x || caretY != y || caretSize != this.caretSize || forceUpdate)
1473 if(lastWindow != this)
1475 updateBox.left = x + 1;
1477 updateBox.right = x + 2;
1478 updateBox.bottom = y + this.caretSize - 1;
1482 updateBox.left = Min(x + 1, caretX + 1);
1483 updateBox.top = Min(y, caretY);
1484 updateBox.right = Max(x + 2, caretX + 2);
1485 updateBox.bottom = Max(y + this.caretSize - 1, caretY + caretSize - 1);
1488 guiApp.caretOwner.Update(updateBox);
1495 caretSize = this.caretSize;
1501 guiApp.interfaceDriver.SetCaret(0,0,0);
1502 guiApp.caretEnabled = false;
1508 void SetPosition(int x, int y, int w, int h, bool modifyArea, bool modifyThisArea, bool modifyClientArea)
1513 scrolledPos.x = position.x = x;
1514 scrolledPos.y = position.y = y;
1516 clientSize.w = size.w = w;
1517 clientSize.h = size.h = h;
1519 if(parent && !style.nonClient)
1521 //if(!style.fixed || style.isDocument)
1523 if(!style.dontScrollHorz) scrolledPos.x -= parent.scroll.x;
1524 if(!style.dontScrollVert) scrolledPos.y -= parent.scroll.y;
1528 clientStart.x = clientStart.y = 0;
1530 SetWindowArea(&clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1532 //if(!activeClient || activeClient.state != maximized)
1533 if(!noAutoScrollArea)
1535 // Check if scroll area must be modified
1536 if(guiApp && !guiApp.modeSwitching && (sbv || sbh))
1538 bool foundChild = false;
1540 int cw = clientSize.w;// + ((!sbv || sbv.range > 1) ? guiApp.currentSkin.VerticalSBW() : 0);
1541 int ch = clientSize.h;// + ((!sbh || sbh.rangw > 1) ? guiApp.currentSkin.HorizontalSBH() : 0);
1542 for(child = children.first; child; child = child.next)
1544 if(child.modifyVirtArea && !child.style.hidden && child.created && /*!child.anchored &&*/
1545 !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1547 if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == offset)
1548 w = Max(w, child.position.x + child.size.w);
1549 else if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == none)
1550 w = Max(w, Max(child.position.x, 0) + child.size.w);
1551 if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == offset)
1552 h = Max(h, child.position.y + child.size.h);
1553 else if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == none)
1554 h = Max(h, Max(child.position.y, 0) + child.size.h);
1559 if(foundChild && (w > cw || h > ch))
1561 //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
1563 int stepX = sbStep.x, stepY = sbStep.y;
1564 // Needed to make snapped down position match the skin's check of client area
1565 // against realvirtual
1568 SNAPDOWN(stepX, textCellW);
1569 SNAPDOWN(stepY, textCellH);
1570 stepX = Max(stepX, textCellW);
1571 stepY = Max(stepY, textCellH);
1573 if(scrollFlags.snapX)
1575 if(scrollFlags.snapY)
1578 reqScrollArea.w = w;
1579 reqScrollArea.h = h;
1582 else if(reqScrollArea.w || reqScrollArea.h)
1584 reqScrollArea.w = 0;
1585 reqScrollArea.h = 0;
1586 SetScrollPosition(0,0);
1591 // Automatic MDI Client Scrolling Area Adjustment
1592 if(parent && !parent.noAutoScrollArea)
1594 if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
1595 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
1597 Window parent = this.parent;
1598 int w = parent.reqScrollArea.w;
1599 int h = parent.reqScrollArea.h;
1601 if(stateAnchor.right.type == none && stateAnchor.left.type == offset)
1602 w = Max(w, position.x + size.w);
1603 else if(stateAnchor.right.type == none && stateAnchor.left.type == none)
1604 w = Max(w, Max(position.x, 0) + size.w);
1605 if(stateAnchor.bottom.type == none && stateAnchor.top.type == offset)
1606 h = Max(h, position.y + size.h);
1607 else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
1608 h = Max(h, Max(position.y, 0) + size.h);
1610 if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
1611 (h > parent.clientSize.h && h > parent.reqScrollArea.h))
1613 /*bool resize = false;
1614 int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
1615 // Needed to make snapped down position match the skin's check of client area
1616 // against realvirtual
1619 SNAPDOWN(stepX, textCellW);
1620 SNAPDOWN(stepY, textCellH);
1621 stepX = Max(stepX, textCellW);
1622 stepY = Max(stepY, textCellH);
1624 if(parent.scrollFlags.snapX)
1626 if(parent.scrollFlags.snapY)
1628 if(parent.reqScrollArea.w != w || parent.reqScrollArea.h != h)
1630 parent.reqScrollArea.w = w;
1631 parent.reqScrollArea.h = h;*/
1633 // parent.UpdateScrollBars(true, true);
1634 parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1635 false, true, true, true, false, false);
1640 GetRidOfVirtualArea();
1644 UpdateScrollBars(modifyThisArea, false);
1645 else if(guiApp.currentSkin)
1648 &clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1650 if(sbv && (scrollFlags.dontHide || sbv.range > 1))
1651 clientSize.w -= guiApp.currentSkin.VerticalSBW();
1652 if(sbh && (scrollFlags.dontHide || sbh.range > 1))
1653 clientSize.h -= guiApp.currentSkin.HorizontalSBH();
1656 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1657 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1659 absPosition = scrolledPos;
1660 if(guiApp && guiApp.driver != null && guiApp.interfaceDriver)
1661 guiApp.interfaceDriver.OffsetWindow(this, &absPosition.x, &absPosition.y);
1663 if(this != guiApp.desktop && parent)
1665 absPosition.x += parent.absPosition.x;
1666 absPosition.y += parent.absPosition.y;
1667 if(!style.nonClient && this != guiApp.desktop)
1669 absPosition.x += parent.clientStart.x;
1670 absPosition.y += parent.clientStart.y;
1674 box = Box { 0, 0, size.w - 1, size.h - 1 };
1679 // Clip against parent's client area
1680 box.ClipOffset(against, scrolledPos.x, scrolledPos.y);
1682 // Compute client area in this window coordinate system
1683 clientArea.left = 0;
1685 clientArea.right = clientSize.w - 1;
1686 clientArea.bottom = clientSize.h - 1;
1688 // Clip against parent's client area
1690 clientArea.ClipOffset(against, scrolledPos.x + clientStart.x, scrolledPos.y + clientStart.y);
1694 //absPosition.x -= parent.clientStart.x;
1695 //absPosition.y -= parent.clientStart.y;
1698 // Adjust all children
1699 for(child = children.first; child; child = child.next)
1700 child.SetPosition(child.position.x, child.position.y, child.size.w, child.size.h, false, true, true);
1702 UpdateCaret(false, false);
1705 void GetRidOfVirtualArea(void)
1707 if(parent && !parent.destroyed && style.fixed &&
1708 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient &&
1709 parent.reqScrollArea.w && parent.reqScrollArea.h)
1711 if(!parent.noAutoScrollArea)
1713 // TODO: Review the logic of all this? Each child is going to reposition the parent?
1717 for(child = children.first; child; child = child.next)
1719 if(child.modifyVirtArea && !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1721 if(child.position.x + child.size.w > parent.clientSize.w + ((!parent.sbv || parent.sbv.style.hidden) ? 0 : guiApp.currentSkin.VerticalSBW()) ||
1722 child.position.y + child.size.h > parent.clientSize.h + ((!parent.sbh || parent.sbh.style.hidden) ? 0 : guiApp.currentSkin.HorizontalSBH()))
1732 Window parent = this.parent;
1734 parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1735 false, true, true, true, false, false);
1737 parent.SetScrollArea(0,0,true);
1738 parent.SetScrollPosition(0,0);
1744 public void ExternalPosition(int x, int y, int w, int h)
1746 Position(x, y, w, h, false, true, true, true, false, false);
1749 // (w, h): Full window size
1750 bool Position(int x, int y, int w, int h, bool force, bool processAnchors, bool modifyArea, bool updateScrollBars, bool thisOnly, bool changeRootWindow)
1752 bool result = false;
1753 int oldCW = clientSize.w, oldCH = clientSize.h;
1754 bool clientResized, windowResized, windowMoved;
1756 //bool realResized = size.w != w || size.h != h;
1758 // TOCHECK: This wasn't in ecere.dll
1759 //if(!parent) return true;
1760 if(destroyed) return false;
1762 windowMoved = position.x != x || position.y != y || force;
1764 // windowResized = realResized || force;
1765 windowResized = size.w != w || size.h != h || force;
1767 if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
1773 scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
1774 scrolledPos.x - parent.clientStart.x + this.box.right,
1775 scrolledPos.y - parent.clientStart.y + this.box.bottom
1781 Box box { scrolledPos.x + this.box.left, scrolledPos.y + this.box.top, scrolledPos.x + this.box.right, scrolledPos.y + this.box.bottom};
1786 SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
1788 clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
1789 if(clientResized && this == rootWindow && nativeDecorations && rootWindow.windowHandle)
1790 windowResized = true;
1792 if(display && rootWindow != this)
1795 if(guiApp && guiApp.windowMoving)
1797 if(guiApp.windowMoving.style.nonClient)
1798 guiApp.windowMoving.parent.SetMouseRangeToWindow();
1800 guiApp.windowMoving.parent.SetMouseRangeToClient();
1810 // Buttons bitmap resources crash if we do this while switching mode
1811 if(!guiApp || !guiApp.modeSwitching)
1814 // Process Anchored Children
1818 for(child = children.first; child; child = child.next)
1821 ((child.stateAnchor.left.type != offset ||
1822 child.stateAnchor.top.type != offset ||
1823 child.stateAnchor.right.type != none ||
1824 child.stateAnchor.bottom.type != none) ||
1825 child.state == maximized || child.state == minimized))
1827 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1829 // child.Position(x, y, w, h, false, true, true, true, false);
1830 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1831 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1837 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1838 //if(updateScrollBars)
1840 OnResize(clientSize.w, clientSize.h);
1842 if((clientResized || windowMoved) && created)
1843 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1845 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1847 Window master = guiApp.interimWindow.master;
1848 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1851 if(rootWindow == this && !is3D)
1855 x -= guiApp.desktop.absPosition.x;
1856 y -= guiApp.desktop.absPosition.y;
1858 //guiApp.Log("Position %s\n", caption);
1861 if(windowResized || windowMoved)
1862 if(display && !display.flags.memBackBuffer && changeRootWindow)
1863 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1866 #if !defined(__EMSCRIPTEN__)
1867 !guiApp.fullScreenMode &&
1869 this != guiApp.desktop && (windowResized || windowMoved))
1870 for(child = parent.children.first; child && child != this; child = child.next)
1871 if(child.rootWindow)
1872 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1877 if(windowMoved || windowResized)
1879 display.Lock(true /*false*/);
1882 display.Position(absPosition.x, absPosition.y);
1883 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1886 // result = realResized ? display.Resize(size.w, size.h) : true;
1887 if(nativeDecorations && rootWindow.windowHandle)
1889 int w = clientSize.w, h = clientSize.h;
1890 if(hasMenuBar) h += skinMenuHeight;
1891 if(hasStatusBar) h += statusBarHeight;
1892 if(sbv && sbv.visible) w += sbv.size.w;
1893 if(sbh && sbh.visible) h += sbh.size.h;
1894 result = manageDisplay ? display.Resize(w, h) : true;
1897 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1901 else if(clientResized)
1903 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1906 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1910 if(windowMoved || windowResized)
1915 if(guiApp.driver && !guiApp.modeSwitching && changeRootWindow && windowHandle)
1917 if(windowResized || windowMoved)
1918 if(!display || display.flags.memBackBuffer)
1919 guiApp.interfaceDriver.PositionRootWindow(this,
1920 x, y, w, h, windowMoved, windowResized);
1921 guiApp.interfaceDriver.UpdateRootWindow(this);
1923 for(child = children.first; child; child = child.next)
1925 if(child.is3D && child.created)
1927 // Copy Display Content
1928 child.display.displaySystem = display.displaySystem;
1929 child.display.window = display.window;
1930 child.display.current = display.current;
1931 child.display.width = display.width;
1932 child.display.height = display.height;
1933 child.display.driverData = display.driverData;
1934 #if !defined(__EMSCRIPTEN__)
1935 child.display.mutex = null;
1947 void UpdateScrollBars(bool flag, bool fullThing)
1950 bool resizeH = false, resizeV = false;
1951 bool scrolled = false;
1952 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1953 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1955 if(destroyed) return;
1956 if(guiApp.currentSkin)
1958 MinMaxValue cw = 0, ch = 0;
1959 bool sbvVisible = false, sbhVisible = false;
1960 int rangeH = 0, rangeV = 0;
1961 int positionH = 0, positionV;
1963 // First get client area with no respect to scroll bars
1968 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1970 if(scrollFlags.dontHide)
1973 cw -= guiApp.currentSkin.VerticalSBW();
1975 ch -= guiApp.currentSkin.HorizontalSBH();
1977 // Update the scrollbar visibility
1983 sbh.disabled = rangeH <= 1;
1984 if(sbh.style.hidden)
1994 sbv.disabled = rangeV <= 1;
1995 if(sbv.style.hidden)
2003 int oldHRange = sbh ? sbh.range : 0;
2004 int oldVRange = sbv ? sbv.range : 0;
2005 // Then start off with horizontal scrollbar range
2008 positionH = sbh.thumbPosition;
2015 SBSetTotal(sbh, rvw);
2018 ch -= guiApp.currentSkin.HorizontalSBH();
2021 // Do the same for vertical scrollbar
2024 positionV = sbv.thumbPosition;
2030 SBSetTotal(sbv, rvh);
2034 cw -= guiApp.currentSkin.VerticalSBW();
2035 // Maybe we need to set the range on the horizontal scrollbar again
2043 SBSetTotal(sbh, rvw);
2044 //sbh.Action(setRange, positionH, 0);
2045 if(rangeH <= 1 && sbh.range > 1)
2047 ch -= guiApp.currentSkin.HorizontalSBH();
2053 SBSetTotal(sbv, rvh);
2055 //sbv.Action(setRange, positionV, 0);
2060 if(sbh && sbh.range != oldHRange) sbh.Action(setRange, positionH, 0);
2061 if(sbv && sbv.range != oldVRange) sbv.Action(setRange, positionV, 0);
2064 // Update the scrollbar visibility
2065 if(!scrollFlags.dontHide)
2067 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
2071 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
2078 if(guiApp.currentSkin)
2085 sbhVisible = sbh.style.hidden ? true : false;
2087 sbvVisible = sbv.style.hidden ? true : false;
2089 // Do our resize here
2090 if(flag && (resizeH || resizeV) && fullThing)
2092 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
2097 OnResize(clientSize.w, clientSize.h);
2103 sbh.visible = sbhVisible;
2105 sbv.visible = sbvVisible;
2107 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
2108 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
2111 sbh.pageStep = clientSize.w;
2113 sbv.pageStep = clientSize.h;
2115 // Notify doesn't handle setRange anymore... process it here
2118 int positionH = sbh.thumbPosition;
2119 if(scroll.x != positionH)
2121 OnHScroll(setRange, positionH, 0);
2125 SNAPDOWN(positionH, textCellW);
2126 scroll.x = positionH;
2132 int seen = clientSize.w, total = reqScrollArea.w;
2135 if(scrollFlags.snapX)
2136 SNAPDOWN(seen, sbStep.x);
2138 if(!total) total = seen;
2139 range = total - seen + 1;
2141 range = Max(range, 1);
2143 if(x >= range) x = range - 1;
2145 if(scrollFlags.snapX)
2146 SNAPUP(x, sbStep.x);
2150 OnHScroll(setRange, x, 0);
2155 SNAPDOWN(x, textCellW);
2161 int positionV = sbv.thumbPosition;
2162 if(scroll.y != positionV)
2164 OnVScroll(setRange, positionV, 0);
2168 SNAPDOWN(positionV, textCellH);
2169 scroll.y = positionV;
2175 int seen = clientSize.h, total = reqScrollArea.h;
2178 if(scrollFlags.snapY)
2179 SNAPDOWN(seen, sbStep.y);
2181 if(!total) total = seen;
2182 range = total - seen + 1;
2183 range = Max(range, 1);
2185 if(y >= range) y = range - 1;
2187 if(scrollFlags.snapY)
2188 SNAPUP(y, sbStep.y);
2192 OnVScroll(setRange, y, 0);
2197 SNAPDOWN(y, textCellH);
2203 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2206 for(child = children.first; child; child = child.next)
2208 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2211 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2212 child.Position(x, y, w, h, false, true, false, true, false, false);
2219 // Process Scrollbars
2221 if(sbh) // && !sbh.style.hidden
2224 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2225 // Need to set the range again (should improve...) since the scrollbars didn't have
2226 // the right size when UpdateScrollArea set the range on it
2229 sbh.seen = clientSize.w;
2233 if(sbv) // && !sbv.state.hidden
2236 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2237 // Need to set the range again (should improve...) since the scrollbars didn't have
2238 // the right size when UpdateScrollArea set the range on it
2241 sbv.seen = clientSize.h;
2246 // TESTING THIS LOWER
2247 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2250 for(child = children.first; child; child = child.next)
2252 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2255 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2256 child.Position(x, y, w, h, false, true, false, true, false, false);
2262 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2264 SetState(maximized, false, mods);
2268 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2270 SetState(normal, false, mods);
2274 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2276 SetState(minimized, false, mods);
2277 parent.CycleChildren(false, true, false, true);
2281 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2284 // Scroll bar notifications
2285 if(action != setRange)
2287 bool changed = false;
2291 if(scroll.x != position)
2293 OnHScroll(action, position, keyFlags);
2298 SNAPDOWN(position, textCellW);
2300 scroll.x = position;
2304 if(scroll.y != position)
2306 OnVScroll(action, position, keyFlags);
2311 SNAPDOWN(position, textCellH);
2313 scroll.y = position;
2317 bool childMove = false;
2318 for(child = children.first; child; child = child.next)
2320 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2323 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2324 child.Position(x, y, w, h, false, true, false, true, false, false);
2328 // Testing this patch out to solve MDI workspace redraw bugs
2329 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2330 // Scroll offsets to blame?
2334 UpdateCaret(false, false);
2338 // Testing this patch out to solve MDI workspace redraw bugs
2339 for(child = children.first; child; child = child.next)
2341 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2350 Window GetParentMenuBar()
2352 Window menuBarParent;
2353 if(formDesigner) return null;
2354 for(menuBarParent = this ? parent : null; menuBarParent; menuBarParent = menuBarParent.parent)
2356 if(menuBarParent.menuBar) return menuBarParent.menuBar;
2357 if(menuBarParent && !menuBarParent.isActiveClient)
2363 void CreateSystemChildren(void)
2365 Window parent = this;
2366 bool scrollBarChanged = false;
2367 bool hasClose = false, hasMaxMin = false;
2368 Point scroll = this.scroll;
2370 if(state == maximized)
2372 parent = GetParentMenuBar();
2379 if(style.hasClose) hasClose = true;
2380 if(style.hasMaximize || style.hasMinimize)
2387 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2389 sysButtons[2].Destroy(0);
2390 sysButtons[2] = null;
2392 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2394 sysButtons[1].Destroy(0);
2395 sysButtons[1] = null;
2397 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2399 sysButtons[0].Destroy(0);
2400 sysButtons[0] = null;
2403 if(hasClose && parent)
2410 parent, master = this,
2411 inactive = true, nonClient = true, visible = false;
2413 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2419 if(this.parent == guiApp.desktop)
2420 sysButtons[2].hotKey = altF4;
2421 else if(style.isActiveClient)
2422 sysButtons[2].hotKey = ctrlF4;
2423 sysButtons[2].Create();
2426 sysButtons[2].symbol = 'X';
2427 sysButtons[2].disabled = !style.hasClose;
2430 if(hasMaxMin && parent)
2434 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2435 if(state == maximized)
2438 method = RestoreButtonClicked;
2444 method = MaximizeButtonClicked;
2452 parent, master = this,
2453 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2455 sysButtons[1].Create();
2457 sysButtons[1].NotifyClicked = method;
2459 sysButtons[1].symbol = symbol;
2460 sysButtons[1].disabled = !style.hasMaximize;
2463 if(hasMaxMin && parent)
2467 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2468 if (state == minimized)
2471 method = RestoreButtonClicked;
2477 method = MinimizeButtonClicked;
2485 parent, master = this,
2486 hotKey = altM, inactive = true, nonClient = true, visible = false
2488 sysButtons[0].Create();
2490 sysButtons[0].NotifyClicked = method;
2492 sysButtons[0].symbol = symbol;
2493 sysButtons[0].disabled = !style.hasMinimize;
2496 // Create the scrollbars
2497 if(style.hasHorzScroll && !sbh)
2503 direction = horizontal,
2507 snap = scrollFlags.snapX,
2508 NotifyScrolling = ScrollBarNotification
2511 scrollBarChanged = true;
2513 else if(sbh && !style.hasHorzScroll)
2519 if(style.hasVertScroll && !sbv)
2525 direction = vertical,
2529 snap = scrollFlags.snapY,
2530 NotifyScrolling = ScrollBarNotification
2533 scrollBarChanged = true;
2535 else if(sbv && !style.hasVertScroll)
2540 if(scrollBarChanged)
2542 SetScrollLineStep(sbStep.x, sbStep.y);
2543 UpdateScrollBars(true, true);
2547 if(scrollBarChanged)
2549 if(sbh) sbh.thumbPosition = scroll.x;
2550 if(sbv) sbv.thumbPosition = scroll.y;
2554 void UpdateCaption(void)
2556 if(rootWindow == this)
2559 FigureCaption(caption);
2560 if(guiApp.interfaceDriver)
2561 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2563 UpdateDecorations();
2566 if(parent.activeClient == this) // Added this last check
2568 if(parent.rootWindow == parent)
2571 parent.FigureCaption(caption);
2572 if(guiApp.interfaceDriver)
2573 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2576 parent.UpdateCaption();
2578 parent.UpdateDecorations();
2582 void UpdateActiveDocument(Window previous)
2584 Window activeClient = this.activeClient;
2585 Window activeChild = this.activeChild;
2592 activeClient.CreateSystemChildren();
2594 previous.CreateSystemChildren();
2606 // Build window list
2609 Menu windowMenu = menu.FindMenu("Window");
2614 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2616 Window document = cycle.data;
2617 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2619 char name[2048], caption[2048];
2620 document.FigureCaption(caption);
2621 sprintf(name, "%d %s", id+1, caption);
2622 windowMenu.AddDynamic(MenuItem
2624 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2625 NotifySelect = MenuWindowSelectWindow
2629 if(activeClient.cycle == cycle) break;
2634 if((!previous && activeClient) || !activeClient)
2640 item = menu.FindItem(MenuWindowCloseAll, 0);
2641 if(item) item.disabled = false;
2642 item = menu.FindItem(MenuWindowNext, 0);
2643 if(item) item.disabled = false;
2644 item = menu.FindItem(MenuWindowPrevious, 0);
2645 if(item) item.disabled = false;
2646 item = menu.FindItem(MenuWindowCascade, 0);
2647 if(item) item.disabled = false;
2648 item = menu.FindItem(MenuWindowTileHorz, 0);
2649 if(item) item.disabled = false;
2650 item = menu.FindItem(MenuWindowTileVert, 0);
2651 if(item) item.disabled = false;
2652 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2653 if(item) item.disabled = false;
2654 item = menu.FindItem(MenuWindowWindows, 0);
2655 if(item) item.disabled = false;
2658 item = menu.FindItem(MenuFileClose, 0);
2659 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2660 item = menu.FindItem(MenuFileSaveAll, 0);
2661 if(item) item.disabled = numDocuments < 1;
2663 if(activeClient && activeClient.menu && activeClient.state != minimized)
2667 //activeClient.menu.Clean(activeClient);
2668 menu.Merge(activeClient.menu, true, activeClient);
2672 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2675 menu.Merge(activeChild.menu, true, activeChild);
2678 // This is called again for a child window change, with same active client
2679 OnActivateClient(activeClient, previous);
2680 if(!menuBar && !((BorderBits)borderStyle).fixed && parent && parent.activeClient == this)
2681 parent.UpdateActiveDocument(null);
2684 void _ShowDecorations(Box box, bool post)
2686 if(rootWindow == this && nativeDecorations && !is3D) return;
2687 if(visible && this != guiApp.desktop)
2689 Surface surface = RedrawFull(box);
2693 FigureCaption(caption);
2696 ShowDecorations(captionFont.font,
2699 active, //parent.activeClient == this
2700 guiApp.windowMoving == this);
2702 PreShowDecorations(captionFont.font,
2705 active, //parent.activeClient == this
2706 guiApp.windowMoving == this);
2713 void UpdateExtent(Box refresh)
2715 Surface surface = null;
2717 if(!manageDisplay) { OnRedraw(null);return; }
2718 _ShowDecorations(refresh, false);
2720 surface = Redraw(refresh);
2721 // Opaque background: just fill before EW_REDRAW (clear?)
2724 surface.SetBackground(background);
2725 surface.SetForeground(foreground);
2726 surface.DrawingChar(' ');
2727 if(this == rootWindow)
2729 if(style.drawBehind || background.a)
2731 int a = background.a;
2732 // Premultiply alpha for clear color
2733 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2734 surface.Clear(colorBuffer);
2735 surface.SetBackground(background);
2738 else if(background.a)
2742 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2743 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2746 if(display.flags.alpha && background.a < 255 && background)
2748 surface.Area(0,0,clientSize.w, clientSize.h);
2749 /*if(style.clearDepthBuffer)
2750 surface.Clear(depthBuffer);*/
2752 else if(/*style.clearDepthBuffer || */background.a)
2754 int a = background.a;
2755 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2756 // Premultiply alpha for clear color
2757 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2758 surface.Clear(colorBuffer);
2759 surface.SetBackground(background);
2764 surface.TextFont(usedFont.font);
2765 surface.TextOpacity(false);
2766 surface.outlineColor = black;
2770 // Draw the caret ...
2771 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2773 // surface.SetBackground(0xFFFFFF - background.color);
2774 surface.SetBackground(~background.color);
2776 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2777 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2783 void DrawOverChildren(Box refresh)
2785 Surface surface = Redraw(refresh);
2789 surface.DrawingChar(' ');
2790 surface.SetBackground(background);
2791 surface.SetForeground(foreground);
2793 surface.TextFont(usedFont.font);
2794 surface.TextOpacity(false);
2795 surface.outlineColor = black;
2797 OnDrawOverChildren(surface);
2802 _ShowDecorations(refresh, true);
2805 void ComputeClipExtents(void)
2808 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2810 clipExtent.Copy(this.clipExtent);
2812 for(child = children.last; child; child = child.prev)
2814 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2816 bool opaque = child.IsOpaque(); // TODO: acess background directly
2817 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2819 child.clipExtent.Copy(clipExtent);
2820 child.clipExtent.Offset(-dx, -dy);
2821 child.clipExtent.IntersectBox(child.box);
2823 child.ComputeClipExtents();
2825 if(opaque && !child.style.nonClient)
2827 // Adjust the box for the parent:
2828 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2829 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2834 // ??? Only do this for overlapped window or if parent has with clip children flag
2836 // Do this if window has clip children flag on (default false?)
2837 // this.clipExtent = clipExtent;
2839 clipExtent.Free(null);
2842 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2845 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2846 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2848 offsetX -= rootWindow.clientStart.x;
2849 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2853 for(child = children.last; child; child = child.prev)
2855 bool opaque = child.IsOpaque();
2856 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2860 // Adjust renderArea to the root window level
2861 Extent * renderArea = &rootWindow.tempExtents[3];
2863 int offsetX = child.absPosition.x - rootWindow.absPosition.x;
2864 int offsetY = child.absPosition.y - rootWindow.absPosition.y;
2865 if(child.rootWindow.nativeDecorations && rootWindow.windowHandle)
2867 offsetX -= child.rootWindow.clientStart.x;
2868 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2872 Extent childRenderArea;
2874 if(backBufferUpdate != null)
2876 childRenderArea.Copy(backBufferUpdate);
2877 childRenderArea.Offset(-offsetX, -offsetY);
2880 childRenderArea.Copy(child.dirtyArea);
2882 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2883 renderArea.Copy(dirtyExtent);
2884 renderArea.Offset(-offsetX, -offsetY);
2885 childRenderArea.Union(renderArea);
2888 // Intersect with the clip extent
2889 childRenderArea.Intersection(child.clipExtent);
2892 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2894 // This intersection with child clip extent was missing and causing #708 (Installer components list scrolling bug):
2895 renderArea->Intersection(child.clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2897 renderArea->Offset(offsetX, offsetY);
2899 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2900 // overDirtyExtent.Union(renderArea);
2901 renderArea->Empty();
2902 // childRenderArea.Free();
2904 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2909 for(child = children.last; child; child = child.prev)
2911 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2913 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2918 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2920 bool opaque = IsOpaque();
2921 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2923 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2924 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2926 offsetX -= rootWindow.clientStart.x;
2927 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2931 for(child = children.last; child; child = child.prev)
2933 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2935 ColorAlpha background = *(ColorAlpha *)&child.background;
2936 bool opaque = child.IsOpaque();
2937 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2941 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2942 // Adjust renderArea to the root window level
2944 renderArea.Copy(child.dirtyArea);
2945 renderArea.Offset(offsetX, offsetY);
2946 dirtyExtent.Union(renderArea);
2947 overDirtyExtent.Union(renderArea);
2953 for(child = children.last; child; child = child.prev)
2955 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2957 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2961 if(backBufferUpdate != null)
2963 renderArea.Copy(backBufferUpdate);
2964 renderArea.Offset(-offsetX, -offsetY);
2966 overRenderArea.Copy(backBufferUpdate);
2967 overRenderArea.Offset(-offsetX, -offsetY);
2973 renderArea.Copy(dirtyArea);
2975 overRenderArea.Copy(dirtyArea);
2978 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2979 dirtyExtentWindow->Copy(dirtyExtent);
2980 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2981 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2982 dirtyExtentWindow->Empty();
2984 // Intersect with the clip extent
2985 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2988 if(renderArea.count > 10)
2991 printf("\nToo many extents (%d):\n", renderArea.count);
2993 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2994 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2999 for(c = 0; c<10; c++)
3002 FASTLIST_LOOP(renderArea, extentBox)
3004 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
3006 renderArea.Copy(extent);
3008 FASTLIST_LOOP(renderArea, extentBox)
3011 printf("(%d, %d) - (%d, %d)\n",
3012 extentBox.box.left, extentBox.box.top,
3013 extentBox.box.right, extentBox.box.bottom);
3017 printf("\nNow %d\n", renderArea.count);
3023 // WHY WAS THIS COMMENTED ??
3025 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
3026 dirtyExtentWindow->Copy(overDirtyExtent);
3027 dirtyExtentWindow->Offset(-offsetX, -offsetY);
3028 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
3029 dirtyExtentWindow->Empty();
3031 // Intersect with the clip extent
3032 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
3038 if(scrollExtent.count)
3040 // Subtract render extent from scrolling extent
3041 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
3043 if(backBufferUpdate == null)
3045 Extent * dirty = &rootWindow.tempExtents[3];
3048 // Intersect scrolling extent with clip extent
3049 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
3051 // offset this scroll to be at the root window level
3052 scrollExtent.Offset(offsetX, offsetY);
3053 // Add area that was scrolled to the dirty extents of the back buffer
3054 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
3058 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
3059 for(scrollBox = (BoxItem)scrollExtent.first; scrollBox; scrollBox = (BoxItem)scrollBox.next)
3060 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
3065 scrollExtent.Empty();
3067 // Add the exposed extent to the window render area
3068 dirty->Offset(-offsetX, -offsetY);
3069 renderArea.Union(dirty, rootWindow.tempExtents[0]);
3074 // Subtract the window's box from the transparency forced extent
3075 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
3081 renderArea.Copy(this.renderArea);
3082 renderArea.Offset(offsetX, offsetY);
3083 dirtyExtent.Union(renderArea);
3089 Extent renderArea { };
3091 renderArea.Copy(overRenderArea);
3092 renderArea.Offset(offsetX, offsetY);
3093 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
3098 if(backBufferUpdate != null)
3100 // Remove render area from dirty area
3101 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
3103 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
3110 // Remove the window render area from the dirty extents of the back buffer
3111 rootWindow.dirtyBack.Exclusion(renderArea);
3115 void Render(Extent updateExtent)
3119 Window rootWindow = this.rootWindow;
3120 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
3121 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
3123 offsetX -= rootWindow.clientStart.x;
3124 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
3127 if(rootWindow.fullRender)
3136 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
3137 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
3142 /*if(renderArea.count)
3143 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
3146 for(extentBox = (BoxItem)renderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
3148 Box box = extentBox.box;
3151 /*printf("(%d, %d) - (%d, %d)\n",
3152 extentBox.box.left, extentBox.box.top,
3153 extentBox.box.right, extentBox.box.bottom);*/
3158 box.left += offsetX;
3160 box.right += offsetX;
3161 box.bottom += offsetY;
3163 if(updateExtent != null)
3164 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
3168 for(child = children.first; child; child = child.next)
3169 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
3170 child.Render(updateExtent);
3172 if(rootWindow.fullRender)
3173 DrawOverChildren(box);
3176 // TO DO: There's an issue about draw over children...
3177 // TO DO: Don't wanna go through this if method isn't used
3178 for(extentBox = (BoxItem)overRenderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
3179 //FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
3181 Box box = extentBox.box;
3183 DrawOverChildren(box);
3185 box.left += offsetX;
3187 box.right += offsetX;
3188 box.bottom += offsetY;
3190 if(updateExtent != null)
3191 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
3194 for(child = children.first; child; child = child.next)
3195 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
3196 child.Render(updateExtent);
3199 overRenderArea.Empty();
3202 public void UpdateDisplay(void)
3204 if(!manageDisplay) { OnRedraw(null);return; }
3205 if(rootWindow && this != rootWindow)
3206 rootWindow.UpdateDisplay();
3209 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
3210 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
3213 dirtyExtent.Clear();
3216 clipExtent.AddBox(box);
3219 display.StartUpdate();
3221 if(!rootWindow.fullRender)
3223 ComputeClipExtents();
3224 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
3225 ComputeRenderArea(dirtyExtent, overExtent, null);
3228 clipExtent.Free(null);
3230 dirtyExtent.Free(null);
3231 overExtent.Free(null);
3233 if(display.flags.flipping)
3236 display.Update(null);
3240 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
3241 updateExtent.Clear();
3243 Render(updateExtent);
3245 updateExtent.UnionBox(this.box, tempExtents[0]);
3248 //printf("\n\nUpdate:\n------------------------------------------\n");
3251 //FASTLIST_LOOP(updateExtent, extentBox)
3252 for(extentBox = (BoxItem)updateExtent.first; extentBox; extentBox = (BoxItem)extentBox.next)
3255 /*printf("Updating (%d, %d) - (%d, %d)\n",
3256 extentBox.box.left, extentBox.box.top,
3257 extentBox.box.right, extentBox.box.bottom);*/
3260 display.Update(extentBox.box);
3263 updateExtent.Free(null);
3266 display.EndUpdate();
3275 void UpdateBackDisplay(Box box)
3281 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3283 //printf("UpdateBackDisplay going through!\n");
3284 display.StartUpdate();
3288 intersection.Copy(dirtyBack);
3289 intersection.IntersectBox(box);
3291 dirtyExtent.Clear();
3294 clipExtent.AddBox(box);
3296 if(!rootWindow.fullRender)
3298 ComputeClipExtents();
3299 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3302 clipExtent.Free(null);
3304 intersection.Free(null);
3305 dirtyExtent.Free(null);
3306 overExtent.Free(null);
3311 if(display.flags.flipping)
3312 display.Update(null);
3315 rootWindow.display.Update(box);
3318 display.EndUpdate();
3322 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3323 if(dirtyBack.count > MAX_DIRTY_BACK)
3325 BoxItem extentBox, next;
3326 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3327 for(extentBox = (BoxItem)dirtyBack.first; extentBox; extentBox = next)
3329 next = (BoxItem)extentBox.next;
3330 if(extentBox != first)
3332 if(extentBox.box.left < first.box.left)
3333 first.box.left = extentBox.box.left;
3334 if(extentBox.box.top < first.box.top)
3335 first.box.top = extentBox.box.top;
3336 if(extentBox.box.right > first.box.right)
3337 first.box.right = extentBox.box.right;
3338 if(extentBox.box.bottom > first.box.bottom)
3339 first.box.bottom = extentBox.box.bottom;
3340 dirtyBack.Delete(extentBox);
3349 // --- Window positioning ---
3350 // --- Window identification ---
3352 // Returns window at position "Position"
3353 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3355 Window child, result = null;
3357 box.left += absPosition.x;
3358 box.right += absPosition.x;
3359 box.top += absPosition.y;
3360 box.bottom += absPosition.y;
3362 if(!destroyed && visible && (acceptDisabled || !disabled))
3364 int lx = x - absPosition.x;
3365 int ly = y - absPosition.y;
3366 if(IsInside(lx, ly))
3367 // if(box.IsPointInside(Point{x, y}))
3369 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3370 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3373 bool isD = (last && last != this && last.IsDescendantOf(this)); // Fix for WSMS (#844)
3374 Window ancestor = null;
3376 for(ancestor = last; ancestor && ancestor.parent != this; ancestor = ancestor.parent);
3377 for(child = (isD ? (last != ancestor ? ancestor : ancestor.previous) : children.last); child; child = child.prev)
3379 if(child != statusBar && child.rootWindow == rootWindow)
3381 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3388 for(child = (isD ? (last != ancestor ? ancestor : ancestor.previous) : children.last); child; child = child.prev)
3390 if(child != statusBar && child.rootWindow == rootWindow)
3392 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3399 if(last && last != this && this.IsDescendantOf(last)) // Fix for installer lockup
3407 Window FindModal(void)
3409 Window modalWindow = this, check;
3410 Window check2 = null;
3411 for(check = this; check.master; check = check.master)
3413 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3415 modalWindow = check.master.modalSlave;
3416 check = modalWindow;
3418 // TESTING THIS FOR DROPBOX...
3419 if(!rootWindow || !rootWindow.style.interim)
3421 for(check2 = check; check2 /*.activeChild*/; check2 = check2.activeChild)
3423 if(check2.modalSlave && check2.modalSlave.created)
3425 modalWindow = check2.modalSlave;
3433 if(modalWindow == this)
3435 for(check = this; check.activeChild; check = check.activeChild)
3437 if(check.modalSlave)
3439 modalWindow = check.modalSlave;
3445 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3446 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3449 void StopMoving(void)
3451 if(this == guiApp.windowMoving)
3453 guiApp.windowMoving = null;
3454 UpdateDecorations();
3455 SetMouseRange(null);
3458 if(rootWindow.active)
3459 guiApp.interfaceDriver.StopMoving(rootWindow);
3461 guiApp.windowCaptured.ReleaseCapture();
3462 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3463 guiApp.windowIsResizing = false;
3467 void SelectMouseCursor(void)
3472 Window cursorWindow = null;
3473 bool rx, ry, rex, rey;
3475 guiApp.desktop.GetMousePosition(&x, &y);
3476 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3478 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3479 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[moving]);
3480 else if(mouseWindow)
3482 modalWindow = mouseWindow.FindModal();
3483 x -= mouseWindow.absPosition.x;
3484 y -= mouseWindow.absPosition.y;
3485 if(guiApp.windowIsResizing)
3487 rex = guiApp.resizeEndX;
3488 rey = guiApp.resizeEndY;
3489 rx = guiApp.resizeX;
3490 ry = guiApp.resizeY;
3491 if((rex && rey) || (rx && ry))
3492 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNWSE]);
3493 else if((rex && ry) || (rx && rey))
3494 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNESW]);
3495 else if((ry || rey) && (!rx && !rex))
3496 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNS]);
3497 else if((rx || rex) && (!ry && !rey))
3498 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeWE]);
3500 else if(!modalWindow && !guiApp.windowCaptured &&
3501 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3502 &rx, &ry, &rex, &rey))
3504 if((rex && rey) || (rx && ry))
3505 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNWSE]);
3506 else if((rex && ry) || (rx && rey))
3507 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNESW]);
3508 else if((ry || rey) && (!rx && !rex))
3509 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNS]);
3510 else if((rx || rex) && (!ry && !rey))
3511 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeWE]);
3513 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3515 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}) &&
3516 mouseWindow.rootWindow != mouseWindow)
3517 cursorWindow = mouseWindow.parent;
3519 cursorWindow = mouseWindow;
3521 else if(!guiApp.interimWindow)
3522 cursorWindow = guiApp.windowCaptured;
3525 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient && cursorWindow.rootWindow != cursorWindow; cursorWindow = cursorWindow.parent);
3526 guiApp.SetCurrentCursor(mouseWindow, cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3528 else if(modalWindow)
3530 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[arrow]);
3532 else if(guiApp.interimWindow)
3534 if(guiApp.interimWindow.cursor)
3535 guiApp.SetCurrentCursor(mouseWindow, guiApp.interimWindow.cursor);
3537 guiApp.SetCurrentCursor(mouseWindow, mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3542 // --- State based input ---
3543 bool AcquireInputEx(bool state)
3548 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3549 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3551 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3553 guiApp.acquiredWindow = state ? this : null;
3556 SetMouseRangeToClient();
3557 guiApp.interfaceDriver.SetMouseCursor(guiApp.acquiredWindow, (SystemCursor)-1);
3562 SelectMouseCursor();
3564 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3568 // --- Window activation ---
3569 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3572 if(!parent || !parent.style.inactive)
3574 Window parent = this.parent;
3577 if(rootWindow == this)
3578 Log(active ? "active\n" : "inactive\n");
3580 if(active && requireRemaximize)
3582 if(state == maximized)
3584 property::state = normal;
3585 property::state = maximized;
3587 requireRemaximize = false;
3590 // Testing this here...
3591 if(!parent || parent == guiApp.desktop || parent.active)
3593 this.active = active;
3596 // TESTING THIS HERE
3597 UpdateDecorations();
3598 if((result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master))
3599 result = NotifyActivate(master, this, active, previous);
3602 this.active = !active;
3607 if(!parent || parent == guiApp.desktop || parent.active)
3609 this.active = active;
3611 AcquireInputEx(active);
3612 if(active && isEnabled)
3616 if(guiApp.caretOwner)
3620 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3621 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3622 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3623 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3625 guiApp.caretOwner.Update(extent);
3628 if(visible || !guiApp.caretOwner)
3629 guiApp.caretOwner = this;
3630 UpdateCaret(false, false);
3636 this.active = false;
3638 AcquireInputEx(active);
3640 if(!active && guiApp.caretOwner == this)
3642 UpdateCaret(false, true);
3643 guiApp.caretOwner = null;
3644 guiApp.interfaceDriver.SetCaret(0,0,0);
3645 guiApp.caretEnabled = false;
3650 if(!active && parent && parent.activeChild && parent.activeChild != this)
3651 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3657 if(!active && menuBar)
3660 menuBar.OnActivate(false, null, &goOn, true);
3661 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3666 Window aChild = activeChild;
3668 if(!aChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3680 void ConsequentialMouseMove(bool kbMoving)
3682 if(rootWindow && !noConsequential)
3684 if(kbMoving || !guiApp.windowMoving)
3688 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3690 if(guiApp.interfaceDriver)
3691 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3693 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3694 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3700 bool IsDescendantOf(Window ancestor)
3703 for(window = this; window && window != ancestor; window = window.parent);
3704 return window == ancestor;
3707 bool IsSlaveOf(Window master)
3710 for(window = this; window && window != master; window = window.master);
3711 return window == master;
3714 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3718 if(this && !destroyed /*&& state != Hidden*/)
3720 Window swap = externalSwap;
3728 if(activateParent &&
3729 (parent.activeChild != this ||
3730 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3731 active && _isModal &&
3732 parent != master && master)
3733 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3739 bool real = parent.activeChild != this;
3741 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3742 if(!style.inactive && /*activateParent && */guiApp.interimWindow &&
3743 !IsDescendantOf(guiApp.interimWindow) &&
3744 !IsSlaveOf(guiApp.interimWindow))
3746 Window interimWindow = guiApp.interimWindow;
3747 while(interimWindow && interimWindow != this)
3749 Window master = interimWindow.master;
3751 guiApp.interimWindow = null;
3752 if(guiApp.caretOwner)
3753 guiApp.caretOwner.UpdateCaret(false, false);
3755 incref interimWindow;
3756 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3761 delete interimWindow;
3762 interimWindow = (master && master.style.interim) ? master : null;
3767 guiApp.interimWindow = this;
3768 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3769 guiApp.caretEnabled = false;*/
3770 UpdateCaret(false, true);
3775 //bool acquireInput = false;
3777 parent.activeChild &&
3778 parent.activeChild.state == maximized &&
3779 parent != guiApp.desktop;
3781 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3786 swap = parent.activeChild;
3787 if(swap && swap.destroyed) swap = null;
3788 if(swap && swap != this)
3791 if(!swap.PropagateActive(false, this, &goOn, true))
3792 swap = parent.activeChild;
3803 if(!parent || parent.activeChild != this || style.interim)
3806 result = PropagateActive(true, swap, &goOn, true);
3807 if(!result && !goOn)
3812 //acquireInput = true;
3816 if(style.hasMaximize && parent != guiApp.desktop)
3819 SetState(maximized, false, 0);
3820 else if(state != maximized)
3823 for(child = parent.children.first; child; child = child.next)
3825 if(this != child && child.state == maximized)
3826 child.SetState(normal, false, 0);
3833 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3835 Window previous = parent.activeClient;
3836 parent.activeChild = this;
3837 if(!style.nonClient /*&& style.isActiveClient*/)
3841 if(style.isActiveClient)
3842 parent.activeClient = this;
3843 // Moved UpdateActiveDocument inside hidden check
3844 // To prevent activating previous window while creating a new one
3845 // (It was messing up the privateModule in the CodeEditor)
3846 parent.UpdateActiveDocument(previous);
3852 //if(!style.isRemote)
3854 if(rootWindow != this)
3856 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3857 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3860 #if !defined(__EMSCRIPTEN__)
3861 if(!guiApp.fullScreenMode)
3864 Window modalRoot = FindModal();
3865 if(!modalRoot) modalRoot = this;
3866 if(!modalRoot.isForegroundWindow)
3868 modalRoot.isForegroundWindow = true;
3869 // To check : Why is parent null?
3870 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3872 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3874 modalRoot.isForegroundWindow = false;
3879 if(result && real && (!style.inactive || moveInactive) && parent)
3881 Window last = parent.children.last;
3883 if(!style.stayOnTop)
3884 for(; last && last.style.stayOnTop; last = last.prev);
3886 parent.children.Move(this, last);
3888 // Definitely don't want that: why not?
3892 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3898 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3905 parent.activeChild = null;
3906 if(!style.nonClient /*&& style.isActiveClient*/)
3908 Window previous = parent.activeClient;
3909 if(style.isActiveClient)
3910 parent.activeClient = null;
3911 parent.UpdateActiveDocument(previous);
3915 if(this == guiApp.interimWindow)
3917 guiApp.interimWindow = null;
3918 if(guiApp.caretOwner)
3919 guiApp.caretOwner.UpdateCaret(false, false);
3921 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3928 if(!active || !swap)
3929 UpdateDecorations();
3931 swap.UpdateDecorations();
3933 if(active && rootWindow != this)
3934 ConsequentialMouseMove(false);
3941 // --- Input Messages ---
3942 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3944 static bool reEntrancy = false;
3945 if(reEntrancy) return;
3949 guiApp.cursorUpdate = true;
3950 if(guiApp.windowScrolling && !consequential)
3952 guiApp.windowScrolling.SetScrollPosition(
3953 (guiApp.windowScrolling.sbh) ?
3954 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3955 (guiApp.windowScrolling.sbv) ?
3956 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3958 if(guiApp.windowMoving)
3960 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3962 Window window = guiApp.windowMoving;
3964 int w = window.size.w;
3965 int h = window.size.h;
3970 rx = mouseX - guiApp.windowMovingStart.x;
3971 ry = mouseY - guiApp.windowMovingStart.y;
3974 window.GetDecorationsSize(&ew, &eh);
3976 if(guiApp.windowIsResizing)
3978 x = window.scrolledPos.x;
3979 y = window.scrolledPos.y;
3983 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3984 rx = guiApp.windowResizingBefore.w - aw;
3985 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3986 w = guiApp.windowResizingBefore.w - rx;
3990 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3991 ry = guiApp.windowResizingBefore.h - ah;
3992 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3993 ry = Max(ry, -guiApp.windowMovingBefore.y);
3994 h = guiApp.windowResizingBefore.h - ry;
3996 if(guiApp.resizeEndX)
3998 w = guiApp.windowResizingBefore.w + rx;
4001 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
4009 w = Max(w, window.minSize.w);
4010 h = Max(h, window.minSize.h);
4011 w = Min(w, window.maxSize.w);
4012 h = Min(h, window.maxSize.h);
4014 if(!window.OnResizing(&w, &h))
4016 w = window.clientSize.w;
4017 h = window.clientSize.h;
4020 w = Max(w, window.skinMinSize.w);
4021 h = Max(h, window.skinMinSize.h);
4028 SNAPDOWN(w, textCellW);
4029 SNAPDOWN(h, textCellH);
4034 aw = Max(w,window.skinMinSize.w);
4035 rx = guiApp.windowResizingBefore.w - aw;
4036 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
4037 w = guiApp.windowResizingBefore.w - rx;
4041 ah = Max(h,window.skinMinSize.h);
4042 ry = guiApp.windowResizingBefore.h - ah;
4043 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
4044 ry = Max(ry, -guiApp.windowMovingBefore.y);
4045 h = guiApp.windowResizingBefore.h - ry;
4050 if(!guiApp.windowIsResizing || guiApp.resizeX)
4051 x = guiApp.windowMovingBefore.x + rx;
4052 if(!guiApp.windowIsResizing || guiApp.resizeY)
4053 y = guiApp.windowMovingBefore.y + ry;
4055 if(!guiApp.windowIsResizing)
4058 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
4060 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
4061 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
4062 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
4063 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
4067 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
4068 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
4074 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
4076 if(!window.OnMoving(&x, &y, w, h))
4078 x = window.scrolledPos.x;
4079 y = window.scrolledPos.y;
4085 SNAPDOWN(x, textCellW);
4086 SNAPDOWN(y, textCellH);
4089 if(!window.style.nonClient)
4091 if(!window.style.fixed /*|| window.style.isDocument*/)
4093 if(!window.style.dontScrollHorz)
4094 x += window.parent.scroll.x;
4095 if(!window.style.dontScrollVert)
4096 y += window.parent.scroll.y;
4100 // Break the anchors for moveable/resizable windows
4101 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
4102 if(window.style.fixed)
4104 if(window.state == normal)
4106 window.normalAnchor = Anchor { left = x, top = y };
4107 window.normalSizeAnchor = SizeAnchor { { w, h } };
4108 window.anchored = false;
4112 window.stateAnchor = Anchor { left = x, top = y };
4113 window.stateSizeAnchor = SizeAnchor { { w, h } };
4115 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
4116 // TOCHECK: Investigate why the following only redraws the scrollbars
4117 //window.Position(x, y, w, h, false, true, true, true, false, true);
4119 guiApp.movingLast.x = mouseX;
4120 guiApp.movingLast.y = mouseY;
4126 public bool MultiTouchMessage(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers * mods, bool consequential, bool activate)
4129 if((infos && infos.count) || (event == up || event == pointerUp))
4132 while(result && w != this)
4134 // TODO: How to handle this?
4135 int x = (infos && infos.count) ? infos[0].point.x : 0;
4136 int y = (infos && infos.count) ? infos[0].point.y : 0;
4137 Window msgWindow = GetAtPosition(x,y, false, true, w);
4142 window = (w && !w.disabled) ? w : null;
4144 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
4146 if(!guiApp.windowCaptured.isEnabled)
4147 guiApp.windowCaptured.ReleaseCapture();
4149 window = guiApp.windowCaptured;
4152 if(consequential) mods->isSideEffect = true;
4153 if(!result || (window && window.destroyed)) window = null;
4157 if(window.OnMultiTouch && !window.disabled)
4159 Array<TouchPointerInfo> in = null;
4160 if(infos && infos.count)
4162 in = { size = infos.size };
4163 memcpy(in.array, infos.array, sizeof(TouchPointerInfo) * infos.size);
4167 i.point.x -= (window.absPosition.x + window.clientStart.x);
4168 i.point.y -= (window.absPosition.y + window.clientStart.y);
4170 i.point.x = Max(Min(i.point.x, 32767),-32768);
4171 i.point.y = Max(Min(i.point.y, 32767),-32768);
4176 if(!window.OnMultiTouch(event, in, *mods))
4183 if(!result || !w || !w.clickThrough)
4191 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
4194 bool wasMoving = guiApp.windowMoving ? true : false;
4195 bool wasScrolling = guiApp.windowScrolling ? true : false;
4196 bool firstPass = true;
4198 while(result && w != this)
4200 Window msgWindow = GetAtPosition(x,y, false, true, w);
4201 Window trueWindow = GetAtPosition(x,y, false, false, w);
4202 bool windowDragged = false;
4207 window = (w && !w.disabled) ? w : null;
4209 if(trueWindow) incref trueWindow;
4211 if(consequential) mods->isSideEffect = true;
4213 UpdateMouseMove(x, y, consequential);
4215 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
4217 if(!guiApp.windowCaptured.isEnabled)
4218 guiApp.windowCaptured.ReleaseCapture();
4220 window = guiApp.windowCaptured;
4223 if(trueWindow && activate &&
4224 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
4225 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
4226 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
4227 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
4229 if(mods->alt && !mods->ctrl && !mods->shift)
4231 Window moved = trueWindow;
4232 for(moved = trueWindow; moved; moved = moved.parent)
4233 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
4238 windowDragged = true;
4240 // Cancel the ALT menu toggling...
4241 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4246 if(window && activate &&
4247 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
4248 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
4249 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
4250 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
4252 Window modalWindow = window.FindModal();
4254 /*if(mods->alt && !mods->shift && !mods->ctrl)
4256 Window moved = window;
4257 for(moved = window; moved; moved = moved.parent)
4258 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
4263 windowDragged = true;
4265 // Cancel the ALT menu toggling...
4266 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
4272 Window activateWindow = modalWindow ? modalWindow : window;
4273 if(activateWindow && !activateWindow.isRemote)
4275 bool doActivation = true;
4276 //bool needToDoActivation = false;
4277 Window check = activateWindow;
4279 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
4281 if(!check.style.inactive)
4283 //needToDoActivation = true;
4285 doActivation = false;
4290 if(!needToDoActivation)
4291 doActivation = false;
4294 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
4295 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
4297 // Let the OnLeftButtonDown do the activating instead
4298 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4306 incref activateWindow;
4307 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
4309 delete activateWindow;
4313 if(activateWindow._refCount == 1)
4315 delete activateWindow;
4319 delete activateWindow;
4320 // Trouble with clickThrough, siblings and activation (Fix for nicktick scrolling, siblings/activation endless loops, #844)
4323 mods->isActivate = true;
4327 if(!modalWindow && window && !window.destroyed)
4329 if(!guiApp.windowCaptured || windowDragged)
4331 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
4333 bool moving = ((window.state != maximized &&
4334 window.IsMouseMoving(
4335 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4336 || (guiApp.windowMoving && !guiApp.windowIsResizing);
4338 if(!moving && window.IsMouseResizing(
4339 x - window.absPosition.x,
4340 y - window.absPosition.y,
4341 window.size.w, window.size.h,
4342 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
4344 guiApp.windowIsResizing = true;
4345 guiApp.windowResizingBefore.w = window.size.w;
4346 guiApp.windowResizingBefore.h = window.size.h;
4348 if(guiApp.windowIsResizing || windowDragged || moving)
4351 guiApp.windowMoving = window;
4352 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4353 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4354 guiApp.windowMovingBefore.x = window.position.x;//s;
4355 guiApp.windowMovingBefore.y = window.position.y;//s;
4356 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4357 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4360 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4362 if(window.style.fixed &&
4364 window.IsMouseMoving(
4365 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4367 window.ShowSysMenu(x, y);
4371 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4373 if(window.sbv || window.sbh)
4376 guiApp.windowScrolling = window;
4377 guiApp.windowScrollingStart.x = x;
4378 guiApp.windowScrollingStart.y = y;
4379 guiApp.windowScrollingBefore.x = window.scroll.x;
4380 guiApp.windowScrollingBefore.y = window.scroll.y;
4383 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4385 if(window.style.hasMaximize &&
4386 window.IsMouseMoving(
4387 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4390 (window.state == maximized) ? normal : maximized, false, *mods);
4398 if(guiApp.windowMoving)
4400 if(guiApp.windowMoving.parent)
4402 if(guiApp.windowMoving.style.nonClient)
4403 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4405 guiApp.windowMoving.parent.SetMouseRangeToClient();
4409 window.UpdateDecorations();
4412 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4414 // Log("\n*** LEFT BUTTON UP ***\n");
4415 if(guiApp.windowMoving)
4416 guiApp.windowMoving.StopMoving();
4418 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4420 if(guiApp.windowScrolling)
4422 Window windowScrolling = guiApp.windowScrolling;
4423 guiApp.windowScrolling = null;
4424 windowScrolling.ReleaseCapture();
4428 if(!result || (window && window.destroyed)) window = null;
4430 if(window && window.FindModal())
4433 if(trueWindow && trueWindow.FindModal())
4441 msgWindow = GetAtPosition(x,y, true, false);
4443 msgWindow.SelectMouseCursor();
4446 if(firstPass && (guiApp.windowCaptured || trueWindow))
4448 Window prevWindow = guiApp.prevWindow;
4449 List<Window> overWindows = guiApp.overWindows;
4450 Iterator<Window> it { overWindows };
4454 Window ww = it.data;
4455 if(trueWindow != ww && !trueWindow.IsDescendantOf(ww))
4458 result = ww.OnMouseLeave(*mods);
4460 overWindows.TakeOut(ww);
4464 if(result && guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4466 guiApp.prevWindow.mouseInside = false;
4467 guiApp.prevWindow = null;
4471 if(trueWindow.IsDescendantOf(prevWindow))
4473 if(!overWindows.Find(prevWindow))
4474 overWindows.Add(prevWindow);
4476 // Eventually fix this not to include captured?
4477 else if(!prevWindow.OnMouseLeave(*mods))
4481 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4483 Box box = trueWindow.box;
4484 box.left += trueWindow.absPosition.x;
4485 box.right += trueWindow.absPosition.x;
4486 box.top += trueWindow.absPosition.y;
4487 box.bottom += trueWindow.absPosition.y;
4489 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4491 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4492 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4494 overX = Max(Min(overX, 32767),-32768);
4495 overY = Max(Min(overY, 32767),-32768);
4497 trueWindow.mouseInside = true;
4498 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4502 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4504 for(wi : guiApp.overWindows; wi == trueWindow)
4507 guiApp.overWindows.TakeOut(wi);
4510 guiApp.prevWindow = trueWindow;
4513 guiApp.prevWindow = null;
4515 SelectMouseCursor();
4517 if(window && ((!guiApp.windowMoving && !wasMoving) ||
4518 (wasMoving && guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp)) && !wasScrolling)
4520 int clientX = x - (window.absPosition.x + window.clientStart.x);
4521 int clientY = y - (window.absPosition.y + window.clientStart.y);
4523 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4525 clientX = Max(Min(clientX, 32767),-32768);
4526 clientY = Max(Min(clientY, 32767),-32768);
4528 MouseMethod = (void *)window._vTbl[method];
4530 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4533 if(!MouseMethod(window, clientX, clientY, *mods))
4537 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4538 window.OnMouseLeave(*mods);
4545 if(result && w && w.clickThrough && w.parent)
4550 if(!result || !w || !w.clickThrough)
4558 // --- Mouse cursor management ---
4560 bool KeyMessage(uint method, Key key, unichar character)
4565 if(guiApp.interimWindow)
4566 this = guiApp.interimWindow;
4569 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4573 if(!style.inactive || rootWindow != this)
4575 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4576 Window modalWindow = FindModal();
4577 Window interimMaster = master ? master.rootWindow : null;
4581 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4582 status = OnSysKeyDown(key, character);
4584 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown ||
4585 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4586 status = OnSysKeyHit(key, character);
4587 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4588 status = OnSysKeyUp(key, character);
4595 // Process Key Message for Internal UI Keyboard actions
4596 if(status && !destroyed && menuBar && state != minimized)
4599 if((SmartKey)key != alt)
4600 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4603 SmartKey sk = (SmartKey) key;
4604 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4606 status = menuBar.KeyMessage(method, key, character);
4611 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4612 menuBar.OnKeyHit(escape, 0);
4614 if(!menuBar.focus && guiApp.caretOwner)
4615 guiApp.caretOwner.UpdateCaret(true, false);
4618 if(!destroyed && status)
4620 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4624 case left: case up: case right: case down:
4625 if(guiApp.windowMoving == this)
4628 int w = guiApp.windowMoving.size.w;
4629 int h = guiApp.windowMoving.size.h;
4630 int x = guiApp.windowMoving.scrolledPos.x;
4631 int y = guiApp.windowMoving.scrolledPos.y;
4635 if(key == down || key == up)
4636 step = Max(step, textCellH);
4638 step = Max(step, textCellW);
4641 if(guiApp.windowIsResizing)
4645 case left: w-=step; break;
4646 case right: w+=step; break;
4647 case up: h-=step; break;
4648 case down: h+=step; break;
4655 case left: x-=step; break;
4656 case right: x+=step; break;
4657 case up: y-=step; break;
4658 case down: y+=step; break;
4662 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4663 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4665 if(!guiApp.windowIsResizing || guiApp.resizeX)
4666 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4668 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4670 if(!guiApp.windowIsResizing || guiApp.resizeY)
4671 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4673 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4675 guiApp.interfaceDriver.SetMousePosition(x, y);
4676 ConsequentialMouseMove(true);
4684 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4686 guiApp.windowMoving.StopMoving();
4687 ConsequentialMouseMove(false);
4695 ShowSysMenu(absPosition.x, absPosition.y);
4703 if(!destroyed && status && state != minimized)
4705 // Process all the way down the children
4706 if(activeChild && !activeChild.disabled)
4708 status = activeChild.KeyMessage(method, key, character);
4710 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4711 key.code != left && key.code != right && key.code != up && key.code != down)
4713 status = activeClient.KeyMessage(method, key, character);
4717 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4719 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4720 // && defaultControl != activeChild)
4722 delete previousActive;
4723 previousActive = activeChild;
4724 if(previousActive) incref previousActive;
4726 ConsequentialMouseMove(false);
4727 if((defaultControl.active ||
4728 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4729 defaultControl.KeyMessage(method, defaultKey, character);
4735 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4737 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4744 ShowSysMenu(absPosition.x, absPosition.y);
4751 if(this != guiApp.desktop)
4753 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4755 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4757 MenuMoveOrSize(key.shift, true);
4761 else if(guiApp.windowMoving)
4763 guiApp.windowMoving.StopMoving();
4764 ConsequentialMouseMove(false);
4772 if(!destroyed && status && state != minimized)
4774 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4778 case tab: case shiftTab:
4780 Window cycleParent = this;
4781 if(this == guiApp.interimWindow && master && !master.style.interim && !cycleParent.style.tabCycle && master.parent)
4782 cycleParent = master.parent;
4784 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4786 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4789 Window child = cycleParent.activeChild;
4791 // Scroll the window to include the active control
4792 if(cycleParent.sbh && !child.style.dontScrollHorz)
4794 if(child.scrolledPos.x < 0)
4795 cycleParent.sbh.Action(Position,
4796 cycleParent.scroll.x + child.scrolledPos.x, 0);
4797 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4798 cycleParent.sbh.Action(Position,
4799 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4801 if(cycleParent.sbv && !child.style.dontScrollVert)
4803 if(child.scrolledPos.y < 0)
4804 cycleParent.sbv.Action(Position,
4805 cycleParent.scroll.y + child.scrolledPos.y, 0);
4806 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4807 cycleParent.sbv.Action(Position,
4808 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4811 cycleParent.ConsequentialMouseMove(false);
4817 case f6: case shiftF6:
4818 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4820 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4821 if(parent == guiApp.desktop)
4822 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4832 if(CycleChildren(key.shift, true, false, true))
4840 // mIRC Style Window Shortcuts
4841 case alt1: case alt2: case alt3: case alt4: case alt5:
4842 case alt6: case alt7: case alt8: case alt9: case alt0:
4847 for(document = children.first; document; document = document.next)
4849 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4851 if(document == activeChild)
4853 if(document.state == minimized)
4854 document.SetState(normal, false, key);
4857 document.SetState(minimized, false, key);
4858 CycleChildren(false, true, false);
4863 if(activeChild.state == maximized && document.style.hasMaximize)
4864 document.SetState(maximized, false, key);
4865 else if(document.state == minimized)
4866 document.SetState(normal, false, key);
4867 document.Activate();
4882 if(!destroyed && status)
4884 if(state == minimized)
4889 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4891 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4893 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4894 previousActive.ActivateEx(true, false, false, true, null, null);
4895 delete previousActive;
4901 if(!destroyed && status)
4903 status = ProcessHotKeys(method, key, character);
4905 if(!destroyed && status && !modalWindow && state != minimized)
4908 status = KeyMethod(this, key, character);
4909 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4910 status = OnKeyHit(key, character);
4911 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4913 bool result = false;
4916 case ctrlUp: case ctrlDown:
4917 if(sbv && !guiApp.windowScrolling)
4918 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4920 case wheelUp: case wheelDown:
4921 if(sbv && !guiApp.windowScrolling)
4923 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4924 // Do we want to do a consequential move regardless of result in this case?
4925 ConsequentialMouseMove(false);
4928 case ctrlPageUp: case ctrlPageDown:
4929 if(sbh && !guiApp.windowScrolling)
4930 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4935 ConsequentialMouseMove(false);
4940 if(status && !destroyed && menuBar && state != minimized)
4941 status = menuBar.KeyMessage(method, key, character);
4943 if(style.interim && /*destroyed && */status && interimMaster)
4945 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4946 status = interimMaster.KeyMessage(method, key, character);
4953 bool ProcessHotKeys(uint method, Key key, unichar character)
4958 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4959 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4960 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4962 Window hotKeyWindow = hotKey.window;
4963 Window parent = hotKeyWindow.parent;
4964 Window prevActiveWindow = activeChild;
4965 // For when sys buttons are placed inside the menu bar
4966 if(parent && parent._class == class(PopupMenu))
4967 parent = parent.parent;
4969 // 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
4970 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1])))
4973 if(prevActiveWindow) incref prevActiveWindow;
4974 incref hotKeyWindow;
4975 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient && !hotKeyWindow.inactive)
4976 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4979 delete hotKeyWindow;
4980 delete prevActiveWindow;
4984 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4985 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4986 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4988 // ********* WORKING ON THIS ***********
4989 if(prevActiveWindow && !guiApp.interimWindow)
4990 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4993 else if(hotKeyWindow.style.inactive)
4994 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4996 delete prevActiveWindow;
4997 delete hotKeyWindow;
4998 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4999 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
5003 if(status && tabCycle)
5006 for(child = children.first; child; child = child.next)
5008 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
5019 // --- Windows and graphics initialization / termination ---
5020 bool SetupRoot(void)
5024 // Setup relationship with outside world (bb root || !bb)
5025 #if defined(__EMSCRIPTEN__)
5026 if(this == guiApp.desktop)
5028 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
5029 (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))
5034 tempExtents = new0 Extent[4];
5039 /*if(guiApp.fullScreenMode)
5040 rootWindow = guiApp.desktop;
5042 //rootWindow = parent.created ? parent.rootWindow : null;
5043 rootWindow = parent.rootWindow;
5046 against = &parent.box;
5048 against = &parent.clientArea;
5051 for(child = children.first; child; child = child.next)
5054 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
5057 bool Setup(bool positionChildren)
5059 bool result = false;
5062 #if defined(__EMSCRIPTEN__)
5063 if(this == guiApp.desktop)
5065 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))))
5068 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
5069 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
5072 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
5074 // This was here, is it really needed?
5075 //guiApp.interfaceDriver.ActivateRootWindow(this);
5079 displaySystem = DisplaySystem { glCapabilities = glCapabilities };
5080 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
5082 delete displaySystem;
5087 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, glCapabilities = glCapabilities, windowDriverData = windowData };
5088 if(display.Create(displaySystem, windowHandle))
5095 // Sometimes icon does not show up on Windows XP if we set here...
5096 // guiApp.interfaceDriver.SetIcon(this, icon);
5098 else if(this != guiApp.desktop)
5100 display = rootWindow ? rootWindow.display : null;
5106 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
5107 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
5109 for(child = children.first; child; child = child.next)
5111 if(child.created && !child.Setup(false))
5114 if(guiApp.modeSwitching && guiApp.fullScreen && child.rootWindow == child)
5115 child.UpdateCaption();
5120 bool SetupDisplay(void)
5122 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
5123 if(is3D) return Window3D_SetupDisplay(this); else
5130 class_data void ** pureVTbl;
5132 bool LoadGraphics(bool creation, bool resetAnchors)
5134 bool result = false;
5135 bool success = false;
5137 WindowState stateBackup = state;
5139 if(((subclass(Window))_class).pureVTbl)
5141 if(_vTbl == _class._vTbl)
5143 _vTbl = ((subclass(Window))_class).pureVTbl;
5148 for(m = 0; m < _class.vTblSize; m++)
5150 if(_vTbl[m] == _class._vTbl[m])
5151 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5155 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
5157 if(_vTbl == ((subclass(Window))_class).pureVTbl)
5159 _vTbl = _class._vTbl;
5164 for(m = 0; m < _class.vTblSize; m++)
5166 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
5167 _vTbl[m] = _class._vTbl[m];
5173 #if !defined(__EMSCRIPTEN__)
5174 guiApp.fullScreenMode ||
5176 this != guiApp.desktop)
5178 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
5184 display.Lock(false);
5185 if(rootWindow == this)
5187 // Set Color Palette
5188 display.SetPalette(palette, true);
5192 if(guiApp.fullScreenMode && this == guiApp.desktop)
5197 for(c=0; c<SystemCursor::enumSize; c++)
5198 if(!guiApp.systemCursors[c].bitmap)
5200 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
5201 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
5202 if(guiApp.systemCursors[c].bitmapName)
5204 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
5205 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
5206 if(guiApp.systemCursors[c].bitmap)
5207 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
5212 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5214 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
5215 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
5217 cursor.bitmap.paletteShades = cursor.paletteShades;
5221 guiApp.cursorUpdate = true;
5224 ConsequentialMouseMove(false);
5230 // Load Window Graphic Resources
5233 if(usedFont == setFont || usedFont == window.systemFont)
5234 RemoveResource(usedFont);
5237 RemoveResource(setFont); // TESTING setFont instead of usedFont);
5240 RemoveResource(systemFont);
5243 RemoveResource(captionFont);
5245 for(ptr = resources.first; ptr; ptr = ptr.next)
5247 if(!ptr.loaded) // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
5248 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
5251 AddResource(setFont);
5253 AddResource(systemFont);
5255 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
5262 //if(master && master.font)
5263 if(parent && parent.font)
5267 faceName = parent.font.faceName,
5268 size = parent.font.size,
5269 bold = parent.font.bold,
5270 italic = parent.font.italic,
5271 underline = parent.font.underline
5273 //font = parent.font;
5274 watch(parent) { font { } };
5277 font = guiApp.currentSkin.SystemFont();
5284 captionFont = guiApp.currentSkin ? guiApp.currentSkin.CaptionFont() : null;
5285 AddResource(captionFont);
5287 if(OnLoadGraphics())
5293 //SetScrollLineStep(sbStep.x, sbStep.y);
5295 if(this != guiApp.desktop)
5299 normalAnchor = anchor;
5300 normalSizeAnchor = sizeAnchor;
5303 // Break the anchors for moveable/resizable windows
5305 if(style.fixed && style.isDocument)
5307 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
5319 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5320 stateSizeAnchor = SizeAnchor {};
5325 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5330 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
5331 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
5334 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5338 stateAnchor = normalAnchor;
5339 stateSizeAnchor = normalSizeAnchor;
5342 position = Point { };
5343 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5354 if(Position(x, y, w, h, true, false, true, true, true, true))
5356 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
5359 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
5376 success = result = true;
5379 if(!creation && result)
5381 // Load menu bar first because sys buttons are on it...
5384 if(!menuBar.LoadGraphics(false, resetAnchors))
5390 for(child = children.first; child; child = child.next)
5392 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
5399 CreateSystemChildren();
5403 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5406 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5409 LogErrorCode(graphicsLoadingFailed, _class.name);
5411 // Do this here to avoid problems on Windows
5412 if(rootWindow == this && parent && stateBackup == maximized)
5413 property::state = maximized;
5417 void UnloadGraphics(bool destroyWindows)
5421 // Free children's graphics
5422 for(child = children.first; child; child = child.next)
5423 child.UnloadGraphics(destroyWindows);
5426 display.Lock(false);
5429 if(guiApp.fullScreenMode && this == guiApp.desktop)
5434 for(c=0; c<SystemCursor::enumSize; c++)
5435 if(guiApp.systemCursors[c].bitmap)
5436 delete guiApp.systemCursors[c].bitmap;
5438 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5439 delete cursor.bitmap;
5441 guiApp.cursorBackground.Free();
5444 if(display && display.displaySystem)
5448 for(ptr = resources.first; ptr; ptr = ptr.next)
5452 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5457 // Free window graphics
5460 // Free skin graphics
5461 if(rootWindow == this)
5463 DisplaySystem displaySystem = display.displaySystem;
5466 display.driverData = null;
5467 display.displaySystem = null;
5471 if(displaySystem && !displaySystem.numDisplays && !is3D)
5472 delete displaySystem;
5481 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5482 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5484 if(this == guiApp.desktop || parent == guiApp.desktop)
5486 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5487 guiApp.interfaceDriver.DestroyRootWindow(this);
5491 // --- Window Hiding ---
5493 void SetVisibility(bool state)
5495 bool visible = (style.hidden || !created) ? false : state;
5496 if(visible != this.visible)
5500 this.visible = visible;
5501 for(child = children.first; child; child = child.next)
5502 child.SetVisibility(visible);
5504 ConsequentialMouseMove(false);
5505 if(parent && !nonClient) parent.OnChildVisibilityToggled(this, visible);
5509 // --- Windows and graphics initialization / termination ---
5511 bool DisplayModeChanged(void)
5513 bool result = false;
5514 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5516 guiApp.modeSwitching = true;
5517 UnloadGraphics(false);
5519 if(LoadGraphics(false, false))
5521 guiApp.modeSwitching = false;
5526 // --- Window updates system ---
5528 void UpdateDirty(Box updateBox)
5530 if(!manageDisplay) { OnRedraw(null);return; }
5533 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5536 if(display.flags.flipping)
5539 rootWindow.UpdateDisplay();
5542 UpdateBackDisplay(updateBox);
5544 if(guiApp.fullScreenMode)
5546 guiApp.cursorUpdate = true;
5547 guiApp.PreserveAndDrawCursor();
5549 if(guiApp.fullScreenMode)
5550 guiApp.RestoreCursorBackground();
5556 // This function is strictly called as a result of system window activation
5557 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5560 Window interimMaster = null;
5561 Window interimWindow = guiApp.interimWindow;
5562 if(interimWindow && interimWindow.master)
5563 interimMaster = interimWindow.master.rootWindow;
5565 if(active && state == minimized && window.parent) // && (!window.nativeDecorations || window.rootWindow != window)
5566 // SetState(normal, false, 0);
5567 SetState(lastState, false, 0);
5569 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5573 /* WTH is this doing here?
5574 while(swap && swap.activeChild)
5576 swap = swap.activeChild;
5579 // TESTING THIS BEFORE...
5580 if(interimWindow && this == interimMaster)
5584 // Window interimSwap = this;
5585 Window menuBar = this.menuBar;
5586 if(menuBar && interimWindow.master == menuBar)
5589 while(interimSwap && interimSwap.activeChild)
5590 interimSwap = interimSwap.activeChild;
5592 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5593 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5595 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5596 //result = ActivateEx(true, true, false, activateRoot, window, null);
5601 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5602 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5604 if(interimWindow == this && interimMaster && !active)
5606 while(interimMaster && interimMaster.interim && interimMaster.master)
5608 // printf("Going up one master %s\n", interimMaster._class.name);
5609 interimMaster = interimMaster.master.rootWindow;
5611 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5612 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5618 bool DestroyEx(int64 returnCode)
5621 Timer timer, nextTimer;
5623 OldLink prevOrder = null;
5624 Window client = null;
5626 if(parent) stopwatching(parent, font);
5628 // if(window.modalSlave) return false;
5629 if(destroyed || !created)
5636 OldLink slave = master.slaves.FindLink(this);
5637 master.slaves.Delete(slave);
5640 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5646 this.returnCode = (DialogResult)returnCode;
5648 AcquireInput(false);
5653 master.hotKeys.Delete(hotKey);
5657 if(guiApp.prevWindow == this)
5659 guiApp.prevWindow = null;
5664 for(w : guiApp.overWindows; w == this)
5667 guiApp.overWindows.TakeOut(w);
5671 if(guiApp.caretOwner == this)
5673 guiApp.interfaceDriver.SetCaret(0,0,0);
5674 UpdateCaret(false, true);
5675 guiApp.caretEnabled = false;
5680 parent.childrenCycle.Remove(cycle);
5684 OldLink tmpPrev = order.prev;
5685 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5686 prevOrder = tmpPrev;
5689 client = tmpPrev ? tmpPrev.data : null;
5690 if(client == this) { client = null; break; }
5691 if(client && (client.style.hidden || client.destroyed || !client.created))
5692 tmpPrev = client.order.prev;
5696 prevOrder = tmpPrev;
5701 // If this window can be an active client, make sure the next window we activate can also be one
5702 if(!style.nonClient && style.isActiveClient)
5704 tmpPrev = prevOrder;
5707 client = tmpPrev ? tmpPrev.data : null;
5708 if(client == this) { client = null; break; }
5709 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5710 tmpPrev = client.order.prev;
5714 prevOrder = tmpPrev;
5718 if(client && client.style.hidden) client = null;
5720 // parent.childrenOrder.Remove(order);
5723 if(parent && style.isActiveClient && visible)
5725 if(state == minimized) parent.numIcons--;
5726 parent.numPositions--;
5729 // TESTING THIS HERE!
5733 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5734 // to create a window inside a rootwindow that's being destroyed)
5735 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5737 if(master && !master.destroyed /*&&
5738 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5740 if(master.defaultControl == this)
5741 master.defaultControl = null;
5744 parent.OnChildAddedOrRemoved(this, true);
5745 if(parent && !parent.destroyed /*&&
5746 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5748 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5750 if(order && prevOrder && prevOrder.data != this && active)
5752 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5754 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5755 if(parent.activeClient == this)
5757 parent.activeClient = null;
5758 parent.UpdateActiveDocument(null);
5763 if(guiApp.interimWindow == this)
5766 PropagateActive(false, null, &goOn, true);
5770 //if(window.parent.activeChild == window)
5771 parent.activeChild = null;
5772 if(!style.nonClient /*&& style.isActiveClient*/)
5774 Window previous = parent.activeClient;
5775 if(style.isActiveClient)
5776 parent.activeClient = null;
5777 parent.UpdateActiveDocument(previous);
5782 else if(parent.activeClient == this)
5784 parent.activeClient = client;
5785 parent.UpdateActiveDocument(this);
5789 if(guiApp.interimWindow == this)
5791 guiApp.interimWindow = null;
5792 if(guiApp.caretOwner)
5794 Window desktop = guiApp.desktop;
5795 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5796 guiApp.caretOwner.UpdateCaret(false, false);
5801 if(_isModal && master && master.modalSlave == this)
5802 master.modalSlave = null;
5806 if(!guiApp.caretOwner && parent.caretSize)
5808 guiApp.caretOwner = parent;
5809 parent.UpdateCaret(false, false);
5810 parent.Update(null);
5813 // Why was this commented out?
5814 GetRidOfVirtualArea();
5820 dirtyArea.Free(null);
5821 dirtyBack.Free(null);
5822 scrollExtent.Free(null);
5824 /* ATTEMPTING TO MOVE THAT ABOVE
5833 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5834 for(;(child = window.children.first);)
5836 for(; child && (child.destroyed || !child.created); child = child.next);
5845 UnloadGraphics(true);
5848 delete previousActive;
5851 // statusBar = null;
5854 if(master && !master.destroyed)
5856 //master.NotifyDestroyed(this, this.returnCode);
5857 NotifyDestroyed(master, this, this.returnCode);
5860 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5862 nextTimer = timer.next;
5863 if(timer.window == this)
5865 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5866 // timer.window = null;
5872 if(this == guiApp.windowMoving)
5875 if(guiApp.windowCaptured == this)
5877 //guiApp.windowCaptured = null;
5879 if(rootWindow != this && rootWindow)
5880 rootWindow.ConsequentialMouseMove(false);
5888 //for(child = children.first; next = child ? child.next : null, child; child = next)
5889 for(;(child = children.first); )
5891 for(; child && (child.destroyed || !child.created); child = child.next);
5901 /* // MOVED THIS UP...
5904 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5905 for(;(child = window.children.first); )
5907 for(; child && (child.destroyed || !child.created); child = child.next);
5916 while((slave = slaves.first))
5918 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5920 ((Window)slave.data).DestroyEx(0);
5925 if(guiApp.caretOwner == this)
5926 guiApp.caretOwner = null;
5928 sysButtons[0] = null;
5929 sysButtons[1] = null;
5930 sysButtons[2] = null;
5933 if(rootWindow != this)
5935 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5938 box.left -= parent.clientStart.x;
5939 box.top -= parent.clientStart.y;
5940 box.right -= parent.clientStart.x;
5941 box.bottom -= parent.clientStart.y;
5943 if(parent) parent.Update(box);
5948 OldLink slave = master.slaves.FindVoid(this);
5949 master.slaves.Delete(slave);
5955 parent.children.Remove(this);
5960 //autoCreate = false;
5963 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5964 if(((subclass(Window))_class).pureVTbl)
5966 if(_vTbl == _class._vTbl)
5968 _vTbl = ((subclass(Window))_class).pureVTbl;
5973 for(m = 0; m < _class.vTblSize; m++)
5975 if(_vTbl[m] == _class._vTbl[m])
5976 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5985 void SetStateEx(WindowState newState, bool activate)
5988 WindowState prevState = state;
5992 if(prevState != newState)
5993 lastState = prevState;
5995 if(rootWindow != this || !nativeDecorations || !windowHandle)
5997 if(style.isActiveClient && !style.hidden && prevState == minimized)
6000 // This block used to be at the end of the function... moved it for flicker problem in X
6001 // ------------------------------------------------------
6005 stateAnchor = normalAnchor;
6006 stateSizeAnchor = normalSizeAnchor;
6009 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
6010 stateSizeAnchor = SizeAnchor {};
6016 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
6019 byte * idBuffer = new0 byte[size];
6021 for(child = parent.children.first; child; child = child.next)
6023 if(child != this && child.state == minimized)
6025 if(child.iconID > size - 2)
6027 idBuffer = renew0 idBuffer byte[size*2];
6028 memset(idBuffer + size, 0, size);
6031 idBuffer[child.iconID] = (byte)bool::true;
6034 for(c = 0; c<size; c++)
6039 if(style.isActiveClient && !style.hidden)
6042 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
6043 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
6048 // TOCHECK: Why was this here?
6049 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
6050 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
6051 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6053 if(state != minimized || hasMinimize)
6054 Position(x, y, w, h, true, true, true, true, false, true);
6056 if(!style.inactive && !style.interim && parent && this == parent.activeClient)
6057 parent.UpdateActiveDocument(null);
6060 if(state != minimized || hasMinimize)
6061 CreateSystemChildren();
6062 // ------------------------------------------------------
6065 int GetPositionID(Window forChild)
6069 byte * idBuffer = new0 byte[size];
6072 for(child = children.first; child; child = child.next)
6074 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
6076 if(child.positionID > size - 2)
6078 idBuffer = renew0 idBuffer byte[size*2];
6079 memset(idBuffer + size, 0, size);
6082 idBuffer[child.positionID] = (byte)bool::true;
6085 for(c = 0; c<size; c++)
6092 // --- Window related graphics ---
6094 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
6096 palette = newPalette;
6097 if(rootWindow.display)
6098 rootWindow.display.SetPalette(palette, colorMatch);
6101 public bool AcquireInput(bool acquired)
6104 if((guiApp.acquiredWindow && acquiredInput) != acquired)
6106 if(active || (!visible && creationActivation == activate))
6107 result = AcquireInputEx(acquired);
6112 acquiredInput = acquired ? result : !result;
6117 void ListChildren(ListBox listBox)
6121 for(child = children.first; child; child = child.next)
6123 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
6125 DataRow row = listBox.AddRow();
6126 row.tag = (int64)(intptr)child;
6127 child.FigureCaption(caption);
6128 row.SetData(null, caption);
6133 void UpdateVisual(Box extent)
6135 if(guiApp.driver != null)
6137 #if !defined(__EMSCRIPTEN__)
6138 if(guiApp.fullScreenMode && guiApp.desktop.display)
6143 #if !defined(__EMSCRIPTEN__)
6144 guiApp.desktop.mutex.Wait();
6146 guiApp.desktop.display.Lock(true);
6149 if(guiApp.desktop.active)
6151 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
6153 if(guiApp.desktop.display.flags.flipping)
6154 guiApp.desktop.Update(null);
6155 guiApp.desktop.UpdateDisplay();
6156 guiApp.cursorUpdate = true;
6158 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
6160 guiApp.PreserveAndDrawCursor();
6161 // guiApp.desktop.display.ShowScreen();
6162 guiApp.cursorUpdate = false;
6163 guiApp.desktop.dirty = false;
6164 guiApp.RestoreCursorBackground();
6168 guiApp.desktop.display.Unlock();
6169 #if !defined(__EMSCRIPTEN__)
6170 guiApp.desktop.mutex.Release();
6175 Window rootWindow = this.rootWindow;
6176 #if !defined(__EMSCRIPTEN__)
6177 rootWindow.mutex.Wait();
6183 guiApp.SignalEvent();
6186 #if !defined(__EMSCRIPTEN__)
6187 guiApp.waitMutex.Wait();
6189 guiApp.interfaceDriver.Lock(rootWindow);
6190 if(!rootWindow.style.hidden && rootWindow.dirty)
6192 if(rootWindow.display)
6194 rootWindow.UpdateDisplay();
6195 //rootWindow.display.ShowScreen(null);
6197 rootWindow.dirty = false;
6199 guiApp.interfaceDriver.Unlock(rootWindow);
6200 #if !defined(__EMSCRIPTEN__)
6201 guiApp.waitMutex.Release();
6205 #if !defined(__EMSCRIPTEN__)
6206 rootWindow.mutex.Release();
6212 void UnlockDisplay(void)
6214 guiApp.interfaceDriver.Unlock(rootWindow);
6217 void LockDisplay(void)
6219 guiApp.interfaceDriver.Lock(rootWindow);
6222 Surface GetSurface(Box box)
6224 return Redraw((box == null) ? this.box : box);
6227 void SetMousePosition(int x, int y)
6229 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
6233 void IntegrationActivate(bool active)
6235 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
6237 isForegroundWindow = true;
6238 ActivateEx(active, active, false, false, null, null);
6239 isForegroundWindow = false;
6244 Window QueryCapture(void)
6246 return guiApp.windowCaptured;
6249 int GetDocumentID(void)
6253 byte * idBuffer = new0 byte[size];
6256 for(child = children.first; child; child = child.next)
6258 // TO CHECK: Do we want a documentID when we already have a file name?
6259 if(child.style.isDocument && !child.fileName)
6261 if(child.documentID-1 > size - 2)
6263 idBuffer = renew0 idBuffer byte[size*2];
6264 memset(idBuffer + size, 0, size);
6267 idBuffer[child.documentID-1] = 1;
6270 for(c = 0; c<size; c++)
6278 void SetInitSize(Size size)
6281 sizeAnchor.size = size;
6282 normalSizeAnchor = sizeAnchor;
6284 // Break the anchors for moveable/resizable windows
6285 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6287 stateAnchor = normalAnchor;
6288 stateSizeAnchor = normalSizeAnchor;
6290 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6291 Position(x,y, w, h, true, true, true, true, false, true);
6295 void MenuMoveOrSize(bool resize, bool setCursorPosition)
6297 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
6299 guiApp.windowIsResizing = resize;
6300 guiApp.windowMoving = this;
6301 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
6302 if(guiApp.windowIsResizing)
6304 guiApp.windowMovingStart.x += size.w - 1;
6305 guiApp.windowMovingStart.y += size.h - 1;
6307 guiApp.windowMovingBefore = scrolledPos;
6308 guiApp.windowResizingBefore = size;
6309 guiApp.windowMoving.UpdateDecorations();
6310 if(guiApp.windowIsResizing)
6311 guiApp.resizeEndX = guiApp.resizeEndY = true;
6313 if(setCursorPosition)
6314 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
6318 guiApp.interfaceDriver.GetMousePosition(&x, &y);
6319 guiApp.windowMovingStart.x += x - absPosition.x;
6320 guiApp.windowMovingStart.y += y - absPosition.y;
6323 if(guiApp.windowMoving)
6325 if(guiApp.windowMoving.style.nonClient)
6326 guiApp.windowMoving.parent.SetMouseRangeToWindow();
6328 guiApp.windowMoving.parent.SetMouseRangeToClient();
6333 if(this == rootWindow)
6334 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
6338 void SetupFileMonitor()
6340 #if !defined(__EMSCRIPTEN__)
6343 fileMonitor = FileMonitor
6345 this, FileChange { modified = true };
6347 bool OnFileNotify(FileChange action, const char * param)
6350 fileMonitor.StopMonitoring();
6351 if(OnFileModified(action, param))
6352 fileMonitor.StartMonitoring();
6366 bool result = false;
6370 else if(guiApp && guiApp.driver != null)
6372 OldLink slaveHolder;
6374 bool visible = !style.hidden;
6378 systemParent = parent;
6379 parent = guiApp.desktop;
6381 last = parent ? parent.children.last : null;
6383 if((parent && parent != guiApp.desktop && !parent.created) ||
6384 (master && master != guiApp.desktop && !master.created))
6388 stopwatching(parent, font);
6391 property::parent = guiApp.desktop;
6392 if(!master) master = parent;
6394 if(_isModal && master.modalSlave)
6395 property::master = master.modalSlave;
6399 parent.children.Remove(this);
6402 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
6403 if(slaveHolder.data == this)
6405 master.slaves.Delete(slaveHolder);
6410 #if !defined(__EMSCRIPTEN__)
6411 if(parent == guiApp.desktop && !mutex)
6415 if(style.isDocument)
6418 parent.numDocuments--;
6419 documentID = parent.GetDocumentID();
6422 if(!style.stayOnTop)
6423 for(; last && last.style.stayOnTop; last = last.prev);
6425 parent.children.Insert((last == this) ? null : last, this);
6426 //parent.children.Add(this);
6429 dispDriver = parent.dispDriver;
6432 master.modalSlave = this;
6434 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
6439 master.slaves.Add(slaveHolder = OldLink { data = this });
6444 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
6446 if(style.isDefault && !master.defaultControl)
6447 master.defaultControl = this;
6449 stateAnchor = normalAnchor = anchor;
6450 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
6452 // TOCHECK: Why is this here?
6453 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
6454 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
6456 this.visible = false;
6457 style.hidden = true;
6460 // autoCreate = true;
6468 if(parent == guiApp.desktop)
6469 Log("LoadGraphics %s\n", caption);
6471 if(LoadGraphics(true, false))
6479 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6486 if(style.hasMenuBar /*&& menu*/)
6492 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6493 interim = false, inactive = true, nonClient = true, size.h = 24
6501 // Create the system buttons
6502 CreateSystemChildren();
6504 UpdateActiveDocument(null);
6506 if(style.isDocument)
6510 MenuItem item = menu.FindItem(MenuFileSave, 0);
6511 if(item) item.disabled = !modifiedDocument && fileName;
6516 if(parent == guiApp.desktop)
6517 Log("Preemptive SetState %s\n", caption);
6520 // Preemptive Set State to ensure proper anchoring
6521 SetStateEx(state, false);
6523 style.hidden = true;
6529 for(child = children.first; child; child = next)
6532 if(!child.created && (child.autoCreate || child.wasCreated))
6539 for(link = slaves.first; link; link = next)
6541 Window slave = link.data;
6543 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6546 // Things might have happened that invalidated 'next'...
6547 // Start over the search for slaves to create.
6548 // (Added this to fix crash with Stacker & Toolbar)
6549 next = slaves.first;
6558 if(parent == guiApp.desktop)
6559 Log("Real SetState %s\n", caption);
6562 if(isActiveClient && visible)
6564 parent.numPositions--;
6565 if(state == minimized) parent.numIcons--;
6568 parent.OnChildAddedOrRemoved(this, false);
6570 if(rootWindow == this && visible) // So that X11 windows don't show as 'unknown'
6572 // Real set state & activate for proper display & activation
6573 property::visible = visible;
6574 // SetState(state & 0x00000003, true, 0);
6575 guiApp.interfaceDriver.SetIcon(this, icon);
6580 /*if(rootWindow == this)
6581 guiApp.interfaceDriver.ActivateRootWindow(this);
6583 if(creationActivation == activate && guiApp.desktop.active)
6584 ActivateEx(true, false, true, true, null, null);
6585 else if(creationActivation == activate || creationActivation == flash)
6588 if(this == rootWindow)
6593 if(!destroyed && !noConsequential)
6594 rootWindow.ConsequentialMouseMove(false);
6605 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6611 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6613 //style.hidden = true; // !visible;
6614 style.hidden = !visible;
6615 if(master.modalSlave == this)
6616 master.modalSlave = null;
6623 void WriteCaption(Surface surface, int x, int y)
6626 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6629 void Update(Box region)
6635 rootWindow = this.rootWindow;
6637 // rootWindow.mutex.Wait();
6638 if(!destroyed && visible && display)
6643 // Testing this to avoid repetitve full update to take time...
6644 if(rootWindow.fullRender)
6646 rootWindow.dirty = true;
6649 if(dirtyArea.count == 1)
6651 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6652 if(item.box.left <= box.left &&
6653 item.box.top <= box.top &&
6654 item.box.right >= box.right &&
6655 item.box.bottom >= box.bottom)
6657 rootWindow.dirty = true;
6662 if(display.flags.flipping && !rootWindow.dirty)
6664 if(this == rootWindow)
6668 rootWindow.Update(null);
6673 rootWindow.dirty = true;
6678 realBox.left += clientStart.x;
6679 realBox.top += clientStart.y;
6680 realBox.right += clientStart.x;
6681 realBox.bottom += clientStart.y;
6687 if(realBox.right >= realBox.left &&
6688 realBox.bottom >= realBox.top)
6690 // if(!rootWindow.fullRender)
6691 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6693 for(child = children.first; child; child = child.next)
6698 box.left -= child.absPosition.x - absPosition.x;
6699 box.top -= child.absPosition.y - absPosition.y;
6700 box.right -= child.absPosition.x - absPosition.x;
6701 box.bottom -= child.absPosition.y - absPosition.y;
6702 if(box.right >= child.box.left && box.left <= child.box.right &&
6703 box.bottom >= child.box.top && box.top <= child.box.bottom)
6705 box.left -= child.clientStart.x;
6706 box.top -= child.clientStart.y;
6707 box.right -= child.clientStart.x;
6708 box.bottom -= child.clientStart.y;
6714 realBox.left += absPosition.x - rootWindow.absPosition.x;
6715 realBox.top += absPosition.y - rootWindow.absPosition.y;
6716 realBox.right += absPosition.x - rootWindow.absPosition.x;
6717 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6718 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6721 else if(this == guiApp.desktop)
6724 for(window = children.first; window; window = window.next)
6730 Box childBox = region;
6732 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6733 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6734 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6735 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6737 window.Update(childBox);
6740 window.Update(null);
6745 // rootWindow.mutex.Release();
6752 if(guiApp.windowCaptured != this)
6754 if(guiApp.windowCaptured)
6758 //Logf("Captured %s (%s)\n", caption, class.name);
6759 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6760 guiApp.windowCaptured = this;
6766 bool Destroy(int64 code)
6771 if(!destroyed && !CloseConfirmation(false)) return false;
6775 // TOCHECK: Should autoCreate be set to false here?
6786 void Move(int x, int y, int w, int h)
6788 normalAnchor = Anchor { left = x, top = y };
6789 normalSizeAnchor = SizeAnchor { size = { w, h } };
6791 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6793 if(destroyed) return;
6795 stateAnchor = normalAnchor;
6796 stateSizeAnchor = normalSizeAnchor;
6798 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6799 Position(x,y, w, h, true, true, true, true, false, true);
6803 DialogResult Modal(void)
6809 // FIXES MEMORY LEAK IF Create() FAILED
6815 void SetScrollArea(int width, int height, bool snapToStep)
6819 int stepX = sbStep.x, stepY = sbStep.y;
6820 // Needed to make snapped down position match the skin's check of client area
6821 // against realvirtual
6824 SNAPDOWN(stepX, textCellW);
6825 SNAPDOWN(stepY, textCellH);
6826 stepX = Max(stepX, textCellW);
6827 stepY = Max(stepY, textCellH);
6829 if(scrollFlags.snapX)
6830 SNAPUP(width, stepX);
6831 if(scrollFlags.snapY)
6832 SNAPUP(height, stepY);
6835 reqScrollArea.w = width;
6836 reqScrollArea.h = height;
6837 noAutoScrollArea = (width > 0 || height > 0);
6839 UpdateScrollBars(true, true);
6842 void SetScrollPosition(int x, int y)
6845 sbh.Action(setPosition, x, 0);
6849 int seen = clientSize.w, total = reqScrollArea.w;
6851 if(scrollFlags.snapX)
6852 SNAPDOWN(seen, sbStep.x);
6854 if(!total) total = seen;
6855 range = total - seen + 1;
6856 range = Max(range, 1);
6858 if(x >= range) x = range - 1;
6860 if(scrollFlags.snapX)
6861 SNAPUP(x, sbStep.x);
6864 OnHScroll(setPosition, x, 0);
6868 SNAPDOWN(x, textCellW);
6874 sbv.Action(setPosition, y, 0);
6878 int seen = clientSize.h, total = reqScrollArea.h;
6881 if(scrollFlags.snapY)
6882 SNAPDOWN(seen, sbStep.y);
6884 if(!total) total = seen;
6885 range = total - seen + 1;
6886 range = Max(range, 1);
6888 if(y >= range) y = range - 1;
6890 if(scrollFlags.snapY)
6891 SNAPUP(y, sbStep.y);
6894 OnVScroll(setPosition, y, 0);
6897 SNAPDOWN(y, textCellH);
6902 UpdateCaret(false, false);
6905 void SetScrollLineStep(int stepX, int stepY)
6911 SNAPDOWN(stepX, textCellW);
6912 SNAPDOWN(stepY, textCellH);
6913 stepX = Max(stepX, textCellW);
6914 stepY = Max(stepY, textCellH);
6917 sbh.lineStep = stepX;
6919 sbv.lineStep = stepY;
6922 void SetState(WindowState newState, bool activate, Modifiers mods)
6926 if(state == newState || OnStateChange(newState, mods))
6928 //WindowState prevState = state;
6932 // This used to be at the end of the brackets... moved for X, testing...
6933 // This has the effect of activating the window through the system...
6934 if(rootWindow == this)
6935 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6937 SetStateEx(newState, activate);
6939 if(rootWindow == this && !rootWindow.nativeDecorations)
6941 int x = position.x, y = position.y;
6944 x -= guiApp.desktop.absPosition.x;
6945 y -= guiApp.desktop.absPosition.y;
6947 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6951 //state = prevState;
6953 if(state != maximized && style.hasMaximize)
6956 for(child = parent.children.first; child; child = child.next)
6958 if(child != this && child.state == maximized)
6959 child.SetStateEx(normal, false);
6963 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6964 parent.UpdateScrollBars(true, true);
6967 // Do we really need this stuff here?
6968 // Shouldn't the Activate stuff take care of it?
6969 if(parent.rootWindow == parent && style)
6972 parent.FigureCaption(caption);
6973 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6974 parent.UpdateDecorations();
6978 rootWindow.ConsequentialMouseMove(false);
6985 BitmapResource GetIcon(SkinBitmap iconID)
6987 return guiApp.currentSkin.GetBitmap(iconID);
6990 void SetMouseRange(Box range)
6992 if(range || guiApp.fullScreenMode)
6997 clip.left = range.left + absPosition.x + clientStart.x;
6998 clip.top = range.top + absPosition.y + clientStart.y;
6999 clip.right = range.right + absPosition.x + clientStart.x;
7000 clip.bottom = range.bottom + absPosition.y + clientStart.y;
7004 clip.left = guiApp.desktop.box.left;
7005 clip.top = guiApp.desktop.box.top;
7006 clip.right = guiApp.desktop.box.right;
7007 clip.bottom = guiApp.desktop.box.bottom;
7009 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
7012 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
7015 void SetMouseRangeToClient(void)
7017 if(guiApp.fullScreenMode || this != guiApp.desktop)
7019 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
7020 box.Clip(clientArea);
7024 SetMouseRange(null);
7027 void SetMouseRangeToWindow(void)
7029 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
7030 if(this == guiApp.desktop)
7031 SetMouseRangeToClient();
7036 // x, y: Desktop Coordinates
7037 void ShowSysMenu(int x, int y)
7040 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
7043 menu, $"Restore", r, NotifySelect = MenuWindowRestore,
7044 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
7048 menu, $"Move", m, NotifySelect = MenuWindowMove,
7049 disabled = !style.fixed || state == maximized
7053 menu, $"Size", s, NotifySelect = MenuWindowSize,
7054 disabled = !style.sizable || state != normal
7058 menu, $"Minimize", n, NotifySelect = MenuWindowMinimize,
7059 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
7063 menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
7064 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
7068 menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
7069 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
7071 MenuDivider { menu };
7074 menu, $"Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
7075 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
7077 windowMenu.Create();
7082 ActivateEx(true, true, true, true, null, null);
7085 void MakeActive(void)
7087 ActivateEx(true, false, true, false, null, null);
7090 void SoftActivate(void)
7092 if(guiApp.desktop.active)
7097 if(this == rootWindow)
7102 void Deactivate(void)
7104 ActivateEx(false, true, true, true, null, null);
7109 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
7112 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
7114 bool result = false;
7115 if(activeChild && activeChild.cycle)
7117 Window modalWindow, child = activeChild;
7118 if(!clientOnly /*&& parent.tabCycle*/)
7120 Window next = child;
7123 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
7127 if(parent && parent.CycleChildren(backward, false, true, true))
7135 next = next.cycle.prev.data;
7137 next = next.cycle.next.data;
7138 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
7143 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
7144 parent.tabCycle && parent.CycleChildren(backward, false, false))
7148 if(tabCycleOnly && !tabCycle) return false;
7155 child = child.cycle.prev.data;
7157 child = child.cycle.next.data;
7158 if(child == child.parent.activeChild)
7160 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
7163 modalWindow = child.FindModal();
7166 // Scroll the window to include the active control
7167 if(sbh && !child.style.dontScrollHorz)
7169 if(child.scrolledPos.x < 0)
7170 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
7171 else if(child.scrolledPos.x + child.size.w > clientSize.w)
7172 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
7174 if(sbv && !child.style.dontScrollVert)
7176 if(child.scrolledPos.y < 0)
7177 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
7178 else if(child.scrolledPos.y + child.size.h > clientSize.h)
7179 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
7183 child = modalWindow ? modalWindow : child;
7184 child.ActivateEx(true, true, true, true, null, null);
7185 if(child.tabCycle && child.childrenCycle.first)
7186 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
7194 ConsequentialMouseMove(false);
7198 void AddResource(Resource resource)
7202 ResPtr ptr { resource = resource };
7206 // Load Graphics here if window is created already
7207 if(/*created && */display)
7209 display.Lock(false);
7210 if(!ptr.loaded) // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
7211 ptr.loaded = display.displaySystem.LoadResource(resource);
7215 // Temporary hack to load font right away for listbox in dropbox ...
7216 else if(master && master.display)
7218 master.display.Lock(false);
7219 master.display.displaySystem.LoadResource(resource);
7220 master.display.Unlock();
7226 void RemoveResource(Resource resource)
7231 for(ptr = resources.first; ptr; ptr = ptr.next)
7233 if(ptr.resource == resource)
7239 // Unload Graphics here if window is created already
7240 if(/*created && */display)
7244 display.Lock(false);
7245 display.displaySystem.UnloadResource(resource, ptr.loaded);
7251 resources.Delete(ptr);
7256 void SetCaret(int x, int y, int size)
7263 if(active && !style.interim && isEnabled)
7265 if(visible || !guiApp.caretOwner)
7266 guiApp.caretOwner = size ? this : null;
7268 UpdateCaret(false, false);
7271 guiApp.interfaceDriver.SetCaret(0,0,0);
7272 UpdateCaret(false, true);
7273 guiApp.caretEnabled = false;
7276 else if(style.inactive && active)
7278 guiApp.interfaceDriver.SetCaret(0,0,0);
7279 UpdateCaret(false, true);
7280 guiApp.caretEnabled = false;
7285 void Scroll(int x, int y)
7287 bool opaque = !style.drawBehind || background.a;
7288 if(opaque && display && display.flags.scrolling)
7290 Box box = clientArea;
7291 box.left += clientStart.x;
7292 box.top += clientStart.y;
7293 box.right += clientStart.x;
7294 box.bottom += clientStart.y;
7296 //scrollExtent.Free(null);
7297 scrollExtent.AddBox(box);
7298 scrolledArea.x += x;
7299 scrolledArea.y += y;
7301 //scrollExtent.Free();
7302 //scrollExtent.AddBox(clientArea);
7303 //scrollExtent.Offset(clientStart.x, clientStart.y);
7304 //scrolledArea.x = x;
7305 //scrolledArea.y = y;
7311 rootWindow.dirty = true;
7314 void ReleaseCapture()
7316 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
7318 Window oldCaptured = guiApp.windowCaptured;
7319 guiApp.windowCaptured = null;
7320 guiApp.prevWindow = null;
7323 //guiApp.Log("Released Capture\n");
7325 guiApp.interfaceDriver.SetMouseCapture(null);
7327 //oldCaptured.OnMouseCaptureLost();
7330 oldCaptured.ConsequentialMouseMove(false);
7335 private void _SetCaption(const char * format, va_list args)
7342 char caption[MAX_F_STRING];
7343 vsnprintf(caption, sizeof(caption), format, args);
7344 caption[sizeof(caption)-1] = 0;
7346 this.caption = CopyString(caption);
7351 firewatchers caption;
7355 /*deprecated*/ void SetText(const char * format, ...)
7358 va_start(args, format);
7359 _SetCaption(format, args);
7363 void SetCaption(const char * format, ...)
7366 va_start(args, format);
7367 _SetCaption(format, args);
7371 bool Grab(Bitmap bitmap, Box box, bool decorations)
7373 bool result = false;
7374 if(display || this == guiApp.desktop)
7376 Box clip = {MININT, MININT, MAXINT, MAXINT};
7382 clip.Clip(clientArea);
7384 clip.Clip(this.box);
7386 if(rootWindow != this)
7388 clip.left += absPosition.y;
7389 clip.top += absPosition.y;
7390 clip.right += absPosition.x;
7391 clip.bottom += absPosition.y;
7394 if(!nativeDecorations)
7396 clip.left += decorations ? 0 : clientStart.x;
7397 clip.top += decorations ? 0 : clientStart.y;
7398 clip.right += decorations ? 0 : clientStart.x;
7399 clip.bottom += decorations ? 0 : clientStart.y;
7402 if(decorations && this == guiApp.desktop)
7403 clip = { 0, 0, guiApp.virtualScreen.w, guiApp.virtualScreen.h };
7405 if(display && display.flags.flipping)
7407 rootWindow.Update(null);
7408 rootWindow.UpdateDisplay();
7415 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
7416 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7420 result = display.Grab(bitmap, clip.left, clip.top,
7421 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7423 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
7425 if(!bitmap.Convert(null, pixelFormat888, null))
7432 void GetMousePosition(int * x, int * y)
7434 int mouseX = 0, mouseY = 0;
7435 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
7438 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
7439 if(this != guiApp.desktop)
7441 mouseX -= absPosition.x + clientStart.x;
7442 mouseY -= absPosition.y + clientStart.y;
7449 DialogResult DoModal()
7451 DialogResult returnCode = 0;
7452 int terminated = terminateX;
7455 while(!destroyed && guiApp.driver != null)
7457 if(terminateX != terminated)
7459 terminated = terminateX;
7460 guiApp.desktop.Destroy(0);
7461 if(guiApp.desktop.created)
7464 //printf("Resetting terminate X to 0\n");
7470 guiApp.UpdateDisplay();
7471 if(!guiApp.ProcessInput(false))
7474 returnCode = this.returnCode;
7487 return !destroyed && guiApp.driver != null && terminateX < 2;
7490 DialogResult DoModalEnd()
7492 DialogResult returnCode = this.returnCode;
7497 // --- Window manipulation ---
7498 /*bool GetDisabled()
7500 bool disabled = this.disabled;
7502 for(window = this; (window = window.master); )
7513 // --- Mouse Manipulation ---
7514 void GetNCMousePosition(int * x, int * y)
7516 GetMousePosition(x, y);
7517 if(x) *x += clientStart.x;
7518 if(y) *y += clientStart.y;
7521 // --- Carets manipulation ---
7522 void GetCaretPosition(Point caretPos)
7524 caretPos = this.caretPos;
7527 int GetCaretSize(void)
7532 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7538 bool CloseConfirmation(bool parentClosing)
7551 if(!OnClose(parentClosing))
7554 // If you want to skip this, simply set modifiedDocument to false in OnClose
7555 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7557 DialogResult dialogRes;
7560 sprintf(message, $"Save changes to %s?", fileName);
7562 sprintf(message, $"Save changes to Untitled %d?", documentID);
7564 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = message }.Modal();
7566 if(dialogRes == yes)
7568 // TOFIX: Precomp error if brackets are taken out
7569 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7571 else if(dialogRes == cancel)
7577 for(slave = slaves.first; slave; slave = slave.next)
7579 Window w = slave.data;
7580 if(w.parent != this && !w.IsDescendantOf(this) && !w.CloseConfirmation(true))
7588 // Confirm closure of active clients first (We use OnClose() to hide instead of destroy in the IDE)
7591 for(child = children.first; child; child = child.next)
7592 if(child.isActiveClient && !child.CloseConfirmation(true))
7600 for(child = children.first; child; child = child.next)
7601 if(!child.isActiveClient && !child.CloseConfirmation(true))
7611 // Static methods... move them somewhere else?
7612 void ::RestoreCaret()
7614 if(guiApp.caretOwner)
7615 guiApp.caretOwner.UpdateCaret(false, false);
7618 void ::FreeMouseRange()
7620 guiApp.interfaceDriver.SetMouseRange(null, null);
7624 bool MenuFileClose(MenuItem selection, Modifiers mods)
7626 Window document = activeChild;
7628 document.Destroy(0);
7632 bool MenuFileExit(MenuItem selection, Modifiers mods)
7638 bool MenuFileSave(MenuItem selection, Modifiers mods)
7643 #if !defined(__EMSCRIPTEN__)
7644 fileMonitor.fileName = null;
7648 if(OnSaveFile(fileName))
7650 //if(OnFileModified != Window::OnFileModified)
7653 #if !defined(__EMSCRIPTEN__)
7654 fileMonitor.fileName = fileName;
7661 MessageBox dialog { master = master, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7662 DialogResult answer = dialog.Modal();
7664 if(answer != yes) return (bool)answer;
7667 return MenuFileSaveAs(selection, mods);
7670 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7672 DialogResult result = (DialogResult)bool::true;
7673 FileDialog fileDialog = saveDialog;
7678 fileDialog = FileDialog {};
7683 fileDialog.filePath = fileName;
7686 char filePath[MAX_FILENAME];
7687 sprintf(filePath, "Untitled %d", documentID);
7688 fileDialog.filePath = filePath;
7690 #if !defined(__EMSCRIPTEN__)
7691 fileMonitor.fileName = null;
7694 fileDialog.type = save;
7695 fileDialog.text = $"Save As";
7699 fileDialog.master = master.parent ? master : this;
7700 if(fileDialog.Modal() == ok)
7702 const char * filePath = fileDialog.filePath;
7704 if(OnSaveFile(filePath))
7707 property::fileName = filePath;
7708 NotifySaved(master, this, filePath);
7713 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7714 DialogResult answer = dialog.Modal();
7729 #if !defined(__EMSCRIPTEN__)
7730 //if(OnFileModified != Window::OnFileModified && fileName)
7733 fileMonitor.fileName = fileName;
7738 return (bool)result; // Actually returning result from Yes/NoCancel message box
7741 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7743 Window document = activeChild;
7745 for(document = children.first; document; document = next)
7747 next = document.next;
7748 if(document.style.isDocument || document.fileName)
7749 document.MenuFileSave(selection, mods);
7754 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7758 for(document = children.first; document; document = document.next)
7759 //if(document.style.isDocument && document.state == minimized)
7760 if(document.style.isActiveClient && document.state == minimized)
7761 document.SetState(minimized, false, mods);
7765 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7767 Window document = activeChild;
7770 Window firstDocument = null;
7772 OldLink cycle = document.cycle.prev;
7777 if(child.style.isActiveClient && !child.style.hidden)
7781 firstDocument = child;
7782 if(child.state == minimized)
7783 child.SetState(minimized, false, mods);
7786 child.positionID = id++;
7787 child.SetState(normal, false, mods);
7788 child.anchor.left.type = cascade;
7791 child.normalSizeAnchor = *&child.sizeAnchor;
7792 child.normalAnchor = child.anchor;
7794 // Break the anchors for moveable/resizable windows
7795 if(child.style.fixed)
7797 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7799 (*&child.normalAnchor).left = x;
7800 (*&child.normalAnchor).top = y;
7801 (*&child.normalAnchor).right.type = none;
7802 (*&child.normalAnchor).bottom.type = none;
7803 (*&child.normalSizeAnchor).isClientW = false;
7804 (*&child.normalSizeAnchor).isClientH = false;
7805 (*&child.normalSizeAnchor).size.w = w;
7806 (*&child.normalSizeAnchor).size.h = h;
7807 child.anchored = false;
7810 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7812 child.stateAnchor = child.normalAnchor;
7813 child.stateSizeAnchor = child.normalSizeAnchor;
7815 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7816 child.Position(x, y, w, h, true, true, true, true, false, false);
7821 last = children.last;
7822 if(!child.style.stayOnTop)
7823 for(; last && last.style.stayOnTop; last = last.prev);
7824 children.Move(child, last);
7825 childrenOrder.Move(child.order, childrenOrder.last);
7827 if(cycle == document.cycle) break;
7831 firstDocument.Activate();
7836 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7843 // Close all closes all active clients, not all documents
7844 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7846 Window next, document;
7848 for(document = children.first; document; document = next)
7850 for(next = document.next; next && !next.style.isActiveClient; next = next.next);
7851 if(document.style.isActiveClient)
7852 if(!document.Destroy(0) && !document.style.hidden)
7858 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7860 if(style.hasMaximize && state != maximized)
7861 SetState(maximized, 0, 0);
7865 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7867 if(style.hasMinimize && state != minimized)
7869 SetState(minimized, 0, 0);
7870 parent.CycleChildren(false, true, false, true);
7875 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7877 MenuMoveOrSize(false, selection ? true : false);
7881 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7883 CycleChildren(false, true, false, true);
7887 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7889 CycleChildren(true, true, false, true);
7893 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7895 MenuMoveOrSize(true, true);
7899 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7902 SetState(normal, 0, 0);
7906 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7909 int64 id = selection.id;
7910 OldLink cycle = activeClient.cycle;
7912 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7915 Window sibling = cycle.data;
7916 if(sibling.style.isActiveClient && sibling.visible && !sibling.style.nonClient)
7924 document = cycle.data;
7925 document.Activate();
7927 //if(activeChild.state == maximized)
7928 // document.SetState(maximized, false, mods);
7929 //else if(document.state == minimized)
7930 // document.SetState(normal, false, mods);
7934 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7936 stayOnTop = !style.stayOnTop;
7940 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7942 Window document = activeChild;
7945 Window firstDocument = null;
7946 OldLink cycle = document.cycle;
7950 Window child = cycle.data;
7951 if(child.style.isActiveClient && !child.style.hidden)
7953 if(!firstDocument) firstDocument = child;
7954 if(child.state == minimized)
7955 child.SetState(minimized, false, mods);
7958 child.positionID = id++;
7959 child.SetState(normal, false, mods);
7960 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7962 child.anchor.left.type = hTiled;
7965 child.normalSizeAnchor = *&child.sizeAnchor;
7966 child.normalAnchor = child.anchor;
7968 // Break the anchors for moveable/resizable windows
7969 if(child.style.fixed)
7971 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7973 (*&child.normalAnchor).left = x;
7974 (*&child.normalAnchor).top = y;
7975 (*&child.normalAnchor).right.type = none;
7976 (*&child.normalAnchor).bottom.type = none;
7977 (*&child.normalSizeAnchor).isClientW = false;
7978 (*&child.normalSizeAnchor).isClientH = false;
7979 (*&child.normalSizeAnchor).size.w = w;
7980 (*&child.normalSizeAnchor).size.h = h;
7981 child.anchored = false;
7984 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7986 child.stateAnchor = child.normalAnchor;
7987 child.stateSizeAnchor = child.normalSizeAnchor;
7989 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7990 child.Position(x,y, w, h, true, true, true, true, false, true);
7995 if((cycle = cycle.next) == document.cycle) break;
7998 firstDocument.Activate();
8003 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
8005 Window document = activeChild;
8008 Window firstDocument = null;
8010 OldLink cycle = document.cycle;
8015 //if(child.style.isDocument)
8016 if(child.style.isActiveClient && !child.style.hidden)
8018 if(!firstDocument) firstDocument = child;
8019 if(child.state == minimized)
8020 child.SetState(minimized, false, mods);
8023 child.positionID = id++;
8024 child.SetState(normal, false, mods);
8025 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
8027 child.anchor.left.type = vTiled;
8030 child.normalSizeAnchor = *&child.sizeAnchor;
8031 child.normalAnchor = child.anchor;
8033 // Break the anchors for moveable/resizable windows
8034 if(child.style.fixed)
8036 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
8038 (*&child.normalAnchor).left = x;
8039 (*&child.normalAnchor).top = y;
8040 (*&child.normalAnchor).right.type = none;
8041 (*&child.normalAnchor).bottom.type = none;
8042 (*&child.normalSizeAnchor).isClientW = false;
8043 (*&child.normalSizeAnchor).isClientH = false;
8044 (*&child.normalSizeAnchor).size.w = w;
8045 (*&child.normalSizeAnchor).size.h = h;
8046 child.anchored = false;
8049 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
8051 child.stateAnchor = child.normalAnchor;
8052 child.stateSizeAnchor = child.normalSizeAnchor;
8054 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
8055 child.Position(x,y, w, h, true, true, true, true, false, true);
8060 if((cycle = cycle.next) == document.cycle) break;
8063 firstDocument.Activate();
8068 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
8072 master = this; isModal = true;
8074 void NotifyDestroyed(Window window, DialogResult result)
8076 Window document = (Window)(intptr)result;
8079 if(activeChild.state == maximized)
8080 document.SetState(maximized, false, 0);
8081 else if(document.state == minimized)
8082 document.SetState(normal, false, 0);
8083 document.Activate();
8091 virtual bool OnCreate(void);
8092 virtual void OnDestroy(void);
8093 virtual void OnDestroyed(void);
8094 virtual bool OnClose(bool parentClosing);
8095 virtual bool OnStateChange(WindowState state, Modifiers mods);
8096 virtual bool OnPostCreate(void);
8097 virtual bool OnMoving(int *x, int *y, int w, int h);
8098 virtual bool OnResizing(int *width, int *height);
8099 virtual void OnResize(int width, int height);
8100 virtual void OnPosition(int x, int y, int width, int height);
8101 virtual bool OnLoadGraphics(void);
8102 virtual void OnApplyGraphics(void);
8103 virtual void OnUnloadGraphics(void);
8104 virtual void OnRedraw(Surface surface);
8105 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
8106 virtual void OnActivateClient(Window client, Window previous);
8107 virtual bool OnKeyDown(Key key, unichar ch);
8108 virtual bool OnKeyUp(Key key, unichar ch);
8109 virtual bool OnKeyHit(Key key, unichar ch);
8110 virtual bool OnSysKeyDown(Key key, unichar ch);
8111 virtual bool OnSysKeyUp(Key key, unichar ch);
8112 virtual bool OnSysKeyHit(Key key, unichar ch);
8113 virtual bool OnMouseOver(int x, int y, Modifiers mods);
8114 virtual bool OnMouseLeave(Modifiers mods);
8115 virtual bool OnMouseMove(int x, int y, Modifiers mods);
8116 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
8117 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
8118 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
8119 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
8120 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
8121 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
8122 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
8123 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
8124 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
8125 virtual bool OnMultiTouch(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods);
8126 virtual void OnMouseCaptureLost(void);
8127 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
8128 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
8129 virtual void OnDrawOverChildren(Surface surface);
8130 virtual bool OnFileModified(FileChange fileChange, const char * param);
8131 virtual bool OnSaveFile(const char * fileName);
8133 // Virtual Methods -- Children management (To support Stacker, for lack of built-in auto-layout)
8134 // Note: A 'client' would refer to isActiveClient, rather than
8135 // being confined to the 'client area' (nonClient == false)
8136 virtual void OnChildAddedOrRemoved(Window child, bool removed);
8137 virtual void OnChildVisibilityToggled(Window child, bool visible);
8138 virtual void OnChildResized(Window child, int x, int y, int w, int h);
8140 // Skins Virtual Functions
8141 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
8142 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
8143 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
8148 virtual void ShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
8149 virtual void PreShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
8150 virtual bool IsMouseMoving(int x, int y, int w, int h)
8154 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY)
8158 virtual void UpdateNonClient();
8159 virtual void SetBox(Box box); // This is used in the MySkin skin
8160 virtual bool IsInside(int x, int y)
8162 return box.IsPointInside({x, y});
8164 virtual bool IsOpaque()
8166 return (!style.drawBehind || background.a == 255);
8170 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
8171 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
8172 virtual void Window::NotifySaved(Window window, const char * filePath);
8177 property Window parent
8179 property_category $"Layout"
8182 if(value || guiApp.desktop)
8185 Window oldParent = parent;
8186 Anchor anchor = this.anchor;
8188 if(value && value.IsDescendantOf(this)) return;
8189 if(value && value == this)
8191 if(!value) value = guiApp.desktop;
8193 if(value == oldParent) return;
8195 if(!master || (master == this.parent && master == guiApp.desktop))
8196 property::master = value;
8200 parent.children.Remove(this);
8204 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
8205 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
8206 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
8207 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
8211 last = value.children.last;
8213 if(style.isDocument)
8216 parent.numDocuments--;
8217 documentID = value.GetDocumentID();
8220 if(style.isActiveClient && !style.hidden)
8222 if(parent && parent != guiApp.desktop && !(style.hidden))
8224 if(state == minimized) parent.numIcons--;
8225 parent.numPositions--;
8229 if(!style.stayOnTop)
8230 for(; last && last.style.stayOnTop; last = last.prev);
8232 value.children.Insert(last, this);
8234 // *** NEW HERE: ***
8236 parent.childrenCycle.Delete(cycle);
8238 parent.childrenOrder.Delete(order);
8241 // *** TODO: Added this here to solve crash on setting parent to null before destroying/destructing ***
8242 // Should something else be done?
8243 if(parent && parent.activeChild == this)
8244 parent.activeChild = null;
8245 if(parent && parent.activeClient == this)
8246 parent.activeClient = null;
8252 int x = position.x, y = position.y, w = size.w, h = size.h;
8256 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
8257 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
8259 vpw = value.clientSize.w;
8260 vph = value.clientSize.h;
8266 else if(style.fixed)
8268 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
8269 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
8272 anchor = this.anchor;
8274 if(anchor.left.type == offset) anchor.left.distance = x;
8275 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
8276 if(anchor.top.type == offset) anchor.top.distance = y;
8277 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
8278 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
8279 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
8280 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
8281 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
8282 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
8283 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
8285 if(!anchor.left.type && !anchor.right.type)
8287 anchor.horz.distance = (x + w / 2) - (vpw / 2);
8288 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
8290 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
8291 if(!anchor.top.type && !anchor.bottom.type)
8293 anchor.vert.distance = (y + h / 2) - (vph / 2);
8294 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
8296 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
8299 parent.OnChildAddedOrRemoved(this, false);
8305 parent.childrenCycle.Insert(
8306 // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
8307 //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8309 cycle = OldLink { data = this });
8310 parent.childrenOrder.Insert(
8311 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8312 order = OldLink { data = this });
8315 if(!style.hidden && style.isActiveClient)
8317 positionID = parent.GetPositionID(this);
8318 parent.numPositions++;
8319 if(state == minimized) parent.numIcons--;
8322 // *** FONT INHERITANCE ***
8323 if(!setFont && oldParent)
8324 stopwatching(oldParent, font);
8328 RemoveResource(systemFont);
8331 // TESTING WITH WATCHERS:
8332 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8333 // usedFont = setFont ? setFont : (systemFont);
8337 if(guiApp.currentSkin)
8339 systemFont = guiApp.currentSkin.SystemFont();
8342 usedFont = systemFont;
8343 AddResource(systemFont);
8351 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8360 if(value.rootWindow && value.rootWindow.display && rootWindow && created)
8362 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
8363 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
8366 UnloadGraphics(false);
8369 LoadGraphics(false, false);
8372 if(value.rootWindow != rootWindow)
8373 DisplayModeChanged();
8377 scrolledPos.x = MININT; // Prevent parent update
8379 bool anchored = this.anchored;
8380 property::anchor = anchor;
8381 this.anchored = anchored;
8386 if(guiApp.currentSkin)
8387 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
8389 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8390 Position(x, y, w, h, true, true, true, true, false, true);
8395 // else parent = value;
8397 oldParent.OnChildAddedOrRemoved(this, true);
8400 get { return parent; }
8403 property Window master
8405 property_category $"Behavior"
8408 //if(this == value) return;
8409 if(value && value.IsSlaveOf(this)) return;
8415 OldLink slaveHolder;
8416 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
8417 if(slaveHolder.data == this)
8419 master.slaves.Delete(slaveHolder);
8426 value.slaves.Add(OldLink { data = this });
8431 master.hotKeys.Remove(hotKey);
8432 value.hotKeys.Add(hotKey);
8435 if(master && master.defaultControl == this)
8436 master.defaultControl = null;
8438 if(style.isDefault && !value.defaultControl)
8439 value.defaultControl = this;
8444 get { return master ? master : parent; }
8447 property const char * caption
8449 property_category $"Appearance"
8456 caption = new char[strlen(value)+1];
8458 strcpy(caption, value);
8463 get { return caption; }
8468 property_category $"Behavior"
8477 master.hotKeys.Add(hotKey = HotKeySlot { });
8481 hotKey.window = this;
8486 master.hotKeys.Delete(hotKey);
8491 get { return hotKey ? hotKey.key : 0; }
8494 property Color background
8496 property_category $"Appearance"
8499 background.color = value;
8504 if(this == rootWindow)
8505 guiApp.interfaceDriver.SetRootWindowColor(this);
8508 get { return background.color; }
8511 property Percentage opacity
8513 property_category $"Appearance"
8516 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
8517 drawBehind = (background.a == 255) ? false : true;
8519 get { return background.a / 255.0f; }
8522 property Color foreground
8524 property_category $"Appearance"
8532 get { return foreground; }
8535 property BorderStyle borderStyle
8537 property_category $"Appearance"
8540 if(!((BorderBits)value).fixed)
8542 style.hasClose = false;
8543 style.hasMaximize = false;
8544 style.hasMinimize = false;
8545 nativeDecorations = false;
8547 style.borderBits = value;
8551 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8553 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8554 Position(x, y, w, h, true, true, true, true, false, true);
8555 CreateSystemChildren();
8558 get { return (BorderStyle)style.borderBits; }
8561 property Size minClientSize
8563 property_category $"Layout"
8564 set { minSize = value; }
8565 get { value = minSize; }
8568 property Size maxClientSize
8570 property_category $"Layout"
8571 set { maxSize = value; }
8572 get { value = maxSize; }
8575 property bool hasMaximize
8577 property_category $"Window Style"
8580 style.hasMaximize = value;
8581 if(value) { style.fixed = true; style.contour = true; }
8585 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8587 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8588 Position(x, y, w, h, true, true, true, true, false, true);
8590 CreateSystemChildren();
8593 get { return style.hasMaximize; }
8596 property bool hasMinimize
8598 property_category $"Window Style"
8601 style.hasMinimize = value;
8602 if(value) { style.fixed = true; style.contour = true; }
8606 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8608 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8609 Position(x, y, w, h, true, true, true, true, false, true);
8611 CreateSystemChildren();
8614 get { return style.hasMinimize; }
8617 property bool hasClose
8619 property_category $"Window Style"
8622 style.hasClose = value;
8623 if(value) { style.fixed = true; style.contour = true; }
8627 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8628 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8629 Position(x, y, w, h, true, true, true, true, false, true);
8630 CreateSystemChildren();
8633 get { return style.hasClose; }
8636 property bool nonClient
8638 property_category $"Layout"
8641 style.nonClient = value;
8643 style.stayOnTop = true;
8645 get { return style.nonClient; }
8648 property bool inactive
8650 property_category $"Behavior"
8655 // *** NEW HERE: ***
8659 parent.childrenCycle.Delete(cycle);
8661 parent.childrenOrder.Delete(order);
8668 active = false; // true;
8669 if(parent.activeChild == this)
8670 parent.activeChild = null;
8671 if(parent.activeClient == this)
8672 parent.activeClient = null;
8681 parent.childrenCycle.Insert(
8682 // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
8683 //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8685 cycle = OldLink { data = this });
8687 parent.childrenOrder.Insert(
8688 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8689 order = OldLink { data = this });
8692 style.inactive = value;
8694 get { return style.inactive; }
8697 property bool clickThrough
8699 property_category $"Behavior"
8700 set { style.clickThrough = value; }
8701 get { return style.clickThrough; }
8704 property bool isRemote
8706 property_category $"Behavior"
8707 set { style.isRemote = value; }
8708 get { return style.isRemote; }
8711 property bool noCycle
8713 property_category $"Behavior"
8714 set { style.noCycle = value; }
8715 get { return style.noCycle; }
8718 property bool isModal
8720 property_category $"Behavior"
8721 set { style.modal = value; }
8722 get { return style.modal; }
8725 property bool interim
8727 property_category $"Behavior"
8728 set { style.interim = value; }
8729 get { return style.interim; }
8732 property bool tabCycle
8734 property_category $"Behavior"
8735 set { style.tabCycle = value; }
8736 get { return style.tabCycle; }
8739 property bool isDefault
8741 property_category $"Behavior"
8749 for(sibling = parent.children.first; sibling; sibling = sibling.next)
8750 if(sibling != this && sibling.style.isDefault)
8751 sibling.style.isDefault = false;*/
8752 if(master.defaultControl)
8753 master.defaultControl.style.isDefault = false;
8754 master.defaultControl = this;
8756 else if(master.defaultControl == this)
8757 master.defaultControl = null;
8761 style.isDefault = value;
8763 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8765 get { return style.isDefault; }
8768 property bool drawBehind
8770 property_category $"Window Style"
8771 set { style.drawBehind = value; }
8772 get { return style.drawBehind; }
8775 property bool hasMenuBar
8777 property_category $"Window Style"
8787 if(created && !menuBar)
8794 anchor = Anchor { top = 23, left = 1, right = 1 },
8796 inactive = true, nonClient = true
8801 else if(created && menuBar)
8806 style.hasMenuBar = value;
8808 get { return style.hasMenuBar; }
8811 property bool hasStatusBar
8813 property_category $"Window Style"
8820 statusBar = StatusBar { this };
8828 style.hasStatusBar = value;
8830 get { return style.hasStatusBar; }
8832 property bool stayOnTop
8834 property_category $"Window Style"
8839 if(created && !style.stayOnTop)
8841 if(rootWindow == this)
8842 guiApp.interfaceDriver.OrderRootWindow(this, true);
8843 else if(parent.children.last != this)
8845 parent.children.Move(this, parent.children.last);
8849 style.stayOnTop = true;
8853 if(created && style.stayOnTop)
8855 if(rootWindow == this)
8856 guiApp.interfaceDriver.OrderRootWindow(this, false);
8863 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8864 order && ((Window)order.data).style.stayOnTop;
8865 order = (order == parent.childrenOrder.first) ? null : order.prev);
8866 last = order ? order.data : null;
8870 for(last = parent.children.last;
8871 last && last.style.stayOnTop;
8875 parent.children.Move(this, last);
8879 style.stayOnTop = false;
8882 get { return style.stayOnTop; }
8887 property_category $"Window Style"
8897 if(menuBar && !value)
8904 if(!menuBar && style.hasMenuBar && value)
8908 this, menu = value, isMenuBar = true,
8909 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8910 inactive = true, nonClient = true
8914 UpdateActiveDocument(null);
8917 get { return menu; }
8920 property FontResource font
8922 property_category $"Appearance"
8924 isset { return setFont ? true : false; }
8929 if(value && !setFont) { stopwatching(parent, font); }
8930 else if(!value && setFont)
8936 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8945 RemoveResource(setFont);
8950 RemoveResource(systemFont);
8957 AddResource(setFont);
8960 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8963 systemFont = guiApp.currentSkin.SystemFont();
8965 usedFont = systemFont;
8966 AddResource(systemFont);
8974 get { return usedFont; }
8977 property SizeAnchor sizeAnchor
8979 property_category $"Layout"
8982 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8983 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8984 sizeAnchor.isClientW != sizeAnchor.isClientH;
8991 normalSizeAnchor = sizeAnchor;
8993 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8995 stateAnchor = normalAnchor;
8996 stateSizeAnchor = normalSizeAnchor;
8998 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8999 Position(x,y, w, h, true, true, true, true, false, true);
9006 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
9007 sizeAnchor.isClientW,
9008 sizeAnchor.isClientH
9015 property_category $"Layout"
9018 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
9019 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
9020 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
9026 sizeAnchor.isClientW = false;
9027 sizeAnchor.isClientH = false;
9028 sizeAnchor.size = value;
9030 normalSizeAnchor = sizeAnchor;
9032 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
9034 stateAnchor = normalAnchor;
9035 stateSizeAnchor = normalSizeAnchor;
9037 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9038 Position(x, y, w, h, true, true, true, true, false, true);
9039 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
9042 get { value = size; }
9045 property Size clientSize
9047 property_category $"Layout"
9050 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
9051 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
9052 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
9057 sizeAnchor.isClientW = true;
9058 sizeAnchor.isClientH = true;
9059 sizeAnchor.size = value;
9061 normalSizeAnchor = sizeAnchor;
9063 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9065 stateAnchor = normalAnchor;
9066 stateSizeAnchor = normalSizeAnchor;
9068 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9069 Position(x,y, w, h, true, true, true, true, false, true);
9070 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
9073 get { value = this ? clientSize : { 0, 0 }; }
9076 property Size initSize { get { value = sizeAnchor.size; } };
9078 property Anchor anchor
9080 property_category $"Layout"
9081 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
9087 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
9089 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
9090 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
9092 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
9094 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
9095 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
9099 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
9101 anchor.left.distance = 0;
9102 anchor.horz.type = 0;
9104 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
9106 anchor.top.distance = 0;
9107 anchor.vert.type = 0;
9116 normalAnchor = anchor;
9118 // Break the anchors for moveable/resizable windows
9119 /*if(style.fixed ) //&& value.left.type == cascade)
9121 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
9123 this.anchor = normalAnchor = Anchor { left = x, top = y };
9124 normalSizeAnchor = SizeAnchor { { w, h } };
9127 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9129 stateAnchor = normalAnchor;
9130 stateSizeAnchor = normalSizeAnchor;
9132 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9133 Position(x, y, w, h, true, true, true, true, false, true);
9142 get { value = this ? anchor : Anchor { }; }
9145 property Point position
9147 property_category $"Layout"
9150 if(value == null) return;
9152 anchor.left = value.x;
9153 anchor.top = value.y;
9154 anchor.right.type = none;
9155 anchor.bottom.type = none;
9160 normalAnchor = anchor;
9162 // Break the anchors for moveable/resizable windows
9166 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9168 normalAnchor.left = x;
9169 normalAnchor.top = y;
9170 normalAnchor.right.type = none;
9171 normalAnchor.bottom.type = none;
9172 normalSizeAnchor.size.width = w;
9173 normalSizeAnchor.size.height = h;
9177 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9179 stateAnchor = normalAnchor;
9180 stateSizeAnchor = normalSizeAnchor;
9182 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9183 Position(x,y, w, h, true, true, true, true, false, true);
9187 get { value = position; }
9190 property bool disabled
9192 property_category $"Behavior"
9195 if(this && disabled != value)
9202 get { return (bool)disabled; }
9205 property bool isEnabled
9210 for(parent = this; parent; parent = parent.parent)
9217 property WindowState state
9219 property_category $"Behavior"
9220 set { SetState(value, false, 0); }
9221 get { return this ? state : 0; }
9224 property bool visible
9226 property_category $"Behavior"
9229 if(this && !value && !style.hidden && parent)
9231 bool wasActiveChild = parent.activeChild == this;
9232 Window client = null;
9234 style.hidden = true;
9235 if(style.isActiveClient)
9237 parent.numPositions--;
9238 if(state == minimized) parent.numIcons--;
9243 OldLink prevOrder = null;
9245 if(rootWindow == this)
9246 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
9249 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
9252 box.left -= parent.clientStart.x;
9253 box.top -= parent.clientStart.y;
9254 box.right -= parent.clientStart.x;
9255 box.bottom -= parent.clientStart.y;
9259 if(_isModal && master && master.modalSlave == this)
9260 master.modalSlave = null;
9264 OldLink tmpPrev = order.prev;
9265 client = tmpPrev ? tmpPrev.data : null;
9266 if(client && !client.style.hidden && !client.destroyed && client.created)
9267 prevOrder = tmpPrev;
9270 client = tmpPrev ? tmpPrev.data : null;
9271 if(client == this) { client = null; break; }
9272 if(client && ((client.style.hidden) || client.destroyed || !client.created))
9274 tmpPrev = client.order.prev;
9279 prevOrder = tmpPrev;
9284 // If this window can be an active client, make sure the next window we activate can also be one
9285 if(!style.nonClient && style.isActiveClient)
9287 tmpPrev = prevOrder;
9290 client = tmpPrev ? tmpPrev.data : null;
9291 if(client == this) { client = null; break; }
9292 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
9294 tmpPrev = client.order.prev;
9299 prevOrder = tmpPrev;
9303 if(client && client.style.hidden) client = null;
9307 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
9309 if(order && prevOrder && prevOrder.data != this)
9310 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
9312 ActivateEx(false, false, false, true, null, null);
9314 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
9315 if(parent.activeClient == this)
9317 parent.activeClient = null;
9318 parent.UpdateActiveDocument(null);
9321 else if(parent.activeClient == this)
9323 parent.activeClient = client;
9324 parent.UpdateActiveDocument(this);
9327 // *** Not doing this anymore ***
9330 parent.childrenCycle.Delete(cycle);
9332 parent.childrenOrder.Delete(order);
9337 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9342 else if(this && value && style.hidden)
9344 style.hidden = false;
9347 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9348 if(rootWindow == this)
9349 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
9351 if(_isModal && master)
9352 master.modalSlave = this;
9354 if(style.isActiveClient)
9356 positionID = parent.GetPositionID(this);
9357 parent.numPositions++;
9358 if(state == minimized) parent.numIcons++;
9361 // *** NOT DOING THIS ANYMORE ***
9363 if(!(style.inactive))
9365 if(!(style.noCycle))
9367 cycle = parent.childrenCycle.AddAfter(
9368 (parent.activeChild && parent.activeChild.cycle) ?
9369 parent.activeChild.cycle.prev : null, sizeof(OldLink));
9372 order = parent.childrenOrder.AddAfter(
9373 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
9380 if(true || !parent.activeChild)
9381 ActivateEx(true, false, true, true, null, null);
9383 if(creationActivation == activate && guiApp.desktop.active)
9384 ActivateEx(true, false, true, true, null, null);
9385 else if((creationActivation == activate || creationActivation == flash) && !object)
9388 if(this == rootWindow)
9392 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9396 ConsequentialMouseMove(false);
9402 style.hidden = !value;
9405 get { return (style.hidden || !setVisible) ? false : true; }
9408 property bool isDocument
9410 property_category $"Document"
9411 set { style.isDocument = value; if(value) SetupFileMonitor(); }
9412 get { return style.isDocument; }
9415 property bool mergeMenus
9417 property_category $"Window Style"
9418 set { mergeMenus = value; }
9419 get { return (bool)mergeMenus; }
9422 property bool hasHorzScroll
9424 property_category $"Window Style"
9429 if(!style.hasHorzScroll && created)
9431 CreateSystemChildren();
9432 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9435 else if(style.hasHorzScroll)
9439 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9441 style.hasHorzScroll = value;
9444 get { return style.hasHorzScroll; }
9447 property bool hasVertScroll
9449 property_category $"Window Style"
9454 if(!style.hasVertScroll && created)
9456 style.hasVertScroll = true;
9457 CreateSystemChildren();
9458 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9461 else if(style.hasVertScroll)
9465 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9467 style.hasVertScroll = value;
9469 get { return style.hasVertScroll; }
9472 property bool dontHideScroll
9474 property_category $"Behavior"
9477 scrollFlags.dontHide = value;
9480 //UpdateScrollBars(true, true);
9481 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9485 // UpdateScrollBars(true, true);
9486 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9489 get { return scrollFlags.dontHide; }
9492 property bool dontScrollVert
9494 property_category $"Behavior"
9495 set { style.dontScrollVert = value; }
9496 get { return style.dontScrollVert; }
9498 property bool dontScrollHorz
9500 property_category $"Behavior"
9501 set { style.dontScrollHorz = value; }
9502 get { return style.dontScrollHorz; }
9505 property bool snapVertScroll
9507 property_category $"Behavior"
9510 scrollFlags.snapY = value;
9511 if(sbv) sbv.snap = value;
9513 get { return scrollFlags.snapY; }
9515 property bool snapHorzScroll
9517 property_category $"Behavior"
9520 scrollFlags.snapX = value;
9521 if(sbh) sbh.snap = value;
9523 get { return scrollFlags.snapX; }
9526 property Point scroll
9528 property_category $"Behavior"
9529 set { if(this) SetScrollPosition(value.x, value.y); }
9530 get { value = scroll; }
9533 property bool modifyVirtualArea
9535 property_category $"Behavior"
9536 set { modifyVirtArea = value; }
9537 get { return (bool)modifyVirtArea; }
9540 property bool dontAutoScrollArea
9542 property_category $"Behavior"
9543 // Activating a child control out of view will automatically scroll to make it in view
9544 set { noAutoScrollArea = value; }
9545 get { return (bool)noAutoScrollArea; }
9548 property const char * fileName
9550 property_category $"Document"
9555 if(menu && ((!fileName && value) || (fileName && !value)))
9557 MenuItem item = menu.FindItem(MenuFileSave, 0);
9558 if(item) item.disabled = !modifiedDocument && value;
9563 if(value && value[0])
9564 fileName = CopyString(value);
9566 if(parent && this == parent.activeClient)
9567 parent.UpdateActiveDocument(null);
9571 // if(style.isDocument)
9572 #if !defined(__EMSCRIPTEN__)
9574 fileMonitor.fileName = value;
9577 get { return fileName; }
9582 property_category $"Data"
9587 property bool modifiedDocument
9589 property_category $"Document"
9592 if(style.isDocument || fileName)
9596 MenuItem item = menu.FindItem(MenuFileSave, 0);
9597 if(item) item.disabled = !value && fileName;
9601 if(modifiedDocument != value)
9603 modifiedDocument = value;
9604 if(style.isDocument || fileName)
9608 get { return (bool)modifiedDocument; }
9611 property bool showInTaskBar
9613 property_category $"Window Style"
9616 style.showInTaskBar = value;
9617 #if defined(__WIN32__)
9618 Win32UpdateStyle(this);
9621 get { return style.showInTaskBar; }
9623 property FileDialog saveDialog { set { saveDialog = value; } };
9624 property bool isActiveClient
9626 property_category $"Behavior"
9629 if(parent && style.isActiveClient != value && !style.hidden)
9633 if(state == minimized) parent.numIcons++;
9634 parent.numPositions++;
9638 if(state == minimized) parent.numIcons--;
9639 parent.numPositions--;
9642 style.isActiveClient = value;
9644 get { return style.isActiveClient; }
9647 property Cursor cursor
9649 property_category $"Appearance"
9653 SelectMouseCursor();
9655 get { return cursor; }
9658 //#if !defined(ECERE_VANILLA)
9659 property const char * name
9661 property_category $"Design"
9664 return (this && object) ? object.name : null;
9669 activeDesigner.RenameObject(object, value);
9673 property const char * displayDriver
9675 property_category $"Behavior"
9678 dispDriver = GetDisplayDriver(value);
9679 //DisplayModeChanged();
9683 return dispDriver ? dispDriver.name : null;
9687 // RUNTIME PROPERTIES
9688 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9689 property Size scrollArea
9691 property_category $"Behavior"
9695 SetScrollArea(value.w, value.h, false);
9697 SetScrollArea(0,0, true);
9699 get { value = scrollArea; }
9702 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9707 property_category $"Layout"
9708 set { if(this) is3D = value; }
9709 get { return (bool)is3D; }
9712 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9714 // Will be merged with font later
9715 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9716 property Point clientStart { get { value = clientStart; } };
9717 property Point absPosition { get { value = absPosition; } };
9718 property Anchor normalAnchor { get { value = normalAnchor; } };
9719 property SizeAnchor normalSizeAnchor { get { value = normalSizeAnchor; } };
9720 property bool active { get { return (bool)active; } };
9721 property bool created { get { return (bool)created; } };
9722 property bool destroyed { get { return (bool)destroyed; } };
9723 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9724 property Window firstChild { get { return children.first; } };
9725 property Window lastChild { get { return children.last; } };
9726 property Window activeClient { get { return activeClient; } };
9727 property Window activeChild { get { return activeChild; } };
9728 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9729 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9730 property ScrollBar horzScroll { get { return sbh; } };
9731 property ScrollBar vertScroll { get { return sbv; } };
9732 property StatusBar statusBar { get { return statusBar; } };
9733 property Window rootWindow { get { return rootWindow; } };
9734 property bool closing { get { return (bool)closing; } set { closing = value; } };
9735 property int documentID { get { return documentID; } };
9736 property Window previous { get { return prev; } }
9737 property Window next { get { return next; } }
9738 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9739 property PopupMenu menuBar { get { return menuBar; } }
9740 property ScrollBar sbv { get { return sbv; } }
9741 property ScrollBar sbh { get { return sbh; } }
9742 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9743 property void * systemHandle { get { return windowHandle; } }
9744 property Button minimizeButton { get { return sysButtons[0]; } };
9745 property Button maximizeButton { get { return sysButtons[1]; } };
9746 property Button closeButton { get { return sysButtons[2]; } };
9747 property BitmapResource icon
9749 get { return icon; }
9753 if(icon) incref icon;
9755 guiApp.interfaceDriver.SetIcon(this, value);
9758 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9759 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; if(value) nativeDecorations = false; /* Native Decorations are not supported with alphaBlend */ } };
9760 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9761 property GLCapabilities glCapabilities
9763 get { return glCapabilities; }
9766 bool reload = display != null &&
9767 (glCapabilities.nonPow2Textures != value.nonPow2Textures ||
9768 glCapabilities.intAndDouble != value.intAndDouble ||
9769 glCapabilities.vertexBuffer != value.vertexBuffer ||
9770 glCapabilities.compatible != value.compatible ||
9771 glCapabilities.legacyFormats != value.legacyFormats ||
9772 glCapabilities.debug != value.debug ||
9773 glCapabilities.vertexPointer != value.vertexPointer ||
9774 glCapabilities.quads != value.quads);
9775 guiApp.modeSwitching = true;
9777 UnloadGraphics(false);
9779 glCapabilities = value;
9784 LoadGraphics(false, false);
9787 display.glCapabilities = value;
9788 guiApp.modeSwitching = false;
9791 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9792 property bool nativeDecorations
9794 get { return (bool)nativeDecorations; }
9795 set { nativeDecorations = value; }
9796 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
9799 //return (nativeDecorations && (rootWindow == this || (formDesigner && activeDesigner && ((FormDesigner)activeDesigner.classDesigner).form && parent == ((FormDesigner)activeDesigner.classDesigner).form.parent))) != style.fixed;
9800 bool result = false;
9801 if(nativeDecorations)
9803 if(rootWindow == this)
9807 if(formDesigner && activeDesigner)
9809 FormDesigner cd = (FormDesigner)activeDesigner.classDesigner;
9810 Window form = cd ? cd.form : null;
9811 if(form && parent == form.parent)
9816 return result != style.fixed;
9820 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9822 property const char * text
9824 property_category $"Deprecated"
9826 set { property::caption = value; }
9827 get { return property::caption; }
9833 WindowBits style; // Window Style
9834 char * caption; // Name / Caption
9835 Window parent; // Parent window
9836 OldList children; // List of children in Z order
9837 Window activeChild; // Child window having focus
9838 Window activeClient;
9839 Window previousActive; // Child active prior to activating the default child
9840 Window master; // Window owning and receiving notifications concerning this window
9841 OldList slaves; // List of windows belonging to this window
9842 Display display; // Display this window is drawn into
9844 Point position; // Position in parent window client area
9845 Point absPosition; // Absolute position
9846 Point clientStart; // Client area position from (0,0) in this window
9848 Size clientSize; // Client area size
9849 Size scrollArea; // Virtual Scroll area size
9850 Size reqScrollArea; // Requested virtual area size
9851 Point scroll; // Virtual area scrolling position
9852 ScrollBar sbh, sbv; // Scrollbar window handles
9853 Cursor cursor; // Mouse cursor used for this window
9856 StatusBar statusBar;
9857 Button sysButtons[3];
9859 Box clientArea; // Client Area box clipped to parent
9861 HotKeySlot hotKey; // HotKey for this window
9865 ScrollFlags scrollFlags;// Window Scrollbar Flags
9866 int64 id; // Control ID
9868 ColorAlpha background; // Background color used to draw the window area
9870 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9871 OldList childrenCycle; // Cycling order
9872 OldLink cycle; // Element of parent's cycling order
9873 OldList childrenOrder; // Circular Z-Order
9874 OldLink order; // Element of parent's circular Z-Order
9875 Window modalSlave; // Slave window blocking this window's interaction
9877 Window rootWindow; // Topmost system managed window
9878 void * windowHandle; // System window handle
9880 DialogResult returnCode;// Return code for modal windows
9882 Point sbStep; // Scrollbar line scrolling steps
9885 SizeAnchor stateSizeAnchor;
9887 Anchor normalAnchor;
9888 SizeAnchor normalSizeAnchor;
9890 Size skinMinSize; // Minimal window size based on style
9891 Point scrolledPos; // Scrolled position
9892 Box box; // Window box clipped to parent
9893 Box * against; // What to clip the box to
9895 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9896 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9897 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9898 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9899 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9900 Point scrolledArea; // Distance to scroll area by
9901 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9903 OldList hotKeys; // List of the hotkeys of all children
9904 Window defaultControl; // Default child control
9908 ColorAlpha * palette; // Color palette used for this window
9910 int caretSize; // Size of caret, non zero if a caret is present
9911 Point caretPos; // Caret position
9913 void * systemParent; // Parent System Window for embedded windows
9919 #if !defined(__EMSCRIPTEN__)
9922 WindowState lastState;
9924 #if !defined(__EMSCRIPTEN__)
9925 FileMonitor fileMonitor;
9928 FontResource setFont, systemFont;
9929 FontResource usedFont;
9930 FontResource captionFont;
9932 FileDialog saveDialog;
9934 SizeAnchor sizeAnchor;
9936 // FormDesigner data
9939 Extent * tempExtents; //[4];
9940 BitmapResource icon;
9942 CreationActivationOption creationActivation;
9943 GLCapabilities glCapabilities;
9944 glCapabilities = { true, true, true, true, true, true, true, true, true /*false*/, true, true, true, true, true, true, true };
9947 bool active:1; // true if window and ancestors are active
9948 bool acquiredInput:1; // true if the window is processing state based input
9949 bool modifiedDocument:1;
9950 bool disabled:1; // true if window cannot interact
9951 bool isForegroundWindow:1;// true while a root window is being activated
9952 bool visible:1; // Visibility flag
9953 bool destroyed:1; // true if window is being destroyed
9954 bool anchored:1; // true if this window is repositioned when the parent resizes
9955 bool dirty:1; // Flag set to true if any descendant must be redrawn
9961 bool modifyVirtArea:1;
9962 bool noAutoScrollArea:1;
9965 bool setVisible:1; // FOR FORM DESIGNER
9971 bool useSharedMemory:1;
9974 bool nativeDecorations:1;
9975 bool manageDisplay:1;
9976 bool formDesigner:1; // True if we this is running in the form editor
9977 bool requireRemaximize:1;
9978 bool noConsequential:1;
9981 // Checks used internally for them not to take effect in FormDesigner
9982 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9983 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9985 WindowController controller;
9987 public property WindowController controller
9989 get { return controller; }
9993 controller.setWindow(null);
9999 controller.setWindow(this);
10004 public property bool noConsequential
10006 set { noConsequential = value; }
10007 get { return noConsequential; }
10011 public class CommonControl : Window
10013 // creationActivation = doNothing;
10016 public property const String toolTip
10018 property_category $"Appearance"
10021 if(created) CommonControl::OnDestroy();
10023 toolTip = value ? ToolTip { tip = value; } : null;
10025 if(created) CommonControl::OnCreate();
10027 get { return toolTip ? toolTip.tip : null; }
10033 // (Very) Ugly work around for the fact that the parent watcher
10034 // won't fire when it's already been disconnected...
10035 eInstance_FireSelfWatchers(toolTip,
10036 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
10042 toolTip.parent = this;
10051 public class Percentage : float
10053 const char * OnGetString(char * string, float * fieldData, bool * needClass)
10057 sprintf(string, "%.2f", this);
10058 c = strlen(string)-1;
10059 for( ; c >= 0; c--)
10061 if(string[c] != '0')
10062 last = Max(last, c);
10063 if(string[c] == '.')
10068 string[last+1] = 0;
10076 public void ApplySkin(Class c, const char * name, void ** vTbl)
10078 char className[1024];
10083 subclass(Window) wc = (subclass(Window))c;
10084 subclass(Window) base = (subclass(Window))c.base;
10086 sprintf(className, "%sSkin_%s", name, c.name);
10087 wc.pureVTbl = c._vTbl;
10088 c._vTbl = new void *[c.vTblSize];
10089 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
10090 sc = eSystem_FindClass(c.module.application, className);
10094 for(m = 0; m < c.base.vTblSize; m++)
10096 if(c._vTbl[m] == base.pureVTbl[m])
10097 c._vTbl[m] = vTbl[m];
10102 for(m = 0; m < c.vTblSize; m++)
10104 if(sc._vTbl[m] != wc.pureVTbl[m])
10105 c._vTbl[m] = sc._vTbl[m];
10109 for(d = c.derivatives.first; d; d = d.next)
10111 ApplySkin(d.data, name, c._vTbl);
10115 public void UnapplySkin(Class c)
10117 subclass(Window) wc = (subclass(Window))c;
10120 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
10123 c._vTbl = wc.pureVTbl;
10124 wc.pureVTbl = null;
10127 for(d = c.derivatives.first; d; d = d.next)
10129 UnapplySkin(d.data);
10133 void CheckFontIntegrity(Window window)
10138 if(window.usedFont && window.usedFont.font == 0xecececec)
10140 FontResource uf = window.usedFont;
10141 char * className = window._class.name;
10142 char * text = window.text;
10145 for(c = window.firstChild; c; c = c.next)
10146 CheckFontIntegrity(c);
10150 public class ControllableWindow : Window
10152 /*WindowController controller;
10153 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
10154 ~ControllableWindow() { delete controller; }*/
10157 class WindowControllerInterface : ControllableWindow
10159 bool OnKeyDown(Key key, unichar ch)
10161 bool result = controller.OnKeyDown ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyDown)((Window)controller.controlled, controller, key, ch) : true;
10164 bool (* onKeyDown)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown];
10166 result = onKeyDown(controller.window, key, ch);
10171 bool OnKeyUp(Key key, unichar ch)
10173 bool result = controller.OnKeyUp ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyUp)((Window)controller.controlled, controller, key, ch) : true;
10176 bool (* onKeyUp)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp];
10178 result = onKeyUp(controller.window, key, ch);
10183 bool OnKeyHit(Key key, unichar ch)
10185 bool result = controller.OnKeyHit ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyHit)((Window)controller.controlled, controller, key, ch) : true;
10188 bool (* onKeyHit)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit];
10190 result = onKeyHit(controller.window, key, ch);
10195 bool OnMouseMove(int x, int y, Modifiers mods)
10197 bool result = controller.OnMouseMove ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMouseMove)((Window)controller.controlled, controller, x, y, mods) : true;
10200 bool(* onMouseMove)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove];
10202 result = onMouseMove(controller.window, x, y, mods);
10207 bool OnLeftButtonDown(int x, int y, Modifiers mods)
10209 bool result = controller.OnLeftButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10212 bool(* onLeftButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown];
10213 if(onLeftButtonDown)
10214 result = onLeftButtonDown(controller.window, x, y, mods);
10219 bool OnLeftButtonUp(int x, int y, Modifiers mods)
10221 bool result = controller.OnLeftButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10224 bool(* onLeftButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp];
10226 result = onLeftButtonUp(controller.window, x, y, mods);
10231 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
10233 bool result = controller.OnLeftDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10236 bool(* onLeftDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick];
10237 if(onLeftDoubleClick)
10238 result = onLeftDoubleClick(controller.window, x, y, mods);
10243 bool OnRightButtonDown(int x, int y, Modifiers mods)
10245 bool result = controller.OnRightButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10248 bool(* onRightButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown];
10249 if(onRightButtonDown)
10250 result = onRightButtonDown(controller.window, x, y, mods);
10255 bool OnRightButtonUp(int x, int y, Modifiers mods)
10257 bool result = controller.OnRightButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10260 bool(* onRightButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp];
10261 if(onRightButtonUp)
10262 result = onRightButtonUp(controller.window, x, y, mods);
10267 bool OnRightDoubleClick(int x, int y, Modifiers mods)
10269 bool result = controller.OnRightDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10272 bool(* onRightDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick];
10273 if(onRightDoubleClick)
10274 result = onRightDoubleClick(controller.window, x, y, mods);
10279 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
10281 bool result = controller.OnMiddleButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10284 bool(* onMiddleButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown];
10285 if(onMiddleButtonDown)
10286 result = onMiddleButtonDown(controller.window, x, y, mods);
10291 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
10293 bool result = controller.OnMiddleButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10296 bool(* onMiddleButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp];
10297 if(onMiddleButtonUp)
10298 result = onMiddleButtonUp(controller.window, x, y, mods);
10303 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
10305 bool result = controller.OnMiddleDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10308 bool(* onMiddleDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick];
10309 if(onMiddleDoubleClick)
10310 onMiddleDoubleClick(controller.window, x, y, mods);
10315 bool OnMultiTouch(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods)
10317 bool result = controller.OnMultiTouch ? ((bool(*)(Window, WindowController, TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers))(void *)controller.OnMultiTouch)((Window)controller.controlled, controller, event, infos, mods) : true;
10320 bool(* onMultiTouch)(Window, TouchPointerEvent, Array<TouchPointerInfo>, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMultiTouch];
10322 onMultiTouch(controller.window, event, infos, mods);
10327 void OnResize(int width, int height)
10329 if(controller.OnResize)
10330 ((void(*)(Window, WindowController, int, int))(void *)controller.OnResize)((Window)controller.controlled, controller, width, height);
10332 void(* onResize)(Window, int, int) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize];
10334 onResize(controller.window, width, height);
10338 void OnRedraw(Surface surface)
10340 if(controller.OnRedraw)
10341 ((void(*)(Window, WindowController, Surface))(void *)controller.OnRedraw)((Window)controller.controlled, controller, surface);
10343 void(* onRedraw)(Window, Surface) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw];
10345 onRedraw(controller.window, surface);
10351 bool result = controller.OnCreate ? ((bool(*)(Window, WindowController))(void *)controller.OnCreate)((Window)controller.controlled, controller) : true;
10354 bool(* onCreate)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate];
10356 result = onCreate(controller.window);
10361 bool OnLoadGraphics()
10363 bool result = controller.OnLoadGraphics ? ((bool(*)(Window, WindowController))(void *)controller.OnLoadGraphics)((Window)controller.controlled, controller) : true;
10366 bool(* onLoadGraphics)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLoadGraphics];
10368 result = onLoadGraphics(controller.window);
10373 void OnUnloadGraphics()
10375 if(controller.OnUnloadGraphics)
10376 ((void(*)(Window, WindowController))(void *)controller.OnUnloadGraphics)((Window)controller.controlled, controller);
10378 void(* onUnloadGraphics)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnUnloadGraphics];
10379 if(onUnloadGraphics)
10380 onUnloadGraphics(controller.window);
10385 public class WindowController<class V>
10387 void setWindow(Window value)
10389 uint size = class(Window).vTblSize;
10393 windowVTbl = new void *[size];
10394 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
10395 if(value._vTbl == value._class._vTbl)
10397 value._vTbl = new void *[value._class.vTblSize];
10398 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
10402 for(c = 0; c < size; c++)
10404 void * function = class(WindowControllerInterface)._vTbl[c];
10405 if(function && function != DefaultFunction)
10406 value._vTbl[c] = function;
10408 value._vTbl[c] = windowVTbl[c];
10414 memcpy(window._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
10420 property Window window
10422 get { return window; }
10424 property V controlled
10426 set { controlled = value; }
10427 get { return controlled; }
10429 // TODO: Add OnStateChange so we can implement SavedConfigWindow as a WindowController instead
10430 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
10431 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
10432 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
10433 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
10434 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
10435 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
10436 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10437 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
10438 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
10439 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10440 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
10441 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
10442 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10443 virtual bool V::OnMultiTouch(WindowController controller, TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods);
10444 virtual void V::OnResize(WindowController controller, int width, int height);
10445 virtual void V::OnRedraw(WindowController controller, Surface surface);
10446 virtual bool V::OnCreate(WindowController controller);
10447 virtual bool V::OnLoadGraphics(WindowController controller);
10448 virtual void V::OnUnloadGraphics(WindowController controller);
10451 public int (** windowVTbl)();
10455 ~WindowController()