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)
4089 if((infos && infos.count) || (event == up || event == pointerUp))
4092 while(result && w != this)
4094 // TODO: How to handle this?
4095 int x = (infos && infos.count) ? infos[0].point.x : 0;
4096 int y = (infos && infos.count) ? infos[0].point.y : 0;
4097 Window msgWindow = GetAtPosition(x,y, false, true, w);
4102 window = (w && !w.disabled) ? w : null;
4104 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
4106 if(!guiApp.windowCaptured.isEnabled)
4107 guiApp.windowCaptured.ReleaseCapture();
4109 window = guiApp.windowCaptured;
4112 if(consequential) mods->isSideEffect = true;
4113 if(!result || (window && window.destroyed)) window = null;
4117 if(window.OnMultiTouch && !window.disabled)
4119 Array<TouchPointerInfo> in = null;
4120 if(infos && infos.count)
4122 in = { size = infos.size };
4123 memcpy(in.array, infos.array, sizeof(TouchPointerInfo) * infos.size);
4127 i.point.x -= (window.absPosition.x + window.clientStart.x);
4128 i.point.y -= (window.absPosition.y + window.clientStart.y);
4130 i.point.x = Max(Min(i.point.x, 32767),-32768);
4131 i.point.y = Max(Min(i.point.y, 32767),-32768);
4136 if(!window.OnMultiTouch(event, in, *mods))
4143 if(!result || !w || !w.clickThrough)
4151 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
4154 bool wasMoving = guiApp.windowMoving ? true : false;
4155 bool wasScrolling = guiApp.windowScrolling ? true : false;
4156 bool firstPass = true;
4158 while(result && w != this)
4160 Window msgWindow = GetAtPosition(x,y, false, true, w);
4161 Window trueWindow = GetAtPosition(x,y, false, false, w);
4162 bool windowDragged = false;
4167 window = (w && !w.disabled) ? w : null;
4169 if(trueWindow) incref trueWindow;
4171 if(consequential) mods->isSideEffect = true;
4173 UpdateMouseMove(x, y, consequential);
4175 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
4177 if(!guiApp.windowCaptured.isEnabled)
4178 guiApp.windowCaptured.ReleaseCapture();
4180 window = guiApp.windowCaptured;
4183 if(trueWindow && activate &&
4184 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
4185 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
4186 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
4187 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
4189 if(mods->alt && !mods->ctrl && !mods->shift)
4191 Window moved = trueWindow;
4192 for(moved = trueWindow; moved; moved = moved.parent)
4193 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
4198 windowDragged = true;
4200 // Cancel the ALT menu toggling...
4201 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4206 if(window && activate &&
4207 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
4208 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
4209 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
4210 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
4212 Window modalWindow = window.FindModal();
4214 /*if(mods->alt && !mods->shift && !mods->ctrl)
4216 Window moved = window;
4217 for(moved = window; moved; moved = moved.parent)
4218 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
4223 windowDragged = true;
4225 // Cancel the ALT menu toggling...
4226 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
4232 Window activateWindow = modalWindow ? modalWindow : window;
4233 if(activateWindow && !activateWindow.isRemote)
4235 bool doActivation = true;
4236 //bool needToDoActivation = false;
4237 Window check = activateWindow;
4239 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
4241 if(!check.style.inactive)
4243 //needToDoActivation = true;
4245 doActivation = false;
4250 if(!needToDoActivation)
4251 doActivation = false;
4254 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
4255 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
4257 // Let the OnLeftButtonDown do the activating instead
4258 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4266 incref activateWindow;
4267 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
4269 delete activateWindow;
4273 if(activateWindow._refCount == 1)
4275 delete activateWindow;
4279 delete activateWindow;
4280 // Trouble with clickThrough, siblings and activation (Fix for nicktick scrolling, siblings/activation endless loops, #844)
4283 mods->isActivate = true;
4287 if(!modalWindow && window && !window.destroyed)
4289 if(!guiApp.windowCaptured || windowDragged)
4291 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
4293 bool moving = ((window.state != maximized &&
4294 window.IsMouseMoving(
4295 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4296 || (guiApp.windowMoving && !guiApp.windowIsResizing);
4298 if(!moving && window.IsMouseResizing(
4299 x - window.absPosition.x,
4300 y - window.absPosition.y,
4301 window.size.w, window.size.h,
4302 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
4304 guiApp.windowIsResizing = true;
4305 guiApp.windowResizingBefore.w = window.size.w;
4306 guiApp.windowResizingBefore.h = window.size.h;
4308 if(guiApp.windowIsResizing || windowDragged || moving)
4311 guiApp.windowMoving = window;
4312 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4313 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4314 guiApp.windowMovingBefore.x = window.position.x;//s;
4315 guiApp.windowMovingBefore.y = window.position.y;//s;
4316 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4317 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4320 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4322 if(window.style.fixed &&
4324 window.IsMouseMoving(
4325 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4327 window.ShowSysMenu(x, y);
4331 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4333 if(window.sbv || window.sbh)
4336 guiApp.windowScrolling = window;
4337 guiApp.windowScrollingStart.x = x;
4338 guiApp.windowScrollingStart.y = y;
4339 guiApp.windowScrollingBefore.x = window.scroll.x;
4340 guiApp.windowScrollingBefore.y = window.scroll.y;
4343 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4345 if(window.style.hasMaximize &&
4346 window.IsMouseMoving(
4347 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4350 (window.state == maximized) ? normal : maximized, false, *mods);
4358 if(guiApp.windowMoving)
4360 if(guiApp.windowMoving.parent)
4362 if(guiApp.windowMoving.style.nonClient)
4363 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4365 guiApp.windowMoving.parent.SetMouseRangeToClient();
4369 window.UpdateDecorations();
4372 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4374 // Log("\n*** LEFT BUTTON UP ***\n");
4375 if(guiApp.windowMoving)
4376 guiApp.windowMoving.StopMoving();
4378 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4380 if(guiApp.windowScrolling)
4382 Window windowScrolling = guiApp.windowScrolling;
4383 guiApp.windowScrolling = null;
4384 windowScrolling.ReleaseCapture();
4388 if(!result || (window && window.destroyed)) window = null;
4390 if(window && window.FindModal())
4393 if(trueWindow && trueWindow.FindModal())
4401 msgWindow = GetAtPosition(x,y, true, false);
4403 msgWindow.SelectMouseCursor();
4406 if(firstPass && (guiApp.windowCaptured || trueWindow))
4408 Window prevWindow = guiApp.prevWindow;
4409 List<Window> overWindows = guiApp.overWindows;
4410 Iterator<Window> it { overWindows };
4414 Window ww = it.data;
4415 if(trueWindow != ww && !trueWindow.IsDescendantOf(ww))
4418 result = ww.OnMouseLeave(*mods);
4420 overWindows.TakeOut(ww);
4424 if(result && guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4426 guiApp.prevWindow.mouseInside = false;
4427 guiApp.prevWindow = null;
4431 if(trueWindow.IsDescendantOf(prevWindow))
4433 if(!overWindows.Find(prevWindow))
4434 overWindows.Add(prevWindow);
4436 // Eventually fix this not to include captured?
4437 else if(!prevWindow.OnMouseLeave(*mods))
4441 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4443 Box box = trueWindow.box;
4444 box.left += trueWindow.absPosition.x;
4445 box.right += trueWindow.absPosition.x;
4446 box.top += trueWindow.absPosition.y;
4447 box.bottom += trueWindow.absPosition.y;
4449 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4451 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4452 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4454 overX = Max(Min(overX, 32767),-32768);
4455 overY = Max(Min(overY, 32767),-32768);
4457 trueWindow.mouseInside = true;
4458 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4462 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4464 for(wi : guiApp.overWindows; wi == trueWindow)
4467 guiApp.overWindows.TakeOut(wi);
4470 guiApp.prevWindow = trueWindow;
4473 guiApp.prevWindow = null;
4475 SelectMouseCursor();
4477 if(window && ((!guiApp.windowMoving && !wasMoving) ||
4478 (wasMoving && guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp)) && !wasScrolling)
4480 int clientX = x - (window.absPosition.x + window.clientStart.x);
4481 int clientY = y - (window.absPosition.y + window.clientStart.y);
4483 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4485 clientX = Max(Min(clientX, 32767),-32768);
4486 clientY = Max(Min(clientY, 32767),-32768);
4488 MouseMethod = (void *)window._vTbl[method];
4490 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4493 if(!MouseMethod(window, clientX, clientY, *mods))
4497 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4498 window.OnMouseLeave(*mods);
4505 if(result && w && w.clickThrough && w.parent)
4510 if(!result || !w || !w.clickThrough)
4518 // --- Mouse cursor management ---
4520 bool KeyMessage(uint method, Key key, unichar character)
4525 if(guiApp.interimWindow)
4526 this = guiApp.interimWindow;
4529 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4533 if(!style.inactive || rootWindow != this)
4535 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4536 Window modalWindow = FindModal();
4537 Window interimMaster = master ? master.rootWindow : null;
4541 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4542 status = OnSysKeyDown(key, character);
4543 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4544 status = OnSysKeyHit(key, character);
4545 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4546 status = OnSysKeyUp(key, character);
4553 // Process Key Message for Internal UI Keyboard actions
4554 if(status && !destroyed && menuBar && state != minimized)
4557 if((SmartKey)key != alt)
4558 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4561 SmartKey sk = (SmartKey) key;
4562 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4564 status = menuBar.KeyMessage(method, key, character);
4569 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4570 menuBar.OnKeyHit(escape, 0);
4572 if(!menuBar.focus && guiApp.caretOwner)
4573 guiApp.caretOwner.UpdateCaret(true, false);
4576 if(!destroyed && status)
4578 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4582 case left: case up: case right: case down:
4583 if(guiApp.windowMoving == this)
4586 int w = guiApp.windowMoving.size.w;
4587 int h = guiApp.windowMoving.size.h;
4588 int x = guiApp.windowMoving.scrolledPos.x;
4589 int y = guiApp.windowMoving.scrolledPos.y;
4593 if(key == down || key == up)
4594 step = Max(step, textCellH);
4596 step = Max(step, textCellW);
4599 if(guiApp.windowIsResizing)
4603 case left: w-=step; break;
4604 case right: w+=step; break;
4605 case up: h-=step; break;
4606 case down: h+=step; break;
4613 case left: x-=step; break;
4614 case right: x+=step; break;
4615 case up: y-=step; break;
4616 case down: y+=step; break;
4620 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4621 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4623 if(!guiApp.windowIsResizing || guiApp.resizeX)
4624 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4626 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4628 if(!guiApp.windowIsResizing || guiApp.resizeY)
4629 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4631 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4633 guiApp.interfaceDriver.SetMousePosition(x, y);
4634 ConsequentialMouseMove(true);
4642 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4644 guiApp.windowMoving.StopMoving();
4645 ConsequentialMouseMove(false);
4653 ShowSysMenu(absPosition.x, absPosition.y);
4661 if(!destroyed && status && state != minimized)
4663 // Process all the way down the children
4664 if(activeChild && !activeChild.disabled)
4666 status = activeChild.KeyMessage(method, key, character);
4668 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4669 key.code != left && key.code != right && key.code != up && key.code != down)
4671 status = activeClient.KeyMessage(method, key, character);
4675 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4677 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4678 // && defaultControl != activeChild)
4680 delete previousActive;
4681 previousActive = activeChild;
4682 if(previousActive) incref previousActive;
4684 ConsequentialMouseMove(false);
4685 if((defaultControl.active ||
4686 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4687 defaultControl.KeyMessage(method, defaultKey, character);
4693 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4695 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4702 ShowSysMenu(absPosition.x, absPosition.y);
4709 if(this != guiApp.desktop)
4711 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4713 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4715 MenuMoveOrSize(key.shift, true);
4719 else if(guiApp.windowMoving)
4721 guiApp.windowMoving.StopMoving();
4722 ConsequentialMouseMove(false);
4730 if(!destroyed && status && state != minimized)
4732 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4736 case tab: case shiftTab:
4738 Window cycleParent = this;
4739 if(this == guiApp.interimWindow && master && !master.style.interim && !cycleParent.style.tabCycle && master.parent)
4740 cycleParent = master.parent;
4742 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4744 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4747 Window child = cycleParent.activeChild;
4749 // Scroll the window to include the active control
4750 if(cycleParent.sbh && !child.style.dontScrollHorz)
4752 if(child.scrolledPos.x < 0)
4753 cycleParent.sbh.Action(Position,
4754 cycleParent.scroll.x + child.scrolledPos.x, 0);
4755 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4756 cycleParent.sbh.Action(Position,
4757 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4759 if(cycleParent.sbv && !child.style.dontScrollVert)
4761 if(child.scrolledPos.y < 0)
4762 cycleParent.sbv.Action(Position,
4763 cycleParent.scroll.y + child.scrolledPos.y, 0);
4764 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4765 cycleParent.sbv.Action(Position,
4766 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4769 cycleParent.ConsequentialMouseMove(false);
4775 case f6: case shiftF6:
4776 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4778 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4779 if(parent == guiApp.desktop)
4780 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4790 if(CycleChildren(key.shift, true, false, true))
4798 // mIRC Style Window Shortcuts
4799 case alt1: case alt2: case alt3: case alt4: case alt5:
4800 case alt6: case alt7: case alt8: case alt9: case alt0:
4805 for(document = children.first; document; document = document.next)
4807 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4809 if(document == activeChild)
4811 if(document.state == minimized)
4812 document.SetState(normal, false, key);
4815 document.SetState(minimized, false, key);
4816 CycleChildren(false, true, false);
4821 if(activeChild.state == maximized && document.style.hasMaximize)
4822 document.SetState(maximized, false, key);
4823 else if(document.state == minimized)
4824 document.SetState(normal, false, key);
4825 document.Activate();
4840 if(!destroyed && status)
4842 if(state == minimized)
4847 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4849 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4851 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4852 previousActive.ActivateEx(true, false, false, true, null, null);
4853 delete previousActive;
4859 if(!destroyed && status)
4861 status = ProcessHotKeys(method, key, character);
4863 if(!destroyed && status && !modalWindow && state != minimized)
4866 status = KeyMethod(this, key, character);
4867 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4868 status = OnKeyHit(key, character);
4869 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4871 bool result = false;
4874 case ctrlUp: case ctrlDown:
4875 if(sbv && !guiApp.windowScrolling)
4876 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4878 case wheelUp: case wheelDown:
4879 if(sbv && !guiApp.windowScrolling)
4881 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4882 // Do we want to do a consequential move regardless of result in this case?
4883 ConsequentialMouseMove(false);
4886 case ctrlPageUp: case ctrlPageDown:
4887 if(sbh && !guiApp.windowScrolling)
4888 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4893 ConsequentialMouseMove(false);
4898 if(status && !destroyed && menuBar && state != minimized)
4899 status = menuBar.KeyMessage(method, key, character);
4901 if(style.interim && /*destroyed && */status && interimMaster)
4903 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4904 status = interimMaster.KeyMessage(method, key, character);
4911 bool ProcessHotKeys(uint method, Key key, unichar character)
4916 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4917 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4918 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4920 Window hotKeyWindow = hotKey.window;
4921 Window parent = hotKeyWindow.parent;
4922 Window prevActiveWindow = activeChild;
4923 // For when sys buttons are placed inside the menu bar
4924 if(parent && parent._class == class(PopupMenu))
4925 parent = parent.parent;
4927 // 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
4928 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1])))
4931 if(prevActiveWindow) incref prevActiveWindow;
4932 incref hotKeyWindow;
4933 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient && !hotKeyWindow.inactive)
4934 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4937 delete hotKeyWindow;
4938 delete prevActiveWindow;
4942 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4943 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4944 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4946 // ********* WORKING ON THIS ***********
4947 if(prevActiveWindow && !guiApp.interimWindow)
4948 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4951 else if(hotKeyWindow.style.inactive)
4952 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4954 delete prevActiveWindow;
4955 delete hotKeyWindow;
4956 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4957 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4961 if(status && tabCycle)
4964 for(child = children.first; child; child = child.next)
4966 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4977 // --- Windows and graphics initialization / termination ---
4978 bool SetupRoot(void)
4982 // Setup relationship with outside world (bb root || !bb)
4983 #if defined(__EMSCRIPTEN__)
4984 if(this == guiApp.desktop)
4986 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4987 (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))
4992 tempExtents = new0 Extent[4];
4997 /*if(guiApp.fullScreenMode)
4998 rootWindow = guiApp.desktop;
5000 //rootWindow = parent.created ? parent.rootWindow : null;
5001 rootWindow = parent.rootWindow;
5004 against = &parent.box;
5006 against = &parent.clientArea;
5009 for(child = children.first; child; child = child.next)
5012 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
5015 bool Setup(bool positionChildren)
5017 bool result = false;
5020 #if defined(__EMSCRIPTEN__)
5021 if(this == guiApp.desktop)
5023 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))))
5026 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
5027 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
5030 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
5032 // This was here, is it really needed?
5033 //guiApp.interfaceDriver.ActivateRootWindow(this);
5037 displaySystem = DisplaySystem { glCapabilities = glCapabilities };
5038 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
5040 delete displaySystem;
5045 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, glCapabilities = glCapabilities, windowDriverData = windowData };
5046 if(display.Create(displaySystem, windowHandle))
5053 // Sometimes icon does not show up on Windows XP if we set here...
5054 // guiApp.interfaceDriver.SetIcon(this, icon);
5056 else if(this != guiApp.desktop)
5058 display = rootWindow ? rootWindow.display : null;
5064 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
5065 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
5067 for(child = children.first; child; child = child.next)
5069 if(child.created && !child.Setup(false))
5072 if(guiApp.modeSwitching && guiApp.fullScreen && child.rootWindow == child)
5073 child.UpdateCaption();
5078 bool SetupDisplay(void)
5080 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
5081 if(is3D) return Window3D_SetupDisplay(this); else
5088 class_data void ** pureVTbl;
5090 bool LoadGraphics(bool creation, bool resetAnchors)
5092 bool result = false;
5093 bool success = false;
5095 WindowState stateBackup = state;
5097 if(((subclass(Window))_class).pureVTbl)
5099 if(_vTbl == _class._vTbl)
5101 _vTbl = ((subclass(Window))_class).pureVTbl;
5106 for(m = 0; m < _class.vTblSize; m++)
5108 if(_vTbl[m] == _class._vTbl[m])
5109 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5113 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
5115 if(_vTbl == ((subclass(Window))_class).pureVTbl)
5117 _vTbl = _class._vTbl;
5122 for(m = 0; m < _class.vTblSize; m++)
5124 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
5125 _vTbl[m] = _class._vTbl[m];
5131 #if !defined(__EMSCRIPTEN__)
5132 guiApp.fullScreenMode ||
5134 this != guiApp.desktop)
5136 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
5142 display.Lock(false);
5143 if(rootWindow == this)
5145 // Set Color Palette
5146 display.SetPalette(palette, true);
5150 if(guiApp.fullScreenMode && this == guiApp.desktop)
5155 for(c=0; c<SystemCursor::enumSize; c++)
5156 if(!guiApp.systemCursors[c].bitmap)
5158 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
5159 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
5160 if(guiApp.systemCursors[c].bitmapName)
5162 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
5163 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
5164 if(guiApp.systemCursors[c].bitmap)
5165 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
5170 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5172 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
5173 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
5175 cursor.bitmap.paletteShades = cursor.paletteShades;
5179 guiApp.cursorUpdate = true;
5182 ConsequentialMouseMove(false);
5188 // Load Window Graphic Resources
5191 if(usedFont == setFont || usedFont == window.systemFont)
5192 RemoveResource(usedFont);
5195 RemoveResource(setFont); // TESTING setFont instead of usedFont);
5198 RemoveResource(systemFont);
5201 RemoveResource(captionFont);
5203 for(ptr = resources.first; ptr; ptr = ptr.next)
5205 if(!ptr.loaded) // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
5206 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
5209 AddResource(setFont);
5211 AddResource(systemFont);
5213 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
5220 //if(master && master.font)
5221 if(parent && parent.font)
5225 faceName = parent.font.faceName,
5226 size = parent.font.size,
5227 bold = parent.font.bold,
5228 italic = parent.font.italic,
5229 underline = parent.font.underline
5231 //font = parent.font;
5232 watch(parent) { font { } };
5235 font = guiApp.currentSkin.SystemFont();
5242 captionFont = guiApp.currentSkin ? guiApp.currentSkin.CaptionFont() : null;
5243 AddResource(captionFont);
5245 if(OnLoadGraphics())
5251 //SetScrollLineStep(sbStep.x, sbStep.y);
5253 if(this != guiApp.desktop)
5257 normalAnchor = anchor;
5258 normalSizeAnchor = sizeAnchor;
5261 // Break the anchors for moveable/resizable windows
5263 if(style.fixed && style.isDocument)
5265 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
5277 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5278 stateSizeAnchor = SizeAnchor {};
5283 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5288 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
5289 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
5292 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5296 stateAnchor = normalAnchor;
5297 stateSizeAnchor = normalSizeAnchor;
5300 position = Point { };
5301 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5312 if(Position(x, y, w, h, true, false, true, true, true, true))
5314 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
5317 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
5334 success = result = true;
5337 if(!creation && result)
5339 // Load menu bar first because sys buttons are on it...
5342 if(!menuBar.LoadGraphics(false, resetAnchors))
5348 for(child = children.first; child; child = child.next)
5350 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
5357 CreateSystemChildren();
5361 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5364 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5367 LogErrorCode(graphicsLoadingFailed, _class.name);
5369 // Do this here to avoid problems on Windows
5370 if(rootWindow == this && parent && stateBackup == maximized)
5371 property::state = maximized;
5375 void UnloadGraphics(bool destroyWindows)
5379 // Free children's graphics
5380 for(child = children.first; child; child = child.next)
5381 child.UnloadGraphics(destroyWindows);
5384 display.Lock(false);
5387 if(guiApp.fullScreenMode && this == guiApp.desktop)
5392 for(c=0; c<SystemCursor::enumSize; c++)
5393 if(guiApp.systemCursors[c].bitmap)
5394 delete guiApp.systemCursors[c].bitmap;
5396 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5397 delete cursor.bitmap;
5399 guiApp.cursorBackground.Free();
5402 if(display && display.displaySystem)
5406 for(ptr = resources.first; ptr; ptr = ptr.next)
5410 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5415 // Free window graphics
5418 // Free skin graphics
5419 if(rootWindow == this)
5421 DisplaySystem displaySystem = display.displaySystem;
5424 display.driverData = null;
5425 display.displaySystem = null;
5429 if(displaySystem && !displaySystem.numDisplays && !is3D)
5430 delete displaySystem;
5439 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5440 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5442 if(this == guiApp.desktop || parent == guiApp.desktop)
5444 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5445 guiApp.interfaceDriver.DestroyRootWindow(this);
5449 // --- Window Hiding ---
5451 void SetVisibility(bool state)
5453 bool visible = (style.hidden || !created) ? false : state;
5454 if(visible != this.visible)
5458 this.visible = visible;
5459 for(child = children.first; child; child = child.next)
5460 child.SetVisibility(visible);
5462 ConsequentialMouseMove(false);
5463 if(parent && !nonClient) parent.OnChildVisibilityToggled(this, visible);
5467 // --- Windows and graphics initialization / termination ---
5469 bool DisplayModeChanged(void)
5471 bool result = false;
5472 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5474 guiApp.modeSwitching = true;
5475 UnloadGraphics(false);
5477 if(LoadGraphics(false, false))
5479 guiApp.modeSwitching = false;
5484 // --- Window updates system ---
5486 void UpdateDirty(Box updateBox)
5488 if(!manageDisplay) { OnRedraw(null);return; }
5491 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5494 if(display.flags.flipping)
5497 rootWindow.UpdateDisplay();
5500 UpdateBackDisplay(updateBox);
5502 if(guiApp.fullScreenMode)
5504 guiApp.cursorUpdate = true;
5505 guiApp.PreserveAndDrawCursor();
5507 if(guiApp.fullScreenMode)
5508 guiApp.RestoreCursorBackground();
5514 // This function is strictly called as a result of system window activation
5515 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5518 Window interimMaster = null;
5519 Window interimWindow = guiApp.interimWindow;
5520 if(interimWindow && interimWindow.master)
5521 interimMaster = interimWindow.master.rootWindow;
5523 if(active && state == minimized && window.parent) // && (!window.nativeDecorations || window.rootWindow != window)
5524 // SetState(normal, false, 0);
5525 SetState(lastState, false, 0);
5527 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5531 /* WTH is this doing here?
5532 while(swap && swap.activeChild)
5534 swap = swap.activeChild;
5537 // TESTING THIS BEFORE...
5538 if(interimWindow && this == interimMaster)
5542 // Window interimSwap = this;
5543 Window menuBar = this.menuBar;
5544 if(menuBar && interimWindow.master == menuBar)
5547 while(interimSwap && interimSwap.activeChild)
5548 interimSwap = interimSwap.activeChild;
5550 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5551 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5553 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5554 //result = ActivateEx(true, true, false, activateRoot, window, null);
5559 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5560 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5562 if(interimWindow == this && interimMaster && !active)
5564 while(interimMaster && interimMaster.interim && interimMaster.master)
5566 // printf("Going up one master %s\n", interimMaster._class.name);
5567 interimMaster = interimMaster.master.rootWindow;
5569 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5570 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5576 bool DestroyEx(int64 returnCode)
5579 Timer timer, nextTimer;
5581 OldLink prevOrder = null;
5582 Window client = null;
5584 if(parent) stopwatching(parent, font);
5586 // if(window.modalSlave) return false;
5587 if(destroyed || !created)
5594 OldLink slave = master.slaves.FindLink(this);
5595 master.slaves.Delete(slave);
5598 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5604 this.returnCode = (DialogResult)returnCode;
5606 AcquireInput(false);
5611 master.hotKeys.Delete(hotKey);
5615 if(guiApp.prevWindow == this)
5617 guiApp.prevWindow = null;
5622 for(w : guiApp.overWindows; w == this)
5625 guiApp.overWindows.TakeOut(w);
5629 if(guiApp.caretOwner == this)
5631 guiApp.interfaceDriver.SetCaret(0,0,0);
5632 UpdateCaret(false, true);
5633 guiApp.caretEnabled = false;
5638 parent.childrenCycle.Remove(cycle);
5642 OldLink tmpPrev = order.prev;
5643 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5644 prevOrder = tmpPrev;
5647 client = tmpPrev ? tmpPrev.data : null;
5648 if(client == this) { client = null; break; }
5649 if(client && (client.style.hidden || client.destroyed || !client.created))
5650 tmpPrev = client.order.prev;
5654 prevOrder = tmpPrev;
5659 // If this window can be an active client, make sure the next window we activate can also be one
5660 if(!style.nonClient && style.isActiveClient)
5662 tmpPrev = prevOrder;
5665 client = tmpPrev ? tmpPrev.data : null;
5666 if(client == this) { client = null; break; }
5667 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5668 tmpPrev = client.order.prev;
5672 prevOrder = tmpPrev;
5676 if(client && client.style.hidden) client = null;
5678 // parent.childrenOrder.Remove(order);
5681 if(parent && style.isActiveClient && visible)
5683 if(state == minimized) parent.numIcons--;
5684 parent.numPositions--;
5687 // TESTING THIS HERE!
5691 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5692 // to create a window inside a rootwindow that's being destroyed)
5693 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5695 if(master && !master.destroyed /*&&
5696 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5698 if(master.defaultControl == this)
5699 master.defaultControl = null;
5702 parent.OnChildAddedOrRemoved(this, true);
5703 if(parent && !parent.destroyed /*&&
5704 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5706 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5708 if(order && prevOrder && prevOrder.data != this && active)
5710 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5712 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5713 if(parent.activeClient == this)
5715 parent.activeClient = null;
5716 parent.UpdateActiveDocument(null);
5721 if(guiApp.interimWindow == this)
5724 PropagateActive(false, null, &goOn, true);
5728 //if(window.parent.activeChild == window)
5729 parent.activeChild = null;
5730 if(!style.nonClient /*&& style.isActiveClient*/)
5732 Window previous = parent.activeClient;
5733 if(style.isActiveClient)
5734 parent.activeClient = null;
5735 parent.UpdateActiveDocument(previous);
5740 else if(parent.activeClient == this)
5742 parent.activeClient = client;
5743 parent.UpdateActiveDocument(this);
5747 if(guiApp.interimWindow == this)
5749 guiApp.interimWindow = null;
5750 if(guiApp.caretOwner)
5752 Window desktop = guiApp.desktop;
5753 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5754 guiApp.caretOwner.UpdateCaret(false, false);
5759 if(_isModal && master && master.modalSlave == this)
5760 master.modalSlave = null;
5764 if(!guiApp.caretOwner && parent.caretSize)
5766 guiApp.caretOwner = parent;
5767 parent.UpdateCaret(false, false);
5768 parent.Update(null);
5771 // Why was this commented out?
5772 GetRidOfVirtualArea();
5778 dirtyArea.Free(null);
5779 dirtyBack.Free(null);
5780 scrollExtent.Free(null);
5782 /* ATTEMPTING TO MOVE THAT ABOVE
5791 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5792 for(;(child = window.children.first);)
5794 for(; child && (child.destroyed || !child.created); child = child.next);
5803 UnloadGraphics(true);
5806 delete previousActive;
5809 // statusBar = null;
5812 if(master && !master.destroyed)
5814 //master.NotifyDestroyed(this, this.returnCode);
5815 NotifyDestroyed(master, this, this.returnCode);
5818 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5820 nextTimer = timer.next;
5821 if(timer.window == this)
5823 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5824 // timer.window = null;
5830 if(this == guiApp.windowMoving)
5833 if(guiApp.windowCaptured == this)
5835 //guiApp.windowCaptured = null;
5837 if(rootWindow != this && rootWindow)
5838 rootWindow.ConsequentialMouseMove(false);
5846 //for(child = children.first; next = child ? child.next : null, child; child = next)
5847 for(;(child = children.first); )
5849 for(; child && (child.destroyed || !child.created); child = child.next);
5859 /* // MOVED THIS UP...
5862 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5863 for(;(child = window.children.first); )
5865 for(; child && (child.destroyed || !child.created); child = child.next);
5874 while((slave = slaves.first))
5876 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5878 ((Window)slave.data).DestroyEx(0);
5883 if(guiApp.caretOwner == this)
5884 guiApp.caretOwner = null;
5886 sysButtons[0] = null;
5887 sysButtons[1] = null;
5888 sysButtons[2] = null;
5891 if(rootWindow != this)
5893 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5896 box.left -= parent.clientStart.x;
5897 box.top -= parent.clientStart.y;
5898 box.right -= parent.clientStart.x;
5899 box.bottom -= parent.clientStart.y;
5901 if(parent) parent.Update(box);
5906 OldLink slave = master.slaves.FindVoid(this);
5907 master.slaves.Delete(slave);
5913 parent.children.Remove(this);
5918 //autoCreate = false;
5921 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5922 if(((subclass(Window))_class).pureVTbl)
5924 if(_vTbl == _class._vTbl)
5926 _vTbl = ((subclass(Window))_class).pureVTbl;
5931 for(m = 0; m < _class.vTblSize; m++)
5933 if(_vTbl[m] == _class._vTbl[m])
5934 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5943 void SetStateEx(WindowState newState, bool activate)
5946 WindowState prevState = state;
5950 if(prevState != newState)
5951 lastState = prevState;
5953 if(rootWindow != this || !nativeDecorations || !windowHandle)
5955 if(style.isActiveClient && !style.hidden && prevState == minimized)
5958 // This block used to be at the end of the function... moved it for flicker problem in X
5959 // ------------------------------------------------------
5963 stateAnchor = normalAnchor;
5964 stateSizeAnchor = normalSizeAnchor;
5967 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5968 stateSizeAnchor = SizeAnchor {};
5974 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5977 byte * idBuffer = new0 byte[size];
5979 for(child = parent.children.first; child; child = child.next)
5981 if(child != this && child.state == minimized)
5983 if(child.iconID > size - 2)
5985 idBuffer = renew0 idBuffer byte[size*2];
5986 memset(idBuffer + size, 0, size);
5989 idBuffer[child.iconID] = (byte)bool::true;
5992 for(c = 0; c<size; c++)
5997 if(style.isActiveClient && !style.hidden)
6000 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
6001 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
6006 // TOCHECK: Why was this here?
6007 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
6008 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
6009 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6011 if(state != minimized || hasMinimize)
6012 Position(x, y, w, h, true, true, true, true, false, true);
6014 if(!style.inactive && !style.interim && parent && this == parent.activeClient)
6015 parent.UpdateActiveDocument(null);
6018 if(state != minimized || hasMinimize)
6019 CreateSystemChildren();
6020 // ------------------------------------------------------
6023 int GetPositionID(Window forChild)
6027 byte * idBuffer = new0 byte[size];
6030 for(child = children.first; child; child = child.next)
6032 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
6034 if(child.positionID > size - 2)
6036 idBuffer = renew0 idBuffer byte[size*2];
6037 memset(idBuffer + size, 0, size);
6040 idBuffer[child.positionID] = (byte)bool::true;
6043 for(c = 0; c<size; c++)
6050 // --- Window related graphics ---
6052 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
6054 palette = newPalette;
6055 if(rootWindow.display)
6056 rootWindow.display.SetPalette(palette, colorMatch);
6059 public bool AcquireInput(bool acquired)
6062 if((guiApp.acquiredWindow && acquiredInput) != acquired)
6064 if(active || (!visible && creationActivation == activate))
6065 result = AcquireInputEx(acquired);
6070 acquiredInput = acquired ? result : !result;
6075 void ListChildren(ListBox listBox)
6079 for(child = children.first; child; child = child.next)
6081 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
6083 DataRow row = listBox.AddRow();
6084 row.tag = (int64)(intptr)child;
6085 child.FigureCaption(caption);
6086 row.SetData(null, caption);
6091 void UpdateVisual(Box extent)
6093 if(guiApp.driver != null)
6095 #if !defined(__EMSCRIPTEN__)
6096 if(guiApp.fullScreenMode && guiApp.desktop.display)
6101 #if !defined(__EMSCRIPTEN__)
6102 guiApp.desktop.mutex.Wait();
6104 guiApp.desktop.display.Lock(true);
6107 if(guiApp.desktop.active)
6109 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
6111 if(guiApp.desktop.display.flags.flipping)
6112 guiApp.desktop.Update(null);
6113 guiApp.desktop.UpdateDisplay();
6114 guiApp.cursorUpdate = true;
6116 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
6118 guiApp.PreserveAndDrawCursor();
6119 // guiApp.desktop.display.ShowScreen();
6120 guiApp.cursorUpdate = false;
6121 guiApp.desktop.dirty = false;
6122 guiApp.RestoreCursorBackground();
6126 guiApp.desktop.display.Unlock();
6127 #if !defined(__EMSCRIPTEN__)
6128 guiApp.desktop.mutex.Release();
6133 Window rootWindow = this.rootWindow;
6134 #if !defined(__EMSCRIPTEN__)
6135 rootWindow.mutex.Wait();
6141 guiApp.SignalEvent();
6144 #if !defined(__EMSCRIPTEN__)
6145 guiApp.waitMutex.Wait();
6147 guiApp.interfaceDriver.Lock(rootWindow);
6148 if(!rootWindow.style.hidden && rootWindow.dirty)
6150 if(rootWindow.display)
6152 rootWindow.UpdateDisplay();
6153 //rootWindow.display.ShowScreen(null);
6155 rootWindow.dirty = false;
6157 guiApp.interfaceDriver.Unlock(rootWindow);
6158 #if !defined(__EMSCRIPTEN__)
6159 guiApp.waitMutex.Release();
6163 #if !defined(__EMSCRIPTEN__)
6164 rootWindow.mutex.Release();
6170 void UnlockDisplay(void)
6172 guiApp.interfaceDriver.Unlock(rootWindow);
6175 void LockDisplay(void)
6177 guiApp.interfaceDriver.Lock(rootWindow);
6180 Surface GetSurface(Box box)
6182 return Redraw((box == null) ? this.box : box);
6185 void SetMousePosition(int x, int y)
6187 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
6191 void IntegrationActivate(bool active)
6193 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
6195 isForegroundWindow = true;
6196 ActivateEx(active, active, false, false, null, null);
6197 isForegroundWindow = false;
6202 Window QueryCapture(void)
6204 return guiApp.windowCaptured;
6207 int GetDocumentID(void)
6211 byte * idBuffer = new0 byte[size];
6214 for(child = children.first; child; child = child.next)
6216 // TO CHECK: Do we want a documentID when we already have a file name?
6217 if(child.style.isDocument && !child.fileName)
6219 if(child.documentID-1 > size - 2)
6221 idBuffer = renew0 idBuffer byte[size*2];
6222 memset(idBuffer + size, 0, size);
6225 idBuffer[child.documentID-1] = 1;
6228 for(c = 0; c<size; c++)
6236 void SetInitSize(Size size)
6239 sizeAnchor.size = size;
6240 normalSizeAnchor = sizeAnchor;
6242 // Break the anchors for moveable/resizable windows
6243 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6245 stateAnchor = normalAnchor;
6246 stateSizeAnchor = normalSizeAnchor;
6248 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6249 Position(x,y, w, h, true, true, true, true, false, true);
6253 void MenuMoveOrSize(bool resize, bool setCursorPosition)
6255 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
6257 guiApp.windowIsResizing = resize;
6258 guiApp.windowMoving = this;
6259 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
6260 if(guiApp.windowIsResizing)
6262 guiApp.windowMovingStart.x += size.w - 1;
6263 guiApp.windowMovingStart.y += size.h - 1;
6265 guiApp.windowMovingBefore = scrolledPos;
6266 guiApp.windowResizingBefore = size;
6267 guiApp.windowMoving.UpdateDecorations();
6268 if(guiApp.windowIsResizing)
6269 guiApp.resizeEndX = guiApp.resizeEndY = true;
6271 if(setCursorPosition)
6272 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
6276 guiApp.interfaceDriver.GetMousePosition(&x, &y);
6277 guiApp.windowMovingStart.x += x - absPosition.x;
6278 guiApp.windowMovingStart.y += y - absPosition.y;
6281 if(guiApp.windowMoving)
6283 if(guiApp.windowMoving.style.nonClient)
6284 guiApp.windowMoving.parent.SetMouseRangeToWindow();
6286 guiApp.windowMoving.parent.SetMouseRangeToClient();
6291 if(this == rootWindow)
6292 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
6296 void SetupFileMonitor()
6298 #if !defined(__EMSCRIPTEN__)
6301 fileMonitor = FileMonitor
6303 this, FileChange { modified = true };
6305 bool OnFileNotify(FileChange action, const char * param)
6308 fileMonitor.StopMonitoring();
6309 if(OnFileModified(action, param))
6310 fileMonitor.StartMonitoring();
6324 bool result = false;
6328 else if(guiApp && guiApp.driver != null)
6330 OldLink slaveHolder;
6332 bool visible = !style.hidden;
6336 systemParent = parent;
6337 parent = guiApp.desktop;
6339 last = parent ? parent.children.last : null;
6341 if((parent && parent != guiApp.desktop && !parent.created) ||
6342 (master && master != guiApp.desktop && !master.created))
6346 stopwatching(parent, font);
6349 property::parent = guiApp.desktop;
6350 if(!master) master = parent;
6352 if(_isModal && master.modalSlave)
6353 property::master = master.modalSlave;
6357 parent.children.Remove(this);
6360 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
6361 if(slaveHolder.data == this)
6363 master.slaves.Delete(slaveHolder);
6368 #if !defined(__EMSCRIPTEN__)
6369 if(parent == guiApp.desktop && !mutex)
6373 if(style.isDocument)
6376 parent.numDocuments--;
6377 documentID = parent.GetDocumentID();
6380 if(!style.stayOnTop)
6381 for(; last && last.style.stayOnTop; last = last.prev);
6383 parent.children.Insert((last == this) ? null : last, this);
6384 //parent.children.Add(this);
6387 dispDriver = parent.dispDriver;
6390 master.modalSlave = this;
6392 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
6397 master.slaves.Add(slaveHolder = OldLink { data = this });
6402 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
6404 if(style.isDefault && !master.defaultControl)
6405 master.defaultControl = this;
6407 stateAnchor = normalAnchor = anchor;
6408 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
6410 // TOCHECK: Why is this here?
6411 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
6412 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
6414 this.visible = false;
6415 style.hidden = true;
6418 // autoCreate = true;
6426 if(parent == guiApp.desktop)
6427 Log("LoadGraphics %s\n", caption);
6429 if(LoadGraphics(true, false))
6437 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6444 if(style.hasMenuBar /*&& menu*/)
6450 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6451 interim = false, inactive = true, nonClient = true, size.h = 24
6459 // Create the system buttons
6460 CreateSystemChildren();
6462 UpdateActiveDocument(null);
6464 if(style.isDocument)
6468 MenuItem item = menu.FindItem(MenuFileSave, 0);
6469 if(item) item.disabled = !modifiedDocument && fileName;
6474 if(parent == guiApp.desktop)
6475 Log("Preemptive SetState %s\n", caption);
6478 // Preemptive Set State to ensure proper anchoring
6479 SetStateEx(state, false);
6481 style.hidden = true;
6487 for(child = children.first; child; child = next)
6490 if(!child.created && (child.autoCreate || child.wasCreated))
6497 for(link = slaves.first; link; link = next)
6499 Window slave = link.data;
6501 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6504 // Things might have happened that invalidated 'next'...
6505 // Start over the search for slaves to create.
6506 // (Added this to fix crash with Stacker & Toolbar)
6507 next = slaves.first;
6516 if(parent == guiApp.desktop)
6517 Log("Real SetState %s\n", caption);
6520 if(isActiveClient && visible)
6522 parent.numPositions--;
6523 if(state == minimized) parent.numIcons--;
6526 parent.OnChildAddedOrRemoved(this, false);
6528 if(rootWindow == this && visible) // So that X11 windows don't show as 'unknown'
6530 // Real set state & activate for proper display & activation
6531 property::visible = visible;
6532 // SetState(state & 0x00000003, true, 0);
6533 guiApp.interfaceDriver.SetIcon(this, icon);
6538 /*if(rootWindow == this)
6539 guiApp.interfaceDriver.ActivateRootWindow(this);
6541 if(creationActivation == activate && guiApp.desktop.active)
6542 ActivateEx(true, false, true, true, null, null);
6543 else if(creationActivation == activate || creationActivation == flash)
6546 if(this == rootWindow)
6551 if(!destroyed && !noConsequential)
6552 rootWindow.ConsequentialMouseMove(false);
6563 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6569 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6571 //style.hidden = true; // !visible;
6572 style.hidden = !visible;
6573 if(master.modalSlave == this)
6574 master.modalSlave = null;
6581 void WriteCaption(Surface surface, int x, int y)
6584 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6587 void Update(Box region)
6593 rootWindow = this.rootWindow;
6595 // rootWindow.mutex.Wait();
6596 if(!destroyed && visible && display)
6601 // Testing this to avoid repetitve full update to take time...
6602 if(rootWindow.fullRender)
6604 rootWindow.dirty = true;
6607 if(dirtyArea.count == 1)
6609 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6610 if(item.box.left <= box.left &&
6611 item.box.top <= box.top &&
6612 item.box.right >= box.right &&
6613 item.box.bottom >= box.bottom)
6615 rootWindow.dirty = true;
6620 if(display.flags.flipping && !rootWindow.dirty)
6622 if(this == rootWindow)
6626 rootWindow.Update(null);
6631 rootWindow.dirty = true;
6636 realBox.left += clientStart.x;
6637 realBox.top += clientStart.y;
6638 realBox.right += clientStart.x;
6639 realBox.bottom += clientStart.y;
6645 if(realBox.right >= realBox.left &&
6646 realBox.bottom >= realBox.top)
6648 // if(!rootWindow.fullRender)
6649 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6651 for(child = children.first; child; child = child.next)
6656 box.left -= child.absPosition.x - absPosition.x;
6657 box.top -= child.absPosition.y - absPosition.y;
6658 box.right -= child.absPosition.x - absPosition.x;
6659 box.bottom -= child.absPosition.y - absPosition.y;
6660 if(box.right >= child.box.left && box.left <= child.box.right &&
6661 box.bottom >= child.box.top && box.top <= child.box.bottom)
6663 box.left -= child.clientStart.x;
6664 box.top -= child.clientStart.y;
6665 box.right -= child.clientStart.x;
6666 box.bottom -= child.clientStart.y;
6672 realBox.left += absPosition.x - rootWindow.absPosition.x;
6673 realBox.top += absPosition.y - rootWindow.absPosition.y;
6674 realBox.right += absPosition.x - rootWindow.absPosition.x;
6675 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6676 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6679 else if(this == guiApp.desktop)
6682 for(window = children.first; window; window = window.next)
6688 Box childBox = region;
6690 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6691 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6692 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6693 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6695 window.Update(childBox);
6698 window.Update(null);
6703 // rootWindow.mutex.Release();
6710 if(guiApp.windowCaptured != this)
6712 if(guiApp.windowCaptured)
6716 //Logf("Captured %s (%s)\n", caption, class.name);
6717 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6718 guiApp.windowCaptured = this;
6724 bool Destroy(int64 code)
6729 if(!destroyed && !CloseConfirmation(false)) return false;
6733 // TOCHECK: Should autoCreate be set to false here?
6744 void Move(int x, int y, int w, int h)
6746 normalAnchor = Anchor { left = x, top = y };
6747 normalSizeAnchor = SizeAnchor { size = { w, h } };
6749 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6751 if(destroyed) return;
6753 stateAnchor = normalAnchor;
6754 stateSizeAnchor = normalSizeAnchor;
6756 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6757 Position(x,y, w, h, true, true, true, true, false, true);
6761 DialogResult Modal(void)
6767 // FIXES MEMORY LEAK IF Create() FAILED
6773 void SetScrollArea(int width, int height, bool snapToStep)
6777 int stepX = sbStep.x, stepY = sbStep.y;
6778 // Needed to make snapped down position match the skin's check of client area
6779 // against realvirtual
6782 SNAPDOWN(stepX, textCellW);
6783 SNAPDOWN(stepY, textCellH);
6784 stepX = Max(stepX, textCellW);
6785 stepY = Max(stepY, textCellH);
6787 if(scrollFlags.snapX)
6788 SNAPUP(width, stepX);
6789 if(scrollFlags.snapY)
6790 SNAPUP(height, stepY);
6793 reqScrollArea.w = width;
6794 reqScrollArea.h = height;
6795 noAutoScrollArea = (width > 0 || height > 0);
6797 UpdateScrollBars(true, true);
6800 void SetScrollPosition(int x, int y)
6803 sbh.Action(setPosition, x, 0);
6807 int seen = clientSize.w, total = reqScrollArea.w;
6809 if(scrollFlags.snapX)
6810 SNAPDOWN(seen, sbStep.x);
6812 if(!total) total = seen;
6813 range = total - seen + 1;
6814 range = Max(range, 1);
6816 if(x >= range) x = range - 1;
6818 if(scrollFlags.snapX)
6819 SNAPUP(x, sbStep.x);
6822 OnHScroll(setPosition, x, 0);
6826 SNAPDOWN(x, textCellW);
6832 sbv.Action(setPosition, y, 0);
6836 int seen = clientSize.h, total = reqScrollArea.h;
6839 if(scrollFlags.snapY)
6840 SNAPDOWN(seen, sbStep.y);
6842 if(!total) total = seen;
6843 range = total - seen + 1;
6844 range = Max(range, 1);
6846 if(y >= range) y = range - 1;
6848 if(scrollFlags.snapY)
6849 SNAPUP(y, sbStep.y);
6852 OnVScroll(setPosition, y, 0);
6855 SNAPDOWN(y, textCellH);
6860 UpdateCaret(false, false);
6863 void SetScrollLineStep(int stepX, int stepY)
6869 SNAPDOWN(stepX, textCellW);
6870 SNAPDOWN(stepY, textCellH);
6871 stepX = Max(stepX, textCellW);
6872 stepY = Max(stepY, textCellH);
6875 sbh.lineStep = stepX;
6877 sbv.lineStep = stepY;
6880 void SetState(WindowState newState, bool activate, Modifiers mods)
6884 if(state == newState || OnStateChange(newState, mods))
6886 //WindowState prevState = state;
6890 // This used to be at the end of the brackets... moved for X, testing...
6891 // This has the effect of activating the window through the system...
6892 if(rootWindow == this)
6893 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6895 SetStateEx(newState, activate);
6897 if(rootWindow == this && !rootWindow.nativeDecorations)
6899 int x = position.x, y = position.y;
6902 x -= guiApp.desktop.absPosition.x;
6903 y -= guiApp.desktop.absPosition.y;
6905 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6909 //state = prevState;
6911 if(state != maximized && style.hasMaximize)
6914 for(child = parent.children.first; child; child = child.next)
6916 if(child != this && child.state == maximized)
6917 child.SetStateEx(normal, false);
6921 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6922 parent.UpdateScrollBars(true, true);
6925 // Do we really need this stuff here?
6926 // Shouldn't the Activate stuff take care of it?
6927 if(parent.rootWindow == parent && style)
6930 parent.FigureCaption(caption);
6931 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6932 parent.UpdateDecorations();
6936 rootWindow.ConsequentialMouseMove(false);
6943 BitmapResource GetIcon(SkinBitmap iconID)
6945 return guiApp.currentSkin.GetBitmap(iconID);
6948 void SetMouseRange(Box range)
6950 if(range || guiApp.fullScreenMode)
6955 clip.left = range.left + absPosition.x + clientStart.x;
6956 clip.top = range.top + absPosition.y + clientStart.y;
6957 clip.right = range.right + absPosition.x + clientStart.x;
6958 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6962 clip.left = guiApp.desktop.box.left;
6963 clip.top = guiApp.desktop.box.top;
6964 clip.right = guiApp.desktop.box.right;
6965 clip.bottom = guiApp.desktop.box.bottom;
6967 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6970 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6973 void SetMouseRangeToClient(void)
6975 if(guiApp.fullScreenMode || this != guiApp.desktop)
6977 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6978 box.Clip(clientArea);
6982 SetMouseRange(null);
6985 void SetMouseRangeToWindow(void)
6987 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6988 if(this == guiApp.desktop)
6989 SetMouseRangeToClient();
6994 // x, y: Desktop Coordinates
6995 void ShowSysMenu(int x, int y)
6998 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
7001 menu, $"Restore", r, NotifySelect = MenuWindowRestore,
7002 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
7006 menu, $"Move", m, NotifySelect = MenuWindowMove,
7007 disabled = !style.fixed || state == maximized
7011 menu, $"Size", s, NotifySelect = MenuWindowSize,
7012 disabled = !style.sizable || state != normal
7016 menu, $"Minimize", n, NotifySelect = MenuWindowMinimize,
7017 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
7021 menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
7022 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
7026 menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
7027 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
7029 MenuDivider { menu };
7032 menu, $"Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
7033 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
7035 windowMenu.Create();
7040 ActivateEx(true, true, true, true, null, null);
7043 void MakeActive(void)
7045 ActivateEx(true, false, true, false, null, null);
7048 void SoftActivate(void)
7050 if(guiApp.desktop.active)
7055 if(this == rootWindow)
7060 void Deactivate(void)
7062 ActivateEx(false, true, true, true, null, null);
7067 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
7070 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
7072 bool result = false;
7073 if(activeChild && activeChild.cycle)
7075 Window modalWindow, child = activeChild;
7076 if(!clientOnly /*&& parent.tabCycle*/)
7078 Window next = child;
7081 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
7085 if(parent && parent.CycleChildren(backward, false, true, true))
7093 next = next.cycle.prev.data;
7095 next = next.cycle.next.data;
7096 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
7101 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
7102 parent.tabCycle && parent.CycleChildren(backward, false, false))
7106 if(tabCycleOnly && !tabCycle) return false;
7113 child = child.cycle.prev.data;
7115 child = child.cycle.next.data;
7116 if(child == child.parent.activeChild)
7118 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
7121 modalWindow = child.FindModal();
7124 // Scroll the window to include the active control
7125 if(sbh && !child.style.dontScrollHorz)
7127 if(child.scrolledPos.x < 0)
7128 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
7129 else if(child.scrolledPos.x + child.size.w > clientSize.w)
7130 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
7132 if(sbv && !child.style.dontScrollVert)
7134 if(child.scrolledPos.y < 0)
7135 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
7136 else if(child.scrolledPos.y + child.size.h > clientSize.h)
7137 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
7141 child = modalWindow ? modalWindow : child;
7142 child.ActivateEx(true, true, true, true, null, null);
7143 if(child.tabCycle && child.childrenCycle.first)
7144 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
7152 ConsequentialMouseMove(false);
7156 void AddResource(Resource resource)
7160 ResPtr ptr { resource = resource };
7164 // Load Graphics here if window is created already
7165 if(/*created && */display)
7167 display.Lock(false);
7168 if(!ptr.loaded) // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
7169 ptr.loaded = display.displaySystem.LoadResource(resource);
7173 // Temporary hack to load font right away for listbox in dropbox ...
7174 else if(master && master.display)
7176 master.display.Lock(false);
7177 master.display.displaySystem.LoadResource(resource);
7178 master.display.Unlock();
7184 void RemoveResource(Resource resource)
7189 for(ptr = resources.first; ptr; ptr = ptr.next)
7191 if(ptr.resource == resource)
7197 // Unload Graphics here if window is created already
7198 if(/*created && */display)
7202 display.Lock(false);
7203 display.displaySystem.UnloadResource(resource, ptr.loaded);
7209 resources.Delete(ptr);
7214 void SetCaret(int x, int y, int size)
7221 if(active && !style.interim && isEnabled)
7223 if(visible || !guiApp.caretOwner)
7224 guiApp.caretOwner = size ? this : null;
7226 UpdateCaret(false, false);
7229 guiApp.interfaceDriver.SetCaret(0,0,0);
7230 UpdateCaret(false, true);
7231 guiApp.caretEnabled = false;
7234 else if(style.inactive && active)
7236 guiApp.interfaceDriver.SetCaret(0,0,0);
7237 UpdateCaret(false, true);
7238 guiApp.caretEnabled = false;
7243 void Scroll(int x, int y)
7245 bool opaque = !style.drawBehind || background.a;
7246 if(opaque && display && display.flags.scrolling)
7248 Box box = clientArea;
7249 box.left += clientStart.x;
7250 box.top += clientStart.y;
7251 box.right += clientStart.x;
7252 box.bottom += clientStart.y;
7254 //scrollExtent.Free(null);
7255 scrollExtent.AddBox(box);
7256 scrolledArea.x += x;
7257 scrolledArea.y += y;
7259 //scrollExtent.Free();
7260 //scrollExtent.AddBox(clientArea);
7261 //scrollExtent.Offset(clientStart.x, clientStart.y);
7262 //scrolledArea.x = x;
7263 //scrolledArea.y = y;
7269 rootWindow.dirty = true;
7272 void ReleaseCapture()
7274 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
7276 Window oldCaptured = guiApp.windowCaptured;
7277 guiApp.windowCaptured = null;
7278 guiApp.prevWindow = null;
7281 //guiApp.Log("Released Capture\n");
7283 guiApp.interfaceDriver.SetMouseCapture(null);
7285 //oldCaptured.OnMouseCaptureLost();
7288 oldCaptured.ConsequentialMouseMove(false);
7293 private void _SetCaption(const char * format, va_list args)
7300 char caption[MAX_F_STRING];
7301 vsnprintf(caption, sizeof(caption), format, args);
7302 caption[sizeof(caption)-1] = 0;
7304 this.caption = CopyString(caption);
7309 firewatchers caption;
7313 /*deprecated*/ void SetText(const char * format, ...)
7316 va_start(args, format);
7317 _SetCaption(format, args);
7321 void SetCaption(const char * format, ...)
7324 va_start(args, format);
7325 _SetCaption(format, args);
7329 bool Grab(Bitmap bitmap, Box box, bool decorations)
7331 bool result = false;
7332 if(display || this == guiApp.desktop)
7334 Box clip = {MININT, MININT, MAXINT, MAXINT};
7340 clip.Clip(clientArea);
7342 clip.Clip(this.box);
7344 if(rootWindow != this)
7346 clip.left += absPosition.y;
7347 clip.top += absPosition.y;
7348 clip.right += absPosition.x;
7349 clip.bottom += absPosition.y;
7352 if(!nativeDecorations)
7354 clip.left += decorations ? 0 : clientStart.x;
7355 clip.top += decorations ? 0 : clientStart.y;
7356 clip.right += decorations ? 0 : clientStart.x;
7357 clip.bottom += decorations ? 0 : clientStart.y;
7360 if(decorations && this == guiApp.desktop)
7361 clip = { 0, 0, guiApp.virtualScreen.w, guiApp.virtualScreen.h };
7363 if(display && display.flags.flipping)
7365 rootWindow.Update(null);
7366 rootWindow.UpdateDisplay();
7373 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
7374 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7378 result = display.Grab(bitmap, clip.left, clip.top,
7379 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7381 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
7383 if(!bitmap.Convert(null, pixelFormat888, null))
7390 void GetMousePosition(int * x, int * y)
7392 int mouseX = 0, mouseY = 0;
7393 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
7396 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
7397 if(this != guiApp.desktop)
7399 mouseX -= absPosition.x + clientStart.x;
7400 mouseY -= absPosition.y + clientStart.y;
7407 DialogResult DoModal()
7409 DialogResult returnCode = 0;
7410 int terminated = terminateX;
7413 while(!destroyed && guiApp.driver != null)
7415 if(terminateX != terminated)
7417 terminated = terminateX;
7418 guiApp.desktop.Destroy(0);
7419 if(guiApp.desktop.created)
7422 //printf("Resetting terminate X to 0\n");
7428 guiApp.UpdateDisplay();
7429 if(!guiApp.ProcessInput(false))
7432 returnCode = this.returnCode;
7445 return !destroyed && guiApp.driver != null && terminateX < 2;
7448 DialogResult DoModalEnd()
7450 DialogResult returnCode = this.returnCode;
7455 // --- Window manipulation ---
7456 /*bool GetDisabled()
7458 bool disabled = this.disabled;
7460 for(window = this; (window = window.master); )
7471 // --- Mouse Manipulation ---
7472 void GetNCMousePosition(int * x, int * y)
7474 GetMousePosition(x, y);
7475 if(x) *x += clientStart.x;
7476 if(y) *y += clientStart.y;
7479 // --- Carets manipulation ---
7480 void GetCaretPosition(Point caretPos)
7482 caretPos = this.caretPos;
7485 int GetCaretSize(void)
7490 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7496 bool CloseConfirmation(bool parentClosing)
7509 if(!OnClose(parentClosing))
7512 // If you want to skip this, simply set modifiedDocument to false in OnClose
7513 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7515 DialogResult dialogRes;
7518 sprintf(message, $"Save changes to %s?", fileName);
7520 sprintf(message, $"Save changes to Untitled %d?", documentID);
7522 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = message }.Modal();
7524 if(dialogRes == yes)
7526 // TOFIX: Precomp error if brackets are taken out
7527 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7529 else if(dialogRes == cancel)
7535 for(slave = slaves.first; slave; slave = slave.next)
7537 Window w = slave.data;
7538 if(w.parent != this && !w.IsDescendantOf(this) && !w.CloseConfirmation(true))
7546 // Confirm closure of active clients first (We use OnClose() to hide instead of destroy in the IDE)
7549 for(child = children.first; child; child = child.next)
7550 if(child.isActiveClient && !child.CloseConfirmation(true))
7558 for(child = children.first; child; child = child.next)
7559 if(!child.isActiveClient && !child.CloseConfirmation(true))
7569 // Static methods... move them somewhere else?
7570 void ::RestoreCaret()
7572 if(guiApp.caretOwner)
7573 guiApp.caretOwner.UpdateCaret(false, false);
7576 void ::FreeMouseRange()
7578 guiApp.interfaceDriver.SetMouseRange(null, null);
7582 bool MenuFileClose(MenuItem selection, Modifiers mods)
7584 Window document = activeChild;
7586 document.Destroy(0);
7590 bool MenuFileExit(MenuItem selection, Modifiers mods)
7596 bool MenuFileSave(MenuItem selection, Modifiers mods)
7601 #if !defined(__EMSCRIPTEN__)
7602 fileMonitor.fileName = null;
7606 if(OnSaveFile(fileName))
7608 //if(OnFileModified != Window::OnFileModified)
7611 #if !defined(__EMSCRIPTEN__)
7612 fileMonitor.fileName = fileName;
7619 MessageBox dialog { master = master, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7620 DialogResult answer = dialog.Modal();
7622 if(answer != yes) return (bool)answer;
7625 return MenuFileSaveAs(selection, mods);
7628 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7630 DialogResult result = (DialogResult)bool::true;
7631 FileDialog fileDialog = saveDialog;
7636 fileDialog = FileDialog {};
7641 fileDialog.filePath = fileName;
7644 char filePath[MAX_FILENAME];
7645 sprintf(filePath, "Untitled %d", documentID);
7646 fileDialog.filePath = filePath;
7648 #if !defined(__EMSCRIPTEN__)
7649 fileMonitor.fileName = null;
7652 fileDialog.type = save;
7653 fileDialog.text = $"Save As";
7657 fileDialog.master = master.parent ? master : this;
7658 if(fileDialog.Modal() == ok)
7660 const char * filePath = fileDialog.filePath;
7662 if(OnSaveFile(filePath))
7665 property::fileName = filePath;
7666 NotifySaved(master, this, filePath);
7671 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7672 DialogResult answer = dialog.Modal();
7687 #if !defined(__EMSCRIPTEN__)
7688 //if(OnFileModified != Window::OnFileModified && fileName)
7691 fileMonitor.fileName = fileName;
7696 return (bool)result; // Actually returning result from Yes/NoCancel message box
7699 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7701 Window document = activeChild;
7703 for(document = children.first; document; document = next)
7705 next = document.next;
7706 if(document.style.isDocument || document.fileName)
7707 document.MenuFileSave(selection, mods);
7712 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7716 for(document = children.first; document; document = document.next)
7717 //if(document.style.isDocument && document.state == minimized)
7718 if(document.style.isActiveClient && document.state == minimized)
7719 document.SetState(minimized, false, mods);
7723 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7725 Window document = activeChild;
7728 Window firstDocument = null;
7730 OldLink cycle = document.cycle.prev;
7735 if(child.style.isActiveClient && !child.style.hidden)
7739 firstDocument = child;
7740 if(child.state == minimized)
7741 child.SetState(minimized, false, mods);
7744 child.positionID = id++;
7745 child.SetState(normal, false, mods);
7746 child.anchor.left.type = cascade;
7749 child.normalSizeAnchor = *&child.sizeAnchor;
7750 child.normalAnchor = child.anchor;
7752 // Break the anchors for moveable/resizable windows
7753 if(child.style.fixed)
7755 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7757 (*&child.normalAnchor).left = x;
7758 (*&child.normalAnchor).top = y;
7759 (*&child.normalAnchor).right.type = none;
7760 (*&child.normalAnchor).bottom.type = none;
7761 (*&child.normalSizeAnchor).isClientW = false;
7762 (*&child.normalSizeAnchor).isClientH = false;
7763 (*&child.normalSizeAnchor).size.w = w;
7764 (*&child.normalSizeAnchor).size.h = h;
7765 child.anchored = false;
7768 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7770 child.stateAnchor = child.normalAnchor;
7771 child.stateSizeAnchor = child.normalSizeAnchor;
7773 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7774 child.Position(x, y, w, h, true, true, true, true, false, false);
7779 last = children.last;
7780 if(!child.style.stayOnTop)
7781 for(; last && last.style.stayOnTop; last = last.prev);
7782 children.Move(child, last);
7783 childrenOrder.Move(child.order, childrenOrder.last);
7785 if(cycle == document.cycle) break;
7789 firstDocument.Activate();
7794 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7801 // Close all closes all active clients, not all documents
7802 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7804 Window next, document;
7806 for(document = children.first; document; document = next)
7808 for(next = document.next; next && !next.style.isActiveClient; next = next.next);
7809 if(document.style.isActiveClient)
7810 if(!document.Destroy(0) && !document.style.hidden)
7816 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7818 if(style.hasMaximize && state != maximized)
7819 SetState(maximized, 0, 0);
7823 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7825 if(style.hasMinimize && state != minimized)
7827 SetState(minimized, 0, 0);
7828 parent.CycleChildren(false, true, false, true);
7833 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7835 MenuMoveOrSize(false, selection ? true : false);
7839 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7841 CycleChildren(false, true, false, true);
7845 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7847 CycleChildren(true, true, false, true);
7851 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7853 MenuMoveOrSize(true, true);
7857 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7860 SetState(normal, 0, 0);
7864 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7867 int64 id = selection.id;
7868 OldLink cycle = activeClient.cycle;
7870 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7873 Window sibling = cycle.data;
7874 if(sibling.style.isActiveClient && sibling.visible && !sibling.style.nonClient)
7882 document = cycle.data;
7883 document.Activate();
7885 //if(activeChild.state == maximized)
7886 // document.SetState(maximized, false, mods);
7887 //else if(document.state == minimized)
7888 // document.SetState(normal, false, mods);
7892 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7894 stayOnTop = !style.stayOnTop;
7898 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7900 Window document = activeChild;
7903 Window firstDocument = null;
7904 OldLink cycle = document.cycle;
7908 Window child = cycle.data;
7909 if(child.style.isActiveClient && !child.style.hidden)
7911 if(!firstDocument) firstDocument = child;
7912 if(child.state == minimized)
7913 child.SetState(minimized, false, mods);
7916 child.positionID = id++;
7917 child.SetState(normal, false, mods);
7918 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7920 child.anchor.left.type = hTiled;
7923 child.normalSizeAnchor = *&child.sizeAnchor;
7924 child.normalAnchor = child.anchor;
7926 // Break the anchors for moveable/resizable windows
7927 if(child.style.fixed)
7929 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7931 (*&child.normalAnchor).left = x;
7932 (*&child.normalAnchor).top = y;
7933 (*&child.normalAnchor).right.type = none;
7934 (*&child.normalAnchor).bottom.type = none;
7935 (*&child.normalSizeAnchor).isClientW = false;
7936 (*&child.normalSizeAnchor).isClientH = false;
7937 (*&child.normalSizeAnchor).size.w = w;
7938 (*&child.normalSizeAnchor).size.h = h;
7939 child.anchored = false;
7942 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7944 child.stateAnchor = child.normalAnchor;
7945 child.stateSizeAnchor = child.normalSizeAnchor;
7947 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7948 child.Position(x,y, w, h, true, true, true, true, false, true);
7953 if((cycle = cycle.next) == document.cycle) break;
7956 firstDocument.Activate();
7961 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7963 Window document = activeChild;
7966 Window firstDocument = null;
7968 OldLink cycle = document.cycle;
7973 //if(child.style.isDocument)
7974 if(child.style.isActiveClient && !child.style.hidden)
7976 if(!firstDocument) firstDocument = child;
7977 if(child.state == minimized)
7978 child.SetState(minimized, false, mods);
7981 child.positionID = id++;
7982 child.SetState(normal, false, mods);
7983 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7985 child.anchor.left.type = vTiled;
7988 child.normalSizeAnchor = *&child.sizeAnchor;
7989 child.normalAnchor = child.anchor;
7991 // Break the anchors for moveable/resizable windows
7992 if(child.style.fixed)
7994 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7996 (*&child.normalAnchor).left = x;
7997 (*&child.normalAnchor).top = y;
7998 (*&child.normalAnchor).right.type = none;
7999 (*&child.normalAnchor).bottom.type = none;
8000 (*&child.normalSizeAnchor).isClientW = false;
8001 (*&child.normalSizeAnchor).isClientH = false;
8002 (*&child.normalSizeAnchor).size.w = w;
8003 (*&child.normalSizeAnchor).size.h = h;
8004 child.anchored = false;
8007 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
8009 child.stateAnchor = child.normalAnchor;
8010 child.stateSizeAnchor = child.normalSizeAnchor;
8012 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
8013 child.Position(x,y, w, h, true, true, true, true, false, true);
8018 if((cycle = cycle.next) == document.cycle) break;
8021 firstDocument.Activate();
8026 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
8030 master = this; isModal = true;
8032 void NotifyDestroyed(Window window, DialogResult result)
8034 Window document = (Window)(intptr)result;
8037 if(activeChild.state == maximized)
8038 document.SetState(maximized, false, 0);
8039 else if(document.state == minimized)
8040 document.SetState(normal, false, 0);
8041 document.Activate();
8049 virtual bool OnCreate(void);
8050 virtual void OnDestroy(void);
8051 virtual void OnDestroyed(void);
8052 virtual bool OnClose(bool parentClosing);
8053 virtual bool OnStateChange(WindowState state, Modifiers mods);
8054 virtual bool OnPostCreate(void);
8055 virtual bool OnMoving(int *x, int *y, int w, int h);
8056 virtual bool OnResizing(int *width, int *height);
8057 virtual void OnResize(int width, int height);
8058 virtual void OnPosition(int x, int y, int width, int height);
8059 virtual bool OnLoadGraphics(void);
8060 virtual void OnApplyGraphics(void);
8061 virtual void OnUnloadGraphics(void);
8062 virtual void OnRedraw(Surface surface);
8063 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
8064 virtual void OnActivateClient(Window client, Window previous);
8065 virtual bool OnKeyDown(Key key, unichar ch);
8066 virtual bool OnKeyUp(Key key, unichar ch);
8067 virtual bool OnKeyHit(Key key, unichar ch);
8068 virtual bool OnSysKeyDown(Key key, unichar ch);
8069 virtual bool OnSysKeyUp(Key key, unichar ch);
8070 virtual bool OnSysKeyHit(Key key, unichar ch);
8071 virtual bool OnMouseOver(int x, int y, Modifiers mods);
8072 virtual bool OnMouseLeave(Modifiers mods);
8073 virtual bool OnMouseMove(int x, int y, Modifiers mods);
8074 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
8075 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
8076 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
8077 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
8078 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
8079 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
8080 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
8081 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
8082 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
8083 virtual bool OnMultiTouch(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods);
8084 virtual void OnMouseCaptureLost(void);
8085 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
8086 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
8087 virtual void OnDrawOverChildren(Surface surface);
8088 virtual bool OnFileModified(FileChange fileChange, const char * param);
8089 virtual bool OnSaveFile(const char * fileName);
8091 // Virtual Methods -- Children management (To support Stacker, for lack of built-in auto-layout)
8092 // Note: A 'client' would refer to isActiveClient, rather than
8093 // being confined to the 'client area' (nonClient == false)
8094 virtual void OnChildAddedOrRemoved(Window child, bool removed);
8095 virtual void OnChildVisibilityToggled(Window child, bool visible);
8096 virtual void OnChildResized(Window child, int x, int y, int w, int h);
8098 // Skins Virtual Functions
8099 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
8100 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
8101 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
8106 virtual void ShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
8107 virtual void PreShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
8108 virtual bool IsMouseMoving(int x, int y, int w, int h)
8112 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY)
8116 virtual void UpdateNonClient();
8117 virtual void SetBox(Box box); // This is used in the MySkin skin
8118 virtual bool IsInside(int x, int y)
8120 return box.IsPointInside({x, y});
8122 virtual bool IsOpaque()
8124 return (!style.drawBehind || background.a == 255);
8128 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
8129 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
8130 virtual void Window::NotifySaved(Window window, const char * filePath);
8135 property Window parent
8137 property_category $"Layout"
8140 if(value || guiApp.desktop)
8143 Window oldParent = parent;
8144 Anchor anchor = this.anchor;
8146 if(value && value.IsDescendantOf(this)) return;
8147 if(value && value == this)
8149 if(!value) value = guiApp.desktop;
8151 if(value == oldParent) return;
8153 if(!master || (master == this.parent && master == guiApp.desktop))
8154 property::master = value;
8158 parent.children.Remove(this);
8162 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
8163 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
8164 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
8165 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
8169 last = value.children.last;
8171 if(style.isDocument)
8174 parent.numDocuments--;
8175 documentID = value.GetDocumentID();
8178 if(style.isActiveClient && !style.hidden)
8180 if(parent && parent != guiApp.desktop && !(style.hidden))
8182 if(state == minimized) parent.numIcons--;
8183 parent.numPositions--;
8187 if(!style.stayOnTop)
8188 for(; last && last.style.stayOnTop; last = last.prev);
8190 value.children.Insert(last, this);
8192 // *** NEW HERE: ***
8194 parent.childrenCycle.Delete(cycle);
8196 parent.childrenOrder.Delete(order);
8199 // *** TODO: Added this here to solve crash on setting parent to null before destroying/destructing ***
8200 // Should something else be done?
8201 if(parent && parent.activeChild == this)
8202 parent.activeChild = null;
8203 if(parent && parent.activeClient == this)
8204 parent.activeClient = null;
8210 int x = position.x, y = position.y, w = size.w, h = size.h;
8214 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
8215 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
8217 vpw = value.clientSize.w;
8218 vph = value.clientSize.h;
8224 else if(style.fixed)
8226 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
8227 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
8230 anchor = this.anchor;
8232 if(anchor.left.type == offset) anchor.left.distance = x;
8233 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
8234 if(anchor.top.type == offset) anchor.top.distance = y;
8235 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
8236 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
8237 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
8238 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
8239 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
8240 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
8241 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
8243 if(!anchor.left.type && !anchor.right.type)
8245 anchor.horz.distance = (x + w / 2) - (vpw / 2);
8246 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
8248 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
8249 if(!anchor.top.type && !anchor.bottom.type)
8251 anchor.vert.distance = (y + h / 2) - (vph / 2);
8252 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
8254 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
8257 parent.OnChildAddedOrRemoved(this, false);
8263 parent.childrenCycle.Insert(
8264 // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
8265 //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8267 cycle = OldLink { data = this });
8268 parent.childrenOrder.Insert(
8269 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8270 order = OldLink { data = this });
8273 if(!style.hidden && style.isActiveClient)
8275 positionID = parent.GetPositionID(this);
8276 parent.numPositions++;
8277 if(state == minimized) parent.numIcons--;
8280 // *** FONT INHERITANCE ***
8281 if(!setFont && oldParent)
8282 stopwatching(oldParent, font);
8286 RemoveResource(systemFont);
8289 // TESTING WITH WATCHERS:
8290 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8291 // usedFont = setFont ? setFont : (systemFont);
8295 if(guiApp.currentSkin)
8297 systemFont = guiApp.currentSkin.SystemFont();
8300 usedFont = systemFont;
8301 AddResource(systemFont);
8309 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8318 if(value.rootWindow && value.rootWindow.display && rootWindow && created)
8320 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
8321 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
8324 UnloadGraphics(false);
8327 LoadGraphics(false, false);
8330 if(value.rootWindow != rootWindow)
8331 DisplayModeChanged();
8335 scrolledPos.x = MININT; // Prevent parent update
8337 bool anchored = this.anchored;
8338 property::anchor = anchor;
8339 this.anchored = anchored;
8344 if(guiApp.currentSkin)
8345 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
8347 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8348 Position(x, y, w, h, true, true, true, true, false, true);
8353 // else parent = value;
8355 oldParent.OnChildAddedOrRemoved(this, true);
8358 get { return parent; }
8361 property Window master
8363 property_category $"Behavior"
8366 //if(this == value) return;
8367 if(value && value.IsSlaveOf(this)) return;
8373 OldLink slaveHolder;
8374 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
8375 if(slaveHolder.data == this)
8377 master.slaves.Delete(slaveHolder);
8384 value.slaves.Add(OldLink { data = this });
8389 master.hotKeys.Remove(hotKey);
8390 value.hotKeys.Add(hotKey);
8393 if(master && master.defaultControl == this)
8394 master.defaultControl = null;
8396 if(style.isDefault && !value.defaultControl)
8397 value.defaultControl = this;
8402 get { return master ? master : parent; }
8405 property const char * caption
8407 property_category $"Appearance"
8414 caption = new char[strlen(value)+1];
8416 strcpy(caption, value);
8421 get { return caption; }
8426 property_category $"Behavior"
8435 master.hotKeys.Add(hotKey = HotKeySlot { });
8439 hotKey.window = this;
8444 master.hotKeys.Delete(hotKey);
8449 get { return hotKey ? hotKey.key : 0; }
8452 property Color background
8454 property_category $"Appearance"
8457 background.color = value;
8462 if(this == rootWindow)
8463 guiApp.interfaceDriver.SetRootWindowColor(this);
8466 get { return background.color; }
8469 property Percentage opacity
8471 property_category $"Appearance"
8474 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
8475 drawBehind = (background.a == 255) ? false : true;
8477 get { return background.a / 255.0f; }
8480 property Color foreground
8482 property_category $"Appearance"
8490 get { return foreground; }
8493 property BorderStyle borderStyle
8495 property_category $"Appearance"
8498 if(!((BorderBits)value).fixed)
8500 style.hasClose = false;
8501 style.hasMaximize = false;
8502 style.hasMinimize = false;
8503 nativeDecorations = false;
8505 style.borderBits = value;
8509 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8511 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8512 Position(x, y, w, h, true, true, true, true, false, true);
8513 CreateSystemChildren();
8516 get { return (BorderStyle)style.borderBits; }
8519 property Size minClientSize
8521 property_category $"Layout"
8522 set { minSize = value; }
8523 get { value = minSize; }
8526 property Size maxClientSize
8528 property_category $"Layout"
8529 set { maxSize = value; }
8530 get { value = maxSize; }
8533 property bool hasMaximize
8535 property_category $"Window Style"
8538 style.hasMaximize = value;
8539 if(value) { style.fixed = true; style.contour = true; }
8543 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8545 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8546 Position(x, y, w, h, true, true, true, true, false, true);
8548 CreateSystemChildren();
8551 get { return style.hasMaximize; }
8554 property bool hasMinimize
8556 property_category $"Window Style"
8559 style.hasMinimize = value;
8560 if(value) { style.fixed = true; style.contour = true; }
8564 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8566 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8567 Position(x, y, w, h, true, true, true, true, false, true);
8569 CreateSystemChildren();
8572 get { return style.hasMinimize; }
8575 property bool hasClose
8577 property_category $"Window Style"
8580 style.hasClose = value;
8581 if(value) { style.fixed = true; style.contour = true; }
8585 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8586 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8587 Position(x, y, w, h, true, true, true, true, false, true);
8588 CreateSystemChildren();
8591 get { return style.hasClose; }
8594 property bool nonClient
8596 property_category $"Layout"
8599 style.nonClient = value;
8601 style.stayOnTop = true;
8603 get { return style.nonClient; }
8606 property bool inactive
8608 property_category $"Behavior"
8613 // *** NEW HERE: ***
8617 parent.childrenCycle.Delete(cycle);
8619 parent.childrenOrder.Delete(order);
8626 active = false; // true;
8627 if(parent.activeChild == this)
8628 parent.activeChild = null;
8629 if(parent.activeClient == this)
8630 parent.activeClient = null;
8639 parent.childrenCycle.Insert(
8640 // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
8641 //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8643 cycle = OldLink { data = this });
8645 parent.childrenOrder.Insert(
8646 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8647 order = OldLink { data = this });
8650 style.inactive = value;
8652 get { return style.inactive; }
8655 property bool clickThrough
8657 property_category $"Behavior"
8658 set { style.clickThrough = value; }
8659 get { return style.clickThrough; }
8662 property bool isRemote
8664 property_category $"Behavior"
8665 set { style.isRemote = value; }
8666 get { return style.isRemote; }
8669 property bool noCycle
8671 property_category $"Behavior"
8672 set { style.noCycle = value; }
8673 get { return style.noCycle; }
8676 property bool isModal
8678 property_category $"Behavior"
8679 set { style.modal = value; }
8680 get { return style.modal; }
8683 property bool interim
8685 property_category $"Behavior"
8686 set { style.interim = value; }
8687 get { return style.interim; }
8690 property bool tabCycle
8692 property_category $"Behavior"
8693 set { style.tabCycle = value; }
8694 get { return style.tabCycle; }
8697 property bool isDefault
8699 property_category $"Behavior"
8707 for(sibling = parent.children.first; sibling; sibling = sibling.next)
8708 if(sibling != this && sibling.style.isDefault)
8709 sibling.style.isDefault = false;*/
8710 if(master.defaultControl)
8711 master.defaultControl.style.isDefault = false;
8712 master.defaultControl = this;
8714 else if(master.defaultControl == this)
8715 master.defaultControl = null;
8719 style.isDefault = value;
8721 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8723 get { return style.isDefault; }
8726 property bool drawBehind
8728 property_category $"Window Style"
8729 set { style.drawBehind = value; }
8730 get { return style.drawBehind; }
8733 property bool hasMenuBar
8735 property_category $"Window Style"
8745 if(created && !menuBar)
8752 anchor = Anchor { top = 23, left = 1, right = 1 },
8754 inactive = true, nonClient = true
8759 else if(created && menuBar)
8764 style.hasMenuBar = value;
8766 get { return style.hasMenuBar; }
8769 property bool hasStatusBar
8771 property_category $"Window Style"
8778 statusBar = StatusBar { this };
8786 style.hasStatusBar = value;
8788 get { return style.hasStatusBar; }
8790 property bool stayOnTop
8792 property_category $"Window Style"
8797 if(created && !style.stayOnTop)
8799 if(rootWindow == this)
8800 guiApp.interfaceDriver.OrderRootWindow(this, true);
8801 else if(parent.children.last != this)
8803 parent.children.Move(this, parent.children.last);
8807 style.stayOnTop = true;
8811 if(created && style.stayOnTop)
8813 if(rootWindow == this)
8814 guiApp.interfaceDriver.OrderRootWindow(this, false);
8821 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8822 order && ((Window)order.data).style.stayOnTop;
8823 order = (order == parent.childrenOrder.first) ? null : order.prev);
8824 last = order ? order.data : null;
8828 for(last = parent.children.last;
8829 last && last.style.stayOnTop;
8833 parent.children.Move(this, last);
8837 style.stayOnTop = false;
8840 get { return style.stayOnTop; }
8845 property_category $"Window Style"
8855 if(menuBar && !value)
8862 if(!menuBar && style.hasMenuBar && value)
8866 this, menu = value, isMenuBar = true,
8867 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8868 inactive = true, nonClient = true
8872 UpdateActiveDocument(null);
8875 get { return menu; }
8878 property FontResource font
8880 property_category $"Appearance"
8882 isset { return setFont ? true : false; }
8887 if(value && !setFont) { stopwatching(parent, font); }
8888 else if(!value && setFont)
8894 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8903 RemoveResource(setFont);
8908 RemoveResource(systemFont);
8915 AddResource(setFont);
8918 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8921 systemFont = guiApp.currentSkin.SystemFont();
8923 usedFont = systemFont;
8924 AddResource(systemFont);
8932 get { return usedFont; }
8935 property SizeAnchor sizeAnchor
8937 property_category $"Layout"
8940 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8941 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8942 sizeAnchor.isClientW != sizeAnchor.isClientH;
8949 normalSizeAnchor = sizeAnchor;
8951 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8953 stateAnchor = normalAnchor;
8954 stateSizeAnchor = normalSizeAnchor;
8956 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8957 Position(x,y, w, h, true, true, true, true, false, true);
8964 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8965 sizeAnchor.isClientW,
8966 sizeAnchor.isClientH
8973 property_category $"Layout"
8976 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8977 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8978 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8984 sizeAnchor.isClientW = false;
8985 sizeAnchor.isClientH = false;
8986 sizeAnchor.size = value;
8988 normalSizeAnchor = sizeAnchor;
8990 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8992 stateAnchor = normalAnchor;
8993 stateSizeAnchor = normalSizeAnchor;
8995 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8996 Position(x, y, w, h, true, true, true, true, false, true);
8997 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
9000 get { value = size; }
9003 property Size clientSize
9005 property_category $"Layout"
9008 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
9009 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
9010 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
9015 sizeAnchor.isClientW = true;
9016 sizeAnchor.isClientH = true;
9017 sizeAnchor.size = value;
9019 normalSizeAnchor = sizeAnchor;
9021 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9023 stateAnchor = normalAnchor;
9024 stateSizeAnchor = normalSizeAnchor;
9026 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9027 Position(x,y, w, h, true, true, true, true, false, true);
9028 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
9031 get { value = this ? clientSize : { 0, 0 }; }
9034 property Size initSize { get { value = sizeAnchor.size; } };
9036 property Anchor anchor
9038 property_category $"Layout"
9039 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
9045 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
9047 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
9048 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
9050 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
9052 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
9053 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
9057 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
9059 anchor.left.distance = 0;
9060 anchor.horz.type = 0;
9062 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
9064 anchor.top.distance = 0;
9065 anchor.vert.type = 0;
9074 normalAnchor = anchor;
9076 // Break the anchors for moveable/resizable windows
9077 /*if(style.fixed ) //&& value.left.type == cascade)
9079 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
9081 this.anchor = normalAnchor = Anchor { left = x, top = y };
9082 normalSizeAnchor = SizeAnchor { { w, h } };
9085 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9087 stateAnchor = normalAnchor;
9088 stateSizeAnchor = normalSizeAnchor;
9090 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9091 Position(x, y, w, h, true, true, true, true, false, true);
9100 get { value = this ? anchor : Anchor { }; }
9103 property Point position
9105 property_category $"Layout"
9108 if(value == null) return;
9110 anchor.left = value.x;
9111 anchor.top = value.y;
9112 anchor.right.type = none;
9113 anchor.bottom.type = none;
9118 normalAnchor = anchor;
9120 // Break the anchors for moveable/resizable windows
9124 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9126 normalAnchor.left = x;
9127 normalAnchor.top = y;
9128 normalAnchor.right.type = none;
9129 normalAnchor.bottom.type = none;
9130 normalSizeAnchor.size.width = w;
9131 normalSizeAnchor.size.height = h;
9135 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9137 stateAnchor = normalAnchor;
9138 stateSizeAnchor = normalSizeAnchor;
9140 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9141 Position(x,y, w, h, true, true, true, true, false, true);
9145 get { value = position; }
9148 property bool disabled
9150 property_category $"Behavior"
9153 if(this && disabled != value)
9160 get { return (bool)disabled; }
9163 property bool isEnabled
9168 for(parent = this; parent; parent = parent.parent)
9175 property WindowState state
9177 property_category $"Behavior"
9178 set { SetState(value, false, 0); }
9179 get { return this ? state : 0; }
9182 property bool visible
9184 property_category $"Behavior"
9187 if(this && !value && !style.hidden && parent)
9189 bool wasActiveChild = parent.activeChild == this;
9190 Window client = null;
9192 style.hidden = true;
9193 if(style.isActiveClient)
9195 parent.numPositions--;
9196 if(state == minimized) parent.numIcons--;
9201 OldLink prevOrder = null;
9203 if(rootWindow == this)
9204 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
9207 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
9210 box.left -= parent.clientStart.x;
9211 box.top -= parent.clientStart.y;
9212 box.right -= parent.clientStart.x;
9213 box.bottom -= parent.clientStart.y;
9217 if(_isModal && master && master.modalSlave == this)
9218 master.modalSlave = null;
9222 OldLink tmpPrev = order.prev;
9223 client = tmpPrev ? tmpPrev.data : null;
9224 if(client && !client.style.hidden && !client.destroyed && client.created)
9225 prevOrder = tmpPrev;
9228 client = tmpPrev ? tmpPrev.data : null;
9229 if(client == this) { client = null; break; }
9230 if(client && ((client.style.hidden) || client.destroyed || !client.created))
9232 tmpPrev = client.order.prev;
9237 prevOrder = tmpPrev;
9242 // If this window can be an active client, make sure the next window we activate can also be one
9243 if(!style.nonClient && style.isActiveClient)
9245 tmpPrev = prevOrder;
9248 client = tmpPrev ? tmpPrev.data : null;
9249 if(client == this) { client = null; break; }
9250 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
9252 tmpPrev = client.order.prev;
9257 prevOrder = tmpPrev;
9261 if(client && client.style.hidden) client = null;
9265 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
9267 if(order && prevOrder && prevOrder.data != this)
9268 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
9270 ActivateEx(false, false, false, true, null, null);
9272 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
9273 if(parent.activeClient == this)
9275 parent.activeClient = null;
9276 parent.UpdateActiveDocument(null);
9279 else if(parent.activeClient == this)
9281 parent.activeClient = client;
9282 parent.UpdateActiveDocument(this);
9285 // *** Not doing this anymore ***
9288 parent.childrenCycle.Delete(cycle);
9290 parent.childrenOrder.Delete(order);
9295 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9300 else if(this && value && style.hidden)
9302 style.hidden = false;
9305 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9306 if(rootWindow == this)
9307 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
9309 if(_isModal && master)
9310 master.modalSlave = this;
9312 if(style.isActiveClient)
9314 positionID = parent.GetPositionID(this);
9315 parent.numPositions++;
9316 if(state == minimized) parent.numIcons++;
9319 // *** NOT DOING THIS ANYMORE ***
9321 if(!(style.inactive))
9323 if(!(style.noCycle))
9325 cycle = parent.childrenCycle.AddAfter(
9326 (parent.activeChild && parent.activeChild.cycle) ?
9327 parent.activeChild.cycle.prev : null, sizeof(OldLink));
9330 order = parent.childrenOrder.AddAfter(
9331 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
9338 if(true || !parent.activeChild)
9339 ActivateEx(true, false, true, true, null, null);
9341 if(creationActivation == activate && guiApp.desktop.active)
9342 ActivateEx(true, false, true, true, null, null);
9343 else if((creationActivation == activate || creationActivation == flash) && !object)
9346 if(this == rootWindow)
9350 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9354 ConsequentialMouseMove(false);
9360 style.hidden = !value;
9363 get { return (style.hidden || !setVisible) ? false : true; }
9366 property bool isDocument
9368 property_category $"Document"
9369 set { style.isDocument = value; if(value) SetupFileMonitor(); }
9370 get { return style.isDocument; }
9373 property bool mergeMenus
9375 property_category $"Window Style"
9376 set { mergeMenus = value; }
9377 get { return (bool)mergeMenus; }
9380 property bool hasHorzScroll
9382 property_category $"Window Style"
9387 if(!style.hasHorzScroll && created)
9389 CreateSystemChildren();
9390 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9393 else if(style.hasHorzScroll)
9397 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9399 style.hasHorzScroll = value;
9402 get { return style.hasHorzScroll; }
9405 property bool hasVertScroll
9407 property_category $"Window Style"
9412 if(!style.hasVertScroll && created)
9414 style.hasVertScroll = true;
9415 CreateSystemChildren();
9416 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9419 else if(style.hasVertScroll)
9423 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9425 style.hasVertScroll = value;
9427 get { return style.hasVertScroll; }
9430 property bool dontHideScroll
9432 property_category $"Behavior"
9435 scrollFlags.dontHide = value;
9438 //UpdateScrollBars(true, true);
9439 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9443 // UpdateScrollBars(true, true);
9444 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9447 get { return scrollFlags.dontHide; }
9450 property bool dontScrollVert
9452 property_category $"Behavior"
9453 set { style.dontScrollVert = value; }
9454 get { return style.dontScrollVert; }
9456 property bool dontScrollHorz
9458 property_category $"Behavior"
9459 set { style.dontScrollHorz = value; }
9460 get { return style.dontScrollHorz; }
9463 property bool snapVertScroll
9465 property_category $"Behavior"
9468 scrollFlags.snapY = value;
9469 if(sbv) sbv.snap = value;
9471 get { return scrollFlags.snapY; }
9473 property bool snapHorzScroll
9475 property_category $"Behavior"
9478 scrollFlags.snapX = value;
9479 if(sbh) sbh.snap = value;
9481 get { return scrollFlags.snapX; }
9484 property Point scroll
9486 property_category $"Behavior"
9487 set { if(this) SetScrollPosition(value.x, value.y); }
9488 get { value = scroll; }
9491 property bool modifyVirtualArea
9493 property_category $"Behavior"
9494 set { modifyVirtArea = value; }
9495 get { return (bool)modifyVirtArea; }
9498 property bool dontAutoScrollArea
9500 property_category $"Behavior"
9501 // Activating a child control out of view will automatically scroll to make it in view
9502 set { noAutoScrollArea = value; }
9503 get { return (bool)noAutoScrollArea; }
9506 property const char * fileName
9508 property_category $"Document"
9513 if(menu && ((!fileName && value) || (fileName && !value)))
9515 MenuItem item = menu.FindItem(MenuFileSave, 0);
9516 if(item) item.disabled = !modifiedDocument && value;
9521 if(value && value[0])
9522 fileName = CopyString(value);
9524 if(parent && this == parent.activeClient)
9525 parent.UpdateActiveDocument(null);
9529 // if(style.isDocument)
9530 #if !defined(__EMSCRIPTEN__)
9532 fileMonitor.fileName = value;
9535 get { return fileName; }
9540 property_category $"Data"
9545 property bool modifiedDocument
9547 property_category $"Document"
9550 if(style.isDocument || fileName)
9554 MenuItem item = menu.FindItem(MenuFileSave, 0);
9555 if(item) item.disabled = !value && fileName;
9559 if(modifiedDocument != value)
9561 modifiedDocument = value;
9562 if(style.isDocument || fileName)
9566 get { return (bool)modifiedDocument; }
9569 property bool showInTaskBar
9571 property_category $"Window Style"
9574 style.showInTaskBar = value;
9575 #if defined(__WIN32__)
9576 Win32UpdateStyle(this);
9579 get { return style.showInTaskBar; }
9581 property FileDialog saveDialog { set { saveDialog = value; } };
9582 property bool isActiveClient
9584 property_category $"Behavior"
9587 if(parent && style.isActiveClient != value && !style.hidden)
9591 if(state == minimized) parent.numIcons++;
9592 parent.numPositions++;
9596 if(state == minimized) parent.numIcons--;
9597 parent.numPositions--;
9600 style.isActiveClient = value;
9602 get { return style.isActiveClient; }
9605 property Cursor cursor
9607 property_category $"Appearance"
9611 SelectMouseCursor();
9613 get { return cursor; }
9616 //#if !defined(ECERE_VANILLA)
9617 property const char * name
9619 property_category $"Design"
9622 return (this && object) ? object.name : null;
9627 activeDesigner.RenameObject(object, value);
9631 property const char * displayDriver
9633 property_category $"Behavior"
9636 dispDriver = GetDisplayDriver(value);
9637 //DisplayModeChanged();
9641 return dispDriver ? dispDriver.name : null;
9645 // RUNTIME PROPERTIES
9646 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9647 property Size scrollArea
9649 property_category $"Behavior"
9653 SetScrollArea(value.w, value.h, false);
9655 SetScrollArea(0,0, true);
9657 get { value = scrollArea; }
9660 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9665 property_category $"Layout"
9666 set { if(this) is3D = value; }
9667 get { return (bool)is3D; }
9670 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9672 // Will be merged with font later
9673 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9674 property Point clientStart { get { value = clientStart; } };
9675 property Point absPosition { get { value = absPosition; } };
9676 property Anchor normalAnchor { get { value = normalAnchor; } };
9677 property SizeAnchor normalSizeAnchor { get { value = normalSizeAnchor; } };
9678 property bool active { get { return (bool)active; } };
9679 property bool created { get { return (bool)created; } };
9680 property bool destroyed { get { return (bool)destroyed; } };
9681 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9682 property Window firstChild { get { return children.first; } };
9683 property Window lastChild { get { return children.last; } };
9684 property Window activeClient { get { return activeClient; } };
9685 property Window activeChild { get { return activeChild; } };
9686 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9687 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9688 property ScrollBar horzScroll { get { return sbh; } };
9689 property ScrollBar vertScroll { get { return sbv; } };
9690 property StatusBar statusBar { get { return statusBar; } };
9691 property Window rootWindow { get { return rootWindow; } };
9692 property bool closing { get { return (bool)closing; } set { closing = value; } };
9693 property int documentID { get { return documentID; } };
9694 property Window previous { get { return prev; } }
9695 property Window next { get { return next; } }
9696 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9697 property PopupMenu menuBar { get { return menuBar; } }
9698 property ScrollBar sbv { get { return sbv; } }
9699 property ScrollBar sbh { get { return sbh; } }
9700 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9701 property void * systemHandle { get { return windowHandle; } }
9702 property Button minimizeButton { get { return sysButtons[0]; } };
9703 property Button maximizeButton { get { return sysButtons[1]; } };
9704 property Button closeButton { get { return sysButtons[2]; } };
9705 property BitmapResource icon
9707 get { return icon; }
9711 if(icon) incref icon;
9713 guiApp.interfaceDriver.SetIcon(this, value);
9716 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9717 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; if(value) nativeDecorations = false; /* Native Decorations are not supported with alphaBlend */ } };
9718 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9719 property GLCapabilities glCapabilities
9721 get { return glCapabilities; }
9724 bool reload = display != null &&
9725 (glCapabilities.nonPow2Textures != value.nonPow2Textures ||
9726 glCapabilities.intAndDouble != value.intAndDouble ||
9727 glCapabilities.vertexBuffer != value.vertexBuffer ||
9728 glCapabilities.compatible != value.compatible ||
9729 glCapabilities.legacyFormats != value.legacyFormats ||
9730 glCapabilities.debug != value.debug ||
9731 glCapabilities.vertexPointer != value.vertexPointer ||
9732 glCapabilities.quads != value.quads);
9734 UnloadGraphics(false);
9736 glCapabilities = value;
9741 LoadGraphics(false, false);
9744 display.glCapabilities = value;
9747 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9748 property bool nativeDecorations
9750 get { return (bool)nativeDecorations; }
9751 set { nativeDecorations = value; }
9752 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
9755 //return (nativeDecorations && (rootWindow == this || (formDesigner && activeDesigner && ((FormDesigner)activeDesigner.classDesigner).form && parent == ((FormDesigner)activeDesigner.classDesigner).form.parent))) != style.fixed;
9756 bool result = false;
9757 if(nativeDecorations)
9759 if(rootWindow == this)
9763 if(formDesigner && activeDesigner)
9765 FormDesigner cd = (FormDesigner)activeDesigner.classDesigner;
9766 Window form = cd ? cd.form : null;
9767 if(form && parent == form.parent)
9772 return result != style.fixed;
9776 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9778 property const char * text
9780 property_category $"Deprecated"
9782 set { property::caption = value; }
9783 get { return property::caption; }
9789 WindowBits style; // Window Style
9790 char * caption; // Name / Caption
9791 Window parent; // Parent window
9792 OldList children; // List of children in Z order
9793 Window activeChild; // Child window having focus
9794 Window activeClient;
9795 Window previousActive; // Child active prior to activating the default child
9796 Window master; // Window owning and receiving notifications concerning this window
9797 OldList slaves; // List of windows belonging to this window
9798 Display display; // Display this window is drawn into
9800 Point position; // Position in parent window client area
9801 Point absPosition; // Absolute position
9802 Point clientStart; // Client area position from (0,0) in this window
9804 Size clientSize; // Client area size
9805 Size scrollArea; // Virtual Scroll area size
9806 Size reqScrollArea; // Requested virtual area size
9807 Point scroll; // Virtual area scrolling position
9808 ScrollBar sbh, sbv; // Scrollbar window handles
9809 Cursor cursor; // Mouse cursor used for this window
9812 StatusBar statusBar;
9813 Button sysButtons[3];
9815 Box clientArea; // Client Area box clipped to parent
9817 HotKeySlot hotKey; // HotKey for this window
9821 ScrollFlags scrollFlags;// Window Scrollbar Flags
9822 int64 id; // Control ID
9824 ColorAlpha background; // Background color used to draw the window area
9826 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9827 OldList childrenCycle; // Cycling order
9828 OldLink cycle; // Element of parent's cycling order
9829 OldList childrenOrder; // Circular Z-Order
9830 OldLink order; // Element of parent's circular Z-Order
9831 Window modalSlave; // Slave window blocking this window's interaction
9833 Window rootWindow; // Topmost system managed window
9834 void * windowHandle; // System window handle
9836 DialogResult returnCode;// Return code for modal windows
9838 Point sbStep; // Scrollbar line scrolling steps
9841 SizeAnchor stateSizeAnchor;
9843 Anchor normalAnchor;
9844 SizeAnchor normalSizeAnchor;
9846 Size skinMinSize; // Minimal window size based on style
9847 Point scrolledPos; // Scrolled position
9848 Box box; // Window box clipped to parent
9849 Box * against; // What to clip the box to
9851 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9852 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9853 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9854 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9855 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9856 Point scrolledArea; // Distance to scroll area by
9857 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9859 OldList hotKeys; // List of the hotkeys of all children
9860 Window defaultControl; // Default child control
9864 ColorAlpha * palette; // Color palette used for this window
9866 int caretSize; // Size of caret, non zero if a caret is present
9867 Point caretPos; // Caret position
9869 void * systemParent; // Parent System Window for embedded windows
9875 #if !defined(__EMSCRIPTEN__)
9878 WindowState lastState;
9880 #if !defined(__EMSCRIPTEN__)
9881 FileMonitor fileMonitor;
9884 FontResource setFont, systemFont;
9885 FontResource usedFont;
9886 FontResource captionFont;
9888 FileDialog saveDialog;
9890 SizeAnchor sizeAnchor;
9892 // FormDesigner data
9895 Extent * tempExtents; //[4];
9896 BitmapResource icon;
9898 CreationActivationOption creationActivation;
9899 GLCapabilities glCapabilities;
9900 glCapabilities = { true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true };
9903 bool active:1; // true if window and ancestors are active
9904 bool acquiredInput:1; // true if the window is processing state based input
9905 bool modifiedDocument:1;
9906 bool disabled:1; // true if window cannot interact
9907 bool isForegroundWindow:1;// true while a root window is being activated
9908 bool visible:1; // Visibility flag
9909 bool destroyed:1; // true if window is being destroyed
9910 bool anchored:1; // true if this window is repositioned when the parent resizes
9911 bool dirty:1; // Flag set to true if any descendant must be redrawn
9917 bool modifyVirtArea:1;
9918 bool noAutoScrollArea:1;
9921 bool setVisible:1; // FOR FORM DESIGNER
9927 bool useSharedMemory:1;
9930 bool nativeDecorations:1;
9931 bool manageDisplay:1;
9932 bool formDesigner:1; // True if we this is running in the form editor
9933 bool requireRemaximize:1;
9934 bool noConsequential:1;
9937 // Checks used internally for them not to take effect in FormDesigner
9938 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9939 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9941 WindowController controller;
9943 public property WindowController controller
9945 get { return controller; }
9949 controller.setWindow(null);
9955 controller.setWindow(this);
9960 public property bool noConsequential
9962 set { noConsequential = value; }
9963 get { return noConsequential; }
9967 public class CommonControl : Window
9969 // creationActivation = doNothing;
9972 public property const String toolTip
9974 property_category $"Appearance"
9977 if(created) CommonControl::OnDestroy();
9979 toolTip = value ? ToolTip { tip = value; } : null;
9981 if(created) CommonControl::OnCreate();
9983 get { return toolTip ? toolTip.tip : null; }
9989 // (Very) Ugly work around for the fact that the parent watcher
9990 // won't fire when it's already been disconnected...
9991 eInstance_FireSelfWatchers(toolTip,
9992 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
9998 toolTip.parent = this;
10007 public class Percentage : float
10009 const char * OnGetString(char * string, float * fieldData, bool * needClass)
10013 sprintf(string, "%.2f", this);
10014 c = strlen(string)-1;
10015 for( ; c >= 0; c--)
10017 if(string[c] != '0')
10018 last = Max(last, c);
10019 if(string[c] == '.')
10024 string[last+1] = 0;
10032 public void ApplySkin(Class c, const char * name, void ** vTbl)
10034 char className[1024];
10039 subclass(Window) wc = (subclass(Window))c;
10040 subclass(Window) base = (subclass(Window))c.base;
10042 sprintf(className, "%sSkin_%s", name, c.name);
10043 wc.pureVTbl = c._vTbl;
10044 c._vTbl = new void *[c.vTblSize];
10045 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
10046 sc = eSystem_FindClass(c.module.application, className);
10050 for(m = 0; m < c.base.vTblSize; m++)
10052 if(c._vTbl[m] == base.pureVTbl[m])
10053 c._vTbl[m] = vTbl[m];
10058 for(m = 0; m < c.vTblSize; m++)
10060 if(sc._vTbl[m] != wc.pureVTbl[m])
10061 c._vTbl[m] = sc._vTbl[m];
10065 for(d = c.derivatives.first; d; d = d.next)
10067 ApplySkin(d.data, name, c._vTbl);
10071 public void UnapplySkin(Class c)
10073 subclass(Window) wc = (subclass(Window))c;
10076 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
10079 c._vTbl = wc.pureVTbl;
10080 wc.pureVTbl = null;
10083 for(d = c.derivatives.first; d; d = d.next)
10085 UnapplySkin(d.data);
10089 void CheckFontIntegrity(Window window)
10094 if(window.usedFont && window.usedFont.font == 0xecececec)
10096 FontResource uf = window.usedFont;
10097 char * className = window._class.name;
10098 char * text = window.text;
10101 for(c = window.firstChild; c; c = c.next)
10102 CheckFontIntegrity(c);
10106 public class ControllableWindow : Window
10108 /*WindowController controller;
10109 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
10110 ~ControllableWindow() { delete controller; }*/
10113 class WindowControllerInterface : ControllableWindow
10115 bool OnKeyDown(Key key, unichar ch)
10117 bool result = controller.OnKeyDown ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyDown)((Window)controller.controlled, controller, key, ch) : true;
10120 bool (* onKeyDown)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown];
10122 result = onKeyDown(controller.window, key, ch);
10127 bool OnKeyUp(Key key, unichar ch)
10129 bool result = controller.OnKeyUp ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyUp)((Window)controller.controlled, controller, key, ch) : true;
10132 bool (* onKeyUp)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp];
10134 result = onKeyUp(controller.window, key, ch);
10139 bool OnKeyHit(Key key, unichar ch)
10141 bool result = controller.OnKeyHit ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyHit)((Window)controller.controlled, controller, key, ch) : true;
10144 bool (* onKeyHit)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit];
10146 result = onKeyHit(controller.window, key, ch);
10151 bool OnMouseMove(int x, int y, Modifiers mods)
10153 bool result = controller.OnMouseMove ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMouseMove)((Window)controller.controlled, controller, x, y, mods) : true;
10156 bool(* onMouseMove)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove];
10158 result = onMouseMove(controller.window, x, y, mods);
10163 bool OnLeftButtonDown(int x, int y, Modifiers mods)
10165 bool result = controller.OnLeftButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10168 bool(* onLeftButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown];
10169 if(onLeftButtonDown)
10170 result = onLeftButtonDown(controller.window, x, y, mods);
10175 bool OnLeftButtonUp(int x, int y, Modifiers mods)
10177 bool result = controller.OnLeftButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10180 bool(* onLeftButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp];
10182 result = onLeftButtonUp(controller.window, x, y, mods);
10187 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
10189 bool result = controller.OnLeftDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10192 bool(* onLeftDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick];
10193 if(onLeftDoubleClick)
10194 result = onLeftDoubleClick(controller.window, x, y, mods);
10199 bool OnRightButtonDown(int x, int y, Modifiers mods)
10201 bool result = controller.OnRightButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10204 bool(* onRightButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown];
10205 if(onRightButtonDown)
10206 result = onRightButtonDown(controller.window, x, y, mods);
10211 bool OnRightButtonUp(int x, int y, Modifiers mods)
10213 bool result = controller.OnRightButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10216 bool(* onRightButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp];
10217 if(onRightButtonUp)
10218 result = onRightButtonUp(controller.window, x, y, mods);
10223 bool OnRightDoubleClick(int x, int y, Modifiers mods)
10225 bool result = controller.OnRightDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10228 bool(* onRightDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick];
10229 if(onRightDoubleClick)
10230 result = onRightDoubleClick(controller.window, x, y, mods);
10235 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
10237 bool result = controller.OnMiddleButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10240 bool(* onMiddleButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown];
10241 if(onMiddleButtonDown)
10242 result = onMiddleButtonDown(controller.window, x, y, mods);
10247 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
10249 bool result = controller.OnMiddleButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10252 bool(* onMiddleButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp];
10253 if(onMiddleButtonUp)
10254 result = onMiddleButtonUp(controller.window, x, y, mods);
10259 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
10261 bool result = controller.OnMiddleDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10264 bool(* onMiddleDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick];
10265 if(onMiddleDoubleClick)
10266 onMiddleDoubleClick(controller.window, x, y, mods);
10271 bool OnMultiTouch(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods)
10273 bool result = controller.OnMultiTouch ? ((bool(*)(Window, WindowController, TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers))(void *)controller.OnMultiTouch)((Window)controller.controlled, controller, event, infos, mods) : true;
10276 bool(* onMultiTouch)(Window, TouchPointerEvent, Array<TouchPointerInfo>, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMultiTouch];
10278 onMultiTouch(controller.window, event, infos, mods);
10283 void OnResize(int width, int height)
10285 if(controller.OnResize)
10286 ((void(*)(Window, WindowController, int, int))(void *)controller.OnResize)((Window)controller.controlled, controller, width, height);
10288 void(* onResize)(Window, int, int) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize];
10290 onResize(controller.window, width, height);
10294 void OnRedraw(Surface surface)
10296 if(controller.OnRedraw)
10297 ((void(*)(Window, WindowController, Surface))(void *)controller.OnRedraw)((Window)controller.controlled, controller, surface);
10299 void(* onRedraw)(Window, Surface) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw];
10301 onRedraw(controller.window, surface);
10307 bool result = controller.OnCreate ? ((bool(*)(Window, WindowController))(void *)controller.OnCreate)((Window)controller.controlled, controller) : true;
10310 bool(* onCreate)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate];
10312 result = onCreate(controller.window);
10317 bool OnLoadGraphics()
10319 bool result = controller.OnLoadGraphics ? ((bool(*)(Window, WindowController))(void *)controller.OnLoadGraphics)((Window)controller.controlled, controller) : true;
10322 bool(* onLoadGraphics)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLoadGraphics];
10324 result = onLoadGraphics(controller.window);
10329 void OnUnloadGraphics()
10331 if(controller.OnUnloadGraphics)
10332 ((void(*)(Window, WindowController))(void *)controller.OnUnloadGraphics)((Window)controller.controlled, controller);
10334 void(* onUnloadGraphics)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnUnloadGraphics];
10335 if(onUnloadGraphics)
10336 onUnloadGraphics(controller.window);
10341 public class WindowController<class V>
10343 void setWindow(Window value)
10345 uint size = class(Window).vTblSize;
10349 windowVTbl = new void *[size];
10350 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
10351 if(value._vTbl == value._class._vTbl)
10353 value._vTbl = new void *[value._class.vTblSize];
10354 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
10358 for(c = 0; c < size; c++)
10360 void * function = class(WindowControllerInterface)._vTbl[c];
10361 if(function && function != DefaultFunction)
10362 value._vTbl[c] = function;
10364 value._vTbl[c] = windowVTbl[c];
10370 memcpy(window._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
10376 property Window window
10378 get { return window; }
10380 property V controlled
10382 set { controlled = value; }
10383 get { return controlled; }
10385 // TODO: Add OnStateChange so we can implement SavedConfigWindow as a WindowController instead
10386 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
10387 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
10388 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
10389 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
10390 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
10391 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
10392 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10393 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
10394 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
10395 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10396 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
10397 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
10398 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10399 virtual bool V::OnMultiTouch(WindowController controller, TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods);
10400 virtual void V::OnResize(WindowController controller, int width, int height);
10401 virtual void V::OnRedraw(WindowController controller, Surface surface);
10402 virtual bool V::OnCreate(WindowController controller);
10403 virtual bool V::OnLoadGraphics(WindowController controller);
10404 virtual void V::OnUnloadGraphics(WindowController controller);
10407 public int (** windowVTbl)();
10411 ~WindowController()