7 import "GuiApplication"
28 #if defined(__WIN32__)
29 import "Win32Interface"
32 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
36 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
45 // Had to define this here for native decorations support, because the menu bar is part of total decoration's size, but not part of the system decorations
47 define skinMenuHeight = 40;
48 define statusBarHeight = 30;
50 define skinMenuHeight = 25;
51 define statusBarHeight = 18;
54 default extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
56 public enum DialogResult : int64 { cancel, yes, no, ok };
58 public class MouseButtons
61 bool left:1, right:1, middle:1;
64 public struct SizeAnchor
67 bool isClientW, isClientH;
72 #define SNAPDOWN(x, d) \
75 if(x < 0) x -= ((d) - Abs(x) % (d)); else x -= x % (d); \
78 #define SNAPUP(x, d) \
81 if(x > 0) x += ((d) - Abs(x) % (d)); else x += x % (d); \
84 /*static */define MAX_DIRTY_BACK = 10;
86 /////////////////////////////////////////////////////////////////////////////
87 ////////// EXTENT MANIPULATION //////////////////////////////////////////////
88 /////////////////////////////////////////////////////////////////////////////
90 #define ACCESS_ITEM(l, id) \
93 #define FASTLIST_LOOP(l, v) \
94 for(v = (BoxItem)l.first; v; v = (BoxItem)v.next)
96 #define FASTLIST_LOOPN(l, v, n) \
97 for(v = (BoxItem)l.first, n = (BoxItem)(v ? v.next : null); v; v = (BoxItem)next, n = (BoxItem)(v ? v.next : null))
100 #define ACCESS_ITEM(l, id) \
101 ((FastItem)(((id) == -1) ? null : (((byte *)((l).items)) + (id) * (l).itemSize)))
103 #define FASTLIST_LOOP(l, v) \
104 for(v = (void *)ACCESS_ITEM((l), (l).first); v; v = (void *)ACCESS_ITEM((l), v.next))
106 #define FASTLIST_LOOPN(l, v, n) \
107 for( v = (void *)ACCESS_ITEM((l), (l).first), \
108 n = v ? ((void *)ACCESS_ITEM((l), v.next)): null; \
109 v; v = n, n = n ? (void *)ACCESS_ITEM((l), n.next) : null)
112 private class FastItem : struct
117 private struct FastList
122 int count, size, itemSize;
129 first = last = free = -1;
137 // FASTLIST_LOOPN(this, item, next) { Delete(item); };
140 FastItem Add(uint itemSize)
143 if(free == -1 || !size)
150 newSize = (size + (size >> 1));
151 items = (FastItem)renew items byte[newSize * itemSize];
156 this.itemSize = itemSize;
157 items = (FastItem)new byte[newSize * itemSize];
160 for(c = size; c<newSize-1; c++)
162 ACCESS_ITEM(this, c).prev = -1;
163 ACCESS_ITEM(this, c).next = c+1;
165 ACCESS_ITEM(this, c).prev = -1;
166 ACCESS_ITEM(this, c).next = -1;
170 item = ACCESS_ITEM(this, free);
173 ACCESS_ITEM(this, item.prev).next = free;
183 void Delete(FastItem item)
186 ACCESS_ITEM(this, item.prev).next = item.next;
188 ACCESS_ITEM(this, item.next).prev = item.prev;
190 if(ACCESS_ITEM(this, first) == item)
192 if(ACCESS_ITEM(this, last) == item)
197 free = ((byte *)item - (byte *)items) / itemSize;
205 free = first = last = -1;
209 private class BoxItem : Item //FastItem
214 public /*private */struct Extent : OldList //FastList
223 //BoxItem extentBox = (BoxItem)Add(sizeof(class BoxItem));
224 Add(BoxItem { box = box });
227 void Copy(Extent source)
233 //FASTLIST_LOOP(source, extentBox)
234 for(extentBox = (BoxItem)source.first; extentBox; extentBox = (BoxItem)extentBox.next)
235 AddBox(extentBox.box);
238 void IntersectBox(Box box)
240 // Clip all boxes of extent against inside of the new box
241 BoxItem extentBox, next;
243 //FASTLIST_LOOPN(this, extentBox, next) // Macros still mess up the parser!
244 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
246 next = (BoxItem)extentBox.next;
247 if(box.left > extentBox.box.left) extentBox.box.left = box.left;
248 if(box.top > extentBox.box.top) extentBox.box.top = box.top;
249 if(box.right < extentBox.box.right) extentBox.box.right = box.right;
250 if(box.bottom < extentBox.box.bottom) extentBox.box.bottom = box.bottom;
251 if(extentBox.box.right < extentBox.box.left || extentBox.box.bottom < extentBox.box.top)
256 void ExcludeBox(Box box, Extent temp)
263 for(extentBox = (BoxItem)temp.first; extentBox; extentBox = (BoxItem)extentBox.next)
265 if(extentBox.box.left < box.right && extentBox.box.right > box.left &&
266 extentBox.box.top < box.bottom && extentBox.box.bottom > box.top)
269 if(extentBox.box.top < box.top && extentBox.box.bottom >= box.top)
273 extentBox.box.left, extentBox.box.top,
274 extentBox.box.right, Min(extentBox.box.bottom, box.top -1)
280 if(extentBox.box.bottom > box.bottom && extentBox.box.top <= box.bottom)
284 extentBox.box.left, Max(extentBox.box.top,box.bottom +1),
285 extentBox.box.right, extentBox.box.bottom
291 if(extentBox.box.bottom >= box.top && extentBox.box.top <= box.bottom)
294 if(extentBox.box.left < box.left && extentBox.box.right >= box.left)
298 extentBox.box.left, Max(extentBox.box.top, box.top),
299 Min(extentBox.box.right, box.left-1), Min(extentBox.box.bottom, box.bottom)
305 if(extentBox.box.right > box.right && extentBox.box.left <= box.right)
309 Max(extentBox.box.left, box.right+1), Max(extentBox.box.top, box.top),
310 extentBox.box.right, Min(extentBox.box.bottom, box.bottom)
318 AddBox(extentBox.box);
324 void UnionBox(Box box, Extent temp)
326 BoxItem extentBox, next;
328 // First pass: check if this box is not already covered by one of the extent's box
329 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
331 if(extentBox.box.left <= box.left && extentBox.box.right >= box.right &&
332 extentBox.box.top <= box.top && extentBox.box.bottom >= box.bottom)
339 // Second pass: only keep boxes not completely covered in the new box
340 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
342 next = (BoxItem)extentBox.next;
343 if(extentBox.box.left >= box.left && extentBox.box.right <= box.right &&
344 extentBox.box.top >= box.top && extentBox.box.bottom <= box.bottom)
348 // Add the exclusion to the extent
349 ExcludeBox(box, temp);
352 if(box.bottom >= box.top && box.right >= box.left)
354 // Optimization: if the resulting boxes touch, add them smarter
355 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
357 if(box.top == extentBox.box.top && box.bottom == extentBox.box.bottom)
359 if(Abs(box.right - extentBox.box.left) <= 1)
361 extentBox.box.left = box.left;
364 else if(Abs(box.left - extentBox.box.right) <= 1)
366 extentBox.box.right = box.right;
370 else if(box.left == extentBox.box.left && box.right == extentBox.box.right)
372 if(Abs(box.bottom - extentBox.box.top) <= 1)
374 extentBox.box.top = box.top;
377 else if(Abs(box.top - extentBox.box.bottom) <= 1)
379 extentBox.box.bottom = box.bottom;
391 void Union(Extent b, Extent temp)
395 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
396 UnionBox(extentBox.box, temp);
399 void Intersection(Extent b, Extent temp, Extent temp2, Extent temp3)
406 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
409 temp2.IntersectBox(extentBox.box);
416 void Exclusion(Extent b, Extent temp)
419 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
420 ExcludeBox(extentBox.box, temp);
423 void Offset(int x, int y)
426 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
428 extentBox.box.left += x;
429 extentBox.box.top += y;
430 extentBox.box.right += x;
431 extentBox.box.bottom += y;
436 private define MINIMIZED_WIDTH = 160;
437 private define CASCADE_SPACE = 16;
439 // namespace Windows;
441 private class ScrollFlags
443 bool snapX:1, snapY:1, dontHide:1;
446 public class BorderBits { public: bool contour:1, fixed:1, sizable:1, deep:1, bevel:1, thin:1; };
448 class WindowBits : BorderBits
450 BorderBits borderBits:6:0;
451 bool hidden:1, isActiveClient:1, hasHorzScroll:1, hasVertScroll:1, stayOnTop:1, modal:1, isDefault:1, inactive:1, isRemote:1, drawBehind:1;
452 bool interim:1, tabCycle:1, noCycle:1, dontScrollHorz:1, dontScrollVert:1, hasMaximize:1, hasMinimize:1, hasClose:1;
453 bool embedded:1, hasMenuBar:1, isDocument:1, showInTaskBar:1, hasStatusBar:1, nonClient:1, clickThrough:1;
456 public enum BorderStyle : BorderBits
459 contour = BorderBits { contour = true },
460 fixed = BorderBits { fixed = true } | contour,
461 sizable = BorderBits { sizable = true } | fixed,
462 thin = BorderBits { fixed = true, thin = true } | contour,
463 sizableThin = BorderBits { sizable = true } | thin,
464 deep = BorderBits { deep = true },
465 bevel = BorderBits { bevel = true },
466 sizableDeep = sizable|deep,
467 sizableBevel = sizable|bevel,
468 fixedDeep = fixed|deep,
469 fixedBevel = fixed|bevel,
470 deepContour = deep|contour
473 public enum CreationActivationOption
475 activate, flash, doNothing
478 public enum WindowState { normal, minimized, maximized };
480 private class ResPtr : struct
487 private class HotKeySlot : struct
489 HotKeySlot prev, next;
494 public struct TouchPointerInfo
498 float size, pressure;
501 public enum TouchPointerEvent { move, up, down, pointerUp, pointerDown };
506 class_data const char * icon;
508 class_default_property caption;
509 // class_initialize GuiApplication::Initialize;
510 class_designer FormDesigner;
511 class_property const char * icon
513 set { class_data(icon) = value; }
514 get { return class_data(icon); }
519 bool switchMode = true;
520 #if defined(__ANDROID__)
525 guiApp.Initialize(switchMode);
527 if(guiApp && guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
529 if(_vTbl == ((subclass(Window))_class).pureVTbl)
531 _vTbl = _class._vTbl;
533 else if(_vTbl != _class._vTbl)
536 for(m = 0; m < _class.vTblSize; m++)
538 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
539 _vTbl[m] = _class._vTbl[m];
544 //tempExtents[0] = { /*first = -1, last = -1, free = -1*/ };
545 //tempExtents[1] = { /*first = -1, last = -1, free = -1*/ };
546 //tempExtents[2] = { /*first = -1, last = -1, free = -1*/ };
547 //tempExtents[3] = { /*first = -1, last = -1, free = -1*/ };
551 // caption = CopyString(class.name);
553 children.offset = (byte*)&prev - (byte*)this;
554 childrenOrder.circ = true;
555 childrenCycle.circ = true;
557 maxSize = Size { MAXINT, MAXINT };
561 //style.isActiveClient = true;
564 modifyVirtArea = true;
565 manageDisplay = true;
566 nativeDecorations = true;
568 // scrollFlags = ScrollFlags { snapX = true, snapY = true };
569 sbStep.x = sbStep.y = 8;
571 if(guiApp) // dynamic_cast<GuiApplication>(thisModule)
573 cursor = guiApp.GetCursor(arrow);
574 property::parent = guiApp.desktop;
584 #if !defined(__EMSCRIPTEN__)
587 int i, lockCount = guiApp.lockMutex.lockCount;
588 for(i = 0; i < lockCount; i++)
589 guiApp.lockMutex.Release();
591 for(i = 0; i < lockCount; i++)
592 guiApp.lockMutex.Wait();
598 stopwatching(parent, font);
599 if(parent.activeChild == this)
600 parent.activeChild = null;
601 if(parent.activeClient == this)
602 parent.activeClient = null;
607 // Prevent destructor from being called again...
613 /////////////////////////////////
616 OldLink slave = master.slaves.FindLink(this);
617 master.slaves.Delete(slave);
624 parent.childrenCycle.Remove(cycle);
626 parent.childrenOrder.Remove(order);
627 parent.children.Remove(this);
632 /////////////////////////////////
634 while((ptr = resources.first))
637 resources.Delete(ptr);
644 for(child = children.first; child; child = child.next)
646 // child.stopwatching(this, font);
648 eInstance_StopWatching(this, __ecereProp___ecereNameSpace__ecere__gui__Window_font, child);
649 // Don't want property here
650 *&child.parent = null;
653 while((slave = slaves.first))
655 // Don't want property here
656 *&((Window)slave.data).master = null;
657 slaves.Delete(slave);
660 // Because we do a decref in DestroyEx...
668 // Why was this commented?
669 //if(this != guiApp.desktop)
679 #if !defined(__EMSCRIPTEN__)
684 if(((subclass(Window))_class).pureVTbl)
686 if(_vTbl == _class._vTbl)
688 _vTbl = ((subclass(Window))_class).pureVTbl;
693 for(m = 0; m < _class.vTblSize; m++)
695 if(_vTbl[m] == _class._vTbl[m])
696 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
700 if(_vTbl == ((subclass(Window))_class).pureVTbl || _vTbl == _class._vTbl)
703 dirtyArea.Free(null);
704 renderArea.Free(null);
705 overRenderArea.Free(null);
706 clipExtent.Free(null);
707 scrollExtent.Free(null);
708 dirtyBack.Free(null);
712 tempExtents[0].Free(null);
713 tempExtents[1].Free(null);
714 tempExtents[2].Free(null);
715 tempExtents[3].Free(null);
722 //#if !defined(ECERE_VANILLA)
723 const char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
725 if(this == activeDesigner)
729 const char * name = property::name;
730 return name ? name : "";
735 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
736 bool OnGetDataFromString(const char * string)
738 FormDesigner designer = (FormDesigner)activeDesigner.classDesigner;
741 if(!strcmp(string, "this") || !strcmp(string, designer.form.name))
742 this = designer.form;
743 else if(!strcmpi(string, "(Desktop)"))
744 this = activeDesigner;
746 return activeDesigner.FindObject(&this, string);
752 // --- Window updates system ---
754 // Setup a bitmap for Redrawing on client area of Window
755 Surface Redraw(Box box)
757 Surface surface = null;
759 Box clientArea = this.clientArea;
763 mox.left -= clientStart.x;
764 mox.top -= clientStart.y;
765 mox.right -= clientStart.x;
766 mox.bottom -= clientStart.y;
768 mox.Clip(clientArea);
769 // mox.ClipOffset(against, scrolledPos.x, scrolledPos.y);
771 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && mox.right >= mox.left && mox.bottom >= mox.top)
773 int x = absPosition.x + clientStart.x;
774 int y = absPosition.y + clientStart.y;
775 if(rootWindow.nativeDecorations && rootWindow.windowHandle && !is3D)
777 x -= rootWindow.clientStart.x;
778 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
780 if(!guiApp.fullScreenMode || is3D)
782 x -= rootWindow.absPosition.x;
783 y -= rootWindow.absPosition.y;
787 int dx = rootWindow.parent.parent.clientStart.x;
788 int dy = rootWindow.parent.parent.clientStart.y;
789 if(!rootWindow.parent.nativeDecorations)
791 dx += rootWindow.parent.clientStart.x;
792 dy += rootWindow.parent.clientStart.y;
806 surface = display.GetSurface(x, y, mox);
809 surface.width = clientSize.w;
810 surface.height = clientSize.h;
816 // Setup a bitmap for Redrawing on full Window
817 Surface RedrawFull(Box box)
819 Surface surface = null;
827 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && box.right >= box.left && box.bottom >= box.top)
829 int x = absPosition.x;
830 int y = absPosition.y;
831 if(rootWindow.nativeDecorations && rootWindow.windowHandle && !is3D)
833 x -= rootWindow.clientStart.x;
834 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
836 #if !defined(__EMSCRIPTEN__)
837 if(!guiApp.fullScreenMode || is3D)
840 x -= rootWindow.absPosition.x;
841 y -= rootWindow.absPosition.y;
844 int dx = rootWindow.parent.parent.clientStart.x;
845 int dy = rootWindow.parent.parent.clientStart.y;
846 if(!rootWindow.parent.nativeDecorations)
848 dx += rootWindow.parent.clientStart.x;
849 dy += rootWindow.parent.clientStart.y;
863 surface = display.GetSurface(x, y, mox);
866 surface.width = size.w;
867 surface.height = size.h;
873 void FigureCaption(char * caption)
875 Window activeClient = null;
879 strcpy(caption, this.caption);
880 if(style.isDocument || fileName)
882 if(caption[0]) strcat(caption, " - ");
884 strcat(caption, fileName);
888 sprintf(title, "Untitled %d", documentID);
889 strcat(caption, title);
892 strcat(caption, " *");
897 for(activeClient = this.activeClient; activeClient && !((BorderBits)activeClient.borderStyle).fixed; activeClient = activeClient.activeClient);
899 if(activeClient && activeClient.state == maximized)
901 if(activeClient.caption)
903 if(caption[0]) strcat(caption, " - ");
904 strcat(caption, activeClient.caption);
906 if(activeClient.style.isDocument || activeClient.fileName)
908 if(caption[0]) strcat(caption, " - ");
909 strcat(caption, "[");
910 if(activeClient.fileName)
911 strcat(caption, activeClient.fileName);
915 sprintf(title, "Untitled %d", activeClient.documentID);
916 strcat(caption, title);
918 if(activeClient.modifiedDocument)
919 strcat(caption, " *");
920 strcat(caption, "]");
925 // Code for returning dirty from ScrollDisplay:
927 for(d = 0; d<scrollExtent.count; d++)
929 Box * box = &scrollExtent.boxes[d];
935 Min(box.right, box.left-scroll.x),box.bottom
937 dirtyArea.UnionBox(update);
943 Max(box.left, box.right-scroll.x), box.top,
944 box.right, box.bottom
946 dirtyArea.UnionBox(update);
954 box.right, Min(box.bottom, box.top-scroll.y),
956 dirtyArea.UnionBox(update);
962 box.left, Max(box.top, box.bottom-scroll.y),
963 box.right, box.bottom
965 dirtyArea.UnionBox(update);
970 void UpdateDecorations(void)
972 // TODO: *** TEMPORARY HACK ***
979 Update({ -clientStart.x, -clientStart.y, -clientStart.x + size.w-1, 0 });
981 Update({ -clientStart.x, clientSize.h, -clientStart.x + size.w-1, -clientStart.y + size.h-1 });
983 Update({ -clientStart.x,0, -1, clientSize.h-1 });
985 Update({ clientSize.w, 0, -clientStart.x + size.w-1, clientSize.h-1 });
988 // Returns w & h for Position
989 void ComputeAnchors(Anchor anchor, SizeAnchor sizeAnchor, int *ox, int *oy, int *ow, int *oh)
991 Window parent = this.parent ? this.parent : guiApp.desktop;
992 int xOffset = 0, yOffset = 0;
993 int vpw = parent ? parent.clientSize.w : 0;
994 int vph = parent ? parent.clientSize.h : 0;
995 int pw = parent ? parent.clientSize.w : 0;
996 int ph = parent ? parent.clientSize.h : 0;
997 int w = sizeAnchor.size.w, h = sizeAnchor.size.h;
998 int x = anchor.left.distance, y = anchor.top.distance;
999 float ex = 0, ey = 0;
1000 MinMaxValue ew = 0, eh = 0;
1002 float cascadeW, cascadeH;
1004 int tilingW, tilingH, tilingSplit, tilingLastH = 0;
1005 int addX = 0, addY = 0;
1007 if(parent && rootWindow == this && guiApp && guiApp.interfaceDriver)
1009 Window masterWindow = this;
1010 Box box { addX, addY, addX + vpw - 1, addY + vph - 1 };
1013 if(master == guiApp.desktop)
1014 masterWindow = guiApp.desktop.activeChild;
1016 masterWindow = master.rootWindow;
1017 if(!masterWindow) masterWindow = this;
1019 guiApp.interfaceDriver.GetScreenArea(masterWindow, box);
1020 if((anchor.left.type == offset && anchor.right.type == offset) || anchor.left.type == none)
1023 pw = vpw = box.right - box.left + 1;
1025 if((anchor.top.type == offset && anchor.bottom.type == offset) || anchor.top.type == none)
1028 ph = vph = box.bottom - box.top + 1;
1044 vpw = pw = parent.size.w;
1045 vph = ph = parent.size.h;
1047 else if(!style.fixed /*|| style.isDocument*/)
1049 if(!style.dontScrollHorz && parent.scrollArea.w) vpw = parent.scrollArea.w;
1050 if(!style.dontScrollVert && parent.scrollArea.h) vph = parent.scrollArea.h;
1052 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
1055 Desktop3D_FixSize(&pw, &ph);
1056 Desktop3D_FixSize(&vpw, &vph);
1059 if(pw < skinMinSize.w) pw = skinMinSize.w;
1060 if(ph < skinMinSize.h) ph = skinMinSize.h;
1061 if(vpw < skinMinSize.w) vpw = skinMinSize.w;
1062 if(vph < skinMinSize.h) vph = skinMinSize.h;
1064 // TODO: Must fix what we're snapping
1067 if(anchor.left.type)
1069 SNAPUP(x, textCellW);
1071 else if(anchor.right.type)
1073 SNAPDOWN(x, textCellW);
1078 SNAPUP(y, textCellH);
1080 else if(anchor.bottom.type)
1082 SNAPDOWN(y, textCellH);
1086 // This is required to get proper initial decoration size using native decorations on Windows
1087 #if defined(__WIN32__)
1088 if(nativeDecorations && windowHandle && guiApp && guiApp.interfaceDriver && !visible)
1089 guiApp.interfaceDriver.PositionRootWindow(this, x, y, Max(1, size.w), Max(1, size.h), true, true);
1091 GetDecorationsSize(&ew, &eh);
1093 if(anchor.left.type >= cascade && (state == normal /*|| state == Hidden*/))
1095 // Leave room for non client windows (eventually dockable panels)
1097 int loX = 0, loY = 0, hiX = pw, hiY = ph;
1098 for(win = parent.children.first; win; win = win.next)
1100 if(!win.nonClient && !win.isActiveClient && win.visible)
1102 Size size = win.size;
1103 Point pos = win.position;
1104 int left = pos.x, top = pos.y;
1105 int right = pos.x + size.w, bottom = pos.y + size.h;
1106 if(win.size.w > win.size.h)
1109 loY = Max(loY, bottom);
1110 else if(top > ph - ph / 4)
1111 hiY = Min(hiY, top);
1116 loX = Max(loX, right);
1117 else if(left > pw - pw / 4)
1118 hiX = Min(hiX, left);
1127 if(parent.sbv && !parent.sbv.style.hidden)
1128 pw += guiApp.currentSkin.VerticalSBW();
1129 if(parent.sbh && !parent.sbh.style.hidden)
1130 ph += guiApp.currentSkin.HorizontalSBH();
1132 if(anchor.left.type == cascade)
1134 w = (int)(pw * 0.80);
1135 h = (int)(ph * 0.80);
1137 else if(anchor.left.type >= vTiled)
1142 numTiling = parent.numPositions - parent.numIcons;
1143 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1144 if(anchor.left.type == vTiled)
1148 tilingH = (int)sqrt(numTiling);
1149 tilingW = numTiling / tilingH;
1152 tilingH = tilingW = 0;
1158 tilingW = (int)sqrt(numTiling);
1159 tilingH = numTiling / tilingW;
1162 tilingH = tilingW = 0;
1165 leftOver = numTiling - tilingH * tilingW;
1168 tilingSplit = (tilingW - leftOver) * tilingH;
1169 tilingLastH = tilingH+1;
1172 tilingSplit = numTiling;
1174 if(tilingW && tilingH)
1176 if(positionID >= tilingSplit)
1178 x = xOffset + pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
1179 y = yOffset + ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
1180 x2 = xOffset + pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
1181 y2 = yOffset + ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
1185 x = xOffset + pw * (positionID / tilingH) / tilingW;
1186 y = yOffset + ph * (positionID % tilingH) / tilingH;
1187 x2 = xOffset + pw * (positionID / tilingH + 1) / tilingW;
1188 y2 = yOffset + ph * ((positionID % tilingH) + 1) / tilingH;
1193 // How can this happen? From ec2 parsing test
1201 SNAPDOWN(x, textCellW);
1202 SNAPDOWN(y, textCellH);
1203 SNAPDOWN(x2, textCellW);
1204 SNAPDOWN(y2, textCellH);
1212 if(sizeAnchor.isClientW) w += ew;
1213 if(sizeAnchor.isClientH) h += eh;
1215 if(anchor.left.type == offset)
1216 x = anchor.left.distance;
1217 else if(anchor.left.type == relative)
1218 x = (anchor.left.percent < 0) ? ((int)(vpw * anchor.left.percent - 0.5)) : (int)(vpw * anchor.left.percent + 0.5);
1219 else if(anchor.right.type == relative)
1220 // ex = (anchor.right.percent < 0) ? ((int)(vpw * anchor.right.percent + 0)) : ((int)(vpw * anchor.right.percent + 0));
1221 ex = (anchor.right.percent < 0) ? ((int)(vpw * (1.0-anchor.right.percent) + 0)) : ((int)(vpw * (1.0-anchor.right.percent) + 0));
1222 else if(anchor.right.type == offset)
1223 ex = vpw - anchor.right.distance;
1225 if(anchor.top.type == offset)
1226 y = anchor.top.distance;
1227 else if(anchor.top.type == relative)
1228 y = (anchor.top.percent < 0) ? ((int)(vph * anchor.top.percent - 0.5)) : ((int)(vph * anchor.top.percent + 0.5));
1229 else if(anchor.bottom.type == relative)
1230 //ey = (anchor.bottom.percent < 0) ? ((int)(vph * anchor.bottom.percent + 0)) : ((int)(vph * anchor.bottom.percent + 0));
1231 ey = (anchor.bottom.percent < 0) ? ((int)(vph * (1.0-anchor.bottom.percent) + 0)) : ((int)(vph * (1.0-anchor.bottom.percent) + 0));
1232 else if(anchor.bottom.type == offset)
1233 ey = vph - anchor.bottom.distance;
1235 if(anchor.left.type && anchor.right.type)
1237 switch(anchor.right.type)
1240 ex = pw * (1.0f-anchor.right.percent);
1241 w = Max((int)(ex + 0.5) - x, 0);
1244 ex = vpw - anchor.right.distance;
1245 w = Max((int)(ex + 0.5) - x, 0);
1249 if(anchor.top.type && anchor.bottom.type)
1251 switch(anchor.bottom.type)
1254 ey = ph * (1.0f-anchor.bottom.percent);
1255 h = Max((int)(ey + 0.5) - y, 0);
1258 ey = vph - anchor.bottom.distance;
1259 h = Max((int)(ey + 0.5) - y, 0);
1268 if(state == normal /*|| state == Hidden*/)
1270 bool addSbV = false, addSbH = false;
1272 if(sizeAnchor.isClientW || (anchor.left.type && anchor.right.type)) w = Max(w, 1); else w = Max(w, 0);
1273 if(sizeAnchor.isClientH || (anchor.top.type && anchor.bottom.type)) h = Max(h, 1); else h = Max(h, 0);
1275 w = Max(w, minSize.w);
1276 h = Max(h, minSize.h);
1277 w = Min(w, maxSize.w);
1278 h = Min(h, maxSize.h);
1280 if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
1282 if(w) w -= guiApp.currentSkin.VerticalSBW();
1285 if((sizeAnchor.isClientH || !h || (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
1287 if(h) h -= guiApp.currentSkin.HorizontalSBH();
1291 if(!OnResizing(&w, &h))
1297 if((addSbV)) // || reqScrollArea.h > h) && sbv)
1298 w += guiApp.currentSkin.VerticalSBW();
1299 if((addSbH)) // || reqScrollArea.w > w) && sbh)
1300 h += guiApp.currentSkin.HorizontalSBH();
1302 w = Max(w, skinMinSize.w);
1303 h = Max(h, skinMinSize.h);
1316 SNAPDOWN(w, textCellW);
1317 SNAPDOWN(h, textCellH);
1320 if(anchor.left.type == cascade && (state == normal /*|| state == Hidden*/))
1322 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1325 (pw - w) / CASCADE_SPACE,
1326 (ph - h) / CASCADE_SPACE);
1332 cascW = (pw - w) / (numCascade-1);
1333 cascH = (ph - h) / (numCascade-1);
1334 SNAPDOWN(cascW, textCellW);
1335 SNAPDOWN(cascH, textCellH);
1336 cascadeW = (float)cascW;
1337 cascadeH = (float)cascH;
1341 numCascade = Max(numCascade, 2);
1342 cascadeW = (float)(pw - w) / (numCascade-1);
1343 cascadeH = (float)(ph - h) / (numCascade-1);
1346 x = (int)((positionID % numCascade) * cascadeW) + xOffset;
1347 y = (int)((positionID % numCascade) * cascadeH) + yOffset;
1349 else if(anchor.left.type < vTiled)
1351 if(!anchor.left.type || anchor.horz.type == middleRelative)
1353 if(!anchor.right.type)
1355 if(anchor.horz.type == middleRelative)
1356 x = (int)(vpw * (0.5 + anchor.horz.percent) - w / 2);
1358 x = vpw / 2 + anchor.horz.distance - w / 2;
1364 // case A_EDGE: x = x - w; break;
1366 if(!anchor.top.type || anchor.vert.type == middleRelative)
1368 if(!anchor.bottom.type)
1370 if(anchor.vert.type == middleRelative)
1371 y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
1373 y = vph / 2 + anchor.vert.distance - h / 2;
1379 // case A_EDGE: y = y - h; break;
1382 if((state == normal /*|| state == Hidden*/) && !OnMoving(&x, &y, w, h))
1390 SNAPDOWN(x, textCellW);
1391 SNAPDOWN(y, textCellH);
1403 if(anchored && style.fixed && style.isActiveClient)
1408 void UpdateCaret(bool forceUpdate, bool erase)
1410 static Window lastWindow = null;
1411 static int caretX, caretY, caretSize;
1413 if(guiApp && guiApp.caretOwner == this)
1415 int x = caretPos.x - scroll.x;
1416 int y = caretPos.y - scroll.y;
1418 if((erase || this.caretSize) &&
1419 x >= clientArea.left && x <= clientArea.right &&
1420 y >= clientArea.top && y <= clientArea.bottom)
1424 guiApp.interfaceDriver.SetCaret(
1425 x + absPosition.x + clientStart.x,
1426 y + absPosition.y + clientStart.y, this.caretSize);
1427 guiApp.caretEnabled = true;
1429 if(erase || lastWindow != this || caretX != x || caretY != y || caretSize != this.caretSize || forceUpdate)
1433 if(lastWindow != this)
1435 updateBox.left = x + 1;
1437 updateBox.right = x + 2;
1438 updateBox.bottom = y + this.caretSize - 1;
1442 updateBox.left = Min(x + 1, caretX + 1);
1443 updateBox.top = Min(y, caretY);
1444 updateBox.right = Max(x + 2, caretX + 2);
1445 updateBox.bottom = Max(y + this.caretSize - 1, caretY + caretSize - 1);
1448 guiApp.caretOwner.Update(updateBox);
1455 caretSize = this.caretSize;
1461 guiApp.interfaceDriver.SetCaret(0,0,0);
1462 guiApp.caretEnabled = false;
1468 void SetPosition(int x, int y, int w, int h, bool modifyArea, bool modifyThisArea, bool modifyClientArea)
1473 scrolledPos.x = position.x = x;
1474 scrolledPos.y = position.y = y;
1476 clientSize.w = size.w = w;
1477 clientSize.h = size.h = h;
1479 if(parent && !style.nonClient)
1481 //if(!style.fixed || style.isDocument)
1483 if(!style.dontScrollHorz) scrolledPos.x -= parent.scroll.x;
1484 if(!style.dontScrollVert) scrolledPos.y -= parent.scroll.y;
1488 clientStart.x = clientStart.y = 0;
1490 SetWindowArea(&clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1492 //if(!activeClient || activeClient.state != maximized)
1493 if(!noAutoScrollArea)
1495 // Check if scroll area must be modified
1496 if(guiApp && !guiApp.modeSwitching && (sbv || sbh))
1498 bool foundChild = false;
1500 int cw = clientSize.w;// + ((!sbv || sbv.range > 1) ? guiApp.currentSkin.VerticalSBW() : 0);
1501 int ch = clientSize.h;// + ((!sbh || sbh.rangw > 1) ? guiApp.currentSkin.HorizontalSBH() : 0);
1502 for(child = children.first; child; child = child.next)
1504 if(child.modifyVirtArea && !child.style.hidden && child.created && /*!child.anchored &&*/
1505 !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1507 if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == offset)
1508 w = Max(w, child.position.x + child.size.w);
1509 else if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == none)
1510 w = Max(w, Max(child.position.x, 0) + child.size.w);
1511 if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == offset)
1512 h = Max(h, child.position.y + child.size.h);
1513 else if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == none)
1514 h = Max(h, Max(child.position.y, 0) + child.size.h);
1519 if(foundChild && (w > cw || h > ch))
1521 //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
1523 int stepX = sbStep.x, stepY = sbStep.y;
1524 // Needed to make snapped down position match the skin's check of client area
1525 // against realvirtual
1528 SNAPDOWN(stepX, textCellW);
1529 SNAPDOWN(stepY, textCellH);
1530 stepX = Max(stepX, textCellW);
1531 stepY = Max(stepY, textCellH);
1533 if(scrollFlags.snapX)
1535 if(scrollFlags.snapY)
1538 reqScrollArea.w = w;
1539 reqScrollArea.h = h;
1542 else if(reqScrollArea.w || reqScrollArea.h)
1544 reqScrollArea.w = 0;
1545 reqScrollArea.h = 0;
1546 SetScrollPosition(0,0);
1551 // Automatic MDI Client Scrolling Area Adjustment
1552 if(parent && !parent.noAutoScrollArea)
1554 if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
1555 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
1557 Window parent = this.parent;
1558 int w = parent.reqScrollArea.w;
1559 int h = parent.reqScrollArea.h;
1561 if(stateAnchor.right.type == none && stateAnchor.left.type == offset)
1562 w = Max(w, position.x + size.w);
1563 else if(stateAnchor.right.type == none && stateAnchor.left.type == none)
1564 w = Max(w, Max(position.x, 0) + size.w);
1565 if(stateAnchor.bottom.type == none && stateAnchor.top.type == offset)
1566 h = Max(h, position.y + size.h);
1567 else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
1568 h = Max(h, Max(position.y, 0) + size.h);
1570 if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
1571 (h > parent.clientSize.h && h > parent.reqScrollArea.h))
1573 /*bool resize = false;
1574 int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
1575 // Needed to make snapped down position match the skin's check of client area
1576 // against realvirtual
1579 SNAPDOWN(stepX, textCellW);
1580 SNAPDOWN(stepY, textCellH);
1581 stepX = Max(stepX, textCellW);
1582 stepY = Max(stepY, textCellH);
1584 if(parent.scrollFlags.snapX)
1586 if(parent.scrollFlags.snapY)
1588 if(parent.reqScrollArea.w != w || parent.reqScrollArea.h != h)
1590 parent.reqScrollArea.w = w;
1591 parent.reqScrollArea.h = h;*/
1593 // parent.UpdateScrollBars(true, true);
1594 parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1595 false, true, true, true, false, false);
1600 GetRidOfVirtualArea();
1604 UpdateScrollBars(modifyThisArea, false);
1605 else if(guiApp.currentSkin)
1608 &clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1610 if(sbv && (scrollFlags.dontHide || sbv.range > 1))
1611 clientSize.w -= guiApp.currentSkin.VerticalSBW();
1612 if(sbh && (scrollFlags.dontHide || sbh.range > 1))
1613 clientSize.h -= guiApp.currentSkin.HorizontalSBH();
1616 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1617 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1619 absPosition = scrolledPos;
1620 if(guiApp && guiApp.driver != null && guiApp.interfaceDriver)
1621 guiApp.interfaceDriver.OffsetWindow(this, &absPosition.x, &absPosition.y);
1623 if(this != guiApp.desktop && parent)
1625 absPosition.x += parent.absPosition.x;
1626 absPosition.y += parent.absPosition.y;
1627 if(!style.nonClient && this != guiApp.desktop)
1629 absPosition.x += parent.clientStart.x;
1630 absPosition.y += parent.clientStart.y;
1634 box = Box { 0, 0, size.w - 1, size.h - 1 };
1639 // Clip against parent's client area
1640 box.ClipOffset(against, scrolledPos.x, scrolledPos.y);
1642 // Compute client area in this window coordinate system
1643 clientArea.left = 0;
1645 clientArea.right = clientSize.w - 1;
1646 clientArea.bottom = clientSize.h - 1;
1648 // Clip against parent's client area
1650 clientArea.ClipOffset(against, scrolledPos.x + clientStart.x, scrolledPos.y + clientStart.y);
1654 //absPosition.x -= parent.clientStart.x;
1655 //absPosition.y -= parent.clientStart.y;
1658 // Adjust all children
1659 for(child = children.first; child; child = child.next)
1660 child.SetPosition(child.position.x, child.position.y, child.size.w, child.size.h, false, true, true);
1662 UpdateCaret(false, false);
1665 void GetRidOfVirtualArea(void)
1667 if(parent && !parent.destroyed && style.fixed &&
1668 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient &&
1669 parent.reqScrollArea.w && parent.reqScrollArea.h)
1671 if(!parent.noAutoScrollArea)
1673 // TODO: Review the logic of all this? Each child is going to reposition the parent?
1677 for(child = children.first; child; child = child.next)
1679 if(child.modifyVirtArea && !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1681 if(child.position.x + child.size.w > parent.clientSize.w + ((!parent.sbv || parent.sbv.style.hidden) ? 0 : guiApp.currentSkin.VerticalSBW()) ||
1682 child.position.y + child.size.h > parent.clientSize.h + ((!parent.sbh || parent.sbh.style.hidden) ? 0 : guiApp.currentSkin.HorizontalSBH()))
1692 Window parent = this.parent;
1694 parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1695 false, true, true, true, false, false);
1697 parent.SetScrollArea(0,0,true);
1698 parent.SetScrollPosition(0,0);
1704 public void ExternalPosition(int x, int y, int w, int h)
1706 Position(x, y, w, h, false, true, true, true, false, false);
1709 // (w, h): Full window size
1710 bool Position(int x, int y, int w, int h, bool force, bool processAnchors, bool modifyArea, bool updateScrollBars, bool thisOnly, bool changeRootWindow)
1712 bool result = false;
1713 int oldCW = clientSize.w, oldCH = clientSize.h;
1714 bool clientResized, windowResized, windowMoved;
1716 //bool realResized = size.w != w || size.h != h;
1718 // TOCHECK: This wasn't in ecere.dll
1719 //if(!parent) return true;
1720 if(destroyed) return false;
1722 windowMoved = position.x != x || position.y != y || force;
1724 // windowResized = realResized || force;
1725 windowResized = size.w != w || size.h != h || force;
1727 if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
1733 scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
1734 scrolledPos.x - parent.clientStart.x + this.box.right,
1735 scrolledPos.y - parent.clientStart.y + this.box.bottom
1741 Box box { scrolledPos.x + this.box.left, scrolledPos.y + this.box.top, scrolledPos.x + this.box.right, scrolledPos.y + this.box.bottom};
1746 SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
1748 clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
1749 if(clientResized && this == rootWindow && nativeDecorations && rootWindow.windowHandle)
1750 windowResized = true;
1752 if(display && rootWindow != this)
1755 if(guiApp && guiApp.windowMoving)
1757 if(guiApp.windowMoving.style.nonClient)
1758 guiApp.windowMoving.parent.SetMouseRangeToWindow();
1760 guiApp.windowMoving.parent.SetMouseRangeToClient();
1770 // Buttons bitmap resources crash if we do this while switching mode
1771 if(!guiApp || !guiApp.modeSwitching)
1774 // Process Anchored Children
1778 for(child = children.first; child; child = child.next)
1781 ((child.stateAnchor.left.type != offset ||
1782 child.stateAnchor.top.type != offset ||
1783 child.stateAnchor.right.type != none ||
1784 child.stateAnchor.bottom.type != none) ||
1785 child.state == maximized || child.state == minimized))
1787 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1789 // child.Position(x, y, w, h, false, true, true, true, false);
1790 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1791 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1797 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1798 //if(updateScrollBars)
1800 OnResize(clientSize.w, clientSize.h);
1802 if((clientResized || windowMoved) && created)
1803 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1805 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1807 Window master = guiApp.interimWindow.master;
1808 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1811 if(rootWindow == this && !is3D)
1815 x -= guiApp.desktop.absPosition.x;
1816 y -= guiApp.desktop.absPosition.y;
1818 //guiApp.Log("Position %s\n", caption);
1821 if(windowResized || windowMoved)
1822 if(display && !display.flags.memBackBuffer && changeRootWindow)
1823 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1826 #if !defined(__EMSCRIPTEN__)
1827 !guiApp.fullScreenMode &&
1829 this != guiApp.desktop && (windowResized || windowMoved))
1830 for(child = parent.children.first; child && child != this; child = child.next)
1831 if(child.rootWindow)
1832 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1837 if(windowMoved || windowResized)
1839 display.Lock(true /*false*/);
1842 display.Position(absPosition.x, absPosition.y);
1843 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1846 // result = realResized ? display.Resize(size.w, size.h) : true;
1847 if(nativeDecorations && rootWindow.windowHandle)
1849 int w = clientSize.w, h = clientSize.h;
1850 if(hasMenuBar) h += skinMenuHeight;
1851 if(hasStatusBar) h += statusBarHeight;
1852 if(sbv && sbv.visible) w += sbv.size.w;
1853 if(sbh && sbh.visible) h += sbh.size.h;
1854 result = manageDisplay ? display.Resize(w, h) : true;
1857 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1861 else if(clientResized)
1863 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1866 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1870 if(windowMoved || windowResized)
1875 if(guiApp.driver && changeRootWindow && windowHandle)
1877 if(windowResized || windowMoved)
1878 if(!display || display.flags.memBackBuffer)
1879 guiApp.interfaceDriver.PositionRootWindow(this,
1880 x, y, w, h, windowMoved, windowResized);
1881 guiApp.interfaceDriver.UpdateRootWindow(this);
1883 for(child = children.first; child; child = child.next)
1885 if(child.is3D && child.created)
1887 // Copy Display Content
1888 child.display.displaySystem = display.displaySystem;
1889 child.display.window = display.window;
1890 child.display.current = display.current;
1891 child.display.width = display.width;
1892 child.display.height = display.height;
1893 child.display.driverData = display.driverData;
1894 #if !defined(__EMSCRIPTEN__)
1895 child.display.mutex = null;
1907 void UpdateScrollBars(bool flag, bool fullThing)
1910 bool resizeH = false, resizeV = false;
1911 bool scrolled = false;
1912 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1913 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1915 if(destroyed) return;
1916 if(guiApp.currentSkin)
1918 MinMaxValue cw = 0, ch = 0;
1919 bool sbvVisible = false, sbhVisible = false;
1920 int rangeH = 0, rangeV = 0;
1921 int positionH = 0, positionV;
1923 // First get client area with no respect to scroll bars
1928 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1930 if(scrollFlags.dontHide)
1933 cw -= guiApp.currentSkin.VerticalSBW();
1935 ch -= guiApp.currentSkin.HorizontalSBH();
1937 // Update the scrollbar visibility
1943 sbh.disabled = rangeH <= 1;
1944 if(sbh.style.hidden)
1954 sbv.disabled = rangeV <= 1;
1955 if(sbv.style.hidden)
1963 int oldHRange = sbh ? sbh.range : 0;
1964 int oldVRange = sbv ? sbv.range : 0;
1965 // Then start off with horizontal scrollbar range
1968 positionH = sbh.thumbPosition;
1975 SBSetTotal(sbh, rvw);
1978 ch -= guiApp.currentSkin.HorizontalSBH();
1981 // Do the same for vertical scrollbar
1984 positionV = sbv.thumbPosition;
1990 SBSetTotal(sbv, rvh);
1994 cw -= guiApp.currentSkin.VerticalSBW();
1995 // Maybe we need to set the range on the horizontal scrollbar again
2003 SBSetTotal(sbh, rvw);
2004 //sbh.Action(setRange, positionH, 0);
2005 if(rangeH <= 1 && sbh.range > 1)
2007 ch -= guiApp.currentSkin.HorizontalSBH();
2013 SBSetTotal(sbv, rvh);
2015 //sbv.Action(setRange, positionV, 0);
2020 if(sbh && sbh.range != oldHRange) sbh.Action(setRange, positionH, 0);
2021 if(sbv && sbv.range != oldVRange) sbv.Action(setRange, positionV, 0);
2024 // Update the scrollbar visibility
2025 if(!scrollFlags.dontHide)
2027 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
2031 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
2038 if(guiApp.currentSkin)
2045 sbhVisible = sbh.style.hidden ? true : false;
2047 sbvVisible = sbv.style.hidden ? true : false;
2049 // Do our resize here
2050 if(flag && (resizeH || resizeV) && fullThing)
2052 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
2057 OnResize(clientSize.w, clientSize.h);
2063 sbh.visible = sbhVisible;
2065 sbv.visible = sbvVisible;
2067 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
2068 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
2071 sbh.pageStep = clientSize.w;
2073 sbv.pageStep = clientSize.h;
2075 // Notify doesn't handle setRange anymore... process it here
2078 int positionH = sbh.thumbPosition;
2079 if(scroll.x != positionH)
2081 OnHScroll(setRange, positionH, 0);
2085 SNAPDOWN(positionH, textCellW);
2086 scroll.x = positionH;
2092 int seen = clientSize.w, total = reqScrollArea.w;
2095 if(scrollFlags.snapX)
2096 SNAPDOWN(seen, sbStep.x);
2098 if(!total) total = seen;
2099 range = total - seen + 1;
2101 range = Max(range, 1);
2103 if(x >= range) x = range - 1;
2105 if(scrollFlags.snapX)
2106 SNAPUP(x, sbStep.x);
2110 OnHScroll(setRange, x, 0);
2115 SNAPDOWN(x, textCellW);
2121 int positionV = sbv.thumbPosition;
2122 if(scroll.y != positionV)
2124 OnVScroll(setRange, positionV, 0);
2128 SNAPDOWN(positionV, textCellH);
2129 scroll.y = positionV;
2135 int seen = clientSize.h, total = reqScrollArea.h;
2138 if(scrollFlags.snapY)
2139 SNAPDOWN(seen, sbStep.y);
2141 if(!total) total = seen;
2142 range = total - seen + 1;
2143 range = Max(range, 1);
2145 if(y >= range) y = range - 1;
2147 if(scrollFlags.snapY)
2148 SNAPUP(y, sbStep.y);
2152 OnVScroll(setRange, y, 0);
2157 SNAPDOWN(y, textCellH);
2163 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2166 for(child = children.first; child; child = child.next)
2168 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2171 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2172 child.Position(x, y, w, h, false, true, false, true, false, false);
2179 // Process Scrollbars
2181 if(sbh) // && !sbh.style.hidden
2184 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2185 // Need to set the range again (should improve...) since the scrollbars didn't have
2186 // the right size when UpdateScrollArea set the range on it
2189 sbh.seen = clientSize.w;
2193 if(sbv) // && !sbv.state.hidden
2196 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2197 // Need to set the range again (should improve...) since the scrollbars didn't have
2198 // the right size when UpdateScrollArea set the range on it
2201 sbv.seen = clientSize.h;
2206 // TESTING THIS LOWER
2207 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2210 for(child = children.first; child; child = child.next)
2212 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2215 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2216 child.Position(x, y, w, h, false, true, false, true, false, false);
2222 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2224 SetState(maximized, false, mods);
2228 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2230 SetState(normal, false, mods);
2234 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2236 SetState(minimized, false, mods);
2237 parent.CycleChildren(false, true, false, true);
2241 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2244 // Scroll bar notifications
2245 if(action != setRange)
2247 bool changed = false;
2251 if(scroll.x != position)
2253 OnHScroll(action, position, keyFlags);
2258 SNAPDOWN(position, textCellW);
2260 scroll.x = position;
2264 if(scroll.y != position)
2266 OnVScroll(action, position, keyFlags);
2271 SNAPDOWN(position, textCellH);
2273 scroll.y = position;
2277 bool childMove = false;
2278 for(child = children.first; child; child = child.next)
2280 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2283 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2284 child.Position(x, y, w, h, false, true, false, true, false, false);
2288 // Testing this patch out to solve MDI workspace redraw bugs
2289 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2290 // Scroll offsets to blame?
2294 UpdateCaret(false, false);
2298 // Testing this patch out to solve MDI workspace redraw bugs
2299 for(child = children.first; child; child = child.next)
2301 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2310 Window GetParentMenuBar()
2312 Window menuBarParent;
2313 if(formDesigner) return null;
2314 for(menuBarParent = this ? parent : null; menuBarParent; menuBarParent = menuBarParent.parent)
2316 if(menuBarParent.menuBar) return menuBarParent.menuBar;
2317 if(menuBarParent && !menuBarParent.isActiveClient)
2323 void CreateSystemChildren(void)
2325 Window parent = this;
2326 bool scrollBarChanged = false;
2327 bool hasClose = false, hasMaxMin = false;
2328 Point scroll = this.scroll;
2330 if(state == maximized)
2332 parent = GetParentMenuBar();
2339 if(style.hasClose) hasClose = true;
2340 if(style.hasMaximize || style.hasMinimize)
2347 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2349 sysButtons[2].Destroy(0);
2350 sysButtons[2] = null;
2352 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2354 sysButtons[1].Destroy(0);
2355 sysButtons[1] = null;
2357 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2359 sysButtons[0].Destroy(0);
2360 sysButtons[0] = null;
2363 if(hasClose && parent)
2370 parent, master = this,
2371 inactive = true, nonClient = true, visible = false;
2373 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2379 if(this.parent == guiApp.desktop)
2380 sysButtons[2].hotKey = altF4;
2381 else if(style.isActiveClient)
2382 sysButtons[2].hotKey = ctrlF4;
2383 sysButtons[2].Create();
2386 sysButtons[2].symbol = 'X';
2387 sysButtons[2].disabled = !style.hasClose;
2390 if(hasMaxMin && parent)
2394 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2395 if(state == maximized)
2398 method = RestoreButtonClicked;
2404 method = MaximizeButtonClicked;
2412 parent, master = this,
2413 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2415 sysButtons[1].Create();
2417 sysButtons[1].NotifyClicked = method;
2419 sysButtons[1].symbol = symbol;
2420 sysButtons[1].disabled = !style.hasMaximize;
2423 if(hasMaxMin && parent)
2427 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2428 if (state == minimized)
2431 method = RestoreButtonClicked;
2437 method = MinimizeButtonClicked;
2445 parent, master = this,
2446 hotKey = altM, inactive = true, nonClient = true, visible = false
2448 sysButtons[0].Create();
2450 sysButtons[0].NotifyClicked = method;
2452 sysButtons[0].symbol = symbol;
2453 sysButtons[0].disabled = !style.hasMinimize;
2456 // Create the scrollbars
2457 if(style.hasHorzScroll && !sbh)
2463 direction = horizontal,
2467 snap = scrollFlags.snapX,
2468 NotifyScrolling = ScrollBarNotification
2471 scrollBarChanged = true;
2473 else if(sbh && !style.hasHorzScroll)
2479 if(style.hasVertScroll && !sbv)
2485 direction = vertical,
2489 snap = scrollFlags.snapY,
2490 NotifyScrolling = ScrollBarNotification
2493 scrollBarChanged = true;
2495 else if(sbv && !style.hasVertScroll)
2500 if(scrollBarChanged)
2502 SetScrollLineStep(sbStep.x, sbStep.y);
2503 UpdateScrollBars(true, true);
2507 if(scrollBarChanged)
2509 if(sbh) sbh.thumbPosition = scroll.x;
2510 if(sbv) sbv.thumbPosition = scroll.y;
2514 void UpdateCaption(void)
2516 if(rootWindow == this)
2519 FigureCaption(caption);
2520 if(guiApp.interfaceDriver)
2521 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2523 UpdateDecorations();
2526 if(parent.activeClient == this) // Added this last check
2528 if(parent.rootWindow == parent)
2531 parent.FigureCaption(caption);
2532 if(guiApp.interfaceDriver)
2533 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2536 parent.UpdateCaption();
2538 parent.UpdateDecorations();
2542 void UpdateActiveDocument(Window previous)
2544 Window activeClient = this.activeClient;
2545 Window activeChild = this.activeChild;
2552 activeClient.CreateSystemChildren();
2554 previous.CreateSystemChildren();
2566 // Build window list
2569 Menu windowMenu = menu.FindMenu("Window");
2574 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2576 Window document = cycle.data;
2577 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2579 char name[2048], caption[2048];
2580 document.FigureCaption(caption);
2581 sprintf(name, "%d %s", id+1, caption);
2582 windowMenu.AddDynamic(MenuItem
2584 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2585 NotifySelect = MenuWindowSelectWindow
2589 if(activeClient.cycle == cycle) break;
2594 if((!previous && activeClient) || !activeClient)
2600 item = menu.FindItem(MenuWindowCloseAll, 0);
2601 if(item) item.disabled = false;
2602 item = menu.FindItem(MenuWindowNext, 0);
2603 if(item) item.disabled = false;
2604 item = menu.FindItem(MenuWindowPrevious, 0);
2605 if(item) item.disabled = false;
2606 item = menu.FindItem(MenuWindowCascade, 0);
2607 if(item) item.disabled = false;
2608 item = menu.FindItem(MenuWindowTileHorz, 0);
2609 if(item) item.disabled = false;
2610 item = menu.FindItem(MenuWindowTileVert, 0);
2611 if(item) item.disabled = false;
2612 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2613 if(item) item.disabled = false;
2614 item = menu.FindItem(MenuWindowWindows, 0);
2615 if(item) item.disabled = false;
2618 item = menu.FindItem(MenuFileClose, 0);
2619 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2620 item = menu.FindItem(MenuFileSaveAll, 0);
2621 if(item) item.disabled = numDocuments < 1;
2623 if(activeClient && activeClient.menu && activeClient.state != minimized)
2627 //activeClient.menu.Clean(activeClient);
2628 menu.Merge(activeClient.menu, true, activeClient);
2632 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2635 menu.Merge(activeChild.menu, true, activeChild);
2638 // This is called again for a child window change, with same active client
2639 OnActivateClient(activeClient, previous);
2640 if(!menuBar && !((BorderBits)borderStyle).fixed && parent && parent.activeClient == this)
2641 parent.UpdateActiveDocument(null);
2644 void _ShowDecorations(Box box, bool post)
2646 if(rootWindow == this && nativeDecorations && !is3D) return;
2647 if(visible && this != guiApp.desktop)
2649 Surface surface = RedrawFull(box);
2653 FigureCaption(caption);
2656 ShowDecorations(captionFont.font,
2659 active, //parent.activeClient == this
2660 guiApp.windowMoving == this);
2662 PreShowDecorations(captionFont.font,
2665 active, //parent.activeClient == this
2666 guiApp.windowMoving == this);
2673 void UpdateExtent(Box refresh)
2675 Surface surface = null;
2677 if(!manageDisplay) { OnRedraw(null);return; }
2678 _ShowDecorations(refresh, false);
2680 surface = Redraw(refresh);
2681 // Opaque background: just fill before EW_REDRAW (clear?)
2684 surface.SetBackground(background);
2685 surface.SetForeground(foreground);
2686 surface.DrawingChar(' ');
2687 if(this == rootWindow)
2689 if(style.drawBehind || background.a)
2691 int a = background.a;
2692 // Premultiply alpha for clear color
2693 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2694 surface.Clear(colorBuffer);
2695 surface.SetBackground(background);
2698 else if(background.a)
2702 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2703 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2706 if(display.flags.alpha && background.a < 255 && background)
2708 surface.Area(0,0,clientSize.w, clientSize.h);
2709 /*if(style.clearDepthBuffer)
2710 surface.Clear(depthBuffer);*/
2712 else if(/*style.clearDepthBuffer || */background.a)
2714 int a = background.a;
2715 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2716 // Premultiply alpha for clear color
2717 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2718 surface.Clear(colorBuffer);
2719 surface.SetBackground(background);
2724 surface.TextFont(usedFont.font);
2725 surface.TextOpacity(false);
2726 surface.outlineColor = black;
2730 // Draw the caret ...
2731 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2733 // surface.SetBackground(0xFFFFFF - background.color);
2734 surface.SetBackground(~background.color);
2736 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2737 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2743 void DrawOverChildren(Box refresh)
2745 Surface surface = Redraw(refresh);
2749 surface.DrawingChar(' ');
2750 surface.SetBackground(background);
2751 surface.SetForeground(foreground);
2753 surface.TextFont(usedFont.font);
2754 surface.TextOpacity(false);
2755 surface.outlineColor = black;
2757 OnDrawOverChildren(surface);
2762 _ShowDecorations(refresh, true);
2765 void ComputeClipExtents(void)
2768 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2770 clipExtent.Copy(this.clipExtent);
2772 for(child = children.last; child; child = child.prev)
2774 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2776 bool opaque = child.IsOpaque(); // TODO: acess background directly
2777 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2779 child.clipExtent.Copy(clipExtent);
2780 child.clipExtent.Offset(-dx, -dy);
2781 child.clipExtent.IntersectBox(child.box);
2783 child.ComputeClipExtents();
2785 if(opaque && !child.style.nonClient)
2787 // Adjust the box for the parent:
2788 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2789 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2794 // ??? Only do this for overlapped window or if parent has with clip children flag
2796 // Do this if window has clip children flag on (default false?)
2797 // this.clipExtent = clipExtent;
2799 clipExtent.Free(null);
2802 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2805 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2806 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2808 offsetX -= rootWindow.clientStart.x;
2809 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2813 for(child = children.last; child; child = child.prev)
2815 bool opaque = child.IsOpaque();
2816 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2820 // Adjust renderArea to the root window level
2821 Extent * renderArea = &rootWindow.tempExtents[3];
2823 int offsetX = child.absPosition.x - rootWindow.absPosition.x;
2824 int offsetY = child.absPosition.y - rootWindow.absPosition.y;
2825 if(child.rootWindow.nativeDecorations && rootWindow.windowHandle)
2827 offsetX -= child.rootWindow.clientStart.x;
2828 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2832 Extent childRenderArea;
2834 if(backBufferUpdate != null)
2836 childRenderArea.Copy(backBufferUpdate);
2837 childRenderArea.Offset(-offsetX, -offsetY);
2840 childRenderArea.Copy(child.dirtyArea);
2842 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2843 renderArea.Copy(dirtyExtent);
2844 renderArea.Offset(-offsetX, -offsetY);
2845 childRenderArea.Union(renderArea);
2848 // Intersect with the clip extent
2849 childRenderArea.Intersection(child.clipExtent);
2852 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2854 // This intersection with child clip extent was missing and causing #708 (Installer components list scrolling bug):
2855 renderArea->Intersection(child.clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2857 renderArea->Offset(offsetX, offsetY);
2859 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2860 // overDirtyExtent.Union(renderArea);
2861 renderArea->Empty();
2862 // childRenderArea.Free();
2864 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2869 for(child = children.last; child; child = child.prev)
2871 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2873 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2878 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2880 bool opaque = IsOpaque();
2881 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2883 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2884 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2886 offsetX -= rootWindow.clientStart.x;
2887 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2891 for(child = children.last; child; child = child.prev)
2893 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2895 ColorAlpha background = *(ColorAlpha *)&child.background;
2896 bool opaque = child.IsOpaque();
2897 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2901 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2902 // Adjust renderArea to the root window level
2904 renderArea.Copy(child.dirtyArea);
2905 renderArea.Offset(offsetX, offsetY);
2906 dirtyExtent.Union(renderArea);
2907 overDirtyExtent.Union(renderArea);
2913 for(child = children.last; child; child = child.prev)
2915 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2917 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2921 if(backBufferUpdate != null)
2923 renderArea.Copy(backBufferUpdate);
2924 renderArea.Offset(-offsetX, -offsetY);
2926 overRenderArea.Copy(backBufferUpdate);
2927 overRenderArea.Offset(-offsetX, -offsetY);
2933 renderArea.Copy(dirtyArea);
2935 overRenderArea.Copy(dirtyArea);
2938 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2939 dirtyExtentWindow->Copy(dirtyExtent);
2940 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2941 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2942 dirtyExtentWindow->Empty();
2944 // Intersect with the clip extent
2945 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2948 if(renderArea.count > 10)
2951 printf("\nToo many extents (%d):\n", renderArea.count);
2953 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2954 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2959 for(c = 0; c<10; c++)
2962 FASTLIST_LOOP(renderArea, extentBox)
2964 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2966 renderArea.Copy(extent);
2968 FASTLIST_LOOP(renderArea, extentBox)
2971 printf("(%d, %d) - (%d, %d)\n",
2972 extentBox.box.left, extentBox.box.top,
2973 extentBox.box.right, extentBox.box.bottom);
2977 printf("\nNow %d\n", renderArea.count);
2983 // WHY WAS THIS COMMENTED ??
2985 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2986 dirtyExtentWindow->Copy(overDirtyExtent);
2987 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2988 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2989 dirtyExtentWindow->Empty();
2991 // Intersect with the clip extent
2992 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2998 if(scrollExtent.count)
3000 // Subtract render extent from scrolling extent
3001 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
3003 if(backBufferUpdate == null)
3005 Extent * dirty = &rootWindow.tempExtents[3];
3008 // Intersect scrolling extent with clip extent
3009 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
3011 // offset this scroll to be at the root window level
3012 scrollExtent.Offset(offsetX, offsetY);
3013 // Add area that was scrolled to the dirty extents of the back buffer
3014 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
3018 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
3019 for(scrollBox = (BoxItem)scrollExtent.first; scrollBox; scrollBox = (BoxItem)scrollBox.next)
3020 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
3025 scrollExtent.Empty();
3027 // Add the exposed extent to the window render area
3028 dirty->Offset(-offsetX, -offsetY);
3029 renderArea.Union(dirty, rootWindow.tempExtents[0]);
3034 // Subtract the window's box from the transparency forced extent
3035 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
3041 renderArea.Copy(this.renderArea);
3042 renderArea.Offset(offsetX, offsetY);
3043 dirtyExtent.Union(renderArea);
3049 Extent renderArea { };
3051 renderArea.Copy(overRenderArea);
3052 renderArea.Offset(offsetX, offsetY);
3053 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
3058 if(backBufferUpdate != null)
3060 // Remove render area from dirty area
3061 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
3063 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
3070 // Remove the window render area from the dirty extents of the back buffer
3071 rootWindow.dirtyBack.Exclusion(renderArea);
3075 void Render(Extent updateExtent)
3079 Window rootWindow = this.rootWindow;
3080 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
3081 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
3083 offsetX -= rootWindow.clientStart.x;
3084 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
3087 if(rootWindow.fullRender)
3096 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
3097 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
3102 /*if(renderArea.count)
3103 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
3106 for(extentBox = (BoxItem)renderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
3108 Box box = extentBox.box;
3111 /*printf("(%d, %d) - (%d, %d)\n",
3112 extentBox.box.left, extentBox.box.top,
3113 extentBox.box.right, extentBox.box.bottom);*/
3118 box.left += offsetX;
3120 box.right += offsetX;
3121 box.bottom += offsetY;
3123 if(updateExtent != null)
3124 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
3128 for(child = children.first; child; child = child.next)
3129 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
3130 child.Render(updateExtent);
3132 if(rootWindow.fullRender)
3133 DrawOverChildren(box);
3136 // TO DO: There's an issue about draw over children...
3137 // TO DO: Don't wanna go through this if method isn't used
3138 for(extentBox = (BoxItem)overRenderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
3139 //FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
3141 Box box = extentBox.box;
3143 DrawOverChildren(box);
3145 box.left += offsetX;
3147 box.right += offsetX;
3148 box.bottom += offsetY;
3150 if(updateExtent != null)
3151 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
3154 for(child = children.first; child; child = child.next)
3155 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
3156 child.Render(updateExtent);
3159 overRenderArea.Empty();
3162 public void UpdateDisplay(void)
3164 if(!manageDisplay) { OnRedraw(null);return; }
3165 if(rootWindow && this != rootWindow)
3166 rootWindow.UpdateDisplay();
3169 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
3170 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
3173 dirtyExtent.Clear();
3176 clipExtent.AddBox(box);
3179 display.StartUpdate();
3181 if(!rootWindow.fullRender)
3183 ComputeClipExtents();
3184 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
3185 ComputeRenderArea(dirtyExtent, overExtent, null);
3188 clipExtent.Free(null);
3190 dirtyExtent.Free(null);
3191 overExtent.Free(null);
3193 if(display.flags.flipping)
3196 display.Update(null);
3200 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
3201 updateExtent.Clear();
3203 Render(updateExtent);
3205 updateExtent.UnionBox(this.box, tempExtents[0]);
3208 //printf("\n\nUpdate:\n------------------------------------------\n");
3211 //FASTLIST_LOOP(updateExtent, extentBox)
3212 for(extentBox = (BoxItem)updateExtent.first; extentBox; extentBox = (BoxItem)extentBox.next)
3215 /*printf("Updating (%d, %d) - (%d, %d)\n",
3216 extentBox.box.left, extentBox.box.top,
3217 extentBox.box.right, extentBox.box.bottom);*/
3220 display.Update(extentBox.box);
3223 updateExtent.Free(null);
3226 display.EndUpdate();
3235 void UpdateBackDisplay(Box box)
3241 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3243 //printf("UpdateBackDisplay going through!\n");
3244 display.StartUpdate();
3248 intersection.Copy(dirtyBack);
3249 intersection.IntersectBox(box);
3251 dirtyExtent.Clear();
3254 clipExtent.AddBox(box);
3256 if(!rootWindow.fullRender)
3258 ComputeClipExtents();
3259 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3262 clipExtent.Free(null);
3264 intersection.Free(null);
3265 dirtyExtent.Free(null);
3266 overExtent.Free(null);
3271 if(display.flags.flipping)
3272 display.Update(null);
3275 rootWindow.display.Update(box);
3278 display.EndUpdate();
3282 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3283 if(dirtyBack.count > MAX_DIRTY_BACK)
3285 BoxItem extentBox, next;
3286 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3287 for(extentBox = (BoxItem)dirtyBack.first; extentBox; extentBox = next)
3289 next = (BoxItem)extentBox.next;
3290 if(extentBox != first)
3292 if(extentBox.box.left < first.box.left)
3293 first.box.left = extentBox.box.left;
3294 if(extentBox.box.top < first.box.top)
3295 first.box.top = extentBox.box.top;
3296 if(extentBox.box.right > first.box.right)
3297 first.box.right = extentBox.box.right;
3298 if(extentBox.box.bottom > first.box.bottom)
3299 first.box.bottom = extentBox.box.bottom;
3300 dirtyBack.Delete(extentBox);
3309 // --- Window positioning ---
3310 // --- Window identification ---
3312 // Returns window at position "Position"
3313 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3315 Window child, result = null;
3317 box.left += absPosition.x;
3318 box.right += absPosition.x;
3319 box.top += absPosition.y;
3320 box.bottom += absPosition.y;
3322 if(!destroyed && visible && (acceptDisabled || !disabled))
3324 int lx = x - absPosition.x;
3325 int ly = y - absPosition.y;
3326 if(IsInside(lx, ly))
3327 // if(box.IsPointInside(Point{x, y}))
3329 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3330 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3333 bool isD = (last && last != this && last.IsDescendantOf(this)); // Fix for WSMS (#844)
3334 Window ancestor = null;
3336 for(ancestor = last; ancestor && ancestor.parent != this; ancestor = ancestor.parent);
3337 for(child = (isD ? (last != ancestor ? ancestor : ancestor.previous) : children.last); child; child = child.prev)
3339 if(child != statusBar && child.rootWindow == rootWindow)
3341 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3348 for(child = (isD ? (last != ancestor ? ancestor : ancestor.previous) : children.last); child; child = child.prev)
3350 if(child != statusBar && child.rootWindow == rootWindow)
3352 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3359 if(last && last != this && this.IsDescendantOf(last)) // Fix for installer lockup
3367 Window FindModal(void)
3369 Window modalWindow = this, check;
3370 Window check2 = null;
3371 for(check = this; check.master; check = check.master)
3373 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3375 modalWindow = check.master.modalSlave;
3376 check = modalWindow;
3378 // TESTING THIS FOR DROPBOX...
3379 if(!rootWindow || !rootWindow.style.interim)
3381 for(check2 = check; check2 /*.activeChild*/; check2 = check2.activeChild)
3383 if(check2.modalSlave && check2.modalSlave.created)
3385 modalWindow = check2.modalSlave;
3393 if(modalWindow == this)
3395 for(check = this; check.activeChild; check = check.activeChild)
3397 if(check.modalSlave)
3399 modalWindow = check.modalSlave;
3405 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3406 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3409 void StopMoving(void)
3411 if(this == guiApp.windowMoving)
3413 guiApp.windowMoving = null;
3414 UpdateDecorations();
3415 SetMouseRange(null);
3418 if(rootWindow.active)
3419 guiApp.interfaceDriver.StopMoving(rootWindow);
3421 guiApp.windowCaptured.ReleaseCapture();
3422 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3423 guiApp.windowIsResizing = false;
3427 void SelectMouseCursor(void)
3432 Window cursorWindow = null;
3433 bool rx, ry, rex, rey;
3435 guiApp.desktop.GetMousePosition(&x, &y);
3436 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3438 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3439 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[moving]);
3440 else if(mouseWindow)
3442 modalWindow = mouseWindow.FindModal();
3443 x -= mouseWindow.absPosition.x;
3444 y -= mouseWindow.absPosition.y;
3445 if(guiApp.windowIsResizing)
3447 rex = guiApp.resizeEndX;
3448 rey = guiApp.resizeEndY;
3449 rx = guiApp.resizeX;
3450 ry = guiApp.resizeY;
3451 if((rex && rey) || (rx && ry))
3452 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNWSE]);
3453 else if((rex && ry) || (rx && rey))
3454 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNESW]);
3455 else if((ry || rey) && (!rx && !rex))
3456 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNS]);
3457 else if((rx || rex) && (!ry && !rey))
3458 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeWE]);
3460 else if(!modalWindow && !guiApp.windowCaptured &&
3461 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3462 &rx, &ry, &rex, &rey))
3464 if((rex && rey) || (rx && ry))
3465 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNWSE]);
3466 else if((rex && ry) || (rx && rey))
3467 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNESW]);
3468 else if((ry || rey) && (!rx && !rex))
3469 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNS]);
3470 else if((rx || rex) && (!ry && !rey))
3471 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeWE]);
3473 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3475 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}) &&
3476 mouseWindow.rootWindow != mouseWindow)
3477 cursorWindow = mouseWindow.parent;
3479 cursorWindow = mouseWindow;
3481 else if(!guiApp.interimWindow)
3482 cursorWindow = guiApp.windowCaptured;
3485 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient && cursorWindow.rootWindow != cursorWindow; cursorWindow = cursorWindow.parent);
3486 guiApp.SetCurrentCursor(mouseWindow, cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3488 else if(modalWindow)
3490 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[arrow]);
3492 else if(guiApp.interimWindow)
3494 if(guiApp.interimWindow.cursor)
3495 guiApp.SetCurrentCursor(mouseWindow, guiApp.interimWindow.cursor);
3497 guiApp.SetCurrentCursor(mouseWindow, mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3502 // --- State based input ---
3503 bool AcquireInputEx(bool state)
3508 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3509 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3511 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3513 guiApp.acquiredWindow = state ? this : null;
3516 SetMouseRangeToClient();
3517 guiApp.interfaceDriver.SetMouseCursor(guiApp.acquiredWindow, (SystemCursor)-1);
3522 SelectMouseCursor();
3524 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3528 // --- Window activation ---
3529 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3532 if(!parent || !parent.style.inactive)
3534 Window parent = this.parent;
3537 if(rootWindow == this)
3538 Log(active ? "active\n" : "inactive\n");
3540 if(active && requireRemaximize)
3542 if(state == maximized)
3544 property::state = normal;
3545 property::state = maximized;
3547 requireRemaximize = false;
3550 // Testing this here...
3551 if(!parent || parent == guiApp.desktop || parent.active)
3553 this.active = active;
3556 // TESTING THIS HERE
3557 UpdateDecorations();
3558 if((result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master))
3559 result = NotifyActivate(master, this, active, previous);
3562 this.active = !active;
3567 if(!parent || parent == guiApp.desktop || parent.active)
3569 this.active = active;
3571 AcquireInputEx(active);
3572 if(active && isEnabled)
3576 if(guiApp.caretOwner)
3580 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3581 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3582 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3583 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3585 guiApp.caretOwner.Update(extent);
3588 if(visible || !guiApp.caretOwner)
3589 guiApp.caretOwner = this;
3590 UpdateCaret(false, false);
3596 this.active = false;
3598 AcquireInputEx(active);
3600 if(!active && guiApp.caretOwner == this)
3602 UpdateCaret(false, true);
3603 guiApp.caretOwner = null;
3604 guiApp.interfaceDriver.SetCaret(0,0,0);
3605 guiApp.caretEnabled = false;
3610 if(!active && parent && parent.activeChild && parent.activeChild != this)
3611 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3617 if(!active && menuBar)
3620 menuBar.OnActivate(false, null, &goOn, true);
3621 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3626 Window aChild = activeChild;
3628 if(!aChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3640 void ConsequentialMouseMove(bool kbMoving)
3642 if(rootWindow && !noConsequential)
3644 if(kbMoving || !guiApp.windowMoving)
3648 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3650 if(guiApp.interfaceDriver)
3651 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3653 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3654 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3660 bool IsDescendantOf(Window ancestor)
3663 for(window = this; window && window != ancestor; window = window.parent);
3664 return window == ancestor;
3667 bool IsSlaveOf(Window master)
3670 for(window = this; window && window != master; window = window.master);
3671 return window == master;
3674 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3678 if(this && !destroyed /*&& state != Hidden*/)
3680 Window swap = externalSwap;
3688 if(activateParent &&
3689 (parent.activeChild != this ||
3690 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3691 active && _isModal &&
3692 parent != master && master)
3693 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3699 bool real = parent.activeChild != this;
3701 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3702 if(!style.inactive && /*activateParent && */guiApp.interimWindow &&
3703 !IsDescendantOf(guiApp.interimWindow) &&
3704 !IsSlaveOf(guiApp.interimWindow))
3706 Window interimWindow = guiApp.interimWindow;
3707 while(interimWindow && interimWindow != this)
3709 Window master = interimWindow.master;
3711 guiApp.interimWindow = null;
3712 if(guiApp.caretOwner)
3713 guiApp.caretOwner.UpdateCaret(false, false);
3715 incref interimWindow;
3716 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3721 delete interimWindow;
3722 interimWindow = (master && master.style.interim) ? master : null;
3727 guiApp.interimWindow = this;
3728 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3729 guiApp.caretEnabled = false;*/
3730 UpdateCaret(false, true);
3735 //bool acquireInput = false;
3737 parent.activeChild &&
3738 parent.activeChild.state == maximized &&
3739 parent != guiApp.desktop;
3741 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3746 swap = parent.activeChild;
3747 if(swap && swap.destroyed) swap = null;
3748 if(swap && swap != this)
3751 if(!swap.PropagateActive(false, this, &goOn, true))
3752 swap = parent.activeChild;
3763 if(!parent || parent.activeChild != this || style.interim)
3766 result = PropagateActive(true, swap, &goOn, true);
3767 if(!result && !goOn)
3772 //acquireInput = true;
3776 if(style.hasMaximize && parent != guiApp.desktop)
3779 SetState(maximized, false, 0);
3780 else if(state != maximized)
3783 for(child = parent.children.first; child; child = child.next)
3785 if(this != child && child.state == maximized)
3786 child.SetState(normal, false, 0);
3793 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3795 Window previous = parent.activeClient;
3796 parent.activeChild = this;
3797 if(!style.nonClient /*&& style.isActiveClient*/)
3801 if(style.isActiveClient)
3802 parent.activeClient = this;
3803 // Moved UpdateActiveDocument inside hidden check
3804 // To prevent activating previous window while creating a new one
3805 // (It was messing up the privateModule in the CodeEditor)
3806 parent.UpdateActiveDocument(previous);
3812 //if(!style.isRemote)
3814 if(rootWindow != this)
3816 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3817 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3820 #if !defined(__EMSCRIPTEN__)
3821 if(!guiApp.fullScreenMode)
3824 Window modalRoot = FindModal();
3825 if(!modalRoot) modalRoot = this;
3826 if(!modalRoot.isForegroundWindow)
3828 modalRoot.isForegroundWindow = true;
3829 // To check : Why is parent null?
3830 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3832 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3834 modalRoot.isForegroundWindow = false;
3839 if(result && real && (!style.inactive || moveInactive) && parent)
3841 Window last = parent.children.last;
3843 if(!style.stayOnTop)
3844 for(; last && last.style.stayOnTop; last = last.prev);
3846 parent.children.Move(this, last);
3848 // Definitely don't want that: why not?
3852 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3858 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3865 parent.activeChild = null;
3866 if(!style.nonClient /*&& style.isActiveClient*/)
3868 Window previous = parent.activeClient;
3869 if(style.isActiveClient)
3870 parent.activeClient = null;
3871 parent.UpdateActiveDocument(previous);
3875 if(this == guiApp.interimWindow)
3877 guiApp.interimWindow = null;
3878 if(guiApp.caretOwner)
3879 guiApp.caretOwner.UpdateCaret(false, false);
3881 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3888 if(!active || !swap)
3889 UpdateDecorations();
3891 swap.UpdateDecorations();
3893 if(active && rootWindow != this)
3894 ConsequentialMouseMove(false);
3901 // --- Input Messages ---
3902 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3904 static bool reEntrancy = false;
3905 if(reEntrancy) return;
3909 guiApp.cursorUpdate = true;
3910 if(guiApp.windowScrolling && !consequential)
3912 guiApp.windowScrolling.SetScrollPosition(
3913 (guiApp.windowScrolling.sbh) ?
3914 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3915 (guiApp.windowScrolling.sbv) ?
3916 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3918 if(guiApp.windowMoving)
3920 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3922 Window window = guiApp.windowMoving;
3924 int w = window.size.w;
3925 int h = window.size.h;
3930 rx = mouseX - guiApp.windowMovingStart.x;
3931 ry = mouseY - guiApp.windowMovingStart.y;
3934 window.GetDecorationsSize(&ew, &eh);
3936 if(guiApp.windowIsResizing)
3938 x = window.scrolledPos.x;
3939 y = window.scrolledPos.y;
3943 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3944 rx = guiApp.windowResizingBefore.w - aw;
3945 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3946 w = guiApp.windowResizingBefore.w - rx;
3950 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3951 ry = guiApp.windowResizingBefore.h - ah;
3952 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3953 ry = Max(ry, -guiApp.windowMovingBefore.y);
3954 h = guiApp.windowResizingBefore.h - ry;
3956 if(guiApp.resizeEndX)
3958 w = guiApp.windowResizingBefore.w + rx;
3961 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3969 w = Max(w, window.minSize.w);
3970 h = Max(h, window.minSize.h);
3971 w = Min(w, window.maxSize.w);
3972 h = Min(h, window.maxSize.h);
3974 if(!window.OnResizing(&w, &h))
3976 w = window.clientSize.w;
3977 h = window.clientSize.h;
3980 w = Max(w, window.skinMinSize.w);
3981 h = Max(h, window.skinMinSize.h);
3988 SNAPDOWN(w, textCellW);
3989 SNAPDOWN(h, textCellH);
3994 aw = Max(w,window.skinMinSize.w);
3995 rx = guiApp.windowResizingBefore.w - aw;
3996 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3997 w = guiApp.windowResizingBefore.w - rx;
4001 ah = Max(h,window.skinMinSize.h);
4002 ry = guiApp.windowResizingBefore.h - ah;
4003 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
4004 ry = Max(ry, -guiApp.windowMovingBefore.y);
4005 h = guiApp.windowResizingBefore.h - ry;
4010 if(!guiApp.windowIsResizing || guiApp.resizeX)
4011 x = guiApp.windowMovingBefore.x + rx;
4012 if(!guiApp.windowIsResizing || guiApp.resizeY)
4013 y = guiApp.windowMovingBefore.y + ry;
4015 if(!guiApp.windowIsResizing)
4018 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
4020 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
4021 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
4022 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
4023 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
4027 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
4028 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
4034 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
4036 if(!window.OnMoving(&x, &y, w, h))
4038 x = window.scrolledPos.x;
4039 y = window.scrolledPos.y;
4045 SNAPDOWN(x, textCellW);
4046 SNAPDOWN(y, textCellH);
4049 if(!window.style.nonClient)
4051 if(!window.style.fixed /*|| window.style.isDocument*/)
4053 if(!window.style.dontScrollHorz)
4054 x += window.parent.scroll.x;
4055 if(!window.style.dontScrollVert)
4056 y += window.parent.scroll.y;
4060 // Break the anchors for moveable/resizable windows
4061 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
4062 if(window.style.fixed)
4064 if(window.state == normal)
4066 window.normalAnchor = Anchor { left = x, top = y };
4067 window.normalSizeAnchor = SizeAnchor { { w, h } };
4068 window.anchored = false;
4072 window.stateAnchor = Anchor { left = x, top = y };
4073 window.stateSizeAnchor = SizeAnchor { { w, h } };
4075 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
4076 // TOCHECK: Investigate why the following only redraws the scrollbars
4077 //window.Position(x, y, w, h, false, true, true, true, false, true);
4079 guiApp.movingLast.x = mouseX;
4080 guiApp.movingLast.y = mouseY;
4086 public bool MultiTouchMessage(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers * mods, bool consequential, bool activate)
4092 while(result && w != this)
4094 // TODO: How to handle this?
4095 int x = infos[0].point.x;
4096 int y = infos[0].point.y;
4097 Window msgWindow = GetAtPosition(x,y, false, true, w);
4102 window = (w && !w.disabled) ? w : null;
4104 if(consequential) mods->isSideEffect = true;
4105 if(!result || (window && window.destroyed)) window = null;
4109 if(window.OnMultiTouch && !window.disabled)
4111 Array<TouchPointerInfo> in { size = infos.size };
4112 memcpy(in.array, infos.array, sizeof(TouchPointerInfo) * infos.size);
4116 i.point.x -= (window.absPosition.x + window.clientStart.x);
4117 i.point.y -= (window.absPosition.y + window.clientStart.y);
4119 i.point.x = Max(Min(i.point.x, 32767),-32768);
4120 i.point.y = Max(Min(i.point.y, 32767),-32768);
4124 if(!window.OnMultiTouch(event, in, *mods))
4131 if(!result || !w || !w.clickThrough)
4139 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
4142 bool wasMoving = guiApp.windowMoving ? true : false;
4143 bool wasScrolling = guiApp.windowScrolling ? true : false;
4144 bool firstPass = true;
4146 while(result && w != this)
4148 Window msgWindow = GetAtPosition(x,y, false, true, w);
4149 Window trueWindow = GetAtPosition(x,y, false, false, w);
4150 bool windowDragged = false;
4155 window = (w && !w.disabled) ? w : null;
4157 if(trueWindow) incref trueWindow;
4159 if(consequential) mods->isSideEffect = true;
4161 UpdateMouseMove(x, y, consequential);
4163 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
4165 if(!guiApp.windowCaptured.isEnabled)
4166 guiApp.windowCaptured.ReleaseCapture();
4168 window = guiApp.windowCaptured;
4171 if(trueWindow && activate &&
4172 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
4173 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
4174 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
4175 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
4177 if(mods->alt && !mods->ctrl && !mods->shift)
4179 Window moved = trueWindow;
4180 for(moved = trueWindow; moved; moved = moved.parent)
4181 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
4186 windowDragged = true;
4188 // Cancel the ALT menu toggling...
4189 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4194 if(window && activate &&
4195 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
4196 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
4197 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
4198 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
4200 Window modalWindow = window.FindModal();
4202 /*if(mods->alt && !mods->shift && !mods->ctrl)
4204 Window moved = window;
4205 for(moved = window; moved; moved = moved.parent)
4206 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
4211 windowDragged = true;
4213 // Cancel the ALT menu toggling...
4214 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
4220 Window activateWindow = modalWindow ? modalWindow : window;
4221 if(activateWindow && !activateWindow.isRemote)
4223 bool doActivation = true;
4224 //bool needToDoActivation = false;
4225 Window check = activateWindow;
4227 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
4229 if(!check.style.inactive)
4231 //needToDoActivation = true;
4233 doActivation = false;
4238 if(!needToDoActivation)
4239 doActivation = false;
4242 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
4243 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
4245 // Let the OnLeftButtonDown do the activating instead
4246 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4254 incref activateWindow;
4255 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
4257 delete activateWindow;
4261 if(activateWindow._refCount == 1)
4263 delete activateWindow;
4267 delete activateWindow;
4268 // Trouble with clickThrough, siblings and activation (Fix for nicktick scrolling, siblings/activation endless loops, #844)
4271 mods->isActivate = true;
4275 if(!modalWindow && window && !window.destroyed)
4277 if(!guiApp.windowCaptured || windowDragged)
4279 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
4281 bool moving = ((window.state != maximized &&
4282 window.IsMouseMoving(
4283 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4284 || (guiApp.windowMoving && !guiApp.windowIsResizing);
4286 if(!moving && window.IsMouseResizing(
4287 x - window.absPosition.x,
4288 y - window.absPosition.y,
4289 window.size.w, window.size.h,
4290 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
4292 guiApp.windowIsResizing = true;
4293 guiApp.windowResizingBefore.w = window.size.w;
4294 guiApp.windowResizingBefore.h = window.size.h;
4296 if(guiApp.windowIsResizing || windowDragged || moving)
4299 guiApp.windowMoving = window;
4300 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4301 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4302 guiApp.windowMovingBefore.x = window.position.x;//s;
4303 guiApp.windowMovingBefore.y = window.position.y;//s;
4304 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4305 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4308 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4310 if(window.style.fixed &&
4312 window.IsMouseMoving(
4313 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4315 window.ShowSysMenu(x, y);
4319 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4321 if(window.sbv || window.sbh)
4324 guiApp.windowScrolling = window;
4325 guiApp.windowScrollingStart.x = x;
4326 guiApp.windowScrollingStart.y = y;
4327 guiApp.windowScrollingBefore.x = window.scroll.x;
4328 guiApp.windowScrollingBefore.y = window.scroll.y;
4331 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4333 if(window.style.hasMaximize &&
4334 window.IsMouseMoving(
4335 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4338 (window.state == maximized) ? normal : maximized, false, *mods);
4346 if(guiApp.windowMoving)
4348 if(guiApp.windowMoving.parent)
4350 if(guiApp.windowMoving.style.nonClient)
4351 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4353 guiApp.windowMoving.parent.SetMouseRangeToClient();
4357 window.UpdateDecorations();
4360 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4362 // Log("\n*** LEFT BUTTON UP ***\n");
4363 if(guiApp.windowMoving)
4364 guiApp.windowMoving.StopMoving();
4366 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4368 if(guiApp.windowScrolling)
4370 Window windowScrolling = guiApp.windowScrolling;
4371 guiApp.windowScrolling = null;
4372 windowScrolling.ReleaseCapture();
4376 if(!result || (window && window.destroyed)) window = null;
4378 if(window && window.FindModal())
4381 if(trueWindow && trueWindow.FindModal())
4389 msgWindow = GetAtPosition(x,y, true, false);
4391 msgWindow.SelectMouseCursor();
4394 if(firstPass && (guiApp.windowCaptured || trueWindow))
4396 Window prevWindow = guiApp.prevWindow;
4397 List<Window> overWindows = guiApp.overWindows;
4398 Iterator<Window> it { overWindows };
4403 if(trueWindow != w && !trueWindow.IsDescendantOf(w))
4406 result = w.OnMouseLeave(*mods);
4408 overWindows.TakeOut(w);
4412 if(result && guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4414 guiApp.prevWindow.mouseInside = false;
4415 guiApp.prevWindow = null;
4419 if(trueWindow.IsDescendantOf(prevWindow))
4421 if(!overWindows.Find(prevWindow))
4422 overWindows.Add(prevWindow);
4424 // Eventually fix this not to include captured?
4425 else if(!prevWindow.OnMouseLeave(*mods))
4429 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4431 Box box = trueWindow.box;
4432 box.left += trueWindow.absPosition.x;
4433 box.right += trueWindow.absPosition.x;
4434 box.top += trueWindow.absPosition.y;
4435 box.bottom += trueWindow.absPosition.y;
4437 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4439 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4440 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4442 overX = Max(Min(overX, 32767),-32768);
4443 overY = Max(Min(overY, 32767),-32768);
4445 trueWindow.mouseInside = true;
4446 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4450 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4452 for(w : guiApp.overWindows; w == trueWindow)
4455 guiApp.overWindows.TakeOut(w);
4458 guiApp.prevWindow = trueWindow;
4461 guiApp.prevWindow = null;
4463 SelectMouseCursor();
4465 if(window && ((!guiApp.windowMoving && !wasMoving) ||
4466 (wasMoving && guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp)) && !wasScrolling)
4468 int clientX = x - (window.absPosition.x + window.clientStart.x);
4469 int clientY = y - (window.absPosition.y + window.clientStart.y);
4471 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4473 clientX = Max(Min(clientX, 32767),-32768);
4474 clientY = Max(Min(clientY, 32767),-32768);
4476 MouseMethod = (void *)window._vTbl[method];
4478 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4481 if(!MouseMethod(window, clientX, clientY, *mods))
4485 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4486 window.OnMouseLeave(*mods);
4493 if(result && w && w.clickThrough && w.parent)
4498 if(!result || !w || !w.clickThrough)
4506 // --- Mouse cursor management ---
4508 bool KeyMessage(uint method, Key key, unichar character)
4513 if(guiApp.interimWindow)
4514 this = guiApp.interimWindow;
4517 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4521 if(!style.inactive || rootWindow != this)
4523 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4524 Window modalWindow = FindModal();
4525 Window interimMaster = master ? master.rootWindow : null;
4529 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4530 status = OnSysKeyDown(key, character);
4531 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4532 status = OnSysKeyHit(key, character);
4533 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4534 status = OnSysKeyUp(key, character);
4541 // Process Key Message for Internal UI Keyboard actions
4542 if(status && !destroyed && menuBar && state != minimized)
4545 if((SmartKey)key != alt)
4546 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4549 SmartKey sk = (SmartKey) key;
4550 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4552 status = menuBar.KeyMessage(method, key, character);
4557 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4558 menuBar.OnKeyHit(escape, 0);
4560 if(!menuBar.focus && guiApp.caretOwner)
4561 guiApp.caretOwner.UpdateCaret(true, false);
4564 if(!destroyed && status)
4566 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4570 case left: case up: case right: case down:
4571 if(guiApp.windowMoving == this)
4574 int w = guiApp.windowMoving.size.w;
4575 int h = guiApp.windowMoving.size.h;
4576 int x = guiApp.windowMoving.scrolledPos.x;
4577 int y = guiApp.windowMoving.scrolledPos.y;
4581 if(key == down || key == up)
4582 step = Max(step, textCellH);
4584 step = Max(step, textCellW);
4587 if(guiApp.windowIsResizing)
4591 case left: w-=step; break;
4592 case right: w+=step; break;
4593 case up: h-=step; break;
4594 case down: h+=step; break;
4601 case left: x-=step; break;
4602 case right: x+=step; break;
4603 case up: y-=step; break;
4604 case down: y+=step; break;
4608 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4609 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4611 if(!guiApp.windowIsResizing || guiApp.resizeX)
4612 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4614 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4616 if(!guiApp.windowIsResizing || guiApp.resizeY)
4617 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4619 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4621 guiApp.interfaceDriver.SetMousePosition(x, y);
4622 ConsequentialMouseMove(true);
4630 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4632 guiApp.windowMoving.StopMoving();
4633 ConsequentialMouseMove(false);
4641 ShowSysMenu(absPosition.x, absPosition.y);
4649 if(!destroyed && status && state != minimized)
4651 // Process all the way down the children
4652 if(activeChild && !activeChild.disabled)
4654 status = activeChild.KeyMessage(method, key, character);
4656 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4657 key.code != left && key.code != right && key.code != up && key.code != down)
4659 status = activeClient.KeyMessage(method, key, character);
4663 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4665 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4666 // && defaultControl != activeChild)
4668 delete previousActive;
4669 previousActive = activeChild;
4670 if(previousActive) incref previousActive;
4672 ConsequentialMouseMove(false);
4673 if((defaultControl.active ||
4674 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4675 defaultControl.KeyMessage(method, defaultKey, character);
4681 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4683 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4690 ShowSysMenu(absPosition.x, absPosition.y);
4697 if(this != guiApp.desktop)
4699 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4701 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4703 MenuMoveOrSize(key.shift, true);
4707 else if(guiApp.windowMoving)
4709 guiApp.windowMoving.StopMoving();
4710 ConsequentialMouseMove(false);
4718 if(!destroyed && status && state != minimized)
4720 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4724 case tab: case shiftTab:
4726 Window cycleParent = this;
4727 if(this == guiApp.interimWindow && master && !master.style.interim && !cycleParent.style.tabCycle && master.parent)
4728 cycleParent = master.parent;
4730 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4732 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4735 Window child = cycleParent.activeChild;
4737 // Scroll the window to include the active control
4738 if(cycleParent.sbh && !child.style.dontScrollHorz)
4740 if(child.scrolledPos.x < 0)
4741 cycleParent.sbh.Action(Position,
4742 cycleParent.scroll.x + child.scrolledPos.x, 0);
4743 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4744 cycleParent.sbh.Action(Position,
4745 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4747 if(cycleParent.sbv && !child.style.dontScrollVert)
4749 if(child.scrolledPos.y < 0)
4750 cycleParent.sbv.Action(Position,
4751 cycleParent.scroll.y + child.scrolledPos.y, 0);
4752 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4753 cycleParent.sbv.Action(Position,
4754 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4757 cycleParent.ConsequentialMouseMove(false);
4763 case f6: case shiftF6:
4764 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4766 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4767 if(parent == guiApp.desktop)
4768 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4778 if(CycleChildren(key.shift, true, false, true))
4786 // mIRC Style Window Shortcuts
4787 case alt1: case alt2: case alt3: case alt4: case alt5:
4788 case alt6: case alt7: case alt8: case alt9: case alt0:
4793 for(document = children.first; document; document = document.next)
4795 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4797 if(document == activeChild)
4799 if(document.state == minimized)
4800 document.SetState(normal, false, key);
4803 document.SetState(minimized, false, key);
4804 CycleChildren(false, true, false);
4809 if(activeChild.state == maximized && document.style.hasMaximize)
4810 document.SetState(maximized, false, key);
4811 else if(document.state == minimized)
4812 document.SetState(normal, false, key);
4813 document.Activate();
4828 if(!destroyed && status)
4830 if(state == minimized)
4835 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4837 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4839 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4840 previousActive.ActivateEx(true, false, false, true, null, null);
4841 delete previousActive;
4847 if(!destroyed && status)
4849 status = ProcessHotKeys(method, key, character);
4851 if(!destroyed && status && !modalWindow && state != minimized)
4854 status = KeyMethod(this, key, character);
4855 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4856 status = OnKeyHit(key, character);
4857 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4859 bool result = false;
4862 case ctrlUp: case ctrlDown:
4863 if(sbv && !guiApp.windowScrolling)
4864 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4866 case wheelUp: case wheelDown:
4867 if(sbv && !guiApp.windowScrolling)
4869 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4870 // Do we want to do a consequential move regardless of result in this case?
4871 ConsequentialMouseMove(false);
4874 case ctrlPageUp: case ctrlPageDown:
4875 if(sbh && !guiApp.windowScrolling)
4876 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4881 ConsequentialMouseMove(false);
4886 if(status && !destroyed && menuBar && state != minimized)
4887 status = menuBar.KeyMessage(method, key, character);
4889 if(style.interim && /*destroyed && */status && interimMaster)
4891 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4892 status = interimMaster.KeyMessage(method, key, character);
4899 bool ProcessHotKeys(uint method, Key key, unichar character)
4904 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4905 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4906 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4908 Window hotKeyWindow = hotKey.window;
4909 Window parent = hotKeyWindow.parent;
4910 Window prevActiveWindow = activeChild;
4911 // For when sys buttons are placed inside the menu bar
4912 if(parent && parent._class == class(PopupMenu))
4913 parent = parent.parent;
4915 // 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
4916 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1])))
4919 if(prevActiveWindow) incref prevActiveWindow;
4920 incref hotKeyWindow;
4921 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient && !hotKeyWindow.inactive)
4922 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4925 delete hotKeyWindow;
4926 delete prevActiveWindow;
4930 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4931 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4932 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4934 // ********* WORKING ON THIS ***********
4935 if(prevActiveWindow && !guiApp.interimWindow)
4936 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4939 else if(hotKeyWindow.style.inactive)
4940 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4942 delete prevActiveWindow;
4943 delete hotKeyWindow;
4944 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4945 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4949 if(status && tabCycle)
4952 for(child = children.first; child; child = child.next)
4954 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4965 // --- Windows and graphics initialization / termination ---
4966 bool SetupRoot(void)
4970 // Setup relationship with outside world (bb root || !bb)
4971 #if defined(__EMSCRIPTEN__)
4972 if(this == guiApp.desktop)
4974 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4975 (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))
4980 tempExtents = new0 Extent[4];
4985 /*if(guiApp.fullScreenMode)
4986 rootWindow = guiApp.desktop;
4988 //rootWindow = parent.created ? parent.rootWindow : null;
4989 rootWindow = parent.rootWindow;
4992 against = &parent.box;
4994 against = &parent.clientArea;
4997 for(child = children.first; child; child = child.next)
5000 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
5003 bool Setup(bool positionChildren)
5005 bool result = false;
5008 #if defined(__EMSCRIPTEN__)
5009 if(this == guiApp.desktop)
5011 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))))
5014 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
5015 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
5018 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
5020 // This was here, is it really needed?
5021 //guiApp.interfaceDriver.ActivateRootWindow(this);
5025 displaySystem = DisplaySystem { glCapabilities = glCapabilities };
5026 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
5028 delete displaySystem;
5033 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, glCapabilities = glCapabilities, windowDriverData = windowData };
5034 if(display.Create(displaySystem, windowHandle))
5041 // Sometimes icon does not show up on Windows XP if we set here...
5042 // guiApp.interfaceDriver.SetIcon(this, icon);
5044 else if(this != guiApp.desktop)
5046 display = rootWindow ? rootWindow.display : null;
5052 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
5053 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
5055 for(child = children.first; child; child = child.next)
5057 if(child.created && !child.Setup(false))
5060 if(guiApp.modeSwitching && guiApp.fullScreen && child.rootWindow == child)
5061 child.UpdateCaption();
5066 bool SetupDisplay(void)
5068 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
5069 if(is3D) return Window3D_SetupDisplay(this); else
5076 class_data void ** pureVTbl;
5078 bool LoadGraphics(bool creation, bool resetAnchors)
5080 bool result = false;
5081 bool success = false;
5083 WindowState stateBackup = state;
5085 if(((subclass(Window))_class).pureVTbl)
5087 if(_vTbl == _class._vTbl)
5089 _vTbl = ((subclass(Window))_class).pureVTbl;
5094 for(m = 0; m < _class.vTblSize; m++)
5096 if(_vTbl[m] == _class._vTbl[m])
5097 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5101 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
5103 if(_vTbl == ((subclass(Window))_class).pureVTbl)
5105 _vTbl = _class._vTbl;
5110 for(m = 0; m < _class.vTblSize; m++)
5112 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
5113 _vTbl[m] = _class._vTbl[m];
5119 #if !defined(__EMSCRIPTEN__)
5120 guiApp.fullScreenMode ||
5122 this != guiApp.desktop)
5124 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
5130 display.Lock(false);
5131 if(rootWindow == this)
5133 // Set Color Palette
5134 display.SetPalette(palette, true);
5138 if(guiApp.fullScreenMode && this == guiApp.desktop)
5143 for(c=0; c<SystemCursor::enumSize; c++)
5144 if(!guiApp.systemCursors[c].bitmap)
5146 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
5147 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
5148 if(guiApp.systemCursors[c].bitmapName)
5150 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
5151 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
5152 if(guiApp.systemCursors[c].bitmap)
5153 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
5158 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5160 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
5161 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
5163 cursor.bitmap.paletteShades = cursor.paletteShades;
5167 guiApp.cursorUpdate = true;
5170 ConsequentialMouseMove(false);
5176 // Load Window Graphic Resources
5179 if(usedFont == setFont || usedFont == window.systemFont)
5180 RemoveResource(usedFont);
5183 RemoveResource(setFont); // TESTING setFont instead of usedFont);
5186 RemoveResource(systemFont);
5189 RemoveResource(captionFont);
5191 for(ptr = resources.first; ptr; ptr = ptr.next)
5193 if(!ptr.loaded) // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
5194 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
5197 AddResource(setFont);
5199 AddResource(systemFont);
5201 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
5208 //if(master && master.font)
5209 if(parent && parent.font)
5213 faceName = parent.font.faceName,
5214 size = parent.font.size,
5215 bold = parent.font.bold,
5216 italic = parent.font.italic,
5217 underline = parent.font.underline
5219 //font = parent.font;
5220 watch(parent) { font { } };
5223 font = guiApp.currentSkin.SystemFont();
5230 captionFont = guiApp.currentSkin ? guiApp.currentSkin.CaptionFont() : null;
5231 AddResource(captionFont);
5233 if(OnLoadGraphics())
5239 //SetScrollLineStep(sbStep.x, sbStep.y);
5241 if(this != guiApp.desktop)
5245 normalAnchor = anchor;
5246 normalSizeAnchor = sizeAnchor;
5249 // Break the anchors for moveable/resizable windows
5251 if(style.fixed && style.isDocument)
5253 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
5265 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5266 stateSizeAnchor = SizeAnchor {};
5271 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5276 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
5277 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
5280 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5284 stateAnchor = normalAnchor;
5285 stateSizeAnchor = normalSizeAnchor;
5288 position = Point { };
5289 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5300 if(Position(x, y, w, h, true, false, true, true, true, true))
5302 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
5305 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
5322 success = result = true;
5325 if(!creation && result)
5327 // Load menu bar first because sys buttons are on it...
5330 if(!menuBar.LoadGraphics(false, resetAnchors))
5336 for(child = children.first; child; child = child.next)
5338 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
5345 CreateSystemChildren();
5349 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5352 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5355 LogErrorCode(graphicsLoadingFailed, _class.name);
5357 // Do this here to avoid problems on Windows
5358 if(rootWindow == this && parent && stateBackup == maximized)
5359 property::state = maximized;
5363 void UnloadGraphics(bool destroyWindows)
5367 // Free children's graphics
5368 for(child = children.first; child; child = child.next)
5369 child.UnloadGraphics(destroyWindows);
5372 display.Lock(false);
5375 if(guiApp.fullScreenMode && this == guiApp.desktop)
5380 for(c=0; c<SystemCursor::enumSize; c++)
5381 if(guiApp.systemCursors[c].bitmap)
5382 delete guiApp.systemCursors[c].bitmap;
5384 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5385 delete cursor.bitmap;
5387 guiApp.cursorBackground.Free();
5390 if(display && display.displaySystem)
5394 for(ptr = resources.first; ptr; ptr = ptr.next)
5398 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5403 // Free window graphics
5406 // Free skin graphics
5407 if(rootWindow == this)
5409 DisplaySystem displaySystem = display.displaySystem;
5412 display.driverData = null;
5413 display.displaySystem = null;
5417 if(displaySystem && !displaySystem.numDisplays && !is3D)
5418 delete displaySystem;
5427 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5428 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5430 if(this == guiApp.desktop || parent == guiApp.desktop)
5432 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5433 guiApp.interfaceDriver.DestroyRootWindow(this);
5437 // --- Window Hiding ---
5439 void SetVisibility(bool state)
5441 bool visible = (style.hidden || !created) ? false : state;
5442 if(visible != this.visible)
5446 this.visible = visible;
5447 for(child = children.first; child; child = child.next)
5448 child.SetVisibility(visible);
5450 ConsequentialMouseMove(false);
5451 if(parent && !nonClient) parent.OnChildVisibilityToggled(this, visible);
5455 // --- Windows and graphics initialization / termination ---
5457 bool DisplayModeChanged(void)
5459 bool result = false;
5460 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5462 guiApp.modeSwitching = true;
5463 UnloadGraphics(false);
5465 if(LoadGraphics(false, false))
5467 guiApp.modeSwitching = false;
5472 // --- Window updates system ---
5474 void UpdateDirty(Box updateBox)
5476 if(!manageDisplay) { OnRedraw(null);return; }
5479 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5482 if(display.flags.flipping)
5485 rootWindow.UpdateDisplay();
5488 UpdateBackDisplay(updateBox);
5490 if(guiApp.fullScreenMode)
5492 guiApp.cursorUpdate = true;
5493 guiApp.PreserveAndDrawCursor();
5495 if(guiApp.fullScreenMode)
5496 guiApp.RestoreCursorBackground();
5502 // This function is strictly called as a result of system window activation
5503 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5506 Window interimMaster = null;
5507 Window interimWindow = guiApp.interimWindow;
5508 if(interimWindow && interimWindow.master)
5509 interimMaster = interimWindow.master.rootWindow;
5511 if(active && state == minimized && window.parent) // && (!window.nativeDecorations || window.rootWindow != window)
5512 // SetState(normal, false, 0);
5513 SetState(lastState, false, 0);
5515 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5519 /* WTH is this doing here?
5520 while(swap && swap.activeChild)
5522 swap = swap.activeChild;
5525 // TESTING THIS BEFORE...
5526 if(interimWindow && this == interimMaster)
5530 // Window interimSwap = this;
5531 Window menuBar = this.menuBar;
5532 if(menuBar && interimWindow.master == menuBar)
5535 while(interimSwap && interimSwap.activeChild)
5536 interimSwap = interimSwap.activeChild;
5538 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5539 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5541 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5542 //result = ActivateEx(true, true, false, activateRoot, window, null);
5547 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5548 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5550 if(interimWindow == this && interimMaster && !active)
5552 while(interimMaster && interimMaster.interim && interimMaster.master)
5554 // printf("Going up one master %s\n", interimMaster._class.name);
5555 interimMaster = interimMaster.master.rootWindow;
5557 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5558 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5564 bool DestroyEx(int64 returnCode)
5567 Timer timer, nextTimer;
5569 OldLink prevOrder = null;
5570 Window client = null;
5572 if(parent) stopwatching(parent, font);
5574 // if(window.modalSlave) return false;
5575 if(destroyed || !created)
5582 OldLink slave = master.slaves.FindLink(this);
5583 master.slaves.Delete(slave);
5586 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5592 this.returnCode = (DialogResult)returnCode;
5594 AcquireInput(false);
5599 master.hotKeys.Delete(hotKey);
5603 if(guiApp.prevWindow == this)
5605 guiApp.prevWindow = null;
5610 for(w : guiApp.overWindows; w == this)
5613 guiApp.overWindows.TakeOut(w);
5617 if(guiApp.caretOwner == this)
5619 guiApp.interfaceDriver.SetCaret(0,0,0);
5620 UpdateCaret(false, true);
5621 guiApp.caretEnabled = false;
5626 parent.childrenCycle.Remove(cycle);
5630 OldLink tmpPrev = order.prev;
5631 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5632 prevOrder = tmpPrev;
5635 client = tmpPrev ? tmpPrev.data : null;
5636 if(client == this) { client = null; break; }
5637 if(client && (client.style.hidden || client.destroyed || !client.created))
5638 tmpPrev = client.order.prev;
5642 prevOrder = tmpPrev;
5647 // If this window can be an active client, make sure the next window we activate can also be one
5648 if(!style.nonClient && style.isActiveClient)
5650 tmpPrev = prevOrder;
5653 client = tmpPrev ? tmpPrev.data : null;
5654 if(client == this) { client = null; break; }
5655 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5656 tmpPrev = client.order.prev;
5660 prevOrder = tmpPrev;
5664 if(client && client.style.hidden) client = null;
5666 // parent.childrenOrder.Remove(order);
5669 if(parent && style.isActiveClient && visible)
5671 if(state == minimized) parent.numIcons--;
5672 parent.numPositions--;
5675 // TESTING THIS HERE!
5679 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5680 // to create a window inside a rootwindow that's being destroyed)
5681 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5683 if(master && !master.destroyed /*&&
5684 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5686 if(master.defaultControl == this)
5687 master.defaultControl = null;
5690 parent.OnChildAddedOrRemoved(this, true);
5691 if(parent && !parent.destroyed /*&&
5692 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5694 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5696 if(order && prevOrder && prevOrder.data != this && active)
5698 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5700 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5701 if(parent.activeClient == this)
5703 parent.activeClient = null;
5704 parent.UpdateActiveDocument(null);
5709 if(guiApp.interimWindow == this)
5712 PropagateActive(false, null, &goOn, true);
5716 //if(window.parent.activeChild == window)
5717 parent.activeChild = null;
5718 if(!style.nonClient /*&& style.isActiveClient*/)
5720 Window previous = parent.activeClient;
5721 if(style.isActiveClient)
5722 parent.activeClient = null;
5723 parent.UpdateActiveDocument(previous);
5728 else if(parent.activeClient == this)
5730 parent.activeClient = client;
5731 parent.UpdateActiveDocument(this);
5735 if(guiApp.interimWindow == this)
5737 guiApp.interimWindow = null;
5738 if(guiApp.caretOwner)
5740 Window desktop = guiApp.desktop;
5741 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5742 guiApp.caretOwner.UpdateCaret(false, false);
5747 if(_isModal && master && master.modalSlave == this)
5748 master.modalSlave = null;
5752 if(!guiApp.caretOwner && parent.caretSize)
5754 guiApp.caretOwner = parent;
5755 parent.UpdateCaret(false, false);
5756 parent.Update(null);
5759 // Why was this commented out?
5760 GetRidOfVirtualArea();
5766 dirtyArea.Free(null);
5767 dirtyBack.Free(null);
5768 scrollExtent.Free(null);
5770 /* ATTEMPTING TO MOVE THAT ABOVE
5779 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5780 for(;(child = window.children.first);)
5782 for(; child && (child.destroyed || !child.created); child = child.next);
5791 UnloadGraphics(true);
5794 delete previousActive;
5797 // statusBar = null;
5800 if(master && !master.destroyed)
5802 //master.NotifyDestroyed(this, this.returnCode);
5803 NotifyDestroyed(master, this, this.returnCode);
5806 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5808 nextTimer = timer.next;
5809 if(timer.window == this)
5811 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5812 // timer.window = null;
5818 if(this == guiApp.windowMoving)
5821 if(guiApp.windowCaptured == this)
5823 //guiApp.windowCaptured = null;
5825 if(rootWindow != this && rootWindow)
5826 rootWindow.ConsequentialMouseMove(false);
5834 //for(child = children.first; next = child ? child.next : null, child; child = next)
5835 for(;(child = children.first); )
5837 for(; child && (child.destroyed || !child.created); child = child.next);
5847 /* // MOVED THIS UP...
5850 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5851 for(;(child = window.children.first); )
5853 for(; child && (child.destroyed || !child.created); child = child.next);
5862 while((slave = slaves.first))
5864 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5866 ((Window)slave.data).DestroyEx(0);
5871 if(guiApp.caretOwner == this)
5872 guiApp.caretOwner = null;
5874 sysButtons[0] = null;
5875 sysButtons[1] = null;
5876 sysButtons[2] = null;
5879 if(rootWindow != this)
5881 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5884 box.left -= parent.clientStart.x;
5885 box.top -= parent.clientStart.y;
5886 box.right -= parent.clientStart.x;
5887 box.bottom -= parent.clientStart.y;
5889 if(parent) parent.Update(box);
5894 OldLink slave = master.slaves.FindVoid(this);
5895 master.slaves.Delete(slave);
5901 parent.children.Remove(this);
5906 //autoCreate = false;
5909 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5910 if(((subclass(Window))_class).pureVTbl)
5912 if(_vTbl == _class._vTbl)
5914 _vTbl = ((subclass(Window))_class).pureVTbl;
5919 for(m = 0; m < _class.vTblSize; m++)
5921 if(_vTbl[m] == _class._vTbl[m])
5922 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5931 void SetStateEx(WindowState newState, bool activate)
5934 WindowState prevState = state;
5938 if(prevState != newState)
5939 lastState = prevState;
5941 if(rootWindow != this || !nativeDecorations || !windowHandle)
5943 if(style.isActiveClient && !style.hidden && prevState == minimized)
5946 // This block used to be at the end of the function... moved it for flicker problem in X
5947 // ------------------------------------------------------
5951 stateAnchor = normalAnchor;
5952 stateSizeAnchor = normalSizeAnchor;
5955 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5956 stateSizeAnchor = SizeAnchor {};
5962 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5965 byte * idBuffer = new0 byte[size];
5967 for(child = parent.children.first; child; child = child.next)
5969 if(child != this && child.state == minimized)
5971 if(child.iconID > size - 2)
5973 idBuffer = renew0 idBuffer byte[size*2];
5974 memset(idBuffer + size, 0, size);
5977 idBuffer[child.iconID] = (byte)bool::true;
5980 for(c = 0; c<size; c++)
5985 if(style.isActiveClient && !style.hidden)
5988 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5989 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5994 // TOCHECK: Why was this here?
5995 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5996 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5997 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5999 if(state != minimized || hasMinimize)
6000 Position(x, y, w, h, true, true, true, true, false, true);
6002 if(!style.inactive && !style.interim && parent && this == parent.activeClient)
6003 parent.UpdateActiveDocument(null);
6006 if(state != minimized || hasMinimize)
6007 CreateSystemChildren();
6008 // ------------------------------------------------------
6011 int GetPositionID(Window forChild)
6015 byte * idBuffer = new0 byte[size];
6018 for(child = children.first; child; child = child.next)
6020 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
6022 if(child.positionID > size - 2)
6024 idBuffer = renew0 idBuffer byte[size*2];
6025 memset(idBuffer + size, 0, size);
6028 idBuffer[child.positionID] = (byte)bool::true;
6031 for(c = 0; c<size; c++)
6038 // --- Window related graphics ---
6040 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
6042 palette = newPalette;
6043 if(rootWindow.display)
6044 rootWindow.display.SetPalette(palette, colorMatch);
6047 public bool AcquireInput(bool acquired)
6050 if((guiApp.acquiredWindow && acquiredInput) != acquired)
6052 if(active || (!visible && creationActivation == activate))
6053 result = AcquireInputEx(acquired);
6058 acquiredInput = acquired ? result : !result;
6063 void ListChildren(ListBox listBox)
6067 for(child = children.first; child; child = child.next)
6069 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
6071 DataRow row = listBox.AddRow();
6072 row.tag = (int64)(intptr)child;
6073 child.FigureCaption(caption);
6074 row.SetData(null, caption);
6079 void UpdateVisual(Box extent)
6081 if(guiApp.driver != null)
6083 #if !defined(__EMSCRIPTEN__)
6084 if(guiApp.fullScreenMode && guiApp.desktop.display)
6089 #if !defined(__EMSCRIPTEN__)
6090 guiApp.desktop.mutex.Wait();
6092 guiApp.desktop.display.Lock(true);
6095 if(guiApp.desktop.active)
6097 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
6099 if(guiApp.desktop.display.flags.flipping)
6100 guiApp.desktop.Update(null);
6101 guiApp.desktop.UpdateDisplay();
6102 guiApp.cursorUpdate = true;
6104 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
6106 guiApp.PreserveAndDrawCursor();
6107 // guiApp.desktop.display.ShowScreen();
6108 guiApp.cursorUpdate = false;
6109 guiApp.desktop.dirty = false;
6110 guiApp.RestoreCursorBackground();
6114 guiApp.desktop.display.Unlock();
6115 #if !defined(__EMSCRIPTEN__)
6116 guiApp.desktop.mutex.Release();
6121 Window rootWindow = this.rootWindow;
6122 #if !defined(__EMSCRIPTEN__)
6123 rootWindow.mutex.Wait();
6129 guiApp.SignalEvent();
6132 #if !defined(__EMSCRIPTEN__)
6133 guiApp.waitMutex.Wait();
6135 guiApp.interfaceDriver.Lock(rootWindow);
6136 if(!rootWindow.style.hidden && rootWindow.dirty)
6138 if(rootWindow.display)
6140 rootWindow.UpdateDisplay();
6141 //rootWindow.display.ShowScreen(null);
6143 rootWindow.dirty = false;
6145 guiApp.interfaceDriver.Unlock(rootWindow);
6146 #if !defined(__EMSCRIPTEN__)
6147 guiApp.waitMutex.Release();
6151 #if !defined(__EMSCRIPTEN__)
6152 rootWindow.mutex.Release();
6158 void UnlockDisplay(void)
6160 guiApp.interfaceDriver.Unlock(rootWindow);
6163 void LockDisplay(void)
6165 guiApp.interfaceDriver.Lock(rootWindow);
6168 Surface GetSurface(Box box)
6170 return Redraw((box == null) ? this.box : box);
6173 void SetMousePosition(int x, int y)
6175 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
6179 void IntegrationActivate(bool active)
6181 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
6183 isForegroundWindow = true;
6184 ActivateEx(active, active, false, false, null, null);
6185 isForegroundWindow = false;
6190 Window QueryCapture(void)
6192 return guiApp.windowCaptured;
6195 int GetDocumentID(void)
6199 byte * idBuffer = new0 byte[size];
6202 for(child = children.first; child; child = child.next)
6204 // TO CHECK: Do we want a documentID when we already have a file name?
6205 if(child.style.isDocument && !child.fileName)
6207 if(child.documentID-1 > size - 2)
6209 idBuffer = renew0 idBuffer byte[size*2];
6210 memset(idBuffer + size, 0, size);
6213 idBuffer[child.documentID-1] = 1;
6216 for(c = 0; c<size; c++)
6224 void SetInitSize(Size size)
6227 sizeAnchor.size = size;
6228 normalSizeAnchor = sizeAnchor;
6230 // Break the anchors for moveable/resizable windows
6231 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6233 stateAnchor = normalAnchor;
6234 stateSizeAnchor = normalSizeAnchor;
6236 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6237 Position(x,y, w, h, true, true, true, true, false, true);
6241 void MenuMoveOrSize(bool resize, bool setCursorPosition)
6243 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
6245 guiApp.windowIsResizing = resize;
6246 guiApp.windowMoving = this;
6247 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
6248 if(guiApp.windowIsResizing)
6250 guiApp.windowMovingStart.x += size.w - 1;
6251 guiApp.windowMovingStart.y += size.h - 1;
6253 guiApp.windowMovingBefore = scrolledPos;
6254 guiApp.windowResizingBefore = size;
6255 guiApp.windowMoving.UpdateDecorations();
6256 if(guiApp.windowIsResizing)
6257 guiApp.resizeEndX = guiApp.resizeEndY = true;
6259 if(setCursorPosition)
6260 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
6264 guiApp.interfaceDriver.GetMousePosition(&x, &y);
6265 guiApp.windowMovingStart.x += x - absPosition.x;
6266 guiApp.windowMovingStart.y += y - absPosition.y;
6269 if(guiApp.windowMoving)
6271 if(guiApp.windowMoving.style.nonClient)
6272 guiApp.windowMoving.parent.SetMouseRangeToWindow();
6274 guiApp.windowMoving.parent.SetMouseRangeToClient();
6279 if(this == rootWindow)
6280 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
6284 void SetupFileMonitor()
6286 #if !defined(__EMSCRIPTEN__)
6289 fileMonitor = FileMonitor
6291 this, FileChange { modified = true };
6293 bool OnFileNotify(FileChange action, const char * param)
6296 fileMonitor.StopMonitoring();
6297 if(OnFileModified(action, param))
6298 fileMonitor.StartMonitoring();
6312 bool result = false;
6316 else if(guiApp && guiApp.driver != null)
6318 OldLink slaveHolder;
6320 bool visible = !style.hidden;
6324 systemParent = parent;
6325 parent = guiApp.desktop;
6327 last = parent ? parent.children.last : null;
6329 if((parent && parent != guiApp.desktop && !parent.created) ||
6330 (master && master != guiApp.desktop && !master.created))
6334 stopwatching(parent, font);
6337 property::parent = guiApp.desktop;
6338 if(!master) master = parent;
6340 if(_isModal && master.modalSlave)
6341 property::master = master.modalSlave;
6345 parent.children.Remove(this);
6348 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
6349 if(slaveHolder.data == this)
6351 master.slaves.Delete(slaveHolder);
6356 #if !defined(__EMSCRIPTEN__)
6357 if(parent == guiApp.desktop && !mutex)
6361 if(style.isDocument)
6364 parent.numDocuments--;
6365 documentID = parent.GetDocumentID();
6368 if(!style.stayOnTop)
6369 for(; last && last.style.stayOnTop; last = last.prev);
6371 parent.children.Insert((last == this) ? null : last, this);
6372 //parent.children.Add(this);
6375 dispDriver = parent.dispDriver;
6378 master.modalSlave = this;
6380 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
6385 master.slaves.Add(slaveHolder = OldLink { data = this });
6390 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
6392 if(style.isDefault && !master.defaultControl)
6393 master.defaultControl = this;
6395 stateAnchor = normalAnchor = anchor;
6396 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
6398 // TOCHECK: Why is this here?
6399 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
6400 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
6402 this.visible = false;
6403 style.hidden = true;
6406 // autoCreate = true;
6414 if(parent == guiApp.desktop)
6415 Log("LoadGraphics %s\n", caption);
6417 if(LoadGraphics(true, false))
6425 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6432 if(style.hasMenuBar /*&& menu*/)
6438 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6439 interim = false, inactive = true, nonClient = true, size.h = 24
6447 // Create the system buttons
6448 CreateSystemChildren();
6450 UpdateActiveDocument(null);
6452 if(style.isDocument)
6456 MenuItem item = menu.FindItem(MenuFileSave, 0);
6457 if(item) item.disabled = !modifiedDocument && fileName;
6462 if(parent == guiApp.desktop)
6463 Log("Preemptive SetState %s\n", caption);
6466 // Preemptive Set State to ensure proper anchoring
6467 SetStateEx(state, false);
6469 style.hidden = true;
6475 for(child = children.first; child; child = next)
6478 if(!child.created && (child.autoCreate || child.wasCreated))
6485 for(link = slaves.first; link; link = next)
6487 Window slave = link.data;
6489 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6492 // Things might have happened that invalidated 'next'...
6493 // Start over the search for slaves to create.
6494 // (Added this to fix crash with Stacker & Toolbar)
6495 next = slaves.first;
6504 if(parent == guiApp.desktop)
6505 Log("Real SetState %s\n", caption);
6508 if(isActiveClient && visible)
6510 parent.numPositions--;
6511 if(state == minimized) parent.numIcons--;
6514 parent.OnChildAddedOrRemoved(this, false);
6516 if(rootWindow == this && visible) // So that X11 windows don't show as 'unknown'
6518 // Real set state & activate for proper display & activation
6519 property::visible = visible;
6520 // SetState(state & 0x00000003, true, 0);
6521 guiApp.interfaceDriver.SetIcon(this, icon);
6526 /*if(rootWindow == this)
6527 guiApp.interfaceDriver.ActivateRootWindow(this);
6529 if(creationActivation == activate && guiApp.desktop.active)
6530 ActivateEx(true, false, true, true, null, null);
6531 else if(creationActivation == activate || creationActivation == flash)
6534 if(this == rootWindow)
6539 if(!destroyed && !noConsequential)
6540 rootWindow.ConsequentialMouseMove(false);
6551 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6557 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6559 //style.hidden = true; // !visible;
6560 style.hidden = !visible;
6561 if(master.modalSlave == this)
6562 master.modalSlave = null;
6569 void WriteCaption(Surface surface, int x, int y)
6572 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6575 void Update(Box region)
6581 rootWindow = this.rootWindow;
6583 // rootWindow.mutex.Wait();
6584 if(!destroyed && visible && display)
6589 // Testing this to avoid repetitve full update to take time...
6590 if(rootWindow.fullRender)
6592 rootWindow.dirty = true;
6595 if(dirtyArea.count == 1)
6597 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6598 if(item.box.left <= box.left &&
6599 item.box.top <= box.top &&
6600 item.box.right >= box.right &&
6601 item.box.bottom >= box.bottom)
6603 rootWindow.dirty = true;
6608 if(display.flags.flipping && !rootWindow.dirty)
6610 if(this == rootWindow)
6614 rootWindow.Update(null);
6619 rootWindow.dirty = true;
6624 realBox.left += clientStart.x;
6625 realBox.top += clientStart.y;
6626 realBox.right += clientStart.x;
6627 realBox.bottom += clientStart.y;
6633 if(realBox.right >= realBox.left &&
6634 realBox.bottom >= realBox.top)
6636 // if(!rootWindow.fullRender)
6637 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6639 for(child = children.first; child; child = child.next)
6644 box.left -= child.absPosition.x - absPosition.x;
6645 box.top -= child.absPosition.y - absPosition.y;
6646 box.right -= child.absPosition.x - absPosition.x;
6647 box.bottom -= child.absPosition.y - absPosition.y;
6648 if(box.right >= child.box.left && box.left <= child.box.right &&
6649 box.bottom >= child.box.top && box.top <= child.box.bottom)
6651 box.left -= child.clientStart.x;
6652 box.top -= child.clientStart.y;
6653 box.right -= child.clientStart.x;
6654 box.bottom -= child.clientStart.y;
6660 realBox.left += absPosition.x - rootWindow.absPosition.x;
6661 realBox.top += absPosition.y - rootWindow.absPosition.y;
6662 realBox.right += absPosition.x - rootWindow.absPosition.x;
6663 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6664 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6667 else if(this == guiApp.desktop)
6670 for(window = children.first; window; window = window.next)
6676 Box childBox = region;
6678 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6679 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6680 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6681 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6683 window.Update(childBox);
6686 window.Update(null);
6691 // rootWindow.mutex.Release();
6698 if(guiApp.windowCaptured != this)
6700 if(guiApp.windowCaptured)
6704 //Logf("Captured %s (%s)\n", caption, class.name);
6705 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6706 guiApp.windowCaptured = this;
6712 bool Destroy(int64 code)
6717 if(!destroyed && !CloseConfirmation(false)) return false;
6721 // TOCHECK: Should autoCreate be set to false here?
6732 void Move(int x, int y, int w, int h)
6734 normalAnchor = Anchor { left = x, top = y };
6735 normalSizeAnchor = SizeAnchor { size = { w, h } };
6737 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6739 if(destroyed) return;
6741 stateAnchor = normalAnchor;
6742 stateSizeAnchor = normalSizeAnchor;
6744 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6745 Position(x,y, w, h, true, true, true, true, false, true);
6749 DialogResult Modal(void)
6755 // FIXES MEMORY LEAK IF Create() FAILED
6761 void SetScrollArea(int width, int height, bool snapToStep)
6765 int stepX = sbStep.x, stepY = sbStep.y;
6766 // Needed to make snapped down position match the skin's check of client area
6767 // against realvirtual
6770 SNAPDOWN(stepX, textCellW);
6771 SNAPDOWN(stepY, textCellH);
6772 stepX = Max(stepX, textCellW);
6773 stepY = Max(stepY, textCellH);
6775 if(scrollFlags.snapX)
6776 SNAPUP(width, stepX);
6777 if(scrollFlags.snapY)
6778 SNAPUP(height, stepY);
6781 reqScrollArea.w = width;
6782 reqScrollArea.h = height;
6783 noAutoScrollArea = (width > 0 || height > 0);
6785 UpdateScrollBars(true, true);
6788 void SetScrollPosition(int x, int y)
6791 sbh.Action(setPosition, x, 0);
6795 int seen = clientSize.w, total = reqScrollArea.w;
6797 if(scrollFlags.snapX)
6798 SNAPDOWN(seen, sbStep.x);
6800 if(!total) total = seen;
6801 range = total - seen + 1;
6802 range = Max(range, 1);
6804 if(x >= range) x = range - 1;
6806 if(scrollFlags.snapX)
6807 SNAPUP(x, sbStep.x);
6810 OnHScroll(setPosition, x, 0);
6814 SNAPDOWN(x, textCellW);
6820 sbv.Action(setPosition, y, 0);
6824 int seen = clientSize.h, total = reqScrollArea.h;
6827 if(scrollFlags.snapY)
6828 SNAPDOWN(seen, sbStep.y);
6830 if(!total) total = seen;
6831 range = total - seen + 1;
6832 range = Max(range, 1);
6834 if(y >= range) y = range - 1;
6836 if(scrollFlags.snapY)
6837 SNAPUP(y, sbStep.y);
6840 OnVScroll(setPosition, y, 0);
6843 SNAPDOWN(y, textCellH);
6848 UpdateCaret(false, false);
6851 void SetScrollLineStep(int stepX, int stepY)
6857 SNAPDOWN(stepX, textCellW);
6858 SNAPDOWN(stepY, textCellH);
6859 stepX = Max(stepX, textCellW);
6860 stepY = Max(stepY, textCellH);
6863 sbh.lineStep = stepX;
6865 sbv.lineStep = stepY;
6868 void SetState(WindowState newState, bool activate, Modifiers mods)
6872 if(state == newState || OnStateChange(newState, mods))
6874 //WindowState prevState = state;
6878 // This used to be at the end of the brackets... moved for X, testing...
6879 // This has the effect of activating the window through the system...
6880 if(rootWindow == this)
6881 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6883 SetStateEx(newState, activate);
6885 if(rootWindow == this && !rootWindow.nativeDecorations)
6887 int x = position.x, y = position.y;
6890 x -= guiApp.desktop.absPosition.x;
6891 y -= guiApp.desktop.absPosition.y;
6893 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6897 //state = prevState;
6899 if(state != maximized && style.hasMaximize)
6902 for(child = parent.children.first; child; child = child.next)
6904 if(child != this && child.state == maximized)
6905 child.SetStateEx(normal, false);
6909 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6910 parent.UpdateScrollBars(true, true);
6913 // Do we really need this stuff here?
6914 // Shouldn't the Activate stuff take care of it?
6915 if(parent.rootWindow == parent && style)
6918 parent.FigureCaption(caption);
6919 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6920 parent.UpdateDecorations();
6924 rootWindow.ConsequentialMouseMove(false);
6931 BitmapResource GetIcon(SkinBitmap iconID)
6933 return guiApp.currentSkin.GetBitmap(iconID);
6936 void SetMouseRange(Box range)
6938 if(range || guiApp.fullScreenMode)
6943 clip.left = range.left + absPosition.x + clientStart.x;
6944 clip.top = range.top + absPosition.y + clientStart.y;
6945 clip.right = range.right + absPosition.x + clientStart.x;
6946 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6950 clip.left = guiApp.desktop.box.left;
6951 clip.top = guiApp.desktop.box.top;
6952 clip.right = guiApp.desktop.box.right;
6953 clip.bottom = guiApp.desktop.box.bottom;
6955 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6958 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6961 void SetMouseRangeToClient(void)
6963 if(guiApp.fullScreenMode || this != guiApp.desktop)
6965 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6966 box.Clip(clientArea);
6970 SetMouseRange(null);
6973 void SetMouseRangeToWindow(void)
6975 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6976 if(this == guiApp.desktop)
6977 SetMouseRangeToClient();
6982 // x, y: Desktop Coordinates
6983 void ShowSysMenu(int x, int y)
6986 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6989 menu, $"Restore", r, NotifySelect = MenuWindowRestore,
6990 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6994 menu, $"Move", m, NotifySelect = MenuWindowMove,
6995 disabled = !style.fixed || state == maximized
6999 menu, $"Size", s, NotifySelect = MenuWindowSize,
7000 disabled = !style.sizable || state != normal
7004 menu, $"Minimize", n, NotifySelect = MenuWindowMinimize,
7005 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
7009 menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
7010 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
7014 menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
7015 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
7017 MenuDivider { menu };
7020 menu, $"Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
7021 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
7023 windowMenu.Create();
7028 ActivateEx(true, true, true, true, null, null);
7031 void MakeActive(void)
7033 ActivateEx(true, false, true, false, null, null);
7036 void SoftActivate(void)
7038 if(guiApp.desktop.active)
7043 if(this == rootWindow)
7048 void Deactivate(void)
7050 ActivateEx(false, true, true, true, null, null);
7055 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
7058 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
7060 bool result = false;
7061 if(activeChild && activeChild.cycle)
7063 Window modalWindow, child = activeChild;
7064 if(!clientOnly /*&& parent.tabCycle*/)
7066 Window next = child;
7069 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
7073 if(parent && parent.CycleChildren(backward, false, true, true))
7081 next = next.cycle.prev.data;
7083 next = next.cycle.next.data;
7084 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
7089 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
7090 parent.tabCycle && parent.CycleChildren(backward, false, false))
7094 if(tabCycleOnly && !tabCycle) return false;
7101 child = child.cycle.prev.data;
7103 child = child.cycle.next.data;
7104 if(child == child.parent.activeChild)
7106 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
7109 modalWindow = child.FindModal();
7112 // Scroll the window to include the active control
7113 if(sbh && !child.style.dontScrollHorz)
7115 if(child.scrolledPos.x < 0)
7116 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
7117 else if(child.scrolledPos.x + child.size.w > clientSize.w)
7118 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
7120 if(sbv && !child.style.dontScrollVert)
7122 if(child.scrolledPos.y < 0)
7123 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
7124 else if(child.scrolledPos.y + child.size.h > clientSize.h)
7125 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
7129 child = modalWindow ? modalWindow : child;
7130 child.ActivateEx(true, true, true, true, null, null);
7131 if(child.tabCycle && child.childrenCycle.first)
7132 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
7140 ConsequentialMouseMove(false);
7144 void AddResource(Resource resource)
7148 ResPtr ptr { resource = resource };
7152 // Load Graphics here if window is created already
7153 if(/*created && */display)
7155 display.Lock(false);
7156 if(!ptr.loaded) // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
7157 ptr.loaded = display.displaySystem.LoadResource(resource);
7161 // Temporary hack to load font right away for listbox in dropbox ...
7162 else if(master && master.display)
7164 master.display.Lock(false);
7165 master.display.displaySystem.LoadResource(resource);
7166 master.display.Unlock();
7172 void RemoveResource(Resource resource)
7177 for(ptr = resources.first; ptr; ptr = ptr.next)
7179 if(ptr.resource == resource)
7185 // Unload Graphics here if window is created already
7186 if(/*created && */display)
7190 display.Lock(false);
7191 display.displaySystem.UnloadResource(resource, ptr.loaded);
7197 resources.Delete(ptr);
7202 void SetCaret(int x, int y, int size)
7209 if(active && !style.interim && isEnabled)
7211 if(visible || !guiApp.caretOwner)
7212 guiApp.caretOwner = size ? this : null;
7214 UpdateCaret(false, false);
7217 guiApp.interfaceDriver.SetCaret(0,0,0);
7218 UpdateCaret(false, true);
7219 guiApp.caretEnabled = false;
7222 else if(style.inactive && active)
7224 guiApp.interfaceDriver.SetCaret(0,0,0);
7225 UpdateCaret(false, true);
7226 guiApp.caretEnabled = false;
7231 void Scroll(int x, int y)
7233 bool opaque = !style.drawBehind || background.a;
7234 if(opaque && display && display.flags.scrolling)
7236 Box box = clientArea;
7237 box.left += clientStart.x;
7238 box.top += clientStart.y;
7239 box.right += clientStart.x;
7240 box.bottom += clientStart.y;
7242 //scrollExtent.Free(null);
7243 scrollExtent.AddBox(box);
7244 scrolledArea.x += x;
7245 scrolledArea.y += y;
7247 //scrollExtent.Free();
7248 //scrollExtent.AddBox(clientArea);
7249 //scrollExtent.Offset(clientStart.x, clientStart.y);
7250 //scrolledArea.x = x;
7251 //scrolledArea.y = y;
7257 rootWindow.dirty = true;
7260 void ReleaseCapture()
7262 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
7264 Window oldCaptured = guiApp.windowCaptured;
7265 guiApp.windowCaptured = null;
7266 guiApp.prevWindow = null;
7269 //guiApp.Log("Released Capture\n");
7271 guiApp.interfaceDriver.SetMouseCapture(null);
7273 //oldCaptured.OnMouseCaptureLost();
7276 oldCaptured.ConsequentialMouseMove(false);
7281 private void _SetCaption(const char * format, va_list args)
7288 char caption[MAX_F_STRING];
7289 vsnprintf(caption, sizeof(caption), format, args);
7290 caption[sizeof(caption)-1] = 0;
7292 this.caption = CopyString(caption);
7297 firewatchers caption;
7301 /*deprecated*/ void SetText(const char * format, ...)
7304 va_start(args, format);
7305 _SetCaption(format, args);
7309 void SetCaption(const char * format, ...)
7312 va_start(args, format);
7313 _SetCaption(format, args);
7317 bool Grab(Bitmap bitmap, Box box, bool decorations)
7319 bool result = false;
7320 if(display || this == guiApp.desktop)
7322 Box clip = {MININT, MININT, MAXINT, MAXINT};
7328 clip.Clip(clientArea);
7330 clip.Clip(this.box);
7332 if(rootWindow != this)
7334 clip.left += absPosition.y;
7335 clip.top += absPosition.y;
7336 clip.right += absPosition.x;
7337 clip.bottom += absPosition.y;
7340 if(!nativeDecorations)
7342 clip.left += decorations ? 0 : clientStart.x;
7343 clip.top += decorations ? 0 : clientStart.y;
7344 clip.right += decorations ? 0 : clientStart.x;
7345 clip.bottom += decorations ? 0 : clientStart.y;
7348 if(decorations && this == guiApp.desktop)
7349 clip = { 0, 0, guiApp.virtualScreen.w, guiApp.virtualScreen.h };
7351 if(display && display.flags.flipping)
7353 rootWindow.Update(null);
7354 rootWindow.UpdateDisplay();
7361 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
7362 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7366 result = display.Grab(bitmap, clip.left, clip.top,
7367 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7369 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
7371 if(!bitmap.Convert(null, pixelFormat888, null))
7378 void GetMousePosition(int * x, int * y)
7380 int mouseX = 0, mouseY = 0;
7381 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
7384 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
7385 if(this != guiApp.desktop)
7387 mouseX -= absPosition.x + clientStart.x;
7388 mouseY -= absPosition.y + clientStart.y;
7395 DialogResult DoModal()
7397 DialogResult returnCode = 0;
7398 int terminated = terminateX;
7401 while(!destroyed && guiApp.driver != null)
7403 if(terminateX != terminated)
7405 terminated = terminateX;
7406 guiApp.desktop.Destroy(0);
7407 if(guiApp.desktop.created)
7410 //printf("Resetting terminate X to 0\n");
7416 guiApp.UpdateDisplay();
7417 if(!guiApp.ProcessInput(false))
7420 returnCode = this.returnCode;
7433 return !destroyed && guiApp.driver != null && terminateX < 2;
7436 DialogResult DoModalEnd()
7438 DialogResult returnCode = this.returnCode;
7443 // --- Window manipulation ---
7444 /*bool GetDisabled()
7446 bool disabled = this.disabled;
7448 for(window = this; (window = window.master); )
7459 // --- Mouse Manipulation ---
7460 void GetNCMousePosition(int * x, int * y)
7462 GetMousePosition(x, y);
7463 if(x) *x += clientStart.x;
7464 if(y) *y += clientStart.y;
7467 // --- Carets manipulation ---
7468 void GetCaretPosition(Point caretPos)
7470 caretPos = this.caretPos;
7473 int GetCaretSize(void)
7478 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7484 bool CloseConfirmation(bool parentClosing)
7497 if(!OnClose(parentClosing))
7500 // If you want to skip this, simply set modifiedDocument to false in OnClose
7501 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7503 DialogResult dialogRes;
7506 sprintf(message, $"Save changes to %s?", fileName);
7508 sprintf(message, $"Save changes to Untitled %d?", documentID);
7510 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = message }.Modal();
7512 if(dialogRes == yes)
7514 // TOFIX: Precomp error if brackets are taken out
7515 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7517 else if(dialogRes == cancel)
7523 for(slave = slaves.first; slave; slave = slave.next)
7525 Window w = slave.data;
7526 if(w.parent != this && !w.IsDescendantOf(this) && !w.CloseConfirmation(true))
7534 // Confirm closure of active clients first (We use OnClose() to hide instead of destroy in the IDE)
7537 for(child = children.first; child; child = child.next)
7538 if(child.isActiveClient && !child.CloseConfirmation(true))
7546 for(child = children.first; child; child = child.next)
7547 if(!child.isActiveClient && !child.CloseConfirmation(true))
7557 // Static methods... move them somewhere else?
7558 void ::RestoreCaret()
7560 if(guiApp.caretOwner)
7561 guiApp.caretOwner.UpdateCaret(false, false);
7564 void ::FreeMouseRange()
7566 guiApp.interfaceDriver.SetMouseRange(null, null);
7570 bool MenuFileClose(MenuItem selection, Modifiers mods)
7572 Window document = activeChild;
7574 document.Destroy(0);
7578 bool MenuFileExit(MenuItem selection, Modifiers mods)
7584 bool MenuFileSave(MenuItem selection, Modifiers mods)
7589 #if !defined(__EMSCRIPTEN__)
7590 fileMonitor.fileName = null;
7594 if(OnSaveFile(fileName))
7596 //if(OnFileModified != Window::OnFileModified)
7599 #if !defined(__EMSCRIPTEN__)
7600 fileMonitor.fileName = fileName;
7607 MessageBox dialog { master = master, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7608 DialogResult answer = dialog.Modal();
7610 if(answer != yes) return (bool)answer;
7613 return MenuFileSaveAs(selection, mods);
7616 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7618 DialogResult result = (DialogResult)bool::true;
7619 FileDialog fileDialog = saveDialog;
7624 fileDialog = FileDialog {};
7629 fileDialog.filePath = fileName;
7632 char filePath[MAX_FILENAME];
7633 sprintf(filePath, "Untitled %d", documentID);
7634 fileDialog.filePath = filePath;
7636 #if !defined(__EMSCRIPTEN__)
7637 fileMonitor.fileName = null;
7640 fileDialog.type = save;
7641 fileDialog.text = $"Save As";
7645 fileDialog.master = master.parent ? master : this;
7646 if(fileDialog.Modal() == ok)
7648 const char * filePath = fileDialog.filePath;
7650 if(OnSaveFile(filePath))
7653 property::fileName = filePath;
7654 NotifySaved(master, this, filePath);
7659 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7660 DialogResult answer = dialog.Modal();
7675 #if !defined(__EMSCRIPTEN__)
7676 //if(OnFileModified != Window::OnFileModified && fileName)
7679 fileMonitor.fileName = fileName;
7684 return (bool)result; // Actually returning result from Yes/NoCancel message box
7687 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7689 Window document = activeChild;
7691 for(document = children.first; document; document = next)
7693 next = document.next;
7694 if(document.style.isDocument || document.fileName)
7695 document.MenuFileSave(selection, mods);
7700 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7704 for(document = children.first; document; document = document.next)
7705 //if(document.style.isDocument && document.state == minimized)
7706 if(document.style.isActiveClient && document.state == minimized)
7707 document.SetState(minimized, false, mods);
7711 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7713 Window document = activeChild;
7716 Window firstDocument = null;
7718 OldLink cycle = document.cycle.prev;
7723 if(child.style.isActiveClient && !child.style.hidden)
7727 firstDocument = child;
7728 if(child.state == minimized)
7729 child.SetState(minimized, false, mods);
7732 child.positionID = id++;
7733 child.SetState(normal, false, mods);
7734 child.anchor.left.type = cascade;
7737 child.normalSizeAnchor = *&child.sizeAnchor;
7738 child.normalAnchor = child.anchor;
7740 // Break the anchors for moveable/resizable windows
7741 if(child.style.fixed)
7743 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7745 (*&child.normalAnchor).left = x;
7746 (*&child.normalAnchor).top = y;
7747 (*&child.normalAnchor).right.type = none;
7748 (*&child.normalAnchor).bottom.type = none;
7749 (*&child.normalSizeAnchor).isClientW = false;
7750 (*&child.normalSizeAnchor).isClientH = false;
7751 (*&child.normalSizeAnchor).size.w = w;
7752 (*&child.normalSizeAnchor).size.h = h;
7753 child.anchored = false;
7756 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7758 child.stateAnchor = child.normalAnchor;
7759 child.stateSizeAnchor = child.normalSizeAnchor;
7761 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7762 child.Position(x, y, w, h, true, true, true, true, false, false);
7767 last = children.last;
7768 if(!child.style.stayOnTop)
7769 for(; last && last.style.stayOnTop; last = last.prev);
7770 children.Move(child, last);
7771 childrenOrder.Move(child.order, childrenOrder.last);
7773 if(cycle == document.cycle) break;
7777 firstDocument.Activate();
7782 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7789 // Close all closes all active clients, not all documents
7790 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7792 Window next, document;
7794 for(document = children.first; document; document = next)
7796 for(next = document.next; next && !next.style.isActiveClient; next = next.next);
7797 if(document.style.isActiveClient)
7798 if(!document.Destroy(0) && !document.style.hidden)
7804 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7806 if(style.hasMaximize && state != maximized)
7807 SetState(maximized, 0, 0);
7811 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7813 if(style.hasMinimize && state != minimized)
7815 SetState(minimized, 0, 0);
7816 parent.CycleChildren(false, true, false, true);
7821 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7823 MenuMoveOrSize(false, selection ? true : false);
7827 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7829 CycleChildren(false, true, false, true);
7833 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7835 CycleChildren(true, true, false, true);
7839 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7841 MenuMoveOrSize(true, true);
7845 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7848 SetState(normal, 0, 0);
7852 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7855 int64 id = selection.id;
7856 OldLink cycle = activeClient.cycle;
7858 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7861 Window sibling = cycle.data;
7862 if(sibling.style.isActiveClient && sibling.visible && !sibling.style.nonClient)
7870 document = cycle.data;
7871 document.Activate();
7873 //if(activeChild.state == maximized)
7874 // document.SetState(maximized, false, mods);
7875 //else if(document.state == minimized)
7876 // document.SetState(normal, false, mods);
7880 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7882 stayOnTop = !style.stayOnTop;
7886 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7888 Window document = activeChild;
7891 Window firstDocument = null;
7892 OldLink cycle = document.cycle;
7896 Window child = cycle.data;
7897 if(child.style.isActiveClient && !child.style.hidden)
7899 if(!firstDocument) firstDocument = child;
7900 if(child.state == minimized)
7901 child.SetState(minimized, false, mods);
7904 child.positionID = id++;
7905 child.SetState(normal, false, mods);
7906 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7908 child.anchor.left.type = hTiled;
7911 child.normalSizeAnchor = *&child.sizeAnchor;
7912 child.normalAnchor = child.anchor;
7914 // Break the anchors for moveable/resizable windows
7915 if(child.style.fixed)
7917 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7919 (*&child.normalAnchor).left = x;
7920 (*&child.normalAnchor).top = y;
7921 (*&child.normalAnchor).right.type = none;
7922 (*&child.normalAnchor).bottom.type = none;
7923 (*&child.normalSizeAnchor).isClientW = false;
7924 (*&child.normalSizeAnchor).isClientH = false;
7925 (*&child.normalSizeAnchor).size.w = w;
7926 (*&child.normalSizeAnchor).size.h = h;
7927 child.anchored = false;
7930 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7932 child.stateAnchor = child.normalAnchor;
7933 child.stateSizeAnchor = child.normalSizeAnchor;
7935 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7936 child.Position(x,y, w, h, true, true, true, true, false, true);
7941 if((cycle = cycle.next) == document.cycle) break;
7944 firstDocument.Activate();
7949 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7951 Window document = activeChild;
7954 Window firstDocument = null;
7956 OldLink cycle = document.cycle;
7961 //if(child.style.isDocument)
7962 if(child.style.isActiveClient && !child.style.hidden)
7964 if(!firstDocument) firstDocument = child;
7965 if(child.state == minimized)
7966 child.SetState(minimized, false, mods);
7969 child.positionID = id++;
7970 child.SetState(normal, false, mods);
7971 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7973 child.anchor.left.type = vTiled;
7976 child.normalSizeAnchor = *&child.sizeAnchor;
7977 child.normalAnchor = child.anchor;
7979 // Break the anchors for moveable/resizable windows
7980 if(child.style.fixed)
7982 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7984 (*&child.normalAnchor).left = x;
7985 (*&child.normalAnchor).top = y;
7986 (*&child.normalAnchor).right.type = none;
7987 (*&child.normalAnchor).bottom.type = none;
7988 (*&child.normalSizeAnchor).isClientW = false;
7989 (*&child.normalSizeAnchor).isClientH = false;
7990 (*&child.normalSizeAnchor).size.w = w;
7991 (*&child.normalSizeAnchor).size.h = h;
7992 child.anchored = false;
7995 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7997 child.stateAnchor = child.normalAnchor;
7998 child.stateSizeAnchor = child.normalSizeAnchor;
8000 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
8001 child.Position(x,y, w, h, true, true, true, true, false, true);
8006 if((cycle = cycle.next) == document.cycle) break;
8009 firstDocument.Activate();
8014 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
8018 master = this; isModal = true;
8020 void NotifyDestroyed(Window window, DialogResult result)
8022 Window document = (Window)(intptr)result;
8025 if(activeChild.state == maximized)
8026 document.SetState(maximized, false, 0);
8027 else if(document.state == minimized)
8028 document.SetState(normal, false, 0);
8029 document.Activate();
8037 virtual bool OnCreate(void);
8038 virtual void OnDestroy(void);
8039 virtual void OnDestroyed(void);
8040 virtual bool OnClose(bool parentClosing);
8041 virtual bool OnStateChange(WindowState state, Modifiers mods);
8042 virtual bool OnPostCreate(void);
8043 virtual bool OnMoving(int *x, int *y, int w, int h);
8044 virtual bool OnResizing(int *width, int *height);
8045 virtual void OnResize(int width, int height);
8046 virtual void OnPosition(int x, int y, int width, int height);
8047 virtual bool OnLoadGraphics(void);
8048 virtual void OnApplyGraphics(void);
8049 virtual void OnUnloadGraphics(void);
8050 virtual void OnRedraw(Surface surface);
8051 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
8052 virtual void OnActivateClient(Window client, Window previous);
8053 virtual bool OnKeyDown(Key key, unichar ch);
8054 virtual bool OnKeyUp(Key key, unichar ch);
8055 virtual bool OnKeyHit(Key key, unichar ch);
8056 virtual bool OnSysKeyDown(Key key, unichar ch);
8057 virtual bool OnSysKeyUp(Key key, unichar ch);
8058 virtual bool OnSysKeyHit(Key key, unichar ch);
8059 virtual bool OnMouseOver(int x, int y, Modifiers mods);
8060 virtual bool OnMouseLeave(Modifiers mods);
8061 virtual bool OnMouseMove(int x, int y, Modifiers mods);
8062 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
8063 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
8064 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
8065 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
8066 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
8067 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
8068 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
8069 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
8070 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
8071 virtual bool OnMultiTouch(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods);
8072 virtual void OnMouseCaptureLost(void);
8073 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
8074 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
8075 virtual void OnDrawOverChildren(Surface surface);
8076 virtual bool OnFileModified(FileChange fileChange, const char * param);
8077 virtual bool OnSaveFile(const char * fileName);
8079 // Virtual Methods -- Children management (To support Stacker, for lack of built-in auto-layout)
8080 // Note: A 'client' would refer to isActiveClient, rather than
8081 // being confined to the 'client area' (nonClient == false)
8082 virtual void OnChildAddedOrRemoved(Window child, bool removed);
8083 virtual void OnChildVisibilityToggled(Window child, bool visible);
8084 virtual void OnChildResized(Window child, int x, int y, int w, int h);
8086 // Skins Virtual Functions
8087 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
8088 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
8089 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
8094 virtual void ShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
8095 virtual void PreShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
8096 virtual bool IsMouseMoving(int x, int y, int w, int h)
8100 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY)
8104 virtual void UpdateNonClient();
8105 virtual void SetBox(Box box); // This is used in the MySkin skin
8106 virtual bool IsInside(int x, int y)
8108 return box.IsPointInside({x, y});
8110 virtual bool IsOpaque()
8112 return (!style.drawBehind || background.a == 255);
8116 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
8117 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
8118 virtual void Window::NotifySaved(Window window, const char * filePath);
8123 property Window parent
8125 property_category $"Layout"
8128 if(value || guiApp.desktop)
8131 Window oldParent = parent;
8132 Anchor anchor = this.anchor;
8134 if(value && value.IsDescendantOf(this)) return;
8135 if(value && value == this)
8137 if(!value) value = guiApp.desktop;
8139 if(value == oldParent) return;
8141 if(!master || (master == this.parent && master == guiApp.desktop))
8142 property::master = value;
8146 parent.children.Remove(this);
8150 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
8151 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
8152 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
8153 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
8157 last = value.children.last;
8159 if(style.isDocument)
8162 parent.numDocuments--;
8163 documentID = value.GetDocumentID();
8166 if(style.isActiveClient && !style.hidden)
8168 if(parent && parent != guiApp.desktop && !(style.hidden))
8170 if(state == minimized) parent.numIcons--;
8171 parent.numPositions--;
8175 if(!style.stayOnTop)
8176 for(; last && last.style.stayOnTop; last = last.prev);
8178 value.children.Insert(last, this);
8180 // *** NEW HERE: ***
8182 parent.childrenCycle.Delete(cycle);
8184 parent.childrenOrder.Delete(order);
8187 // *** TODO: Added this here to solve crash on setting parent to null before destroying/destructing ***
8188 // Should something else be done?
8189 if(parent && parent.activeChild == this)
8190 parent.activeChild = null;
8191 if(parent && parent.activeClient == this)
8192 parent.activeClient = null;
8198 int x = position.x, y = position.y, w = size.w, h = size.h;
8202 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
8203 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
8205 vpw = value.clientSize.w;
8206 vph = value.clientSize.h;
8212 else if(style.fixed)
8214 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
8215 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
8218 anchor = this.anchor;
8220 if(anchor.left.type == offset) anchor.left.distance = x;
8221 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
8222 if(anchor.top.type == offset) anchor.top.distance = y;
8223 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
8224 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
8225 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
8226 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
8227 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
8228 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
8229 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
8231 if(!anchor.left.type && !anchor.right.type)
8233 anchor.horz.distance = (x + w / 2) - (vpw / 2);
8234 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
8236 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
8237 if(!anchor.top.type && !anchor.bottom.type)
8239 anchor.vert.distance = (y + h / 2) - (vph / 2);
8240 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
8242 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
8245 parent.OnChildAddedOrRemoved(this, false);
8251 parent.childrenCycle.Insert(
8252 // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
8253 //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8255 cycle = OldLink { data = this });
8256 parent.childrenOrder.Insert(
8257 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8258 order = OldLink { data = this });
8261 if(!style.hidden && style.isActiveClient)
8263 positionID = parent.GetPositionID(this);
8264 parent.numPositions++;
8265 if(state == minimized) parent.numIcons--;
8268 // *** FONT INHERITANCE ***
8269 if(!setFont && oldParent)
8270 stopwatching(oldParent, font);
8274 RemoveResource(systemFont);
8277 // TESTING WITH WATCHERS:
8278 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8279 // usedFont = setFont ? setFont : (systemFont);
8283 if(guiApp.currentSkin)
8285 systemFont = guiApp.currentSkin.SystemFont();
8288 usedFont = systemFont;
8289 AddResource(systemFont);
8297 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8306 if(value.rootWindow && value.rootWindow.display && rootWindow && created)
8308 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
8309 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
8312 UnloadGraphics(false);
8315 LoadGraphics(false, false);
8318 if(value.rootWindow != rootWindow)
8319 DisplayModeChanged();
8323 scrolledPos.x = MININT; // Prevent parent update
8325 bool anchored = this.anchored;
8326 property::anchor = anchor;
8327 this.anchored = anchored;
8332 if(guiApp.currentSkin)
8333 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
8335 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8336 Position(x, y, w, h, true, true, true, true, false, true);
8341 // else parent = value;
8343 oldParent.OnChildAddedOrRemoved(this, true);
8346 get { return parent; }
8349 property Window master
8351 property_category $"Behavior"
8354 //if(this == value) return;
8355 if(value && value.IsSlaveOf(this)) return;
8361 OldLink slaveHolder;
8362 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
8363 if(slaveHolder.data == this)
8365 master.slaves.Delete(slaveHolder);
8372 value.slaves.Add(OldLink { data = this });
8377 master.hotKeys.Remove(hotKey);
8378 value.hotKeys.Add(hotKey);
8381 if(master && master.defaultControl == this)
8382 master.defaultControl = null;
8384 if(style.isDefault && !value.defaultControl)
8385 value.defaultControl = this;
8390 get { return master ? master : parent; }
8393 property const char * caption
8395 property_category $"Appearance"
8402 caption = new char[strlen(value)+1];
8404 strcpy(caption, value);
8409 get { return caption; }
8414 property_category $"Behavior"
8423 master.hotKeys.Add(hotKey = HotKeySlot { });
8427 hotKey.window = this;
8432 master.hotKeys.Delete(hotKey);
8437 get { return hotKey ? hotKey.key : 0; }
8440 property Color background
8442 property_category $"Appearance"
8445 background.color = value;
8450 if(this == rootWindow)
8451 guiApp.interfaceDriver.SetRootWindowColor(this);
8454 get { return background.color; }
8457 property Percentage opacity
8459 property_category $"Appearance"
8462 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
8463 drawBehind = (background.a == 255) ? false : true;
8465 get { return background.a / 255.0f; }
8468 property Color foreground
8470 property_category $"Appearance"
8478 get { return foreground; }
8481 property BorderStyle borderStyle
8483 property_category $"Appearance"
8486 if(!((BorderBits)value).fixed)
8488 style.hasClose = false;
8489 style.hasMaximize = false;
8490 style.hasMinimize = false;
8491 nativeDecorations = false;
8493 style.borderBits = value;
8497 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8499 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8500 Position(x, y, w, h, true, true, true, true, false, true);
8501 CreateSystemChildren();
8504 get { return (BorderStyle)style.borderBits; }
8507 property Size minClientSize
8509 property_category $"Layout"
8510 set { minSize = value; }
8511 get { value = minSize; }
8514 property Size maxClientSize
8516 property_category $"Layout"
8517 set { maxSize = value; }
8518 get { value = maxSize; }
8521 property bool hasMaximize
8523 property_category $"Window Style"
8526 style.hasMaximize = value;
8527 if(value) { style.fixed = true; style.contour = true; }
8531 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8533 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8534 Position(x, y, w, h, true, true, true, true, false, true);
8536 CreateSystemChildren();
8539 get { return style.hasMaximize; }
8542 property bool hasMinimize
8544 property_category $"Window Style"
8547 style.hasMinimize = value;
8548 if(value) { style.fixed = true; style.contour = true; }
8552 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8554 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8555 Position(x, y, w, h, true, true, true, true, false, true);
8557 CreateSystemChildren();
8560 get { return style.hasMinimize; }
8563 property bool hasClose
8565 property_category $"Window Style"
8568 style.hasClose = value;
8569 if(value) { style.fixed = true; style.contour = true; }
8573 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8574 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8575 Position(x, y, w, h, true, true, true, true, false, true);
8576 CreateSystemChildren();
8579 get { return style.hasClose; }
8582 property bool nonClient
8584 property_category $"Layout"
8587 style.nonClient = value;
8589 style.stayOnTop = true;
8591 get { return style.nonClient; }
8594 property bool inactive
8596 property_category $"Behavior"
8601 // *** NEW HERE: ***
8605 parent.childrenCycle.Delete(cycle);
8607 parent.childrenOrder.Delete(order);
8614 active = false; // true;
8615 if(parent.activeChild == this)
8616 parent.activeChild = null;
8617 if(parent.activeClient == this)
8618 parent.activeClient = null;
8627 parent.childrenCycle.Insert(
8628 // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
8629 //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8631 cycle = OldLink { data = this });
8633 parent.childrenOrder.Insert(
8634 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8635 order = OldLink { data = this });
8638 style.inactive = value;
8640 get { return style.inactive; }
8643 property bool clickThrough
8645 property_category $"Behavior"
8646 set { style.clickThrough = value; }
8647 get { return style.clickThrough; }
8650 property bool isRemote
8652 property_category $"Behavior"
8653 set { style.isRemote = value; }
8654 get { return style.isRemote; }
8657 property bool noCycle
8659 property_category $"Behavior"
8660 set { style.noCycle = value; }
8661 get { return style.noCycle; }
8664 property bool isModal
8666 property_category $"Behavior"
8667 set { style.modal = value; }
8668 get { return style.modal; }
8671 property bool interim
8673 property_category $"Behavior"
8674 set { style.interim = value; }
8675 get { return style.interim; }
8678 property bool tabCycle
8680 property_category $"Behavior"
8681 set { style.tabCycle = value; }
8682 get { return style.tabCycle; }
8685 property bool isDefault
8687 property_category $"Behavior"
8695 for(sibling = parent.children.first; sibling; sibling = sibling.next)
8696 if(sibling != this && sibling.style.isDefault)
8697 sibling.style.isDefault = false;*/
8698 if(master.defaultControl)
8699 master.defaultControl.style.isDefault = false;
8700 master.defaultControl = this;
8702 else if(master.defaultControl == this)
8703 master.defaultControl = null;
8707 style.isDefault = value;
8709 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8711 get { return style.isDefault; }
8714 property bool drawBehind
8716 property_category $"Window Style"
8717 set { style.drawBehind = value; }
8718 get { return style.drawBehind; }
8721 property bool hasMenuBar
8723 property_category $"Window Style"
8733 if(created && !menuBar)
8740 anchor = Anchor { top = 23, left = 1, right = 1 },
8742 inactive = true, nonClient = true
8747 else if(created && menuBar)
8752 style.hasMenuBar = value;
8754 get { return style.hasMenuBar; }
8757 property bool hasStatusBar
8759 property_category $"Window Style"
8766 statusBar = StatusBar { this };
8774 style.hasStatusBar = value;
8776 get { return style.hasStatusBar; }
8778 property bool stayOnTop
8780 property_category $"Window Style"
8785 if(created && !style.stayOnTop)
8787 if(rootWindow == this)
8788 guiApp.interfaceDriver.OrderRootWindow(this, true);
8789 else if(parent.children.last != this)
8791 parent.children.Move(this, parent.children.last);
8795 style.stayOnTop = true;
8799 if(created && style.stayOnTop)
8801 if(rootWindow == this)
8802 guiApp.interfaceDriver.OrderRootWindow(this, false);
8809 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8810 order && ((Window)order.data).style.stayOnTop;
8811 order = (order == parent.childrenOrder.first) ? null : order.prev);
8812 last = order ? order.data : null;
8816 for(last = parent.children.last;
8817 last && last.style.stayOnTop;
8821 parent.children.Move(this, last);
8825 style.stayOnTop = false;
8828 get { return style.stayOnTop; }
8833 property_category $"Window Style"
8843 if(menuBar && !value)
8850 if(!menuBar && style.hasMenuBar && value)
8854 this, menu = value, isMenuBar = true,
8855 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8856 inactive = true, nonClient = true
8860 UpdateActiveDocument(null);
8863 get { return menu; }
8866 property FontResource font
8868 property_category $"Appearance"
8870 isset { return setFont ? true : false; }
8875 if(value && !setFont) { stopwatching(parent, font); }
8876 else if(!value && setFont)
8882 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8891 RemoveResource(setFont);
8896 RemoveResource(systemFont);
8903 AddResource(setFont);
8906 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8909 systemFont = guiApp.currentSkin.SystemFont();
8911 usedFont = systemFont;
8912 AddResource(systemFont);
8920 get { return usedFont; }
8923 property SizeAnchor sizeAnchor
8925 property_category $"Layout"
8928 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8929 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8930 sizeAnchor.isClientW != sizeAnchor.isClientH;
8937 normalSizeAnchor = sizeAnchor;
8939 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8941 stateAnchor = normalAnchor;
8942 stateSizeAnchor = normalSizeAnchor;
8944 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8945 Position(x,y, w, h, true, true, true, true, false, true);
8952 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8953 sizeAnchor.isClientW,
8954 sizeAnchor.isClientH
8961 property_category $"Layout"
8964 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8965 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8966 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8972 sizeAnchor.isClientW = false;
8973 sizeAnchor.isClientH = false;
8974 sizeAnchor.size = value;
8976 normalSizeAnchor = sizeAnchor;
8978 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8980 stateAnchor = normalAnchor;
8981 stateSizeAnchor = normalSizeAnchor;
8983 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8984 Position(x, y, w, h, true, true, true, true, false, true);
8985 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
8988 get { value = size; }
8991 property Size clientSize
8993 property_category $"Layout"
8996 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8997 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8998 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
9003 sizeAnchor.isClientW = true;
9004 sizeAnchor.isClientH = true;
9005 sizeAnchor.size = value;
9007 normalSizeAnchor = sizeAnchor;
9009 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9011 stateAnchor = normalAnchor;
9012 stateSizeAnchor = normalSizeAnchor;
9014 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9015 Position(x,y, w, h, true, true, true, true, false, true);
9016 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
9019 get { value = this ? clientSize : { 0, 0 }; }
9022 property Size initSize { get { value = sizeAnchor.size; } };
9024 property Anchor anchor
9026 property_category $"Layout"
9027 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
9033 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
9035 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
9036 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
9038 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
9040 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
9041 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
9045 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
9047 anchor.left.distance = 0;
9048 anchor.horz.type = 0;
9050 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
9052 anchor.top.distance = 0;
9053 anchor.vert.type = 0;
9062 normalAnchor = anchor;
9064 // Break the anchors for moveable/resizable windows
9065 /*if(style.fixed ) //&& value.left.type == cascade)
9067 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
9069 this.anchor = normalAnchor = Anchor { left = x, top = y };
9070 normalSizeAnchor = SizeAnchor { { w, h } };
9073 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9075 stateAnchor = normalAnchor;
9076 stateSizeAnchor = normalSizeAnchor;
9078 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9079 Position(x, y, w, h, true, true, true, true, false, true);
9088 get { value = this ? anchor : Anchor { }; }
9091 property Point position
9093 property_category $"Layout"
9096 if(value == null) return;
9098 anchor.left = value.x;
9099 anchor.top = value.y;
9100 anchor.right.type = none;
9101 anchor.bottom.type = none;
9106 normalAnchor = anchor;
9108 // Break the anchors for moveable/resizable windows
9112 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9114 normalAnchor.left = x;
9115 normalAnchor.top = y;
9116 normalAnchor.right.type = none;
9117 normalAnchor.bottom.type = none;
9118 normalSizeAnchor.size.width = w;
9119 normalSizeAnchor.size.height = h;
9123 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9125 stateAnchor = normalAnchor;
9126 stateSizeAnchor = normalSizeAnchor;
9128 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9129 Position(x,y, w, h, true, true, true, true, false, true);
9133 get { value = position; }
9136 property bool disabled
9138 property_category $"Behavior"
9141 if(this && disabled != value)
9148 get { return (bool)disabled; }
9151 property bool isEnabled
9156 for(parent = this; parent; parent = parent.parent)
9163 property WindowState state
9165 property_category $"Behavior"
9166 set { SetState(value, false, 0); }
9167 get { return this ? state : 0; }
9170 property bool visible
9172 property_category $"Behavior"
9175 if(this && !value && !style.hidden && parent)
9177 bool wasActiveChild = parent.activeChild == this;
9178 Window client = null;
9180 style.hidden = true;
9181 if(style.isActiveClient)
9183 parent.numPositions--;
9184 if(state == minimized) parent.numIcons--;
9189 OldLink prevOrder = null;
9191 if(rootWindow == this)
9192 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
9195 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
9198 box.left -= parent.clientStart.x;
9199 box.top -= parent.clientStart.y;
9200 box.right -= parent.clientStart.x;
9201 box.bottom -= parent.clientStart.y;
9205 if(_isModal && master && master.modalSlave == this)
9206 master.modalSlave = null;
9210 OldLink tmpPrev = order.prev;
9211 client = tmpPrev ? tmpPrev.data : null;
9212 if(client && !client.style.hidden && !client.destroyed && client.created)
9213 prevOrder = tmpPrev;
9216 client = tmpPrev ? tmpPrev.data : null;
9217 if(client == this) { client = null; break; }
9218 if(client && ((client.style.hidden) || client.destroyed || !client.created))
9220 tmpPrev = client.order.prev;
9225 prevOrder = tmpPrev;
9230 // If this window can be an active client, make sure the next window we activate can also be one
9231 if(!style.nonClient && style.isActiveClient)
9233 tmpPrev = prevOrder;
9236 client = tmpPrev ? tmpPrev.data : null;
9237 if(client == this) { client = null; break; }
9238 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
9240 tmpPrev = client.order.prev;
9245 prevOrder = tmpPrev;
9249 if(client && client.style.hidden) client = null;
9253 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
9255 if(order && prevOrder && prevOrder.data != this)
9256 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
9258 ActivateEx(false, false, false, true, null, null);
9260 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
9261 if(parent.activeClient == this)
9263 parent.activeClient = null;
9264 parent.UpdateActiveDocument(null);
9267 else if(parent.activeClient == this)
9269 parent.activeClient = client;
9270 parent.UpdateActiveDocument(this);
9273 // *** Not doing this anymore ***
9276 parent.childrenCycle.Delete(cycle);
9278 parent.childrenOrder.Delete(order);
9283 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9288 else if(this && value && style.hidden)
9290 style.hidden = false;
9293 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9294 if(rootWindow == this)
9295 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
9297 if(_isModal && master)
9298 master.modalSlave = this;
9300 if(style.isActiveClient)
9302 positionID = parent.GetPositionID(this);
9303 parent.numPositions++;
9304 if(state == minimized) parent.numIcons++;
9307 // *** NOT DOING THIS ANYMORE ***
9309 if(!(style.inactive))
9311 if(!(style.noCycle))
9313 cycle = parent.childrenCycle.AddAfter(
9314 (parent.activeChild && parent.activeChild.cycle) ?
9315 parent.activeChild.cycle.prev : null, sizeof(OldLink));
9318 order = parent.childrenOrder.AddAfter(
9319 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
9326 if(true || !parent.activeChild)
9327 ActivateEx(true, false, true, true, null, null);
9329 if(creationActivation == activate && guiApp.desktop.active)
9330 ActivateEx(true, false, true, true, null, null);
9331 else if((creationActivation == activate || creationActivation == flash) && !object)
9334 if(this == rootWindow)
9338 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9342 ConsequentialMouseMove(false);
9348 style.hidden = !value;
9351 get { return (style.hidden || !setVisible) ? false : true; }
9354 property bool isDocument
9356 property_category $"Document"
9357 set { style.isDocument = value; if(value) SetupFileMonitor(); }
9358 get { return style.isDocument; }
9361 property bool mergeMenus
9363 property_category $"Window Style"
9364 set { mergeMenus = value; }
9365 get { return (bool)mergeMenus; }
9368 property bool hasHorzScroll
9370 property_category $"Window Style"
9375 if(!style.hasHorzScroll && created)
9377 CreateSystemChildren();
9378 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9381 else if(style.hasHorzScroll)
9385 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9387 style.hasHorzScroll = value;
9390 get { return style.hasHorzScroll; }
9393 property bool hasVertScroll
9395 property_category $"Window Style"
9400 if(!style.hasVertScroll && created)
9402 style.hasVertScroll = true;
9403 CreateSystemChildren();
9404 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9407 else if(style.hasVertScroll)
9411 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9413 style.hasVertScroll = value;
9415 get { return style.hasVertScroll; }
9418 property bool dontHideScroll
9420 property_category $"Behavior"
9423 scrollFlags.dontHide = value;
9426 //UpdateScrollBars(true, true);
9427 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9431 // UpdateScrollBars(true, true);
9432 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9435 get { return scrollFlags.dontHide; }
9438 property bool dontScrollVert
9440 property_category $"Behavior"
9441 set { style.dontScrollVert = value; }
9442 get { return style.dontScrollVert; }
9444 property bool dontScrollHorz
9446 property_category $"Behavior"
9447 set { style.dontScrollHorz = value; }
9448 get { return style.dontScrollHorz; }
9451 property bool snapVertScroll
9453 property_category $"Behavior"
9456 scrollFlags.snapY = value;
9457 if(sbv) sbv.snap = value;
9459 get { return scrollFlags.snapY; }
9461 property bool snapHorzScroll
9463 property_category $"Behavior"
9466 scrollFlags.snapX = value;
9467 if(sbh) sbh.snap = value;
9469 get { return scrollFlags.snapX; }
9472 property Point scroll
9474 property_category $"Behavior"
9475 set { if(this) SetScrollPosition(value.x, value.y); }
9476 get { value = scroll; }
9479 property bool modifyVirtualArea
9481 property_category $"Behavior"
9482 set { modifyVirtArea = value; }
9483 get { return (bool)modifyVirtArea; }
9486 property bool dontAutoScrollArea
9488 property_category $"Behavior"
9489 // Activating a child control out of view will automatically scroll to make it in view
9490 set { noAutoScrollArea = value; }
9491 get { return (bool)noAutoScrollArea; }
9494 property const char * fileName
9496 property_category $"Document"
9501 if(menu && ((!fileName && value) || (fileName && !value)))
9503 MenuItem item = menu.FindItem(MenuFileSave, 0);
9504 if(item) item.disabled = !modifiedDocument && value;
9509 if(value && value[0])
9510 fileName = CopyString(value);
9512 if(parent && this == parent.activeClient)
9513 parent.UpdateActiveDocument(null);
9517 // if(style.isDocument)
9518 #if !defined(__EMSCRIPTEN__)
9520 fileMonitor.fileName = value;
9523 get { return fileName; }
9528 property_category $"Data"
9533 property bool modifiedDocument
9535 property_category $"Document"
9538 if(style.isDocument || fileName)
9542 MenuItem item = menu.FindItem(MenuFileSave, 0);
9543 if(item) item.disabled = !value && fileName;
9547 if(modifiedDocument != value)
9549 modifiedDocument = value;
9550 if(style.isDocument || fileName)
9554 get { return (bool)modifiedDocument; }
9557 property bool showInTaskBar
9559 property_category $"Window Style"
9562 style.showInTaskBar = value;
9563 #if defined(__WIN32__)
9564 Win32UpdateStyle(this);
9567 get { return style.showInTaskBar; }
9569 property FileDialog saveDialog { set { saveDialog = value; } };
9570 property bool isActiveClient
9572 property_category $"Behavior"
9575 if(parent && style.isActiveClient != value && !style.hidden)
9579 if(state == minimized) parent.numIcons++;
9580 parent.numPositions++;
9584 if(state == minimized) parent.numIcons--;
9585 parent.numPositions--;
9588 style.isActiveClient = value;
9590 get { return style.isActiveClient; }
9593 property Cursor cursor
9595 property_category $"Appearance"
9599 SelectMouseCursor();
9601 get { return cursor; }
9604 //#if !defined(ECERE_VANILLA)
9605 property const char * name
9607 property_category $"Design"
9610 return (this && object) ? object.name : null;
9615 activeDesigner.RenameObject(object, value);
9619 property const char * displayDriver
9621 property_category $"Behavior"
9624 dispDriver = GetDisplayDriver(value);
9625 //DisplayModeChanged();
9629 return dispDriver ? dispDriver.name : null;
9633 // RUNTIME PROPERTIES
9634 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9635 property Size scrollArea
9637 property_category $"Behavior"
9641 SetScrollArea(value.w, value.h, false);
9643 SetScrollArea(0,0, true);
9645 get { value = scrollArea; }
9648 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9653 property_category $"Layout"
9654 set { if(this) is3D = value; }
9655 get { return (bool)is3D; }
9658 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9660 // Will be merged with font later
9661 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9662 property Point clientStart { get { value = clientStart; } };
9663 property Point absPosition { get { value = absPosition; } };
9664 property Anchor normalAnchor { get { value = normalAnchor; } };
9665 property SizeAnchor normalSizeAnchor { get { value = normalSizeAnchor; } };
9666 property bool active { get { return (bool)active; } };
9667 property bool created { get { return (bool)created; } };
9668 property bool destroyed { get { return (bool)destroyed; } };
9669 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9670 property Window firstChild { get { return children.first; } };
9671 property Window lastChild { get { return children.last; } };
9672 property Window activeClient { get { return activeClient; } };
9673 property Window activeChild { get { return activeChild; } };
9674 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9675 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9676 property ScrollBar horzScroll { get { return sbh; } };
9677 property ScrollBar vertScroll { get { return sbv; } };
9678 property StatusBar statusBar { get { return statusBar; } };
9679 property Window rootWindow { get { return rootWindow; } };
9680 property bool closing { get { return (bool)closing; } set { closing = value; } };
9681 property int documentID { get { return documentID; } };
9682 property Window previous { get { return prev; } }
9683 property Window next { get { return next; } }
9684 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9685 property PopupMenu menuBar { get { return menuBar; } }
9686 property ScrollBar sbv { get { return sbv; } }
9687 property ScrollBar sbh { get { return sbh; } }
9688 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9689 property void * systemHandle { get { return windowHandle; } }
9690 property Button minimizeButton { get { return sysButtons[0]; } };
9691 property Button maximizeButton { get { return sysButtons[1]; } };
9692 property Button closeButton { get { return sysButtons[2]; } };
9693 property BitmapResource icon
9695 get { return icon; }
9699 if(icon) incref icon;
9701 guiApp.interfaceDriver.SetIcon(this, value);
9704 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9705 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; if(value) nativeDecorations = false; /* Native Decorations are not supported with alphaBlend */ } };
9706 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9707 property GLCapabilities glCapabilities
9709 get { return glCapabilities; }
9712 bool reload = display != null &&
9713 (glCapabilities.nonPow2Textures != value.nonPow2Textures ||
9714 glCapabilities.intAndDouble != value.intAndDouble ||
9715 glCapabilities.vertexBuffer != value.vertexBuffer ||
9716 glCapabilities.compatible != value.compatible ||
9717 glCapabilities.legacyFormats != value.legacyFormats ||
9718 glCapabilities.debug != value.debug ||
9719 glCapabilities.vertexPointer != value.vertexPointer ||
9720 glCapabilities.quads != value.quads);
9722 UnloadGraphics(false);
9724 glCapabilities = value;
9729 LoadGraphics(false, false);
9732 display.glCapabilities = value;
9735 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9736 property bool nativeDecorations
9738 get { return (bool)nativeDecorations; }
9739 set { nativeDecorations = value; }
9740 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
9743 //return (nativeDecorations && (rootWindow == this || (formDesigner && activeDesigner && ((FormDesigner)activeDesigner.classDesigner).form && parent == ((FormDesigner)activeDesigner.classDesigner).form.parent))) != style.fixed;
9744 bool result = false;
9745 if(nativeDecorations)
9747 if(rootWindow == this)
9751 if(formDesigner && activeDesigner)
9753 FormDesigner cd = (FormDesigner)activeDesigner.classDesigner;
9754 Window form = cd ? cd.form : null;
9755 if(form && parent == form.parent)
9760 return result != style.fixed;
9764 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9766 property const char * text
9768 property_category $"Deprecated"
9770 set { property::caption = value; }
9771 get { return property::caption; }
9777 WindowBits style; // Window Style
9778 char * caption; // Name / Caption
9779 Window parent; // Parent window
9780 OldList children; // List of children in Z order
9781 Window activeChild; // Child window having focus
9782 Window activeClient;
9783 Window previousActive; // Child active prior to activating the default child
9784 Window master; // Window owning and receiving notifications concerning this window
9785 OldList slaves; // List of windows belonging to this window
9786 Display display; // Display this window is drawn into
9788 Point position; // Position in parent window client area
9789 Point absPosition; // Absolute position
9790 Point clientStart; // Client area position from (0,0) in this window
9792 Size clientSize; // Client area size
9793 Size scrollArea; // Virtual Scroll area size
9794 Size reqScrollArea; // Requested virtual area size
9795 Point scroll; // Virtual area scrolling position
9796 ScrollBar sbh, sbv; // Scrollbar window handles
9797 Cursor cursor; // Mouse cursor used for this window
9800 StatusBar statusBar;
9801 Button sysButtons[3];
9803 Box clientArea; // Client Area box clipped to parent
9805 HotKeySlot hotKey; // HotKey for this window
9809 ScrollFlags scrollFlags;// Window Scrollbar Flags
9810 int64 id; // Control ID
9812 ColorAlpha background; // Background color used to draw the window area
9814 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9815 OldList childrenCycle; // Cycling order
9816 OldLink cycle; // Element of parent's cycling order
9817 OldList childrenOrder; // Circular Z-Order
9818 OldLink order; // Element of parent's circular Z-Order
9819 Window modalSlave; // Slave window blocking this window's interaction
9821 Window rootWindow; // Topmost system managed window
9822 void * windowHandle; // System window handle
9824 DialogResult returnCode;// Return code for modal windows
9826 Point sbStep; // Scrollbar line scrolling steps
9829 SizeAnchor stateSizeAnchor;
9831 Anchor normalAnchor;
9832 SizeAnchor normalSizeAnchor;
9834 Size skinMinSize; // Minimal window size based on style
9835 Point scrolledPos; // Scrolled position
9836 Box box; // Window box clipped to parent
9837 Box * against; // What to clip the box to
9839 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9840 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9841 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9842 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9843 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9844 Point scrolledArea; // Distance to scroll area by
9845 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9847 OldList hotKeys; // List of the hotkeys of all children
9848 Window defaultControl; // Default child control
9852 ColorAlpha * palette; // Color palette used for this window
9854 int caretSize; // Size of caret, non zero if a caret is present
9855 Point caretPos; // Caret position
9857 void * systemParent; // Parent System Window for embedded windows
9863 #if !defined(__EMSCRIPTEN__)
9866 WindowState lastState;
9868 #if !defined(__EMSCRIPTEN__)
9869 FileMonitor fileMonitor;
9872 FontResource setFont, systemFont;
9873 FontResource usedFont;
9874 FontResource captionFont;
9876 FileDialog saveDialog;
9878 SizeAnchor sizeAnchor;
9880 // FormDesigner data
9883 Extent * tempExtents; //[4];
9884 BitmapResource icon;
9886 CreationActivationOption creationActivation;
9887 GLCapabilities glCapabilities;
9888 glCapabilities = { true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true };
9891 bool active:1; // true if window and ancestors are active
9892 bool acquiredInput:1; // true if the window is processing state based input
9893 bool modifiedDocument:1;
9894 bool disabled:1; // true if window cannot interact
9895 bool isForegroundWindow:1;// true while a root window is being activated
9896 bool visible:1; // Visibility flag
9897 bool destroyed:1; // true if window is being destroyed
9898 bool anchored:1; // true if this window is repositioned when the parent resizes
9899 bool dirty:1; // Flag set to true if any descendant must be redrawn
9905 bool modifyVirtArea:1;
9906 bool noAutoScrollArea:1;
9909 bool setVisible:1; // FOR FORM DESIGNER
9915 bool useSharedMemory:1;
9918 bool nativeDecorations:1;
9919 bool manageDisplay:1;
9920 bool formDesigner:1; // True if we this is running in the form editor
9921 bool requireRemaximize:1;
9922 bool noConsequential:1;
9925 // Checks used internally for them not to take effect in FormDesigner
9926 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9927 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9929 WindowController controller;
9931 public property WindowController controller
9933 get { return controller; }
9937 controller.setWindow(null);
9943 controller.setWindow(this);
9948 public property bool noConsequential
9950 set { noConsequential = value; }
9951 get { return noConsequential; }
9955 public class CommonControl : Window
9957 // creationActivation = doNothing;
9960 public property const String toolTip
9962 property_category $"Appearance"
9965 if(created) CommonControl::OnDestroy();
9967 toolTip = value ? ToolTip { tip = value; } : null;
9969 if(created) CommonControl::OnCreate();
9971 get { return toolTip ? toolTip.tip : null; }
9977 // (Very) Ugly work around for the fact that the parent watcher
9978 // won't fire when it's already been disconnected...
9979 eInstance_FireSelfWatchers(toolTip,
9980 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
9986 toolTip.parent = this;
9995 public class Percentage : float
9997 const char * OnGetString(char * string, float * fieldData, bool * needClass)
10001 sprintf(string, "%.2f", this);
10002 c = strlen(string)-1;
10003 for( ; c >= 0; c--)
10005 if(string[c] != '0')
10006 last = Max(last, c);
10007 if(string[c] == '.')
10012 string[last+1] = 0;
10020 public void ApplySkin(Class c, const char * name, void ** vTbl)
10022 char className[1024];
10027 subclass(Window) wc = (subclass(Window))c;
10028 subclass(Window) base = (subclass(Window))c.base;
10030 sprintf(className, "%sSkin_%s", name, c.name);
10031 wc.pureVTbl = c._vTbl;
10032 c._vTbl = new void *[c.vTblSize];
10033 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
10034 sc = eSystem_FindClass(c.module.application, className);
10038 for(m = 0; m < c.base.vTblSize; m++)
10040 if(c._vTbl[m] == base.pureVTbl[m])
10041 c._vTbl[m] = vTbl[m];
10046 for(m = 0; m < c.vTblSize; m++)
10048 if(sc._vTbl[m] != wc.pureVTbl[m])
10049 c._vTbl[m] = sc._vTbl[m];
10053 for(d = c.derivatives.first; d; d = d.next)
10055 ApplySkin(d.data, name, c._vTbl);
10059 public void UnapplySkin(Class c)
10061 subclass(Window) wc = (subclass(Window))c;
10064 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
10067 c._vTbl = wc.pureVTbl;
10068 wc.pureVTbl = null;
10071 for(d = c.derivatives.first; d; d = d.next)
10073 UnapplySkin(d.data);
10077 void CheckFontIntegrity(Window window)
10082 if(window.usedFont && window.usedFont.font == 0xecececec)
10084 FontResource uf = window.usedFont;
10085 char * className = window._class.name;
10086 char * text = window.text;
10089 for(c = window.firstChild; c; c = c.next)
10090 CheckFontIntegrity(c);
10094 public class ControllableWindow : Window
10096 /*WindowController controller;
10097 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
10098 ~ControllableWindow() { delete controller; }*/
10101 class WindowControllerInterface : ControllableWindow
10103 bool OnKeyDown(Key key, unichar ch)
10105 bool result = controller.OnKeyDown ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyDown)((Window)controller.controlled, controller, key, ch) : true;
10108 bool (* onKeyDown)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown];
10110 result = onKeyDown(controller.window, key, ch);
10115 bool OnKeyUp(Key key, unichar ch)
10117 bool result = controller.OnKeyUp ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyUp)((Window)controller.controlled, controller, key, ch) : true;
10120 bool (* onKeyUp)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp];
10122 result = onKeyUp(controller.window, key, ch);
10127 bool OnKeyHit(Key key, unichar ch)
10129 bool result = controller.OnKeyHit ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyHit)((Window)controller.controlled, controller, key, ch) : true;
10132 bool (* onKeyHit)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit];
10134 result = onKeyHit(controller.window, key, ch);
10139 bool OnMouseMove(int x, int y, Modifiers mods)
10141 bool result = controller.OnMouseMove ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMouseMove)((Window)controller.controlled, controller, x, y, mods) : true;
10144 bool(* onMouseMove)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove];
10146 result = onMouseMove(controller.window, x, y, mods);
10151 bool OnLeftButtonDown(int x, int y, Modifiers mods)
10153 bool result = controller.OnLeftButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10156 bool(* onLeftButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown];
10157 if(onLeftButtonDown)
10158 result = onLeftButtonDown(controller.window, x, y, mods);
10163 bool OnLeftButtonUp(int x, int y, Modifiers mods)
10165 bool result = controller.OnLeftButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10168 bool(* onLeftButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp];
10170 result = onLeftButtonUp(controller.window, x, y, mods);
10175 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
10177 bool result = controller.OnLeftDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10180 bool(* onLeftDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick];
10181 if(onLeftDoubleClick)
10182 result = onLeftDoubleClick(controller.window, x, y, mods);
10187 bool OnRightButtonDown(int x, int y, Modifiers mods)
10189 bool result = controller.OnRightButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10192 bool(* onRightButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown];
10193 if(onRightButtonDown)
10194 result = onRightButtonDown(controller.window, x, y, mods);
10199 bool OnRightButtonUp(int x, int y, Modifiers mods)
10201 bool result = controller.OnRightButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10204 bool(* onRightButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp];
10205 if(onRightButtonUp)
10206 result = onRightButtonUp(controller.window, x, y, mods);
10211 bool OnRightDoubleClick(int x, int y, Modifiers mods)
10213 bool result = controller.OnRightDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10216 bool(* onRightDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick];
10217 if(onRightDoubleClick)
10218 result = onRightDoubleClick(controller.window, x, y, mods);
10223 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
10225 bool result = controller.OnMiddleButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10228 bool(* onMiddleButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown];
10229 if(onMiddleButtonDown)
10230 result = onMiddleButtonDown(controller.window, x, y, mods);
10235 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
10237 bool result = controller.OnMiddleButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10240 bool(* onMiddleButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp];
10241 if(onMiddleButtonUp)
10242 result = onMiddleButtonUp(controller.window, x, y, mods);
10247 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
10249 bool result = controller.OnMiddleDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10252 bool(* onMiddleDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick];
10253 if(onMiddleDoubleClick)
10254 onMiddleDoubleClick(controller.window, x, y, mods);
10259 bool OnMultiTouch(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods)
10261 bool result = controller.OnMultiTouch ? ((bool(*)(Window, WindowController, TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers))(void *)controller.OnMultiTouch)((Window)controller.controlled, controller, event, infos, mods) : true;
10264 bool(* onMultiTouch)(Window, TouchPointerEvent, Array<TouchPointerInfo>, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMultiTouch];
10266 onMultiTouch(controller.window, event, infos, mods);
10271 void OnResize(int width, int height)
10273 if(controller.OnResize)
10274 ((void(*)(Window, WindowController, int, int))(void *)controller.OnResize)((Window)controller.controlled, controller, width, height);
10276 void(* onResize)(Window, int, int) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize];
10278 onResize(controller.window, width, height);
10282 void OnRedraw(Surface surface)
10284 if(controller.OnRedraw)
10285 ((void(*)(Window, WindowController, Surface))(void *)controller.OnRedraw)((Window)controller.controlled, controller, surface);
10287 void(* onRedraw)(Window, Surface) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw];
10289 onRedraw(controller.window, surface);
10295 bool result = controller.OnCreate ? ((bool(*)(Window, WindowController))(void *)controller.OnCreate)((Window)controller.controlled, controller) : true;
10298 bool(* onCreate)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate];
10300 result = onCreate(controller.window);
10305 bool OnLoadGraphics()
10307 bool result = controller.OnLoadGraphics ? ((bool(*)(Window, WindowController))(void *)controller.OnLoadGraphics)((Window)controller.controlled, controller) : true;
10310 bool(* onLoadGraphics)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLoadGraphics];
10312 result = onLoadGraphics(controller.window);
10317 void OnUnloadGraphics()
10319 if(controller.OnUnloadGraphics)
10320 ((void(*)(Window, WindowController))(void *)controller.OnUnloadGraphics)((Window)controller.controlled, controller);
10322 void(* onUnloadGraphics)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnUnloadGraphics];
10323 if(onUnloadGraphics)
10324 onUnloadGraphics(controller.window);
10329 public class WindowController<class V>
10331 void setWindow(Window value)
10333 uint size = class(Window).vTblSize;
10337 windowVTbl = new void *[size];
10338 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
10339 if(value._vTbl == value._class._vTbl)
10341 value._vTbl = new void *[value._class.vTblSize];
10342 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
10346 for(c = 0; c < size; c++)
10348 void * function = class(WindowControllerInterface)._vTbl[c];
10349 if(function && function != DefaultFunction)
10350 value._vTbl[c] = function;
10352 value._vTbl[c] = windowVTbl[c];
10358 memcpy(window._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
10364 property Window window
10366 get { return window; }
10368 property V controlled
10370 set { controlled = value; }
10371 get { return controlled; }
10373 // TODO: Add OnStateChange so we can implement SavedConfigWindow as a WindowController instead
10374 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
10375 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
10376 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
10377 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
10378 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
10379 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
10380 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10381 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
10382 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
10383 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10384 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
10385 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
10386 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10387 virtual bool V::OnMultiTouch(WindowController controller, TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods);
10388 virtual void V::OnResize(WindowController controller, int width, int height);
10389 virtual void V::OnRedraw(WindowController controller, Surface surface);
10390 virtual bool V::OnCreate(WindowController controller);
10391 virtual bool V::OnLoadGraphics(WindowController controller);
10392 virtual void V::OnUnloadGraphics(WindowController controller);
10395 public int (** windowVTbl)();
10399 ~WindowController()