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;
586 int i, lockCount = guiApp.lockMutex.lockCount;
587 for(i = 0; i < lockCount; i++)
588 guiApp.lockMutex.Release();
590 for(i = 0; i < lockCount; i++)
591 guiApp.lockMutex.Wait();
596 stopwatching(parent, font);
597 if(parent.activeChild == this)
598 parent.activeChild = null;
599 if(parent.activeClient == this)
600 parent.activeClient = null;
605 // Prevent destructor from being called again...
611 /////////////////////////////////
614 OldLink slave = master.slaves.FindLink(this);
615 master.slaves.Delete(slave);
622 parent.childrenCycle.Remove(cycle);
624 parent.childrenOrder.Remove(order);
625 parent.children.Remove(this);
630 /////////////////////////////////
632 while((ptr = resources.first))
635 resources.Delete(ptr);
642 for(child = children.first; child; child = child.next)
644 // child.stopwatching(this, font);
646 eInstance_StopWatching(this, __ecereProp___ecereNameSpace__ecere__gui__Window_font, child);
647 // Don't want property here
648 *&child.parent = null;
651 while((slave = slaves.first))
653 // Don't want property here
654 *&((Window)slave.data).master = null;
655 slaves.Delete(slave);
658 // Because we do a decref in DestroyEx...
666 // Why was this commented?
667 //if(this != guiApp.desktop)
680 if(((subclass(Window))_class).pureVTbl)
682 if(_vTbl == _class._vTbl)
684 _vTbl = ((subclass(Window))_class).pureVTbl;
689 for(m = 0; m < _class.vTblSize; m++)
691 if(_vTbl[m] == _class._vTbl[m])
692 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
696 if(_vTbl == ((subclass(Window))_class).pureVTbl || _vTbl == _class._vTbl)
699 dirtyArea.Free(null);
700 renderArea.Free(null);
701 overRenderArea.Free(null);
702 clipExtent.Free(null);
703 scrollExtent.Free(null);
704 dirtyBack.Free(null);
708 tempExtents[0].Free(null);
709 tempExtents[1].Free(null);
710 tempExtents[2].Free(null);
711 tempExtents[3].Free(null);
718 //#if !defined(ECERE_VANILLA)
719 const char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
721 if(this == activeDesigner)
725 const char * name = property::name;
726 return name ? name : "";
731 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
732 bool OnGetDataFromString(const char * string)
734 FormDesigner designer = (FormDesigner)activeDesigner.classDesigner;
737 if(!strcmp(string, "this") || !strcmp(string, designer.form.name))
738 this = designer.form;
739 else if(!strcmpi(string, "(Desktop)"))
740 this = activeDesigner;
742 return activeDesigner.FindObject(&this, string);
748 // --- Window updates system ---
750 // Setup a bitmap for Redrawing on client area of Window
751 Surface Redraw(Box box)
753 Surface surface = null;
755 Box clientArea = this.clientArea;
759 mox.left -= clientStart.x;
760 mox.top -= clientStart.y;
761 mox.right -= clientStart.x;
762 mox.bottom -= clientStart.y;
764 mox.Clip(clientArea);
765 // mox.ClipOffset(against, scrolledPos.x, scrolledPos.y);
767 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && mox.right >= mox.left && mox.bottom >= mox.top)
769 int x = absPosition.x + clientStart.x;
770 int y = absPosition.y + clientStart.y;
771 if(rootWindow.nativeDecorations && rootWindow.windowHandle && !is3D)
773 x -= rootWindow.clientStart.x;
774 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
776 if(!guiApp.fullScreenMode || is3D)
778 x -= rootWindow.absPosition.x;
779 y -= rootWindow.absPosition.y;
783 int dx = rootWindow.parent.parent.clientStart.x;
784 int dy = rootWindow.parent.parent.clientStart.y;
785 if(!rootWindow.parent.nativeDecorations)
787 dx += rootWindow.parent.clientStart.x;
788 dy += rootWindow.parent.clientStart.y;
802 surface = display.GetSurface(x, y, mox);
805 surface.width = clientSize.w;
806 surface.height = clientSize.h;
812 // Setup a bitmap for Redrawing on full Window
813 Surface RedrawFull(Box box)
815 Surface surface = null;
823 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && box.right >= box.left && box.bottom >= box.top)
825 int x = absPosition.x;
826 int y = absPosition.y;
827 if(rootWindow.nativeDecorations && rootWindow.windowHandle && !is3D)
829 x -= rootWindow.clientStart.x;
830 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
832 if(!guiApp.fullScreenMode || is3D)
834 x -= rootWindow.absPosition.x;
835 y -= rootWindow.absPosition.y;
838 int dx = rootWindow.parent.parent.clientStart.x;
839 int dy = rootWindow.parent.parent.clientStart.y;
840 if(!rootWindow.parent.nativeDecorations)
842 dx += rootWindow.parent.clientStart.x;
843 dy += rootWindow.parent.clientStart.y;
857 surface = display.GetSurface(x, y, mox);
860 surface.width = size.w;
861 surface.height = size.h;
867 void FigureCaption(char * caption)
869 Window activeClient = null;
873 strcpy(caption, this.caption);
874 if(style.isDocument || fileName)
876 if(caption[0]) strcat(caption, " - ");
878 strcat(caption, fileName);
882 sprintf(title, "Untitled %d", documentID);
883 strcat(caption, title);
886 strcat(caption, " *");
891 for(activeClient = this.activeClient; activeClient && !((BorderBits)activeClient.borderStyle).fixed; activeClient = activeClient.activeClient);
893 if(activeClient && activeClient.state == maximized)
895 if(activeClient.caption)
897 if(caption[0]) strcat(caption, " - ");
898 strcat(caption, activeClient.caption);
900 if(activeClient.style.isDocument || activeClient.fileName)
902 if(caption[0]) strcat(caption, " - ");
903 strcat(caption, "[");
904 if(activeClient.fileName)
905 strcat(caption, activeClient.fileName);
909 sprintf(title, "Untitled %d", activeClient.documentID);
910 strcat(caption, title);
912 if(activeClient.modifiedDocument)
913 strcat(caption, " *");
914 strcat(caption, "]");
919 // Code for returning dirty from ScrollDisplay:
921 for(d = 0; d<scrollExtent.count; d++)
923 Box * box = &scrollExtent.boxes[d];
929 Min(box.right, box.left-scroll.x),box.bottom
931 dirtyArea.UnionBox(update);
937 Max(box.left, box.right-scroll.x), box.top,
938 box.right, box.bottom
940 dirtyArea.UnionBox(update);
948 box.right, Min(box.bottom, box.top-scroll.y),
950 dirtyArea.UnionBox(update);
956 box.left, Max(box.top, box.bottom-scroll.y),
957 box.right, box.bottom
959 dirtyArea.UnionBox(update);
964 void UpdateDecorations(void)
966 // TODO: *** TEMPORARY HACK ***
973 Update({ -clientStart.x, -clientStart.y, -clientStart.x + size.w-1, 0 });
975 Update({ -clientStart.x, clientSize.h, -clientStart.x + size.w-1, -clientStart.y + size.h-1 });
977 Update({ -clientStart.x,0, -1, clientSize.h-1 });
979 Update({ clientSize.w, 0, -clientStart.x + size.w-1, clientSize.h-1 });
982 // Returns w & h for Position
983 void ComputeAnchors(Anchor anchor, SizeAnchor sizeAnchor, int *ox, int *oy, int *ow, int *oh)
985 Window parent = this.parent ? this.parent : guiApp.desktop;
986 int xOffset = 0, yOffset = 0;
987 int vpw = parent ? parent.clientSize.w : 0;
988 int vph = parent ? parent.clientSize.h : 0;
989 int pw = parent ? parent.clientSize.w : 0;
990 int ph = parent ? parent.clientSize.h : 0;
991 int w = sizeAnchor.size.w, h = sizeAnchor.size.h;
992 int x = anchor.left.distance, y = anchor.top.distance;
993 float ex = 0, ey = 0;
994 MinMaxValue ew = 0, eh = 0;
996 float cascadeW, cascadeH;
998 int tilingW, tilingH, tilingSplit, tilingLastH = 0;
999 int addX = 0, addY = 0;
1001 if(parent && rootWindow == this && guiApp && guiApp.interfaceDriver)
1003 Window masterWindow = this;
1004 Box box { addX, addY, addX + vpw - 1, addY + vph - 1 };
1007 if(master == guiApp.desktop)
1008 masterWindow = guiApp.desktop.activeChild;
1010 masterWindow = master.rootWindow;
1011 if(!masterWindow) masterWindow = this;
1013 guiApp.interfaceDriver.GetScreenArea(masterWindow, box);
1014 if((anchor.left.type == offset && anchor.right.type == offset) || anchor.left.type == none)
1017 pw = vpw = box.right - box.left + 1;
1019 if((anchor.top.type == offset && anchor.bottom.type == offset) || anchor.top.type == none)
1022 ph = vph = box.bottom - box.top + 1;
1038 vpw = pw = parent.size.w;
1039 vph = ph = parent.size.h;
1041 else if(!style.fixed /*|| style.isDocument*/)
1043 if(!style.dontScrollHorz && parent.scrollArea.w) vpw = parent.scrollArea.w;
1044 if(!style.dontScrollVert && parent.scrollArea.h) vph = parent.scrollArea.h;
1046 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
1049 Desktop3D_FixSize(&pw, &ph);
1050 Desktop3D_FixSize(&vpw, &vph);
1053 if(pw < skinMinSize.w) pw = skinMinSize.w;
1054 if(ph < skinMinSize.h) ph = skinMinSize.h;
1055 if(vpw < skinMinSize.w) vpw = skinMinSize.w;
1056 if(vph < skinMinSize.h) vph = skinMinSize.h;
1058 // TODO: Must fix what we're snapping
1061 if(anchor.left.type)
1063 SNAPUP(x, textCellW);
1065 else if(anchor.right.type)
1067 SNAPDOWN(x, textCellW);
1072 SNAPUP(y, textCellH);
1074 else if(anchor.bottom.type)
1076 SNAPDOWN(y, textCellH);
1080 // This is required to get proper initial decoration size using native decorations on Windows
1081 #if defined(__WIN32__)
1082 if(nativeDecorations && windowHandle && guiApp && guiApp.interfaceDriver && !visible)
1083 guiApp.interfaceDriver.PositionRootWindow(this, x, y, Max(1, size.w), Max(1, size.h), true, true);
1085 GetDecorationsSize(&ew, &eh);
1087 if(anchor.left.type >= cascade && (state == normal /*|| state == Hidden*/))
1089 // Leave room for non client windows (eventually dockable panels)
1091 int loX = 0, loY = 0, hiX = pw, hiY = ph;
1092 for(win = parent.children.first; win; win = win.next)
1094 if(!win.nonClient && !win.isActiveClient && win.visible)
1096 Size size = win.size;
1097 Point pos = win.position;
1098 int left = pos.x, top = pos.y;
1099 int right = pos.x + size.w, bottom = pos.y + size.h;
1100 if(win.size.w > win.size.h)
1103 loY = Max(loY, bottom);
1104 else if(top > ph - ph / 4)
1105 hiY = Min(hiY, top);
1110 loX = Max(loX, right);
1111 else if(left > pw - pw / 4)
1112 hiX = Min(hiX, left);
1121 if(parent.sbv && !parent.sbv.style.hidden)
1122 pw += guiApp.currentSkin.VerticalSBW();
1123 if(parent.sbh && !parent.sbh.style.hidden)
1124 ph += guiApp.currentSkin.HorizontalSBH();
1126 if(anchor.left.type == cascade)
1128 w = (int)(pw * 0.80);
1129 h = (int)(ph * 0.80);
1131 else if(anchor.left.type >= vTiled)
1136 numTiling = parent.numPositions - parent.numIcons;
1137 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1138 if(anchor.left.type == vTiled)
1142 tilingH = (int)sqrt(numTiling);
1143 tilingW = numTiling / tilingH;
1146 tilingH = tilingW = 0;
1152 tilingW = (int)sqrt(numTiling);
1153 tilingH = numTiling / tilingW;
1156 tilingH = tilingW = 0;
1159 leftOver = numTiling - tilingH * tilingW;
1162 tilingSplit = (tilingW - leftOver) * tilingH;
1163 tilingLastH = tilingH+1;
1166 tilingSplit = numTiling;
1168 if(tilingW && tilingH)
1170 if(positionID >= tilingSplit)
1172 x = xOffset + pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
1173 y = yOffset + ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
1174 x2 = xOffset + pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
1175 y2 = yOffset + ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
1179 x = xOffset + pw * (positionID / tilingH) / tilingW;
1180 y = yOffset + ph * (positionID % tilingH) / tilingH;
1181 x2 = xOffset + pw * (positionID / tilingH + 1) / tilingW;
1182 y2 = yOffset + ph * ((positionID % tilingH) + 1) / tilingH;
1187 // How can this happen? From ec2 parsing test
1195 SNAPDOWN(x, textCellW);
1196 SNAPDOWN(y, textCellH);
1197 SNAPDOWN(x2, textCellW);
1198 SNAPDOWN(y2, textCellH);
1206 if(sizeAnchor.isClientW) w += ew;
1207 if(sizeAnchor.isClientH) h += eh;
1209 if(anchor.left.type == offset)
1210 x = anchor.left.distance;
1211 else if(anchor.left.type == relative)
1212 x = (anchor.left.percent < 0) ? ((int)(vpw * anchor.left.percent - 0.5)) : (int)(vpw * anchor.left.percent + 0.5);
1213 else if(anchor.right.type == relative)
1214 // ex = (anchor.right.percent < 0) ? ((int)(vpw * anchor.right.percent + 0)) : ((int)(vpw * anchor.right.percent + 0));
1215 ex = (anchor.right.percent < 0) ? ((int)(vpw * (1.0-anchor.right.percent) + 0)) : ((int)(vpw * (1.0-anchor.right.percent) + 0));
1216 else if(anchor.right.type == offset)
1217 ex = vpw - anchor.right.distance;
1219 if(anchor.top.type == offset)
1220 y = anchor.top.distance;
1221 else if(anchor.top.type == relative)
1222 y = (anchor.top.percent < 0) ? ((int)(vph * anchor.top.percent - 0.5)) : ((int)(vph * anchor.top.percent + 0.5));
1223 else if(anchor.bottom.type == relative)
1224 //ey = (anchor.bottom.percent < 0) ? ((int)(vph * anchor.bottom.percent + 0)) : ((int)(vph * anchor.bottom.percent + 0));
1225 ey = (anchor.bottom.percent < 0) ? ((int)(vph * (1.0-anchor.bottom.percent) + 0)) : ((int)(vph * (1.0-anchor.bottom.percent) + 0));
1226 else if(anchor.bottom.type == offset)
1227 ey = vph - anchor.bottom.distance;
1229 if(anchor.left.type && anchor.right.type)
1231 switch(anchor.right.type)
1234 ex = pw * (1.0f-anchor.right.percent);
1235 w = Max((int)(ex + 0.5) - x, 0);
1238 ex = vpw - anchor.right.distance;
1239 w = Max((int)(ex + 0.5) - x, 0);
1243 if(anchor.top.type && anchor.bottom.type)
1245 switch(anchor.bottom.type)
1248 ey = ph * (1.0f-anchor.bottom.percent);
1249 h = Max((int)(ey + 0.5) - y, 0);
1252 ey = vph - anchor.bottom.distance;
1253 h = Max((int)(ey + 0.5) - y, 0);
1262 if(state == normal /*|| state == Hidden*/)
1264 bool addSbV = false, addSbH = false;
1266 if(sizeAnchor.isClientW || (anchor.left.type && anchor.right.type)) w = Max(w, 1); else w = Max(w, 0);
1267 if(sizeAnchor.isClientH || (anchor.top.type && anchor.bottom.type)) h = Max(h, 1); else h = Max(h, 0);
1269 w = Max(w, minSize.w);
1270 h = Max(h, minSize.h);
1271 w = Min(w, maxSize.w);
1272 h = Min(h, maxSize.h);
1274 if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
1276 if(w) w -= guiApp.currentSkin.VerticalSBW();
1279 if((sizeAnchor.isClientH || !h || (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
1281 if(h) h -= guiApp.currentSkin.HorizontalSBH();
1285 if(!OnResizing(&w, &h))
1291 if((addSbV)) // || reqScrollArea.h > h) && sbv)
1292 w += guiApp.currentSkin.VerticalSBW();
1293 if((addSbH)) // || reqScrollArea.w > w) && sbh)
1294 h += guiApp.currentSkin.HorizontalSBH();
1296 w = Max(w, skinMinSize.w);
1297 h = Max(h, skinMinSize.h);
1310 SNAPDOWN(w, textCellW);
1311 SNAPDOWN(h, textCellH);
1314 if(anchor.left.type == cascade && (state == normal /*|| state == Hidden*/))
1316 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1319 (pw - w) / CASCADE_SPACE,
1320 (ph - h) / CASCADE_SPACE);
1326 cascW = (pw - w) / (numCascade-1);
1327 cascH = (ph - h) / (numCascade-1);
1328 SNAPDOWN(cascW, textCellW);
1329 SNAPDOWN(cascH, textCellH);
1330 cascadeW = (float)cascW;
1331 cascadeH = (float)cascH;
1335 numCascade = Max(numCascade, 2);
1336 cascadeW = (float)(pw - w) / (numCascade-1);
1337 cascadeH = (float)(ph - h) / (numCascade-1);
1340 x = (int)((positionID % numCascade) * cascadeW) + xOffset;
1341 y = (int)((positionID % numCascade) * cascadeH) + yOffset;
1343 else if(anchor.left.type < vTiled)
1345 if(!anchor.left.type || anchor.horz.type == middleRelative)
1347 if(!anchor.right.type)
1349 if(anchor.horz.type == middleRelative)
1350 x = (int)(vpw * (0.5 + anchor.horz.percent) - w / 2);
1352 x = vpw / 2 + anchor.horz.distance - w / 2;
1358 // case A_EDGE: x = x - w; break;
1360 if(!anchor.top.type || anchor.vert.type == middleRelative)
1362 if(!anchor.bottom.type)
1364 if(anchor.vert.type == middleRelative)
1365 y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
1367 y = vph / 2 + anchor.vert.distance - h / 2;
1373 // case A_EDGE: y = y - h; break;
1376 if((state == normal /*|| state == Hidden*/) && !OnMoving(&x, &y, w, h))
1384 SNAPDOWN(x, textCellW);
1385 SNAPDOWN(y, textCellH);
1397 if(anchored && style.fixed && style.isActiveClient)
1402 void UpdateCaret(bool forceUpdate, bool erase)
1404 static Window lastWindow = null;
1405 static int caretX, caretY, caretSize;
1407 if(guiApp && guiApp.caretOwner == this)
1409 int x = caretPos.x - scroll.x;
1410 int y = caretPos.y - scroll.y;
1412 if((erase || this.caretSize) &&
1413 x >= clientArea.left && x <= clientArea.right &&
1414 y >= clientArea.top && y <= clientArea.bottom)
1418 guiApp.interfaceDriver.SetCaret(
1419 x + absPosition.x + clientStart.x,
1420 y + absPosition.y + clientStart.y, this.caretSize);
1421 guiApp.caretEnabled = true;
1423 if(erase || lastWindow != this || caretX != x || caretY != y || caretSize != this.caretSize || forceUpdate)
1427 if(lastWindow != this)
1429 updateBox.left = x + 1;
1431 updateBox.right = x + 2;
1432 updateBox.bottom = y + this.caretSize - 1;
1436 updateBox.left = Min(x + 1, caretX + 1);
1437 updateBox.top = Min(y, caretY);
1438 updateBox.right = Max(x + 2, caretX + 2);
1439 updateBox.bottom = Max(y + this.caretSize - 1, caretY + caretSize - 1);
1442 guiApp.caretOwner.Update(updateBox);
1449 caretSize = this.caretSize;
1455 guiApp.interfaceDriver.SetCaret(0,0,0);
1456 guiApp.caretEnabled = false;
1462 void SetPosition(int x, int y, int w, int h, bool modifyArea, bool modifyThisArea, bool modifyClientArea)
1467 scrolledPos.x = position.x = x;
1468 scrolledPos.y = position.y = y;
1470 clientSize.w = size.w = w;
1471 clientSize.h = size.h = h;
1473 if(parent && !style.nonClient)
1475 //if(!style.fixed || style.isDocument)
1477 if(!style.dontScrollHorz) scrolledPos.x -= parent.scroll.x;
1478 if(!style.dontScrollVert) scrolledPos.y -= parent.scroll.y;
1482 clientStart.x = clientStart.y = 0;
1484 SetWindowArea(&clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1486 //if(!activeClient || activeClient.state != maximized)
1487 if(!noAutoScrollArea)
1489 // Check if scroll area must be modified
1490 if(guiApp && !guiApp.modeSwitching && (sbv || sbh))
1492 bool foundChild = false;
1494 int cw = clientSize.w;// + ((!sbv || sbv.range > 1) ? guiApp.currentSkin.VerticalSBW() : 0);
1495 int ch = clientSize.h;// + ((!sbh || sbh.rangw > 1) ? guiApp.currentSkin.HorizontalSBH() : 0);
1496 for(child = children.first; child; child = child.next)
1498 if(child.modifyVirtArea && !child.style.hidden && child.created && /*!child.anchored &&*/
1499 !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1501 if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == offset)
1502 w = Max(w, child.position.x + child.size.w);
1503 else if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == none)
1504 w = Max(w, Max(child.position.x, 0) + child.size.w);
1505 if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == offset)
1506 h = Max(h, child.position.y + child.size.h);
1507 else if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == none)
1508 h = Max(h, Max(child.position.y, 0) + child.size.h);
1513 if(foundChild && (w > cw || h > ch))
1515 //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
1517 int stepX = sbStep.x, stepY = sbStep.y;
1518 // Needed to make snapped down position match the skin's check of client area
1519 // against realvirtual
1522 SNAPDOWN(stepX, textCellW);
1523 SNAPDOWN(stepY, textCellH);
1524 stepX = Max(stepX, textCellW);
1525 stepY = Max(stepY, textCellH);
1527 if(scrollFlags.snapX)
1529 if(scrollFlags.snapY)
1532 reqScrollArea.w = w;
1533 reqScrollArea.h = h;
1536 else if(reqScrollArea.w || reqScrollArea.h)
1538 reqScrollArea.w = 0;
1539 reqScrollArea.h = 0;
1540 SetScrollPosition(0,0);
1545 // Automatic MDI Client Scrolling Area Adjustment
1546 if(parent && !parent.noAutoScrollArea)
1548 if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
1549 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
1551 Window parent = this.parent;
1552 int w = parent.reqScrollArea.w;
1553 int h = parent.reqScrollArea.h;
1555 if(stateAnchor.right.type == none && stateAnchor.left.type == offset)
1556 w = Max(w, position.x + size.w);
1557 else if(stateAnchor.right.type == none && stateAnchor.left.type == none)
1558 w = Max(w, Max(position.x, 0) + size.w);
1559 if(stateAnchor.bottom.type == none && stateAnchor.top.type == offset)
1560 h = Max(h, position.y + size.h);
1561 else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
1562 h = Max(h, Max(position.y, 0) + size.h);
1564 if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
1565 (h > parent.clientSize.h && h > parent.reqScrollArea.h))
1567 /*bool resize = false;
1568 int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
1569 // Needed to make snapped down position match the skin's check of client area
1570 // against realvirtual
1573 SNAPDOWN(stepX, textCellW);
1574 SNAPDOWN(stepY, textCellH);
1575 stepX = Max(stepX, textCellW);
1576 stepY = Max(stepY, textCellH);
1578 if(parent.scrollFlags.snapX)
1580 if(parent.scrollFlags.snapY)
1582 if(parent.reqScrollArea.w != w || parent.reqScrollArea.h != h)
1584 parent.reqScrollArea.w = w;
1585 parent.reqScrollArea.h = h;*/
1587 // parent.UpdateScrollBars(true, true);
1588 parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1589 false, true, true, true, false, false);
1594 GetRidOfVirtualArea();
1598 UpdateScrollBars(modifyThisArea, false);
1599 else if(guiApp.currentSkin)
1602 &clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1604 if(sbv && (scrollFlags.dontHide || sbv.range > 1))
1605 clientSize.w -= guiApp.currentSkin.VerticalSBW();
1606 if(sbh && (scrollFlags.dontHide || sbh.range > 1))
1607 clientSize.h -= guiApp.currentSkin.HorizontalSBH();
1610 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1611 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1613 absPosition = scrolledPos;
1614 if(guiApp && guiApp.driver != null && guiApp.interfaceDriver)
1615 guiApp.interfaceDriver.OffsetWindow(this, &absPosition.x, &absPosition.y);
1617 if(this != guiApp.desktop && parent)
1619 absPosition.x += parent.absPosition.x;
1620 absPosition.y += parent.absPosition.y;
1621 if(!style.nonClient && this != guiApp.desktop)
1623 absPosition.x += parent.clientStart.x;
1624 absPosition.y += parent.clientStart.y;
1628 box = Box { 0, 0, size.w - 1, size.h - 1 };
1633 // Clip against parent's client area
1634 box.ClipOffset(against, scrolledPos.x, scrolledPos.y);
1636 // Compute client area in this window coordinate system
1637 clientArea.left = 0;
1639 clientArea.right = clientSize.w - 1;
1640 clientArea.bottom = clientSize.h - 1;
1642 // Clip against parent's client area
1644 clientArea.ClipOffset(against, scrolledPos.x + clientStart.x, scrolledPos.y + clientStart.y);
1648 //absPosition.x -= parent.clientStart.x;
1649 //absPosition.y -= parent.clientStart.y;
1652 // Adjust all children
1653 for(child = children.first; child; child = child.next)
1654 child.SetPosition(child.position.x, child.position.y, child.size.w, child.size.h, false, true, true);
1656 UpdateCaret(false, false);
1659 void GetRidOfVirtualArea(void)
1661 if(parent && !parent.destroyed && style.fixed &&
1662 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient &&
1663 parent.reqScrollArea.w && parent.reqScrollArea.h)
1665 if(!parent.noAutoScrollArea)
1667 // TODO: Review the logic of all this? Each child is going to reposition the parent?
1671 for(child = children.first; child; child = child.next)
1673 if(child.modifyVirtArea && !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1675 if(child.position.x + child.size.w > parent.clientSize.w + ((!parent.sbv || parent.sbv.style.hidden) ? 0 : guiApp.currentSkin.VerticalSBW()) ||
1676 child.position.y + child.size.h > parent.clientSize.h + ((!parent.sbh || parent.sbh.style.hidden) ? 0 : guiApp.currentSkin.HorizontalSBH()))
1686 Window parent = this.parent;
1688 parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1689 false, true, true, true, false, false);
1691 parent.SetScrollArea(0,0,true);
1692 parent.SetScrollPosition(0,0);
1698 public void ExternalPosition(int x, int y, int w, int h)
1700 Position(x, y, w, h, false, true, true, true, false, false);
1703 // (w, h): Full window size
1704 bool Position(int x, int y, int w, int h, bool force, bool processAnchors, bool modifyArea, bool updateScrollBars, bool thisOnly, bool changeRootWindow)
1706 bool result = false;
1707 int oldCW = clientSize.w, oldCH = clientSize.h;
1708 bool clientResized, windowResized, windowMoved;
1710 //bool realResized = size.w != w || size.h != h;
1712 // TOCHECK: This wasn't in ecere.dll
1713 //if(!parent) return true;
1714 if(destroyed) return false;
1716 windowMoved = position.x != x || position.y != y || force;
1718 // windowResized = realResized || force;
1719 windowResized = size.w != w || size.h != h || force;
1721 if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
1727 scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
1728 scrolledPos.x - parent.clientStart.x + this.box.right,
1729 scrolledPos.y - parent.clientStart.y + this.box.bottom
1735 Box box { scrolledPos.x + this.box.left, scrolledPos.y + this.box.top, scrolledPos.x + this.box.right, scrolledPos.y + this.box.bottom};
1740 SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
1742 clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
1743 if(clientResized && this == rootWindow && nativeDecorations && rootWindow.windowHandle)
1744 windowResized = true;
1746 if(display && rootWindow != this)
1749 if(guiApp && guiApp.windowMoving)
1751 if(guiApp.windowMoving.style.nonClient)
1752 guiApp.windowMoving.parent.SetMouseRangeToWindow();
1754 guiApp.windowMoving.parent.SetMouseRangeToClient();
1764 // Buttons bitmap resources crash if we do this while switching mode
1765 if(!guiApp || !guiApp.modeSwitching)
1768 // Process Anchored Children
1772 for(child = children.first; child; child = child.next)
1775 ((child.stateAnchor.left.type != offset ||
1776 child.stateAnchor.top.type != offset ||
1777 child.stateAnchor.right.type != none ||
1778 child.stateAnchor.bottom.type != none) ||
1779 child.state == maximized || child.state == minimized))
1781 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1783 // child.Position(x, y, w, h, false, true, true, true, false);
1784 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1785 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1791 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1792 //if(updateScrollBars)
1794 OnResize(clientSize.w, clientSize.h);
1796 if((clientResized || windowMoved) && created)
1797 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1799 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1801 Window master = guiApp.interimWindow.master;
1802 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1805 if(rootWindow == this && !is3D)
1809 x -= guiApp.desktop.absPosition.x;
1810 y -= guiApp.desktop.absPosition.y;
1812 //guiApp.Log("Position %s\n", caption);
1815 if(windowResized || windowMoved)
1816 if(display && !display.flags.memBackBuffer && changeRootWindow)
1817 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1819 if(!guiApp.fullScreenMode && 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 child.display.mutex = null;
1895 void UpdateScrollBars(bool flag, bool fullThing)
1898 bool resizeH = false, resizeV = false;
1899 bool scrolled = false;
1900 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1901 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1903 if(destroyed) return;
1904 if(guiApp.currentSkin)
1906 MinMaxValue cw = 0, ch = 0;
1907 bool sbvVisible = false, sbhVisible = false;
1908 int rangeH = 0, rangeV = 0;
1909 int positionH = 0, positionV;
1911 // First get client area with no respect to scroll bars
1916 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1918 if(scrollFlags.dontHide)
1921 cw -= guiApp.currentSkin.VerticalSBW();
1923 ch -= guiApp.currentSkin.HorizontalSBH();
1925 // Update the scrollbar visibility
1931 sbh.disabled = rangeH <= 1;
1932 if(sbh.style.hidden)
1942 sbv.disabled = rangeV <= 1;
1943 if(sbv.style.hidden)
1951 int oldHRange = sbh ? sbh.range : 0;
1952 int oldVRange = sbv ? sbv.range : 0;
1953 // Then start off with horizontal scrollbar range
1956 positionH = sbh.thumbPosition;
1963 SBSetTotal(sbh, rvw);
1966 ch -= guiApp.currentSkin.HorizontalSBH();
1969 // Do the same for vertical scrollbar
1972 positionV = sbv.thumbPosition;
1978 SBSetTotal(sbv, rvh);
1982 cw -= guiApp.currentSkin.VerticalSBW();
1983 // Maybe we need to set the range on the horizontal scrollbar again
1991 SBSetTotal(sbh, rvw);
1992 //sbh.Action(setRange, positionH, 0);
1993 if(rangeH <= 1 && sbh.range > 1)
1995 ch -= guiApp.currentSkin.HorizontalSBH();
2001 SBSetTotal(sbv, rvh);
2003 //sbv.Action(setRange, positionV, 0);
2008 if(sbh && sbh.range != oldHRange) sbh.Action(setRange, positionH, 0);
2009 if(sbv && sbv.range != oldVRange) sbv.Action(setRange, positionV, 0);
2012 // Update the scrollbar visibility
2013 if(!scrollFlags.dontHide)
2015 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
2019 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
2026 if(guiApp.currentSkin)
2033 sbhVisible = sbh.style.hidden ? true : false;
2035 sbvVisible = sbv.style.hidden ? true : false;
2037 // Do our resize here
2038 if(flag && (resizeH || resizeV) && fullThing)
2040 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
2045 OnResize(clientSize.w, clientSize.h);
2051 sbh.visible = sbhVisible;
2053 sbv.visible = sbvVisible;
2055 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
2056 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
2059 sbh.pageStep = clientSize.w;
2061 sbv.pageStep = clientSize.h;
2063 // Notify doesn't handle setRange anymore... process it here
2066 int positionH = sbh.thumbPosition;
2067 if(scroll.x != positionH)
2069 OnHScroll(setRange, positionH, 0);
2073 SNAPDOWN(positionH, textCellW);
2074 scroll.x = positionH;
2080 int seen = clientSize.w, total = reqScrollArea.w;
2083 if(scrollFlags.snapX)
2084 SNAPDOWN(seen, sbStep.x);
2086 if(!total) total = seen;
2087 range = total - seen + 1;
2089 range = Max(range, 1);
2091 if(x >= range) x = range - 1;
2093 if(scrollFlags.snapX)
2094 SNAPUP(x, sbStep.x);
2098 OnHScroll(setRange, x, 0);
2103 SNAPDOWN(x, textCellW);
2109 int positionV = sbv.thumbPosition;
2110 if(scroll.y != positionV)
2112 OnVScroll(setRange, positionV, 0);
2116 SNAPDOWN(positionV, textCellH);
2117 scroll.y = positionV;
2123 int seen = clientSize.h, total = reqScrollArea.h;
2126 if(scrollFlags.snapY)
2127 SNAPDOWN(seen, sbStep.y);
2129 if(!total) total = seen;
2130 range = total - seen + 1;
2131 range = Max(range, 1);
2133 if(y >= range) y = range - 1;
2135 if(scrollFlags.snapY)
2136 SNAPUP(y, sbStep.y);
2140 OnVScroll(setRange, y, 0);
2145 SNAPDOWN(y, textCellH);
2151 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2154 for(child = children.first; child; child = child.next)
2156 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2159 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2160 child.Position(x, y, w, h, false, true, false, true, false, false);
2167 // Process Scrollbars
2169 if(sbh) // && !sbh.style.hidden
2172 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2173 // Need to set the range again (should improve...) since the scrollbars didn't have
2174 // the right size when UpdateScrollArea set the range on it
2177 sbh.seen = clientSize.w;
2181 if(sbv) // && !sbv.state.hidden
2184 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2185 // Need to set the range again (should improve...) since the scrollbars didn't have
2186 // the right size when UpdateScrollArea set the range on it
2189 sbv.seen = clientSize.h;
2194 // TESTING THIS LOWER
2195 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2198 for(child = children.first; child; child = child.next)
2200 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2203 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2204 child.Position(x, y, w, h, false, true, false, true, false, false);
2210 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2212 SetState(maximized, false, mods);
2216 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2218 SetState(normal, false, mods);
2222 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2224 SetState(minimized, false, mods);
2225 parent.CycleChildren(false, true, false, true);
2229 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2232 // Scroll bar notifications
2233 if(action != setRange)
2235 bool changed = false;
2239 if(scroll.x != position)
2241 OnHScroll(action, position, keyFlags);
2246 SNAPDOWN(position, textCellW);
2248 scroll.x = position;
2252 if(scroll.y != position)
2254 OnVScroll(action, position, keyFlags);
2259 SNAPDOWN(position, textCellH);
2261 scroll.y = position;
2265 bool childMove = false;
2266 for(child = children.first; child; child = child.next)
2268 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2271 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2272 child.Position(x, y, w, h, false, true, false, true, false, false);
2276 // Testing this patch out to solve MDI workspace redraw bugs
2277 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2278 // Scroll offsets to blame?
2282 UpdateCaret(false, false);
2286 // Testing this patch out to solve MDI workspace redraw bugs
2287 for(child = children.first; child; child = child.next)
2289 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2298 Window GetParentMenuBar()
2300 Window menuBarParent;
2301 if(formDesigner) return null;
2302 for(menuBarParent = this ? parent : null; menuBarParent; menuBarParent = menuBarParent.parent)
2304 if(menuBarParent.menuBar) return menuBarParent.menuBar;
2305 if(menuBarParent && !menuBarParent.isActiveClient)
2311 void CreateSystemChildren(void)
2313 Window parent = this;
2314 bool scrollBarChanged = false;
2315 bool hasClose = false, hasMaxMin = false;
2316 Point scroll = this.scroll;
2318 if(state == maximized)
2320 parent = GetParentMenuBar();
2327 if(style.hasClose) hasClose = true;
2328 if(style.hasMaximize || style.hasMinimize)
2335 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2337 sysButtons[2].Destroy(0);
2338 sysButtons[2] = null;
2340 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2342 sysButtons[1].Destroy(0);
2343 sysButtons[1] = null;
2345 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2347 sysButtons[0].Destroy(0);
2348 sysButtons[0] = null;
2351 if(hasClose && parent)
2358 parent, master = this,
2359 inactive = true, nonClient = true, visible = false;
2361 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2367 if(this.parent == guiApp.desktop)
2368 sysButtons[2].hotKey = altF4;
2369 else if(style.isActiveClient)
2370 sysButtons[2].hotKey = ctrlF4;
2371 sysButtons[2].Create();
2374 sysButtons[2].symbol = 'X';
2375 sysButtons[2].disabled = !style.hasClose;
2378 if(hasMaxMin && parent)
2382 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2383 if(state == maximized)
2386 method = RestoreButtonClicked;
2392 method = MaximizeButtonClicked;
2400 parent, master = this,
2401 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2403 sysButtons[1].Create();
2405 sysButtons[1].NotifyClicked = method;
2407 sysButtons[1].symbol = symbol;
2408 sysButtons[1].disabled = !style.hasMaximize;
2411 if(hasMaxMin && parent)
2415 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2416 if (state == minimized)
2419 method = RestoreButtonClicked;
2425 method = MinimizeButtonClicked;
2433 parent, master = this,
2434 hotKey = altM, inactive = true, nonClient = true, visible = false
2436 sysButtons[0].Create();
2438 sysButtons[0].NotifyClicked = method;
2440 sysButtons[0].symbol = symbol;
2441 sysButtons[0].disabled = !style.hasMinimize;
2444 // Create the scrollbars
2445 if(style.hasHorzScroll && !sbh)
2451 direction = horizontal,
2455 snap = scrollFlags.snapX,
2456 NotifyScrolling = ScrollBarNotification
2459 scrollBarChanged = true;
2461 else if(sbh && !style.hasHorzScroll)
2467 if(style.hasVertScroll && !sbv)
2473 direction = vertical,
2477 snap = scrollFlags.snapY,
2478 NotifyScrolling = ScrollBarNotification
2481 scrollBarChanged = true;
2483 else if(sbv && !style.hasVertScroll)
2488 if(scrollBarChanged)
2490 SetScrollLineStep(sbStep.x, sbStep.y);
2491 UpdateScrollBars(true, true);
2495 if(scrollBarChanged)
2497 if(sbh) sbh.thumbPosition = scroll.x;
2498 if(sbv) sbv.thumbPosition = scroll.y;
2502 void UpdateCaption(void)
2504 if(rootWindow == this)
2507 FigureCaption(caption);
2508 if(guiApp.interfaceDriver)
2509 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2511 UpdateDecorations();
2514 if(parent.activeClient == this) // Added this last check
2516 if(parent.rootWindow == parent)
2519 parent.FigureCaption(caption);
2520 if(guiApp.interfaceDriver)
2521 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2524 parent.UpdateCaption();
2526 parent.UpdateDecorations();
2530 void UpdateActiveDocument(Window previous)
2532 Window activeClient = this.activeClient;
2533 Window activeChild = this.activeChild;
2540 activeClient.CreateSystemChildren();
2542 previous.CreateSystemChildren();
2554 // Build window list
2557 Menu windowMenu = menu.FindMenu("Window");
2562 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2564 Window document = cycle.data;
2565 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2567 char name[2048], caption[2048];
2568 document.FigureCaption(caption);
2569 sprintf(name, "%d %s", id+1, caption);
2570 windowMenu.AddDynamic(MenuItem
2572 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2573 NotifySelect = MenuWindowSelectWindow
2577 if(activeClient.cycle == cycle) break;
2582 if((!previous && activeClient) || !activeClient)
2588 item = menu.FindItem(MenuWindowCloseAll, 0);
2589 if(item) item.disabled = false;
2590 item = menu.FindItem(MenuWindowNext, 0);
2591 if(item) item.disabled = false;
2592 item = menu.FindItem(MenuWindowPrevious, 0);
2593 if(item) item.disabled = false;
2594 item = menu.FindItem(MenuWindowCascade, 0);
2595 if(item) item.disabled = false;
2596 item = menu.FindItem(MenuWindowTileHorz, 0);
2597 if(item) item.disabled = false;
2598 item = menu.FindItem(MenuWindowTileVert, 0);
2599 if(item) item.disabled = false;
2600 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2601 if(item) item.disabled = false;
2602 item = menu.FindItem(MenuWindowWindows, 0);
2603 if(item) item.disabled = false;
2606 item = menu.FindItem(MenuFileClose, 0);
2607 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2608 item = menu.FindItem(MenuFileSaveAll, 0);
2609 if(item) item.disabled = numDocuments < 1;
2611 if(activeClient && activeClient.menu && activeClient.state != minimized)
2615 //activeClient.menu.Clean(activeClient);
2616 menu.Merge(activeClient.menu, true, activeClient);
2620 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2623 menu.Merge(activeChild.menu, true, activeChild);
2626 // This is called again for a child window change, with same active client
2627 OnActivateClient(activeClient, previous);
2628 if(!menuBar && !((BorderBits)borderStyle).fixed && parent && parent.activeClient == this)
2629 parent.UpdateActiveDocument(null);
2632 void _ShowDecorations(Box box, bool post)
2634 if(rootWindow == this && nativeDecorations && !is3D) return;
2635 if(visible && this != guiApp.desktop)
2637 Surface surface = RedrawFull(box);
2641 FigureCaption(caption);
2644 ShowDecorations(captionFont.font,
2647 active, //parent.activeClient == this
2648 guiApp.windowMoving == this);
2650 PreShowDecorations(captionFont.font,
2653 active, //parent.activeClient == this
2654 guiApp.windowMoving == this);
2661 void UpdateExtent(Box refresh)
2663 Surface surface = null;
2665 if(!manageDisplay) { OnRedraw(null);return; }
2666 _ShowDecorations(refresh, false);
2668 surface = Redraw(refresh);
2669 // Opaque background: just fill before EW_REDRAW (clear?)
2672 surface.SetBackground(background);
2673 surface.SetForeground(foreground);
2674 surface.DrawingChar(' ');
2675 if(this == rootWindow)
2677 if(style.drawBehind || background.a)
2679 int a = background.a;
2680 // Premultiply alpha for clear color
2681 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2682 surface.Clear(colorBuffer);
2683 surface.SetBackground(background);
2686 else if(background.a)
2690 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2691 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2694 if(display.flags.alpha && background.a < 255 && background)
2696 surface.Area(0,0,clientSize.w, clientSize.h);
2697 /*if(style.clearDepthBuffer)
2698 surface.Clear(depthBuffer);*/
2700 else if(/*style.clearDepthBuffer || */background.a)
2702 int a = background.a;
2703 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2704 // Premultiply alpha for clear color
2705 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2706 surface.Clear(colorBuffer);
2707 surface.SetBackground(background);
2712 surface.TextFont(usedFont.font);
2713 surface.TextOpacity(false);
2717 // Draw the caret ...
2718 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2720 // surface.SetBackground(0xFFFFFF - background.color);
2721 surface.SetBackground(~background.color);
2723 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2724 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2730 void DrawOverChildren(Box refresh)
2732 Surface surface = Redraw(refresh);
2736 surface.DrawingChar(' ');
2737 surface.SetBackground(background);
2738 surface.SetForeground(foreground);
2740 surface.TextFont(usedFont.font);
2741 surface.TextOpacity(false);
2743 OnDrawOverChildren(surface);
2748 _ShowDecorations(refresh, true);
2751 void ComputeClipExtents(void)
2754 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2756 clipExtent.Copy(this.clipExtent);
2758 for(child = children.last; child; child = child.prev)
2760 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2762 bool opaque = child.IsOpaque(); // TODO: acess background directly
2763 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2765 child.clipExtent.Copy(clipExtent);
2766 child.clipExtent.Offset(-dx, -dy);
2767 child.clipExtent.IntersectBox(child.box);
2769 child.ComputeClipExtents();
2771 if(opaque && !child.style.nonClient)
2773 // Adjust the box for the parent:
2774 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2775 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2780 // ??? Only do this for overlapped window or if parent has with clip children flag
2782 // Do this if window has clip children flag on (default false?)
2783 // this.clipExtent = clipExtent;
2785 clipExtent.Free(null);
2788 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2791 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2792 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2794 offsetX -= rootWindow.clientStart.x;
2795 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2799 for(child = children.last; child; child = child.prev)
2801 bool opaque = child.IsOpaque();
2802 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2806 // Adjust renderArea to the root window level
2807 Extent * renderArea = &rootWindow.tempExtents[3];
2809 int offsetX = child.absPosition.x - rootWindow.absPosition.x;
2810 int offsetY = child.absPosition.y - rootWindow.absPosition.y;
2811 if(child.rootWindow.nativeDecorations && rootWindow.windowHandle)
2813 offsetX -= child.rootWindow.clientStart.x;
2814 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2818 Extent childRenderArea;
2820 if(backBufferUpdate != null)
2822 childRenderArea.Copy(backBufferUpdate);
2823 childRenderArea.Offset(-offsetX, -offsetY);
2826 childRenderArea.Copy(child.dirtyArea);
2828 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2829 renderArea.Copy(dirtyExtent);
2830 renderArea.Offset(-offsetX, -offsetY);
2831 childRenderArea.Union(renderArea);
2834 // Intersect with the clip extent
2835 childRenderArea.Intersection(child.clipExtent);
2838 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2840 // This intersection with child clip extent was missing and causing #708 (Installer components list scrolling bug):
2841 renderArea->Intersection(child.clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2843 renderArea->Offset(offsetX, offsetY);
2845 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2846 // overDirtyExtent.Union(renderArea);
2847 renderArea->Empty();
2848 // childRenderArea.Free();
2850 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2855 for(child = children.last; child; child = child.prev)
2857 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2859 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2864 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2866 bool opaque = IsOpaque();
2867 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2869 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2870 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2872 offsetX -= rootWindow.clientStart.x;
2873 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2877 for(child = children.last; child; child = child.prev)
2879 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2881 ColorAlpha background = *(ColorAlpha *)&child.background;
2882 bool opaque = child.IsOpaque();
2883 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2887 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2888 // Adjust renderArea to the root window level
2890 renderArea.Copy(child.dirtyArea);
2891 renderArea.Offset(offsetX, offsetY);
2892 dirtyExtent.Union(renderArea);
2893 overDirtyExtent.Union(renderArea);
2899 for(child = children.last; child; child = child.prev)
2901 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2903 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2907 if(backBufferUpdate != null)
2909 renderArea.Copy(backBufferUpdate);
2910 renderArea.Offset(-offsetX, -offsetY);
2912 overRenderArea.Copy(backBufferUpdate);
2913 overRenderArea.Offset(-offsetX, -offsetY);
2919 renderArea.Copy(dirtyArea);
2921 overRenderArea.Copy(dirtyArea);
2924 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2925 dirtyExtentWindow->Copy(dirtyExtent);
2926 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2927 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2928 dirtyExtentWindow->Empty();
2930 // Intersect with the clip extent
2931 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2934 if(renderArea.count > 10)
2937 printf("\nToo many extents (%d):\n", renderArea.count);
2939 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2940 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2945 for(c = 0; c<10; c++)
2948 FASTLIST_LOOP(renderArea, extentBox)
2950 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2952 renderArea.Copy(extent);
2954 FASTLIST_LOOP(renderArea, extentBox)
2957 printf("(%d, %d) - (%d, %d)\n",
2958 extentBox.box.left, extentBox.box.top,
2959 extentBox.box.right, extentBox.box.bottom);
2963 printf("\nNow %d\n", renderArea.count);
2969 // WHY WAS THIS COMMENTED ??
2971 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2972 dirtyExtentWindow->Copy(overDirtyExtent);
2973 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2974 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2975 dirtyExtentWindow->Empty();
2977 // Intersect with the clip extent
2978 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2984 if(scrollExtent.count)
2986 // Subtract render extent from scrolling extent
2987 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
2989 if(backBufferUpdate == null)
2991 Extent * dirty = &rootWindow.tempExtents[3];
2994 // Intersect scrolling extent with clip extent
2995 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2997 // offset this scroll to be at the root window level
2998 scrollExtent.Offset(offsetX, offsetY);
2999 // Add area that was scrolled to the dirty extents of the back buffer
3000 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
3004 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
3005 for(scrollBox = (BoxItem)scrollExtent.first; scrollBox; scrollBox = (BoxItem)scrollBox.next)
3006 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
3011 scrollExtent.Empty();
3013 // Add the exposed extent to the window render area
3014 dirty->Offset(-offsetX, -offsetY);
3015 renderArea.Union(dirty, rootWindow.tempExtents[0]);
3020 // Subtract the window's box from the transparency forced extent
3021 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
3027 renderArea.Copy(this.renderArea);
3028 renderArea.Offset(offsetX, offsetY);
3029 dirtyExtent.Union(renderArea);
3035 Extent renderArea { };
3037 renderArea.Copy(overRenderArea);
3038 renderArea.Offset(offsetX, offsetY);
3039 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
3044 if(backBufferUpdate != null)
3046 // Remove render area from dirty area
3047 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
3049 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
3056 // Remove the window render area from the dirty extents of the back buffer
3057 rootWindow.dirtyBack.Exclusion(renderArea);
3061 void Render(Extent updateExtent)
3065 Window rootWindow = this.rootWindow;
3066 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
3067 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
3069 offsetX -= rootWindow.clientStart.x;
3070 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
3073 if(rootWindow.fullRender)
3082 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
3083 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
3088 /*if(renderArea.count)
3089 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
3092 for(extentBox = (BoxItem)renderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
3094 Box box = extentBox.box;
3097 /*printf("(%d, %d) - (%d, %d)\n",
3098 extentBox.box.left, extentBox.box.top,
3099 extentBox.box.right, extentBox.box.bottom);*/
3104 box.left += offsetX;
3106 box.right += offsetX;
3107 box.bottom += offsetY;
3109 if(updateExtent != null)
3110 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
3114 for(child = children.first; child; child = child.next)
3115 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
3116 child.Render(updateExtent);
3118 if(rootWindow.fullRender)
3119 DrawOverChildren(box);
3122 // TO DO: There's an issue about draw over children...
3123 // TO DO: Don't wanna go through this if method isn't used
3124 for(extentBox = (BoxItem)overRenderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
3125 //FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
3127 Box box = extentBox.box;
3129 DrawOverChildren(box);
3131 box.left += offsetX;
3133 box.right += offsetX;
3134 box.bottom += offsetY;
3136 if(updateExtent != null)
3137 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
3140 for(child = children.first; child; child = child.next)
3141 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
3142 child.Render(updateExtent);
3145 overRenderArea.Empty();
3148 public void UpdateDisplay(void)
3150 if(!manageDisplay) { OnRedraw(null);return; }
3151 if(rootWindow && this != rootWindow)
3152 rootWindow.UpdateDisplay();
3155 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
3156 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
3159 dirtyExtent.Clear();
3162 clipExtent.AddBox(box);
3164 display.StartUpdate();
3166 if(!rootWindow.fullRender)
3168 ComputeClipExtents();
3169 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
3170 ComputeRenderArea(dirtyExtent, overExtent, null);
3173 clipExtent.Free(null);
3175 dirtyExtent.Free(null);
3176 overExtent.Free(null);
3178 if(display.flags.flipping)
3181 display.Update(null);
3185 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
3186 updateExtent.Clear();
3188 Render(updateExtent);
3190 updateExtent.UnionBox(this.box, tempExtents[0]);
3193 //printf("\n\nUpdate:\n------------------------------------------\n");
3196 //FASTLIST_LOOP(updateExtent, extentBox)
3197 for(extentBox = (BoxItem)updateExtent.first; extentBox; extentBox = (BoxItem)extentBox.next)
3200 /*printf("Updating (%d, %d) - (%d, %d)\n",
3201 extentBox.box.left, extentBox.box.top,
3202 extentBox.box.right, extentBox.box.bottom);*/
3205 display.Update(extentBox.box);
3208 updateExtent.Free(null);
3211 display.EndUpdate();
3219 void UpdateBackDisplay(Box box)
3225 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3227 //printf("UpdateBackDisplay going through!\n");
3228 display.StartUpdate();
3232 intersection.Copy(dirtyBack);
3233 intersection.IntersectBox(box);
3235 dirtyExtent.Clear();
3238 clipExtent.AddBox(box);
3240 if(!rootWindow.fullRender)
3242 ComputeClipExtents();
3243 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3246 clipExtent.Free(null);
3248 intersection.Free(null);
3249 dirtyExtent.Free(null);
3250 overExtent.Free(null);
3255 if(display.flags.flipping)
3256 display.Update(null);
3259 rootWindow.display.Update(box);
3262 display.EndUpdate();
3266 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3267 if(dirtyBack.count > MAX_DIRTY_BACK)
3269 BoxItem extentBox, next;
3270 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3271 for(extentBox = (BoxItem)dirtyBack.first; extentBox; extentBox = next)
3273 next = (BoxItem)extentBox.next;
3274 if(extentBox != first)
3276 if(extentBox.box.left < first.box.left)
3277 first.box.left = extentBox.box.left;
3278 if(extentBox.box.top < first.box.top)
3279 first.box.top = extentBox.box.top;
3280 if(extentBox.box.right > first.box.right)
3281 first.box.right = extentBox.box.right;
3282 if(extentBox.box.bottom > first.box.bottom)
3283 first.box.bottom = extentBox.box.bottom;
3284 dirtyBack.Delete(extentBox);
3293 // --- Window positioning ---
3294 // --- Window identification ---
3296 // Returns window at position "Position"
3297 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3299 Window child, result = null;
3301 box.left += absPosition.x;
3302 box.right += absPosition.x;
3303 box.top += absPosition.y;
3304 box.bottom += absPosition.y;
3306 if(!destroyed && visible && (acceptDisabled || !disabled))
3308 int lx = x - absPosition.x;
3309 int ly = y - absPosition.y;
3310 if(IsInside(lx, ly))
3311 // if(box.IsPointInside(Point{x, y}))
3313 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3314 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3317 bool isD = (last && last != this && last.IsDescendantOf(this)); // Fix for WSMS (#844)
3318 Window ancestor = null;
3320 for(ancestor = last; ancestor && ancestor.parent != this; ancestor = ancestor.parent);
3321 for(child = (isD ? (last != ancestor ? ancestor : ancestor.previous) : children.last); child; child = child.prev)
3323 if(child != statusBar && child.rootWindow == rootWindow)
3325 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3332 for(child = (isD ? (last != ancestor ? ancestor : ancestor.previous) : children.last); child; child = child.prev)
3334 if(child != statusBar && child.rootWindow == rootWindow)
3336 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3343 if(last && last != this && this.IsDescendantOf(last)) // Fix for installer lockup
3351 Window FindModal(void)
3353 Window modalWindow = this, check;
3354 Window check2 = null;
3355 for(check = this; check.master; check = check.master)
3357 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3359 modalWindow = check.master.modalSlave;
3360 check = modalWindow;
3362 // TESTING THIS FOR DROPBOX...
3363 if(!rootWindow || !rootWindow.style.interim)
3365 for(check2 = check; check2 /*.activeChild*/; check2 = check2.activeChild)
3367 if(check2.modalSlave && check2.modalSlave.created)
3369 modalWindow = check2.modalSlave;
3377 if(modalWindow == this)
3379 for(check = this; check.activeChild; check = check.activeChild)
3381 if(check.modalSlave)
3383 modalWindow = check.modalSlave;
3389 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3390 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3393 void StopMoving(void)
3395 if(this == guiApp.windowMoving)
3397 guiApp.windowMoving = null;
3398 UpdateDecorations();
3399 SetMouseRange(null);
3402 if(rootWindow.active)
3403 guiApp.interfaceDriver.StopMoving(rootWindow);
3405 guiApp.windowCaptured.ReleaseCapture();
3406 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3407 guiApp.windowIsResizing = false;
3411 void SelectMouseCursor(void)
3416 Window cursorWindow = null;
3417 bool rx, ry, rex, rey;
3419 guiApp.desktop.GetMousePosition(&x, &y);
3420 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3422 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3423 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[moving]);
3424 else if(mouseWindow)
3426 modalWindow = mouseWindow.FindModal();
3427 x -= mouseWindow.absPosition.x;
3428 y -= mouseWindow.absPosition.y;
3429 if(guiApp.windowIsResizing)
3431 rex = guiApp.resizeEndX;
3432 rey = guiApp.resizeEndY;
3433 rx = guiApp.resizeX;
3434 ry = guiApp.resizeY;
3435 if((rex && rey) || (rx && ry))
3436 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNWSE]);
3437 else if((rex && ry) || (rx && rey))
3438 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNESW]);
3439 else if((ry || rey) && (!rx && !rex))
3440 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNS]);
3441 else if((rx || rex) && (!ry && !rey))
3442 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeWE]);
3444 else if(!modalWindow && !guiApp.windowCaptured &&
3445 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3446 &rx, &ry, &rex, &rey))
3448 if((rex && rey) || (rx && ry))
3449 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNWSE]);
3450 else if((rex && ry) || (rx && rey))
3451 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNESW]);
3452 else if((ry || rey) && (!rx && !rex))
3453 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeNS]);
3454 else if((rx || rex) && (!ry && !rey))
3455 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[sizeWE]);
3457 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3459 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}) &&
3460 mouseWindow.rootWindow != mouseWindow)
3461 cursorWindow = mouseWindow.parent;
3463 cursorWindow = mouseWindow;
3465 else if(!guiApp.interimWindow)
3466 cursorWindow = guiApp.windowCaptured;
3469 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient && cursorWindow.rootWindow != cursorWindow; cursorWindow = cursorWindow.parent);
3470 guiApp.SetCurrentCursor(mouseWindow, cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3472 else if(modalWindow)
3474 guiApp.SetCurrentCursor(mouseWindow, guiApp.systemCursors[arrow]);
3476 else if(guiApp.interimWindow)
3478 if(guiApp.interimWindow.cursor)
3479 guiApp.SetCurrentCursor(mouseWindow, guiApp.interimWindow.cursor);
3481 guiApp.SetCurrentCursor(mouseWindow, mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3486 // --- State based input ---
3487 bool AcquireInputEx(bool state)
3492 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3493 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3495 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3497 guiApp.acquiredWindow = state ? this : null;
3500 SetMouseRangeToClient();
3501 guiApp.interfaceDriver.SetMouseCursor(guiApp.acquiredWindow, (SystemCursor)-1);
3506 SelectMouseCursor();
3508 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3512 // --- Window activation ---
3513 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3516 if(!parent || !parent.style.inactive)
3518 Window parent = this.parent;
3521 if(rootWindow == this)
3522 Log(active ? "active\n" : "inactive\n");
3524 if(active && requireRemaximize)
3526 if(state == maximized)
3528 property::state = normal;
3529 property::state = maximized;
3531 requireRemaximize = false;
3534 // Testing this here...
3535 if(!parent || parent == guiApp.desktop || parent.active)
3537 this.active = active;
3540 // TESTING THIS HERE
3541 UpdateDecorations();
3542 if((result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master))
3543 result = NotifyActivate(master, this, active, previous);
3546 this.active = !active;
3551 if(!parent || parent == guiApp.desktop || parent.active)
3553 this.active = active;
3555 AcquireInputEx(active);
3556 if(active && isEnabled)
3560 if(guiApp.caretOwner)
3564 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3565 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3566 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3567 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3569 guiApp.caretOwner.Update(extent);
3572 if(visible || !guiApp.caretOwner)
3573 guiApp.caretOwner = this;
3574 UpdateCaret(false, false);
3580 this.active = false;
3582 AcquireInputEx(active);
3584 if(!active && guiApp.caretOwner == this)
3586 UpdateCaret(false, true);
3587 guiApp.caretOwner = null;
3588 guiApp.interfaceDriver.SetCaret(0,0,0);
3589 guiApp.caretEnabled = false;
3594 if(!active && parent && parent.activeChild && parent.activeChild != this)
3595 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3601 if(!active && menuBar)
3604 menuBar.OnActivate(false, null, &goOn, true);
3605 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3610 Window aChild = activeChild;
3612 if(!aChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3624 void ConsequentialMouseMove(bool kbMoving)
3626 if(rootWindow && !noConsequential)
3628 if(kbMoving || !guiApp.windowMoving)
3632 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3634 if(guiApp.interfaceDriver)
3635 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3637 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3638 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3644 bool IsDescendantOf(Window ancestor)
3647 for(window = this; window && window != ancestor; window = window.parent);
3648 return window == ancestor;
3651 bool IsSlaveOf(Window master)
3654 for(window = this; window && window != master; window = window.master);
3655 return window == master;
3658 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3662 if(this && !destroyed /*&& state != Hidden*/)
3664 Window swap = externalSwap;
3672 if(activateParent &&
3673 (parent.activeChild != this ||
3674 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3675 active && _isModal &&
3676 parent != master && master)
3677 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3683 bool real = parent.activeChild != this;
3685 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3686 if(!style.inactive && /*activateParent && */guiApp.interimWindow &&
3687 !IsDescendantOf(guiApp.interimWindow) &&
3688 !IsSlaveOf(guiApp.interimWindow))
3690 Window interimWindow = guiApp.interimWindow;
3691 while(interimWindow && interimWindow != this)
3693 Window master = interimWindow.master;
3695 guiApp.interimWindow = null;
3696 if(guiApp.caretOwner)
3697 guiApp.caretOwner.UpdateCaret(false, false);
3699 incref interimWindow;
3700 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3705 delete interimWindow;
3706 interimWindow = (master && master.style.interim) ? master : null;
3711 guiApp.interimWindow = this;
3712 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3713 guiApp.caretEnabled = false;*/
3714 UpdateCaret(false, true);
3719 //bool acquireInput = false;
3721 parent.activeChild &&
3722 parent.activeChild.state == maximized &&
3723 parent != guiApp.desktop;
3725 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3730 swap = parent.activeChild;
3731 if(swap && swap.destroyed) swap = null;
3732 if(swap && swap != this)
3735 if(!swap.PropagateActive(false, this, &goOn, true))
3736 swap = parent.activeChild;
3747 if(!parent || parent.activeChild != this || style.interim)
3750 result = PropagateActive(true, swap, &goOn, true);
3751 if(!result && !goOn)
3756 //acquireInput = true;
3760 if(style.hasMaximize && parent != guiApp.desktop)
3763 SetState(maximized, false, 0);
3764 else if(state != maximized)
3767 for(child = parent.children.first; child; child = child.next)
3769 if(this != child && child.state == maximized)
3770 child.SetState(normal, false, 0);
3777 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3779 Window previous = parent.activeClient;
3780 parent.activeChild = this;
3781 if(!style.nonClient /*&& style.isActiveClient*/)
3785 if(style.isActiveClient)
3786 parent.activeClient = this;
3787 // Moved UpdateActiveDocument inside hidden check
3788 // To prevent activating previous window while creating a new one
3789 // (It was messing up the privateModule in the CodeEditor)
3790 parent.UpdateActiveDocument(previous);
3796 //if(!style.isRemote)
3798 if(rootWindow != this)
3800 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3801 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3803 else if(!guiApp.fullScreenMode)
3805 Window modalRoot = FindModal();
3806 if(!modalRoot) modalRoot = this;
3807 if(!modalRoot.isForegroundWindow)
3809 modalRoot.isForegroundWindow = true;
3810 // To check : Why is parent null?
3811 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3813 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3815 modalRoot.isForegroundWindow = false;
3820 if(result && real && (!style.inactive || moveInactive) && parent)
3822 Window last = parent.children.last;
3824 if(!style.stayOnTop)
3825 for(; last && last.style.stayOnTop; last = last.prev);
3827 parent.children.Move(this, last);
3829 // Definitely don't want that: why not?
3833 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3839 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3846 parent.activeChild = null;
3847 if(!style.nonClient /*&& style.isActiveClient*/)
3849 Window previous = parent.activeClient;
3850 if(style.isActiveClient)
3851 parent.activeClient = null;
3852 parent.UpdateActiveDocument(previous);
3856 if(this == guiApp.interimWindow)
3858 guiApp.interimWindow = null;
3859 if(guiApp.caretOwner)
3860 guiApp.caretOwner.UpdateCaret(false, false);
3862 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3869 if(!active || !swap)
3870 UpdateDecorations();
3872 swap.UpdateDecorations();
3874 if(active && rootWindow != this)
3875 ConsequentialMouseMove(false);
3882 // --- Input Messages ---
3883 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3885 static bool reEntrancy = false;
3886 if(reEntrancy) return;
3890 guiApp.cursorUpdate = true;
3891 if(guiApp.windowScrolling && !consequential)
3893 guiApp.windowScrolling.SetScrollPosition(
3894 (guiApp.windowScrolling.sbh) ?
3895 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3896 (guiApp.windowScrolling.sbv) ?
3897 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3899 if(guiApp.windowMoving)
3901 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3903 Window window = guiApp.windowMoving;
3905 int w = window.size.w;
3906 int h = window.size.h;
3911 rx = mouseX - guiApp.windowMovingStart.x;
3912 ry = mouseY - guiApp.windowMovingStart.y;
3915 window.GetDecorationsSize(&ew, &eh);
3917 if(guiApp.windowIsResizing)
3919 x = window.scrolledPos.x;
3920 y = window.scrolledPos.y;
3924 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3925 rx = guiApp.windowResizingBefore.w - aw;
3926 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3927 w = guiApp.windowResizingBefore.w - rx;
3931 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3932 ry = guiApp.windowResizingBefore.h - ah;
3933 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3934 ry = Max(ry, -guiApp.windowMovingBefore.y);
3935 h = guiApp.windowResizingBefore.h - ry;
3937 if(guiApp.resizeEndX)
3939 w = guiApp.windowResizingBefore.w + rx;
3942 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3950 w = Max(w, window.minSize.w);
3951 h = Max(h, window.minSize.h);
3952 w = Min(w, window.maxSize.w);
3953 h = Min(h, window.maxSize.h);
3955 if(!window.OnResizing(&w, &h))
3957 w = window.clientSize.w;
3958 h = window.clientSize.h;
3961 w = Max(w, window.skinMinSize.w);
3962 h = Max(h, window.skinMinSize.h);
3969 SNAPDOWN(w, textCellW);
3970 SNAPDOWN(h, textCellH);
3975 aw = Max(w,window.skinMinSize.w);
3976 rx = guiApp.windowResizingBefore.w - aw;
3977 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3978 w = guiApp.windowResizingBefore.w - rx;
3982 ah = Max(h,window.skinMinSize.h);
3983 ry = guiApp.windowResizingBefore.h - ah;
3984 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3985 ry = Max(ry, -guiApp.windowMovingBefore.y);
3986 h = guiApp.windowResizingBefore.h - ry;
3991 if(!guiApp.windowIsResizing || guiApp.resizeX)
3992 x = guiApp.windowMovingBefore.x + rx;
3993 if(!guiApp.windowIsResizing || guiApp.resizeY)
3994 y = guiApp.windowMovingBefore.y + ry;
3996 if(!guiApp.windowIsResizing)
3999 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
4001 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
4002 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
4003 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
4004 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
4008 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
4009 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
4015 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
4017 if(!window.OnMoving(&x, &y, w, h))
4019 x = window.scrolledPos.x;
4020 y = window.scrolledPos.y;
4026 SNAPDOWN(x, textCellW);
4027 SNAPDOWN(y, textCellH);
4030 if(!window.style.nonClient)
4032 if(!window.style.fixed /*|| window.style.isDocument*/)
4034 if(!window.style.dontScrollHorz)
4035 x += window.parent.scroll.x;
4036 if(!window.style.dontScrollVert)
4037 y += window.parent.scroll.y;
4041 // Break the anchors for moveable/resizable windows
4042 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
4043 if(window.style.fixed)
4045 if(window.state == normal)
4047 window.normalAnchor = Anchor { left = x, top = y };
4048 window.normalSizeAnchor = SizeAnchor { { w, h } };
4049 window.anchored = false;
4053 window.stateAnchor = Anchor { left = x, top = y };
4054 window.stateSizeAnchor = SizeAnchor { { w, h } };
4056 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
4057 // TOCHECK: Investigate why the following only redraws the scrollbars
4058 //window.Position(x, y, w, h, false, true, true, true, false, true);
4060 guiApp.movingLast.x = mouseX;
4061 guiApp.movingLast.y = mouseY;
4067 public bool MultiTouchMessage(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers * mods, bool consequential, bool activate)
4073 while(result && w != this)
4075 // TODO: How to handle this?
4078 Window msgWindow = GetAtPosition(x,y, false, true, w);
4083 window = (w && !w.disabled) ? w : null;
4085 if(consequential) mods->isSideEffect = true;
4086 if(!result || (window && window.destroyed)) window = null;
4090 if(window.OnMultiTouch && !window.disabled)
4092 Array<TouchPointerInfo> in { size = infos.size };
4093 memcpy(in.array, infos.array, sizeof(TouchPointerInfo) * infos.size);
4097 i.x -= (window.absPosition.x + window.clientStart.x);
4098 i.y -= (window.absPosition.y + window.clientStart.y);
4100 i.x = Max(Min(i.x, 32767),-32768);
4101 i.y = Max(Min(i.y, 32767),-32768);
4105 if(!window.OnMultiTouch(event, in, *mods))
4112 if(!result || !w || !w.clickThrough)
4120 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
4123 bool wasMoving = guiApp.windowMoving ? true : false;
4124 bool wasScrolling = guiApp.windowScrolling ? true : false;
4125 bool firstPass = true;
4127 while(result && w != this)
4129 Window msgWindow = GetAtPosition(x,y, false, true, w);
4130 Window trueWindow = GetAtPosition(x,y, false, false, w);
4131 bool windowDragged = false;
4136 window = (w && !w.disabled) ? w : null;
4138 if(trueWindow) incref trueWindow;
4140 if(consequential) mods->isSideEffect = true;
4142 UpdateMouseMove(x, y, consequential);
4144 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
4146 if(!guiApp.windowCaptured.isEnabled)
4147 guiApp.windowCaptured.ReleaseCapture();
4149 window = guiApp.windowCaptured;
4152 if(trueWindow && activate &&
4153 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
4154 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
4155 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
4156 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
4158 if(mods->alt && !mods->ctrl && !mods->shift)
4160 Window moved = trueWindow;
4161 for(moved = trueWindow; moved; moved = moved.parent)
4162 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
4167 windowDragged = true;
4169 // Cancel the ALT menu toggling...
4170 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4175 if(window && activate &&
4176 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
4177 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
4178 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
4179 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
4181 Window modalWindow = window.FindModal();
4183 /*if(mods->alt && !mods->shift && !mods->ctrl)
4185 Window moved = window;
4186 for(moved = window; moved; moved = moved.parent)
4187 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
4192 windowDragged = true;
4194 // Cancel the ALT menu toggling...
4195 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
4201 Window activateWindow = modalWindow ? modalWindow : window;
4202 if(activateWindow && !activateWindow.isRemote)
4204 bool doActivation = true;
4205 //bool needToDoActivation = false;
4206 Window check = activateWindow;
4208 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
4210 if(!check.style.inactive)
4212 //needToDoActivation = true;
4214 doActivation = false;
4219 if(!needToDoActivation)
4220 doActivation = false;
4223 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
4224 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
4226 // Let the OnLeftButtonDown do the activating instead
4227 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4235 incref activateWindow;
4236 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
4238 delete activateWindow;
4242 if(activateWindow._refCount == 1)
4244 delete activateWindow;
4248 delete activateWindow;
4249 // Trouble with clickThrough, siblings and activation (Fix for nicktick scrolling, siblings/activation endless loops, #844)
4252 mods->isActivate = true;
4256 if(!modalWindow && window && !window.destroyed)
4258 if(!guiApp.windowCaptured || windowDragged)
4260 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
4262 bool moving = ((window.state != maximized &&
4263 window.IsMouseMoving(
4264 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4265 || (guiApp.windowMoving && !guiApp.windowIsResizing);
4267 if(!moving && window.IsMouseResizing(
4268 x - window.absPosition.x,
4269 y - window.absPosition.y,
4270 window.size.w, window.size.h,
4271 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
4273 guiApp.windowIsResizing = true;
4274 guiApp.windowResizingBefore.w = window.size.w;
4275 guiApp.windowResizingBefore.h = window.size.h;
4277 if(guiApp.windowIsResizing || windowDragged || moving)
4280 guiApp.windowMoving = window;
4281 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4282 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4283 guiApp.windowMovingBefore.x = window.position.x;//s;
4284 guiApp.windowMovingBefore.y = window.position.y;//s;
4285 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4286 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4289 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4291 if(window.style.fixed &&
4293 window.IsMouseMoving(
4294 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4296 window.ShowSysMenu(x, y);
4300 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4302 if(window.sbv || window.sbh)
4305 guiApp.windowScrolling = window;
4306 guiApp.windowScrollingStart.x = x;
4307 guiApp.windowScrollingStart.y = y;
4308 guiApp.windowScrollingBefore.x = window.scroll.x;
4309 guiApp.windowScrollingBefore.y = window.scroll.y;
4312 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4314 if(window.style.hasMaximize &&
4315 window.IsMouseMoving(
4316 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4319 (window.state == maximized) ? normal : maximized, false, *mods);
4327 if(guiApp.windowMoving)
4329 if(guiApp.windowMoving.parent)
4331 if(guiApp.windowMoving.style.nonClient)
4332 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4334 guiApp.windowMoving.parent.SetMouseRangeToClient();
4338 window.UpdateDecorations();
4341 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4343 // Log("\n*** LEFT BUTTON UP ***\n");
4344 if(guiApp.windowMoving)
4345 guiApp.windowMoving.StopMoving();
4347 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4349 if(guiApp.windowScrolling)
4351 Window windowScrolling = guiApp.windowScrolling;
4352 guiApp.windowScrolling = null;
4353 windowScrolling.ReleaseCapture();
4357 if(!result || (window && window.destroyed)) window = null;
4359 if(window && window.FindModal())
4362 if(trueWindow && trueWindow.FindModal())
4370 msgWindow = GetAtPosition(x,y, true, false);
4372 msgWindow.SelectMouseCursor();
4375 if(firstPass && (guiApp.windowCaptured || trueWindow))
4377 Window prevWindow = guiApp.prevWindow;
4378 List<Window> overWindows = guiApp.overWindows;
4379 Iterator<Window> it { overWindows };
4384 if(trueWindow != w && !trueWindow.IsDescendantOf(w))
4387 result = w.OnMouseLeave(*mods);
4389 overWindows.TakeOut(w);
4393 if(result && guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4395 guiApp.prevWindow.mouseInside = false;
4396 guiApp.prevWindow = null;
4400 if(trueWindow.IsDescendantOf(prevWindow))
4402 if(!overWindows.Find(prevWindow))
4403 overWindows.Add(prevWindow);
4405 // Eventually fix this not to include captured?
4406 else if(!prevWindow.OnMouseLeave(*mods))
4410 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4412 Box box = trueWindow.box;
4413 box.left += trueWindow.absPosition.x;
4414 box.right += trueWindow.absPosition.x;
4415 box.top += trueWindow.absPosition.y;
4416 box.bottom += trueWindow.absPosition.y;
4418 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4420 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4421 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4423 overX = Max(Min(overX, 32767),-32768);
4424 overY = Max(Min(overY, 32767),-32768);
4426 trueWindow.mouseInside = true;
4427 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4431 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4433 for(w : guiApp.overWindows; w == trueWindow)
4436 guiApp.overWindows.TakeOut(w);
4439 guiApp.prevWindow = trueWindow;
4442 guiApp.prevWindow = null;
4444 SelectMouseCursor();
4446 if(window && ((!guiApp.windowMoving && !wasMoving) ||
4447 (wasMoving && guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp)) && !wasScrolling)
4449 int clientX = x - (window.absPosition.x + window.clientStart.x);
4450 int clientY = y - (window.absPosition.y + window.clientStart.y);
4452 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4454 clientX = Max(Min(clientX, 32767),-32768);
4455 clientY = Max(Min(clientY, 32767),-32768);
4457 MouseMethod = (void *)window._vTbl[method];
4459 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4462 if(!MouseMethod(window, clientX, clientY, *mods))
4466 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4467 window.OnMouseLeave(*mods);
4474 if(result && w && w.clickThrough && w.parent)
4479 if(!result || !w || !w.clickThrough)
4487 // --- Mouse cursor management ---
4489 bool KeyMessage(uint method, Key key, unichar character)
4494 if(guiApp.interimWindow)
4495 this = guiApp.interimWindow;
4498 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4502 if(!style.inactive || rootWindow != this)
4504 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4505 Window modalWindow = FindModal();
4506 Window interimMaster = master ? master.rootWindow : null;
4510 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4511 status = OnSysKeyDown(key, character);
4512 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4513 status = OnSysKeyHit(key, character);
4514 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4515 status = OnSysKeyUp(key, character);
4522 // Process Key Message for Internal UI Keyboard actions
4523 if(status && !destroyed && menuBar && state != minimized)
4526 if((SmartKey)key != alt)
4527 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4530 SmartKey sk = (SmartKey) key;
4531 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4533 status = menuBar.KeyMessage(method, key, character);
4538 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4539 menuBar.OnKeyHit(escape, 0);
4541 if(!menuBar.focus && guiApp.caretOwner)
4542 guiApp.caretOwner.UpdateCaret(true, false);
4545 if(!destroyed && status)
4547 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4551 case left: case up: case right: case down:
4552 if(guiApp.windowMoving == this)
4555 int w = guiApp.windowMoving.size.w;
4556 int h = guiApp.windowMoving.size.h;
4557 int x = guiApp.windowMoving.scrolledPos.x;
4558 int y = guiApp.windowMoving.scrolledPos.y;
4562 if(key == down || key == up)
4563 step = Max(step, textCellH);
4565 step = Max(step, textCellW);
4568 if(guiApp.windowIsResizing)
4572 case left: w-=step; break;
4573 case right: w+=step; break;
4574 case up: h-=step; break;
4575 case down: h+=step; break;
4582 case left: x-=step; break;
4583 case right: x+=step; break;
4584 case up: y-=step; break;
4585 case down: y+=step; break;
4589 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4590 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4592 if(!guiApp.windowIsResizing || guiApp.resizeX)
4593 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4595 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4597 if(!guiApp.windowIsResizing || guiApp.resizeY)
4598 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4600 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4602 guiApp.interfaceDriver.SetMousePosition(x, y);
4603 ConsequentialMouseMove(true);
4611 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4613 guiApp.windowMoving.StopMoving();
4614 ConsequentialMouseMove(false);
4622 ShowSysMenu(absPosition.x, absPosition.y);
4630 if(!destroyed && status && state != minimized)
4632 // Process all the way down the children
4633 if(activeChild && !activeChild.disabled)
4635 status = activeChild.KeyMessage(method, key, character);
4637 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4638 key.code != left && key.code != right && key.code != up && key.code != down)
4640 status = activeClient.KeyMessage(method, key, character);
4644 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4646 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4647 // && defaultControl != activeChild)
4649 delete previousActive;
4650 previousActive = activeChild;
4651 if(previousActive) incref previousActive;
4653 ConsequentialMouseMove(false);
4654 if((defaultControl.active ||
4655 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4656 defaultControl.KeyMessage(method, defaultKey, character);
4662 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4664 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4671 ShowSysMenu(absPosition.x, absPosition.y);
4678 if(this != guiApp.desktop)
4680 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4682 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4684 MenuMoveOrSize(key.shift, true);
4688 else if(guiApp.windowMoving)
4690 guiApp.windowMoving.StopMoving();
4691 ConsequentialMouseMove(false);
4699 if(!destroyed && status && state != minimized)
4701 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4705 case tab: case shiftTab:
4707 Window cycleParent = this;
4708 if(this == guiApp.interimWindow && master && !master.style.interim && !cycleParent.style.tabCycle && master.parent)
4709 cycleParent = master.parent;
4711 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4713 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4716 Window child = cycleParent.activeChild;
4718 // Scroll the window to include the active control
4719 if(cycleParent.sbh && !child.style.dontScrollHorz)
4721 if(child.scrolledPos.x < 0)
4722 cycleParent.sbh.Action(Position,
4723 cycleParent.scroll.x + child.scrolledPos.x, 0);
4724 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4725 cycleParent.sbh.Action(Position,
4726 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4728 if(cycleParent.sbv && !child.style.dontScrollVert)
4730 if(child.scrolledPos.y < 0)
4731 cycleParent.sbv.Action(Position,
4732 cycleParent.scroll.y + child.scrolledPos.y, 0);
4733 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4734 cycleParent.sbv.Action(Position,
4735 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4738 cycleParent.ConsequentialMouseMove(false);
4744 case f6: case shiftF6:
4745 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4747 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4748 if(parent == guiApp.desktop)
4749 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4759 if(CycleChildren(key.shift, true, false, true))
4767 // mIRC Style Window Shortcuts
4768 case alt1: case alt2: case alt3: case alt4: case alt5:
4769 case alt6: case alt7: case alt8: case alt9: case alt0:
4774 for(document = children.first; document; document = document.next)
4776 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4778 if(document == activeChild)
4780 if(document.state == minimized)
4781 document.SetState(normal, false, key);
4784 document.SetState(minimized, false, key);
4785 CycleChildren(false, true, false);
4790 if(activeChild.state == maximized && document.style.hasMaximize)
4791 document.SetState(maximized, false, key);
4792 else if(document.state == minimized)
4793 document.SetState(normal, false, key);
4794 document.Activate();
4809 if(!destroyed && status)
4811 if(state == minimized)
4816 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4818 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4820 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4821 previousActive.ActivateEx(true, false, false, true, null, null);
4822 delete previousActive;
4828 if(!destroyed && status)
4830 status = ProcessHotKeys(method, key, character);
4832 if(!destroyed && status && !modalWindow && state != minimized)
4835 status = KeyMethod(this, key, character);
4836 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4837 status = OnKeyHit(key, character);
4838 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4840 bool result = false;
4843 case ctrlUp: case ctrlDown:
4844 if(sbv && !guiApp.windowScrolling)
4845 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4847 case wheelUp: case wheelDown:
4848 if(sbv && !guiApp.windowScrolling)
4850 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4851 // Do we want to do a consequential move regardless of result in this case?
4852 ConsequentialMouseMove(false);
4855 case ctrlPageUp: case ctrlPageDown:
4856 if(sbh && !guiApp.windowScrolling)
4857 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4862 ConsequentialMouseMove(false);
4867 if(status && !destroyed && menuBar && state != minimized)
4868 status = menuBar.KeyMessage(method, key, character);
4870 if(style.interim && /*destroyed && */status && interimMaster)
4872 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4873 status = interimMaster.KeyMessage(method, key, character);
4880 bool ProcessHotKeys(uint method, Key key, unichar character)
4885 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4886 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4887 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4889 Window hotKeyWindow = hotKey.window;
4890 Window parent = hotKeyWindow.parent;
4891 Window prevActiveWindow = activeChild;
4892 // For when sys buttons are placed inside the menu bar
4893 if(parent && parent._class == class(PopupMenu))
4894 parent = parent.parent;
4896 // 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
4897 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1])))
4900 if(prevActiveWindow) incref prevActiveWindow;
4901 incref hotKeyWindow;
4902 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient && !hotKeyWindow.inactive)
4903 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4906 delete hotKeyWindow;
4907 delete prevActiveWindow;
4911 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4912 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4913 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4915 // ********* WORKING ON THIS ***********
4916 if(prevActiveWindow && !guiApp.interimWindow)
4917 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4920 else if(hotKeyWindow.style.inactive)
4921 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4923 delete prevActiveWindow;
4924 delete hotKeyWindow;
4925 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4926 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4930 if(status && tabCycle)
4933 for(child = children.first; child; child = child.next)
4935 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4946 // --- Windows and graphics initialization / termination ---
4947 bool SetupRoot(void)
4951 // Setup relationship with outside world (bb root || !bb)
4952 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4953 (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))
4957 tempExtents = new0 Extent[4];
4962 /*if(guiApp.fullScreenMode)
4963 rootWindow = guiApp.desktop;
4965 //rootWindow = parent.created ? parent.rootWindow : null;
4966 rootWindow = parent.rootWindow;
4969 against = &parent.box;
4971 against = &parent.clientArea;
4974 for(child = children.first; child; child = child.next)
4977 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
4980 bool Setup(bool positionChildren)
4982 bool result = false;
4985 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver))))
4987 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
4988 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
4991 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
4993 // This was here, is it really needed?
4994 //guiApp.interfaceDriver.ActivateRootWindow(this);
4998 displaySystem = DisplaySystem {};
4999 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
5001 delete displaySystem;
5006 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData };
5007 if(display.Create(displaySystem, windowHandle))
5014 // Sometimes icon does not show up on Windows XP if we set here...
5015 // guiApp.interfaceDriver.SetIcon(this, icon);
5017 else if(this != guiApp.desktop)
5019 display = rootWindow ? rootWindow.display : null;
5025 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
5026 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
5028 for(child = children.first; child; child = child.next)
5030 if(child.created && !child.Setup(false))
5033 if(guiApp.modeSwitching && guiApp.fullScreen && child.rootWindow == child)
5034 child.UpdateCaption();
5039 bool SetupDisplay(void)
5041 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
5042 if(is3D) return Window3D_SetupDisplay(this); else
5049 class_data void ** pureVTbl;
5051 bool LoadGraphics(bool creation, bool resetAnchors)
5053 bool result = false;
5054 bool success = false;
5056 WindowState stateBackup = state;
5058 if(((subclass(Window))_class).pureVTbl)
5060 if(_vTbl == _class._vTbl)
5062 _vTbl = ((subclass(Window))_class).pureVTbl;
5067 for(m = 0; m < _class.vTblSize; m++)
5069 if(_vTbl[m] == _class._vTbl[m])
5070 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5074 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
5076 if(_vTbl == ((subclass(Window))_class).pureVTbl)
5078 _vTbl = _class._vTbl;
5083 for(m = 0; m < _class.vTblSize; m++)
5085 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
5086 _vTbl[m] = _class._vTbl[m];
5091 if(guiApp.fullScreenMode || this != guiApp.desktop)
5093 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
5099 display.Lock(false);
5100 if(rootWindow == this)
5102 // Set Color Palette
5103 display.SetPalette(palette, true);
5107 if(guiApp.fullScreenMode && this == guiApp.desktop)
5112 for(c=0; c<SystemCursor::enumSize; c++)
5113 if(!guiApp.systemCursors[c].bitmap)
5115 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
5116 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
5117 if(guiApp.systemCursors[c].bitmapName)
5119 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
5120 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
5121 if(guiApp.systemCursors[c].bitmap)
5122 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
5127 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5129 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
5130 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
5132 cursor.bitmap.paletteShades = cursor.paletteShades;
5136 guiApp.cursorUpdate = true;
5139 ConsequentialMouseMove(false);
5145 // Load Window Graphic Resources
5148 if(usedFont == setFont || usedFont == window.systemFont)
5149 RemoveResource(usedFont);
5152 RemoveResource(setFont); // TESTING setFont instead of usedFont);
5155 RemoveResource(systemFont);
5158 RemoveResource(captionFont);
5160 for(ptr = resources.first; ptr; ptr = ptr.next)
5162 if(!ptr.loaded) // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
5163 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
5166 AddResource(setFont);
5168 AddResource(systemFont);
5170 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
5177 //if(master && master.font)
5178 if(parent && parent.font)
5182 faceName = parent.font.faceName,
5183 size = parent.font.size,
5184 bold = parent.font.bold,
5185 italic = parent.font.italic,
5186 underline = parent.font.underline
5188 //font = parent.font;
5189 watch(parent) { font { } };
5192 font = guiApp.currentSkin.SystemFont();
5199 captionFont = guiApp.currentSkin ? guiApp.currentSkin.CaptionFont() : null;
5200 AddResource(captionFont);
5202 if(OnLoadGraphics())
5208 //SetScrollLineStep(sbStep.x, sbStep.y);
5210 if(this != guiApp.desktop)
5214 normalAnchor = anchor;
5215 normalSizeAnchor = sizeAnchor;
5218 // Break the anchors for moveable/resizable windows
5220 if(style.fixed && style.isDocument)
5222 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
5234 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5235 stateSizeAnchor = SizeAnchor {};
5240 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5245 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
5246 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
5249 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5253 stateAnchor = normalAnchor;
5254 stateSizeAnchor = normalSizeAnchor;
5257 position = Point { };
5258 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5269 if(Position(x, y, w, h, true, false, true, true, true, true))
5271 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
5274 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
5291 success = result = true;
5294 if(!creation && result)
5296 // Load menu bar first because sys buttons are on it...
5299 if(!menuBar.LoadGraphics(false, resetAnchors))
5305 for(child = children.first; child; child = child.next)
5307 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
5314 CreateSystemChildren();
5318 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5321 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5324 LogErrorCode(graphicsLoadingFailed, _class.name);
5326 // Do this here to avoid problems on Windows
5327 if(rootWindow == this && parent && stateBackup == maximized)
5328 property::state = maximized;
5332 void UnloadGraphics(bool destroyWindows)
5336 // Free children's graphics
5337 for(child = children.first; child; child = child.next)
5338 child.UnloadGraphics(destroyWindows);
5341 display.Lock(false);
5344 if(guiApp.fullScreenMode && this == guiApp.desktop)
5349 for(c=0; c<SystemCursor::enumSize; c++)
5350 if(guiApp.systemCursors[c].bitmap)
5351 delete guiApp.systemCursors[c].bitmap;
5353 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5354 delete cursor.bitmap;
5356 guiApp.cursorBackground.Free();
5359 if(display && display.displaySystem)
5363 for(ptr = resources.first; ptr; ptr = ptr.next)
5367 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5372 // Free window graphics
5375 // Free skin graphics
5376 if(rootWindow == this)
5378 DisplaySystem displaySystem = display.displaySystem;
5381 display.driverData = null;
5382 display.displaySystem = null;
5386 if(displaySystem && !displaySystem.numDisplays && !is3D)
5387 delete displaySystem;
5396 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5397 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5399 if(this == guiApp.desktop || parent == guiApp.desktop)
5401 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5402 guiApp.interfaceDriver.DestroyRootWindow(this);
5406 // --- Window Hiding ---
5408 void SetVisibility(bool state)
5410 bool visible = (style.hidden || !created) ? false : state;
5411 if(visible != this.visible)
5415 this.visible = visible;
5416 for(child = children.first; child; child = child.next)
5417 child.SetVisibility(visible);
5419 ConsequentialMouseMove(false);
5420 if(parent && !nonClient) parent.OnChildVisibilityToggled(this, visible);
5424 // --- Windows and graphics initialization / termination ---
5426 bool DisplayModeChanged(void)
5428 bool result = false;
5429 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5431 guiApp.modeSwitching = true;
5432 UnloadGraphics(false);
5434 if(LoadGraphics(false, false))
5436 guiApp.modeSwitching = false;
5441 // --- Window updates system ---
5443 void UpdateDirty(Box updateBox)
5445 if(!manageDisplay) { OnRedraw(null);return; }
5448 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5451 if(display.flags.flipping)
5454 rootWindow.UpdateDisplay();
5457 UpdateBackDisplay(updateBox);
5459 if(guiApp.fullScreenMode)
5461 guiApp.cursorUpdate = true;
5462 guiApp.PreserveAndDrawCursor();
5464 if(guiApp.fullScreenMode)
5465 guiApp.RestoreCursorBackground();
5471 // This function is strictly called as a result of system window activation
5472 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5475 Window interimMaster = null;
5476 Window interimWindow = guiApp.interimWindow;
5477 if(interimWindow && interimWindow.master)
5478 interimMaster = interimWindow.master.rootWindow;
5480 if(active && state == minimized && window.parent) // && (!window.nativeDecorations || window.rootWindow != window)
5481 // SetState(normal, false, 0);
5482 SetState(lastState, false, 0);
5484 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5488 /* WTH is this doing here?
5489 while(swap && swap.activeChild)
5491 swap = swap.activeChild;
5494 // TESTING THIS BEFORE...
5495 if(interimWindow && this == interimMaster)
5499 // Window interimSwap = this;
5500 Window menuBar = this.menuBar;
5501 if(menuBar && interimWindow.master == menuBar)
5504 while(interimSwap && interimSwap.activeChild)
5505 interimSwap = interimSwap.activeChild;
5507 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5508 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5510 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5511 //result = ActivateEx(true, true, false, activateRoot, window, null);
5516 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5517 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5519 if(interimWindow == this && interimMaster && !active)
5521 while(interimMaster && interimMaster.interim && interimMaster.master)
5523 // printf("Going up one master %s\n", interimMaster._class.name);
5524 interimMaster = interimMaster.master.rootWindow;
5526 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5527 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5533 bool DestroyEx(int64 returnCode)
5536 Timer timer, nextTimer;
5538 OldLink prevOrder = null;
5539 Window client = null;
5541 if(parent) stopwatching(parent, font);
5543 // if(window.modalSlave) return false;
5544 if(destroyed || !created)
5551 OldLink slave = master.slaves.FindLink(this);
5552 master.slaves.Delete(slave);
5555 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5561 this.returnCode = (DialogResult)returnCode;
5563 AcquireInput(false);
5568 master.hotKeys.Delete(hotKey);
5572 if(guiApp.prevWindow == this)
5574 guiApp.prevWindow = null;
5579 for(w : guiApp.overWindows; w == this)
5582 guiApp.overWindows.TakeOut(w);
5586 if(guiApp.caretOwner == this)
5588 guiApp.interfaceDriver.SetCaret(0,0,0);
5589 UpdateCaret(false, true);
5590 guiApp.caretEnabled = false;
5595 parent.childrenCycle.Remove(cycle);
5599 OldLink tmpPrev = order.prev;
5600 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5601 prevOrder = tmpPrev;
5604 client = tmpPrev ? tmpPrev.data : null;
5605 if(client == this) { client = null; break; }
5606 if(client && (client.style.hidden || client.destroyed || !client.created))
5607 tmpPrev = client.order.prev;
5611 prevOrder = tmpPrev;
5616 // If this window can be an active client, make sure the next window we activate can also be one
5617 if(!style.nonClient && style.isActiveClient)
5619 tmpPrev = prevOrder;
5622 client = tmpPrev ? tmpPrev.data : null;
5623 if(client == this) { client = null; break; }
5624 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5625 tmpPrev = client.order.prev;
5629 prevOrder = tmpPrev;
5633 if(client && client.style.hidden) client = null;
5635 // parent.childrenOrder.Remove(order);
5638 if(parent && style.isActiveClient && visible)
5640 if(state == minimized) parent.numIcons--;
5641 parent.numPositions--;
5644 // TESTING THIS HERE!
5648 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5649 // to create a window inside a rootwindow that's being destroyed)
5650 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5652 if(master && !master.destroyed /*&&
5653 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5655 if(master.defaultControl == this)
5656 master.defaultControl = null;
5659 parent.OnChildAddedOrRemoved(this, true);
5660 if(parent && !parent.destroyed /*&&
5661 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5663 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5665 if(order && prevOrder && prevOrder.data != this && active)
5667 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5669 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5670 if(parent.activeClient == this)
5672 parent.activeClient = null;
5673 parent.UpdateActiveDocument(null);
5678 if(guiApp.interimWindow == this)
5681 PropagateActive(false, null, &goOn, true);
5685 //if(window.parent.activeChild == window)
5686 parent.activeChild = null;
5687 if(!style.nonClient /*&& style.isActiveClient*/)
5689 Window previous = parent.activeClient;
5690 if(style.isActiveClient)
5691 parent.activeClient = null;
5692 parent.UpdateActiveDocument(previous);
5697 else if(parent.activeClient == this)
5699 parent.activeClient = client;
5700 parent.UpdateActiveDocument(this);
5704 if(guiApp.interimWindow == this)
5706 guiApp.interimWindow = null;
5707 if(guiApp.caretOwner)
5709 Window desktop = guiApp.desktop;
5710 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5711 guiApp.caretOwner.UpdateCaret(false, false);
5716 if(_isModal && master && master.modalSlave == this)
5717 master.modalSlave = null;
5721 if(!guiApp.caretOwner && parent.caretSize)
5723 guiApp.caretOwner = parent;
5724 parent.UpdateCaret(false, false);
5725 parent.Update(null);
5728 // Why was this commented out?
5729 GetRidOfVirtualArea();
5735 dirtyArea.Free(null);
5736 dirtyBack.Free(null);
5737 scrollExtent.Free(null);
5739 /* ATTEMPTING TO MOVE THAT ABOVE
5748 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5749 for(;(child = window.children.first);)
5751 for(; child && (child.destroyed || !child.created); child = child.next);
5760 UnloadGraphics(true);
5763 delete previousActive;
5766 // statusBar = null;
5769 if(master && !master.destroyed)
5771 //master.NotifyDestroyed(this, this.returnCode);
5772 NotifyDestroyed(master, this, this.returnCode);
5775 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5777 nextTimer = timer.next;
5778 if(timer.window == this)
5780 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5781 // timer.window = null;
5787 if(this == guiApp.windowMoving)
5790 if(guiApp.windowCaptured == this)
5792 //guiApp.windowCaptured = null;
5794 if(rootWindow != this && rootWindow)
5795 rootWindow.ConsequentialMouseMove(false);
5803 //for(child = children.first; next = child ? child.next : null, child; child = next)
5804 for(;(child = children.first); )
5806 for(; child && (child.destroyed || !child.created); child = child.next);
5816 /* // MOVED THIS UP...
5819 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5820 for(;(child = window.children.first); )
5822 for(; child && (child.destroyed || !child.created); child = child.next);
5831 while((slave = slaves.first))
5833 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5835 ((Window)slave.data).DestroyEx(0);
5840 if(guiApp.caretOwner == this)
5841 guiApp.caretOwner = null;
5843 sysButtons[0] = null;
5844 sysButtons[1] = null;
5845 sysButtons[2] = null;
5848 if(rootWindow != this)
5850 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5853 box.left -= parent.clientStart.x;
5854 box.top -= parent.clientStart.y;
5855 box.right -= parent.clientStart.x;
5856 box.bottom -= parent.clientStart.y;
5858 if(parent) parent.Update(box);
5863 OldLink slave = master.slaves.FindVoid(this);
5864 master.slaves.Delete(slave);
5870 parent.children.Remove(this);
5875 //autoCreate = false;
5878 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5879 if(((subclass(Window))_class).pureVTbl)
5881 if(_vTbl == _class._vTbl)
5883 _vTbl = ((subclass(Window))_class).pureVTbl;
5888 for(m = 0; m < _class.vTblSize; m++)
5890 if(_vTbl[m] == _class._vTbl[m])
5891 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5900 void SetStateEx(WindowState newState, bool activate)
5903 WindowState prevState = state;
5907 if(prevState != newState)
5908 lastState = prevState;
5910 if(rootWindow != this || !nativeDecorations || !windowHandle)
5912 if(style.isActiveClient && !style.hidden && prevState == minimized)
5915 // This block used to be at the end of the function... moved it for flicker problem in X
5916 // ------------------------------------------------------
5920 stateAnchor = normalAnchor;
5921 stateSizeAnchor = normalSizeAnchor;
5924 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5925 stateSizeAnchor = SizeAnchor {};
5931 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5934 byte * idBuffer = new0 byte[size];
5936 for(child = parent.children.first; child; child = child.next)
5938 if(child != this && child.state == minimized)
5940 if(child.iconID > size - 2)
5942 idBuffer = renew0 idBuffer byte[size*2];
5943 memset(idBuffer + size, 0, size);
5946 idBuffer[child.iconID] = (byte)bool::true;
5949 for(c = 0; c<size; c++)
5954 if(style.isActiveClient && !style.hidden)
5957 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5958 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5963 // TOCHECK: Why was this here?
5964 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5965 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5966 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5968 if(state != minimized || hasMinimize)
5969 Position(x, y, w, h, true, true, true, true, false, true);
5971 if(!style.inactive && !style.interim && parent && this == parent.activeClient)
5972 parent.UpdateActiveDocument(null);
5975 if(state != minimized || hasMinimize)
5976 CreateSystemChildren();
5977 // ------------------------------------------------------
5980 int GetPositionID(Window forChild)
5984 byte * idBuffer = new0 byte[size];
5987 for(child = children.first; child; child = child.next)
5989 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
5991 if(child.positionID > size - 2)
5993 idBuffer = renew0 idBuffer byte[size*2];
5994 memset(idBuffer + size, 0, size);
5997 idBuffer[child.positionID] = (byte)bool::true;
6000 for(c = 0; c<size; c++)
6007 // --- Window related graphics ---
6009 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
6011 palette = newPalette;
6012 if(rootWindow.display)
6013 rootWindow.display.SetPalette(palette, colorMatch);
6016 public bool AcquireInput(bool acquired)
6019 if(acquiredInput != acquired)
6021 if(active || (!visible && creationActivation == activate))
6022 result = AcquireInputEx(acquired);
6027 acquiredInput = acquired ? result : !result;
6032 void ListChildren(ListBox listBox)
6036 for(child = children.first; child; child = child.next)
6038 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
6040 DataRow row = listBox.AddRow();
6041 row.tag = (int64)(intptr)child;
6042 child.FigureCaption(caption);
6043 row.SetData(null, caption);
6048 void UpdateVisual(Box extent)
6050 if(guiApp.driver != null)
6052 if(guiApp.fullScreenMode && guiApp.desktop.display)
6054 guiApp.desktop.mutex.Wait();
6055 guiApp.desktop.display.Lock(true);
6058 if(guiApp.desktop.active)
6060 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
6062 if(guiApp.desktop.display.flags.flipping)
6063 guiApp.desktop.Update(null);
6064 guiApp.desktop.UpdateDisplay();
6065 guiApp.cursorUpdate = true;
6067 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
6069 guiApp.PreserveAndDrawCursor();
6070 // guiApp.desktop.display.ShowScreen();
6071 guiApp.cursorUpdate = false;
6072 guiApp.desktop.dirty = false;
6073 guiApp.RestoreCursorBackground();
6077 guiApp.desktop.display.Unlock();
6078 guiApp.desktop.mutex.Release();
6082 Window rootWindow = this.rootWindow;
6083 rootWindow.mutex.Wait();
6088 guiApp.SignalEvent();
6091 guiApp.waitMutex.Wait();
6092 guiApp.interfaceDriver.Lock(rootWindow);
6093 if(!rootWindow.style.hidden && rootWindow.dirty)
6095 if(rootWindow.display)
6097 rootWindow.UpdateDisplay();
6098 //rootWindow.display.ShowScreen(null);
6100 rootWindow.dirty = false;
6102 guiApp.interfaceDriver.Unlock(rootWindow);
6103 guiApp.waitMutex.Release();
6106 rootWindow.mutex.Release();
6111 void UnlockDisplay(void)
6113 guiApp.interfaceDriver.Unlock(rootWindow);
6116 void LockDisplay(void)
6118 guiApp.interfaceDriver.Lock(rootWindow);
6121 Surface GetSurface(Box box)
6123 return Redraw((box == null) ? this.box : box);
6126 void SetMousePosition(int x, int y)
6128 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
6132 void IntegrationActivate(bool active)
6134 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
6136 isForegroundWindow = true;
6137 ActivateEx(active, active, false, false, null, null);
6138 isForegroundWindow = false;
6143 Window QueryCapture(void)
6145 return guiApp.windowCaptured;
6148 int GetDocumentID(void)
6152 byte * idBuffer = new0 byte[size];
6155 for(child = children.first; child; child = child.next)
6157 // TO CHECK: Do we want a documentID when we already have a file name?
6158 if(child.style.isDocument && !child.fileName)
6160 if(child.documentID-1 > size - 2)
6162 idBuffer = renew0 idBuffer byte[size*2];
6163 memset(idBuffer + size, 0, size);
6166 idBuffer[child.documentID-1] = 1;
6169 for(c = 0; c<size; c++)
6177 void SetInitSize(Size size)
6180 sizeAnchor.size = size;
6181 normalSizeAnchor = sizeAnchor;
6183 // Break the anchors for moveable/resizable windows
6184 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6186 stateAnchor = normalAnchor;
6187 stateSizeAnchor = normalSizeAnchor;
6189 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6190 Position(x,y, w, h, true, true, true, true, false, true);
6194 void MenuMoveOrSize(bool resize, bool setCursorPosition)
6196 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
6198 guiApp.windowIsResizing = resize;
6199 guiApp.windowMoving = this;
6200 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
6201 if(guiApp.windowIsResizing)
6203 guiApp.windowMovingStart.x += size.w - 1;
6204 guiApp.windowMovingStart.y += size.h - 1;
6206 guiApp.windowMovingBefore = scrolledPos;
6207 guiApp.windowResizingBefore = size;
6208 guiApp.windowMoving.UpdateDecorations();
6209 if(guiApp.windowIsResizing)
6210 guiApp.resizeEndX = guiApp.resizeEndY = true;
6212 if(setCursorPosition)
6213 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
6217 guiApp.interfaceDriver.GetMousePosition(&x, &y);
6218 guiApp.windowMovingStart.x += x - absPosition.x;
6219 guiApp.windowMovingStart.y += y - absPosition.y;
6222 if(guiApp.windowMoving)
6224 if(guiApp.windowMoving.style.nonClient)
6225 guiApp.windowMoving.parent.SetMouseRangeToWindow();
6227 guiApp.windowMoving.parent.SetMouseRangeToClient();
6232 if(this == rootWindow)
6233 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
6237 void SetupFileMonitor()
6241 fileMonitor = FileMonitor
6243 this, FileChange { modified = true };
6245 bool OnFileNotify(FileChange action, const char * param)
6248 fileMonitor.StopMonitoring();
6249 if(OnFileModified(action, param))
6250 fileMonitor.StartMonitoring();
6263 bool result = false;
6267 else if(guiApp && guiApp.driver != null)
6269 OldLink slaveHolder;
6271 bool visible = !style.hidden;
6275 systemParent = parent;
6276 parent = guiApp.desktop;
6278 last = parent ? parent.children.last : null;
6280 if((parent && parent != guiApp.desktop && !parent.created) ||
6281 (master && master != guiApp.desktop && !master.created))
6285 stopwatching(parent, font);
6288 property::parent = guiApp.desktop;
6289 if(!master) master = parent;
6291 if(_isModal && master.modalSlave)
6292 property::master = master.modalSlave;
6296 parent.children.Remove(this);
6299 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
6300 if(slaveHolder.data == this)
6302 master.slaves.Delete(slaveHolder);
6307 if(parent == guiApp.desktop && !mutex)
6310 if(style.isDocument)
6313 parent.numDocuments--;
6314 documentID = parent.GetDocumentID();
6317 if(!style.stayOnTop)
6318 for(; last && last.style.stayOnTop; last = last.prev);
6320 parent.children.Insert((last == this) ? null : last, this);
6321 //parent.children.Add(this);
6324 dispDriver = parent.dispDriver;
6327 master.modalSlave = this;
6329 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
6334 master.slaves.Add(slaveHolder = OldLink { data = this });
6339 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
6341 if(style.isDefault && !master.defaultControl)
6342 master.defaultControl = this;
6344 stateAnchor = normalAnchor = anchor;
6345 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
6347 // TOCHECK: Why is this here?
6348 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
6349 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
6351 this.visible = false;
6352 style.hidden = true;
6355 // autoCreate = true;
6363 if(parent == guiApp.desktop)
6364 Log("LoadGraphics %s\n", caption);
6366 if(LoadGraphics(true, false))
6374 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6381 if(style.hasMenuBar /*&& menu*/)
6387 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6388 interim = false, inactive = true, nonClient = true, size.h = 24
6396 // Create the system buttons
6397 CreateSystemChildren();
6399 UpdateActiveDocument(null);
6401 if(style.isDocument)
6405 MenuItem item = menu.FindItem(MenuFileSave, 0);
6406 if(item) item.disabled = !modifiedDocument && fileName;
6411 if(parent == guiApp.desktop)
6412 Log("Preemptive SetState %s\n", caption);
6415 // Preemptive Set State to ensure proper anchoring
6416 SetStateEx(state, false);
6418 style.hidden = true;
6424 for(child = children.first; child; child = next)
6427 if(!child.created && (child.autoCreate || child.wasCreated))
6434 for(link = slaves.first; link; link = next)
6436 Window slave = link.data;
6438 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6441 // Things might have happened that invalidated 'next'...
6442 // Start over the search for slaves to create.
6443 // (Added this to fix crash with Stacker & Toolbar)
6444 next = slaves.first;
6453 if(parent == guiApp.desktop)
6454 Log("Real SetState %s\n", caption);
6457 if(isActiveClient && visible)
6459 parent.numPositions--;
6460 if(state == minimized) parent.numIcons--;
6463 parent.OnChildAddedOrRemoved(this, false);
6465 if(rootWindow == this && visible) // So that X11 windows don't show as 'unknown'
6467 // Real set state & activate for proper display & activation
6468 property::visible = visible;
6469 // SetState(state & 0x00000003, true, 0);
6470 guiApp.interfaceDriver.SetIcon(this, icon);
6475 /*if(rootWindow == this)
6476 guiApp.interfaceDriver.ActivateRootWindow(this);
6478 if(creationActivation == activate && guiApp.desktop.active)
6479 ActivateEx(true, false, true, true, null, null);
6480 else if(creationActivation == activate || creationActivation == flash)
6483 if(this == rootWindow)
6488 if(!destroyed && !noConsequential)
6489 rootWindow.ConsequentialMouseMove(false);
6500 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6506 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6508 //style.hidden = true; // !visible;
6509 style.hidden = !visible;
6510 if(master.modalSlave == this)
6511 master.modalSlave = null;
6518 void WriteCaption(Surface surface, int x, int y)
6521 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6524 void Update(Box region)
6530 rootWindow = this.rootWindow;
6532 // rootWindow.mutex.Wait();
6533 if(!destroyed && visible && display)
6538 // Testing this to avoid repetitve full update to take time...
6539 if(rootWindow.fullRender)
6541 rootWindow.dirty = true;
6544 if(dirtyArea.count == 1)
6546 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6547 if(item.box.left <= box.left &&
6548 item.box.top <= box.top &&
6549 item.box.right >= box.right &&
6550 item.box.bottom >= box.bottom)
6552 rootWindow.dirty = true;
6557 if(display.flags.flipping && !rootWindow.dirty)
6559 if(this == rootWindow)
6563 rootWindow.Update(null);
6568 rootWindow.dirty = true;
6573 realBox.left += clientStart.x;
6574 realBox.top += clientStart.y;
6575 realBox.right += clientStart.x;
6576 realBox.bottom += clientStart.y;
6582 if(realBox.right >= realBox.left &&
6583 realBox.bottom >= realBox.top)
6585 // if(!rootWindow.fullRender)
6586 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6588 for(child = children.first; child; child = child.next)
6593 box.left -= child.absPosition.x - absPosition.x;
6594 box.top -= child.absPosition.y - absPosition.y;
6595 box.right -= child.absPosition.x - absPosition.x;
6596 box.bottom -= child.absPosition.y - absPosition.y;
6597 if(box.right >= child.box.left && box.left <= child.box.right &&
6598 box.bottom >= child.box.top && box.top <= child.box.bottom)
6600 box.left -= child.clientStart.x;
6601 box.top -= child.clientStart.y;
6602 box.right -= child.clientStart.x;
6603 box.bottom -= child.clientStart.y;
6609 realBox.left += absPosition.x - rootWindow.absPosition.x;
6610 realBox.top += absPosition.y - rootWindow.absPosition.y;
6611 realBox.right += absPosition.x - rootWindow.absPosition.x;
6612 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6613 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6616 else if(this == guiApp.desktop)
6619 for(window = children.first; window; window = window.next)
6625 Box childBox = region;
6627 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6628 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6629 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6630 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6632 window.Update(childBox);
6635 window.Update(null);
6640 // rootWindow.mutex.Release();
6647 if(guiApp.windowCaptured != this)
6649 if(guiApp.windowCaptured)
6653 //Logf("Captured %s (%s)\n", caption, class.name);
6654 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6655 guiApp.windowCaptured = this;
6661 bool Destroy(int64 code)
6666 if(!destroyed && !CloseConfirmation(false)) return false;
6670 // TOCHECK: Should autoCreate be set to false here?
6681 void Move(int x, int y, int w, int h)
6683 normalAnchor = Anchor { left = x, top = y };
6684 normalSizeAnchor = SizeAnchor { size = { w, h } };
6686 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6688 if(destroyed) return;
6690 stateAnchor = normalAnchor;
6691 stateSizeAnchor = normalSizeAnchor;
6693 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6694 Position(x,y, w, h, true, true, true, true, false, true);
6698 DialogResult Modal(void)
6704 // FIXES MEMORY LEAK IF Create() FAILED
6710 void SetScrollArea(int width, int height, bool snapToStep)
6714 int stepX = sbStep.x, stepY = sbStep.y;
6715 // Needed to make snapped down position match the skin's check of client area
6716 // against realvirtual
6719 SNAPDOWN(stepX, textCellW);
6720 SNAPDOWN(stepY, textCellH);
6721 stepX = Max(stepX, textCellW);
6722 stepY = Max(stepY, textCellH);
6724 if(scrollFlags.snapX)
6725 SNAPUP(width, stepX);
6726 if(scrollFlags.snapY)
6727 SNAPUP(height, stepY);
6730 reqScrollArea.w = width;
6731 reqScrollArea.h = height;
6732 noAutoScrollArea = (width > 0 || height > 0);
6734 UpdateScrollBars(true, true);
6737 void SetScrollPosition(int x, int y)
6740 sbh.Action(setPosition, x, 0);
6744 int seen = clientSize.w, total = reqScrollArea.w;
6746 if(scrollFlags.snapX)
6747 SNAPDOWN(seen, sbStep.x);
6749 if(!total) total = seen;
6750 range = total - seen + 1;
6751 range = Max(range, 1);
6753 if(x >= range) x = range - 1;
6755 if(scrollFlags.snapX)
6756 SNAPUP(x, sbStep.x);
6759 OnHScroll(setPosition, x, 0);
6763 SNAPDOWN(x, textCellW);
6769 sbv.Action(setPosition, y, 0);
6773 int seen = clientSize.h, total = reqScrollArea.h;
6776 if(scrollFlags.snapY)
6777 SNAPDOWN(seen, sbStep.y);
6779 if(!total) total = seen;
6780 range = total - seen + 1;
6781 range = Max(range, 1);
6783 if(y >= range) y = range - 1;
6785 if(scrollFlags.snapY)
6786 SNAPUP(y, sbStep.y);
6789 OnVScroll(setPosition, y, 0);
6792 SNAPDOWN(y, textCellH);
6797 UpdateCaret(false, false);
6800 void SetScrollLineStep(int stepX, int stepY)
6806 SNAPDOWN(stepX, textCellW);
6807 SNAPDOWN(stepY, textCellH);
6808 stepX = Max(stepX, textCellW);
6809 stepY = Max(stepY, textCellH);
6812 sbh.lineStep = stepX;
6814 sbv.lineStep = stepY;
6817 void SetState(WindowState newState, bool activate, Modifiers mods)
6821 if(state == newState || OnStateChange(newState, mods))
6823 //WindowState prevState = state;
6827 // This used to be at the end of the brackets... moved for X, testing...
6828 // This has the effect of activating the window through the system...
6829 if(rootWindow == this)
6830 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6832 SetStateEx(newState, activate);
6834 if(rootWindow == this && !rootWindow.nativeDecorations)
6836 int x = position.x, y = position.y;
6839 x -= guiApp.desktop.absPosition.x;
6840 y -= guiApp.desktop.absPosition.y;
6842 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6846 //state = prevState;
6848 if(state != maximized && style.hasMaximize)
6851 for(child = parent.children.first; child; child = child.next)
6853 if(child != this && child.state == maximized)
6854 child.SetStateEx(normal, false);
6858 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6859 parent.UpdateScrollBars(true, true);
6862 // Do we really need this stuff here?
6863 // Shouldn't the Activate stuff take care of it?
6864 if(parent.rootWindow == parent && style)
6867 parent.FigureCaption(caption);
6868 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6869 parent.UpdateDecorations();
6873 rootWindow.ConsequentialMouseMove(false);
6880 BitmapResource GetIcon(SkinBitmap iconID)
6882 return guiApp.currentSkin.GetBitmap(iconID);
6885 void SetMouseRange(Box range)
6887 if(range || guiApp.fullScreenMode)
6892 clip.left = range.left + absPosition.x + clientStart.x;
6893 clip.top = range.top + absPosition.y + clientStart.y;
6894 clip.right = range.right + absPosition.x + clientStart.x;
6895 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6899 clip.left = guiApp.desktop.box.left;
6900 clip.top = guiApp.desktop.box.top;
6901 clip.right = guiApp.desktop.box.right;
6902 clip.bottom = guiApp.desktop.box.bottom;
6904 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6907 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6910 void SetMouseRangeToClient(void)
6912 if(guiApp.fullScreenMode || this != guiApp.desktop)
6914 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6915 box.Clip(clientArea);
6919 SetMouseRange(null);
6922 void SetMouseRangeToWindow(void)
6924 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6925 if(this == guiApp.desktop)
6926 SetMouseRangeToClient();
6931 // x, y: Desktop Coordinates
6932 void ShowSysMenu(int x, int y)
6935 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6938 menu, $"Restore", r, NotifySelect = MenuWindowRestore,
6939 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6943 menu, $"Move", m, NotifySelect = MenuWindowMove,
6944 disabled = !style.fixed || state == maximized
6948 menu, $"Size", s, NotifySelect = MenuWindowSize,
6949 disabled = !style.sizable || state != normal
6953 menu, $"Minimize", n, NotifySelect = MenuWindowMinimize,
6954 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6958 menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6959 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6963 menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6964 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6966 MenuDivider { menu };
6969 menu, $"Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6970 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6972 windowMenu.Create();
6977 ActivateEx(true, true, true, true, null, null);
6980 void MakeActive(void)
6982 ActivateEx(true, false, true, false, null, null);
6985 void SoftActivate(void)
6987 if(guiApp.desktop.active)
6992 if(this == rootWindow)
6997 void Deactivate(void)
6999 ActivateEx(false, true, true, true, null, null);
7004 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
7007 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
7009 bool result = false;
7010 if(activeChild && activeChild.cycle)
7012 Window modalWindow, child = activeChild;
7013 if(!clientOnly /*&& parent.tabCycle*/)
7015 Window next = child;
7018 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
7022 if(parent && parent.CycleChildren(backward, false, true, true))
7030 next = next.cycle.prev.data;
7032 next = next.cycle.next.data;
7033 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
7038 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
7039 parent.tabCycle && parent.CycleChildren(backward, false, false))
7043 if(tabCycleOnly && !tabCycle) return false;
7050 child = child.cycle.prev.data;
7052 child = child.cycle.next.data;
7053 if(child == child.parent.activeChild)
7055 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
7058 modalWindow = child.FindModal();
7061 // Scroll the window to include the active control
7062 if(sbh && !child.style.dontScrollHorz)
7064 if(child.scrolledPos.x < 0)
7065 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
7066 else if(child.scrolledPos.x + child.size.w > clientSize.w)
7067 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
7069 if(sbv && !child.style.dontScrollVert)
7071 if(child.scrolledPos.y < 0)
7072 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
7073 else if(child.scrolledPos.y + child.size.h > clientSize.h)
7074 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
7078 child = modalWindow ? modalWindow : child;
7079 child.ActivateEx(true, true, true, true, null, null);
7080 if(child.tabCycle && child.childrenCycle.first)
7081 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
7089 ConsequentialMouseMove(false);
7093 void AddResource(Resource resource)
7097 ResPtr ptr { resource = resource };
7101 // Load Graphics here if window is created already
7102 if(/*created && */display)
7104 display.Lock(false);
7105 if(!ptr.loaded) // This check prevents a leak in case a watcher on 'font' calls AddResource (ListBox FontResource leak)
7106 ptr.loaded = display.displaySystem.LoadResource(resource);
7110 // Temporary hack to load font right away for listbox in dropbox ...
7111 else if(master && master.display)
7113 master.display.Lock(false);
7114 master.display.displaySystem.LoadResource(resource);
7115 master.display.Unlock();
7121 void RemoveResource(Resource resource)
7126 for(ptr = resources.first; ptr; ptr = ptr.next)
7128 if(ptr.resource == resource)
7134 // Unload Graphics here if window is created already
7135 if(/*created && */display)
7139 display.Lock(false);
7140 display.displaySystem.UnloadResource(resource, ptr.loaded);
7146 resources.Delete(ptr);
7151 void SetCaret(int x, int y, int size)
7158 if(active && !style.interim && isEnabled)
7160 if(visible || !guiApp.caretOwner)
7161 guiApp.caretOwner = size ? this : null;
7163 UpdateCaret(false, false);
7166 guiApp.interfaceDriver.SetCaret(0,0,0);
7167 UpdateCaret(false, true);
7168 guiApp.caretEnabled = false;
7171 else if(style.inactive && active)
7173 guiApp.interfaceDriver.SetCaret(0,0,0);
7174 UpdateCaret(false, true);
7175 guiApp.caretEnabled = false;
7180 void Scroll(int x, int y)
7182 bool opaque = !style.drawBehind || background.a;
7183 if(opaque && display && display.flags.scrolling)
7185 Box box = clientArea;
7186 box.left += clientStart.x;
7187 box.top += clientStart.y;
7188 box.right += clientStart.x;
7189 box.bottom += clientStart.y;
7191 //scrollExtent.Free(null);
7192 scrollExtent.AddBox(box);
7193 scrolledArea.x += x;
7194 scrolledArea.y += y;
7196 //scrollExtent.Free();
7197 //scrollExtent.AddBox(clientArea);
7198 //scrollExtent.Offset(clientStart.x, clientStart.y);
7199 //scrolledArea.x = x;
7200 //scrolledArea.y = y;
7206 rootWindow.dirty = true;
7209 void ReleaseCapture()
7211 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
7213 Window oldCaptured = guiApp.windowCaptured;
7214 guiApp.windowCaptured = null;
7215 guiApp.prevWindow = null;
7218 //guiApp.Log("Released Capture\n");
7220 guiApp.interfaceDriver.SetMouseCapture(null);
7222 //oldCaptured.OnMouseCaptureLost();
7225 oldCaptured.ConsequentialMouseMove(false);
7230 private void _SetCaption(const char * format, va_list args)
7237 char caption[MAX_F_STRING];
7238 vsnprintf(caption, sizeof(caption), format, args);
7239 caption[sizeof(caption)-1] = 0;
7241 this.caption = CopyString(caption);
7246 firewatchers caption;
7250 /*deprecated*/ void SetText(const char * format, ...)
7253 va_start(args, format);
7254 _SetCaption(format, args);
7258 void SetCaption(const char * format, ...)
7261 va_start(args, format);
7262 _SetCaption(format, args);
7266 bool Grab(Bitmap bitmap, Box box, bool decorations)
7268 bool result = false;
7269 if(display || this == guiApp.desktop)
7271 Box clip = {MININT, MININT, MAXINT, MAXINT};
7277 clip.Clip(clientArea);
7279 clip.Clip(this.box);
7281 if(rootWindow != this)
7283 clip.left += absPosition.y;
7284 clip.top += absPosition.y;
7285 clip.right += absPosition.x;
7286 clip.bottom += absPosition.y;
7289 if(!nativeDecorations)
7291 clip.left += decorations ? 0 : clientStart.x;
7292 clip.top += decorations ? 0 : clientStart.y;
7293 clip.right += decorations ? 0 : clientStart.x;
7294 clip.bottom += decorations ? 0 : clientStart.y;
7297 if(decorations && this == guiApp.desktop)
7298 clip = { 0, 0, guiApp.virtualScreen.w, guiApp.virtualScreen.h };
7300 if(display && display.flags.flipping)
7302 rootWindow.Update(null);
7303 rootWindow.UpdateDisplay();
7310 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
7311 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7315 result = display.Grab(bitmap, clip.left, clip.top,
7316 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7318 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
7320 if(!bitmap.Convert(null, pixelFormat888, null))
7327 void GetMousePosition(int * x, int * y)
7329 int mouseX = 0, mouseY = 0;
7330 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
7333 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
7334 if(this != guiApp.desktop)
7336 mouseX -= absPosition.x + clientStart.x;
7337 mouseY -= absPosition.y + clientStart.y;
7344 DialogResult DoModal()
7346 DialogResult returnCode = 0;
7347 int terminated = terminateX;
7350 while(!destroyed && guiApp.driver != null)
7352 if(terminateX != terminated)
7354 terminated = terminateX;
7355 guiApp.desktop.Destroy(0);
7356 if(guiApp.desktop.created)
7359 //printf("Resetting terminate X to 0\n");
7365 guiApp.UpdateDisplay();
7366 if(!guiApp.ProcessInput(false))
7369 returnCode = this.returnCode;
7382 return !destroyed && guiApp.driver != null && terminateX < 2;
7385 DialogResult DoModalEnd()
7387 DialogResult returnCode = this.returnCode;
7392 // --- Window manipulation ---
7393 /*bool GetDisabled()
7395 bool disabled = this.disabled;
7397 for(window = this; (window = window.master); )
7408 // --- Mouse Manipulation ---
7409 void GetNCMousePosition(int * x, int * y)
7411 GetMousePosition(x, y);
7412 if(x) *x += clientStart.x;
7413 if(y) *y += clientStart.y;
7416 // --- Carets manipulation ---
7417 void GetCaretPosition(Point caretPos)
7419 caretPos = this.caretPos;
7422 int GetCaretSize(void)
7427 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7433 bool CloseConfirmation(bool parentClosing)
7446 if(!OnClose(parentClosing))
7449 // If you want to skip this, simply set modifiedDocument to false in OnClose
7450 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7452 DialogResult dialogRes;
7455 sprintf(message, $"Save changes to %s?", fileName);
7457 sprintf(message, $"Save changes to Untitled %d?", documentID);
7459 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = message }.Modal();
7461 if(dialogRes == yes)
7463 // TOFIX: Precomp error if brackets are taken out
7464 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7466 else if(dialogRes == cancel)
7472 for(slave = slaves.first; slave; slave = slave.next)
7474 Window w = slave.data;
7475 if(w.parent != this && !w.IsDescendantOf(this) && !w.CloseConfirmation(true))
7483 // Confirm closure of active clients first (We use OnClose() to hide instead of destroy in the IDE)
7486 for(child = children.first; child; child = child.next)
7487 if(child.isActiveClient && !child.CloseConfirmation(true))
7495 for(child = children.first; child; child = child.next)
7496 if(!child.isActiveClient && !child.CloseConfirmation(true))
7506 // Static methods... move them somewhere else?
7507 void ::RestoreCaret()
7509 if(guiApp.caretOwner)
7510 guiApp.caretOwner.UpdateCaret(false, false);
7513 void ::FreeMouseRange()
7515 guiApp.interfaceDriver.SetMouseRange(null, null);
7519 bool MenuFileClose(MenuItem selection, Modifiers mods)
7521 Window document = activeChild;
7523 document.Destroy(0);
7527 bool MenuFileExit(MenuItem selection, Modifiers mods)
7533 bool MenuFileSave(MenuItem selection, Modifiers mods)
7538 fileMonitor.fileName = null;
7541 if(OnSaveFile(fileName))
7543 //if(OnFileModified != Window::OnFileModified)
7546 fileMonitor.fileName = fileName;
7552 MessageBox dialog { master = master, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7553 DialogResult answer = dialog.Modal();
7555 if(answer != yes) return (bool)answer;
7558 return MenuFileSaveAs(selection, mods);
7561 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7563 DialogResult result = (DialogResult)bool::true;
7564 FileDialog fileDialog = saveDialog;
7569 fileDialog = FileDialog {};
7574 fileDialog.filePath = fileName;
7577 char filePath[MAX_FILENAME];
7578 sprintf(filePath, "Untitled %d", documentID);
7579 fileDialog.filePath = filePath;
7581 fileMonitor.fileName = null;
7583 fileDialog.type = save;
7584 fileDialog.text = $"Save As";
7588 fileDialog.master = master.parent ? master : this;
7589 if(fileDialog.Modal() == ok)
7591 const char * filePath = fileDialog.filePath;
7593 if(OnSaveFile(filePath))
7596 property::fileName = filePath;
7597 NotifySaved(master, this, filePath);
7602 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7603 DialogResult answer = dialog.Modal();
7618 //if(OnFileModified != Window::OnFileModified && fileName)
7621 fileMonitor.fileName = fileName;
7625 return (bool)result; // Actually returning result from Yes/NoCancel message box
7628 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7630 Window document = activeChild;
7632 for(document = children.first; document; document = next)
7634 next = document.next;
7635 if(document.style.isDocument || document.fileName)
7636 document.MenuFileSave(selection, mods);
7641 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7645 for(document = children.first; document; document = document.next)
7646 //if(document.style.isDocument && document.state == minimized)
7647 if(document.style.isActiveClient && document.state == minimized)
7648 document.SetState(minimized, false, mods);
7652 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7654 Window document = activeChild;
7657 Window firstDocument = null;
7659 OldLink cycle = document.cycle.prev;
7664 if(child.style.isActiveClient && !child.style.hidden)
7668 firstDocument = child;
7669 if(child.state == minimized)
7670 child.SetState(minimized, false, mods);
7673 child.positionID = id++;
7674 child.SetState(normal, false, mods);
7675 child.anchor.left.type = cascade;
7678 child.normalSizeAnchor = *&child.sizeAnchor;
7679 child.normalAnchor = child.anchor;
7681 // Break the anchors for moveable/resizable windows
7682 if(child.style.fixed)
7684 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7686 (*&child.normalAnchor).left = x;
7687 (*&child.normalAnchor).top = y;
7688 (*&child.normalAnchor).right.type = none;
7689 (*&child.normalAnchor).bottom.type = none;
7690 (*&child.normalSizeAnchor).isClientW = false;
7691 (*&child.normalSizeAnchor).isClientH = false;
7692 (*&child.normalSizeAnchor).size.w = w;
7693 (*&child.normalSizeAnchor).size.h = h;
7694 child.anchored = false;
7697 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7699 child.stateAnchor = child.normalAnchor;
7700 child.stateSizeAnchor = child.normalSizeAnchor;
7702 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7703 child.Position(x, y, w, h, true, true, true, true, false, false);
7708 last = children.last;
7709 if(!child.style.stayOnTop)
7710 for(; last && last.style.stayOnTop; last = last.prev);
7711 children.Move(child, last);
7712 childrenOrder.Move(child.order, childrenOrder.last);
7714 if(cycle == document.cycle) break;
7718 firstDocument.Activate();
7723 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7730 // Close all closes all active clients, not all documents
7731 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7733 Window next, document;
7735 for(document = children.first; document; document = next)
7737 for(next = document.next; next && !next.style.isActiveClient; next = next.next);
7738 if(document.style.isActiveClient)
7739 if(!document.Destroy(0) && !document.style.hidden)
7745 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7747 if(style.hasMaximize && state != maximized)
7748 SetState(maximized, 0, 0);
7752 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7754 if(style.hasMinimize && state != minimized)
7756 SetState(minimized, 0, 0);
7757 parent.CycleChildren(false, true, false, true);
7762 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7764 MenuMoveOrSize(false, selection ? true : false);
7768 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7770 CycleChildren(false, true, false, true);
7774 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7776 CycleChildren(true, true, false, true);
7780 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7782 MenuMoveOrSize(true, true);
7786 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7789 SetState(normal, 0, 0);
7793 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7796 int64 id = selection.id;
7797 OldLink cycle = activeClient.cycle;
7799 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7802 Window sibling = cycle.data;
7803 if(sibling.style.isActiveClient && sibling.visible && !sibling.style.nonClient)
7811 document = cycle.data;
7812 document.Activate();
7814 //if(activeChild.state == maximized)
7815 // document.SetState(maximized, false, mods);
7816 //else if(document.state == minimized)
7817 // document.SetState(normal, false, mods);
7821 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7823 stayOnTop = !style.stayOnTop;
7827 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7829 Window document = activeChild;
7832 Window firstDocument = null;
7833 OldLink cycle = document.cycle;
7837 Window child = cycle.data;
7838 if(child.style.isActiveClient && !child.style.hidden)
7840 if(!firstDocument) firstDocument = child;
7841 if(child.state == minimized)
7842 child.SetState(minimized, false, mods);
7845 child.positionID = id++;
7846 child.SetState(normal, false, mods);
7847 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7849 child.anchor.left.type = hTiled;
7852 child.normalSizeAnchor = *&child.sizeAnchor;
7853 child.normalAnchor = child.anchor;
7855 // Break the anchors for moveable/resizable windows
7856 if(child.style.fixed)
7858 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7860 (*&child.normalAnchor).left = x;
7861 (*&child.normalAnchor).top = y;
7862 (*&child.normalAnchor).right.type = none;
7863 (*&child.normalAnchor).bottom.type = none;
7864 (*&child.normalSizeAnchor).isClientW = false;
7865 (*&child.normalSizeAnchor).isClientH = false;
7866 (*&child.normalSizeAnchor).size.w = w;
7867 (*&child.normalSizeAnchor).size.h = h;
7868 child.anchored = false;
7871 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7873 child.stateAnchor = child.normalAnchor;
7874 child.stateSizeAnchor = child.normalSizeAnchor;
7876 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7877 child.Position(x,y, w, h, true, true, true, true, false, true);
7882 if((cycle = cycle.next) == document.cycle) break;
7885 firstDocument.Activate();
7890 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7892 Window document = activeChild;
7895 Window firstDocument = null;
7897 OldLink cycle = document.cycle;
7902 //if(child.style.isDocument)
7903 if(child.style.isActiveClient && !child.style.hidden)
7905 if(!firstDocument) firstDocument = child;
7906 if(child.state == minimized)
7907 child.SetState(minimized, false, mods);
7910 child.positionID = id++;
7911 child.SetState(normal, false, mods);
7912 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7914 child.anchor.left.type = vTiled;
7917 child.normalSizeAnchor = *&child.sizeAnchor;
7918 child.normalAnchor = child.anchor;
7920 // Break the anchors for moveable/resizable windows
7921 if(child.style.fixed)
7923 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7925 (*&child.normalAnchor).left = x;
7926 (*&child.normalAnchor).top = y;
7927 (*&child.normalAnchor).right.type = none;
7928 (*&child.normalAnchor).bottom.type = none;
7929 (*&child.normalSizeAnchor).isClientW = false;
7930 (*&child.normalSizeAnchor).isClientH = false;
7931 (*&child.normalSizeAnchor).size.w = w;
7932 (*&child.normalSizeAnchor).size.h = h;
7933 child.anchored = false;
7936 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7938 child.stateAnchor = child.normalAnchor;
7939 child.stateSizeAnchor = child.normalSizeAnchor;
7941 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7942 child.Position(x,y, w, h, true, true, true, true, false, true);
7947 if((cycle = cycle.next) == document.cycle) break;
7950 firstDocument.Activate();
7955 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7957 WindowList dialog { master = this };
7958 Window document = (Window)(intptr)dialog.Modal();
7961 if(activeChild.state == maximized)
7962 document.SetState(maximized, false, mods);
7963 else if(document.state == minimized)
7964 document.SetState(normal, false, mods);
7965 document.Activate();
7971 virtual bool OnCreate(void);
7972 virtual void OnDestroy(void);
7973 virtual void OnDestroyed(void);
7974 virtual bool OnClose(bool parentClosing);
7975 virtual bool OnStateChange(WindowState state, Modifiers mods);
7976 virtual bool OnPostCreate(void);
7977 virtual bool OnMoving(int *x, int *y, int w, int h);
7978 virtual bool OnResizing(int *width, int *height);
7979 virtual void OnResize(int width, int height);
7980 virtual void OnPosition(int x, int y, int width, int height);
7981 virtual bool OnLoadGraphics(void);
7982 virtual void OnApplyGraphics(void);
7983 virtual void OnUnloadGraphics(void);
7984 virtual void OnRedraw(Surface surface);
7985 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7986 virtual void OnActivateClient(Window client, Window previous);
7987 virtual bool OnKeyDown(Key key, unichar ch);
7988 virtual bool OnKeyUp(Key key, unichar ch);
7989 virtual bool OnKeyHit(Key key, unichar ch);
7990 virtual bool OnSysKeyDown(Key key, unichar ch);
7991 virtual bool OnSysKeyUp(Key key, unichar ch);
7992 virtual bool OnSysKeyHit(Key key, unichar ch);
7993 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7994 virtual bool OnMouseLeave(Modifiers mods);
7995 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7996 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7997 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
7998 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
7999 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
8000 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
8001 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
8002 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
8003 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
8004 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
8005 virtual bool OnMultiTouch(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods);
8006 virtual void OnMouseCaptureLost(void);
8007 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
8008 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
8009 virtual void OnDrawOverChildren(Surface surface);
8010 virtual bool OnFileModified(FileChange fileChange, const char * param);
8011 virtual bool OnSaveFile(const char * fileName);
8013 // Virtual Methods -- Children management (To support Stacker, for lack of built-in auto-layout)
8014 // Note: A 'client' would refer to isActiveClient, rather than
8015 // being confined to the 'client area' (nonClient == false)
8016 virtual void OnChildAddedOrRemoved(Window child, bool removed);
8017 virtual void OnChildVisibilityToggled(Window child, bool visible);
8018 virtual void OnChildResized(Window child, int x, int y, int w, int h);
8020 // Skins Virtual Functions
8021 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
8022 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
8023 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
8028 virtual void ShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
8029 virtual void PreShowDecorations(Font captionFont, Surface surface, const char * name, bool active, bool moving);
8030 virtual bool IsMouseMoving(int x, int y, int w, int h)
8034 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY)
8038 virtual void UpdateNonClient();
8039 virtual void SetBox(Box box); // This is used in the MySkin skin
8040 virtual bool IsInside(int x, int y)
8042 return box.IsPointInside({x, y});
8044 virtual bool IsOpaque()
8046 return (!style.drawBehind || background.a == 255);
8050 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
8051 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
8052 virtual void Window::NotifySaved(Window window, const char * filePath);
8057 property Window parent
8059 property_category $"Layout"
8062 if(value || guiApp.desktop)
8065 Window oldParent = parent;
8066 Anchor anchor = this.anchor;
8068 if(value && value.IsDescendantOf(this)) return;
8069 if(value && value == this)
8071 if(!value) value = guiApp.desktop;
8073 if(value == oldParent) return;
8075 if(!master || (master == this.parent && master == guiApp.desktop))
8076 property::master = value;
8080 parent.children.Remove(this);
8084 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
8085 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
8086 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
8087 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
8091 last = value.children.last;
8093 if(style.isDocument)
8096 parent.numDocuments--;
8097 documentID = value.GetDocumentID();
8100 if(style.isActiveClient && !style.hidden)
8102 if(parent && parent != guiApp.desktop && !(style.hidden))
8104 if(state == minimized) parent.numIcons--;
8105 parent.numPositions--;
8109 if(!style.stayOnTop)
8110 for(; last && last.style.stayOnTop; last = last.prev);
8112 value.children.Insert(last, this);
8114 // *** NEW HERE: ***
8116 parent.childrenCycle.Delete(cycle);
8118 parent.childrenOrder.Delete(order);
8121 // *** TODO: Added this here to solve crash on setting parent to null before destroying/destructing ***
8122 // Should something else be done?
8123 if(parent && parent.activeChild == this)
8124 parent.activeChild = null;
8125 if(parent && parent.activeClient == this)
8126 parent.activeClient = null;
8132 int x = position.x, y = position.y, w = size.w, h = size.h;
8136 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
8137 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
8139 vpw = value.clientSize.w;
8140 vph = value.clientSize.h;
8146 else if(style.fixed)
8148 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
8149 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
8152 anchor = this.anchor;
8154 if(anchor.left.type == offset) anchor.left.distance = x;
8155 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
8156 if(anchor.top.type == offset) anchor.top.distance = y;
8157 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
8158 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
8159 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
8160 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
8161 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
8162 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
8163 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
8165 if(!anchor.left.type && !anchor.right.type)
8167 anchor.horz.distance = (x + w / 2) - (vpw / 2);
8168 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
8170 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
8171 if(!anchor.top.type && !anchor.bottom.type)
8173 anchor.vert.distance = (y + h / 2) - (vph / 2);
8174 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
8176 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
8179 parent.OnChildAddedOrRemoved(this, false);
8185 parent.childrenCycle.Insert(
8186 // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
8187 //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8189 cycle = OldLink { data = this });
8190 parent.childrenOrder.Insert(
8191 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8192 order = OldLink { data = this });
8195 if(!style.hidden && style.isActiveClient)
8197 positionID = parent.GetPositionID(this);
8198 parent.numPositions++;
8199 if(state == minimized) parent.numIcons--;
8202 // *** FONT INHERITANCE ***
8203 if(!setFont && oldParent)
8204 stopwatching(oldParent, font);
8208 RemoveResource(systemFont);
8211 // TESTING WITH WATCHERS:
8212 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8213 // usedFont = setFont ? setFont : (systemFont);
8217 if(guiApp.currentSkin)
8219 systemFont = guiApp.currentSkin.SystemFont();
8222 usedFont = systemFont;
8223 AddResource(systemFont);
8231 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8240 if(value.rootWindow && value.rootWindow.display && rootWindow && created)
8242 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
8243 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
8246 UnloadGraphics(false);
8249 LoadGraphics(false, false);
8252 if(value.rootWindow != rootWindow)
8253 DisplayModeChanged();
8257 scrolledPos.x = MININT; // Prevent parent update
8259 bool anchored = this.anchored;
8260 property::anchor = anchor;
8261 this.anchored = anchored;
8266 if(guiApp.currentSkin)
8267 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
8269 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8270 Position(x, y, w, h, true, true, true, true, false, true);
8275 // else parent = value;
8277 oldParent.OnChildAddedOrRemoved(this, true);
8280 get { return parent; }
8283 property Window master
8285 property_category $"Behavior"
8288 //if(this == value) return;
8289 if(value && value.IsSlaveOf(this)) return;
8295 OldLink slaveHolder;
8296 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
8297 if(slaveHolder.data == this)
8299 master.slaves.Delete(slaveHolder);
8306 value.slaves.Add(OldLink { data = this });
8311 master.hotKeys.Remove(hotKey);
8312 value.hotKeys.Add(hotKey);
8315 if(master && master.defaultControl == this)
8316 master.defaultControl = null;
8318 if(style.isDefault && !value.defaultControl)
8319 value.defaultControl = this;
8324 get { return master ? master : parent; }
8327 property const char * caption
8329 property_category $"Appearance"
8336 caption = new char[strlen(value)+1];
8338 strcpy(caption, value);
8343 get { return caption; }
8348 property_category $"Behavior"
8357 master.hotKeys.Add(hotKey = HotKeySlot { });
8361 hotKey.window = this;
8366 master.hotKeys.Delete(hotKey);
8371 get { return hotKey ? hotKey.key : 0; }
8374 property Color background
8376 property_category $"Appearance"
8379 background.color = value;
8384 if(this == rootWindow)
8385 guiApp.interfaceDriver.SetRootWindowColor(this);
8388 get { return background.color; }
8391 property Percentage opacity
8393 property_category $"Appearance"
8396 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
8397 drawBehind = (background.a == 255) ? false : true;
8399 get { return background.a / 255.0f; }
8402 property Color foreground
8404 property_category $"Appearance"
8412 get { return foreground; }
8415 property BorderStyle borderStyle
8417 property_category $"Appearance"
8420 if(!((BorderBits)value).fixed)
8422 style.hasClose = false;
8423 style.hasMaximize = false;
8424 style.hasMinimize = false;
8425 nativeDecorations = false;
8427 style.borderBits = value;
8431 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8433 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8434 Position(x, y, w, h, true, true, true, true, false, true);
8435 CreateSystemChildren();
8438 get { return (BorderStyle)style.borderBits; }
8441 property Size minClientSize
8443 property_category $"Layout"
8444 set { minSize = value; }
8445 get { value = minSize; }
8448 property Size maxClientSize
8450 property_category $"Layout"
8451 set { maxSize = value; }
8452 get { value = maxSize; }
8455 property bool hasMaximize
8457 property_category $"Window Style"
8460 style.hasMaximize = value;
8461 if(value) { style.fixed = true; style.contour = true; }
8465 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8467 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8468 Position(x, y, w, h, true, true, true, true, false, true);
8470 CreateSystemChildren();
8473 get { return style.hasMaximize; }
8476 property bool hasMinimize
8478 property_category $"Window Style"
8481 style.hasMinimize = value;
8482 if(value) { style.fixed = true; style.contour = true; }
8486 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8488 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8489 Position(x, y, w, h, true, true, true, true, false, true);
8491 CreateSystemChildren();
8494 get { return style.hasMinimize; }
8497 property bool hasClose
8499 property_category $"Window Style"
8502 style.hasClose = value;
8503 if(value) { style.fixed = true; style.contour = true; }
8507 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8508 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8509 Position(x, y, w, h, true, true, true, true, false, true);
8510 CreateSystemChildren();
8513 get { return style.hasClose; }
8516 property bool nonClient
8518 property_category $"Layout"
8521 style.nonClient = value;
8523 style.stayOnTop = true;
8525 get { return style.nonClient; }
8528 property bool inactive
8530 property_category $"Behavior"
8535 // *** NEW HERE: ***
8539 parent.childrenCycle.Delete(cycle);
8541 parent.childrenOrder.Delete(order);
8548 active = false; // true;
8549 if(parent.activeChild == this)
8550 parent.activeChild = null;
8551 if(parent.activeClient == this)
8552 parent.activeClient = null;
8561 parent.childrenCycle.Insert(
8562 // Note: changed to 'null' to fix broken tab cycling in WSMS custom reports
8563 //(parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8565 cycle = OldLink { data = this });
8567 parent.childrenOrder.Insert(
8568 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8569 order = OldLink { data = this });
8572 style.inactive = value;
8574 get { return style.inactive; }
8577 property bool clickThrough
8579 property_category $"Behavior"
8580 set { style.clickThrough = value; }
8581 get { return style.clickThrough; }
8584 property bool isRemote
8586 property_category $"Behavior"
8587 set { style.isRemote = value; }
8588 get { return style.isRemote; }
8591 property bool noCycle
8593 property_category $"Behavior"
8594 set { style.noCycle = value; }
8595 get { return style.noCycle; }
8598 property bool isModal
8600 property_category $"Behavior"
8601 set { style.modal = value; }
8602 get { return style.modal; }
8605 property bool interim
8607 property_category $"Behavior"
8608 set { style.interim = value; }
8609 get { return style.interim; }
8612 property bool tabCycle
8614 property_category $"Behavior"
8615 set { style.tabCycle = value; }
8616 get { return style.tabCycle; }
8619 property bool isDefault
8621 property_category $"Behavior"
8629 for(sibling = parent.children.first; sibling; sibling = sibling.next)
8630 if(sibling != this && sibling.style.isDefault)
8631 sibling.style.isDefault = false;*/
8632 if(master.defaultControl)
8633 master.defaultControl.style.isDefault = false;
8634 master.defaultControl = this;
8636 else if(master.defaultControl == this)
8637 master.defaultControl = null;
8641 style.isDefault = value;
8643 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8645 get { return style.isDefault; }
8648 property bool drawBehind
8650 property_category $"Window Style"
8651 set { style.drawBehind = value; }
8652 get { return style.drawBehind; }
8655 property bool hasMenuBar
8657 property_category $"Window Style"
8667 if(created && !menuBar)
8674 anchor = Anchor { top = 23, left = 1, right = 1 },
8676 inactive = true, nonClient = true
8681 else if(created && menuBar)
8686 style.hasMenuBar = value;
8688 get { return style.hasMenuBar; }
8691 property bool hasStatusBar
8693 property_category $"Window Style"
8700 statusBar = StatusBar { this };
8708 style.hasStatusBar = value;
8710 get { return style.hasStatusBar; }
8712 property bool stayOnTop
8714 property_category $"Window Style"
8719 if(created && !style.stayOnTop)
8721 if(rootWindow == this)
8722 guiApp.interfaceDriver.OrderRootWindow(this, true);
8723 else if(parent.children.last != this)
8725 parent.children.Move(this, parent.children.last);
8729 style.stayOnTop = true;
8733 if(created && style.stayOnTop)
8735 if(rootWindow == this)
8736 guiApp.interfaceDriver.OrderRootWindow(this, false);
8743 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8744 order && ((Window)order.data).style.stayOnTop;
8745 order = (order == parent.childrenOrder.first) ? null : order.prev);
8746 last = order ? order.data : null;
8750 for(last = parent.children.last;
8751 last && last.style.stayOnTop;
8755 parent.children.Move(this, last);
8759 style.stayOnTop = false;
8762 get { return style.stayOnTop; }
8767 property_category $"Window Style"
8777 if(menuBar && !value)
8784 if(!menuBar && style.hasMenuBar && value)
8788 this, menu = value, isMenuBar = true,
8789 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8790 inactive = true, nonClient = true
8794 UpdateActiveDocument(null);
8797 get { return menu; }
8800 property FontResource font
8802 property_category $"Appearance"
8804 isset { return setFont ? true : false; }
8809 if(value && !setFont) { stopwatching(parent, font); }
8810 else if(!value && setFont)
8816 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8825 RemoveResource(setFont);
8830 RemoveResource(systemFont);
8837 AddResource(setFont);
8840 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8843 systemFont = guiApp.currentSkin.SystemFont();
8845 usedFont = systemFont;
8846 AddResource(systemFont);
8854 get { return usedFont; }
8857 property SizeAnchor sizeAnchor
8859 property_category $"Layout"
8862 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8863 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8864 sizeAnchor.isClientW != sizeAnchor.isClientH;
8871 normalSizeAnchor = sizeAnchor;
8873 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8875 stateAnchor = normalAnchor;
8876 stateSizeAnchor = normalSizeAnchor;
8878 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8879 Position(x,y, w, h, true, true, true, true, false, true);
8886 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8887 sizeAnchor.isClientW,
8888 sizeAnchor.isClientH
8895 property_category $"Layout"
8898 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8899 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8900 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8906 sizeAnchor.isClientW = false;
8907 sizeAnchor.isClientH = false;
8908 sizeAnchor.size = value;
8910 normalSizeAnchor = sizeAnchor;
8912 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8914 stateAnchor = normalAnchor;
8915 stateSizeAnchor = normalSizeAnchor;
8917 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8918 Position(x, y, w, h, true, true, true, true, false, true);
8919 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
8922 get { value = size; }
8925 property Size clientSize
8927 property_category $"Layout"
8930 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8931 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8932 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8937 sizeAnchor.isClientW = true;
8938 sizeAnchor.isClientH = true;
8939 sizeAnchor.size = value;
8941 normalSizeAnchor = sizeAnchor;
8943 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8945 stateAnchor = normalAnchor;
8946 stateSizeAnchor = normalSizeAnchor;
8948 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8949 Position(x,y, w, h, true, true, true, true, false, true);
8950 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
8953 get { value = this ? clientSize : { 0, 0 }; }
8956 property Size initSize { get { value = sizeAnchor.size; } };
8958 property Anchor anchor
8960 property_category $"Layout"
8961 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8967 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8969 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8970 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8972 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8974 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8975 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8979 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8981 anchor.left.distance = 0;
8982 anchor.horz.type = 0;
8984 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8986 anchor.top.distance = 0;
8987 anchor.vert.type = 0;
8996 normalAnchor = anchor;
8998 // Break the anchors for moveable/resizable windows
8999 /*if(style.fixed ) //&& value.left.type == cascade)
9001 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
9003 this.anchor = normalAnchor = Anchor { left = x, top = y };
9004 normalSizeAnchor = SizeAnchor { { w, h } };
9007 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9009 stateAnchor = normalAnchor;
9010 stateSizeAnchor = normalSizeAnchor;
9012 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9013 Position(x, y, w, h, true, true, true, true, false, true);
9022 get { value = this ? anchor : Anchor { }; }
9025 property Point position
9027 property_category $"Layout"
9030 if(value == null) return;
9032 anchor.left = value.x;
9033 anchor.top = value.y;
9034 anchor.right.type = none;
9035 anchor.bottom.type = none;
9040 normalAnchor = anchor;
9042 // Break the anchors for moveable/resizable windows
9046 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9048 normalAnchor.left = x;
9049 normalAnchor.top = y;
9050 normalAnchor.right.type = none;
9051 normalAnchor.bottom.type = none;
9052 normalSizeAnchor.size.width = w;
9053 normalSizeAnchor.size.height = h;
9057 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
9059 stateAnchor = normalAnchor;
9060 stateSizeAnchor = normalSizeAnchor;
9062 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
9063 Position(x,y, w, h, true, true, true, true, false, true);
9067 get { value = position; }
9070 property bool disabled
9072 property_category $"Behavior"
9075 if(this && disabled != value)
9082 get { return (bool)disabled; }
9085 property bool isEnabled
9090 for(parent = this; parent; parent = parent.parent)
9097 property WindowState state
9099 property_category $"Behavior"
9100 set { SetState(value, false, 0); }
9101 get { return this ? state : 0; }
9104 property bool visible
9106 property_category $"Behavior"
9109 if(this && !value && !style.hidden && parent)
9111 bool wasActiveChild = parent.activeChild == this;
9112 Window client = null;
9114 style.hidden = true;
9115 if(style.isActiveClient)
9117 parent.numPositions--;
9118 if(state == minimized) parent.numIcons--;
9123 OldLink prevOrder = null;
9125 if(rootWindow == this)
9126 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
9129 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
9132 box.left -= parent.clientStart.x;
9133 box.top -= parent.clientStart.y;
9134 box.right -= parent.clientStart.x;
9135 box.bottom -= parent.clientStart.y;
9139 if(_isModal && master && master.modalSlave == this)
9140 master.modalSlave = null;
9144 OldLink tmpPrev = order.prev;
9145 client = tmpPrev ? tmpPrev.data : null;
9146 if(client && !client.style.hidden && !client.destroyed && client.created)
9147 prevOrder = tmpPrev;
9150 client = tmpPrev ? tmpPrev.data : null;
9151 if(client == this) { client = null; break; }
9152 if(client && ((client.style.hidden) || client.destroyed || !client.created))
9154 tmpPrev = client.order.prev;
9159 prevOrder = tmpPrev;
9164 // If this window can be an active client, make sure the next window we activate can also be one
9165 if(!style.nonClient && style.isActiveClient)
9167 tmpPrev = prevOrder;
9170 client = tmpPrev ? tmpPrev.data : null;
9171 if(client == this) { client = null; break; }
9172 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
9174 tmpPrev = client.order.prev;
9179 prevOrder = tmpPrev;
9183 if(client && client.style.hidden) client = null;
9187 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
9189 if(order && prevOrder && prevOrder.data != this)
9190 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
9192 ActivateEx(false, false, false, true, null, null);
9194 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
9195 if(parent.activeClient == this)
9197 parent.activeClient = null;
9198 parent.UpdateActiveDocument(null);
9201 else if(parent.activeClient == this)
9203 parent.activeClient = client;
9204 parent.UpdateActiveDocument(this);
9207 // *** Not doing this anymore ***
9210 parent.childrenCycle.Delete(cycle);
9212 parent.childrenOrder.Delete(order);
9217 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9222 else if(this && value && style.hidden)
9224 style.hidden = false;
9227 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9228 if(rootWindow == this)
9229 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
9231 if(_isModal && master)
9232 master.modalSlave = this;
9234 if(style.isActiveClient)
9236 positionID = parent.GetPositionID(this);
9237 parent.numPositions++;
9238 if(state == minimized) parent.numIcons++;
9241 // *** NOT DOING THIS ANYMORE ***
9243 if(!(style.inactive))
9245 if(!(style.noCycle))
9247 cycle = parent.childrenCycle.AddAfter(
9248 (parent.activeChild && parent.activeChild.cycle) ?
9249 parent.activeChild.cycle.prev : null, sizeof(OldLink));
9252 order = parent.childrenOrder.AddAfter(
9253 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
9260 if(true || !parent.activeChild)
9261 ActivateEx(true, false, true, true, null, null);
9263 if(creationActivation == activate && guiApp.desktop.active)
9264 ActivateEx(true, false, true, true, null, null);
9265 else if((creationActivation == activate || creationActivation == flash) && !object)
9268 if(this == rootWindow)
9272 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
9276 ConsequentialMouseMove(false);
9282 style.hidden = !value;
9285 get { return (style.hidden || !setVisible) ? false : true; }
9288 property bool isDocument
9290 property_category $"Document"
9291 set { style.isDocument = value; if(value) SetupFileMonitor(); }
9292 get { return style.isDocument; }
9295 property bool mergeMenus
9297 property_category $"Window Style"
9298 set { mergeMenus = value; }
9299 get { return (bool)mergeMenus; }
9302 property bool hasHorzScroll
9304 property_category $"Window Style"
9309 if(!style.hasHorzScroll && created)
9311 CreateSystemChildren();
9312 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9315 else if(style.hasHorzScroll)
9319 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9321 style.hasHorzScroll = value;
9324 get { return style.hasHorzScroll; }
9327 property bool hasVertScroll
9329 property_category $"Window Style"
9334 if(!style.hasVertScroll && created)
9336 style.hasVertScroll = true;
9337 CreateSystemChildren();
9338 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9341 else if(style.hasVertScroll)
9345 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9347 style.hasVertScroll = value;
9349 get { return style.hasVertScroll; }
9352 property bool dontHideScroll
9354 property_category $"Behavior"
9357 scrollFlags.dontHide = value;
9360 //UpdateScrollBars(true, true);
9361 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9365 // UpdateScrollBars(true, true);
9366 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9369 get { return scrollFlags.dontHide; }
9372 property bool dontScrollVert
9374 property_category $"Behavior"
9375 set { style.dontScrollVert = value; }
9376 get { return style.dontScrollVert; }
9378 property bool dontScrollHorz
9380 property_category $"Behavior"
9381 set { style.dontScrollHorz = value; }
9382 get { return style.dontScrollHorz; }
9385 property bool snapVertScroll
9387 property_category $"Behavior"
9390 scrollFlags.snapY = value;
9391 if(sbv) sbv.snap = value;
9393 get { return scrollFlags.snapY; }
9395 property bool snapHorzScroll
9397 property_category $"Behavior"
9400 scrollFlags.snapX = value;
9401 if(sbh) sbh.snap = value;
9403 get { return scrollFlags.snapX; }
9406 property Point scroll
9408 property_category $"Behavior"
9409 set { if(this) SetScrollPosition(value.x, value.y); }
9410 get { value = scroll; }
9413 property bool modifyVirtualArea
9415 property_category $"Behavior"
9416 set { modifyVirtArea = value; }
9417 get { return (bool)modifyVirtArea; }
9420 property bool dontAutoScrollArea
9422 property_category $"Behavior"
9423 // Activating a child control out of view will automatically scroll to make it in view
9424 set { noAutoScrollArea = value; }
9425 get { return (bool)noAutoScrollArea; }
9428 property const char * fileName
9430 property_category $"Document"
9435 if(menu && ((!fileName && value) || (fileName && !value)))
9437 MenuItem item = menu.FindItem(MenuFileSave, 0);
9438 if(item) item.disabled = !modifiedDocument && value;
9443 if(value && value[0])
9444 fileName = CopyString(value);
9446 if(parent && this == parent.activeClient)
9447 parent.UpdateActiveDocument(null);
9451 // if(style.isDocument)
9453 fileMonitor.fileName = value;
9455 get { return fileName; }
9460 property_category $"Data"
9465 property bool modifiedDocument
9467 property_category $"Document"
9470 if(style.isDocument || fileName)
9474 MenuItem item = menu.FindItem(MenuFileSave, 0);
9475 if(item) item.disabled = !value && fileName;
9479 if(modifiedDocument != value)
9481 modifiedDocument = value;
9482 if(style.isDocument || fileName)
9486 get { return (bool)modifiedDocument; }
9489 property bool showInTaskBar
9491 property_category $"Window Style"
9494 style.showInTaskBar = value;
9495 #if defined(__WIN32__)
9496 Win32UpdateStyle(this);
9499 get { return style.showInTaskBar; }
9501 property FileDialog saveDialog { set { saveDialog = value; } };
9502 property bool isActiveClient
9504 property_category $"Behavior"
9507 if(parent && style.isActiveClient != value && !style.hidden)
9511 if(state == minimized) parent.numIcons++;
9512 parent.numPositions++;
9516 if(state == minimized) parent.numIcons--;
9517 parent.numPositions--;
9520 style.isActiveClient = value;
9522 get { return style.isActiveClient; }
9525 property Cursor cursor
9527 property_category $"Appearance"
9531 SelectMouseCursor();
9533 get { return cursor; }
9536 //#if !defined(ECERE_VANILLA)
9537 property const char * name
9539 property_category $"Design"
9542 return (this && object) ? object.name : null;
9547 activeDesigner.RenameObject(object, value);
9551 property const char * displayDriver
9553 property_category $"Behavior"
9556 dispDriver = GetDisplayDriver(value);
9557 //DisplayModeChanged();
9561 return dispDriver ? dispDriver.name : null;
9565 // RUNTIME PROPERTIES
9566 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9567 property Size scrollArea
9569 property_category $"Behavior"
9573 SetScrollArea(value.w, value.h, false);
9575 SetScrollArea(0,0, true);
9577 get { value = scrollArea; }
9580 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9585 property_category $"Layout"
9586 set { if(this) is3D = value; }
9587 get { return (bool)is3D; }
9590 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9592 // Will be merged with font later
9593 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9594 property Point clientStart { get { value = clientStart; } };
9595 property Point absPosition { get { value = absPosition; } };
9596 property Anchor normalAnchor { get { value = normalAnchor; } };
9597 property SizeAnchor normalSizeAnchor { get { value = normalSizeAnchor; } };
9598 property bool active { get { return (bool)active; } };
9599 property bool created { get { return (bool)created; } };
9600 property bool destroyed { get { return (bool)destroyed; } };
9601 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9602 property Window firstChild { get { return children.first; } };
9603 property Window lastChild { get { return children.last; } };
9604 property Window activeClient { get { return activeClient; } };
9605 property Window activeChild { get { return activeChild; } };
9606 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9607 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9608 property ScrollBar horzScroll { get { return sbh; } };
9609 property ScrollBar vertScroll { get { return sbv; } };
9610 property StatusBar statusBar { get { return statusBar; } };
9611 property Window rootWindow { get { return rootWindow; } };
9612 property bool closing { get { return (bool)closing; } set { closing = value; } };
9613 property int documentID { get { return documentID; } };
9614 property Window previous { get { return prev; } }
9615 property Window next { get { return next; } }
9616 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9617 property PopupMenu menuBar { get { return menuBar; } }
9618 property ScrollBar sbv { get { return sbv; } }
9619 property ScrollBar sbh { get { return sbh; } }
9620 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9621 property void * systemHandle { get { return windowHandle; } }
9622 property Button minimizeButton { get { return sysButtons[0]; } };
9623 property Button maximizeButton { get { return sysButtons[1]; } };
9624 property Button closeButton { get { return sysButtons[2]; } };
9625 property BitmapResource icon
9627 get { return icon; }
9631 if(icon) incref icon;
9633 guiApp.interfaceDriver.SetIcon(this, value);
9636 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9637 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; if(value) nativeDecorations = false; /* Native Decorations are not supported with alphaBlend */ } };
9638 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9639 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9640 property bool nativeDecorations
9642 get { return (bool)nativeDecorations; }
9643 set { nativeDecorations = value; }
9644 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
9647 //return (nativeDecorations && (rootWindow == this || (formDesigner && activeDesigner && ((FormDesigner)activeDesigner.classDesigner).form && parent == ((FormDesigner)activeDesigner.classDesigner).form.parent))) != style.fixed;
9648 bool result = false;
9649 if(nativeDecorations)
9651 if(rootWindow == this)
9655 if(formDesigner && activeDesigner)
9657 FormDesigner cd = (FormDesigner)activeDesigner.classDesigner;
9658 Window form = cd ? cd.form : null;
9659 if(form && parent == form.parent)
9664 return result != style.fixed;
9668 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9670 property const char * text
9672 property_category $"Deprecated"
9674 set { property::caption = value; }
9675 get { return property::caption; }
9681 WindowBits style; // Window Style
9682 char * caption; // Name / Caption
9683 Window parent; // Parent window
9684 OldList children; // List of children in Z order
9685 Window activeChild; // Child window having focus
9686 Window activeClient;
9687 Window previousActive; // Child active prior to activating the default child
9688 Window master; // Window owning and receiving notifications concerning this window
9689 OldList slaves; // List of windows belonging to this window
9690 Display display; // Display this window is drawn into
9692 Point position; // Position in parent window client area
9693 Point absPosition; // Absolute position
9694 Point clientStart; // Client area position from (0,0) in this window
9696 Size clientSize; // Client area size
9697 Size scrollArea; // Virtual Scroll area size
9698 Size reqScrollArea; // Requested virtual area size
9699 Point scroll; // Virtual area scrolling position
9700 ScrollBar sbh, sbv; // Scrollbar window handles
9701 Cursor cursor; // Mouse cursor used for this window
9704 StatusBar statusBar;
9705 Button sysButtons[3];
9707 Box clientArea; // Client Area box clipped to parent
9709 HotKeySlot hotKey; // HotKey for this window
9713 ScrollFlags scrollFlags;// Window Scrollbar Flags
9714 int64 id; // Control ID
9716 ColorAlpha background; // Background color used to draw the window area
9718 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9719 OldList childrenCycle; // Cycling order
9720 OldLink cycle; // Element of parent's cycling order
9721 OldList childrenOrder; // Circular Z-Order
9722 OldLink order; // Element of parent's circular Z-Order
9723 Window modalSlave; // Slave window blocking this window's interaction
9725 Window rootWindow; // Topmost system managed window
9726 void * windowHandle; // System window handle
9728 DialogResult returnCode;// Return code for modal windows
9730 Point sbStep; // Scrollbar line scrolling steps
9733 SizeAnchor stateSizeAnchor;
9735 Anchor normalAnchor;
9736 SizeAnchor normalSizeAnchor;
9738 Size skinMinSize; // Minimal window size based on style
9739 Point scrolledPos; // Scrolled position
9740 Box box; // Window box clipped to parent
9741 Box * against; // What to clip the box to
9743 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9744 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9745 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9746 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9747 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9748 Point scrolledArea; // Distance to scroll area by
9749 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9751 OldList hotKeys; // List of the hotkeys of all children
9752 Window defaultControl; // Default child control
9756 ColorAlpha * palette; // Color palette used for this window
9758 int caretSize; // Size of caret, non zero if a caret is present
9759 Point caretPos; // Caret position
9761 void * systemParent; // Parent System Window for embedded windows
9768 WindowState lastState;
9770 FileMonitor fileMonitor;
9772 FontResource setFont, systemFont;
9773 FontResource usedFont;
9774 FontResource captionFont;
9776 FileDialog saveDialog;
9778 SizeAnchor sizeAnchor;
9780 // FormDesigner data
9783 Extent * tempExtents; //[4];
9784 BitmapResource icon;
9786 CreationActivationOption creationActivation;
9789 bool active:1; // true if window and ancestors are active
9790 bool acquiredInput:1; // true if the window is processing state based input
9791 bool modifiedDocument:1;
9792 bool disabled:1; // true if window cannot interact
9793 bool isForegroundWindow:1;// true while a root window is being activated
9794 bool visible:1; // Visibility flag
9795 bool destroyed:1; // true if window is being destroyed
9796 bool anchored:1; // true if this window is repositioned when the parent resizes
9797 bool dirty:1; // Flag set to true if any descendant must be redrawn
9803 bool modifyVirtArea:1;
9804 bool noAutoScrollArea:1;
9807 bool setVisible:1; // FOR FORM DESIGNER
9813 bool useSharedMemory:1;
9816 bool nativeDecorations:1;
9817 bool manageDisplay:1;
9818 bool formDesigner:1; // True if we this is running in the form editor
9819 bool requireRemaximize:1;
9820 bool noConsequential:1;
9823 // Checks used internally for them not to take effect in FormDesigner
9824 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9825 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9827 WindowController controller;
9829 public property WindowController controller
9831 get { return controller; }
9835 controller.setWindow(null);
9841 controller.setWindow(this);
9846 public property bool noConsequential
9848 set { noConsequential = value; }
9849 get { return noConsequential; }
9853 public class CommonControl : Window
9855 // creationActivation = doNothing;
9858 public property const String toolTip
9860 property_category $"Appearance"
9863 if(created) CommonControl::OnDestroy();
9865 toolTip = value ? ToolTip { tip = value; } : null;
9867 if(created) CommonControl::OnCreate();
9869 get { return toolTip ? toolTip.tip : null; }
9875 // (Very) Ugly work around for the fact that the parent watcher
9876 // won't fire when it's already been disconnected...
9877 eInstance_FireSelfWatchers(toolTip,
9878 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
9884 toolTip.parent = this;
9893 public class Percentage : float
9895 const char * OnGetString(char * string, float * fieldData, bool * needClass)
9899 sprintf(string, "%.2f", this);
9900 c = strlen(string)-1;
9903 if(string[c] != '0')
9904 last = Max(last, c);
9905 if(string[c] == '.')
9918 public void ApplySkin(Class c, const char * name, void ** vTbl)
9920 char className[1024];
9925 subclass(Window) wc = (subclass(Window))c;
9926 subclass(Window) base = (subclass(Window))c.base;
9928 sprintf(className, "%sSkin_%s", name, c.name);
9929 wc.pureVTbl = c._vTbl;
9930 c._vTbl = new void *[c.vTblSize];
9931 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9932 sc = eSystem_FindClass(c.module.application, className);
9936 for(m = 0; m < c.base.vTblSize; m++)
9938 if(c._vTbl[m] == base.pureVTbl[m])
9939 c._vTbl[m] = vTbl[m];
9944 for(m = 0; m < c.vTblSize; m++)
9946 if(sc._vTbl[m] != wc.pureVTbl[m])
9947 c._vTbl[m] = sc._vTbl[m];
9951 for(d = c.derivatives.first; d; d = d.next)
9953 ApplySkin(d.data, name, c._vTbl);
9957 public void UnapplySkin(Class c)
9959 subclass(Window) wc = (subclass(Window))c;
9962 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9965 c._vTbl = wc.pureVTbl;
9969 for(d = c.derivatives.first; d; d = d.next)
9971 UnapplySkin(d.data);
9975 void CheckFontIntegrity(Window window)
9980 if(window.usedFont && window.usedFont.font == 0xecececec)
9982 FontResource uf = window.usedFont;
9983 char * className = window._class.name;
9984 char * text = window.text;
9987 for(c = window.firstChild; c; c = c.next)
9988 CheckFontIntegrity(c);
9992 public class ControllableWindow : Window
9994 /*WindowController controller;
9995 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9996 ~ControllableWindow() { delete controller; }*/
9999 class WindowControllerInterface : ControllableWindow
10001 bool OnKeyDown(Key key, unichar ch)
10003 bool result = controller.OnKeyDown ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyDown)((Window)controller.controlled, controller, key, ch) : true;
10006 bool (* onKeyDown)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown];
10008 result = onKeyDown(controller.window, key, ch);
10013 bool OnKeyUp(Key key, unichar ch)
10015 bool result = controller.OnKeyUp ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyUp)((Window)controller.controlled, controller, key, ch) : true;
10018 bool (* onKeyUp)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp];
10020 result = onKeyUp(controller.window, key, ch);
10025 bool OnKeyHit(Key key, unichar ch)
10027 bool result = controller.OnKeyHit ? ((bool(*)(Window, WindowController, Key, unichar))(void *)controller.OnKeyHit)((Window)controller.controlled, controller, key, ch) : true;
10030 bool (* onKeyHit)(Window, Key, unichar) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit];
10032 result = onKeyHit(controller.window, key, ch);
10037 bool OnMouseMove(int x, int y, Modifiers mods)
10039 bool result = controller.OnMouseMove ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMouseMove)((Window)controller.controlled, controller, x, y, mods) : true;
10042 bool(* onMouseMove)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove];
10044 result = onMouseMove(controller.window, x, y, mods);
10049 bool OnLeftButtonDown(int x, int y, Modifiers mods)
10051 bool result = controller.OnLeftButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10054 bool(* onLeftButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown];
10055 if(onLeftButtonDown)
10056 result = onLeftButtonDown(controller.window, x, y, mods);
10061 bool OnLeftButtonUp(int x, int y, Modifiers mods)
10063 bool result = controller.OnLeftButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10066 bool(* onLeftButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp];
10068 result = onLeftButtonUp(controller.window, x, y, mods);
10073 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
10075 bool result = controller.OnLeftDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnLeftDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10078 bool(* onLeftDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick];
10079 if(onLeftDoubleClick)
10080 result = onLeftDoubleClick(controller.window, x, y, mods);
10085 bool OnRightButtonDown(int x, int y, Modifiers mods)
10087 bool result = controller.OnRightButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10090 bool(* onRightButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown];
10091 if(onRightButtonDown)
10092 result = onRightButtonDown(controller.window, x, y, mods);
10097 bool OnRightButtonUp(int x, int y, Modifiers mods)
10099 bool result = controller.OnRightButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10102 bool(* onRightButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp];
10103 if(onRightButtonUp)
10104 result = onRightButtonUp(controller.window, x, y, mods);
10109 bool OnRightDoubleClick(int x, int y, Modifiers mods)
10111 bool result = controller.OnRightDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnRightDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10114 bool(* onRightDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick];
10115 if(onRightDoubleClick)
10116 result = onRightDoubleClick(controller.window, x, y, mods);
10121 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
10123 bool result = controller.OnMiddleButtonDown ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonDown)((Window)controller.controlled, controller, x, y, mods) : true;
10126 bool(* onMiddleButtonDown)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown];
10127 if(onMiddleButtonDown)
10128 result = onMiddleButtonDown(controller.window, x, y, mods);
10133 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
10135 bool result = controller.OnMiddleButtonUp ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleButtonUp)((Window)controller.controlled, controller, x, y, mods) : true;
10138 bool(* onMiddleButtonUp)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp];
10139 if(onMiddleButtonUp)
10140 result = onMiddleButtonUp(controller.window, x, y, mods);
10145 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
10147 bool result = controller.OnMiddleDoubleClick ? ((bool(*)(Window, WindowController, int, int, Modifiers))(void *)controller.OnMiddleDoubleClick)((Window)controller.controlled, controller, x, y, mods) : true;
10150 bool(* onMiddleDoubleClick)(Window, int, int, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick];
10151 if(onMiddleDoubleClick)
10152 onMiddleDoubleClick(controller.window, x, y, mods);
10157 bool OnMultiTouch(TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods)
10159 bool result = controller.OnMultiTouch ? ((bool(*)(Window, WindowController, TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers))(void *)controller.OnMultiTouch)((Window)controller.controlled, controller, event, infos, mods) : true;
10162 bool(* onMultiTouch)(Window, TouchPointerEvent, Array<TouchPointerInfo>, Modifiers) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMultiTouch];
10164 onMultiTouch(controller.window, event, infos, mods);
10169 void OnResize(int width, int height)
10171 if(controller.OnResize)
10172 ((void(*)(Window, WindowController, int, int))(void *)controller.OnResize)((Window)controller.controlled, controller, width, height);
10174 void(* onResize)(Window, int, int) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize];
10176 onResize(controller.window, width, height);
10180 void OnRedraw(Surface surface)
10182 if(controller.OnRedraw)
10183 ((void(*)(Window, WindowController, Surface))(void *)controller.OnRedraw)((Window)controller.controlled, controller, surface);
10185 void(* onRedraw)(Window, Surface) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw];
10187 onRedraw(controller.window, surface);
10193 bool result = controller.OnCreate ? ((bool(*)(Window, WindowController))(void *)controller.OnCreate)((Window)controller.controlled, controller) : true;
10196 bool(* onCreate)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate];
10198 result = onCreate(controller.window);
10203 bool OnLoadGraphics()
10205 bool result = controller.OnLoadGraphics ? ((bool(*)(Window, WindowController))(void *)controller.OnLoadGraphics)((Window)controller.controlled, controller) : true;
10208 bool(* onLoadGraphics)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLoadGraphics];
10210 result = onLoadGraphics(controller.window);
10215 void OnUnloadGraphics()
10217 if(controller.OnUnloadGraphics)
10218 ((void(*)(Window, WindowController))(void *)controller.OnUnloadGraphics)((Window)controller.controlled, controller);
10220 void(* onUnloadGraphics)(Window) = (void *)controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnUnloadGraphics];
10221 if(onUnloadGraphics)
10222 onUnloadGraphics(controller.window);
10227 public class WindowController<class V>
10229 void setWindow(Window value)
10231 uint size = class(Window).vTblSize;
10235 windowVTbl = new void *[size];
10236 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
10237 if(value._vTbl == value._class._vTbl)
10239 value._vTbl = new void *[value._class.vTblSize];
10240 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
10244 for(c = 0; c < size; c++)
10246 void * function = class(WindowControllerInterface)._vTbl[c];
10247 if(function && function != DefaultFunction)
10248 value._vTbl[c] = function;
10250 value._vTbl[c] = windowVTbl[c];
10256 memcpy(window._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
10262 property Window window
10264 get { return window; }
10266 property V controlled
10268 set { controlled = value; }
10269 get { return controlled; }
10271 // TODO: Add OnStateChange so we can implement SavedConfigWindow as a WindowController instead
10272 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
10273 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
10274 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
10275 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
10276 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
10277 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
10278 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10279 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
10280 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
10281 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10282 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
10283 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
10284 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
10285 virtual bool V::OnMultiTouch(WindowController controller, TouchPointerEvent event, Array<TouchPointerInfo> infos, Modifiers mods);
10286 virtual void V::OnResize(WindowController controller, int width, int height);
10287 virtual void V::OnRedraw(WindowController controller, Surface surface);
10288 virtual bool V::OnCreate(WindowController controller);
10289 virtual bool V::OnLoadGraphics(WindowController controller);
10290 virtual void V::OnUnloadGraphics(WindowController controller);
10293 public int (** windowVTbl)();
10297 ~WindowController()