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);
4583 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4584 status = OnSysKeyHit(key, character);
4585 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4586 status = OnSysKeyUp(key, character);
4593 // Process Key Message for Internal UI Keyboard actions
4594 if(status && !destroyed && menuBar && state != minimized)
4597 if((SmartKey)key != alt)
4598 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4601 SmartKey sk = (SmartKey) key;
4602 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4604 status = menuBar.KeyMessage(method, key, character);
4609 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4610 menuBar.OnKeyHit(escape, 0);
4612 if(!menuBar.focus && guiApp.caretOwner)
4613 guiApp.caretOwner.UpdateCaret(true, false);
4616 if(!destroyed && status)
4618 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4622 case left: case up: case right: case down:
4623 if(guiApp.windowMoving == this)
4626 int w = guiApp.windowMoving.size.w;
4627 int h = guiApp.windowMoving.size.h;
4628 int x = guiApp.windowMoving.scrolledPos.x;
4629 int y = guiApp.windowMoving.scrolledPos.y;
4633 if(key == down || key == up)
4634 step = Max(step, textCellH);
4636 step = Max(step, textCellW);
4639 if(guiApp.windowIsResizing)
4643 case left: w-=step; break;
4644 case right: w+=step; break;
4645 case up: h-=step; break;
4646 case down: h+=step; break;
4653 case left: x-=step; break;
4654 case right: x+=step; break;
4655 case up: y-=step; break;
4656 case down: y+=step; break;
4660 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4661 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4663 if(!guiApp.windowIsResizing || guiApp.resizeX)
4664 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4666 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4668 if(!guiApp.windowIsResizing || guiApp.resizeY)
4669 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4671 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4673 guiApp.interfaceDriver.SetMousePosition(x, y);
4674 ConsequentialMouseMove(true);
4682 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4684 guiApp.windowMoving.StopMoving();
4685 ConsequentialMouseMove(false);
4693 ShowSysMenu(absPosition.x, absPosition.y);
4701 if(!destroyed && status && state != minimized)
4703 // Process all the way down the children
4704 if(activeChild && !activeChild.disabled)
4706 status = activeChild.KeyMessage(method, key, character);
4708 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4709 key.code != left && key.code != right && key.code != up && key.code != down)
4711 status = activeClient.KeyMessage(method, key, character);
4715 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4717 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4718 // && defaultControl != activeChild)
4720 delete previousActive;
4721 previousActive = activeChild;
4722 if(previousActive) incref previousActive;
4724 ConsequentialMouseMove(false);
4725 if((defaultControl.active ||
4726 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4727 defaultControl.KeyMessage(method, defaultKey, character);
4733 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4735 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4742 ShowSysMenu(absPosition.x, absPosition.y);
4749 if(this != guiApp.desktop)
4751 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4753 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4755 MenuMoveOrSize(key.shift, true);
4759 else if(guiApp.windowMoving)
4761 guiApp.windowMoving.StopMoving();
4762 ConsequentialMouseMove(false);
4770 if(!destroyed && status && state != minimized)
4772 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4776 case tab: case shiftTab:
4778 Window cycleParent = this;
4779 if(this == guiApp.interimWindow && master && !master.style.interim && !cycleParent.style.tabCycle && master.parent)
4780 cycleParent = master.parent;
4782 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4784 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4787 Window child = cycleParent.activeChild;
4789 // Scroll the window to include the active control
4790 if(cycleParent.sbh && !child.style.dontScrollHorz)
4792 if(child.scrolledPos.x < 0)
4793 cycleParent.sbh.Action(Position,
4794 cycleParent.scroll.x + child.scrolledPos.x, 0);
4795 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4796 cycleParent.sbh.Action(Position,
4797 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4799 if(cycleParent.sbv && !child.style.dontScrollVert)
4801 if(child.scrolledPos.y < 0)
4802 cycleParent.sbv.Action(Position,
4803 cycleParent.scroll.y + child.scrolledPos.y, 0);
4804 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4805 cycleParent.sbv.Action(Position,
4806 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4809 cycleParent.ConsequentialMouseMove(false);
4815 case f6: case shiftF6:
4816 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4818 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4819 if(parent == guiApp.desktop)
4820 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4830 if(CycleChildren(key.shift, true, false, true))
4838 // mIRC Style Window Shortcuts
4839 case alt1: case alt2: case alt3: case alt4: case alt5:
4840 case alt6: case alt7: case alt8: case alt9: case alt0:
4845 for(document = children.first; document; document = document.next)
4847 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4849 if(document == activeChild)
4851 if(document.state == minimized)
4852 document.SetState(normal, false, key);
4855 document.SetState(minimized, false, key);
4856 CycleChildren(false, true, false);
4861 if(activeChild.state == maximized && document.style.hasMaximize)
4862 document.SetState(maximized, false, key);
4863 else if(document.state == minimized)
4864 document.SetState(normal, false, key);
4865 document.Activate();
4880 if(!destroyed && status)
4882 if(state == minimized)
4887 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4889 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4891 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4892 previousActive.ActivateEx(true, false, false, true, null, null);
4893 delete previousActive;
4899 if(!destroyed && status)
4901 status = ProcessHotKeys(method, key, character);
4903 if(!destroyed && status && !modalWindow && state != minimized)
4906 status = KeyMethod(this, key, character);
4907 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4908 status = OnKeyHit(key, character);
4909 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4911 bool result = false;
4914 case ctrlUp: case ctrlDown:
4915 if(sbv && !guiApp.windowScrolling)
4916 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4918 case wheelUp: case wheelDown:
4919 if(sbv && !guiApp.windowScrolling)
4921 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4922 // Do we want to do a consequential move regardless of result in this case?
4923 ConsequentialMouseMove(false);
4926 case ctrlPageUp: case ctrlPageDown:
4927 if(sbh && !guiApp.windowScrolling)
4928 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4933 ConsequentialMouseMove(false);
4938 if(status && !destroyed && menuBar && state != minimized)
4939 status = menuBar.KeyMessage(method, key, character);
4941 if(style.interim && /*destroyed && */status && interimMaster)
4943 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4944 status = interimMaster.KeyMessage(method, key, character);
4951 bool ProcessHotKeys(uint method, Key key, unichar character)
4956 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4957 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4958 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4960 Window hotKeyWindow = hotKey.window;
4961 Window parent = hotKeyWindow.parent;
4962 Window prevActiveWindow = activeChild;
4963 // For when sys buttons are placed inside the menu bar
4964 if(parent && parent._class == class(PopupMenu))
4965 parent = parent.parent;
4967 // 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
4968 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1])))
4971 if(prevActiveWindow) incref prevActiveWindow;
4972 incref hotKeyWindow;
4973 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient && !hotKeyWindow.inactive)
4974 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4977 delete hotKeyWindow;
4978 delete prevActiveWindow;
4982 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4983 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4984 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4986 // ********* WORKING ON THIS ***********
4987 if(prevActiveWindow && !guiApp.interimWindow)
4988 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4991 else if(hotKeyWindow.style.inactive)
4992 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4994 delete prevActiveWindow;
4995 delete hotKeyWindow;
4996 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4997 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
5001 if(status && tabCycle)
5004 for(child = children.first; child; child = child.next)
5006 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
5017 // --- Windows and graphics initialization / termination ---
5018 bool SetupRoot(void)
5022 // Setup relationship with outside world (bb root || !bb)
5023 #if defined(__EMSCRIPTEN__)
5024 if(this == guiApp.desktop)
5026 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
5027 (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))
5032 tempExtents = new0 Extent[4];
5037 /*if(guiApp.fullScreenMode)
5038 rootWindow = guiApp.desktop;
5040 //rootWindow = parent.created ? parent.rootWindow : null;
5041 rootWindow = parent.rootWindow;
5044 against = &parent.box;
5046 against = &parent.clientArea;
5049 for(child = children.first; child; child = child.next)
5052 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
5055 bool Setup(bool positionChildren)
5057 bool result = false;
5060 #if defined(__EMSCRIPTEN__)
5061 if(this == guiApp.desktop)
5063 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))))
5066 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
5067 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
5070 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
5072 // This was here, is it really needed?
5073 //guiApp.interfaceDriver.ActivateRootWindow(this);
5077 displaySystem = DisplaySystem { glCapabilities = glCapabilities };
5078 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
5080 delete displaySystem;
5085 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, glCapabilities = glCapabilities, windowDriverData = windowData };
5086 if(display.Create(displaySystem, windowHandle))
5093 // Sometimes icon does not show up on Windows XP if we set here...
5094 // guiApp.interfaceDriver.SetIcon(this, icon);
5096 else if(this != guiApp.desktop)
5098 display = rootWindow ? rootWindow.display : null;
5104 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
5105 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
5107 for(child = children.first; child; child = child.next)
5109 if(child.created && !child.Setup(false))
5112 if(guiApp.modeSwitching && guiApp.fullScreen && child.rootWindow == child)
5113 child.UpdateCaption();
5118 bool SetupDisplay(void)
5120 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
5121 if(is3D) return Window3D_SetupDisplay(this); else
5128 class_data void ** pureVTbl;
5130 bool LoadGraphics(bool creation, bool resetAnchors)
5132 bool result = false;
5133 bool success = false;
5135 WindowState stateBackup = state;
5137 if(((subclass(Window))_class).pureVTbl)
5139 if(_vTbl == _class._vTbl)
5141 _vTbl = ((subclass(Window))_class).pureVTbl;
5146 for(m = 0; m < _class.vTblSize; m++)
5148 if(_vTbl[m] == _class._vTbl[m])
5149 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5153 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
5155 if(_vTbl == ((subclass(Window))_class).pureVTbl)
5157 _vTbl = _class._vTbl;
5162 for(m = 0; m < _class.vTblSize; m++)
5164 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
5165 _vTbl[m] = _class._vTbl[m];
5171 #if !defined(__EMSCRIPTEN__)
5172 guiApp.fullScreenMode ||
5174 this != guiApp.desktop)
5176 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
5182 display.Lock(false);
5183 if(rootWindow == this)
5185 // Set Color Palette
5186 display.SetPalette(palette, true);
5190 if(guiApp.fullScreenMode && this == guiApp.desktop)
5195 for(c=0; c<SystemCursor::enumSize; c++)
5196 if(!guiApp.systemCursors[c].bitmap)
5198 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
5199 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
5200 if(guiApp.systemCursors[c].bitmapName)
5202 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
5203 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
5204 if(guiApp.systemCursors[c].bitmap)
5205 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
5210 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5212 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
5213 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
5215 cursor.bitmap.paletteShades = cursor.paletteShades;
5219 guiApp.cursorUpdate = true;
5222 ConsequentialMouseMove(false);
5228 // Load Window Graphic Resources
5231 if(usedFont == setFont || usedFont == window.systemFont)
5232 RemoveResource(usedFont);
5235 RemoveResource(setFont); // TESTING setFont instead of usedFont);
5238 RemoveResource(systemFont);
5241 RemoveResource(captionFont);
5243 for(ptr = resources.first; ptr; ptr = ptr.next)
5245 if(!ptr.loaded) // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
5246 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
5249 AddResource(setFont);
5251 AddResource(systemFont);
5253 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
5260 //if(master && master.font)
5261 if(parent && parent.font)
5265 faceName = parent.font.faceName,
5266 size = parent.font.size,
5267 bold = parent.font.bold,
5268 italic = parent.font.italic,
5269 underline = parent.font.underline
5271 //font = parent.font;
5272 watch(parent) { font { } };
5275 font = guiApp.currentSkin.SystemFont();
5282 captionFont = guiApp.currentSkin ? guiApp.currentSkin.CaptionFont() : null;
5283 AddResource(captionFont);
5285 if(OnLoadGraphics())
5291 //SetScrollLineStep(sbStep.x, sbStep.y);
5293 if(this != guiApp.desktop)
5297 normalAnchor = anchor;
5298 normalSizeAnchor = sizeAnchor;
5301 // Break the anchors for moveable/resizable windows
5303 if(style.fixed && style.isDocument)
5305 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
5317 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5318 stateSizeAnchor = SizeAnchor {};
5323 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5328 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
5329 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
5332 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5336 stateAnchor = normalAnchor;
5337 stateSizeAnchor = normalSizeAnchor;
5340 position = Point { };
5341 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5352 if(Position(x, y, w, h, true, false, true, true, true, true))
5354 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
5357 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
5374 success = result = true;
5377 if(!creation && result)
5379 // Load menu bar first because sys buttons are on it...
5382 if(!menuBar.LoadGraphics(false, resetAnchors))
5388 for(child = children.first; child; child = child.next)
5390 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
5397 CreateSystemChildren();
5401 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5404 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5407 LogErrorCode(graphicsLoadingFailed, _class.name);
5409 // Do this here to avoid problems on Windows
5410 if(rootWindow == this && parent && stateBackup == maximized)
5411 property::state = maximized;
5415 void UnloadGraphics(bool destroyWindows)
5419 // Free children's graphics
5420 for(child = children.first; child; child = child.next)
5421 child.UnloadGraphics(destroyWindows);
5424 display.Lock(false);
5427 if(guiApp.fullScreenMode && this == guiApp.desktop)
5432 for(c=0; c<SystemCursor::enumSize; c++)
5433 if(guiApp.systemCursors[c].bitmap)
5434 delete guiApp.systemCursors[c].bitmap;
5436 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5437 delete cursor.bitmap;
5439 guiApp.cursorBackground.Free();
5442 if(display && display.displaySystem)
5446 for(ptr = resources.first; ptr; ptr = ptr.next)
5450 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5455 // Free window graphics
5458 // Free skin graphics
5459 if(rootWindow == this)
5461 DisplaySystem displaySystem = display.displaySystem;
5464 display.driverData = null;
5465 display.displaySystem = null;
5469 if(displaySystem && !displaySystem.numDisplays && !is3D)
5470 delete displaySystem;
5479 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5480 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5482 if(this == guiApp.desktop || parent == guiApp.desktop)
5484 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5485 guiApp.interfaceDriver.DestroyRootWindow(this);
5489 // --- Window Hiding ---
5491 void SetVisibility(bool state)
5493 bool visible = (style.hidden || !created) ? false : state;
5494 if(visible != this.visible)
5498 this.visible = visible;
5499 for(child = children.first; child; child = child.next)
5500 child.SetVisibility(visible);
5502 ConsequentialMouseMove(false);
5503 if(parent && !nonClient) parent.OnChildVisibilityToggled(this, visible);
5507 // --- Windows and graphics initialization / termination ---
5509 bool DisplayModeChanged(void)
5511 bool result = false;
5512 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5514 guiApp.modeSwitching = true;
5515 UnloadGraphics(false);
5517 if(LoadGraphics(false, false))
5519 guiApp.modeSwitching = false;
5524 // --- Window updates system ---
5526 void UpdateDirty(Box updateBox)
5528 if(!manageDisplay) { OnRedraw(null);return; }
5531 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5534 if(display.flags.flipping)
5537 rootWindow.UpdateDisplay();
5540 UpdateBackDisplay(updateBox);
5542 if(guiApp.fullScreenMode)
5544 guiApp.cursorUpdate = true;
5545 guiApp.PreserveAndDrawCursor();
5547 if(guiApp.fullScreenMode)
5548 guiApp.RestoreCursorBackground();
5554 // This function is strictly called as a result of system window activation
5555 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5558 Window interimMaster = null;
5559 Window interimWindow = guiApp.interimWindow;
5560 if(interimWindow && interimWindow.master)
5561 interimMaster = interimWindow.master.rootWindow;
5563 if(active && state == minimized && window.parent) // && (!window.nativeDecorations || window.rootWindow != window)
5564 // SetState(normal, false, 0);
5565 SetState(lastState, false, 0);
5567 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5571 /* WTH is this doing here?
5572 while(swap && swap.activeChild)
5574 swap = swap.activeChild;
5577 // TESTING THIS BEFORE...
5578 if(interimWindow && this == interimMaster)
5582 // Window interimSwap = this;
5583 Window menuBar = this.menuBar;
5584 if(menuBar && interimWindow.master == menuBar)
5587 while(interimSwap && interimSwap.activeChild)
5588 interimSwap = interimSwap.activeChild;
5590 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5591 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5593 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5594 //result = ActivateEx(true, true, false, activateRoot, window, null);
5599 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5600 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5602 if(interimWindow == this && interimMaster && !active)
5604 while(interimMaster && interimMaster.interim && interimMaster.master)
5606 // printf("Going up one master %s\n", interimMaster._class.name);
5607 interimMaster = interimMaster.master.rootWindow;
5609 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5610 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5616 bool DestroyEx(int64 returnCode)
5619 Timer timer, nextTimer;
5621 OldLink prevOrder = null;
5622 Window client = null;
5624 if(parent) stopwatching(parent, font);
5626 // if(window.modalSlave) return false;
5627 if(destroyed || !created)
5634 OldLink slave = master.slaves.FindLink(this);
5635 master.slaves.Delete(slave);
5638 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5644 this.returnCode = (DialogResult)returnCode;
5646 AcquireInput(false);
5651 master.hotKeys.Delete(hotKey);
5655 if(guiApp.prevWindow == this)
5657 guiApp.prevWindow = null;
5662 for(w : guiApp.overWindows; w == this)
5665 guiApp.overWindows.TakeOut(w);
5669 if(guiApp.caretOwner == this)
5671 guiApp.interfaceDriver.SetCaret(0,0,0);
5672 UpdateCaret(false, true);
5673 guiApp.caretEnabled = false;
5678 parent.childrenCycle.Remove(cycle);
5682 OldLink tmpPrev = order.prev;
5683 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5684 prevOrder = tmpPrev;
5687 client = tmpPrev ? tmpPrev.data : null;
5688 if(client == this) { client = null; break; }
5689 if(client && (client.style.hidden || client.destroyed || !client.created))
5690 tmpPrev = client.order.prev;
5694 prevOrder = tmpPrev;
5699 // If this window can be an active client, make sure the next window we activate can also be one
5700 if(!style.nonClient && style.isActiveClient)
5702 tmpPrev = prevOrder;
5705 client = tmpPrev ? tmpPrev.data : null;
5706 if(client == this) { client = null; break; }
5707 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5708 tmpPrev = client.order.prev;
5712 prevOrder = tmpPrev;
5716 if(client && client.style.hidden) client = null;
5718 // parent.childrenOrder.Remove(order);
5721 if(parent && style.isActiveClient && visible)
5723 if(state == minimized) parent.numIcons--;
5724 parent.numPositions--;
5727 // TESTING THIS HERE!
5731 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5732 // to create a window inside a rootwindow that's being destroyed)
5733 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5735 if(master && !master.destroyed /*&&
5736 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5738 if(master.defaultControl == this)
5739 master.defaultControl = null;
5742 parent.OnChildAddedOrRemoved(this, true);
5743 if(parent && !parent.destroyed /*&&
5744 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5746 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5748 if(order && prevOrder && prevOrder.data != this && active)
5750 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5752 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5753 if(parent.activeClient == this)
5755 parent.activeClient = null;
5756 parent.UpdateActiveDocument(null);
5761 if(guiApp.interimWindow == this)
5764 PropagateActive(false, null, &goOn, true);
5768 //if(window.parent.activeChild == window)
5769 parent.activeChild = null;
5770 if(!style.nonClient /*&& style.isActiveClient*/)
5772 Window previous = parent.activeClient;
5773 if(style.isActiveClient)
5774 parent.activeClient = null;
5775 parent.UpdateActiveDocument(previous);
5780 else if(parent.activeClient == this)
5782 parent.activeClient = client;
5783 parent.UpdateActiveDocument(this);
5787 if(guiApp.interimWindow == this)
5789 guiApp.interimWindow = null;
5790 if(guiApp.caretOwner)
5792 Window desktop = guiApp.desktop;
5793 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5794 guiApp.caretOwner.UpdateCaret(false, false);
5799 if(_isModal && master && master.modalSlave == this)
5800 master.modalSlave = null;
5804 if(!guiApp.caretOwner && parent.caretSize)
5806 guiApp.caretOwner = parent;
5807 parent.UpdateCaret(false, false);
5808 parent.Update(null);
5811 // Why was this commented out?
5812 GetRidOfVirtualArea();
5818 dirtyArea.Free(null);
5819 dirtyBack.Free(null);
5820 scrollExtent.Free(null);
5822 /* ATTEMPTING TO MOVE THAT ABOVE
5831 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5832 for(;(child = window.children.first);)
5834 for(; child && (child.destroyed || !child.created); child = child.next);
5843 UnloadGraphics(true);
5846 delete previousActive;
5849 // statusBar = null;
5852 if(master && !master.destroyed)
5854 //master.NotifyDestroyed(this, this.returnCode);
5855 NotifyDestroyed(master, this, this.returnCode);
5858 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5860 nextTimer = timer.next;
5861 if(timer.window == this)
5863 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5864 // timer.window = null;
5870 if(this == guiApp.windowMoving)
5873 if(guiApp.windowCaptured == this)
5875 //guiApp.windowCaptured = null;
5877 if(rootWindow != this && rootWindow)
5878 rootWindow.ConsequentialMouseMove(false);
5886 //for(child = children.first; next = child ? child.next : null, child; child = next)
5887 for(;(child = children.first); )
5889 for(; child && (child.destroyed || !child.created); child = child.next);
5899 /* // MOVED THIS UP...
5902 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5903 for(;(child = window.children.first); )
5905 for(; child && (child.destroyed || !child.created); child = child.next);
5914 while((slave = slaves.first))
5916 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5918 ((Window)slave.data).DestroyEx(0);
5923 if(guiApp.caretOwner == this)
5924 guiApp.caretOwner = null;
5926 sysButtons[0] = null;
5927 sysButtons[1] = null;
5928 sysButtons[2] = null;
5931 if(rootWindow != this)
5933 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5936 box.left -= parent.clientStart.x;
5937 box.top -= parent.clientStart.y;
5938 box.right -= parent.clientStart.x;
5939 box.bottom -= parent.clientStart.y;
5941 if(parent) parent.Update(box);
5946 OldLink slave = master.slaves.FindVoid(this);
5947 master.slaves.Delete(slave);
5953 parent.children.Remove(this);
5958 //autoCreate = false;
5961 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5962 if(((subclass(Window))_class).pureVTbl)
5964 if(_vTbl == _class._vTbl)
5966 _vTbl = ((subclass(Window))_class).pureVTbl;
5971 for(m = 0; m < _class.vTblSize; m++)
5973 if(_vTbl[m] == _class._vTbl[m])
5974 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5983 void SetStateEx(WindowState newState, bool activate)
5986 WindowState prevState = state;
5990 if(prevState != newState)
5991 lastState = prevState;
5993 if(rootWindow != this || !nativeDecorations || !windowHandle)
5995 if(style.isActiveClient && !style.hidden && prevState == minimized)
5998 // This block used to be at the end of the function... moved it for flicker problem in X
5999 // ------------------------------------------------------
6003 stateAnchor = normalAnchor;
6004 stateSizeAnchor = normalSizeAnchor;
6007 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
6008 stateSizeAnchor = SizeAnchor {};
6014 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
6017 byte * idBuffer = new0 byte[size];
6019 for(child = parent.children.first; child; child = child.next)
6021 if(child != this && child.state == minimized)
6023 if(child.iconID > size - 2)
6025 idBuffer = renew0 idBuffer byte[size*2];
6026 memset(idBuffer + size, 0, size);
6029 idBuffer[child.iconID] = (byte)bool::true;
6032 for(c = 0; c<size; c++)
6037 if(style.isActiveClient && !style.hidden)
6040 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
6041 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
6046 // TOCHECK: Why was this here?
6047 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
6048 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
6049 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6051 if(state != minimized || hasMinimize)
6052 Position(x, y, w, h, true, true, true, true, false, true);
6054 if(!style.inactive && !style.interim && parent && this == parent.activeClient)
6055 parent.UpdateActiveDocument(null);
6058 if(state != minimized || hasMinimize)
6059 CreateSystemChildren();
6060 // ------------------------------------------------------
6063 int GetPositionID(Window forChild)
6067 byte * idBuffer = new0 byte[size];
6070 for(child = children.first; child; child = child.next)
6072 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
6074 if(child.positionID > size - 2)
6076 idBuffer = renew0 idBuffer byte[size*2];
6077 memset(idBuffer + size, 0, size);
6080 idBuffer[child.positionID] = (byte)bool::true;
6083 for(c = 0; c<size; c++)
6090 // --- Window related graphics ---
6092 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
6094 palette = newPalette;
6095 if(rootWindow.display)
6096 rootWindow.display.SetPalette(palette, colorMatch);
6099 public bool AcquireInput(bool acquired)
6102 if((guiApp.acquiredWindow && acquiredInput) != acquired)
6104 if(active || (!visible && creationActivation == activate))
6105 result = AcquireInputEx(acquired);
6110 acquiredInput = acquired ? result : !result;
6115 void ListChildren(ListBox listBox)
6119 for(child = children.first; child; child = child.next)
6121 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
6123 DataRow row = listBox.AddRow();
6124 row.tag = (int64)(intptr)child;
6125 child.FigureCaption(caption);
6126 row.SetData(null, caption);
6131 void UpdateVisual(Box extent)
6133 if(guiApp.driver != null)
6135 #if !defined(__EMSCRIPTEN__)
6136 if(guiApp.fullScreenMode && guiApp.desktop.display)
6141 #if !defined(__EMSCRIPTEN__)
6142 guiApp.desktop.mutex.Wait();
6144 guiApp.desktop.display.Lock(true);
6147 if(guiApp.desktop.active)
6149 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
6151 if(guiApp.desktop.display.flags.flipping)
6152 guiApp.desktop.Update(null);
6153 guiApp.desktop.UpdateDisplay();
6154 guiApp.cursorUpdate = true;
6156 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
6158 guiApp.PreserveAndDrawCursor();
6159 // guiApp.desktop.display.ShowScreen();
6160 guiApp.cursorUpdate = false;
6161 guiApp.desktop.dirty = false;
6162 guiApp.RestoreCursorBackground();
6166 guiApp.desktop.display.Unlock();
6167 #if !defined(__EMSCRIPTEN__)
6168 guiApp.desktop.mutex.Release();
6173 Window rootWindow = this.rootWindow;
6174 #if !defined(__EMSCRIPTEN__)
6175 rootWindow.mutex.Wait();
6181 guiApp.SignalEvent();
6184 #if !defined(__EMSCRIPTEN__)
6185 guiApp.waitMutex.Wait();
6187 guiApp.interfaceDriver.Lock(rootWindow);
6188 if(!rootWindow.style.hidden && rootWindow.dirty)
6190 if(rootWindow.display)
6192 rootWindow.UpdateDisplay();
6193 //rootWindow.display.ShowScreen(null);
6195 rootWindow.dirty = false;
6197 guiApp.interfaceDriver.Unlock(rootWindow);
6198 #if !defined(__EMSCRIPTEN__)
6199 guiApp.waitMutex.Release();
6203 #if !defined(__EMSCRIPTEN__)
6204 rootWindow.mutex.Release();
6210 void UnlockDisplay(void)
6212 guiApp.interfaceDriver.Unlock(rootWindow);
6215 void LockDisplay(void)
6217 guiApp.interfaceDriver.Lock(rootWindow);
6220 Surface GetSurface(Box box)
6222 return Redraw((box == null) ? this.box : box);
6225 void SetMousePosition(int x, int y)
6227 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
6231 void IntegrationActivate(bool active)
6233 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
6235 isForegroundWindow = true;
6236 ActivateEx(active, active, false, false, null, null);
6237 isForegroundWindow = false;
6242 Window QueryCapture(void)
6244 return guiApp.windowCaptured;
6247 int GetDocumentID(void)
6251 byte * idBuffer = new0 byte[size];
6254 for(child = children.first; child; child = child.next)
6256 // TO CHECK: Do we want a documentID when we already have a file name?
6257 if(child.style.isDocument && !child.fileName)
6259 if(child.documentID-1 > size - 2)
6261 idBuffer = renew0 idBuffer byte[size*2];
6262 memset(idBuffer + size, 0, size);
6265 idBuffer[child.documentID-1] = 1;
6268 for(c = 0; c<size; c++)
6276 void SetInitSize(Size size)
6279 sizeAnchor.size = size;
6280 normalSizeAnchor = sizeAnchor;
6282 // Break the anchors for moveable/resizable windows
6283 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6285 stateAnchor = normalAnchor;
6286 stateSizeAnchor = normalSizeAnchor;
6288 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6289 Position(x,y, w, h, true, true, true, true, false, true);
6293 void MenuMoveOrSize(bool resize, bool setCursorPosition)
6295 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
6297 guiApp.windowIsResizing = resize;
6298 guiApp.windowMoving = this;
6299 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
6300 if(guiApp.windowIsResizing)
6302 guiApp.windowMovingStart.x += size.w - 1;
6303 guiApp.windowMovingStart.y += size.h - 1;
6305 guiApp.windowMovingBefore = scrolledPos;
6306 guiApp.windowResizingBefore = size;
6307 guiApp.windowMoving.UpdateDecorations();
6308 if(guiApp.windowIsResizing)
6309 guiApp.resizeEndX = guiApp.resizeEndY = true;
6311 if(setCursorPosition)
6312 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
6316 guiApp.interfaceDriver.GetMousePosition(&x, &y);
6317 guiApp.windowMovingStart.x += x - absPosition.x;
6318 guiApp.windowMovingStart.y += y - absPosition.y;
6321 if(guiApp.windowMoving)
6323 if(guiApp.windowMoving.style.nonClient)
6324 guiApp.windowMoving.parent.SetMouseRangeToWindow();
6326 guiApp.windowMoving.parent.SetMouseRangeToClient();
6331 if(this == rootWindow)
6332 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
6336 void SetupFileMonitor()
6338 #if !defined(__EMSCRIPTEN__)
6341 fileMonitor = FileMonitor
6343 this, FileChange { modified = true };
6345 bool OnFileNotify(FileChange action, const char * param)
6348 fileMonitor.StopMonitoring();
6349 if(OnFileModified(action, param))
6350 fileMonitor.StartMonitoring();
6364 bool result = false;
6368 else if(guiApp && guiApp.driver != null)
6370 OldLink slaveHolder;
6372 bool visible = !style.hidden;
6376 systemParent = parent;
6377 parent = guiApp.desktop;
6379 last = parent ? parent.children.last : null;
6381 if((parent && parent != guiApp.desktop && !parent.created) ||
6382 (master && master != guiApp.desktop && !master.created))
6386 stopwatching(parent, font);
6389 property::parent = guiApp.desktop;
6390 if(!master) master = parent;
6392 if(_isModal && master.modalSlave)
6393 property::master = master.modalSlave;
6397 parent.children.Remove(this);
6400 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
6401 if(slaveHolder.data == this)
6403 master.slaves.Delete(slaveHolder);
6408 #if !defined(__EMSCRIPTEN__)
6409 if(parent == guiApp.desktop && !mutex)
6413 if(style.isDocument)
6416 parent.numDocuments--;
6417 documentID = parent.GetDocumentID();
6420 if(!style.stayOnTop)
6421 for(; last && last.style.stayOnTop; last = last.prev);
6423 parent.children.Insert((last == this) ? null : last, this);
6424 //parent.children.Add(this);
6427 dispDriver = parent.dispDriver;
6430 master.modalSlave = this;
6432 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
6437 master.slaves.Add(slaveHolder = OldLink { data = this });
6442 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
6444 if(style.isDefault && !master.defaultControl)
6445 master.defaultControl = this;
6447 stateAnchor = normalAnchor = anchor;
6448 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
6450 // TOCHECK: Why is this here?
6451 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
6452 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
6454 this.visible = false;
6455 style.hidden = true;
6458 // autoCreate = true;
6466 if(parent == guiApp.desktop)
6467 Log("LoadGraphics %s\n", caption);
6469 if(LoadGraphics(true, false))
6477 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6484 if(style.hasMenuBar /*&& menu*/)
6490 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6491 interim = false, inactive = true, nonClient = true, size.h = 24
6499 // Create the system buttons
6500 CreateSystemChildren();
6502 UpdateActiveDocument(null);
6504 if(style.isDocument)
6508 MenuItem item = menu.FindItem(MenuFileSave, 0);
6509 if(item) item.disabled = !modifiedDocument && fileName;
6514 if(parent == guiApp.desktop)
6515 Log("Preemptive SetState %s\n", caption);
6518 // Preemptive Set State to ensure proper anchoring
6519 SetStateEx(state, false);
6521 style.hidden = true;
6527 for(child = children.first; child; child = next)
6530 if(!child.created && (child.autoCreate || child.wasCreated))
6537 for(link = slaves.first; link; link = next)
6539 Window slave = link.data;
6541 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6544 // Things might have happened that invalidated 'next'...
6545 // Start over the search for slaves to create.
6546 // (Added this to fix crash with Stacker & Toolbar)
6547 next = slaves.first;
6556 if(parent == guiApp.desktop)
6557 Log("Real SetState %s\n", caption);
6560 if(isActiveClient && visible)
6562 parent.numPositions--;
6563 if(state == minimized) parent.numIcons--;
6566 parent.OnChildAddedOrRemoved(this, false);
6568 if(rootWindow == this && visible) // So that X11 windows don't show as 'unknown'
6570 // Real set state & activate for proper display & activation
6571 property::visible = visible;
6572 // SetState(state & 0x00000003, true, 0);
6573 guiApp.interfaceDriver.SetIcon(this, icon);
6578 /*if(rootWindow == this)
6579 guiApp.interfaceDriver.ActivateRootWindow(this);
6581 if(creationActivation == activate && guiApp.desktop.active)
6582 ActivateEx(true, false, true, true, null, null);
6583 else if(creationActivation == activate || creationActivation == flash)
6586 if(this == rootWindow)
6591 if(!destroyed && !noConsequential)
6592 rootWindow.ConsequentialMouseMove(false);
6603 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6609 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6611 //style.hidden = true; // !visible;
6612 style.hidden = !visible;
6613 if(master.modalSlave == this)
6614 master.modalSlave = null;
6621 void WriteCaption(Surface surface, int x, int y)
6624 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6627 void Update(Box region)
6633 rootWindow = this.rootWindow;
6635 // rootWindow.mutex.Wait();
6636 if(!destroyed && visible && display)
6641 // Testing this to avoid repetitve full update to take time...
6642 if(rootWindow.fullRender)
6644 rootWindow.dirty = true;
6647 if(dirtyArea.count == 1)
6649 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6650 if(item.box.left <= box.left &&
6651 item.box.top <= box.top &&
6652 item.box.right >= box.right &&
6653 item.box.bottom >= box.bottom)
6655 rootWindow.dirty = true;
6660 if(display.flags.flipping && !rootWindow.dirty)
6662 if(this == rootWindow)
6666 rootWindow.Update(null);
6671 rootWindow.dirty = true;
6676 realBox.left += clientStart.x;
6677 realBox.top += clientStart.y;
6678 realBox.right += clientStart.x;
6679 realBox.bottom += clientStart.y;
6685 if(realBox.right >= realBox.left &&
6686 realBox.bottom >= realBox.top)
6688 // if(!rootWindow.fullRender)
6689 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6691 for(child = children.first; child; child = child.next)
6696 box.left -= child.absPosition.x - absPosition.x;
6697 box.top -= child.absPosition.y - absPosition.y;
6698 box.right -= child.absPosition.x - absPosition.x;
6699 box.bottom -= child.absPosition.y - absPosition.y;
6700 if(box.right >= child.box.left && box.left <= child.box.right &&
6701 box.bottom >= child.box.top && box.top <= child.box.bottom)
6703 box.left -= child.clientStart.x;
6704 box.top -= child.clientStart.y;
6705 box.right -= child.clientStart.x;
6706 box.bottom -= child.clientStart.y;
6712 realBox.left += absPosition.x - rootWindow.absPosition.x;
6713 realBox.top += absPosition.y - rootWindow.absPosition.y;
6714 realBox.right += absPosition.x - rootWindow.absPosition.x;
6715 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6716 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6719 else if(this == guiApp.desktop)
6722 for(window = children.first; window; window = window.next)
6728 Box childBox = region;
6730 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6731 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6732 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6733 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6735 window.Update(childBox);
6738 window.Update(null);
6743 // rootWindow.mutex.Release();
6750 if(guiApp.windowCaptured != this)
6752 if(guiApp.windowCaptured)
6756 //Logf("Captured %s (%s)\n", caption, class.name);
6757 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6758 guiApp.windowCaptured = this;
6764 bool Destroy(int64 code)
6769 if(!destroyed && !CloseConfirmation(false)) return false;
6773 // TOCHECK: Should autoCreate be set to false here?
6784 void Move(int x, int y, int w, int h)
6786 normalAnchor = Anchor { left = x, top = y };
6787 normalSizeAnchor = SizeAnchor { size = { w, h } };
6789 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6791 if(destroyed) return;
6793 stateAnchor = normalAnchor;
6794 stateSizeAnchor = normalSizeAnchor;
6796 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6797 Position(x,y, w, h, true, true, true, true, false, true);
6801 DialogResult Modal(void)
6807 // FIXES MEMORY LEAK IF Create() FAILED
6813 void SetScrollArea(int width, int height, bool snapToStep)
6817 int stepX = sbStep.x, stepY = sbStep.y;
6818 // Needed to make snapped down position match the skin's check of client area
6819 // against realvirtual
6822 SNAPDOWN(stepX, textCellW);
6823 SNAPDOWN(stepY, textCellH);
6824 stepX = Max(stepX, textCellW);
6825 stepY = Max(stepY, textCellH);
6827 if(scrollFlags.snapX)
6828 SNAPUP(width, stepX);
6829 if(scrollFlags.snapY)
6830 SNAPUP(height, stepY);
6833 reqScrollArea.w = width;
6834 reqScrollArea.h = height;
6835 noAutoScrollArea = (width > 0 || height > 0);
6837 UpdateScrollBars(true, true);
6840 void SetScrollPosition(int x, int y)
6843 sbh.Action(setPosition, x, 0);
6847 int seen = clientSize.w, total = reqScrollArea.w;
6849 if(scrollFlags.snapX)
6850 SNAPDOWN(seen, sbStep.x);
6852 if(!total) total = seen;
6853 range = total - seen + 1;
6854 range = Max(range, 1);
6856 if(x >= range) x = range - 1;
6858 if(scrollFlags.snapX)
6859 SNAPUP(x, sbStep.x);
6862 OnHScroll(setPosition, x, 0);
6866 SNAPDOWN(x, textCellW);
6872 sbv.Action(setPosition, y, 0);
6876 int seen = clientSize.h, total = reqScrollArea.h;
6879 if(scrollFlags.snapY)
6880 SNAPDOWN(seen, sbStep.y);
6882 if(!total) total = seen;
6883 range = total - seen + 1;
6884 range = Max(range, 1);
6886 if(y >= range) y = range - 1;
6888 if(scrollFlags.snapY)
6889 SNAPUP(y, sbStep.y);
6892 OnVScroll(setPosition, y, 0);
6895 SNAPDOWN(y, textCellH);
6900 UpdateCaret(false, false);
6903 void SetScrollLineStep(int stepX, int stepY)
6909 SNAPDOWN(stepX, textCellW);
6910 SNAPDOWN(stepY, textCellH);
6911 stepX = Max(stepX, textCellW);
6912 stepY = Max(stepY, textCellH);
6915 sbh.lineStep = stepX;
6917 sbv.lineStep = stepY;
6920 void SetState(WindowState newState, bool activate, Modifiers mods)
6924 if(state == newState || OnStateChange(newState, mods))
6926 //WindowState prevState = state;
6930 // This used to be at the end of the brackets... moved for X, testing...
6931 // This has the effect of activating the window through the system...
6932 if(rootWindow == this)
6933 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6935 SetStateEx(newState, activate);
6937 if(rootWindow == this && !rootWindow.nativeDecorations)
6939 int x = position.x, y = position.y;
6942 x -= guiApp.desktop.absPosition.x;
6943 y -= guiApp.desktop.absPosition.y;
6945 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6949 //state = prevState;
6951 if(state != maximized && style.hasMaximize)
6954 for(child = parent.children.first; child; child = child.next)
6956 if(child != this && child.state == maximized)
6957 child.SetStateEx(normal, false);
6961 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6962 parent.UpdateScrollBars(true, true);
6965 // Do we really need this stuff here?
6966 // Shouldn't the Activate stuff take care of it?
6967 if(parent.rootWindow == parent && style)
6970 parent.FigureCaption(caption);
6971 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6972 parent.UpdateDecorations();
6976 rootWindow.ConsequentialMouseMove(false);
6983 BitmapResource GetIcon(SkinBitmap iconID)
6985 return guiApp.currentSkin.GetBitmap(iconID);
6988 void SetMouseRange(Box range)
6990 if(range || guiApp.fullScreenMode)
6995 clip.left = range.left + absPosition.x + clientStart.x;
6996 clip.top = range.top + absPosition.y + clientStart.y;
6997 clip.right = range.right + absPosition.x + clientStart.x;
6998 clip.bottom = range.bottom + absPosition.y + clientStart.y;
7002 clip.left = guiApp.desktop.box.left;
7003 clip.top = guiApp.desktop.box.top;
7004 clip.right = guiApp.desktop.box.right;
7005 clip.bottom = guiApp.desktop.box.bottom;
7007 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
7010 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
7013 void SetMouseRangeToClient(void)
7015 if(guiApp.fullScreenMode || this != guiApp.desktop)
7017 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
7018 box.Clip(clientArea);
7022 SetMouseRange(null);
7025 void SetMouseRangeToWindow(void)
7027 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
7028 if(this == guiApp.desktop)
7029 SetMouseRangeToClient();
7034 // x, y: Desktop Coordinates
7035 void ShowSysMenu(int x, int y)
7038 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
7041 menu, $"Restore", r, NotifySelect = MenuWindowRestore,
7042 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
7046 menu, $"Move", m, NotifySelect = MenuWindowMove,
7047 disabled = !style.fixed || state == maximized
7051 menu, $"Size", s, NotifySelect = MenuWindowSize,
7052 disabled = !style.sizable || state != normal
7056 menu, $"Minimize", n, NotifySelect = MenuWindowMinimize,
7057 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
7061 menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
7062 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
7066 menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
7067 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
7069 MenuDivider { menu };
7072 menu, $"Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
7073 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
7075 windowMenu.Create();
7080 ActivateEx(true, true, true, true, null, null);
7083 void MakeActive(void)
7085 ActivateEx(true, false, true, false, null, null);
7088 void SoftActivate(void)
7090 if(guiApp.desktop.active)
7095 if(this == rootWindow)
7100 void Deactivate(void)
7102 ActivateEx(false, true, true, true, null, null);
7107 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
7110 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
7112 bool result = false;
7113 if(activeChild && activeChild.cycle)
7115 Window modalWindow, child = activeChild;
7116 if(!clientOnly /*&& parent.tabCycle*/)
7118 Window next = child;
7121 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
7125 if(parent && parent.CycleChildren(backward, false, true, true))
7133 next = next.cycle.prev.data;
7135 next = next.cycle.next.data;
7136 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
7141 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
7142 parent.tabCycle && parent.CycleChildren(backward, false, false))
7146 if(tabCycleOnly && !tabCycle) return false;
7153 child = child.cycle.prev.data;
7155 child = child.cycle.next.data;
7156 if(child == child.parent.activeChild)
7158 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
7161 modalWindow = child.FindModal();
7164 // Scroll the window to include the active control
7165 if(sbh && !child.style.dontScrollHorz)
7167 if(child.scrolledPos.x < 0)
7168 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
7169 else if(child.scrolledPos.x + child.size.w > clientSize.w)
7170 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
7172 if(sbv && !child.style.dontScrollVert)
7174 if(child.scrolledPos.y < 0)
7175 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
7176 else if(child.scrolledPos.y + child.size.h > clientSize.h)
7177 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
7181 child = modalWindow ? modalWindow : child;
7182 child.ActivateEx(true, true, true, true, null, null);
7183 if(child.tabCycle && child.childrenCycle.first)
7184 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
7192 ConsequentialMouseMove(false);
7196 void AddResource(Resource resource)
7200 ResPtr ptr { resource = resource };
7204 // Load Graphics here if window is created already
7205 if(/*created && */display)
7207 display.Lock(false);
7208 if(!ptr.loaded) // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
7209 ptr.loaded = display.displaySystem.LoadResource(resource);
7213 // Temporary hack to load font right away for listbox in dropbox ...
7214 else if(master && master.display)
7216 master.display.Lock(false);
7217 master.display.displaySystem.LoadResource(resource);
7218 master.display.Unlock();
7224 void RemoveResource(Resource resource)
7229 for(ptr = resources.first; ptr; ptr = ptr.next)
7231 if(ptr.resource == resource)
7237 // Unload Graphics here if window is created already
7238 if(/*created && */display)
7242 display.Lock(false);
7243 display.displaySystem.UnloadResource(resource, ptr.loaded);
7249 resources.Delete(ptr);
7254 void SetCaret(int x, int y, int size)
7261 if(active && !style.interim && isEnabled)
7263 if(visible || !guiApp.caretOwner)
7264 guiApp.caretOwner = size ? this : null;
7266 UpdateCaret(false, false);
7269 guiApp.interfaceDriver.SetCaret(0,0,0);
7270 UpdateCaret(false, true);
7271 guiApp.caretEnabled = false;
7274 else if(style.inactive && active)
7276 guiApp.interfaceDriver.SetCaret(0,0,0);
7277 UpdateCaret(false, true);
7278 guiApp.caretEnabled = false;
7283 void Scroll(int x, int y)
7285 bool opaque = !style.drawBehind || background.a;
7286 if(opaque && display && display.flags.scrolling)
7288 Box box = clientArea;
7289 box.left += clientStart.x;
7290 box.top += clientStart.y;
7291 box.right += clientStart.x;
7292 box.bottom += clientStart.y;
7294 //scrollExtent.Free(null);
7295 scrollExtent.AddBox(box);
7296 scrolledArea.x += x;
7297 scrolledArea.y += y;
7299 //scrollExtent.Free();
7300 //scrollExtent.AddBox(clientArea);
7301 //scrollExtent.Offset(clientStart.x, clientStart.y);
7302 //scrolledArea.x = x;
7303 //scrolledArea.y = y;
7309 rootWindow.dirty = true;
7312 void ReleaseCapture()
7314 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
7316 Window oldCaptured = guiApp.windowCaptured;
7317 guiApp.windowCaptured = null;
7318 guiApp.prevWindow = null;
7321 //guiApp.Log("Released Capture\n");
7323 guiApp.interfaceDriver.SetMouseCapture(null);
7325 //oldCaptured.OnMouseCaptureLost();
7328 oldCaptured.ConsequentialMouseMove(false);
7333 private void _SetCaption(const char * format, va_list args)
7340 char caption[MAX_F_STRING];
7341 vsnprintf(caption, sizeof(caption), format, args);
7342 caption[sizeof(caption)-1] = 0;
7344 this.caption = CopyString(caption);
7349 firewatchers caption;
7353 /*deprecated*/ void SetText(const char * format, ...)
7356 va_start(args, format);
7357 _SetCaption(format, args);
7361 void SetCaption(const char * format, ...)
7364 va_start(args, format);
7365 _SetCaption(format, args);
7369 bool Grab(Bitmap bitmap, Box box, bool decorations)
7371 bool result = false;
7372 if(display || this == guiApp.desktop)
7374 Box clip = {MININT, MININT, MAXINT, MAXINT};
7380 clip.Clip(clientArea);
7382 clip.Clip(this.box);
7384 if(rootWindow != this)
7386 clip.left += absPosition.y;
7387 clip.top += absPosition.y;
7388 clip.right += absPosition.x;
7389 clip.bottom += absPosition.y;
7392 if(!nativeDecorations)
7394 clip.left += decorations ? 0 : clientStart.x;
7395 clip.top += decorations ? 0 : clientStart.y;
7396 clip.right += decorations ? 0 : clientStart.x;
7397 clip.bottom += decorations ? 0 : clientStart.y;
7400 if(decorations && this == guiApp.desktop)
7401 clip = { 0, 0, guiApp.virtualScreen.w, guiApp.virtualScreen.h };
7403 if(display && display.flags.flipping)
7405 rootWindow.Update(null);
7406 rootWindow.UpdateDisplay();
7413 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
7414 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7418 result = display.Grab(bitmap, clip.left, clip.top,
7419 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7421 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
7423 if(!bitmap.Convert(null, pixelFormat888, null))
7430 void GetMousePosition(int * x, int * y)
7432 int mouseX = 0, mouseY = 0;
7433 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
7436 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
7437 if(this != guiApp.desktop)
7439 mouseX -= absPosition.x + clientStart.x;
7440 mouseY -= absPosition.y + clientStart.y;
7447 DialogResult DoModal()
7449 DialogResult returnCode = 0;
7450 int terminated = terminateX;
7453 while(!destroyed && guiApp.driver != null)
7455 if(terminateX != terminated)
7457 terminated = terminateX;
7458 guiApp.desktop.Destroy(0);
7459 if(guiApp.desktop.created)
7462 //printf("Resetting terminate X to 0\n");
7468 guiApp.UpdateDisplay();
7469 if(!guiApp.ProcessInput(false))
7472 returnCode = this.returnCode;
7485 return !destroyed && guiApp.driver != null && terminateX < 2;
7488 DialogResult DoModalEnd()
7490 DialogResult returnCode = this.returnCode;
7495 // --- Window manipulation ---
7496 /*bool GetDisabled()
7498 bool disabled = this.disabled;
7500 for(window = this; (window = window.master); )
7511 // --- Mouse Manipulation ---
7512 void GetNCMousePosition(int * x, int * y)
7514 GetMousePosition(x, y);
7515 if(x) *x += clientStart.x;
7516 if(y) *y += clientStart.y;
7519 // --- Carets manipulation ---
7520 void GetCaretPosition(Point caretPos)
7522 caretPos = this.caretPos;
7525 int GetCaretSize(void)
7530 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7536 bool CloseConfirmation(bool parentClosing)
7549 if(!OnClose(parentClosing))
7552 // If you want to skip this, simply set modifiedDocument to false in OnClose
7553 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7555 DialogResult dialogRes;
7558 sprintf(message, $"Save changes to %s?", fileName);
7560 sprintf(message, $"Save changes to Untitled %d?", documentID);
7562 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = message }.Modal();
7564 if(dialogRes == yes)
7566 // TOFIX: Precomp error if brackets are taken out
7567 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7569 else if(dialogRes == cancel)
7575 for(slave = slaves.first; slave; slave = slave.next)
7577 Window w = slave.data;
7578 if(w.parent != this && !w.IsDescendantOf(this) && !w.CloseConfirmation(true))
7586 // Confirm closure of active clients first (We use OnClose() to hide instead of destroy in the IDE)
7589 for(child = children.first; child; child = child.next)
7590 if(child.isActiveClient && !child.CloseConfirmation(true))
7598 for(child = children.first; child; child = child.next)
7599 if(!child.isActiveClient && !child.CloseConfirmation(true))
7609 // Static methods... move them somewhere else?
7610 void ::RestoreCaret()
7612 if(guiApp.caretOwner)
7613 guiApp.caretOwner.UpdateCaret(false, false);
7616 void ::FreeMouseRange()
7618 guiApp.interfaceDriver.SetMouseRange(null, null);
7622 bool MenuFileClose(MenuItem selection, Modifiers mods)
7624 Window document = activeChild;
7626 document.Destroy(0);
7630 bool MenuFileExit(MenuItem selection, Modifiers mods)
7636 bool MenuFileSave(MenuItem selection, Modifiers mods)
7641 #if !defined(__EMSCRIPTEN__)
7642 fileMonitor.fileName = null;
7646 if(OnSaveFile(fileName))
7648 //if(OnFileModified != Window::OnFileModified)
7651 #if !defined(__EMSCRIPTEN__)
7652 fileMonitor.fileName = fileName;
7659 MessageBox dialog { master = master, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7660 DialogResult answer = dialog.Modal();
7662 if(answer != yes) return (bool)answer;
7665 return MenuFileSaveAs(selection, mods);
7668 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7670 DialogResult result = (DialogResult)bool::true;
7671 FileDialog fileDialog = saveDialog;
7676 fileDialog = FileDialog {};
7681 fileDialog.filePath = fileName;
7684 char filePath[MAX_FILENAME];
7685 sprintf(filePath, "Untitled %d", documentID);
7686 fileDialog.filePath = filePath;
7688 #if !defined(__EMSCRIPTEN__)
7689 fileMonitor.fileName = null;
7692 fileDialog.type = save;
7693 fileDialog.text = $"Save As";
7697 fileDialog.master = master.parent ? master : this;
7698 if(fileDialog.Modal() == ok)
7700 const char * filePath = fileDialog.filePath;
7702 if(OnSaveFile(filePath))
7705 property::fileName = filePath;
7706 NotifySaved(master, this, filePath);
7711 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7712 DialogResult answer = dialog.Modal();
7727 #if !defined(__EMSCRIPTEN__)
7728 //if(OnFileModified != Window::OnFileModified && fileName)
7731 fileMonitor.fileName = fileName;
7736 return (bool)result; // Actually returning result from Yes/NoCancel message box
7739 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7741 Window document = activeChild;
7743 for(document = children.first; document; document = next)
7745 next = document.next;
7746 if(document.style.isDocument || document.fileName)
7747 document.MenuFileSave(selection, mods);
7752 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7756 for(document = children.first; document; document = document.next)
7757 //if(document.style.isDocument && document.state == minimized)
7758 if(document.style.isActiveClient && document.state == minimized)
7759 document.SetState(minimized, false, mods);
7763 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7765 Window document = activeChild;
7768 Window firstDocument = null;
7770 OldLink cycle = document.cycle.prev;
7775 if(child.style.isActiveClient && !child.style.hidden)
7779 firstDocument = child;
7780 if(child.state == minimized)
7781 child.SetState(minimized, false, mods);
7784 child.positionID = id++;
7785 child.SetState(normal, false, mods);
7786 child.anchor.left.type = cascade;
7789 child.normalSizeAnchor = *&child.sizeAnchor;
7790 child.normalAnchor = child.anchor;
7792 // Break the anchors for moveable/resizable windows
7793 if(child.style.fixed)
7795 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7797 (*&child.normalAnchor).left = x;
7798 (*&child.normalAnchor).top = y;
7799 (*&child.normalAnchor).right.type = none;
7800 (*&child.normalAnchor).bottom.type = none;
7801 (*&child.normalSizeAnchor).isClientW = false;
7802 (*&child.normalSizeAnchor).isClientH = false;
7803 (*&child.normalSizeAnchor).size.w = w;
7804 (*&child.normalSizeAnchor).size.h = h;
7805 child.anchored = false;
7808 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7810 child.stateAnchor = child.normalAnchor;
7811 child.stateSizeAnchor = child.normalSizeAnchor;
7813 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7814 child.Position(x, y, w, h, true, true, true, true, false, false);
7819 last = children.last;
7820 if(!child.style.stayOnTop)
7821 for(; last && last.style.stayOnTop; last = last.prev);
7822 children.Move(child, last);
7823 childrenOrder.Move(child.order, childrenOrder.last);
7825 if(cycle == document.cycle) break;
7829 firstDocument.Activate();
7834 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7841 // Close all closes all active clients, not all documents
7842 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7844 Window next, document;
7846 for(document = children.first; document; document = next)
7848 for(next = document.next; next && !next.style.isActiveClient; next = next.next);
7849 if(document.style.isActiveClient)
7850 if(!document.Destroy(0) && !document.style.hidden)
7856 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7858 if(style.hasMaximize && state != maximized)
7859 SetState(maximized, 0, 0);
7863 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7865 if(style.hasMinimize && state != minimized)
7867 SetState(minimized, 0, 0);
7868 parent.CycleChildren(false, true, false, true);
7873 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7875 MenuMoveOrSize(false, selection ? true : false);
7879 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7881 CycleChildren(false, true, false, true);
7885 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7887 CycleChildren(true, true, false, true);
7891 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7893 MenuMoveOrSize(true, true);
7897 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7900 SetState(normal, 0, 0);
7904 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7907 int64 id = selection.id;
7908 OldLink cycle = activeClient.cycle;
7910 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7913 Window sibling = cycle.data;
7914 if(sibling.style.isActiveClient && sibling.visible && !sibling.style.nonClient)
7922 document = cycle.data;
7923 document.Activate();
7925 //if(activeChild.state == maximized)
7926 // document.SetState(maximized, false, mods);
7927 //else if(document.state == minimized)
7928 // document.SetState(normal, false, mods);
7932 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7934 stayOnTop = !style.stayOnTop;
7938 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7940 Window document = activeChild;
7943 Window firstDocument = null;
7944 OldLink cycle = document.cycle;
7948 Window child = cycle.data;
7949 if(child.style.isActiveClient && !child.style.hidden)
7951 if(!firstDocument) firstDocument = child;
7952 if(child.state == minimized)
7953 child.SetState(minimized, false, mods);
7956 child.positionID = id++;
7957 child.SetState(normal, false, mods);
7958 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7960 child.anchor.left.type = hTiled;
7963 child.normalSizeAnchor = *&child.sizeAnchor;
7964 child.normalAnchor = child.anchor;
7966 // Break the anchors for moveable/resizable windows
7967 if(child.style.fixed)
7969 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7971 (*&child.normalAnchor).left = x;
7972 (*&child.normalAnchor).top = y;
7973 (*&child.normalAnchor).right.type = none;
7974 (*&child.normalAnchor).bottom.type = none;
7975 (*&child.normalSizeAnchor).isClientW = false;
7976 (*&child.normalSizeAnchor).isClientH = false;
7977 (*&child.normalSizeAnchor).size.w = w;
7978 (*&child.normalSizeAnchor).size.h = h;
7979 child.anchored = false;
7982 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7984 child.stateAnchor = child.normalAnchor;
7985 child.stateSizeAnchor = child.normalSizeAnchor;
7987 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7988 child.Position(x,y, w, h, true, true, true, true, false, true);
7993 if((cycle = cycle.next) == document.cycle) break;
7996 firstDocument.Activate();
8001 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
8003 Window document = activeChild;
8006 Window firstDocument = null;
8008 OldLink cycle = document.cycle;
8013 //if(child.style.isDocument)
8014 if(child.style.isActiveClient && !child.style.hidden)
8016 if(!firstDocument) firstDocument = child;
8017 if(child.state == minimized)
8018 child.SetState(minimized, false, mods);
8021 child.positionID = id++;
8022 child.SetState(normal, false, mods);
8023 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
8025 child.anchor.left.type = vTiled;
8028 child.normalSizeAnchor = *&child.sizeAnchor;
8029 child.normalAnchor = child.anchor;
8031 // Break the anchors for moveable/resizable windows
8032 if(child.style.fixed)
8034 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
8036 (*&child.normalAnchor).left = x;
8037 (*&child.normalAnchor).top = y;
8038 (*&child.normalAnchor).right.type = none;
8039 (*&child.normalAnchor).bottom.type = none;
8040 (*&child.normalSizeAnchor).isClientW = false;
8041 (*&child.normalSizeAnchor).isClientH = false;
8042 (*&child.normalSizeAnchor).size.w = w;
8043 (*&child.normalSizeAnchor).size.h = h;
8044 child.anchored = false;
8047 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
8049 child.stateAnchor = child.normalAnchor;
8050 child.stateSizeAnchor = child.normalSizeAnchor;
8052 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
8053 child.Position(x,y, w, h, true, true, true, true, false, true);
8058 if((cycle = cycle.next) == document.cycle) break;
8061 firstDocument.Activate();
8066 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
8070 master = this; isModal = true;
8072 void NotifyDestroyed(Window window, DialogResult result)
8074 Window document = (Window)(intptr)result;
8077 if(activeChild.state == maximized)
8078 document.SetState(maximized, false, 0);
8079 else if(document.state == minimized)
8080 document.SetState(normal, false, 0);
8081 document.Activate();
8089 virtual bool OnCreate(void);
8090 virtual void OnDestroy(void);
8091 virtual void OnDestroyed(void);
8092 virtual bool OnClose(bool parentClosing);
8093 virtual bool OnStateChange(WindowState state, Modifiers mods);
8094 virtual bool OnPostCreate(void);
8095 virtual bool OnMoving(int *x, int *y, int w, int h);
8096 virtual bool OnResizing(int *width, int *height);
8097 virtual void OnResize(int width, int height);
8098 virtual void OnPosition(int x, int y, int width, int height);
8099 virtual bool OnLoadGraphics(void);
8100 virtual void OnApplyGraphics(void);
8101 virtual void OnUnloadGraphics(void);
8102 virtual void OnRedraw(Surface surface);
8103 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
8104 virtual void OnActivateClient(Window client, Window previous);
8105 virtual bool OnKeyDown(Key key, unichar ch);
8106 virtual bool OnKeyUp(Key key, unichar ch);
8107 virtual bool OnKeyHit(Key key, unichar ch);
8108 virtual bool OnSysKeyDown(Key key, unichar ch);
8109 virtual bool OnSysKeyUp(Key key, unichar ch);
8110 virtual bool OnSysKeyHit(Key key, unichar ch);
8111 virtual bool OnMouseOver(int x, int y, Modifiers mods);
8112 virtual bool OnMouseLeave(Modifiers mods);
8113 virtual bool OnMouseMove(int x, int y, Modifiers mods);
8114 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
8115 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
8116 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
8117 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
8118 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
8119 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
8120 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
8121 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
8122 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
8123 virtual bool OnMultiTouch(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods);
8124 virtual void OnMouseCaptureLost(void);
8125 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
8126 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
8127 virtual void OnDrawOverChildren(Surface surface);
8128 virtual bool OnFileModified(FileChange fileChange, const char * param);
8129 virtual bool OnSaveFile(const char * fileName);
8131 // Virtual Methods -- Children management (To support Stacker, for lack of built-in auto-layout)
8132 // Note: A 'client' would refer to isActiveClient, rather than
8133 // being confined to the 'client area' (nonClient == false)
8134 virtual void OnChildAddedOrRemoved(Window child, bool removed);
8135 virtual void OnChildVisibilityToggled(Window child, bool visible);
8136 virtual void OnChildResized(Window child, int x, int y, int w, int h);
8138 // Skins Virtual Functions
8139 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
8140 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
8141 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
8146 virtual void ShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
8147 virtual void PreShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
8148 virtual bool IsMouseMoving(int x, int y, int w, int h)
8152 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY)
8156 virtual void UpdateNonClient();
8157 virtual void SetBox(Box box); // This is used in the MySkin skin
8158 virtual bool IsInside(int x, int y)
8160 return box.IsPointInside({x, y});
8162 virtual bool IsOpaque()
8164 return (!style.drawBehind || background.a == 255);
8168 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
8169 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
8170 virtual void Window::NotifySaved(Window window, const char * filePath);
8175 property Window parent
8177 property_category $"Layout"
8180 if(value || guiApp.desktop)
8183 Window oldParent = parent;
8184 Anchor anchor = this.anchor;
8186 if(value && value.IsDescendantOf(this)) return;
8187 if(value && value == this)
8189 if(!value) value = guiApp.desktop;
8191 if(value == oldParent) return;
8193 if(!master || (master == this.parent && master == guiApp.desktop))
8194 property::master = value;
8198 parent.children.Remove(this);
8202 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
8203 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
8204 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
8205 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
8209 last = value.children.last;
8211 if(style.isDocument)
8214 parent.numDocuments--;
8215 documentID = value.GetDocumentID();
8218 if(style.isActiveClient && !style.hidden)
8220 if(parent && parent != guiApp.desktop && !(style.hidden))
8222 if(state == minimized) parent.numIcons--;
8223 parent.numPositions--;
8227 if(!style.stayOnTop)
8228 for(; last && last.style.stayOnTop; last = last.prev);
8230 value.children.Insert(last, this);
8232 // *** NEW HERE: ***
8234 parent.childrenCycle.Delete(cycle);
8236 parent.childrenOrder.Delete(order);
8239 // *** TODO: Added this here to solve crash on setting parent to null before destroying/destructing ***
8240 // Should something else be done?
8241 if(parent && parent.activeChild == this)
8242 parent.activeChild = null;
8243 if(parent && parent.activeClient == this)
8244 parent.activeClient = null;
8250 int x = position.x, y = position.y, w = size.w, h = size.h;
8254 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
8255 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
8257 vpw = value.clientSize.w;
8258 vph = value.clientSize.h;
8264 else if(style.fixed)
8266 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
8267 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
8270 anchor = this.anchor;
8272 if(anchor.left.type == offset) anchor.left.distance = x;
8273 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
8274 if(anchor.top.type == offset) anchor.top.distance = y;
8275 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
8276 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
8277 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
8278 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
8279 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
8280 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
8281 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
8283 if(!anchor.left.type && !anchor.right.type)
8285 anchor.horz.distance = (x + w / 2) - (vpw / 2);
8286 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
8288 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
8289 if(!anchor.top.type && !anchor.bottom.type)
8291 anchor.vert.distance = (y + h / 2) - (vph / 2);
8292 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
8294 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
8297 parent.OnChildAddedOrRemoved(this, false);
8303 parent.childrenCycle.Insert(
8304 // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
8305 //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8307 cycle = OldLink { data = this });
8308 parent.childrenOrder.Insert(
8309 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8310 order = OldLink { data = this });
8313 if(!style.hidden && style.isActiveClient)
8315 positionID = parent.GetPositionID(this);
8316 parent.numPositions++;
8317 if(state == minimized) parent.numIcons--;
8320 // *** FONT INHERITANCE ***
8321 if(!setFont && oldParent)
8322 stopwatching(oldParent, font);
8326 RemoveResource(systemFont);
8329 // TESTING WITH WATCHERS:
8330 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8331 // usedFont = setFont ? setFont : (systemFont);
8335 if(guiApp.currentSkin)
8337 systemFont = guiApp.currentSkin.SystemFont();
8340 usedFont = systemFont;
8341 AddResource(systemFont);
8349 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8358 if(value.rootWindow && value.rootWindow.display && rootWindow && created)
8360 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
8361 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
8364 UnloadGraphics(false);
8367 LoadGraphics(false, false);
8370 if(value.rootWindow != rootWindow)
8371 DisplayModeChanged();
8375 scrolledPos.x = MININT; // Prevent parent update
8377 bool anchored = this.anchored;
8378 property::anchor = anchor;
8379 this.anchored = anchored;
8384 if(guiApp.currentSkin)
8385 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
8387 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8388 Position(x, y, w, h, true, true, true, true, false, true);
8393 // else parent = value;
8395 oldParent.OnChildAddedOrRemoved(this, true);
8398 get { return parent; }
8401 property Window master
8403 property_category $"Behavior"
8406 //if(this == value) return;
8407 if(value && value.IsSlaveOf(this)) return;
8413 OldLink slaveHolder;
8414 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
8415 if(slaveHolder.data == this)
8417 master.slaves.Delete(slaveHolder);
8424 value.slaves.Add(OldLink { data = this });
8429 master.hotKeys.Remove(hotKey);
8430 value.hotKeys.Add(hotKey);
8433 if(master && master.defaultControl == this)
8434 master.defaultControl = null;
8436 if(style.isDefault && !value.defaultControl)
8437 value.defaultControl = this;
8442 get { return master ? master : parent; }
8445 property const char * caption
8447 property_category $"Appearance"
8454 caption = new char[strlen(value)+1];
8456 strcpy(caption, value);
8461 get { return caption; }
8466 property_category $"Behavior"
8475 master.hotKeys.Add(hotKey = HotKeySlot { });
8479 hotKey.window = this;
8484 master.hotKeys.Delete(hotKey);
8489 get { return hotKey ? hotKey.key : 0; }
8492 property Color background
8494 property_category $"Appearance"
8497 background.color = value;
8502 if(this == rootWindow)
8503 guiApp.interfaceDriver.SetRootWindowColor(this);
8506 get { return background.color; }
8509 property Percentage opacity
8511 property_category $"Appearance"
8514 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
8515 drawBehind = (background.a == 255) ? false : true;
8517 get { return background.a / 255.0f; }
8520 property Color foreground
8522 property_category $"Appearance"
8530 get { return foreground; }
8533 property BorderStyle borderStyle
8535 property_category $"Appearance"
8538 if(!((BorderBits)value).fixed)
8540 style.hasClose = false;
8541 style.hasMaximize = false;
8542 style.hasMinimize = false;
8543 nativeDecorations = false;
8545 style.borderBits = value;
8549 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8551 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8552 Position(x, y, w, h, true, true, true, true, false, true);
8553 CreateSystemChildren();
8556 get { return (BorderStyle)style.borderBits; }
8559 property Size minClientSize
8561 property_category $"Layout"
8562 set { minSize = value; }
8563 get { value = minSize; }
8566 property Size maxClientSize
8568 property_category $"Layout"
8569 set { maxSize = value; }
8570 get { value = maxSize; }
8573 property bool hasMaximize
8575 property_category $"Window Style"
8578 style.hasMaximize = value;
8579 if(value) { style.fixed = true; style.contour = true; }
8583 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8585 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8586 Position(x, y, w, h, true, true, true, true, false, true);
8588 CreateSystemChildren();
8591 get { return style.hasMaximize; }
8594 property bool hasMinimize
8596 property_category $"Window Style"
8599 style.hasMinimize = value;
8600 if(value) { style.fixed = true; style.contour = true; }
8604 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8606 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8607 Position(x, y, w, h, true, true, true, true, false, true);
8609 CreateSystemChildren();
8612 get { return style.hasMinimize; }
8615 property bool hasClose
8617 property_category $"Window Style"
8620 style.hasClose = value;
8621 if(value) { style.fixed = true; style.contour = true; }
8625 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8626 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8627 Position(x, y, w, h, true, true, true, true, false, true);
8628 CreateSystemChildren();
8631 get { return style.hasClose; }
8634 property bool nonClient
8636 property_category $"Layout"
8639 style.nonClient = value;
8641 style.stayOnTop = true;
8643 get { return style.nonClient; }
8646 property bool inactive
8648 property_category $"Behavior"
8653 // *** NEW HERE: ***
8657 parent.childrenCycle.Delete(cycle);
8659 parent.childrenOrder.Delete(order);
8666 active = false; // true;
8667 if(parent.activeChild == this)
8668 parent.activeChild = null;
8669 if(parent.activeClient == this)
8670 parent.activeClient = null;
8679 parent.childrenCycle.Insert(
8680 // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
8681 //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8683 cycle = OldLink { data = this });
8685 parent.childrenOrder.Insert(
8686 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8687 order = OldLink { data = this });
8690 style.inactive = value;
8692 get { return style.inactive; }
8695 property bool clickThrough
8697 property_category $"Behavior"
8698 set { style.clickThrough = value; }
8699 get { return style.clickThrough; }
8702 property bool isRemote
8704 property_category $"Behavior"
8705 set { style.isRemote = value; }
8706 get { return style.isRemote; }
8709 property bool noCycle
8711 property_category $"Behavior"
8712 set { style.noCycle = value; }
8713 get { return style.noCycle; }
8716 property bool isModal
8718 property_category $"Behavior"
8719 set { style.modal = value; }
8720 get { return style.modal; }
8723 property bool interim
8725 property_category $"Behavior"
8726 set { style.interim = value; }
8727 get { return style.interim; }
8730 property bool tabCycle
8732 property_category $"Behavior"
8733 set { style.tabCycle = value; }
8734 get { return style.tabCycle; }
8737 property bool isDefault
8739 property_category $"Behavior"
8747 for(sibling = parent.children.first; sibling; sibling = sibling.next)
8748 if(sibling != this && sibling.style.isDefault)
8749 sibling.style.isDefault = false;*/
8750 if(master.defaultControl)
8751 master.defaultControl.style.isDefault = false;
8752 master.defaultControl = this;
8754 else if(master.defaultControl == this)
8755 master.defaultControl = null;
8759 style.isDefault = value;
8761 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8763 get { return style.isDefault; }
8766 property bool drawBehind
8768 property_category $"Window Style"
8769 set { style.drawBehind = value; }
8770 get { return style.drawBehind; }
8773 property bool hasMenuBar
8775 property_category $"Window Style"
8785 if(created && !menuBar)
8792 anchor = Anchor { top = 23, left = 1, right = 1 },
8794 inactive = true, nonClient = true
8799 else if(created && menuBar)
8804 style.hasMenuBar = value;
8806 get { return style.hasMenuBar; }
8809 property bool hasStatusBar
8811 property_category $"Window Style"
8818 statusBar = StatusBar { this };
8826 style.hasStatusBar = value;
8828 get { return style.hasStatusBar; }
8830 property bool stayOnTop
8832 property_category $"Window Style"
8837 if(created && !style.stayOnTop)
8839 if(rootWindow == this)
8840 guiApp.interfaceDriver.OrderRootWindow(this, true);
8841 else if(parent.children.last != this)
8843 parent.children.Move(this, parent.children.last);
8847 style.stayOnTop = true;
8851 if(created && style.stayOnTop)
8853 if(rootWindow == this)
8854 guiApp.interfaceDriver.OrderRootWindow(this, false);
8861 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8862 order && ((Window)order.data).style.stayOnTop;
8863 order = (order == parent.childrenOrder.first) ? null : order.prev);
8864 last = order ? order.data : null;
8868 for(last = parent.children.last;
8869 last && last.style.stayOnTop;
8873 parent.children.Move(this, last);
8877 style.stayOnTop = false;
8880 get { return style.stayOnTop; }
8885 property_category $"Window Style"
8895 if(menuBar && !value)
8902 if(!menuBar && style.hasMenuBar && value)
8906 this, menu = value, isMenuBar = true,
8907 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8908 inactive = true, nonClient = true
8912 UpdateActiveDocument(null);
8915 get { return menu; }
8918 property FontResource font
8920 property_category $"Appearance"
8922 isset { return setFont ? true : false; }
8927 if(value && !setFont) { stopwatching(parent, font); }
8928 else if(!value && setFont)
8934 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8943 RemoveResource(setFont);
8948 RemoveResource(systemFont);
8955 AddResource(setFont);
8958 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8961 systemFont = guiApp.currentSkin.SystemFont();
8963 usedFont = systemFont;
8964 AddResource(systemFont);
8972 get { return usedFont; }
8975 property SizeAnchor sizeAnchor
8977 property_category $"Layout"
8980 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8981 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8982 sizeAnchor.isClientW != sizeAnchor.isClientH;
8989 normalSizeAnchor = sizeAnchor;
8991 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8993 stateAnchor = normalAnchor;
8994 stateSizeAnchor = normalSizeAnchor;
8996 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8997 Position(x,y, w, h, true, true, true, true, false, true);
9004 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
9005 sizeAnchor.isClientW,
9006 sizeAnchor.isClientH
9013 property_category $"Layout"
9016 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
9017 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
9018 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
9024 sizeAnchor.isClientW = false;
9025 sizeAnchor.isClientH = false;
9026 sizeAnchor.size = value;
9028 normalSizeAnchor = sizeAnchor;
9030 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
9032 stateAnchor = normalAnchor;
9033 stateSizeAnchor = normalSizeAnchor;
9035 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9036 Position(x, y, w, h, true, true, true, true, false, true);
9037 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
9040 get { value = size; }
9043 property Size clientSize
9045 property_category $"Layout"
9048 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
9049 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
9050 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
9055 sizeAnchor.isClientW = true;
9056 sizeAnchor.isClientH = true;
9057 sizeAnchor.size = value;
9059 normalSizeAnchor = sizeAnchor;
9061 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9063 stateAnchor = normalAnchor;
9064 stateSizeAnchor = normalSizeAnchor;
9066 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9067 Position(x,y, w, h, true, true, true, true, false, true);
9068 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
9071 get { value = this ? clientSize : { 0, 0 }; }
9074 property Size initSize { get { value = sizeAnchor.size; } };
9076 property Anchor anchor
9078 property_category $"Layout"
9079 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
9085 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
9087 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
9088 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
9090 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
9092 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
9093 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
9097 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
9099 anchor.left.distance = 0;
9100 anchor.horz.type = 0;
9102 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
9104 anchor.top.distance = 0;
9105 anchor.vert.type = 0;
9114 normalAnchor = anchor;
9116 // Break the anchors for moveable/resizable windows
9117 /*if(style.fixed ) //&& value.left.type == cascade)
9119 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
9121 this.anchor = normalAnchor = Anchor { left = x, top = y };
9122 normalSizeAnchor = SizeAnchor { { w, h } };
9125 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9127 stateAnchor = normalAnchor;
9128 stateSizeAnchor = normalSizeAnchor;
9130 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9131 Position(x, y, w, h, true, true, true, true, false, true);
9140 get { value = this ? anchor : Anchor { }; }
9143 property Point position
9145 property_category $"Layout"
9148 if(value == null) return;
9150 anchor.left = value.x;
9151 anchor.top = value.y;
9152 anchor.right.type = none;
9153 anchor.bottom.type = none;
9158 normalAnchor = anchor;
9160 // Break the anchors for moveable/resizable windows
9164 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9166 normalAnchor.left = x;
9167 normalAnchor.top = y;
9168 normalAnchor.right.type = none;
9169 normalAnchor.bottom.type = none;
9170 normalSizeAnchor.size.width = w;
9171 normalSizeAnchor.size.height = h;
9175 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9177 stateAnchor = normalAnchor;
9178 stateSizeAnchor = normalSizeAnchor;
9180 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9181 Position(x,y, w, h, true, true, true, true, false, true);
9185 get { value = position; }
9188 property bool disabled
9190 property_category $"Behavior"
9193 if(this && disabled != value)
9200 get { return (bool)disabled; }
9203 property bool isEnabled
9208 for(parent = this; parent; parent = parent.parent)
9215 property WindowState state
9217 property_category $"Behavior"
9218 set { SetState(value, false, 0); }
9219 get { return this ? state : 0; }
9222 property bool visible
9224 property_category $"Behavior"
9227 if(this && !value && !style.hidden && parent)
9229 bool wasActiveChild = parent.activeChild == this;
9230 Window client = null;
9232 style.hidden = true;
9233 if(style.isActiveClient)
9235 parent.numPositions--;
9236 if(state == minimized) parent.numIcons--;
9241 OldLink prevOrder = null;
9243 if(rootWindow == this)
9244 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
9247 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
9250 box.left -= parent.clientStart.x;
9251 box.top -= parent.clientStart.y;
9252 box.right -= parent.clientStart.x;
9253 box.bottom -= parent.clientStart.y;
9257 if(_isModal && master && master.modalSlave == this)
9258 master.modalSlave = null;
9262 OldLink tmpPrev = order.prev;
9263 client = tmpPrev ? tmpPrev.data : null;
9264 if(client && !client.style.hidden && !client.destroyed && client.created)
9265 prevOrder = tmpPrev;
9268 client = tmpPrev ? tmpPrev.data : null;
9269 if(client == this) { client = null; break; }
9270 if(client && ((client.style.hidden) || client.destroyed || !client.created))
9272 tmpPrev = client.order.prev;
9277 prevOrder = tmpPrev;
9282 // If this window can be an active client, make sure the next window we activate can also be one
9283 if(!style.nonClient && style.isActiveClient)
9285 tmpPrev = prevOrder;
9288 client = tmpPrev ? tmpPrev.data : null;
9289 if(client == this) { client = null; break; }
9290 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
9292 tmpPrev = client.order.prev;
9297 prevOrder = tmpPrev;
9301 if(client && client.style.hidden) client = null;
9305 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
9307 if(order && prevOrder && prevOrder.data != this)
9308 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
9310 ActivateEx(false, false, false, true, null, null);
9312 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
9313 if(parent.activeClient == this)
9315 parent.activeClient = null;
9316 parent.UpdateActiveDocument(null);
9319 else if(parent.activeClient == this)
9321 parent.activeClient = client;
9322 parent.UpdateActiveDocument(this);
9325 // *** Not doing this anymore ***
9328 parent.childrenCycle.Delete(cycle);
9330 parent.childrenOrder.Delete(order);
9335 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9340 else if(this && value && style.hidden)
9342 style.hidden = false;
9345 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9346 if(rootWindow == this)
9347 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
9349 if(_isModal && master)
9350 master.modalSlave = this;
9352 if(style.isActiveClient)
9354 positionID = parent.GetPositionID(this);
9355 parent.numPositions++;
9356 if(state == minimized) parent.numIcons++;
9359 // *** NOT DOING THIS ANYMORE ***
9361 if(!(style.inactive))
9363 if(!(style.noCycle))
9365 cycle = parent.childrenCycle.AddAfter(
9366 (parent.activeChild && parent.activeChild.cycle) ?
9367 parent.activeChild.cycle.prev : null, sizeof(OldLink));
9370 order = parent.childrenOrder.AddAfter(
9371 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
9378 if(true || !parent.activeChild)
9379 ActivateEx(true, false, true, true, null, null);
9381 if(creationActivation == activate && guiApp.desktop.active)
9382 ActivateEx(true, false, true, true, null, null);
9383 else if((creationActivation == activate || creationActivation == flash) && !object)
9386 if(this == rootWindow)
9390 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9394 ConsequentialMouseMove(false);
9400 style.hidden = !value;
9403 get { return (style.hidden || !setVisible) ? false : true; }
9406 property bool isDocument
9408 property_category $"Document"
9409 set { style.isDocument = value; if(value) SetupFileMonitor(); }
9410 get { return style.isDocument; }
9413 property bool mergeMenus
9415 property_category $"Window Style"
9416 set { mergeMenus = value; }
9417 get { return (bool)mergeMenus; }
9420 property bool hasHorzScroll
9422 property_category $"Window Style"
9427 if(!style.hasHorzScroll && created)
9429 CreateSystemChildren();
9430 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9433 else if(style.hasHorzScroll)
9437 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9439 style.hasHorzScroll = value;
9442 get { return style.hasHorzScroll; }
9445 property bool hasVertScroll
9447 property_category $"Window Style"
9452 if(!style.hasVertScroll && created)
9454 style.hasVertScroll = true;
9455 CreateSystemChildren();
9456 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9459 else if(style.hasVertScroll)
9463 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9465 style.hasVertScroll = value;
9467 get { return style.hasVertScroll; }
9470 property bool dontHideScroll
9472 property_category $"Behavior"
9475 scrollFlags.dontHide = value;
9478 //UpdateScrollBars(true, true);
9479 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9483 // UpdateScrollBars(true, true);
9484 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9487 get { return scrollFlags.dontHide; }
9490 property bool dontScrollVert
9492 property_category $"Behavior"
9493 set { style.dontScrollVert = value; }
9494 get { return style.dontScrollVert; }
9496 property bool dontScrollHorz
9498 property_category $"Behavior"
9499 set { style.dontScrollHorz = value; }
9500 get { return style.dontScrollHorz; }
9503 property bool snapVertScroll
9505 property_category $"Behavior"
9508 scrollFlags.snapY = value;
9509 if(sbv) sbv.snap = value;
9511 get { return scrollFlags.snapY; }
9513 property bool snapHorzScroll
9515 property_category $"Behavior"
9518 scrollFlags.snapX = value;
9519 if(sbh) sbh.snap = value;
9521 get { return scrollFlags.snapX; }
9524 property Point scroll
9526 property_category $"Behavior"
9527 set { if(this) SetScrollPosition(value.x, value.y); }
9528 get { value = scroll; }
9531 property bool modifyVirtualArea
9533 property_category $"Behavior"
9534 set { modifyVirtArea = value; }
9535 get { return (bool)modifyVirtArea; }
9538 property bool dontAutoScrollArea
9540 property_category $"Behavior"
9541 // Activating a child control out of view will automatically scroll to make it in view
9542 set { noAutoScrollArea = value; }
9543 get { return (bool)noAutoScrollArea; }
9546 property const char * fileName
9548 property_category $"Document"
9553 if(menu && ((!fileName && value) || (fileName && !value)))
9555 MenuItem item = menu.FindItem(MenuFileSave, 0);
9556 if(item) item.disabled = !modifiedDocument && value;
9561 if(value && value[0])
9562 fileName = CopyString(value);
9564 if(parent && this == parent.activeClient)
9565 parent.UpdateActiveDocument(null);
9569 // if(style.isDocument)
9570 #if !defined(__EMSCRIPTEN__)
9572 fileMonitor.fileName = value;
9575 get { return fileName; }
9580 property_category $"Data"
9585 property bool modifiedDocument
9587 property_category $"Document"
9590 if(style.isDocument || fileName)
9594 MenuItem item = menu.FindItem(MenuFileSave, 0);
9595 if(item) item.disabled = !value && fileName;
9599 if(modifiedDocument != value)
9601 modifiedDocument = value;
9602 if(style.isDocument || fileName)
9606 get { return (bool)modifiedDocument; }
9609 property bool showInTaskBar
9611 property_category $"Window Style"
9614 style.showInTaskBar = value;
9615 #if defined(__WIN32__)
9616 Win32UpdateStyle(this);
9619 get { return style.showInTaskBar; }
9621 property FileDialog saveDialog { set { saveDialog = value; } };
9622 property bool isActiveClient
9624 property_category $"Behavior"
9627 if(parent && style.isActiveClient != value && !style.hidden)
9631 if(state == minimized) parent.numIcons++;
9632 parent.numPositions++;
9636 if(state == minimized) parent.numIcons--;
9637 parent.numPositions--;
9640 style.isActiveClient = value;
9642 get { return style.isActiveClient; }
9645 property Cursor cursor
9647 property_category $"Appearance"
9651 SelectMouseCursor();
9653 get { return cursor; }
9656 //#if !defined(ECERE_VANILLA)
9657 property const char * name
9659 property_category $"Design"
9662 return (this && object) ? object.name : null;
9667 activeDesigner.RenameObject(object, value);
9671 property const char * displayDriver
9673 property_category $"Behavior"
9676 dispDriver = GetDisplayDriver(value);
9677 //DisplayModeChanged();
9681 return dispDriver ? dispDriver.name : null;
9685 // RUNTIME PROPERTIES
9686 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9687 property Size scrollArea
9689 property_category $"Behavior"
9693 SetScrollArea(value.w, value.h, false);
9695 SetScrollArea(0,0, true);
9697 get { value = scrollArea; }
9700 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9705 property_category $"Layout"
9706 set { if(this) is3D = value; }
9707 get { return (bool)is3D; }
9710 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9712 // Will be merged with font later
9713 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9714 property Point clientStart { get { value = clientStart; } };
9715 property Point absPosition { get { value = absPosition; } };
9716 property Anchor normalAnchor { get { value = normalAnchor; } };
9717 property SizeAnchor normalSizeAnchor { get { value = normalSizeAnchor; } };
9718 property bool active { get { return (bool)active; } };
9719 property bool created { get { return (bool)created; } };
9720 property bool destroyed { get { return (bool)destroyed; } };
9721 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9722 property Window firstChild { get { return children.first; } };
9723 property Window lastChild { get { return children.last; } };
9724 property Window activeClient { get { return activeClient; } };
9725 property Window activeChild { get { return activeChild; } };
9726 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9727 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9728 property ScrollBar horzScroll { get { return sbh; } };
9729 property ScrollBar vertScroll { get { return sbv; } };
9730 property StatusBar statusBar { get { return statusBar; } };
9731 property Window rootWindow { get { return rootWindow; } };
9732 property bool closing { get { return (bool)closing; } set { closing = value; } };
9733 property int documentID { get { return documentID; } };
9734 property Window previous { get { return prev; } }
9735 property Window next { get { return next; } }
9736 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9737 property PopupMenu menuBar { get { return menuBar; } }
9738 property ScrollBar sbv { get { return sbv; } }
9739 property ScrollBar sbh { get { return sbh; } }
9740 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9741 property void * systemHandle { get { return windowHandle; } }
9742 property Button minimizeButton { get { return sysButtons[0]; } };
9743 property Button maximizeButton { get { return sysButtons[1]; } };
9744 property Button closeButton { get { return sysButtons[2]; } };
9745 property BitmapResource icon
9747 get { return icon; }
9751 if(icon) incref icon;
9753 guiApp.interfaceDriver.SetIcon(this, value);
9756 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9757 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; if(value) nativeDecorations = false; /* Native Decorations are not supported with alphaBlend */ } };
9758 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9759 property GLCapabilities glCapabilities
9761 get { return glCapabilities; }
9764 bool reload = display != null &&
9765 (glCapabilities.nonPow2Textures != value.nonPow2Textures ||
9766 glCapabilities.intAndDouble != value.intAndDouble ||
9767 glCapabilities.vertexBuffer != value.vertexBuffer ||
9768 glCapabilities.compatible != value.compatible ||
9769 glCapabilities.legacyFormats != value.legacyFormats ||
9770 glCapabilities.debug != value.debug ||
9771 glCapabilities.vertexPointer != value.vertexPointer ||
9772 glCapabilities.quads != value.quads);
9773 guiApp.modeSwitching = true;
9775 UnloadGraphics(false);
9777 glCapabilities = value;
9782 LoadGraphics(false, false);
9785 display.glCapabilities = value;
9786 guiApp.modeSwitching = false;
9789 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9790 property bool nativeDecorations
9792 get { return (bool)nativeDecorations; }
9793 set { nativeDecorations = value; }
9794 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
9797 //return (nativeDecorations && (rootWindow == this || (formDesigner && activeDesigner && ((FormDesigner)activeDesigner.classDesigner).form && parent == ((FormDesigner)activeDesigner.classDesigner).form.parent))) != style.fixed;
9798 bool result = false;
9799 if(nativeDecorations)
9801 if(rootWindow == this)
9805 if(formDesigner && activeDesigner)
9807 FormDesigner cd = (FormDesigner)activeDesigner.classDesigner;
9808 Window form = cd ? cd.form : null;
9809 if(form && parent == form.parent)
9814 return result != style.fixed;
9818 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9820 property const char * text
9822 property_category $"Deprecated"
9824 set { property::caption = value; }
9825 get { return property::caption; }
9831 WindowBits style; // Window Style
9832 char * caption; // Name / Caption
9833 Window parent; // Parent window
9834 OldList children; // List of children in Z order
9835 Window activeChild; // Child window having focus
9836 Window activeClient;
9837 Window previousActive; // Child active prior to activating the default child
9838 Window master; // Window owning and receiving notifications concerning this window
9839 OldList slaves; // List of windows belonging to this window
9840 Display display; // Display this window is drawn into
9842 Point position; // Position in parent window client area
9843 Point absPosition; // Absolute position
9844 Point clientStart; // Client area position from (0,0) in this window
9846 Size clientSize; // Client area size
9847 Size scrollArea; // Virtual Scroll area size
9848 Size reqScrollArea; // Requested virtual area size
9849 Point scroll; // Virtual area scrolling position
9850 ScrollBar sbh, sbv; // Scrollbar window handles
9851 Cursor cursor; // Mouse cursor used for this window
9854 StatusBar statusBar;
9855 Button sysButtons[3];
9857 Box clientArea; // Client Area box clipped to parent
9859 HotKeySlot hotKey; // HotKey for this window
9863 ScrollFlags scrollFlags;// Window Scrollbar Flags
9864 int64 id; // Control ID
9866 ColorAlpha background; // Background color used to draw the window area
9868 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9869 OldList childrenCycle; // Cycling order
9870 OldLink cycle; // Element of parent's cycling order
9871 OldList childrenOrder; // Circular Z-Order
9872 OldLink order; // Element of parent's circular Z-Order
9873 Window modalSlave; // Slave window blocking this window's interaction
9875 Window rootWindow; // Topmost system managed window
9876 void * windowHandle; // System window handle
9878 DialogResult returnCode;// Return code for modal windows
9880 Point sbStep; // Scrollbar line scrolling steps
9883 SizeAnchor stateSizeAnchor;
9885 Anchor normalAnchor;
9886 SizeAnchor normalSizeAnchor;
9888 Size skinMinSize; // Minimal window size based on style
9889 Point scrolledPos; // Scrolled position
9890 Box box; // Window box clipped to parent
9891 Box * against; // What to clip the box to
9893 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9894 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9895 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9896 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9897 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9898 Point scrolledArea; // Distance to scroll area by
9899 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9901 OldList hotKeys; // List of the hotkeys of all children
9902 Window defaultControl; // Default child control
9906 ColorAlpha * palette; // Color palette used for this window
9908 int caretSize; // Size of caret, non zero if a caret is present
9909 Point caretPos; // Caret position
9911 void * systemParent; // Parent System Window for embedded windows
9917 #if !defined(__EMSCRIPTEN__)
9920 WindowState lastState;
9922 #if !defined(__EMSCRIPTEN__)
9923 FileMonitor fileMonitor;
9926 FontResource setFont, systemFont;
9927 FontResource usedFont;
9928 FontResource captionFont;
9930 FileDialog saveDialog;
9932 SizeAnchor sizeAnchor;
9934 // FormDesigner data
9937 Extent * tempExtents; //[4];
9938 BitmapResource icon;
9940 CreationActivationOption creationActivation;
9941 GLCapabilities glCapabilities;
9942 glCapabilities = { true, true, true, true, true, true, true, true, true /*false*/, true, true, true, true, true, true, true };
9945 bool active:1; // true if window and ancestors are active
9946 bool acquiredInput:1; // true if the window is processing state based input
9947 bool modifiedDocument:1;
9948 bool disabled:1; // true if window cannot interact
9949 bool isForegroundWindow:1;// true while a root window is being activated
9950 bool visible:1; // Visibility flag
9951 bool destroyed:1; // true if window is being destroyed
9952 bool anchored:1; // true if this window is repositioned when the parent resizes
9953 bool dirty:1; // Flag set to true if any descendant must be redrawn
9959 bool modifyVirtArea:1;
9960 bool noAutoScrollArea:1;
9963 bool setVisible:1; // FOR FORM DESIGNER
9969 bool useSharedMemory:1;
9972 bool nativeDecorations:1;
9973 bool manageDisplay:1;
9974 bool formDesigner:1; // True if we this is running in the form editor
9975 bool requireRemaximize:1;
9976 bool noConsequential:1;
9979 // Checks used internally for them not to take effect in FormDesigner
9980 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9981 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9983 WindowController controller;
9985 public property WindowController controller
9987 get { return controller; }
9991 controller.setWindow(null);
9997 controller.setWindow(this);
10002 public property bool noConsequential
10004 set { noConsequential = value; }
10005 get { return noConsequential; }
10009 public class CommonControl : Window
10011 // creationActivation = doNothing;
10014 public property const String toolTip
10016 property_category $"Appearance"
10019 if(created) CommonControl::OnDestroy();
10021 toolTip = value ? ToolTip { tip = value; } : null;
10023 if(created) CommonControl::OnCreate();
10025 get { return toolTip ? toolTip.tip : null; }
10031 // (Very) Ugly work around for the fact that the parent watcher
10032 // won't fire when it's already been disconnected...
10033 eInstance_FireSelfWatchers(toolTip,
10034 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
10040 toolTip.parent = this;
10049 public class Percentage : float
10051 const char * OnGetString(char * string, float * fieldData, bool * needClass)
10055 sprintf(string, "%.2f", this);
10056 c = strlen(string)-1;
10057 for( ; c >= 0; c--)
10059 if(string[c] != '0')
10060 last = Max(last, c);
10061 if(string[c] == '.')
10066 string[last+1] = 0;
10074 public void ApplySkin(Class c, const char * name, void ** vTbl)
10076 char className[1024];
10081 subclass(Window) wc = (subclass(Window))c;
10082 subclass(Window) base = (subclass(Window))c.base;
10084 sprintf(className, "%sSkin_%s", name, c.name);
10085 wc.pureVTbl = c._vTbl;
10086 c._vTbl = new void *[c.vTblSize];
10087 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
10088 sc = eSystem_FindClass(c.module.application, className);
10092 for(m = 0; m < c.base.vTblSize; m++)
10094 if(c._vTbl[m] == base.pureVTbl[m])
10095 c._vTbl[m] = vTbl[m];
10100 for(m = 0; m < c.vTblSize; m++)
10102 if(sc._vTbl[m] != wc.pureVTbl[m])
10103 c._vTbl[m] = sc._vTbl[m];
10107 for(d = c.derivatives.first; d; d = d.next)
10109 ApplySkin(d.data, name, c._vTbl);
10113 public void UnapplySkin(Class c)
10115 subclass(Window) wc = (subclass(Window))c;
10118 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
10121 c._vTbl = wc.pureVTbl;
10122 wc.pureVTbl = null;
10125 for(d = c.derivatives.first; d; d = d.next)
10127 UnapplySkin(d.data);
10131 void CheckFontIntegrity(Window window)
10136 if(window.usedFont && window.usedFont.font == 0xecececec)
10138 FontResource uf = window.usedFont;
10139 char * className = window._class.name;
10140 char * text = window.text;
10143 for(c = window.firstChild; c; c = c.next)
10144 CheckFontIntegrity(c);
10148 public class ControllableWindow : Window
10150 /*WindowController controller;
10151 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
10152 ~ControllableWindow() { delete controller; }*/
10155 class WindowControllerInterface : ControllableWindow
10157 bool OnKeyDown(Key key, unichar ch)
10159 bool result = controller.OnKeyDown ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyDown)((Window)controller.controlled, controller, key, ch) : true;
10162 bool (* onKeyDown)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown];
10164 result = onKeyDown(controller.window, key, ch);
10169 bool OnKeyUp(Key key, unichar ch)
10171 bool result = controller.OnKeyUp ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyUp)((Window)controller.controlled, controller, key, ch) : true;
10174 bool (* onKeyUp)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp];
10176 result = onKeyUp(controller.window, key, ch);
10181 bool OnKeyHit(Key key, unichar ch)
10183 bool result = controller.OnKeyHit ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyHit)((Window)controller.controlled, controller, key, ch) : true;
10186 bool (* onKeyHit)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit];
10188 result = onKeyHit(controller.window, key, ch);
10193 bool OnMouseMove(int x, int y, Modifiers mods)
10195 bool result = controller.OnMouseMove ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMouseMove)((Window)controller.controlled, controller, x, y, mods) : true;
10198 bool(* onMouseMove)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove];
10200 result = onMouseMove(controller.window, x, y, mods);
10205 bool OnLeftButtonDown(int x, int y, Modifiers mods)
10207 bool result = controller.OnLeftButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10210 bool(* onLeftButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown];
10211 if(onLeftButtonDown)
10212 result = onLeftButtonDown(controller.window, x, y, mods);
10217 bool OnLeftButtonUp(int x, int y, Modifiers mods)
10219 bool result = controller.OnLeftButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10222 bool(* onLeftButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp];
10224 result = onLeftButtonUp(controller.window, x, y, mods);
10229 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
10231 bool result = controller.OnLeftDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10234 bool(* onLeftDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick];
10235 if(onLeftDoubleClick)
10236 result = onLeftDoubleClick(controller.window, x, y, mods);
10241 bool OnRightButtonDown(int x, int y, Modifiers mods)
10243 bool result = controller.OnRightButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10246 bool(* onRightButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown];
10247 if(onRightButtonDown)
10248 result = onRightButtonDown(controller.window, x, y, mods);
10253 bool OnRightButtonUp(int x, int y, Modifiers mods)
10255 bool result = controller.OnRightButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10258 bool(* onRightButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp];
10259 if(onRightButtonUp)
10260 result = onRightButtonUp(controller.window, x, y, mods);
10265 bool OnRightDoubleClick(int x, int y, Modifiers mods)
10267 bool result = controller.OnRightDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10270 bool(* onRightDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick];
10271 if(onRightDoubleClick)
10272 result = onRightDoubleClick(controller.window, x, y, mods);
10277 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
10279 bool result = controller.OnMiddleButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10282 bool(* onMiddleButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown];
10283 if(onMiddleButtonDown)
10284 result = onMiddleButtonDown(controller.window, x, y, mods);
10289 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
10291 bool result = controller.OnMiddleButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10294 bool(* onMiddleButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp];
10295 if(onMiddleButtonUp)
10296 result = onMiddleButtonUp(controller.window, x, y, mods);
10301 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
10303 bool result = controller.OnMiddleDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10306 bool(* onMiddleDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick];
10307 if(onMiddleDoubleClick)
10308 onMiddleDoubleClick(controller.window, x, y, mods);
10313 bool OnMultiTouch(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods)
10315 bool result = controller.OnMultiTouch ? ((bool(*)(Window, WindowController, TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers))(void *)controller.OnMultiTouch)((Window)controller.controlled, controller, event, infos, mods) : true;
10318 bool(* onMultiTouch)(Window, TouchPointerEvent, Array<TouchPointerInfo>, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMultiTouch];
10320 onMultiTouch(controller.window, event, infos, mods);
10325 void OnResize(int width, int height)
10327 if(controller.OnResize)
10328 ((void(*)(Window, WindowController, int, int))(void *)controller.OnResize)((Window)controller.controlled, controller, width, height);
10330 void(* onResize)(Window, int, int) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize];
10332 onResize(controller.window, width, height);
10336 void OnRedraw(Surface surface)
10338 if(controller.OnRedraw)
10339 ((void(*)(Window, WindowController, Surface))(void *)controller.OnRedraw)((Window)controller.controlled, controller, surface);
10341 void(* onRedraw)(Window, Surface) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw];
10343 onRedraw(controller.window, surface);
10349 bool result = controller.OnCreate ? ((bool(*)(Window, WindowController))(void *)controller.OnCreate)((Window)controller.controlled, controller) : true;
10352 bool(* onCreate)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate];
10354 result = onCreate(controller.window);
10359 bool OnLoadGraphics()
10361 bool result = controller.OnLoadGraphics ? ((bool(*)(Window, WindowController))(void *)controller.OnLoadGraphics)((Window)controller.controlled, controller) : true;
10364 bool(* onLoadGraphics)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLoadGraphics];
10366 result = onLoadGraphics(controller.window);
10371 void OnUnloadGraphics()
10373 if(controller.OnUnloadGraphics)
10374 ((void(*)(Window, WindowController))(void *)controller.OnUnloadGraphics)((Window)controller.controlled, controller);
10376 void(* onUnloadGraphics)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnUnloadGraphics];
10377 if(onUnloadGraphics)
10378 onUnloadGraphics(controller.window);
10383 public class WindowController<class V>
10385 void setWindow(Window value)
10387 uint size = class(Window).vTblSize;
10391 windowVTbl = new void *[size];
10392 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
10393 if(value._vTbl == value._class._vTbl)
10395 value._vTbl = new void *[value._class.vTblSize];
10396 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
10400 for(c = 0; c < size; c++)
10402 void * function = class(WindowControllerInterface)._vTbl[c];
10403 if(function && function != DefaultFunction)
10404 value._vTbl[c] = function;
10406 value._vTbl[c] = windowVTbl[c];
10412 memcpy(window._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
10418 property Window window
10420 get { return window; }
10422 property V controlled
10424 set { controlled = value; }
10425 get { return controlled; }
10427 // TODO: Add OnStateChange so we can implement SavedConfigWindow as a WindowController instead
10428 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
10429 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
10430 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
10431 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
10432 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
10433 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
10434 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10435 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
10436 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
10437 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10438 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
10439 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
10440 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10441 virtual bool V::OnMultiTouch(WindowController controller, TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods);
10442 virtual void V::OnResize(WindowController controller, int width, int height);
10443 virtual void V::OnRedraw(WindowController controller, Surface surface);
10444 virtual bool V::OnCreate(WindowController controller);
10445 virtual bool V::OnLoadGraphics(WindowController controller);
10446 virtual void V::OnUnloadGraphics(WindowController controller);
10449 public int (** windowVTbl)();
10453 ~WindowController()