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)
1146 tilingH = (int)sqrt(numTiling);
1147 tilingW = numTiling / tilingH;
1151 tilingW = (int)sqrt(numTiling);
1152 tilingH = numTiling / tilingW;
1155 leftOver = numTiling - tilingH * tilingW;
1158 tilingSplit = (tilingW - leftOver) * tilingH;
1159 tilingLastH = tilingH+1;
1162 tilingSplit = numTiling;
1164 if(positionID >= tilingSplit)
1166 x = xOffset + pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
1167 y = yOffset + ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
1168 x2 = xOffset + pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
1169 y2 = yOffset + ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
1173 x = xOffset + pw * (positionID / tilingH) / tilingW;
1174 y = yOffset + ph * (positionID % tilingH) / tilingH;
1175 x2 = xOffset + pw * (positionID / tilingH + 1) / tilingW;
1176 y2 = yOffset + ph * ((positionID % tilingH) + 1) / tilingH;
1180 SNAPDOWN(x, textCellW);
1181 SNAPDOWN(y, textCellH);
1182 SNAPDOWN(x2, textCellW);
1183 SNAPDOWN(y2, textCellH);
1191 if(sizeAnchor.isClientW) w += ew;
1192 if(sizeAnchor.isClientH) h += eh;
1194 if(anchor.left.type == offset)
1195 x = anchor.left.distance;
1196 else if(anchor.left.type == relative)
1197 x = (anchor.left.percent < 0) ? ((int)(vpw * anchor.left.percent - 0.5)) : (int)(vpw * anchor.left.percent + 0.5);
1198 else if(anchor.right.type == relative)
1199 // ex = (anchor.right.percent < 0) ? ((int)(vpw * anchor.right.percent + 0)) : ((int)(vpw * anchor.right.percent + 0));
1200 ex = (anchor.right.percent < 0) ? ((int)(vpw * (1.0-anchor.right.percent) + 0)) : ((int)(vpw * (1.0-anchor.right.percent) + 0));
1201 else if(anchor.right.type == offset)
1202 ex = vpw - anchor.right.distance;
1204 if(anchor.top.type == offset)
1205 y = anchor.top.distance;
1206 else if(anchor.top.type == relative)
1207 y = (anchor.top.percent < 0) ? ((int)(vph * anchor.top.percent - 0.5)) : ((int)(vph * anchor.top.percent + 0.5));
1208 else if(anchor.bottom.type == relative)
1209 //ey = (anchor.bottom.percent < 0) ? ((int)(vph * anchor.bottom.percent + 0)) : ((int)(vph * anchor.bottom.percent + 0));
1210 ey = (anchor.bottom.percent < 0) ? ((int)(vph * (1.0-anchor.bottom.percent) + 0)) : ((int)(vph * (1.0-anchor.bottom.percent) + 0));
1211 else if(anchor.bottom.type == offset)
1212 ey = vph - anchor.bottom.distance;
1214 if(anchor.left.type && anchor.right.type)
1216 switch(anchor.right.type)
1219 ex = pw * (1.0f-anchor.right.percent);
1220 w = Max((int)(ex + 0.5) - x, 0);
1223 ex = vpw - anchor.right.distance;
1224 w = Max((int)(ex + 0.5) - x, 0);
1228 if(anchor.top.type && anchor.bottom.type)
1230 switch(anchor.bottom.type)
1233 ey = ph * (1.0f-anchor.bottom.percent);
1234 h = Max((int)(ey + 0.5) - y, 0);
1237 ey = vph - anchor.bottom.distance;
1238 h = Max((int)(ey + 0.5) - y, 0);
1247 if(state == normal /*|| state == Hidden*/)
1249 bool addSbV = false, addSbH = false;
1251 if(sizeAnchor.isClientW || (anchor.left.type && anchor.right.type)) w = Max(w, 1); else w = Max(w, 0);
1252 if(sizeAnchor.isClientH || (anchor.top.type && anchor.bottom.type)) h = Max(h, 1); else h = Max(h, 0);
1254 w = Max(w, minSize.w);
1255 h = Max(h, minSize.h);
1256 w = Min(w, maxSize.w);
1257 h = Min(h, maxSize.h);
1259 if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
1261 if(w) w -= guiApp.currentSkin.VerticalSBW();
1264 if((sizeAnchor.isClientH || !h || (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
1266 if(h) h -= guiApp.currentSkin.HorizontalSBH();
1270 if(!OnResizing(&w, &h))
1276 if((addSbV)) // || reqScrollArea.h > h) && sbv)
1277 w += guiApp.currentSkin.VerticalSBW();
1278 if((addSbH)) // || reqScrollArea.w > w) && sbh)
1279 h += guiApp.currentSkin.HorizontalSBH();
1281 w = Max(w, skinMinSize.w);
1282 h = Max(h, skinMinSize.h);
1295 SNAPDOWN(w, textCellW);
1296 SNAPDOWN(h, textCellH);
1299 if(anchor.left.type == cascade && (state == normal /*|| state == Hidden*/))
1301 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1304 (pw - w) / CASCADE_SPACE,
1305 (ph - h) / CASCADE_SPACE);
1311 cascW = (pw - w) / (numCascade-1);
1312 cascH = (ph - h) / (numCascade-1);
1313 SNAPDOWN(cascW, textCellW);
1314 SNAPDOWN(cascH, textCellH);
1315 cascadeW = (float)cascW;
1316 cascadeH = (float)cascH;
1320 numCascade = Max(numCascade, 2);
1321 cascadeW = (float)(pw - w) / (numCascade-1);
1322 cascadeH = (float)(ph - h) / (numCascade-1);
1325 x = (int)((positionID % numCascade) * cascadeW) + xOffset;
1326 y = (int)((positionID % numCascade) * cascadeH) + yOffset;
1328 else if(anchor.left.type < vTiled)
1330 if(!anchor.left.type || anchor.horz.type == middleRelative)
1332 if(!anchor.right.type)
1334 if(anchor.horz.type == middleRelative)
1335 x = (int)(vpw * (0.5 + anchor.horz.percent) - w / 2);
1337 x = vpw / 2 + anchor.horz.distance - w / 2;
1343 // case A_EDGE: x = x - w; break;
1345 if(!anchor.top.type || anchor.vert.type == middleRelative)
1347 if(!anchor.bottom.type)
1349 if(anchor.vert.type == middleRelative)
1350 y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
1352 y = vph / 2 + anchor.vert.distance - h / 2;
1358 // case A_EDGE: y = y - h; break;
1361 if((state == normal /*|| state == Hidden*/) && !OnMoving(&x, &y, w, h))
1369 SNAPDOWN(x, textCellW);
1370 SNAPDOWN(y, textCellH);
1382 if(anchored && style.fixed && style.isActiveClient)
1387 void UpdateCaret(bool forceUpdate, bool erase)
1389 static Window lastWindow = null;
1390 static int caretX, caretY, caretSize;
1392 if(guiApp && guiApp.caretOwner == this)
1394 int x = caretPos.x - scroll.x;
1395 int y = caretPos.y - scroll.y;
1397 if((erase || this.caretSize) &&
1398 x >= clientArea.left && x <= clientArea.right &&
1399 y >= clientArea.top && y <= clientArea.bottom)
1403 guiApp.interfaceDriver.SetCaret(
1404 x + absPosition.x + clientStart.x,
1405 y + absPosition.y + clientStart.y, this.caretSize);
1406 guiApp.caretEnabled = true;
1408 if(erase || lastWindow != this || caretX != x || caretY != y || caretSize != this.caretSize || forceUpdate)
1412 if(lastWindow != this)
1414 updateBox.left = x + 1;
1416 updateBox.right = x + 2;
1417 updateBox.bottom = y + this.caretSize - 1;
1421 updateBox.left = Min(x + 1, caretX + 1);
1422 updateBox.top = Min(y, caretY);
1423 updateBox.right = Max(x + 2, caretX + 2);
1424 updateBox.bottom = Max(y + this.caretSize - 1, caretY + caretSize - 1);
1427 guiApp.caretOwner.Update(updateBox);
1434 caretSize = this.caretSize;
1440 guiApp.interfaceDriver.SetCaret(0,0,0);
1441 guiApp.caretEnabled = false;
1447 void SetPosition(int x, int y, int w, int h, bool modifyArea, bool modifyThisArea, bool modifyClientArea)
1452 scrolledPos.x = position.x = x;
1453 scrolledPos.y = position.y = y;
1455 clientSize.w = size.w = w;
1456 clientSize.h = size.h = h;
1458 if(parent && !style.nonClient)
1460 //if(!style.fixed || style.isDocument)
1462 if(!style.dontScrollHorz) scrolledPos.x -= parent.scroll.x;
1463 if(!style.dontScrollVert) scrolledPos.y -= parent.scroll.y;
1467 clientStart.x = clientStart.y = 0;
1469 SetWindowArea(&clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1471 //if(!activeClient || activeClient.state != maximized)
1472 if(!noAutoScrollArea)
1474 // Check if scroll area must be modified
1475 if(guiApp && !guiApp.modeSwitching && (sbv || sbh))
1477 bool foundChild = false;
1479 int cw = clientSize.w;// + ((!sbv || sbv.range > 1) ? guiApp.currentSkin.VerticalSBW() : 0);
1480 int ch = clientSize.h;// + ((!sbh || sbh.rangw > 1) ? guiApp.currentSkin.HorizontalSBH() : 0);
1481 for(child = children.first; child; child = child.next)
1483 if(child.modifyVirtArea && !child.style.hidden && child.created && /*!child.anchored &&*/
1484 !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1486 if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == offset)
1487 w = Max(w, child.position.x + child.size.w);
1488 else if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == none)
1489 w = Max(w, Max(child.position.x, 0) + child.size.w);
1490 if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == offset)
1491 h = Max(h, child.position.y + child.size.h);
1492 else if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == none)
1493 h = Max(h, Max(child.position.y, 0) + child.size.h);
1498 if(foundChild && (w > cw || h > ch))
1500 //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
1502 int stepX = sbStep.x, stepY = sbStep.y;
1503 // Needed to make snapped down position match the skin's check of client area
1504 // against realvirtual
1507 SNAPDOWN(stepX, textCellW);
1508 SNAPDOWN(stepY, textCellH);
1509 stepX = Max(stepX, textCellW);
1510 stepY = Max(stepY, textCellH);
1512 if(scrollFlags.snapX)
1514 if(scrollFlags.snapY)
1517 reqScrollArea.w = w;
1518 reqScrollArea.h = h;
1521 else if(reqScrollArea.w || reqScrollArea.h)
1523 reqScrollArea.w = 0;
1524 reqScrollArea.h = 0;
1525 SetScrollPosition(0,0);
1530 // Automatic MDI Client Scrolling Area Adjustment
1531 if(parent && !parent.noAutoScrollArea)
1533 if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
1534 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
1536 Window parent = this.parent;
1537 int w = parent.reqScrollArea.w;
1538 int h = parent.reqScrollArea.h;
1540 if(stateAnchor.right.type == none && stateAnchor.left.type == offset)
1541 w = Max(w, position.x + size.w);
1542 else if(stateAnchor.right.type == none && stateAnchor.left.type == none)
1543 w = Max(w, Max(position.x, 0) + size.w);
1544 if(stateAnchor.bottom.type == none && stateAnchor.top.type == offset)
1545 h = Max(h, position.y + size.h);
1546 else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
1547 h = Max(h, Max(position.y, 0) + size.h);
1549 if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
1550 (h > parent.clientSize.h && h > parent.reqScrollArea.h))
1552 /*bool resize = false;
1553 int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
1554 // Needed to make snapped down position match the skin's check of client area
1555 // against realvirtual
1558 SNAPDOWN(stepX, textCellW);
1559 SNAPDOWN(stepY, textCellH);
1560 stepX = Max(stepX, textCellW);
1561 stepY = Max(stepY, textCellH);
1563 if(parent.scrollFlags.snapX)
1565 if(parent.scrollFlags.snapY)
1567 if(parent.reqScrollArea.w != w || parent.reqScrollArea.h != h)
1569 parent.reqScrollArea.w = w;
1570 parent.reqScrollArea.h = h;*/
1572 // parent.UpdateScrollBars(true, true);
1573 parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1574 false, true, true, true, false, false);
1579 GetRidOfVirtualArea();
1583 UpdateScrollBars(modifyThisArea, false);
1584 else if(guiApp.currentSkin)
1587 &clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1589 if(sbv && (scrollFlags.dontHide || sbv.range > 1))
1590 clientSize.w -= guiApp.currentSkin.VerticalSBW();
1591 if(sbh && (scrollFlags.dontHide || sbh.range > 1))
1592 clientSize.h -= guiApp.currentSkin.HorizontalSBH();
1595 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1596 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1598 absPosition = scrolledPos;
1599 if(guiApp && guiApp.driver != null && guiApp.interfaceDriver)
1600 guiApp.interfaceDriver.OffsetWindow(this, &absPosition.x, &absPosition.y);
1602 if(this != guiApp.desktop && parent)
1604 absPosition.x += parent.absPosition.x;
1605 absPosition.y += parent.absPosition.y;
1606 if(!style.nonClient && this != guiApp.desktop)
1608 absPosition.x += parent.clientStart.x;
1609 absPosition.y += parent.clientStart.y;
1613 box = Box { 0, 0, size.w - 1, size.h - 1 };
1618 // Clip against parent's client area
1619 box.ClipOffset(against, scrolledPos.x, scrolledPos.y);
1621 // Compute client area in this window coordinate system
1622 clientArea.left = 0;
1624 clientArea.right = clientSize.w - 1;
1625 clientArea.bottom = clientSize.h - 1;
1627 // Clip against parent's client area
1629 clientArea.ClipOffset(against, scrolledPos.x + clientStart.x, scrolledPos.y + clientStart.y);
1633 //absPosition.x -= parent.clientStart.x;
1634 //absPosition.y -= parent.clientStart.y;
1637 // Adjust all children
1638 for(child = children.first; child; child = child.next)
1639 child.SetPosition(child.position.x, child.position.y, child.size.w, child.size.h, false, true, true);
1641 UpdateCaret(false, false);
1644 void GetRidOfVirtualArea(void)
1646 if(parent && !parent.destroyed && style.fixed &&
1647 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient &&
1648 parent.reqScrollArea.w && parent.reqScrollArea.h)
1650 if(!parent.noAutoScrollArea)
1652 // TODO: Review the logic of all this? Each child is going to reposition the parent?
1656 for(child = children.first; child; child = child.next)
1658 if(child.modifyVirtArea && !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1660 if(child.position.x + child.size.w > parent.clientSize.w + ((!parent.sbv || parent.sbv.style.hidden) ? 0 : guiApp.currentSkin.VerticalSBW()) ||
1661 child.position.y + child.size.h > parent.clientSize.h + ((!parent.sbh || parent.sbh.style.hidden) ? 0 : guiApp.currentSkin.HorizontalSBH()))
1671 Window parent = this.parent;
1673 parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1674 false, true, true, true, false, false);
1676 parent.SetScrollArea(0,0,true);
1677 parent.SetScrollPosition(0,0);
1683 public void ExternalPosition(int x, int y, int w, int h)
1685 Position(x, y, w, h, false, true, true, true, false, false);
1686 /* TO REVIEW: Redj's code trying to fix position saving
1691 normalAnchor = Anchor { left = x, top = y };
1692 normalSizeAnchor = SizeAnchor { { w, h } };
1699 // (w, h): Full window size
1700 bool Position(int x, int y, int w, int h, bool force, bool processAnchors, bool modifyArea, bool updateScrollBars, bool thisOnly, bool changeRootWindow)
1702 bool result = false;
1703 int oldCW = clientSize.w, oldCH = clientSize.h;
1704 bool clientResized, windowResized, windowMoved;
1706 //bool realResized = size.w != w || size.h != h;
1708 // TOCHECK: This wasn't in ecere.dll
1709 //if(!parent) return true;
1710 if(destroyed) return false;
1712 windowMoved = position.x != x || position.y != y || force;
1714 // windowResized = realResized || force;
1715 windowResized = size.w != w || size.h != h || force;
1717 if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
1723 scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
1724 scrolledPos.x - parent.clientStart.x + this.box.right,
1725 scrolledPos.y - parent.clientStart.y + this.box.bottom
1731 Box box { scrolledPos.x + this.box.left, scrolledPos.y + this.box.top, scrolledPos.x + this.box.right, scrolledPos.y + this.box.bottom};
1736 SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
1738 clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
1739 if(clientResized && this == rootWindow && nativeDecorations && rootWindow.windowHandle)
1740 windowResized = true;
1742 if(display && rootWindow != this)
1745 if(guiApp && guiApp.windowMoving)
1747 if(guiApp.windowMoving.style.nonClient)
1748 guiApp.windowMoving.parent.SetMouseRangeToWindow();
1750 guiApp.windowMoving.parent.SetMouseRangeToClient();
1760 // Buttons bitmap resources crash if we do this while switching mode
1761 if(!guiApp || !guiApp.modeSwitching)
1764 // Process Anchored Children
1768 for(child = children.first; child; child = child.next)
1771 ((child.stateAnchor.left.type != offset ||
1772 child.stateAnchor.top.type != offset ||
1773 child.stateAnchor.right.type != none ||
1774 child.stateAnchor.bottom.type != none) ||
1775 child.state == maximized || child.state == minimized))
1777 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1779 // child.Position(x, y, w, h, false, true, true, true, false);
1780 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1781 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1787 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1788 //if(updateScrollBars)
1790 OnResize(clientSize.w, clientSize.h);
1792 if((clientResized || windowMoved) && created)
1793 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1795 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1797 Window master = guiApp.interimWindow.master;
1798 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1801 if(rootWindow == this && !is3D)
1805 x -= guiApp.desktop.absPosition.x;
1806 y -= guiApp.desktop.absPosition.y;
1808 //guiApp.Log("Position %s\n", caption);
1811 if(windowResized || windowMoved)
1812 if(display && !display.flags.memBackBuffer && changeRootWindow)
1813 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1816 #if !defined(__EMSCRIPTEN__)
1817 !guiApp.fullScreenMode &&
1819 this != guiApp.desktop && (windowResized || windowMoved))
1820 for(child = parent.children.first; child && child != this; child = child.next)
1821 if(child.rootWindow)
1822 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1827 if(windowMoved || windowResized)
1829 display.Lock(true /*false*/);
1832 display.Position(absPosition.x, absPosition.y);
1833 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1836 // result = realResized ? display.Resize(size.w, size.h) : true;
1837 if(nativeDecorations && rootWindow.windowHandle)
1839 int w = clientSize.w, h = clientSize.h;
1840 if(hasMenuBar) h += skinMenuHeight;
1841 if(hasStatusBar) h += statusBarHeight;
1842 if(sbv && sbv.visible) w += sbv.size.w;
1843 if(sbh && sbh.visible) h += sbh.size.h;
1844 result = manageDisplay ? display.Resize(w, h) : true;
1847 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1851 else if(clientResized)
1853 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1856 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1860 if(windowMoved || windowResized)
1865 if(guiApp.driver && changeRootWindow && windowHandle)
1867 if(windowResized || windowMoved)
1868 if(!display || display.flags.memBackBuffer)
1869 guiApp.interfaceDriver.PositionRootWindow(this,
1870 x, y, w, h, windowMoved, windowResized);
1871 guiApp.interfaceDriver.UpdateRootWindow(this);
1873 for(child = children.first; child; child = child.next)
1875 if(child.is3D && child.created)
1877 // Copy Display Content
1878 child.display.displaySystem = display.displaySystem;
1879 child.display.window = display.window;
1880 child.display.current = display.current;
1881 child.display.width = display.width;
1882 child.display.height = display.height;
1883 child.display.driverData = display.driverData;
1884 #if !defined(__EMSCRIPTEN__)
1885 child.display.mutex = null;
1897 void UpdateScrollBars(bool flag, bool fullThing)
1900 bool resizeH = false, resizeV = false;
1901 bool scrolled = false;
1902 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1903 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1905 if(destroyed) return;
1906 if(guiApp.currentSkin)
1908 MinMaxValue cw = 0, ch = 0;
1909 bool sbvVisible, sbhVisible;
1910 int rangeH = 0, rangeV = 0;
1911 int positionH = 0, positionV;
1913 // First get client area with no respect to scroll bars
1918 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1920 if(scrollFlags.dontHide)
1923 cw -= guiApp.currentSkin.VerticalSBW();
1925 ch -= guiApp.currentSkin.HorizontalSBH();
1927 // Update the scrollbar visibility
1933 sbh.disabled = rangeH <= 1;
1934 if(sbh.style.hidden)
1944 sbv.disabled = rangeV <= 1;
1945 if(sbv.style.hidden)
1953 int oldHRange = sbh ? sbh.range : 0;
1954 int oldVRange = sbv ? sbv.range : 0;
1955 // Then start off with horizontal scrollbar range
1958 positionH = sbh.thumbPosition;
1965 SBSetTotal(sbh, rvw);
1968 ch -= guiApp.currentSkin.HorizontalSBH();
1971 // Do the same for vertical scrollbar
1974 positionV = sbv.thumbPosition;
1980 SBSetTotal(sbv, rvh);
1984 cw -= guiApp.currentSkin.VerticalSBW();
1985 // Maybe we need to set the range on the horizontal scrollbar again
1993 SBSetTotal(sbh, rvw);
1994 //sbh.Action(setRange, positionH, 0);
1995 if(rangeH <= 1 && sbh.range > 1)
1997 ch -= guiApp.currentSkin.HorizontalSBH();
2003 SBSetTotal(sbv, rvh);
2005 //sbv.Action(setRange, positionV, 0);
2010 if(sbh && sbh.range != oldHRange) sbh.Action(setRange, positionH, 0);
2011 if(sbv && sbv.range != oldVRange) sbv.Action(setRange, positionV, 0);
2014 // Update the scrollbar visibility
2015 if(!scrollFlags.dontHide)
2017 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
2021 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
2028 if(guiApp.currentSkin)
2035 sbhVisible = sbh.style.hidden ? true : false;
2037 sbvVisible = sbv.style.hidden ? true : false;
2039 // Do our resize here
2040 if(flag && (resizeH || resizeV) && fullThing)
2042 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
2047 OnResize(clientSize.w, clientSize.h);
2053 sbh.visible = sbhVisible;
2055 sbv.visible = sbvVisible;
2057 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
2058 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
2061 sbh.pageStep = clientSize.w;
2063 sbv.pageStep = clientSize.h;
2065 // Notify doesn't handle setRange anymore... process it here
2068 int positionH = sbh.thumbPosition;
2069 if(scroll.x != positionH)
2071 OnHScroll(setRange, positionH, 0);
2075 SNAPDOWN(positionH, textCellW);
2076 scroll.x = positionH;
2082 int seen = clientSize.w, total = reqScrollArea.w;
2085 if(scrollFlags.snapX)
2086 SNAPDOWN(seen, sbStep.x);
2088 if(!total) total = seen;
2089 range = total - seen + 1;
2091 range = Max(range, 1);
2093 if(x >= range) x = range - 1;
2095 if(scrollFlags.snapX)
2096 SNAPUP(x, sbStep.x);
2100 OnHScroll(setRange, x, 0);
2105 SNAPDOWN(x, textCellW);
2111 int positionV = sbv.thumbPosition;
2112 if(scroll.y != positionV)
2114 OnVScroll(setRange, positionV, 0);
2118 SNAPDOWN(positionV, textCellH);
2119 scroll.y = positionV;
2125 int seen = clientSize.h, total = reqScrollArea.h;
2128 if(scrollFlags.snapY)
2129 SNAPDOWN(seen, sbStep.y);
2131 if(!total) total = seen;
2132 range = total - seen + 1;
2133 range = Max(range, 1);
2135 if(y >= range) y = range - 1;
2137 if(scrollFlags.snapY)
2138 SNAPUP(y, sbStep.y);
2142 OnVScroll(setRange, y, 0);
2147 SNAPDOWN(y, textCellH);
2153 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2156 for(child = children.first; child; child = child.next)
2158 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2161 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2162 child.Position(x, y, w, h, false, true, false, true, false, false);
2169 // Process Scrollbars
2171 if(sbh) // && !sbh.style.hidden
2174 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2175 // Need to set the range again (should improve...) since the scrollbars didn't have
2176 // the right size when UpdateScrollArea set the range on it
2179 sbh.seen = clientSize.w;
2183 if(sbv) // && !sbv.state.hidden
2186 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2187 // Need to set the range again (should improve...) since the scrollbars didn't have
2188 // the right size when UpdateScrollArea set the range on it
2191 sbv.seen = clientSize.h;
2196 // TESTING THIS LOWER
2197 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2200 for(child = children.first; child; child = child.next)
2202 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2205 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2206 child.Position(x, y, w, h, false, true, false, true, false, false);
2212 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2214 SetState(maximized, false, mods);
2218 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2220 SetState(normal, false, mods);
2224 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2226 SetState(minimized, false, mods);
2227 parent.CycleChildren(false, true, false, true);
2231 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2234 // Scroll bar notifications
2235 if(action != setRange)
2237 bool changed = false;
2241 if(scroll.x != position)
2243 OnHScroll(action, position, keyFlags);
2248 SNAPDOWN(position, textCellW);
2250 scroll.x = position;
2254 if(scroll.y != position)
2256 OnVScroll(action, position, keyFlags);
2261 SNAPDOWN(position, textCellH);
2263 scroll.y = position;
2267 bool childMove = false;
2268 for(child = children.first; child; child = child.next)
2270 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2273 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2274 child.Position(x, y, w, h, false, true, false, true, false, false);
2278 // Testing this patch out to solve MDI workspace redraw bugs
2279 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2280 // Scroll offsets to blame?
2284 UpdateCaret(false, false);
2288 // Testing this patch out to solve MDI workspace redraw bugs
2289 for(child = children.first; child; child = child.next)
2291 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2300 Window GetParentMenuBar()
2302 Window menuBarParent;
2303 if(formDesigner) return null;
2304 for(menuBarParent = this ? parent : null; menuBarParent; menuBarParent = menuBarParent.parent)
2306 if(menuBarParent.menuBar) return menuBarParent.menuBar;
2307 if(menuBarParent && !menuBarParent.isActiveClient)
2313 void CreateSystemChildren(void)
2315 Window parent = this;
2316 bool scrollBarChanged = false;
2317 bool hasClose = false, hasMaxMin = false;
2318 Point scroll = this.scroll;
2320 if(state == maximized)
2322 parent = GetParentMenuBar();
2329 if(style.hasClose) hasClose = true;
2330 if(style.hasMaximize || style.hasMinimize)
2337 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2339 sysButtons[2].Destroy(0);
2340 sysButtons[2] = null;
2342 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2344 sysButtons[1].Destroy(0);
2345 sysButtons[1] = null;
2347 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2349 sysButtons[0].Destroy(0);
2350 sysButtons[0] = null;
2353 if(hasClose && parent)
2360 parent, master = this,
2361 inactive = true, nonClient = true, visible = false;
2363 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2369 if(this.parent == guiApp.desktop)
2370 sysButtons[2].hotKey = altF4;
2371 else if(style.isActiveClient)
2372 sysButtons[2].hotKey = ctrlF4;
2373 sysButtons[2].Create();
2376 sysButtons[2].symbol = 'X';
2377 sysButtons[2].disabled = !style.hasClose;
2380 if(hasMaxMin && parent)
2384 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2385 if(state == maximized)
2388 method = RestoreButtonClicked;
2394 method = MaximizeButtonClicked;
2402 parent, master = this,
2403 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2405 sysButtons[1].Create();
2407 sysButtons[1].NotifyClicked = method;
2409 sysButtons[1].symbol = symbol;
2410 sysButtons[1].disabled = !style.hasMaximize;
2413 if(hasMaxMin && parent)
2417 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2418 if (state == minimized)
2421 method = RestoreButtonClicked;
2427 method = MinimizeButtonClicked;
2435 parent, master = this,
2436 hotKey = altM, inactive = true, nonClient = true, visible = false
2438 sysButtons[0].Create();
2440 sysButtons[0].NotifyClicked = method;
2442 sysButtons[0].symbol = symbol;
2443 sysButtons[0].disabled = !style.hasMinimize;
2446 // Create the scrollbars
2447 if(style.hasHorzScroll && !sbh)
2453 direction = horizontal,
2457 snap = scrollFlags.snapX,
2458 NotifyScrolling = ScrollBarNotification
2461 scrollBarChanged = true;
2463 else if(sbh && !style.hasHorzScroll)
2469 if(style.hasVertScroll && !sbv)
2475 direction = vertical,
2479 snap = scrollFlags.snapY,
2480 NotifyScrolling = ScrollBarNotification
2483 scrollBarChanged = true;
2485 else if(sbv && !style.hasVertScroll)
2490 if(scrollBarChanged)
2492 SetScrollLineStep(sbStep.x, sbStep.y);
2493 UpdateScrollBars(true, true);
2497 if(scrollBarChanged)
2499 if(sbh) sbh.thumbPosition = scroll.x;
2500 if(sbv) sbv.thumbPosition = scroll.y;
2504 void UpdateCaption(void)
2506 if(rootWindow == this)
2509 FigureCaption(caption);
2510 if(guiApp.interfaceDriver)
2511 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2513 UpdateDecorations();
2516 if(parent.activeClient == this) // Added this last check
2518 if(parent.rootWindow == parent)
2521 parent.FigureCaption(caption);
2522 if(guiApp.interfaceDriver)
2523 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2526 parent.UpdateCaption();
2528 parent.UpdateDecorations();
2532 void UpdateActiveDocument(Window previous)
2534 Window activeClient = this.activeClient;
2535 Window activeChild = this.activeChild;
2542 activeClient.CreateSystemChildren();
2544 previous.CreateSystemChildren();
2556 // Build window list
2559 Menu windowMenu = menu.FindMenu("Window");
2564 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2566 Window document = cycle.data;
2567 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2569 char name[2048], caption[2048];
2570 document.FigureCaption(caption);
2571 sprintf(name, "%d %s", id+1, caption);
2572 windowMenu.AddDynamic(MenuItem
2574 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2575 NotifySelect = MenuWindowSelectWindow
2579 if(activeClient.cycle == cycle) break;
2584 if((!previous && activeClient) || !activeClient)
2590 item = menu.FindItem(MenuWindowCloseAll, 0);
2591 if(item) item.disabled = false;
2592 item = menu.FindItem(MenuWindowNext, 0);
2593 if(item) item.disabled = false;
2594 item = menu.FindItem(MenuWindowPrevious, 0);
2595 if(item) item.disabled = false;
2596 item = menu.FindItem(MenuWindowCascade, 0);
2597 if(item) item.disabled = false;
2598 item = menu.FindItem(MenuWindowTileHorz, 0);
2599 if(item) item.disabled = false;
2600 item = menu.FindItem(MenuWindowTileVert, 0);
2601 if(item) item.disabled = false;
2602 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2603 if(item) item.disabled = false;
2604 item = menu.FindItem(MenuWindowWindows, 0);
2605 if(item) item.disabled = false;
2608 item = menu.FindItem(MenuFileClose, 0);
2609 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2610 item = menu.FindItem(MenuFileSaveAll, 0);
2611 if(item) item.disabled = numDocuments < 1;
2613 if(activeClient && activeClient.menu && activeClient.state != minimized)
2617 //activeClient.menu.Clean(activeClient);
2618 menu.Merge(activeClient.menu, true, activeClient);
2622 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2625 menu.Merge(activeChild.menu, true, activeChild);
2628 // This is called again for a child window change, with same active client
2629 OnActivateClient(activeClient, previous);
2630 if(!menuBar && !((BorderBits)borderStyle).fixed && parent && parent.activeClient == this)
2631 parent.UpdateActiveDocument(null);
2634 void _ShowDecorations(Box box, bool post)
2636 if(rootWindow == this && nativeDecorations && !is3D) return;
2637 if(visible && this != guiApp.desktop)
2639 Surface surface = RedrawFull(box);
2643 FigureCaption(caption);
2646 ShowDecorations(captionFont.font,
2649 active, //parent.activeClient == this
2650 guiApp.windowMoving == this);
2652 PreShowDecorations(captionFont.font,
2655 active, //parent.activeClient == this
2656 guiApp.windowMoving == this);
2663 void UpdateExtent(Box refresh)
2665 Surface surface = null;
2667 if(!manageDisplay) { OnRedraw(null);return; }
2668 _ShowDecorations(refresh, false);
2670 surface = Redraw(refresh);
2671 // Opaque background: just fill before EW_REDRAW (clear?)
2674 surface.SetBackground(background);
2675 surface.SetForeground(foreground);
2676 surface.DrawingChar(' ');
2677 if(this == rootWindow)
2679 if(style.drawBehind || background.a)
2681 int a = background.a;
2682 // Premultiply alpha for clear color
2683 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2684 surface.Clear(colorBuffer);
2685 surface.SetBackground(background);
2688 else if(background.a)
2692 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2693 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2696 if(display.flags.alpha && background.a < 255 && background)
2698 surface.Area(0,0,clientSize.w, clientSize.h);
2699 /*if(style.clearDepthBuffer)
2700 surface.Clear(depthBuffer);*/
2702 else if(/*style.clearDepthBuffer || */background.a)
2704 int a = background.a;
2705 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2706 // Premultiply alpha for clear color
2707 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2708 surface.Clear(colorBuffer);
2709 surface.SetBackground(background);
2714 surface.TextFont(usedFont.font);
2715 surface.TextOpacity(false);
2719 // Draw the caret ...
2720 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2722 // surface.SetBackground(0xFFFFFF - background.color);
2723 surface.SetBackground(~background.color);
2725 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2726 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2732 void DrawOverChildren(Box refresh)
2734 Surface surface = Redraw(refresh);
2738 surface.DrawingChar(' ');
2739 surface.SetBackground(background);
2740 surface.SetForeground(foreground);
2742 surface.TextFont(usedFont.font);
2743 surface.TextOpacity(false);
2745 OnDrawOverChildren(surface);
2750 _ShowDecorations(refresh, true);
2753 void ComputeClipExtents(void)
2756 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2758 clipExtent.Copy(this.clipExtent);
2760 for(child = children.last; child; child = child.prev)
2762 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2764 bool opaque = child.IsOpaque(); // TODO: acess background directly
2765 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2767 child.clipExtent.Copy(clipExtent);
2768 child.clipExtent.Offset(-dx, -dy);
2769 child.clipExtent.IntersectBox(child.box);
2771 child.ComputeClipExtents();
2773 if(opaque && !child.style.nonClient)
2775 // Adjust the box for the parent:
2776 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2777 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2782 // ??? Only do this for overlapped window or if parent has with clip children flag
2784 // Do this if window has clip children flag on (default false?)
2785 // this.clipExtent = clipExtent;
2787 clipExtent.Free(null);
2790 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2793 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2794 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2796 offsetX -= rootWindow.clientStart.x;
2797 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2801 for(child = children.last; child; child = child.prev)
2803 bool opaque = child.IsOpaque();
2804 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2808 // Adjust renderArea to the root window level
2809 Extent * renderArea = &rootWindow.tempExtents[3];
2811 int offsetX = child.absPosition.x - rootWindow.absPosition.x;
2812 int offsetY = child.absPosition.y - rootWindow.absPosition.y;
2813 if(child.rootWindow.nativeDecorations && rootWindow.windowHandle)
2815 offsetX -= child.rootWindow.clientStart.x;
2816 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2820 Extent childRenderArea;
2822 if(backBufferUpdate != null)
2824 childRenderArea.Copy(backBufferUpdate);
2825 childRenderArea.Offset(-offsetX, -offsetY);
2828 childRenderArea.Copy(child.dirtyArea);
2830 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2831 renderArea.Copy(dirtyExtent);
2832 renderArea.Offset(-offsetX, -offsetY);
2833 childRenderArea.Union(renderArea);
2836 // Intersect with the clip extent
2837 childRenderArea.Intersection(child.clipExtent);
2840 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2842 // This intersection with child clip extent was missing and causing #708 (Installer components list scrolling bug):
2843 renderArea->Intersection(child.clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2845 renderArea->Offset(offsetX, offsetY);
2847 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2848 // overDirtyExtent.Union(renderArea);
2849 renderArea->Empty();
2850 // childRenderArea.Free();
2852 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2857 for(child = children.last; child; child = child.prev)
2859 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2861 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2866 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2868 bool opaque = IsOpaque();
2869 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2871 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2872 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2874 offsetX -= rootWindow.clientStart.x;
2875 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2879 for(child = children.last; child; child = child.prev)
2881 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2883 ColorAlpha background = *(ColorAlpha *)&child.background;
2884 bool opaque = child.IsOpaque();
2885 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2889 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2890 // Adjust renderArea to the root window level
2892 renderArea.Copy(child.dirtyArea);
2893 renderArea.Offset(offsetX, offsetY);
2894 dirtyExtent.Union(renderArea);
2895 overDirtyExtent.Union(renderArea);
2901 for(child = children.last; child; child = child.prev)
2903 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2905 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2909 if(backBufferUpdate != null)
2911 renderArea.Copy(backBufferUpdate);
2912 renderArea.Offset(-offsetX, -offsetY);
2914 overRenderArea.Copy(backBufferUpdate);
2915 overRenderArea.Offset(-offsetX, -offsetY);
2921 renderArea.Copy(dirtyArea);
2923 overRenderArea.Copy(dirtyArea);
2926 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2927 dirtyExtentWindow->Copy(dirtyExtent);
2928 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2929 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2930 dirtyExtentWindow->Empty();
2932 // Intersect with the clip extent
2933 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2936 if(renderArea.count > 10)
2939 printf("\nToo many extents (%d):\n", renderArea.count);
2941 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2942 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2947 for(c = 0; c<10; c++)
2950 FASTLIST_LOOP(renderArea, extentBox)
2952 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2954 renderArea.Copy(extent);
2956 FASTLIST_LOOP(renderArea, extentBox)
2959 printf("(%d, %d) - (%d, %d)\n",
2960 extentBox.box.left, extentBox.box.top,
2961 extentBox.box.right, extentBox.box.bottom);
2965 printf("\nNow %d\n", renderArea.count);
2971 // WHY WAS THIS COMMENTED ??
2973 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2974 dirtyExtentWindow->Copy(overDirtyExtent);
2975 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2976 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2977 dirtyExtentWindow->Empty();
2979 // Intersect with the clip extent
2980 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2986 if(scrollExtent.count)
2988 // Subtract render extent from scrolling extent
2989 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
2991 if(backBufferUpdate == null)
2993 Extent * dirty = &rootWindow.tempExtents[3];
2996 // Intersect scrolling extent with clip extent
2997 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2999 // offset this scroll to be at the root window level
3000 scrollExtent.Offset(offsetX, offsetY);
3001 // Add area that was scrolled to the dirty extents of the back buffer
3002 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
3006 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
3007 for(scrollBox = (BoxItem)scrollExtent.first; scrollBox; scrollBox = (BoxItem)scrollBox.next)
3008 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
3013 scrollExtent.Empty();
3015 // Add the exposed extent to the window render area
3016 dirty->Offset(-offsetX, -offsetY);
3017 renderArea.Union(dirty, rootWindow.tempExtents[0]);
3022 // Subtract the window's box from the transparency forced extent
3023 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
3029 renderArea.Copy(this.renderArea);
3030 renderArea.Offset(offsetX, offsetY);
3031 dirtyExtent.Union(renderArea);
3037 Extent renderArea { };
3039 renderArea.Copy(overRenderArea);
3040 renderArea.Offset(offsetX, offsetY);
3041 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
3046 if(backBufferUpdate != null)
3048 // Remove render area from dirty area
3049 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
3051 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
3058 // Remove the window render area from the dirty extents of the back buffer
3059 rootWindow.dirtyBack.Exclusion(renderArea);
3063 void Render(Extent updateExtent)
3067 Window rootWindow = this.rootWindow;
3068 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
3069 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
3071 offsetX -= rootWindow.clientStart.x;
3072 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
3075 if(rootWindow.fullRender)
3084 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
3085 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
3090 /*if(renderArea.count)
3091 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
3094 for(extentBox = (BoxItem)renderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
3096 Box box = extentBox.box;
3099 /*printf("(%d, %d) - (%d, %d)\n",
3100 extentBox.box.left, extentBox.box.top,
3101 extentBox.box.right, extentBox.box.bottom);*/
3106 box.left += offsetX;
3108 box.right += offsetX;
3109 box.bottom += offsetY;
3111 if(updateExtent != null)
3112 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
3116 for(child = children.first; child; child = child.next)
3117 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
3118 child.Render(updateExtent);
3120 if(rootWindow.fullRender)
3121 DrawOverChildren(box);
3124 // TO DO: There's an issue about draw over children...
3125 // TO DO: Don't wanna go through this if method isn't used
3126 for(extentBox = (BoxItem)overRenderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
3127 //FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
3129 Box box = extentBox.box;
3131 DrawOverChildren(box);
3133 box.left += offsetX;
3135 box.right += offsetX;
3136 box.bottom += offsetY;
3138 if(updateExtent != null)
3139 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
3142 for(child = children.first; child; child = child.next)
3143 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
3144 child.Render(updateExtent);
3147 overRenderArea.Empty();
3150 public void UpdateDisplay(void)
3152 if(!manageDisplay) { OnRedraw(null);return; }
3153 if(rootWindow && this != rootWindow)
3154 rootWindow.UpdateDisplay();
3157 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
3158 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
3161 dirtyExtent.Clear();
3164 clipExtent.AddBox(box);
3166 display.StartUpdate();
3168 if(!rootWindow.fullRender)
3170 ComputeClipExtents();
3171 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
3172 ComputeRenderArea(dirtyExtent, overExtent, null);
3175 clipExtent.Free(null);
3177 dirtyExtent.Free(null);
3178 overExtent.Free(null);
3180 if(display.flags.flipping)
3183 display.Update(null);
3187 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
3188 updateExtent.Clear();
3190 Render(updateExtent);
3192 updateExtent.UnionBox(this.box, tempExtents[0]);
3195 //printf("\n\nUpdate:\n------------------------------------------\n");
3198 //FASTLIST_LOOP(updateExtent, extentBox)
3199 for(extentBox = (BoxItem)updateExtent.first; extentBox; extentBox = (BoxItem)extentBox.next)
3202 /*printf("Updating (%d, %d) - (%d, %d)\n",
3203 extentBox.box.left, extentBox.box.top,
3204 extentBox.box.right, extentBox.box.bottom);*/
3207 display.Update(extentBox.box);
3210 updateExtent.Free(null);
3213 display.EndUpdate();
3221 void UpdateBackDisplay(Box box)
3227 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3229 //printf("UpdateBackDisplay going through!\n");
3230 display.StartUpdate();
3234 intersection.Copy(dirtyBack);
3235 intersection.IntersectBox(box);
3237 dirtyExtent.Clear();
3240 clipExtent.AddBox(box);
3242 if(!rootWindow.fullRender)
3244 ComputeClipExtents();
3245 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3248 clipExtent.Free(null);
3250 intersection.Free(null);
3251 dirtyExtent.Free(null);
3252 overExtent.Free(null);
3257 if(display.flags.flipping)
3258 display.Update(null);
3261 rootWindow.display.Update(box);
3264 display.EndUpdate();
3268 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3269 if(dirtyBack.count > MAX_DIRTY_BACK)
3271 BoxItem extentBox, next;
3272 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3273 for(extentBox = (BoxItem)dirtyBack.first; extentBox; extentBox = next)
3275 next = (BoxItem)extentBox.next;
3276 if(extentBox != first)
3278 if(extentBox.box.left < first.box.left)
3279 first.box.left = extentBox.box.left;
3280 if(extentBox.box.top < first.box.top)
3281 first.box.top = extentBox.box.top;
3282 if(extentBox.box.right > first.box.right)
3283 first.box.right = extentBox.box.right;
3284 if(extentBox.box.bottom > first.box.bottom)
3285 first.box.bottom = extentBox.box.bottom;
3286 dirtyBack.Delete(extentBox);
3295 // --- Window positioning ---
3296 // --- Window identification ---
3298 // Returns window at position "Position"
3299 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3301 Window child, result = null;
3303 box.left += absPosition.x;
3304 box.right += absPosition.x;
3305 box.top += absPosition.y;
3306 box.bottom += absPosition.y;
3308 if(!destroyed && visible && (acceptDisabled || !disabled))
3310 int lx = x - absPosition.x;
3311 int ly = y - absPosition.y;
3312 if(IsInside(lx, ly))
3313 // if(box.IsPointInside(Point{x, y}))
3315 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3316 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3319 bool isD = (last && last != this && last.IsDescendantOf(this)); // Fix for WSMS (#844)
3320 Window ancestor = null;
3322 for(ancestor = last; ancestor && ancestor.parent != this; ancestor = ancestor.parent);
3323 for(child = (isD ? (last != ancestor ? ancestor : ancestor.previous) : children.last); child; child = child.prev)
3325 if(child != statusBar && child.rootWindow == rootWindow)
3327 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3334 for(child = (isD ? (last != ancestor ? ancestor : ancestor.previous) : children.last); child; child = child.prev)
3336 if(child != statusBar && child.rootWindow == rootWindow)
3338 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3345 if(last && last != this && this.IsDescendantOf(last)) // Fix for installer lockup
3353 Window FindModal(void)
3355 Window modalWindow = this, check;
3356 Window check2 = null;
3357 for(check = this; check.master; check = check.master)
3359 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3361 modalWindow = check.master.modalSlave;
3362 check = modalWindow;
3364 // TESTING THIS FOR DROPBOX...
3365 if(!rootWindow || !rootWindow.style.interim)
3367 for(check2 = check; check2 /*.activeChild*/; check2 = check2.activeChild)
3369 if(check2.modalSlave && check2.modalSlave.created)
3371 modalWindow = check2.modalSlave;
3379 if(modalWindow == this)
3381 for(check = this; check.activeChild; check = check.activeChild)
3383 if(check.modalSlave)
3385 modalWindow = check.modalSlave;
3391 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3392 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3395 void StopMoving(void)
3397 if(this == guiApp.windowMoving)
3399 guiApp.windowMoving = null;
3400 UpdateDecorations();
3401 SetMouseRange(null);
3404 if(rootWindow.active)
3405 guiApp.interfaceDriver.StopMoving(rootWindow);
3407 guiApp.windowCaptured.ReleaseCapture();
3408 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3409 guiApp.windowIsResizing = false;
3413 void SelectMouseCursor(void)
3418 Window cursorWindow = null;
3419 bool rx, ry, rex, rey;
3421 guiApp.desktop.GetMousePosition(&x, &y);
3422 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3424 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3425 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[moving]);
3426 else if(mouseWindow)
3428 modalWindow = mouseWindow.FindModal();
3429 x -= mouseWindow.absPosition.x;
3430 y -= mouseWindow.absPosition.y;
3431 if(guiApp.windowIsResizing)
3433 rex = guiApp.resizeEndX;
3434 rey = guiApp.resizeEndY;
3435 rx = guiApp.resizeX;
3436 ry = guiApp.resizeY;
3437 if((rex && rey) || (rx && ry))
3438 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNWSE]);
3439 else if((rex && ry) || (rx && rey))
3440 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNESW]);
3441 else if((ry || rey) && (!rx && !rex))
3442 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNS]);
3443 else if((rx || rex) && (!ry && !rey))
3444 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeWE]);
3446 else if(!modalWindow && !guiApp.windowCaptured &&
3447 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3448 &rx, &ry, &rex, &rey))
3450 if((rex && rey) || (rx && ry))
3451 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNWSE]);
3452 else if((rex && ry) || (rx && rey))
3453 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNESW]);
3454 else if((ry || rey) && (!rx && !rex))
3455 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNS]);
3456 else if((rx || rex) && (!ry && !rey))
3457 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeWE]);
3459 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3461 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}) &&
3462 mouseWindow.rootWindow != mouseWindow)
3463 cursorWindow = mouseWindow.parent;
3465 cursorWindow = mouseWindow;
3467 else if(!guiApp.interimWindow)
3468 cursorWindow = guiApp.windowCaptured;
3471 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient && cursorWindow.rootWindow != cursorWindow; cursorWindow = cursorWindow.parent);
3472 guiApp.SetCurrentCursor(mouseWindow, cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3474 else if(modalWindow)
3476 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[arrow]);
3478 else if(guiApp.interimWindow)
3480 if(guiApp.interimWindow.cursor)
3481 guiApp.SetCurrentCursor(mouseWindow, guiApp.interimWindow.cursor);
3483 guiApp.SetCurrentCursor(mouseWindow, mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3488 // --- State based input ---
3489 bool AcquireInputEx(bool state)
3494 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3495 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3497 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3499 guiApp.acquiredWindow = state ? this : null;
3502 SetMouseRangeToClient();
3503 guiApp.interfaceDriver.SetMouseCursor(guiApp.acquiredWindow, (SystemCursor)-1);
3508 SelectMouseCursor();
3510 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3514 // --- Window activation ---
3515 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3518 if(!parent || !parent.style.inactive)
3520 Window parent = this.parent;
3523 if(rootWindow == this)
3524 Log(active ? "active\n" : "inactive\n");
3526 if(active && requireRemaximize)
3528 if(state == maximized)
3530 property::state = normal;
3531 property::state = maximized;
3533 requireRemaximize = false;
3536 // Testing this here...
3537 if(!parent || parent == guiApp.desktop || parent.active)
3539 this.active = active;
3542 // TESTING THIS HERE
3543 UpdateDecorations();
3544 if((result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master))
3545 result = NotifyActivate(master, this, active, previous);
3548 this.active = !active;
3553 if(!parent || parent == guiApp.desktop || parent.active)
3555 this.active = active;
3557 AcquireInputEx(active);
3558 if(active && isEnabled)
3562 if(guiApp.caretOwner)
3566 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3567 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3568 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3569 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3571 guiApp.caretOwner.Update(extent);
3574 if(visible || !guiApp.caretOwner)
3575 guiApp.caretOwner = this;
3576 UpdateCaret(false, false);
3582 this.active = false;
3584 AcquireInputEx(active);
3586 if(!active && guiApp.caretOwner == this)
3588 UpdateCaret(false, true);
3589 guiApp.caretOwner = null;
3590 guiApp.interfaceDriver.SetCaret(0,0,0);
3591 guiApp.caretEnabled = false;
3596 if(!active && parent && parent.activeChild && parent.activeChild != this)
3597 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3603 if(!active && menuBar)
3606 menuBar.OnActivate(false, null, &goOn, true);
3607 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3612 Window aChild = activeChild;
3614 if(!aChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3626 void ConsequentialMouseMove(bool kbMoving)
3630 if(kbMoving || !guiApp.windowMoving)
3634 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3636 if(guiApp.interfaceDriver)
3637 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3639 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3640 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3646 bool IsDescendantOf(Window ancestor)
3649 for(window = this; window && window != ancestor; window = window.parent);
3650 return window == ancestor;
3653 bool IsSlaveOf(Window master)
3656 for(window = this; window && window != master; window = window.master);
3657 return window == master;
3660 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3664 if(this && !destroyed /*&& state != Hidden*/)
3666 Window swap = externalSwap;
3674 if(activateParent &&
3675 (parent.activeChild != this ||
3676 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3677 active && _isModal &&
3678 parent != master && master)
3679 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3685 bool real = parent.activeChild != this;
3687 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3688 if(!style.inactive && /*activateParent && */guiApp.interimWindow &&
3689 !IsDescendantOf(guiApp.interimWindow) &&
3690 !IsSlaveOf(guiApp.interimWindow))
3692 Window interimWindow = guiApp.interimWindow;
3693 while(interimWindow && interimWindow != this)
3695 Window master = interimWindow.master;
3697 guiApp.interimWindow = null;
3698 if(guiApp.caretOwner)
3699 guiApp.caretOwner.UpdateCaret(false, false);
3701 incref interimWindow;
3702 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3707 delete interimWindow;
3708 interimWindow = (master && master.style.interim) ? master : null;
3713 guiApp.interimWindow = this;
3714 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3715 guiApp.caretEnabled = false;*/
3716 UpdateCaret(false, true);
3721 //bool acquireInput = false;
3723 parent.activeChild &&
3724 parent.activeChild.state == maximized &&
3725 parent != guiApp.desktop;
3727 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3732 swap = parent.activeChild;
3733 if(swap && swap.destroyed) swap = null;
3734 if(swap && swap != this)
3737 if(!swap.PropagateActive(false, this, &goOn, true))
3738 swap = parent.activeChild;
3749 if(!parent || parent.activeChild != this || style.interim)
3752 result = PropagateActive(true, swap, &goOn, true);
3753 if(!result && !goOn)
3758 //acquireInput = true;
3762 if(style.hasMaximize && parent != guiApp.desktop)
3765 SetState(maximized, false, 0);
3766 else if(state != maximized)
3769 for(child = parent.children.first; child; child = child.next)
3771 if(this != child && child.state == maximized)
3772 child.SetState(normal, false, 0);
3779 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3781 Window previous = parent.activeClient;
3782 parent.activeChild = this;
3783 if(!style.nonClient /*&& style.isActiveClient*/)
3787 if(style.isActiveClient)
3788 parent.activeClient = this;
3789 // Moved UpdateActiveDocument inside hidden check
3790 // To prevent activating previous window while creating a new one
3791 // (It was messing up the privateModule in the CodeEditor)
3792 parent.UpdateActiveDocument(previous);
3798 //if(!style.isRemote)
3800 if(rootWindow != this)
3802 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3803 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3806 #if !defined(__EMSCRIPTEN__)
3807 if(!guiApp.fullScreenMode)
3810 Window modalRoot = FindModal();
3811 if(!modalRoot) modalRoot = this;
3812 if(!modalRoot.isForegroundWindow)
3814 modalRoot.isForegroundWindow = true;
3815 // To check : Why is parent null?
3816 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3818 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3820 modalRoot.isForegroundWindow = false;
3825 if(result && real && (!style.inactive || moveInactive) && parent)
3827 Window last = parent.children.last;
3829 if(!style.stayOnTop)
3830 for(; last && last.style.stayOnTop; last = last.prev);
3832 parent.children.Move(this, last);
3834 // Definitely don't want that: why not?
3838 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3844 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3851 parent.activeChild = null;
3852 if(!style.nonClient /*&& style.isActiveClient*/)
3854 Window previous = parent.activeClient;
3855 if(style.isActiveClient)
3856 parent.activeClient = null;
3857 parent.UpdateActiveDocument(previous);
3861 if(this == guiApp.interimWindow)
3863 guiApp.interimWindow = null;
3864 if(guiApp.caretOwner)
3865 guiApp.caretOwner.UpdateCaret(false, false);
3867 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3874 if(!active || !swap)
3875 UpdateDecorations();
3877 swap.UpdateDecorations();
3879 if(active && rootWindow != this)
3880 ConsequentialMouseMove(false);
3887 // --- Input Messages ---
3888 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3890 static bool reEntrancy = false;
3891 if(reEntrancy) return;
3895 guiApp.cursorUpdate = true;
3896 if(guiApp.windowScrolling && !consequential)
3898 guiApp.windowScrolling.SetScrollPosition(
3899 (guiApp.windowScrolling.sbh) ?
3900 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3901 (guiApp.windowScrolling.sbv) ?
3902 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3904 if(guiApp.windowMoving)
3906 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3908 Window window = guiApp.windowMoving;
3910 int w = window.size.w;
3911 int h = window.size.h;
3916 rx = mouseX - guiApp.windowMovingStart.x;
3917 ry = mouseY - guiApp.windowMovingStart.y;
3920 window.GetDecorationsSize(&ew, &eh);
3922 if(guiApp.windowIsResizing)
3924 x = window.scrolledPos.x;
3925 y = window.scrolledPos.y;
3929 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3930 rx = guiApp.windowResizingBefore.w - aw;
3931 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3932 w = guiApp.windowResizingBefore.w - rx;
3936 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3937 ry = guiApp.windowResizingBefore.h - ah;
3938 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3939 ry = Max(ry, -guiApp.windowMovingBefore.y);
3940 h = guiApp.windowResizingBefore.h - ry;
3942 if(guiApp.resizeEndX)
3944 w = guiApp.windowResizingBefore.w + rx;
3947 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3955 w = Max(w, window.minSize.w);
3956 h = Max(h, window.minSize.h);
3957 w = Min(w, window.maxSize.w);
3958 h = Min(h, window.maxSize.h);
3960 if(!window.OnResizing(&w, &h))
3962 w = window.clientSize.w;
3963 h = window.clientSize.h;
3966 w = Max(w, window.skinMinSize.w);
3967 h = Max(h, window.skinMinSize.h);
3974 SNAPDOWN(w, textCellW);
3975 SNAPDOWN(h, textCellH);
3980 aw = Max(w,window.skinMinSize.w);
3981 rx = guiApp.windowResizingBefore.w - aw;
3982 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3983 w = guiApp.windowResizingBefore.w - rx;
3987 ah = Max(h,window.skinMinSize.h);
3988 ry = guiApp.windowResizingBefore.h - ah;
3989 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3990 ry = Max(ry, -guiApp.windowMovingBefore.y);
3991 h = guiApp.windowResizingBefore.h - ry;
3996 if(!guiApp.windowIsResizing || guiApp.resizeX)
3997 x = guiApp.windowMovingBefore.x + rx;
3998 if(!guiApp.windowIsResizing || guiApp.resizeY)
3999 y = guiApp.windowMovingBefore.y + ry;
4001 if(!guiApp.windowIsResizing)
4004 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
4006 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
4007 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
4008 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
4009 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
4013 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
4014 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
4020 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
4022 if(!window.OnMoving(&x, &y, w, h))
4024 x = window.scrolledPos.x;
4025 y = window.scrolledPos.y;
4031 SNAPDOWN(x, textCellW);
4032 SNAPDOWN(y, textCellH);
4035 if(!window.style.nonClient)
4037 if(!window.style.fixed /*|| window.style.isDocument*/)
4039 if(!window.style.dontScrollHorz)
4040 x += window.parent.scroll.x;
4041 if(!window.style.dontScrollVert)
4042 y += window.parent.scroll.y;
4046 // Break the anchors for moveable/resizable windows
4047 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
4048 if(window.style.fixed)
4050 if(window.state == normal)
4052 window.normalAnchor = Anchor { left = x, top = y };
4053 window.normalSizeAnchor = SizeAnchor { { w, h } };
4054 window.anchored = false;
4058 window.stateAnchor = Anchor { left = x, top = y };
4059 window.stateSizeAnchor = SizeAnchor { { w, h } };
4061 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
4062 // TOCHECK: Investigate why the following only redraws the scrollbars
4063 //window.Position(x, y, w, h, false, true, true, true, false, true);
4065 guiApp.movingLast.x = mouseX;
4066 guiApp.movingLast.y = mouseY;
4072 public bool MultiTouchMessage(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers * mods, bool consequential, bool activate)
4078 while(result && w != this)
4080 // TODO: How to handle this?
4083 Window msgWindow = GetAtPosition(x,y, false, true, w);
4088 window = (w && !w.disabled) ? w : null;
4090 if(consequential) mods->isSideEffect = true;
4091 if(!result || (window && window.destroyed)) window = null;
4095 if(window.OnMultiTouch && !window.disabled)
4097 Array<TouchPointerInfo> in { size = infos.size };
4098 memcpy(in.array, infos.array, sizeof(TouchPointerInfo) * infos.size);
4102 i.x -= (window.absPosition.x + window.clientStart.x);
4103 i.y -= (window.absPosition.y + window.clientStart.y);
4105 i.x = Max(Min(i.x, 32767),-32768);
4106 i.y = Max(Min(i.y, 32767),-32768);
4110 if(!window.OnMultiTouch(event, in, *mods))
4117 if(!result || !w || !w.clickThrough)
4125 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
4128 bool wasMoving = guiApp.windowMoving ? true : false;
4129 bool wasScrolling = guiApp.windowScrolling ? true : false;
4131 while(result && w != this)
4133 Window msgWindow = GetAtPosition(x,y, false, true, w);
4134 Window trueWindow = GetAtPosition(x,y, false, false, w);
4135 bool windowDragged = false;
4140 window = (w && !w.disabled) ? w : null;
4142 if(trueWindow) incref trueWindow;
4144 if(consequential) mods->isSideEffect = true;
4146 UpdateMouseMove(x, y, consequential);
4148 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
4150 if(!guiApp.windowCaptured.isEnabled)
4151 guiApp.windowCaptured.ReleaseCapture();
4153 window = guiApp.windowCaptured;
4156 if(trueWindow && activate &&
4157 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
4158 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
4159 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
4160 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
4162 if(mods->alt && !mods->ctrl && !mods->shift)
4164 Window moved = trueWindow;
4165 for(moved = trueWindow; moved; moved = moved.parent)
4166 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
4171 windowDragged = true;
4173 // Cancel the ALT menu toggling...
4174 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4179 if(window && activate &&
4180 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
4181 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
4182 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
4183 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
4185 Window modalWindow = window.FindModal();
4187 /*if(mods->alt && !mods->shift && !mods->ctrl)
4189 Window moved = window;
4190 for(moved = window; moved; moved = moved.parent)
4191 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
4196 windowDragged = true;
4198 // Cancel the ALT menu toggling...
4199 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
4205 Window activateWindow = modalWindow ? modalWindow : window;
4206 if(activateWindow && !activateWindow.isRemote)
4208 bool doActivation = true;
4209 //bool needToDoActivation = false;
4210 Window check = activateWindow;
4212 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
4214 if(!check.style.inactive)
4216 //needToDoActivation = true;
4218 doActivation = false;
4223 if(!needToDoActivation)
4224 doActivation = false;
4227 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
4228 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
4230 // Let the OnLeftButtonDown do the activating instead
4231 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4239 incref activateWindow;
4240 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
4242 delete activateWindow;
4246 if(activateWindow._refCount == 1)
4248 delete activateWindow;
4252 delete activateWindow;
4253 // Trouble with clickThrough, siblings and activation (Fix for nicktick scrolling, siblings/activation endless loops, #844)
4256 mods->isActivate = true;
4260 if(!modalWindow && window && !window.destroyed)
4262 if(!guiApp.windowCaptured || windowDragged)
4264 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
4266 bool moving = ((window.state != maximized &&
4267 window.IsMouseMoving(
4268 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4269 || (guiApp.windowMoving && !guiApp.windowIsResizing);
4271 if(!moving && window.IsMouseResizing(
4272 x - window.absPosition.x,
4273 y - window.absPosition.y,
4274 window.size.w, window.size.h,
4275 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
4277 guiApp.windowIsResizing = true;
4278 guiApp.windowResizingBefore.w = window.size.w;
4279 guiApp.windowResizingBefore.h = window.size.h;
4281 if(guiApp.windowIsResizing || windowDragged || moving)
4284 guiApp.windowMoving = window;
4285 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4286 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4287 guiApp.windowMovingBefore.x = window.position.x;//s;
4288 guiApp.windowMovingBefore.y = window.position.y;//s;
4289 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4290 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4293 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4295 if(window.style.fixed &&
4297 window.IsMouseMoving(
4298 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4300 window.ShowSysMenu(x, y);
4304 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4306 if(window.sbv || window.sbh)
4309 guiApp.windowScrolling = window;
4310 guiApp.windowScrollingStart.x = x;
4311 guiApp.windowScrollingStart.y = y;
4312 guiApp.windowScrollingBefore.x = window.scroll.x;
4313 guiApp.windowScrollingBefore.y = window.scroll.y;
4316 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4318 if(window.style.hasMaximize &&
4319 window.IsMouseMoving(
4320 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4323 (window.state == maximized) ? normal : maximized, false, *mods);
4331 if(guiApp.windowMoving)
4333 if(guiApp.windowMoving.parent)
4335 if(guiApp.windowMoving.style.nonClient)
4336 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4338 guiApp.windowMoving.parent.SetMouseRangeToClient();
4342 window.UpdateDecorations();
4345 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4347 // Log("\n*** LEFT BUTTON UP ***\n");
4348 if(guiApp.windowMoving)
4349 guiApp.windowMoving.StopMoving();
4351 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4353 if(guiApp.windowScrolling)
4355 Window windowScrolling = guiApp.windowScrolling;
4356 guiApp.windowScrolling = null;
4357 windowScrolling.ReleaseCapture();
4361 if(!result || (window && window.destroyed)) window = null;
4363 if(window && window.FindModal())
4366 if(trueWindow && trueWindow.FindModal())
4374 msgWindow = GetAtPosition(x,y, true, false);
4376 msgWindow.SelectMouseCursor();
4379 if(guiApp.windowCaptured || trueWindow)
4381 Window prevWindow = guiApp.prevWindow;
4382 List<Window> overWindows = guiApp.overWindows;
4383 Iterator<Window> it { overWindows };
4388 if(trueWindow != w && !trueWindow.IsDescendantOf(w))
4391 result = w.OnMouseLeave(*mods);
4393 overWindows.TakeOut(w);
4397 if(result && guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4399 guiApp.prevWindow.mouseInside = false;
4400 guiApp.prevWindow = null;
4404 if(trueWindow.IsDescendantOf(prevWindow))
4406 if(!overWindows.Find(prevWindow))
4407 overWindows.Add(prevWindow);
4409 // Eventually fix this not to include captured?
4410 else if(!prevWindow.OnMouseLeave(*mods))
4414 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4416 Box box = trueWindow.box;
4417 box.left += trueWindow.absPosition.x;
4418 box.right += trueWindow.absPosition.x;
4419 box.top += trueWindow.absPosition.y;
4420 box.bottom += trueWindow.absPosition.y;
4422 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4424 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4425 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4427 overX = Max(Min(overX, 32767),-32768);
4428 overY = Max(Min(overY, 32767),-32768);
4430 trueWindow.mouseInside = true;
4431 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4435 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4437 for(w : guiApp.overWindows; w == trueWindow)
4440 guiApp.overWindows.TakeOut(w);
4443 guiApp.prevWindow = trueWindow;
4446 guiApp.prevWindow = null;
4448 SelectMouseCursor();
4450 if(window && ((!guiApp.windowMoving && !wasMoving) ||
4451 (wasMoving && guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp)) && !wasScrolling)
4453 int clientX = x - (window.absPosition.x + window.clientStart.x);
4454 int clientY = y - (window.absPosition.y + window.clientStart.y);
4456 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4458 clientX = Max(Min(clientX, 32767),-32768);
4459 clientY = Max(Min(clientY, 32767),-32768);
4461 MouseMethod = (void *)window._vTbl[method];
4463 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4466 if(!MouseMethod(window, clientX, clientY, *mods))
4470 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4471 window.OnMouseLeave(*mods);
4478 if(result && w && w.clickThrough && w.parent)
4483 if(!result || !w || !w.clickThrough)
4490 // --- Mouse cursor management ---
4492 bool KeyMessage(uint method, Key key, unichar character)
4497 if(guiApp.interimWindow)
4498 this = guiApp.interimWindow;
4501 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4505 if(!style.inactive || rootWindow != this)
4507 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4508 Window modalWindow = FindModal();
4509 Window interimMaster = master ? master.rootWindow : null;
4513 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4514 status = OnSysKeyDown(key, character);
4515 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4516 status = OnSysKeyHit(key, character);
4517 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4518 status = OnSysKeyUp(key, character);
4525 // Process Key Message for Internal UI Keyboard actions
4526 if(status && !destroyed && menuBar && state != minimized)
4529 if((SmartKey)key != alt)
4530 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4533 SmartKey sk = (SmartKey) key;
4534 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4536 status = menuBar.KeyMessage(method, key, character);
4541 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4542 menuBar.OnKeyHit(escape, 0);
4544 if(!menuBar.focus && guiApp.caretOwner)
4545 guiApp.caretOwner.UpdateCaret(true, false);
4548 if(!destroyed && status)
4550 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4554 case left: case up: case right: case down:
4555 if(guiApp.windowMoving == this)
4558 int w = guiApp.windowMoving.size.w;
4559 int h = guiApp.windowMoving.size.h;
4560 int x = guiApp.windowMoving.scrolledPos.x;
4561 int y = guiApp.windowMoving.scrolledPos.y;
4565 if(key == down || key == up)
4566 step = Max(step, textCellH);
4568 step = Max(step, textCellW);
4571 if(guiApp.windowIsResizing)
4575 case left: w-=step; break;
4576 case right: w+=step; break;
4577 case up: h-=step; break;
4578 case down: h+=step; break;
4585 case left: x-=step; break;
4586 case right: x+=step; break;
4587 case up: y-=step; break;
4588 case down: y+=step; break;
4592 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4593 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4595 if(!guiApp.windowIsResizing || guiApp.resizeX)
4596 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4598 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4600 if(!guiApp.windowIsResizing || guiApp.resizeY)
4601 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4603 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4605 guiApp.interfaceDriver.SetMousePosition(x, y);
4606 ConsequentialMouseMove(true);
4614 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4616 guiApp.windowMoving.StopMoving();
4617 ConsequentialMouseMove(false);
4625 ShowSysMenu(absPosition.x, absPosition.y);
4633 if(!destroyed && status && state != minimized)
4635 // Process all the way down the children
4636 if(activeChild && !activeChild.disabled)
4638 status = activeChild.KeyMessage(method, key, character);
4640 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4641 key.code != left && key.code != right && key.code != up && key.code != down)
4643 status = activeClient.KeyMessage(method, key, character);
4647 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4649 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4650 // && defaultControl != activeChild)
4652 delete previousActive;
4653 previousActive = activeChild;
4654 if(previousActive) incref previousActive;
4656 ConsequentialMouseMove(false);
4657 if((defaultControl.active ||
4658 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4659 defaultControl.KeyMessage(method, defaultKey, character);
4665 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4667 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4674 ShowSysMenu(absPosition.x, absPosition.y);
4681 if(this != guiApp.desktop)
4683 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4685 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4687 MenuMoveOrSize(key.shift, true);
4691 else if(guiApp.windowMoving)
4693 guiApp.windowMoving.StopMoving();
4694 ConsequentialMouseMove(false);
4702 if(!destroyed && status && state != minimized)
4704 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4708 case tab: case shiftTab:
4710 Window cycleParent = this;
4711 if(this == guiApp.interimWindow && master && !master.style.interim && !cycleParent.style.tabCycle && master.parent)
4712 cycleParent = master.parent;
4714 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4716 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4719 Window child = cycleParent.activeChild;
4721 // Scroll the window to include the active control
4722 if(cycleParent.sbh && !child.style.dontScrollHorz)
4724 if(child.scrolledPos.x < 0)
4725 cycleParent.sbh.Action(Position,
4726 cycleParent.scroll.x + child.scrolledPos.x, 0);
4727 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4728 cycleParent.sbh.Action(Position,
4729 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4731 if(cycleParent.sbv && !child.style.dontScrollVert)
4733 if(child.scrolledPos.y < 0)
4734 cycleParent.sbv.Action(Position,
4735 cycleParent.scroll.y + child.scrolledPos.y, 0);
4736 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4737 cycleParent.sbv.Action(Position,
4738 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4741 cycleParent.ConsequentialMouseMove(false);
4747 case f6: case shiftF6:
4748 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4750 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4751 if(parent == guiApp.desktop)
4752 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4762 if(CycleChildren(key.shift, true, false, true))
4770 // mIRC Style Window Shortcuts
4771 case alt1: case alt2: case alt3: case alt4: case alt5:
4772 case alt6: case alt7: case alt8: case alt9: case alt0:
4777 for(document = children.first; document; document = document.next)
4779 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4781 if(document == activeChild)
4783 if(document.state == minimized)
4784 document.SetState(normal, false, key);
4787 document.SetState(minimized, false, key);
4788 CycleChildren(false, true, false);
4793 if(activeChild.state == maximized && document.style.hasMaximize)
4794 document.SetState(maximized, false, key);
4795 else if(document.state == minimized)
4796 document.SetState(normal, false, key);
4797 document.Activate();
4812 if(!destroyed && status)
4814 if(state == minimized)
4819 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4821 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4823 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4824 previousActive.ActivateEx(true, false, false, true, null, null);
4825 delete previousActive;
4831 if(!destroyed && status)
4833 status = ProcessHotKeys(method, key, character);
4835 if(!destroyed && status && !modalWindow && state != minimized)
4838 status = KeyMethod(this, key, character);
4839 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4840 status = OnKeyHit(key, character);
4841 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4843 bool result = false;
4846 case ctrlUp: case ctrlDown:
4847 if(sbv && !guiApp.windowScrolling)
4848 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4850 case wheelUp: case wheelDown:
4851 if(sbv && !guiApp.windowScrolling)
4853 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4854 // Do we want to do a consequential move regardless of result in this case?
4855 ConsequentialMouseMove(false);
4858 case ctrlPageUp: case ctrlPageDown:
4859 if(sbh && !guiApp.windowScrolling)
4860 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4865 ConsequentialMouseMove(false);
4870 if(status && !destroyed && menuBar && state != minimized)
4871 status = menuBar.KeyMessage(method, key, character);
4873 if(style.interim && /*destroyed && */status && interimMaster)
4875 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4876 status = interimMaster.KeyMessage(method, key, character);
4883 bool ProcessHotKeys(uint method, Key key, unichar character)
4888 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4889 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4890 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4892 Window hotKeyWindow = hotKey.window;
4893 Window parent = hotKeyWindow.parent;
4894 Window prevActiveWindow = activeChild;
4895 // For when sys buttons are placed inside the menu bar
4896 if(parent && parent._class == class(PopupMenu))
4897 parent = parent.parent;
4899 // 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
4900 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1])))
4903 if(prevActiveWindow) incref prevActiveWindow;
4904 incref hotKeyWindow;
4905 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient && !hotKeyWindow.inactive)
4906 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4909 delete hotKeyWindow;
4910 delete prevActiveWindow;
4914 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4915 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4916 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4918 // ********* WORKING ON THIS ***********
4919 if(prevActiveWindow && !guiApp.interimWindow)
4920 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4923 else if(hotKeyWindow.style.inactive)
4924 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4926 delete prevActiveWindow;
4927 delete hotKeyWindow;
4928 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4929 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4933 if(status && tabCycle)
4936 for(child = children.first; child; child = child.next)
4938 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4949 // --- Windows and graphics initialization / termination ---
4950 bool SetupRoot(void)
4954 // Setup relationship with outside world (bb root || !bb)
4955 #if defined(__EMSCRIPTEN__)
4956 if(this == guiApp.desktop)
4958 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4959 (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))
4964 tempExtents = new0 Extent[4];
4969 /*if(guiApp.fullScreenMode)
4970 rootWindow = guiApp.desktop;
4972 //rootWindow = parent.created ? parent.rootWindow : null;
4973 rootWindow = parent.rootWindow;
4976 against = &parent.box;
4978 against = &parent.clientArea;
4981 for(child = children.first; child; child = child.next)
4984 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
4987 bool Setup(bool positionChildren)
4989 bool result = false;
4992 #if defined(__EMSCRIPTEN__)
4993 if(this == guiApp.desktop)
4995 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))))
4998 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
4999 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
5002 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
5004 // This was here, is it really needed?
5005 //guiApp.interfaceDriver.ActivateRootWindow(this);
5009 displaySystem = DisplaySystem {};
5010 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
5012 delete displaySystem;
5017 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData };
5018 if(display.Create(displaySystem, windowHandle))
5025 // Sometimes icon does not show up on Windows XP if we set here...
5026 // guiApp.interfaceDriver.SetIcon(this, icon);
5028 else if(this != guiApp.desktop)
5030 display = rootWindow ? rootWindow.display : null;
5036 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
5037 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
5039 for(child = children.first; child; child = child.next)
5041 if(child.created && !child.Setup(false))
5044 if(guiApp.modeSwitching && guiApp.fullScreen && child.rootWindow == child)
5045 child.UpdateCaption();
5050 bool SetupDisplay(void)
5052 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
5053 if(is3D) return Window3D_SetupDisplay(this); else
5060 class_data void ** pureVTbl;
5062 bool LoadGraphics(bool creation, bool resetAnchors)
5064 bool result = false;
5065 bool success = false;
5067 WindowState stateBackup = state;
5069 if(((subclass(Window))_class).pureVTbl)
5071 if(_vTbl == _class._vTbl)
5073 _vTbl = ((subclass(Window))_class).pureVTbl;
5078 for(m = 0; m < _class.vTblSize; m++)
5080 if(_vTbl[m] == _class._vTbl[m])
5081 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5085 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
5087 if(_vTbl == ((subclass(Window))_class).pureVTbl)
5089 _vTbl = _class._vTbl;
5094 for(m = 0; m < _class.vTblSize; m++)
5096 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
5097 _vTbl[m] = _class._vTbl[m];
5103 #if !defined(__EMSCRIPTEN__)
5104 guiApp.fullScreenMode ||
5106 this != guiApp.desktop)
5108 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
5114 display.Lock(false);
5115 if(rootWindow == this)
5117 // Set Color Palette
5118 display.SetPalette(palette, true);
5122 if(guiApp.fullScreenMode && this == guiApp.desktop)
5127 for(c=0; c<SystemCursor::enumSize; c++)
5128 if(!guiApp.systemCursors[c].bitmap)
5130 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
5131 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
5132 if(guiApp.systemCursors[c].bitmapName)
5134 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
5135 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
5136 if(guiApp.systemCursors[c].bitmap)
5137 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
5142 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5144 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
5145 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
5147 cursor.bitmap.paletteShades = cursor.paletteShades;
5151 guiApp.cursorUpdate = true;
5154 ConsequentialMouseMove(false);
5160 // Load Window Graphic Resources
5163 if(usedFont == setFont || usedFont == window.systemFont)
5164 RemoveResource(usedFont);
5167 RemoveResource(setFont); // TESTING setFont instead of usedFont);
5170 RemoveResource(systemFont);
5173 RemoveResource(captionFont);
5175 for(ptr = resources.first; ptr; ptr = ptr.next)
5177 if(!ptr.loaded) // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
5178 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
5181 AddResource(setFont);
5183 AddResource(systemFont);
5185 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
5192 //if(master && master.font)
5193 if(parent && parent.font)
5197 faceName = parent.font.faceName,
5198 size = parent.font.size,
5199 bold = parent.font.bold,
5200 italic = parent.font.italic,
5201 underline = parent.font.underline
5203 //font = parent.font;
5204 watch(parent) { font { } };
5207 font = guiApp.currentSkin.SystemFont();
5214 captionFont = guiApp.currentSkin ? guiApp.currentSkin.CaptionFont() : null;
5215 AddResource(captionFont);
5217 if(OnLoadGraphics())
5223 //SetScrollLineStep(sbStep.x, sbStep.y);
5225 if(this != guiApp.desktop)
5229 normalAnchor = anchor;
5230 normalSizeAnchor = sizeAnchor;
5233 // Break the anchors for moveable/resizable windows
5235 if(style.fixed && style.isDocument)
5237 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
5249 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5250 stateSizeAnchor = SizeAnchor {};
5255 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5260 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
5261 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
5264 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5268 stateAnchor = normalAnchor;
5269 stateSizeAnchor = normalSizeAnchor;
5272 position = Point { };
5273 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5284 if(Position(x, y, w, h, true, false, true, true, true, true))
5286 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
5289 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
5306 success = result = true;
5309 if(!creation && result)
5311 // Load menu bar first because sys buttons are on it...
5314 if(!menuBar.LoadGraphics(false, resetAnchors))
5320 for(child = children.first; child; child = child.next)
5322 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
5329 CreateSystemChildren();
5333 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5336 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5339 LogErrorCode(graphicsLoadingFailed, _class.name);
5341 // Do this here to avoid problems on Windows
5342 if(rootWindow == this && parent && stateBackup == maximized)
5343 property::state = maximized;
5347 void UnloadGraphics(bool destroyWindows)
5351 // Free children's graphics
5352 for(child = children.first; child; child = child.next)
5353 child.UnloadGraphics(destroyWindows);
5356 display.Lock(false);
5359 if(guiApp.fullScreenMode && this == guiApp.desktop)
5364 for(c=0; c<SystemCursor::enumSize; c++)
5365 if(guiApp.systemCursors[c].bitmap)
5366 delete guiApp.systemCursors[c].bitmap;
5368 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5369 delete cursor.bitmap;
5371 guiApp.cursorBackground.Free();
5374 if(display && display.displaySystem)
5378 for(ptr = resources.first; ptr; ptr = ptr.next)
5382 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5387 // Free window graphics
5390 // Free skin graphics
5391 if(rootWindow == this)
5393 DisplaySystem displaySystem = display.displaySystem;
5396 display.driverData = null;
5397 display.displaySystem = null;
5401 if(displaySystem && !displaySystem.numDisplays && !is3D)
5402 delete displaySystem;
5411 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5412 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5414 if(this == guiApp.desktop || parent == guiApp.desktop)
5416 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5417 guiApp.interfaceDriver.DestroyRootWindow(this);
5421 // --- Window Hiding ---
5423 void SetVisibility(bool state)
5425 bool visible = (style.hidden || !created) ? false : state;
5426 if(visible != this.visible)
5430 this.visible = visible;
5431 for(child = children.first; child; child = child.next)
5432 child.SetVisibility(visible);
5434 ConsequentialMouseMove(false);
5435 if(parent && !nonClient) parent.OnChildVisibilityToggled(this, visible);
5439 // --- Windows and graphics initialization / termination ---
5441 bool DisplayModeChanged(void)
5443 bool result = false;
5444 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5446 guiApp.modeSwitching = true;
5447 UnloadGraphics(false);
5449 if(LoadGraphics(false, false))
5451 guiApp.modeSwitching = false;
5456 // --- Window updates system ---
5458 void UpdateDirty(Box updateBox)
5460 if(!manageDisplay) { OnRedraw(null);return; }
5463 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5466 if(display.flags.flipping)
5469 rootWindow.UpdateDisplay();
5472 UpdateBackDisplay(updateBox);
5474 if(guiApp.fullScreenMode)
5476 guiApp.cursorUpdate = true;
5477 guiApp.PreserveAndDrawCursor();
5479 if(guiApp.fullScreenMode)
5480 guiApp.RestoreCursorBackground();
5486 // This function is strictly called as a result of system window activation
5487 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5490 Window interimMaster = null;
5491 Window interimWindow = guiApp.interimWindow;
5492 if(interimWindow && interimWindow.master)
5493 interimMaster = interimWindow.master.rootWindow;
5495 if(active && state == minimized && window.parent) // && (!window.nativeDecorations || window.rootWindow != window)
5496 // SetState(normal, false, 0);
5497 SetState(lastState, false, 0);
5499 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5503 /* WTH is this doing here?
5504 while(swap && swap.activeChild)
5506 swap = swap.activeChild;
5509 // TESTING THIS BEFORE...
5510 if(interimWindow && this == interimMaster)
5514 // Window interimSwap = this;
5515 Window menuBar = this.menuBar;
5516 if(menuBar && interimWindow.master == menuBar)
5519 while(interimSwap && interimSwap.activeChild)
5520 interimSwap = interimSwap.activeChild;
5522 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5523 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5525 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5526 //result = ActivateEx(true, true, false, activateRoot, window, null);
5531 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5532 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5534 if(interimWindow == this && interimMaster && !active)
5536 while(interimMaster && interimMaster.interim && interimMaster.master)
5538 // printf("Going up one master %s\n", interimMaster._class.name);
5539 interimMaster = interimMaster.master.rootWindow;
5541 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5542 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5548 bool DestroyEx(int64 returnCode)
5551 Timer timer, nextTimer;
5553 OldLink prevOrder = null;
5554 Window client = null;
5556 if(parent) stopwatching(parent, font);
5558 // if(window.modalSlave) return false;
5559 if(destroyed || !created)
5566 OldLink slave = master.slaves.FindLink(this);
5567 master.slaves.Delete(slave);
5570 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5576 this.returnCode = (DialogResult)returnCode;
5578 AcquireInput(false);
5583 master.hotKeys.Delete(hotKey);
5587 if(guiApp.prevWindow == this)
5589 guiApp.prevWindow = null;
5594 for(w : guiApp.overWindows; w == this)
5597 guiApp.overWindows.TakeOut(w);
5601 if(guiApp.caretOwner == this)
5603 guiApp.interfaceDriver.SetCaret(0,0,0);
5604 UpdateCaret(false, true);
5605 guiApp.caretEnabled = false;
5610 parent.childrenCycle.Remove(cycle);
5614 OldLink tmpPrev = order.prev;
5615 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5616 prevOrder = tmpPrev;
5619 client = tmpPrev ? tmpPrev.data : null;
5620 if(client == this) { client = null; break; }
5621 if(client && (client.style.hidden || client.destroyed || !client.created))
5622 tmpPrev = client.order.prev;
5626 prevOrder = tmpPrev;
5631 // If this window can be an active client, make sure the next window we activate can also be one
5632 if(!style.nonClient && style.isActiveClient)
5634 tmpPrev = prevOrder;
5637 client = tmpPrev ? tmpPrev.data : null;
5638 if(client == this) { client = null; break; }
5639 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5640 tmpPrev = client.order.prev;
5644 prevOrder = tmpPrev;
5648 if(client && client.style.hidden) client = null;
5650 // parent.childrenOrder.Remove(order);
5653 if(parent && style.isActiveClient && visible)
5655 if(state == minimized) parent.numIcons--;
5656 parent.numPositions--;
5659 // TESTING THIS HERE!
5663 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5664 // to create a window inside a rootwindow that's being destroyed)
5665 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5667 if(master && !master.destroyed /*&&
5668 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5670 if(master.defaultControl == this)
5671 master.defaultControl = null;
5674 parent.OnChildAddedOrRemoved(this, true);
5675 if(parent && !parent.destroyed /*&&
5676 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5678 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5680 if(order && prevOrder && prevOrder.data != this && active)
5682 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5684 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5685 if(parent.activeClient == this)
5687 parent.activeClient = null;
5688 parent.UpdateActiveDocument(null);
5693 if(guiApp.interimWindow == this)
5696 PropagateActive(false, null, &goOn, true);
5700 //if(window.parent.activeChild == window)
5701 parent.activeChild = null;
5702 if(!style.nonClient /*&& style.isActiveClient*/)
5704 Window previous = parent.activeClient;
5705 if(style.isActiveClient)
5706 parent.activeClient = null;
5707 parent.UpdateActiveDocument(previous);
5712 else if(parent.activeClient == this)
5714 parent.activeClient = client;
5715 parent.UpdateActiveDocument(this);
5719 if(guiApp.interimWindow == this)
5721 guiApp.interimWindow = null;
5722 if(guiApp.caretOwner)
5724 Window desktop = guiApp.desktop;
5725 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5726 guiApp.caretOwner.UpdateCaret(false, false);
5731 if(_isModal && master && master.modalSlave == this)
5732 master.modalSlave = null;
5736 if(!guiApp.caretOwner && parent.caretSize)
5738 guiApp.caretOwner = parent;
5739 parent.UpdateCaret(false, false);
5740 parent.Update(null);
5743 // Why was this commented out?
5744 GetRidOfVirtualArea();
5750 dirtyArea.Free(null);
5751 dirtyBack.Free(null);
5752 scrollExtent.Free(null);
5754 /* ATTEMPTING TO MOVE THAT ABOVE
5763 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5764 for(;(child = window.children.first);)
5766 for(; child && (child.destroyed || !child.created); child = child.next);
5775 UnloadGraphics(true);
5778 delete previousActive;
5781 // statusBar = null;
5784 if(master && !master.destroyed)
5786 //master.NotifyDestroyed(this, this.returnCode);
5787 NotifyDestroyed(master, this, this.returnCode);
5790 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5792 nextTimer = timer.next;
5793 if(timer.window == this)
5795 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5796 // timer.window = null;
5802 if(this == guiApp.windowMoving)
5805 if(guiApp.windowCaptured == this)
5807 //guiApp.windowCaptured = null;
5809 if(rootWindow != this && rootWindow)
5810 rootWindow.ConsequentialMouseMove(false);
5818 //for(child = children.first; next = child ? child.next : null, child; child = next)
5819 for(;(child = children.first); )
5821 for(; child && (child.destroyed || !child.created); child = child.next);
5831 /* // MOVED THIS UP...
5834 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5835 for(;(child = window.children.first); )
5837 for(; child && (child.destroyed || !child.created); child = child.next);
5846 while((slave = slaves.first))
5848 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5850 ((Window)slave.data).DestroyEx(0);
5855 if(guiApp.caretOwner == this)
5856 guiApp.caretOwner = null;
5858 sysButtons[0] = null;
5859 sysButtons[1] = null;
5860 sysButtons[2] = null;
5863 if(rootWindow != this)
5865 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5868 box.left -= parent.clientStart.x;
5869 box.top -= parent.clientStart.y;
5870 box.right -= parent.clientStart.x;
5871 box.bottom -= parent.clientStart.y;
5873 if(parent) parent.Update(box);
5878 OldLink slave = master.slaves.FindVoid(this);
5879 master.slaves.Delete(slave);
5885 parent.children.Remove(this);
5890 //autoCreate = false;
5893 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5894 if(((subclass(Window))_class).pureVTbl)
5896 if(_vTbl == _class._vTbl)
5898 _vTbl = ((subclass(Window))_class).pureVTbl;
5903 for(m = 0; m < _class.vTblSize; m++)
5905 if(_vTbl[m] == _class._vTbl[m])
5906 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5915 void SetStateEx(WindowState newState, bool activate)
5918 WindowState prevState = state;
5922 if(prevState != newState)
5923 lastState = prevState;
5925 if(rootWindow != this || !nativeDecorations || !windowHandle)
5927 if(style.isActiveClient && !style.hidden && prevState == minimized)
5930 // This block used to be at the end of the function... moved it for flicker problem in X
5931 // ------------------------------------------------------
5935 stateAnchor = normalAnchor;
5936 stateSizeAnchor = normalSizeAnchor;
5939 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5940 stateSizeAnchor = SizeAnchor {};
5946 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5949 byte * idBuffer = new0 byte[size];
5951 for(child = parent.children.first; child; child = child.next)
5953 if(child != this && child.state == minimized)
5955 if(child.iconID > size - 2)
5957 idBuffer = renew0 idBuffer byte[size*2];
5958 memset(idBuffer + size, 0, size);
5961 idBuffer[child.iconID] = (byte)bool::true;
5964 for(c = 0; c<size; c++)
5969 if(style.isActiveClient && !style.hidden)
5972 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5973 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5978 // TOCHECK: Why was this here?
5979 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5980 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5981 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5983 if(state != minimized || hasMinimize)
5984 Position(x, y, w, h, true, true, true, true, false, true);
5986 if(!style.inactive && !style.interim && parent && this == parent.activeClient)
5987 parent.UpdateActiveDocument(null);
5990 if(state != minimized || hasMinimize)
5991 CreateSystemChildren();
5992 // ------------------------------------------------------
5995 int GetPositionID(Window forChild)
5999 byte * idBuffer = new0 byte[size];
6002 for(child = children.first; child; child = child.next)
6004 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
6006 if(child.positionID > size - 2)
6008 idBuffer = renew0 idBuffer byte[size*2];
6009 memset(idBuffer + size, 0, size);
6012 idBuffer[child.positionID] = (byte)bool::true;
6015 for(c = 0; c<size; c++)
6022 // --- Window related graphics ---
6024 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
6026 palette = newPalette;
6027 if(rootWindow.display)
6028 rootWindow.display.SetPalette(palette, colorMatch);
6031 public bool AcquireInput(bool acquired)
6034 if((guiApp.acquiredWindow && acquiredInput) != acquired)
6036 if(active || (!visible && creationActivation == activate))
6037 result = AcquireInputEx(acquired);
6042 acquiredInput = acquired ? result : !result;
6047 void ListChildren(ListBox listBox)
6051 for(child = children.first; child; child = child.next)
6053 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
6055 DataRow row = listBox.AddRow();
6056 row.tag = (int64)(intptr)child;
6057 child.FigureCaption(caption);
6058 row.SetData(null, caption);
6063 void UpdateVisual(Box extent)
6065 if(guiApp.driver != null)
6067 #if !defined(__EMSCRIPTEN__)
6068 if(guiApp.fullScreenMode && guiApp.desktop.display)
6073 #if !defined(__EMSCRIPTEN__)
6074 guiApp.desktop.mutex.Wait();
6076 guiApp.desktop.display.Lock(true);
6079 if(guiApp.desktop.active)
6081 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
6083 if(guiApp.desktop.display.flags.flipping)
6084 guiApp.desktop.Update(null);
6085 guiApp.desktop.UpdateDisplay();
6086 guiApp.cursorUpdate = true;
6088 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
6090 guiApp.PreserveAndDrawCursor();
6091 // guiApp.desktop.display.ShowScreen();
6092 guiApp.cursorUpdate = false;
6093 guiApp.desktop.dirty = false;
6094 guiApp.RestoreCursorBackground();
6098 guiApp.desktop.display.Unlock();
6099 #if !defined(__EMSCRIPTEN__)
6100 guiApp.desktop.mutex.Release();
6105 Window rootWindow = this.rootWindow;
6106 #if !defined(__EMSCRIPTEN__)
6107 rootWindow.mutex.Wait();
6113 guiApp.SignalEvent();
6116 #if !defined(__EMSCRIPTEN__)
6117 guiApp.waitMutex.Wait();
6119 guiApp.interfaceDriver.Lock(rootWindow);
6120 if(!rootWindow.style.hidden && rootWindow.dirty)
6122 if(rootWindow.display)
6124 rootWindow.UpdateDisplay();
6125 //rootWindow.display.ShowScreen(null);
6127 rootWindow.dirty = false;
6129 guiApp.interfaceDriver.Unlock(rootWindow);
6130 #if !defined(__EMSCRIPTEN__)
6131 guiApp.waitMutex.Release();
6135 #if !defined(__EMSCRIPTEN__)
6136 rootWindow.mutex.Release();
6142 void UnlockDisplay(void)
6144 guiApp.interfaceDriver.Unlock(rootWindow);
6147 void LockDisplay(void)
6149 guiApp.interfaceDriver.Lock(rootWindow);
6152 Surface GetSurface(Box box)
6154 return Redraw((box == null) ? this.box : box);
6157 void SetMousePosition(int x, int y)
6159 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
6163 void IntegrationActivate(bool active)
6165 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
6167 isForegroundWindow = true;
6168 ActivateEx(active, active, false, false, null, null);
6169 isForegroundWindow = false;
6174 Window QueryCapture(void)
6176 return guiApp.windowCaptured;
6179 int GetDocumentID(void)
6183 byte * idBuffer = new0 byte[size];
6186 for(child = children.first; child; child = child.next)
6188 // TO CHECK: Do we want a documentID when we already have a file name?
6189 if(child.style.isDocument && !child.fileName)
6191 if(child.documentID-1 > size - 2)
6193 idBuffer = renew0 idBuffer byte[size*2];
6194 memset(idBuffer + size, 0, size);
6197 idBuffer[child.documentID-1] = 1;
6200 for(c = 0; c<size; c++)
6208 void SetInitSize(Size size)
6211 sizeAnchor.size = size;
6212 normalSizeAnchor = sizeAnchor;
6214 // Break the anchors for moveable/resizable windows
6215 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6217 stateAnchor = normalAnchor;
6218 stateSizeAnchor = normalSizeAnchor;
6220 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6221 Position(x,y, w, h, true, true, true, true, false, true);
6225 void MenuMoveOrSize(bool resize, bool setCursorPosition)
6227 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
6229 guiApp.windowIsResizing = resize;
6230 guiApp.windowMoving = this;
6231 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
6232 if(guiApp.windowIsResizing)
6234 guiApp.windowMovingStart.x += size.w - 1;
6235 guiApp.windowMovingStart.y += size.h - 1;
6237 guiApp.windowMovingBefore = scrolledPos;
6238 guiApp.windowResizingBefore = size;
6239 guiApp.windowMoving.UpdateDecorations();
6240 if(guiApp.windowIsResizing)
6241 guiApp.resizeEndX = guiApp.resizeEndY = true;
6243 if(setCursorPosition)
6244 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
6248 guiApp.interfaceDriver.GetMousePosition(&x, &y);
6249 guiApp.windowMovingStart.x += x - absPosition.x;
6250 guiApp.windowMovingStart.y += y - absPosition.y;
6253 if(guiApp.windowMoving)
6255 if(guiApp.windowMoving.style.nonClient)
6256 guiApp.windowMoving.parent.SetMouseRangeToWindow();
6258 guiApp.windowMoving.parent.SetMouseRangeToClient();
6263 if(this == rootWindow)
6264 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
6268 void SetupFileMonitor()
6270 #if !defined(__EMSCRIPTEN__)
6273 fileMonitor = FileMonitor
6275 this, FileChange { modified = true };
6277 bool OnFileNotify(FileChange action, const char * param)
6280 fileMonitor.StopMonitoring();
6281 if(OnFileModified(action, param))
6282 fileMonitor.StartMonitoring();
6296 bool result = false;
6300 else if(guiApp && guiApp.driver != null)
6302 OldLink slaveHolder;
6304 bool visible = !style.hidden;
6308 systemParent = parent;
6309 parent = guiApp.desktop;
6311 last = parent ? parent.children.last : null;
6313 if((parent && parent != guiApp.desktop && !parent.created) ||
6314 (master && master != guiApp.desktop && !master.created))
6318 stopwatching(parent, font);
6321 property::parent = guiApp.desktop;
6322 if(!master) master = parent;
6324 if(_isModal && master.modalSlave)
6325 property::master = master.modalSlave;
6329 parent.children.Remove(this);
6332 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
6333 if(slaveHolder.data == this)
6335 master.slaves.Delete(slaveHolder);
6340 #if !defined(__EMSCRIPTEN__)
6341 if(parent == guiApp.desktop && !mutex)
6345 if(style.isDocument)
6348 parent.numDocuments--;
6349 documentID = parent.GetDocumentID();
6352 if(!style.stayOnTop)
6353 for(; last && last.style.stayOnTop; last = last.prev);
6355 parent.children.Insert((last == this) ? null : last, this);
6356 //parent.children.Add(this);
6359 dispDriver = parent.dispDriver;
6362 master.modalSlave = this;
6364 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
6369 master.slaves.Add(slaveHolder = OldLink { data = this });
6374 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
6376 if(style.isDefault && !master.defaultControl)
6377 master.defaultControl = this;
6379 stateAnchor = normalAnchor = anchor;
6380 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
6382 // TOCHECK: Why is this here?
6383 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
6384 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
6386 this.visible = false;
6387 style.hidden = true;
6390 // autoCreate = true;
6398 if(parent == guiApp.desktop)
6399 Log("LoadGraphics %s\n", caption);
6401 if(LoadGraphics(true, false))
6409 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6416 if(style.hasMenuBar /*&& menu*/)
6422 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6423 interim = false, inactive = true, nonClient = true, size.h = 24
6431 // Create the system buttons
6432 CreateSystemChildren();
6434 UpdateActiveDocument(null);
6436 if(style.isDocument)
6440 MenuItem item = menu.FindItem(MenuFileSave, 0);
6441 if(item) item.disabled = !modifiedDocument && fileName;
6446 if(parent == guiApp.desktop)
6447 Log("Preemptive SetState %s\n", caption);
6450 // Preemptive Set State to ensure proper anchoring
6451 SetStateEx(state, false);
6453 style.hidden = true;
6459 for(child = children.first; child; child = next)
6462 if(!child.created && (child.autoCreate || child.wasCreated))
6469 for(link = slaves.first; link; link = next)
6471 Window slave = link.data;
6473 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6476 // Things might have happened that invalidated 'next'...
6477 // Start over the search for slaves to create.
6478 // (Added this to fix crash with Stacker & Toolbar)
6479 next = slaves.first;
6488 if(parent == guiApp.desktop)
6489 Log("Real SetState %s\n", caption);
6492 if(isActiveClient && visible)
6494 parent.numPositions--;
6495 if(state == minimized) parent.numIcons--;
6498 parent.OnChildAddedOrRemoved(this, false);
6500 if(rootWindow == this && visible) // So that X11 windows don't show as 'unknown'
6502 // Real set state & activate for proper display & activation
6503 property::visible = visible;
6504 // SetState(state & 0x00000003, true, 0);
6505 guiApp.interfaceDriver.SetIcon(this, icon);
6510 /*if(rootWindow == this)
6511 guiApp.interfaceDriver.ActivateRootWindow(this);
6513 if(creationActivation == activate && guiApp.desktop.active)
6514 ActivateEx(true, false, true, true, null, null);
6515 else if(creationActivation == activate || creationActivation == flash)
6518 if(this == rootWindow)
6524 rootWindow.ConsequentialMouseMove(false);
6535 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6541 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6543 //style.hidden = true; // !visible;
6544 style.hidden = !visible;
6545 if(master.modalSlave == this)
6546 master.modalSlave = null;
6553 void WriteCaption(Surface surface, int x, int y)
6556 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6559 void Update(Box region)
6565 rootWindow = this.rootWindow;
6567 // rootWindow.mutex.Wait();
6568 if(!destroyed && visible && display)
6573 // Testing this to avoid repetitve full update to take time...
6574 if(rootWindow.fullRender)
6576 rootWindow.dirty = true;
6579 if(dirtyArea.count == 1)
6581 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6582 if(item.box.left <= box.left &&
6583 item.box.top <= box.top &&
6584 item.box.right >= box.right &&
6585 item.box.bottom >= box.bottom)
6587 rootWindow.dirty = true;
6592 if(display.flags.flipping && !rootWindow.dirty)
6594 if(this == rootWindow)
6598 rootWindow.Update(null);
6603 rootWindow.dirty = true;
6608 realBox.left += clientStart.x;
6609 realBox.top += clientStart.y;
6610 realBox.right += clientStart.x;
6611 realBox.bottom += clientStart.y;
6617 if(realBox.right >= realBox.left &&
6618 realBox.bottom >= realBox.top)
6620 // if(!rootWindow.fullRender)
6621 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6623 for(child = children.first; child; child = child.next)
6628 box.left -= child.absPosition.x - absPosition.x;
6629 box.top -= child.absPosition.y - absPosition.y;
6630 box.right -= child.absPosition.x - absPosition.x;
6631 box.bottom -= child.absPosition.y - absPosition.y;
6632 if(box.right >= child.box.left && box.left <= child.box.right &&
6633 box.bottom >= child.box.top && box.top <= child.box.bottom)
6635 box.left -= child.clientStart.x;
6636 box.top -= child.clientStart.y;
6637 box.right -= child.clientStart.x;
6638 box.bottom -= child.clientStart.y;
6644 realBox.left += absPosition.x - rootWindow.absPosition.x;
6645 realBox.top += absPosition.y - rootWindow.absPosition.y;
6646 realBox.right += absPosition.x - rootWindow.absPosition.x;
6647 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6648 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6651 else if(this == guiApp.desktop)
6654 for(window = children.first; window; window = window.next)
6660 Box childBox = region;
6662 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6663 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6664 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6665 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6667 window.Update(childBox);
6670 window.Update(null);
6675 // rootWindow.mutex.Release();
6682 if(guiApp.windowCaptured != this)
6684 if(guiApp.windowCaptured)
6688 //Logf("Captured %s (%s)\n", caption, class.name);
6689 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6690 guiApp.windowCaptured = this;
6696 bool Destroy(int64 code)
6701 if(!destroyed && !CloseConfirmation(false)) return false;
6705 // TOCHECK: Should autoCreate be set to false here?
6716 void Move(int x, int y, int w, int h)
6718 normalAnchor = Anchor { left = x, top = y };
6719 normalSizeAnchor = SizeAnchor { size = { w, h } };
6721 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6723 if(destroyed) return;
6725 stateAnchor = normalAnchor;
6726 stateSizeAnchor = normalSizeAnchor;
6728 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6729 Position(x,y, w, h, true, true, true, true, false, true);
6733 DialogResult Modal(void)
6739 // FIXES MEMORY LEAK IF Create() FAILED
6745 void SetScrollArea(int width, int height, bool snapToStep)
6749 int stepX = sbStep.x, stepY = sbStep.y;
6750 // Needed to make snapped down position match the skin's check of client area
6751 // against realvirtual
6754 SNAPDOWN(stepX, textCellW);
6755 SNAPDOWN(stepY, textCellH);
6756 stepX = Max(stepX, textCellW);
6757 stepY = Max(stepY, textCellH);
6759 if(scrollFlags.snapX)
6760 SNAPUP(width, stepX);
6761 if(scrollFlags.snapY)
6762 SNAPUP(height, stepY);
6765 reqScrollArea.w = width;
6766 reqScrollArea.h = height;
6767 noAutoScrollArea = (width > 0 || height > 0);
6769 UpdateScrollBars(true, true);
6772 void SetScrollPosition(int x, int y)
6775 sbh.Action(setPosition, x, 0);
6779 int seen = clientSize.w, total = reqScrollArea.w;
6781 if(scrollFlags.snapX)
6782 SNAPDOWN(seen, sbStep.x);
6784 if(!total) total = seen;
6785 range = total - seen + 1;
6786 range = Max(range, 1);
6788 if(x >= range) x = range - 1;
6790 if(scrollFlags.snapX)
6791 SNAPUP(x, sbStep.x);
6794 OnHScroll(setPosition, x, 0);
6798 SNAPDOWN(x, textCellW);
6804 sbv.Action(setPosition, y, 0);
6808 int seen = clientSize.h, total = reqScrollArea.h;
6811 if(scrollFlags.snapY)
6812 SNAPDOWN(seen, sbStep.y);
6814 if(!total) total = seen;
6815 range = total - seen + 1;
6816 range = Max(range, 1);
6818 if(y >= range) y = range - 1;
6820 if(scrollFlags.snapY)
6821 SNAPUP(y, sbStep.y);
6824 OnVScroll(setPosition, y, 0);
6827 SNAPDOWN(y, textCellH);
6832 UpdateCaret(false, false);
6835 void SetScrollLineStep(int stepX, int stepY)
6841 SNAPDOWN(stepX, textCellW);
6842 SNAPDOWN(stepY, textCellH);
6843 stepX = Max(stepX, textCellW);
6844 stepY = Max(stepY, textCellH);
6847 sbh.lineStep = stepX;
6849 sbv.lineStep = stepY;
6852 void SetState(WindowState newState, bool activate, Modifiers mods)
6856 if(state == newState || OnStateChange(newState, mods))
6858 //WindowState prevState = state;
6862 // This used to be at the end of the brackets... moved for X, testing...
6863 // This has the effect of activating the window through the system...
6864 if(rootWindow == this)
6865 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6867 SetStateEx(newState, activate);
6869 if(rootWindow == this && !rootWindow.nativeDecorations)
6871 int x = position.x, y = position.y;
6874 x -= guiApp.desktop.absPosition.x;
6875 y -= guiApp.desktop.absPosition.y;
6877 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6881 //state = prevState;
6883 if(state != maximized && style.hasMaximize)
6886 for(child = parent.children.first; child; child = child.next)
6888 if(child != this && child.state == maximized)
6889 child.SetStateEx(normal, false);
6893 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6894 parent.UpdateScrollBars(true, true);
6897 // Do we really need this stuff here?
6898 // Shouldn't the Activate stuff take care of it?
6899 if(parent.rootWindow == parent && style)
6902 parent.FigureCaption(caption);
6903 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6904 parent.UpdateDecorations();
6908 rootWindow.ConsequentialMouseMove(false);
6915 BitmapResource GetIcon(SkinBitmap iconID)
6917 return guiApp.currentSkin.GetBitmap(iconID);
6920 void SetMouseRange(Box range)
6922 if(range || guiApp.fullScreenMode)
6927 clip.left = range.left + absPosition.x + clientStart.x;
6928 clip.top = range.top + absPosition.y + clientStart.y;
6929 clip.right = range.right + absPosition.x + clientStart.x;
6930 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6934 clip.left = guiApp.desktop.box.left;
6935 clip.top = guiApp.desktop.box.top;
6936 clip.right = guiApp.desktop.box.right;
6937 clip.bottom = guiApp.desktop.box.bottom;
6939 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6942 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6945 void SetMouseRangeToClient(void)
6947 if(guiApp.fullScreenMode || this != guiApp.desktop)
6949 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6950 box.Clip(clientArea);
6954 SetMouseRange(null);
6957 void SetMouseRangeToWindow(void)
6959 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6960 if(this == guiApp.desktop)
6961 SetMouseRangeToClient();
6966 // x, y: Desktop Coordinates
6967 void ShowSysMenu(int x, int y)
6970 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6973 menu, $"Restore", r, NotifySelect = MenuWindowRestore,
6974 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6978 menu, $"Move", m, NotifySelect = MenuWindowMove,
6979 disabled = !style.fixed || state == maximized
6983 menu, $"Size", s, NotifySelect = MenuWindowSize,
6984 disabled = !style.sizable || state != normal
6988 menu, $"Minimize", n, NotifySelect = MenuWindowMinimize,
6989 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6993 menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6994 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6998 menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6999 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
7001 MenuDivider { menu };
7004 menu, $"Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
7005 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
7007 windowMenu.Create();
7012 ActivateEx(true, true, true, true, null, null);
7015 void MakeActive(void)
7017 ActivateEx(true, false, true, false, null, null);
7020 void SoftActivate(void)
7022 if(guiApp.desktop.active)
7027 if(this == rootWindow)
7032 void Deactivate(void)
7034 ActivateEx(false, true, true, true, null, null);
7039 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
7042 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
7044 bool result = false;
7045 if(activeChild && activeChild.cycle)
7047 Window modalWindow, child = activeChild;
7048 if(!clientOnly /*&& parent.tabCycle*/)
7050 Window next = child;
7053 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
7057 if(parent && parent.CycleChildren(backward, false, true, true))
7065 next = next.cycle.prev.data;
7067 next = next.cycle.next.data;
7068 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
7073 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
7074 parent.tabCycle && parent.CycleChildren(backward, false, false))
7078 if(tabCycleOnly && !tabCycle) return false;
7085 child = child.cycle.prev.data;
7087 child = child.cycle.next.data;
7088 if(child == child.parent.activeChild)
7090 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
7093 modalWindow = child.FindModal();
7096 // Scroll the window to include the active control
7097 if(sbh && !child.style.dontScrollHorz)
7099 if(child.scrolledPos.x < 0)
7100 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
7101 else if(child.scrolledPos.x + child.size.w > clientSize.w)
7102 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
7104 if(sbv && !child.style.dontScrollVert)
7106 if(child.scrolledPos.y < 0)
7107 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
7108 else if(child.scrolledPos.y + child.size.h > clientSize.h)
7109 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
7113 child = modalWindow ? modalWindow : child;
7114 child.ActivateEx(true, true, true, true, null, null);
7115 if(child.tabCycle && child.childrenCycle.first)
7116 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
7124 ConsequentialMouseMove(false);
7128 void AddResource(Resource resource)
7132 ResPtr ptr { resource = resource };
7136 // Load Graphics here if window is created already
7137 if(/*created && */display)
7139 display.Lock(false);
7140 if(!ptr.loaded) // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
7141 ptr.loaded = display.displaySystem.LoadResource(resource);
7145 // Temporary hack to load font right away for listbox in dropbox ...
7146 else if(master && master.display)
7148 master.display.Lock(false);
7149 master.display.displaySystem.LoadResource(resource);
7150 master.display.Unlock();
7156 void RemoveResource(Resource resource)
7161 for(ptr = resources.first; ptr; ptr = ptr.next)
7163 if(ptr.resource == resource)
7169 // Unload Graphics here if window is created already
7170 if(/*created && */display)
7174 display.Lock(false);
7175 display.displaySystem.UnloadResource(resource, ptr.loaded);
7181 resources.Delete(ptr);
7186 void SetCaret(int x, int y, int size)
7193 if(active && !style.interim && isEnabled)
7195 if(visible || !guiApp.caretOwner)
7196 guiApp.caretOwner = size ? this : null;
7198 UpdateCaret(false, false);
7201 guiApp.interfaceDriver.SetCaret(0,0,0);
7202 UpdateCaret(false, true);
7203 guiApp.caretEnabled = false;
7206 else if(style.inactive && active)
7208 guiApp.interfaceDriver.SetCaret(0,0,0);
7209 UpdateCaret(false, true);
7210 guiApp.caretEnabled = false;
7215 void Scroll(int x, int y)
7217 bool opaque = !style.drawBehind || background.a;
7218 if(opaque && display && display.flags.scrolling)
7220 Box box = clientArea;
7221 box.left += clientStart.x;
7222 box.top += clientStart.y;
7223 box.right += clientStart.x;
7224 box.bottom += clientStart.y;
7226 //scrollExtent.Free(null);
7227 scrollExtent.AddBox(box);
7228 scrolledArea.x += x;
7229 scrolledArea.y += y;
7231 //scrollExtent.Free();
7232 //scrollExtent.AddBox(clientArea);
7233 //scrollExtent.Offset(clientStart.x, clientStart.y);
7234 //scrolledArea.x = x;
7235 //scrolledArea.y = y;
7241 rootWindow.dirty = true;
7244 void ReleaseCapture()
7246 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
7248 Window oldCaptured = guiApp.windowCaptured;
7249 guiApp.windowCaptured = null;
7250 guiApp.prevWindow = null;
7253 //guiApp.Log("Released Capture\n");
7255 guiApp.interfaceDriver.SetMouseCapture(null);
7257 //oldCaptured.OnMouseCaptureLost();
7260 oldCaptured.ConsequentialMouseMove(false);
7265 private void _SetCaption(const char * format, va_list args)
7272 char caption[MAX_F_STRING];
7273 vsnprintf(caption, sizeof(caption), format, args);
7274 caption[sizeof(caption)-1] = 0;
7276 this.caption = CopyString(caption);
7281 firewatchers caption;
7285 /*deprecated*/ void SetText(const char * format, ...)
7288 va_start(args, format);
7289 _SetCaption(format, args);
7293 void SetCaption(const char * format, ...)
7296 va_start(args, format);
7297 _SetCaption(format, args);
7301 bool Grab(Bitmap bitmap, Box box, bool decorations)
7303 bool result = false;
7304 if(display || this == guiApp.desktop)
7306 Box clip = {MININT, MININT, MAXINT, MAXINT};
7312 clip.Clip(clientArea);
7314 clip.Clip(this.box);
7316 if(rootWindow != this)
7318 clip.left += absPosition.y;
7319 clip.top += absPosition.y;
7320 clip.right += absPosition.x;
7321 clip.bottom += absPosition.y;
7324 clip.left += decorations ? 0 : clientStart.x;
7325 clip.top += decorations ? 0 : clientStart.y;
7326 clip.right += decorations ? 0 : clientStart.x;
7327 clip.bottom += decorations ? 0 : clientStart.y;
7329 if(display && display.flags.flipping)
7331 rootWindow.Update(null);
7332 rootWindow.UpdateDisplay();
7339 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
7340 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7344 result = display.Grab(bitmap, clip.left, clip.top,
7345 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7347 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
7349 if(!bitmap.Convert(null, pixelFormat888, null))
7356 void GetMousePosition(int * x, int * y)
7358 int mouseX = 0, mouseY = 0;
7359 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
7362 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
7363 if(this != guiApp.desktop)
7365 mouseX -= absPosition.x + clientStart.x;
7366 mouseY -= absPosition.y + clientStart.y;
7373 DialogResult DoModal()
7375 DialogResult returnCode = 0;
7376 int terminated = terminateX;
7379 while(!destroyed && guiApp.driver != null)
7381 if(terminateX != terminated)
7383 terminated = terminateX;
7384 guiApp.desktop.Destroy(0);
7385 if(guiApp.desktop.created)
7388 //printf("Resetting terminate X to 0\n");
7394 guiApp.UpdateDisplay();
7395 if(!guiApp.ProcessInput(false))
7398 returnCode = this.returnCode;
7411 return !destroyed && guiApp.driver != null && terminateX < 2;
7414 DialogResult DoModalEnd()
7416 DialogResult returnCode = this.returnCode;
7421 // --- Window manipulation ---
7422 /*bool GetDisabled()
7424 bool disabled = this.disabled;
7426 for(window = this; (window = window.master); )
7437 // --- Mouse Manipulation ---
7438 void GetNCMousePosition(int * x, int * y)
7440 GetMousePosition(x, y);
7441 if(x) *x += clientStart.x;
7442 if(y) *y += clientStart.y;
7445 // --- Carets manipulation ---
7446 void GetCaretPosition(Point caretPos)
7448 caretPos = this.caretPos;
7451 int GetCaretSize(void)
7456 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7462 bool CloseConfirmation(bool parentClosing)
7475 if(!OnClose(parentClosing))
7478 // If you want to skip this, simply set modifiedDocument to false in OnClose
7479 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7481 DialogResult dialogRes;
7484 sprintf(message, $"Save changes to %s?", fileName);
7486 sprintf(message, $"Save changes to Untitled %d?", documentID);
7488 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = message }.Modal();
7490 if(dialogRes == yes)
7492 // TOFIX: Precomp error if brackets are taken out
7493 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7495 else if(dialogRes == cancel)
7501 for(slave = slaves.first; slave; slave = slave.next)
7503 Window w = slave.data;
7504 if(w.parent != this && !w.IsDescendantOf(this) && !w.CloseConfirmation(true))
7512 // Confirm closure of active clients first (We use OnClose() to hide instead of destroy in the IDE)
7515 for(child = children.first; child; child = child.next)
7516 if(child.isActiveClient && !child.CloseConfirmation(true))
7524 for(child = children.first; child; child = child.next)
7525 if(!child.isActiveClient && !child.CloseConfirmation(true))
7535 // Static methods... move them somewhere else?
7536 void ::RestoreCaret()
7538 if(guiApp.caretOwner)
7539 guiApp.caretOwner.UpdateCaret(false, false);
7542 void ::FreeMouseRange()
7544 guiApp.interfaceDriver.SetMouseRange(null, null);
7548 bool MenuFileClose(MenuItem selection, Modifiers mods)
7550 Window document = activeChild;
7552 document.Destroy(0);
7556 bool MenuFileExit(MenuItem selection, Modifiers mods)
7562 bool MenuFileSave(MenuItem selection, Modifiers mods)
7567 #if !defined(__EMSCRIPTEN__)
7568 fileMonitor.fileName = null;
7572 if(OnSaveFile(fileName))
7574 //if(OnFileModified != Window::OnFileModified)
7577 #if !defined(__EMSCRIPTEN__)
7578 fileMonitor.fileName = fileName;
7585 MessageBox dialog { master = master, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7586 DialogResult answer = dialog.Modal();
7588 if(answer != yes) return (bool)answer;
7591 return MenuFileSaveAs(selection, mods);
7594 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7596 DialogResult result = (DialogResult)bool::true;
7597 FileDialog fileDialog = saveDialog;
7602 fileDialog = FileDialog {};
7607 fileDialog.filePath = fileName;
7610 char filePath[MAX_FILENAME];
7611 sprintf(filePath, "Untitled %d", documentID);
7612 fileDialog.filePath = filePath;
7614 #if !defined(__EMSCRIPTEN__)
7615 fileMonitor.fileName = null;
7618 fileDialog.type = save;
7619 fileDialog.text = $"Save As";
7623 fileDialog.master = master.parent ? master : this;
7624 if(fileDialog.Modal() == ok)
7626 const char * filePath = fileDialog.filePath;
7628 if(OnSaveFile(filePath))
7631 property::fileName = filePath;
7632 NotifySaved(master, this, filePath);
7637 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7638 DialogResult answer = dialog.Modal();
7653 #if !defined(__EMSCRIPTEN__)
7654 //if(OnFileModified != Window::OnFileModified && fileName)
7657 fileMonitor.fileName = fileName;
7662 return (bool)result; // Actually returning result from Yes/NoCancel message box
7665 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7667 Window document = activeChild;
7669 for(document = children.first; document; document = next)
7671 next = document.next;
7672 if(document.style.isDocument || document.fileName)
7673 document.MenuFileSave(selection, mods);
7678 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7682 for(document = children.first; document; document = document.next)
7683 //if(document.style.isDocument && document.state == minimized)
7684 if(document.style.isActiveClient && document.state == minimized)
7685 document.SetState(minimized, false, mods);
7689 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7691 Window document = activeChild;
7694 Window firstDocument = null;
7696 OldLink cycle = document.cycle.prev;
7701 if(child.style.isActiveClient && !child.style.hidden)
7705 firstDocument = child;
7706 if(child.state == minimized)
7707 child.SetState(minimized, false, mods);
7710 child.positionID = id++;
7711 child.SetState(normal, false, mods);
7712 child.anchor.left.type = cascade;
7715 child.normalSizeAnchor = *&child.sizeAnchor;
7716 child.normalAnchor = child.anchor;
7718 // Break the anchors for moveable/resizable windows
7719 if(child.style.fixed)
7721 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7723 (*&child.normalAnchor).left = x;
7724 (*&child.normalAnchor).top = y;
7725 (*&child.normalAnchor).right.type = none;
7726 (*&child.normalAnchor).bottom.type = none;
7728 (*&child.normalSizeAnchor).isClientW = false;
7729 (*&child.normalSizeAnchor).isClientH = false;
7730 (*&child.normalSizeAnchor).size.w = w;
7731 (*&child.normalSizeAnchor).size.h = h;
7732 child.anchored = false;
7735 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7737 child.stateAnchor = child.normalAnchor;
7738 child.stateSizeAnchor = child.normalSizeAnchor;
7740 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7741 child.Position(x, y, w, h, true, true, true, true, false, false);
7746 last = children.last;
7747 if(!child.style.stayOnTop)
7748 for(; last && last.style.stayOnTop; last = last.prev);
7749 children.Move(child, last);
7750 childrenOrder.Move(child.order, childrenOrder.last);
7752 if(cycle == document.cycle) break;
7756 firstDocument.Activate();
7761 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7768 // Close all closes all active clients, not all documents
7769 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7771 Window next, document;
7773 for(document = children.first; document; document = next)
7775 for(next = document.next; next && !next.style.isActiveClient; next = next.next);
7776 if(document.style.isActiveClient)
7777 if(!document.Destroy(0) && !document.style.hidden)
7783 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7785 if(style.hasMaximize && state != maximized)
7786 SetState(maximized, 0, 0);
7790 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7792 if(style.hasMinimize && state != minimized)
7794 SetState(minimized, 0, 0);
7795 parent.CycleChildren(false, true, false, true);
7800 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7802 MenuMoveOrSize(false, selection ? true : false);
7806 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7808 CycleChildren(false, true, false, true);
7812 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7814 CycleChildren(true, true, false, true);
7818 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7820 MenuMoveOrSize(true, true);
7824 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7827 SetState(normal, 0, 0);
7831 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7834 int64 id = selection.id;
7835 OldLink cycle = activeClient.cycle;
7837 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7840 Window sibling = cycle.data;
7841 if(sibling.style.isActiveClient && sibling.visible && !sibling.style.nonClient)
7849 document = cycle.data;
7850 document.Activate();
7852 //if(activeChild.state == maximized)
7853 // document.SetState(maximized, false, mods);
7854 //else if(document.state == minimized)
7855 // document.SetState(normal, false, mods);
7859 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7861 stayOnTop = !style.stayOnTop;
7865 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7867 Window document = activeChild;
7870 Window firstDocument = null;
7871 OldLink cycle = document.cycle;
7875 Window child = cycle.data;
7876 if(child.style.isActiveClient && !child.style.hidden)
7878 if(!firstDocument) firstDocument = child;
7879 if(child.state == minimized)
7880 child.SetState(minimized, false, mods);
7883 child.positionID = id++;
7884 child.SetState(normal, false, mods);
7885 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7887 child.anchor.left.type = hTiled;
7890 child.normalSizeAnchor = *&child.sizeAnchor;
7891 child.normalAnchor = child.anchor;
7893 // Break the anchors for moveable/resizable windows
7894 if(child.style.fixed)
7896 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7898 (*&child.normalAnchor).left = x;
7899 (*&child.normalAnchor).top = y;
7900 (*&child.normalAnchor).right.type = none;
7901 (*&child.normalAnchor).bottom.type = none;
7902 (*&child.normalSizeAnchor).isClientW = false;
7903 (*&child.normalSizeAnchor).isClientH = false;
7904 (*&child.normalSizeAnchor).size.w = w;
7905 (*&child.normalSizeAnchor).size.h = h;
7906 child.anchored = false;
7909 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7911 child.stateAnchor = child.normalAnchor;
7912 child.stateSizeAnchor = child.normalSizeAnchor;
7914 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7915 child.Position(x,y, w, h, true, true, true, true, false, true);
7920 if((cycle = cycle.next) == document.cycle) break;
7923 firstDocument.Activate();
7928 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7930 Window document = activeChild;
7933 Window firstDocument = null;
7935 OldLink cycle = document.cycle;
7940 //if(child.style.isDocument)
7941 if(child.style.isActiveClient && !child.style.hidden)
7943 if(!firstDocument) firstDocument = child;
7944 if(child.state == minimized)
7945 child.SetState(minimized, false, mods);
7948 child.positionID = id++;
7949 child.SetState(normal, false, mods);
7950 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7952 child.anchor.left.type = vTiled;
7955 child.normalSizeAnchor = *&child.sizeAnchor;
7956 child.normalAnchor = child.anchor;
7958 // Break the anchors for moveable/resizable windows
7959 if(child.style.fixed)
7961 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7963 (*&child.normalAnchor).left = x;
7964 (*&child.normalAnchor).top = y;
7965 (*&child.normalAnchor).right.type = none;
7966 (*&child.normalAnchor).bottom.type = none;
7967 (*&child.normalSizeAnchor).isClientW = false;
7968 (*&child.normalSizeAnchor).isClientH = false;
7969 (*&child.normalSizeAnchor).size.w = w;
7970 (*&child.normalSizeAnchor).size.h = h;
7971 child.anchored = false;
7974 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7976 child.stateAnchor = child.normalAnchor;
7977 child.stateSizeAnchor = child.normalSizeAnchor;
7979 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7980 child.Position(x,y, w, h, true, true, true, true, false, true);
7985 if((cycle = cycle.next) == document.cycle) break;
7988 firstDocument.Activate();
7993 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7997 master = this; isModal = true;
7999 void NotifyDestroyed(Window window, DialogResult result)
8001 Window document = (Window)(intptr)result;
8004 if(activeChild.state == maximized)
8005 document.SetState(maximized, false, 0);
8006 else if(document.state == minimized)
8007 document.SetState(normal, false, 0);
8008 document.Activate();
8016 virtual bool OnCreate(void);
8017 virtual void OnDestroy(void);
8018 virtual void OnDestroyed(void);
8019 virtual bool OnClose(bool parentClosing);
8020 virtual bool OnStateChange(WindowState state, Modifiers mods);
8021 virtual bool OnPostCreate(void);
8022 virtual bool OnMoving(int *x, int *y, int w, int h);
8023 virtual bool OnResizing(int *width, int *height);
8024 virtual void OnResize(int width, int height);
8025 virtual void OnPosition(int x, int y, int width, int height);
8026 virtual bool OnLoadGraphics(void);
8027 virtual void OnApplyGraphics(void);
8028 virtual void OnUnloadGraphics(void);
8029 virtual void OnRedraw(Surface surface);
8030 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
8031 virtual void OnActivateClient(Window client, Window previous);
8032 virtual bool OnKeyDown(Key key, unichar ch);
8033 virtual bool OnKeyUp(Key key, unichar ch);
8034 virtual bool OnKeyHit(Key key, unichar ch);
8035 virtual bool OnSysKeyDown(Key key, unichar ch);
8036 virtual bool OnSysKeyUp(Key key, unichar ch);
8037 virtual bool OnSysKeyHit(Key key, unichar ch);
8038 virtual bool OnMouseOver(int x, int y, Modifiers mods);
8039 virtual bool OnMouseLeave(Modifiers mods);
8040 virtual bool OnMouseMove(int x, int y, Modifiers mods);
8041 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
8042 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
8043 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
8044 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
8045 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
8046 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
8047 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
8048 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
8049 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
8050 virtual bool OnMultiTouch(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods);
8051 virtual void OnMouseCaptureLost(void);
8052 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
8053 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
8054 virtual void OnDrawOverChildren(Surface surface);
8055 virtual bool OnFileModified(FileChange fileChange, const char * param);
8056 virtual bool OnSaveFile(const char * fileName);
8058 // Virtual Methods -- Children management (To support Stacker, for lack of built-in auto-layout)
8059 // Note: A 'client' would refer to isActiveClient, rather than
8060 // being confined to the 'client area' (nonClient == false)
8061 virtual void OnChildAddedOrRemoved(Window child, bool removed);
8062 virtual void OnChildVisibilityToggled(Window child, bool visible);
8063 virtual void OnChildResized(Window child, int x, int y, int w, int h);
8065 // Skins Virtual Functions
8066 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
8067 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
8068 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
8073 virtual void ShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
8074 virtual void PreShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
8075 virtual bool IsMouseMoving(int x, int y, int w, int h)
8079 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY)
8083 virtual void UpdateNonClient();
8084 virtual void SetBox(Box box); // This is used in the MySkin skin
8085 virtual bool IsInside(int x, int y)
8087 return box.IsPointInside({x, y});
8089 virtual bool IsOpaque()
8091 return (!style.drawBehind || background.a == 255);
8095 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
8096 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
8097 virtual void Window::NotifySaved(Window window, const char * filePath);
8102 property Window parent
8104 property_category $"Layout"
8107 if(value || guiApp.desktop)
8110 Window oldParent = parent;
8111 Anchor anchor = this.anchor;
8113 if(value && value.IsDescendantOf(this)) return;
8114 if(value && value == this)
8116 if(!value) value = guiApp.desktop;
8118 if(value == oldParent) return;
8120 if(!master || (master == this.parent && master == guiApp.desktop))
8121 property::master = value;
8125 parent.children.Remove(this);
8129 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
8130 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
8131 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
8132 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
8136 last = value.children.last;
8138 if(style.isDocument)
8141 parent.numDocuments--;
8142 documentID = value.GetDocumentID();
8145 if(style.isActiveClient && !style.hidden)
8147 if(parent && parent != guiApp.desktop && !(style.hidden))
8149 if(state == minimized) parent.numIcons--;
8150 parent.numPositions--;
8154 if(!style.stayOnTop)
8155 for(; last && last.style.stayOnTop; last = last.prev);
8157 value.children.Insert(last, this);
8159 // *** NEW HERE: ***
8161 parent.childrenCycle.Delete(cycle);
8163 parent.childrenOrder.Delete(order);
8166 // *** TODO: Added this here to solve crash on setting parent to null before destroying/destructing ***
8167 // Should something else be done?
8168 if(parent && parent.activeChild == this)
8169 parent.activeChild = null;
8170 if(parent && parent.activeClient == this)
8171 parent.activeClient = null;
8177 int x = position.x, y = position.y, w = size.w, h = size.h;
8181 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
8182 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
8184 vpw = value.clientSize.w;
8185 vph = value.clientSize.h;
8191 else if(style.fixed)
8193 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
8194 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
8197 anchor = this.anchor;
8199 if(anchor.left.type == offset) anchor.left.distance = x;
8200 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
8201 if(anchor.top.type == offset) anchor.top.distance = y;
8202 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
8203 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
8204 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
8205 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
8206 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
8207 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
8208 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
8210 if(!anchor.left.type && !anchor.right.type)
8212 anchor.horz.distance = (x + w / 2) - (vpw / 2);
8213 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
8215 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
8216 if(!anchor.top.type && !anchor.bottom.type)
8218 anchor.vert.distance = (y + h / 2) - (vph / 2);
8219 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
8221 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
8224 parent.OnChildAddedOrRemoved(this, false);
8230 parent.childrenCycle.Insert(
8231 // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
8232 //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8234 cycle = OldLink { data = this });
8235 parent.childrenOrder.Insert(
8236 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8237 order = OldLink { data = this });
8240 if(!style.hidden && style.isActiveClient)
8242 positionID = parent.GetPositionID(this);
8243 parent.numPositions++;
8244 if(state == minimized) parent.numIcons--;
8247 // *** FONT INHERITANCE ***
8248 if(!setFont && oldParent)
8249 stopwatching(oldParent, font);
8253 RemoveResource(systemFont);
8256 // TESTING WITH WATCHERS:
8257 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8258 // usedFont = setFont ? setFont : (systemFont);
8262 if(guiApp.currentSkin)
8264 systemFont = guiApp.currentSkin.SystemFont();
8267 usedFont = systemFont;
8268 AddResource(systemFont);
8276 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8285 if(value.rootWindow && value.rootWindow.display && rootWindow && created)
8287 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
8288 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
8291 UnloadGraphics(false);
8294 LoadGraphics(false, false);
8297 if(value.rootWindow != rootWindow)
8298 DisplayModeChanged();
8302 scrolledPos.x = MININT; // Prevent parent update
8304 bool anchored = this.anchored;
8305 property::anchor = anchor;
8306 this.anchored = anchored;
8311 if(guiApp.currentSkin)
8312 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
8314 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8315 Position(x, y, w, h, true, true, true, true, false, true);
8320 // else parent = value;
8322 oldParent.OnChildAddedOrRemoved(this, true);
8325 get { return parent; }
8328 property Window master
8330 property_category $"Behavior"
8333 //if(this == value) return;
8334 if(value && value.IsSlaveOf(this)) return;
8340 OldLink slaveHolder;
8341 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
8342 if(slaveHolder.data == this)
8344 master.slaves.Delete(slaveHolder);
8351 value.slaves.Add(OldLink { data = this });
8356 master.hotKeys.Remove(hotKey);
8357 value.hotKeys.Add(hotKey);
8360 if(master && master.defaultControl == this)
8361 master.defaultControl = null;
8363 if(style.isDefault && !value.defaultControl)
8364 value.defaultControl = this;
8369 get { return master ? master : parent; }
8372 property const char * caption
8374 property_category $"Appearance"
8381 caption = new char[strlen(value)+1];
8383 strcpy(caption, value);
8388 get { return caption; }
8393 property_category $"Behavior"
8402 master.hotKeys.Add(hotKey = HotKeySlot { });
8406 hotKey.window = this;
8411 master.hotKeys.Delete(hotKey);
8416 get { return hotKey ? hotKey.key : 0; }
8419 property Color background
8421 property_category $"Appearance"
8424 background.color = value;
8429 if(this == rootWindow)
8430 guiApp.interfaceDriver.SetRootWindowColor(this);
8433 get { return background.color; }
8436 property Percentage opacity
8438 property_category $"Appearance"
8441 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
8442 drawBehind = (background.a == 255) ? false : true;
8444 get { return background.a / 255.0f; }
8447 property Color foreground
8449 property_category $"Appearance"
8457 get { return foreground; }
8460 property BorderStyle borderStyle
8462 property_category $"Appearance"
8465 if(!((BorderBits)value).fixed)
8467 style.hasClose = false;
8468 style.hasMaximize = false;
8469 style.hasMinimize = false;
8470 nativeDecorations = false;
8472 style.borderBits = value;
8476 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8478 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8479 Position(x, y, w, h, true, true, true, true, false, true);
8480 CreateSystemChildren();
8483 get { return (BorderStyle)style.borderBits; }
8486 property Size minClientSize
8488 property_category $"Layout"
8489 set { minSize = value; }
8490 get { value = minSize; }
8493 property Size maxClientSize
8495 property_category $"Layout"
8496 set { maxSize = value; }
8497 get { value = maxSize; }
8500 property bool hasMaximize
8502 property_category $"Window Style"
8505 style.hasMaximize = value;
8506 if(value) { style.fixed = true; style.contour = true; }
8510 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8512 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8513 Position(x, y, w, h, true, true, true, true, false, true);
8515 CreateSystemChildren();
8518 get { return style.hasMaximize; }
8521 property bool hasMinimize
8523 property_category $"Window Style"
8526 style.hasMinimize = value;
8527 if(value) { style.fixed = true; style.contour = true; }
8531 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8533 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8534 Position(x, y, w, h, true, true, true, true, false, true);
8536 CreateSystemChildren();
8539 get { return style.hasMinimize; }
8542 property bool hasClose
8544 property_category $"Window Style"
8547 style.hasClose = value;
8548 if(value) { style.fixed = true; style.contour = true; }
8552 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8553 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8554 Position(x, y, w, h, true, true, true, true, false, true);
8555 CreateSystemChildren();
8558 get { return style.hasClose; }
8561 property bool nonClient
8563 property_category $"Layout"
8566 style.nonClient = value;
8568 style.stayOnTop = true;
8570 get { return style.nonClient; }
8573 property bool inactive
8575 property_category $"Behavior"
8580 // *** NEW HERE: ***
8584 parent.childrenCycle.Delete(cycle);
8586 parent.childrenOrder.Delete(order);
8593 active = false; // true;
8594 if(parent.activeChild == this)
8595 parent.activeChild = null;
8596 if(parent.activeClient == this)
8597 parent.activeClient = null;
8606 parent.childrenCycle.Insert(
8607 // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
8608 //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8610 cycle = OldLink { data = this });
8612 parent.childrenOrder.Insert(
8613 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8614 order = OldLink { data = this });
8617 style.inactive = value;
8619 get { return style.inactive; }
8622 property bool clickThrough
8624 property_category $"Behavior"
8625 set { style.clickThrough = value; }
8626 get { return style.clickThrough; }
8629 property bool isRemote
8631 property_category $"Behavior"
8632 set { style.isRemote = value; }
8633 get { return style.isRemote; }
8636 property bool noCycle
8638 property_category $"Behavior"
8639 set { style.noCycle = value; }
8640 get { return style.noCycle; }
8643 property bool isModal
8645 property_category $"Behavior"
8646 set { style.modal = value; }
8647 get { return style.modal; }
8650 property bool interim
8652 property_category $"Behavior"
8653 set { style.interim = value; }
8654 get { return style.interim; }
8657 property bool tabCycle
8659 property_category $"Behavior"
8660 set { style.tabCycle = value; }
8661 get { return style.tabCycle; }
8664 property bool isDefault
8666 property_category $"Behavior"
8674 for(sibling = parent.children.first; sibling; sibling = sibling.next)
8675 if(sibling != this && sibling.style.isDefault)
8676 sibling.style.isDefault = false;*/
8677 if(master.defaultControl)
8678 master.defaultControl.style.isDefault = false;
8679 master.defaultControl = this;
8681 else if(master.defaultControl == this)
8682 master.defaultControl = null;
8686 style.isDefault = value;
8688 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8690 get { return style.isDefault; }
8693 property bool drawBehind
8695 property_category $"Window Style"
8696 set { style.drawBehind = value; }
8697 get { return style.drawBehind; }
8700 property bool hasMenuBar
8702 property_category $"Window Style"
8712 if(created && !menuBar)
8719 anchor = Anchor { top = 23, left = 1, right = 1 },
8721 inactive = true, nonClient = true
8726 else if(created && menuBar)
8731 style.hasMenuBar = value;
8733 get { return style.hasMenuBar; }
8736 property bool hasStatusBar
8738 property_category $"Window Style"
8745 statusBar = StatusBar { this };
8753 style.hasStatusBar = value;
8755 get { return style.hasStatusBar; }
8757 property bool stayOnTop
8759 property_category $"Window Style"
8764 if(created && !style.stayOnTop)
8766 if(rootWindow == this)
8767 guiApp.interfaceDriver.OrderRootWindow(this, true);
8768 else if(parent.children.last != this)
8770 parent.children.Move(this, parent.children.last);
8774 style.stayOnTop = true;
8778 if(created && style.stayOnTop)
8780 if(rootWindow == this)
8781 guiApp.interfaceDriver.OrderRootWindow(this, false);
8788 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8789 order && ((Window)order.data).style.stayOnTop;
8790 order = (order == parent.childrenOrder.first) ? null : order.prev);
8791 last = order ? order.data : null;
8795 for(last = parent.children.last;
8796 last && last.style.stayOnTop;
8800 parent.children.Move(this, last);
8804 style.stayOnTop = false;
8807 get { return style.stayOnTop; }
8812 property_category $"Window Style"
8822 if(menuBar && !value)
8829 if(!menuBar && style.hasMenuBar && value)
8833 this, menu = value, isMenuBar = true,
8834 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8835 inactive = true, nonClient = true
8839 UpdateActiveDocument(null);
8842 get { return menu; }
8845 property FontResource font
8847 property_category $"Appearance"
8849 isset { return setFont ? true : false; }
8854 if(value && !setFont) { stopwatching(parent, font); }
8855 else if(!value && setFont)
8861 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8870 RemoveResource(setFont);
8875 RemoveResource(systemFont);
8882 AddResource(setFont);
8885 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8888 systemFont = guiApp.currentSkin.SystemFont();
8890 usedFont = systemFont;
8891 AddResource(systemFont);
8899 get { return usedFont; }
8902 property SizeAnchor sizeAnchor
8904 property_category $"Layout"
8907 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8908 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8909 sizeAnchor.isClientW != sizeAnchor.isClientH;
8916 normalSizeAnchor = sizeAnchor;
8918 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8920 stateAnchor = normalAnchor;
8921 stateSizeAnchor = normalSizeAnchor;
8923 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8924 Position(x,y, w, h, true, true, true, true, false, true);
8931 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8932 sizeAnchor.isClientW,
8933 sizeAnchor.isClientH
8940 property_category $"Layout"
8943 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8944 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8945 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8951 sizeAnchor.isClientW = false;
8952 sizeAnchor.isClientH = false;
8953 sizeAnchor.size = value;
8955 normalSizeAnchor = sizeAnchor;
8957 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8959 stateAnchor = normalAnchor;
8960 stateSizeAnchor = normalSizeAnchor;
8962 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8963 Position(x, y, w, h, true, true, true, true, false, true);
8964 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
8967 get { value = size; }
8970 property Size clientSize
8972 property_category $"Layout"
8975 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8976 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8977 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8982 sizeAnchor.isClientW = true;
8983 sizeAnchor.isClientH = true;
8984 sizeAnchor.size = value;
8986 normalSizeAnchor = sizeAnchor;
8988 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8990 stateAnchor = normalAnchor;
8991 stateSizeAnchor = normalSizeAnchor;
8993 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8994 Position(x,y, w, h, true, true, true, true, false, true);
8995 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
8998 get { value = this ? clientSize : { 0, 0 }; }
9001 property Size initSize { get { value = sizeAnchor.size; } };
9003 property Anchor anchor
9005 property_category $"Layout"
9006 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
9012 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
9014 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
9015 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
9017 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
9019 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
9020 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
9024 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
9026 anchor.left.distance = 0;
9027 anchor.horz.type = 0;
9029 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
9031 anchor.top.distance = 0;
9032 anchor.vert.type = 0;
9041 normalAnchor = anchor;
9043 // Break the anchors for moveable/resizable windows
9044 /*if(style.fixed ) //&& value.left.type == cascade)
9046 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
9048 this.anchor = normalAnchor = Anchor { left = x, top = y };
9049 normalSizeAnchor = SizeAnchor { { w, h } };
9052 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9054 stateAnchor = normalAnchor;
9055 stateSizeAnchor = normalSizeAnchor;
9057 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9058 Position(x, y, w, h, true, true, true, true, false, true);
9067 get { value = this ? anchor : Anchor { }; }
9070 property Point position
9072 property_category $"Layout"
9075 if(value == null) return;
9077 anchor.left = value.x;
9078 anchor.top = value.y;
9079 anchor.right.type = none;
9080 anchor.bottom.type = none;
9085 normalAnchor = anchor;
9087 // Break the anchors for moveable/resizable windows
9091 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9093 normalAnchor.left = x;
9094 normalAnchor.top = y;
9095 normalAnchor.right.type = none;
9096 normalAnchor.bottom.type = none;
9097 normalSizeAnchor.size.width = w;
9098 normalSizeAnchor.size.height = h;
9102 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9104 stateAnchor = normalAnchor;
9105 stateSizeAnchor = normalSizeAnchor;
9107 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9108 Position(x,y, w, h, true, true, true, true, false, true);
9112 get { value = position; }
9115 property bool disabled
9117 property_category $"Behavior"
9120 if(this && disabled != value)
9127 get { return (bool)disabled; }
9130 property bool isEnabled
9135 for(parent = this; parent; parent = parent.parent)
9142 property WindowState state
9144 property_category $"Behavior"
9145 set { SetState(value, false, 0); }
9146 get { return this ? state : 0; }
9149 property bool visible
9151 property_category $"Behavior"
9154 if(this && !value && !style.hidden && parent)
9156 bool wasActiveChild = parent.activeChild == this;
9157 Window client = null;
9159 style.hidden = true;
9160 if(style.isActiveClient)
9162 parent.numPositions--;
9163 if(state == minimized) parent.numIcons--;
9168 OldLink prevOrder = null;
9170 if(rootWindow == this)
9171 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
9174 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
9177 box.left -= parent.clientStart.x;
9178 box.top -= parent.clientStart.y;
9179 box.right -= parent.clientStart.x;
9180 box.bottom -= parent.clientStart.y;
9184 if(_isModal && master && master.modalSlave == this)
9185 master.modalSlave = null;
9189 OldLink tmpPrev = order.prev;
9190 client = tmpPrev ? tmpPrev.data : null;
9191 if(client && !client.style.hidden && !client.destroyed && client.created)
9192 prevOrder = tmpPrev;
9195 client = tmpPrev ? tmpPrev.data : null;
9196 if(client == this) { client = null; break; }
9197 if(client && ((client.style.hidden) || client.destroyed || !client.created))
9199 tmpPrev = client.order.prev;
9204 prevOrder = tmpPrev;
9209 // If this window can be an active client, make sure the next window we activate can also be one
9210 if(!style.nonClient && style.isActiveClient)
9212 tmpPrev = prevOrder;
9215 client = tmpPrev ? tmpPrev.data : null;
9216 if(client == this) { client = null; break; }
9217 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
9219 tmpPrev = client.order.prev;
9224 prevOrder = tmpPrev;
9228 if(client && client.style.hidden) client = null;
9232 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
9234 if(order && prevOrder && prevOrder.data != this)
9235 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
9237 ActivateEx(false, false, false, true, null, null);
9239 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
9240 if(parent.activeClient == this)
9242 parent.activeClient = null;
9243 parent.UpdateActiveDocument(null);
9246 else if(parent.activeClient == this)
9248 parent.activeClient = client;
9249 parent.UpdateActiveDocument(this);
9252 // *** Not doing this anymore ***
9255 parent.childrenCycle.Delete(cycle);
9257 parent.childrenOrder.Delete(order);
9262 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9267 else if(this && value && style.hidden)
9269 style.hidden = false;
9272 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9273 if(rootWindow == this)
9274 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
9276 if(_isModal && master)
9277 master.modalSlave = this;
9279 if(style.isActiveClient)
9281 positionID = parent.GetPositionID(this);
9282 parent.numPositions++;
9283 if(state == minimized) parent.numIcons++;
9286 // *** NOT DOING THIS ANYMORE ***
9288 if(!(style.inactive))
9290 if(!(style.noCycle))
9292 cycle = parent.childrenCycle.AddAfter(
9293 (parent.activeChild && parent.activeChild.cycle) ?
9294 parent.activeChild.cycle.prev : null, sizeof(OldLink));
9297 order = parent.childrenOrder.AddAfter(
9298 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
9305 if(true || !parent.activeChild)
9306 ActivateEx(true, false, true, true, null, null);
9308 if(creationActivation == activate && guiApp.desktop.active)
9309 ActivateEx(true, false, true, true, null, null);
9310 else if((creationActivation == activate || creationActivation == flash) && !object)
9313 if(this == rootWindow)
9317 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9321 ConsequentialMouseMove(false);
9327 style.hidden = !value;
9330 get { return (style.hidden || !setVisible) ? false : true; }
9333 property bool isDocument
9335 property_category $"Document"
9336 set { style.isDocument = value; if(value) SetupFileMonitor(); }
9337 get { return style.isDocument; }
9340 property bool mergeMenus
9342 property_category $"Window Style"
9343 set { mergeMenus = value; }
9344 get { return (bool)mergeMenus; }
9347 property bool hasHorzScroll
9349 property_category $"Window Style"
9354 if(!style.hasHorzScroll && created)
9356 CreateSystemChildren();
9357 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9360 else if(style.hasHorzScroll)
9364 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9366 style.hasHorzScroll = value;
9369 get { return style.hasHorzScroll; }
9372 property bool hasVertScroll
9374 property_category $"Window Style"
9379 if(!style.hasVertScroll && created)
9381 style.hasVertScroll = true;
9382 CreateSystemChildren();
9383 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9386 else if(style.hasVertScroll)
9390 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9392 style.hasVertScroll = value;
9394 get { return style.hasVertScroll; }
9397 property bool dontHideScroll
9399 property_category $"Behavior"
9402 scrollFlags.dontHide = value;
9405 //UpdateScrollBars(true, true);
9406 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9410 // UpdateScrollBars(true, true);
9411 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9414 get { return scrollFlags.dontHide; }
9417 property bool dontScrollVert
9419 property_category $"Behavior"
9420 set { style.dontScrollVert = value; }
9421 get { return style.dontScrollVert; }
9423 property bool dontScrollHorz
9425 property_category $"Behavior"
9426 set { style.dontScrollHorz = value; }
9427 get { return style.dontScrollHorz; }
9430 property bool snapVertScroll
9432 property_category $"Behavior"
9435 scrollFlags.snapY = value;
9436 if(sbv) sbv.snap = value;
9438 get { return scrollFlags.snapY; }
9440 property bool snapHorzScroll
9442 property_category $"Behavior"
9445 scrollFlags.snapX = value;
9446 if(sbh) sbh.snap = value;
9448 get { return scrollFlags.snapX; }
9451 property Point scroll
9453 property_category $"Behavior"
9454 set { if(this) SetScrollPosition(value.x, value.y); }
9455 get { value = scroll; }
9458 property bool modifyVirtualArea
9460 property_category $"Behavior"
9461 set { modifyVirtArea = value; }
9462 get { return (bool)modifyVirtArea; }
9465 property bool dontAutoScrollArea
9467 property_category $"Behavior"
9468 // Activating a child control out of view will automatically scroll to make it in view
9469 set { noAutoScrollArea = value; }
9470 get { return (bool)noAutoScrollArea; }
9473 property const char * fileName
9475 property_category $"Document"
9480 if(menu && ((!fileName && value) || (fileName && !value)))
9482 MenuItem item = menu.FindItem(MenuFileSave, 0);
9483 if(item) item.disabled = !modifiedDocument && value;
9488 if(value && value[0])
9489 fileName = CopyString(value);
9491 if(parent && this == parent.activeClient)
9492 parent.UpdateActiveDocument(null);
9496 // if(style.isDocument)
9497 #if !defined(__EMSCRIPTEN__)
9499 fileMonitor.fileName = value;
9502 get { return fileName; }
9507 property_category $"Data"
9512 property bool modifiedDocument
9514 property_category $"Document"
9517 if(style.isDocument || fileName)
9521 MenuItem item = menu.FindItem(MenuFileSave, 0);
9522 if(item) item.disabled = !value && fileName;
9526 if(modifiedDocument != value)
9528 modifiedDocument = value;
9529 if(style.isDocument || fileName)
9533 get { return (bool)modifiedDocument; }
9536 property bool showInTaskBar
9538 property_category $"Window Style"
9541 style.showInTaskBar = value;
9542 #if defined(__WIN32__)
9543 Win32UpdateStyle(this);
9546 get { return style.showInTaskBar; }
9548 property FileDialog saveDialog { set { saveDialog = value; } };
9549 property bool isActiveClient
9551 property_category $"Behavior"
9554 if(parent && style.isActiveClient != value && !style.hidden)
9558 if(state == minimized) parent.numIcons++;
9559 parent.numPositions++;
9563 if(state == minimized) parent.numIcons--;
9564 parent.numPositions--;
9567 style.isActiveClient = value;
9569 get { return style.isActiveClient; }
9572 property Cursor cursor
9574 property_category $"Appearance"
9578 SelectMouseCursor();
9580 get { return cursor; }
9583 //#if !defined(ECERE_VANILLA)
9584 property const char * name
9586 property_category $"Design"
9589 return (this && object) ? object.name : null;
9594 activeDesigner.RenameObject(object, value);
9598 property const char * displayDriver
9600 property_category $"Behavior"
9603 dispDriver = GetDisplayDriver(value);
9604 //DisplayModeChanged();
9608 return dispDriver ? dispDriver.name : null;
9612 // RUNTIME PROPERTIES
9613 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9614 property Size scrollArea
9616 property_category $"Behavior"
9620 SetScrollArea(value.w, value.h, false);
9622 SetScrollArea(0,0, true);
9624 get { value = scrollArea; }
9627 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9632 property_category $"Layout"
9633 set { if(this) is3D = value; }
9634 get { return (bool)is3D; }
9637 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9639 // Will be merged with font later
9640 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9641 property Point clientStart { get { value = clientStart; } };
9642 property Point absPosition { get { value = absPosition; } };
9643 property Anchor normalAnchor { get { value = normalAnchor; } };
9644 property SizeAnchor normalSizeAnchor { get { value = normalSizeAnchor; } };
9645 property bool active { get { return (bool)active; } };
9646 property bool created { get { return (bool)created; } };
9647 property bool destroyed { get { return (bool)destroyed; } };
9648 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9649 property Window firstChild { get { return children.first; } };
9650 property Window lastChild { get { return children.last; } };
9651 property Window activeClient { get { return activeClient; } };
9652 property Window activeChild { get { return activeChild; } };
9653 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9654 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9655 property ScrollBar horzScroll { get { return sbh; } };
9656 property ScrollBar vertScroll { get { return sbv; } };
9657 property StatusBar statusBar { get { return statusBar; } };
9658 property Window rootWindow { get { return rootWindow; } };
9659 property bool closing { get { return (bool)closing; } set { closing = value; } };
9660 property int documentID { get { return documentID; } };
9661 property Window previous { get { return prev; } }
9662 property Window next { get { return next; } }
9663 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9664 property PopupMenu menuBar { get { return menuBar; } }
9665 property ScrollBar sbv { get { return sbv; } }
9666 property ScrollBar sbh { get { return sbh; } }
9667 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9668 property void * systemHandle { get { return windowHandle; } }
9669 property Button minimizeButton { get { return sysButtons[0]; } };
9670 property Button maximizeButton { get { return sysButtons[1]; } };
9671 property Button closeButton { get { return sysButtons[2]; } };
9672 property BitmapResource icon
9674 get { return icon; }
9678 if(icon) incref icon;
9680 guiApp.interfaceDriver.SetIcon(this, value);
9683 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9684 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } };
9685 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9686 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9687 property bool nativeDecorations
9689 get { return (bool)nativeDecorations; }
9690 set { nativeDecorations = value; }
9691 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
9694 //return (nativeDecorations && (rootWindow == this || (formDesigner && activeDesigner && ((FormDesigner)activeDesigner.classDesigner).form && parent == ((FormDesigner)activeDesigner.classDesigner).form.parent))) != style.fixed;
9695 bool result = false;
9696 if(nativeDecorations)
9698 if(rootWindow == this)
9702 if(formDesigner && activeDesigner)
9704 FormDesigner cd = (FormDesigner)activeDesigner.classDesigner;
9705 Window form = cd ? cd.form : null;
9706 if(form && parent == form.parent)
9711 return result != style.fixed;
9715 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9717 property const char * text
9719 property_category $"Deprecated"
9721 set { property::caption = value; }
9722 get { return property::caption; }
9728 WindowBits style; // Window Style
9729 char * caption; // Name / Caption
9730 Window parent; // Parent window
9731 OldList children; // List of children in Z order
9732 Window activeChild; // Child window having focus
9733 Window activeClient;
9734 Window previousActive; // Child active prior to activating the default child
9735 Window master; // Window owning and receiving notifications concerning this window
9736 OldList slaves; // List of windows belonging to this window
9737 Display display; // Display this window is drawn into
9739 Point position; // Position in parent window client area
9740 Point absPosition; // Absolute position
9741 Point clientStart; // Client area position from (0,0) in this window
9743 Size clientSize; // Client area size
9744 Size scrollArea; // Virtual Scroll area size
9745 Size reqScrollArea; // Requested virtual area size
9746 Point scroll; // Virtual area scrolling position
9747 ScrollBar sbh, sbv; // Scrollbar window handles
9748 Cursor cursor; // Mouse cursor used for this window
9751 StatusBar statusBar;
9752 Button sysButtons[3];
9754 Box clientArea; // Client Area box clipped to parent
9756 HotKeySlot hotKey; // HotKey for this window
9760 ScrollFlags scrollFlags;// Window Scrollbar Flags
9761 int64 id; // Control ID
9763 ColorAlpha background; // Background color used to draw the window area
9765 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9766 OldList childrenCycle; // Cycling order
9767 OldLink cycle; // Element of parent's cycling order
9768 OldList childrenOrder; // Circular Z-Order
9769 OldLink order; // Element of parent's circular Z-Order
9770 Window modalSlave; // Slave window blocking this window's interaction
9772 Window rootWindow; // Topmost system managed window
9773 void * windowHandle; // System window handle
9775 DialogResult returnCode;// Return code for modal windows
9777 Point sbStep; // Scrollbar line scrolling steps
9780 SizeAnchor stateSizeAnchor;
9782 Anchor normalAnchor;
9783 SizeAnchor normalSizeAnchor;
9785 Size skinMinSize; // Minimal window size based on style
9786 Point scrolledPos; // Scrolled position
9787 Box box; // Window box clipped to parent
9788 Box * against; // What to clip the box to
9790 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9791 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9792 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9793 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9794 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9795 Point scrolledArea; // Distance to scroll area by
9796 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9798 OldList hotKeys; // List of the hotkeys of all children
9799 Window defaultControl; // Default child control
9803 ColorAlpha * palette; // Color palette used for this window
9805 int caretSize; // Size of caret, non zero if a caret is present
9806 Point caretPos; // Caret position
9808 void * systemParent; // Parent System Window for embedded windows
9814 #if !defined(__EMSCRIPTEN__)
9817 WindowState lastState;
9819 #if !defined(__EMSCRIPTEN__)
9820 FileMonitor fileMonitor;
9823 FontResource setFont, systemFont;
9824 FontResource usedFont;
9825 FontResource captionFont;
9827 FileDialog saveDialog;
9829 SizeAnchor sizeAnchor;
9831 // FormDesigner data
9834 Extent * tempExtents; //[4];
9835 BitmapResource icon;
9837 CreationActivationOption creationActivation;
9840 bool active:1; // true if window and ancestors are active
9841 bool acquiredInput:1; // true if the window is processing state based input
9842 bool modifiedDocument:1;
9843 bool disabled:1; // true if window cannot interact
9844 bool isForegroundWindow:1;// true while a root window is being activated
9845 bool visible:1; // Visibility flag
9846 bool destroyed:1; // true if window is being destroyed
9847 bool anchored:1; // true if this window is repositioned when the parent resizes
9848 bool dirty:1; // Flag set to true if any descendant must be redrawn
9854 bool modifyVirtArea:1;
9855 bool noAutoScrollArea:1;
9858 bool setVisible:1; // FOR FORM DESIGNER
9864 bool useSharedMemory:1;
9867 bool nativeDecorations:1;
9868 bool manageDisplay:1;
9869 bool formDesigner:1; // True if we this is running in the form editor
9870 bool requireRemaximize:1;
9873 // Checks used internally for them not to take effect in FormDesigner
9874 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9875 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9877 WindowController controller;
9878 public property WindowController controller
9880 get { return controller; }
9884 controller.setWindow(null);
9890 controller.setWindow(this);
9896 public class CommonControl : Window
9898 // creationActivation = doNothing;
9901 public property const String toolTip
9903 property_category $"Appearance"
9906 if(created) CommonControl::OnDestroy();
9908 toolTip = value ? ToolTip { tip = value; } : null;
9910 if(created) CommonControl::OnCreate();
9912 get { return toolTip ? toolTip.tip : null; }
9918 // (Very) Ugly work around for the fact that the parent watcher
9919 // won't fire when it's already been disconnected...
9920 eInstance_FireSelfWatchers(toolTip,
9921 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
9927 toolTip.parent = this;
9936 public class Percentage : float
9938 const char * OnGetString(char * string, float * fieldData, bool * needClass)
9942 sprintf(string, "%.2f", this);
9943 c = strlen(string)-1;
9946 if(string[c] != '0')
9947 last = Max(last, c);
9948 if(string[c] == '.')
9961 public void ApplySkin(Class c, const char * name, void ** vTbl)
9963 char className[1024];
9968 subclass(Window) wc = (subclass(Window))c;
9969 subclass(Window) base = (subclass(Window))c.base;
9971 sprintf(className, "%sSkin_%s", name, c.name);
9972 wc.pureVTbl = c._vTbl;
9973 c._vTbl = new void *[c.vTblSize];
9974 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9975 sc = eSystem_FindClass(c.module.application, className);
9979 for(m = 0; m < c.base.vTblSize; m++)
9981 if(c._vTbl[m] == base.pureVTbl[m])
9982 c._vTbl[m] = vTbl[m];
9987 for(m = 0; m < c.vTblSize; m++)
9989 if(sc._vTbl[m] != wc.pureVTbl[m])
9990 c._vTbl[m] = sc._vTbl[m];
9994 for(d = c.derivatives.first; d; d = d.next)
9996 ApplySkin(d.data, name, c._vTbl);
10000 public void UnapplySkin(Class c)
10002 subclass(Window) wc = (subclass(Window))c;
10005 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
10008 c._vTbl = wc.pureVTbl;
10009 wc.pureVTbl = null;
10012 for(d = c.derivatives.first; d; d = d.next)
10014 UnapplySkin(d.data);
10018 void CheckFontIntegrity(Window window)
10023 if(window.usedFont && window.usedFont.font == 0xecececec)
10025 FontResource uf = window.usedFont;
10026 char * className = window._class.name;
10027 char * text = window.text;
10030 for(c = window.firstChild; c; c = c.next)
10031 CheckFontIntegrity(c);
10035 public class ControllableWindow : Window
10037 /*WindowController controller;
10038 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
10039 ~ControllableWindow() { delete controller; }*/
10042 class WindowControllerInterface : ControllableWindow
10044 bool OnKeyDown(Key key, unichar ch)
10046 bool result = controller.OnKeyDown ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyDown)((Window)controller.controlled, controller, key, ch) : true;
10049 bool (* onKeyDown)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown];
10051 result = onKeyDown(controller.window, key, ch);
10056 bool OnKeyUp(Key key, unichar ch)
10058 bool result = controller.OnKeyUp ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyUp)((Window)controller.controlled, controller, key, ch) : true;
10061 bool (* onKeyUp)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp];
10063 result = onKeyUp(controller.window, key, ch);
10068 bool OnKeyHit(Key key, unichar ch)
10070 bool result = controller.OnKeyHit ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyHit)((Window)controller.controlled, controller, key, ch) : true;
10073 bool (* onKeyHit)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit];
10075 result = onKeyHit(controller.window, key, ch);
10080 bool OnMouseMove(int x, int y, Modifiers mods)
10082 bool result = controller.OnMouseMove ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMouseMove)((Window)controller.controlled, controller, x, y, mods) : true;
10085 bool(* onMouseMove)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove];
10087 result = onMouseMove(controller.window, x, y, mods);
10092 bool OnLeftButtonDown(int x, int y, Modifiers mods)
10094 bool result = controller.OnLeftButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10097 bool(* onLeftButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown];
10098 if(onLeftButtonDown)
10099 result = onLeftButtonDown(controller.window, x, y, mods);
10104 bool OnLeftButtonUp(int x, int y, Modifiers mods)
10106 bool result = controller.OnLeftButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10109 bool(* onLeftButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp];
10111 result = onLeftButtonUp(controller.window, x, y, mods);
10116 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
10118 bool result = controller.OnLeftDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10121 bool(* onLeftDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick];
10122 if(onLeftDoubleClick)
10123 result = onLeftDoubleClick(controller.window, x, y, mods);
10128 bool OnRightButtonDown(int x, int y, Modifiers mods)
10130 bool result = controller.OnRightButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10133 bool(* onRightButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown];
10134 if(onRightButtonDown)
10135 result = onRightButtonDown(controller.window, x, y, mods);
10140 bool OnRightButtonUp(int x, int y, Modifiers mods)
10142 bool result = controller.OnRightButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10145 bool(* onRightButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp];
10146 if(onRightButtonUp)
10147 result = onRightButtonUp(controller.window, x, y, mods);
10152 bool OnRightDoubleClick(int x, int y, Modifiers mods)
10154 bool result = controller.OnRightDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10157 bool(* onRightDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick];
10158 if(onRightDoubleClick)
10159 result = onRightDoubleClick(controller.window, x, y, mods);
10164 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
10166 bool result = controller.OnMiddleButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10169 bool(* onMiddleButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown];
10170 if(onMiddleButtonDown)
10171 result = onMiddleButtonDown(controller.window, x, y, mods);
10176 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
10178 bool result = controller.OnMiddleButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10181 bool(* onMiddleButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp];
10182 if(onMiddleButtonUp)
10183 result = onMiddleButtonUp(controller.window, x, y, mods);
10188 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
10190 bool result = controller.OnMiddleDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10193 bool(* onMiddleDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick];
10194 if(onMiddleDoubleClick)
10195 onMiddleDoubleClick(controller.window, x, y, mods);
10200 bool OnMultiTouch(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods)
10202 bool result = controller.OnMultiTouch ? ((bool(*)(Window, WindowController, TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers))(void *)controller.OnMultiTouch)((Window)controller.controlled, controller, event, infos, mods) : true;
10205 bool(* onMultiTouch)(Window, TouchPointerEvent, Array<TouchPointerInfo>, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMultiTouch];
10207 onMultiTouch(controller.window, event, infos, mods);
10212 void OnResize(int width, int height)
10214 if(controller.OnResize)
10215 ((void(*)(Window, WindowController, int, int))(void *)controller.OnResize)((Window)controller.controlled, controller, width, height);
10217 void(* onResize)(Window, int, int) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize];
10219 onResize(controller.window, width, height);
10223 void OnRedraw(Surface surface)
10225 if(controller.OnRedraw)
10226 ((void(*)(Window, WindowController, Surface))(void *)controller.OnRedraw)((Window)controller.controlled, controller, surface);
10228 void(* onRedraw)(Window, Surface) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw];
10230 onRedraw(controller.window, surface);
10236 bool result = controller.OnCreate ? ((bool(*)(Window, WindowController))(void *)controller.OnCreate)((Window)controller.controlled, controller) : true;
10239 bool(* onCreate)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate];
10241 result = onCreate(controller.window);
10246 bool OnLoadGraphics()
10248 bool result = controller.OnLoadGraphics ? ((bool(*)(Window, WindowController))(void *)controller.OnLoadGraphics)((Window)controller.controlled, controller) : true;
10251 bool(* onLoadGraphics)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLoadGraphics];
10253 result = onLoadGraphics(controller.window);
10258 void OnUnloadGraphics()
10260 if(controller.OnUnloadGraphics)
10261 ((void(*)(Window, WindowController))(void *)controller.OnUnloadGraphics)((Window)controller.controlled, controller);
10263 void(* onUnloadGraphics)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnUnloadGraphics];
10264 if(onUnloadGraphics)
10265 onUnloadGraphics(controller.window);
10270 public class WindowController<class V>
10272 void setWindow(Window value)
10274 uint size = class(Window).vTblSize;
10278 windowVTbl = new void *[size];
10279 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
10280 if(value._vTbl == value._class._vTbl)
10282 value._vTbl = new void *[value._class.vTblSize];
10283 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
10287 for(c = 0; c < size; c++)
10289 void * function = class(WindowControllerInterface)._vTbl[c];
10290 if(function && function != DefaultFunction)
10291 value._vTbl[c] = function;
10293 value._vTbl[c] = windowVTbl[c];
10299 memcpy(window._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
10305 property Window window
10307 get { return window; }
10309 property V controlled
10311 set { controlled = value; }
10312 get { return controlled; }
10314 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
10315 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
10316 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
10317 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
10318 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
10319 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
10320 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10321 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
10322 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
10323 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10324 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
10325 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
10326 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10327 virtual bool V::OnMultiTouch(WindowController controller, TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods);
10328 virtual void V::OnResize(WindowController controller, int width, int height);
10329 virtual void V::OnRedraw(WindowController controller, Surface surface);
10330 virtual bool V::OnCreate(WindowController controller);
10331 virtual bool V::OnLoadGraphics(WindowController controller);
10332 virtual void V::OnUnloadGraphics(WindowController controller);
10335 public int (** windowVTbl)();
10339 ~WindowController()