7 import "GuiApplication"
28 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
32 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
41 // 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
42 define skinMenuHeight = 25;
43 define statusBarHeight = 18;
45 default extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
47 public enum DialogResult { cancel, yes, no, ok };
49 public class MouseButtons
52 bool left:1, right:1, middle:1;
55 public struct SizeAnchor
58 bool isClientW, isClientH;
63 #define SNAPDOWN(x, d) \
66 if(x < 0) x -= ((d) - Abs(x) % (d)); else x -= x % (d); \
69 #define SNAPUP(x, d) \
72 if(x > 0) x += ((d) - Abs(x) % (d)); else x += x % (d); \
75 /*static */define MAX_DIRTY_BACK = 10;
77 /////////////////////////////////////////////////////////////////////////////
78 ////////// EXTENT MANIPULATION //////////////////////////////////////////////
79 /////////////////////////////////////////////////////////////////////////////
81 #define ACCESS_ITEM(l, id) \
84 #define FASTLIST_LOOP(l, v) \
85 for(v = (BoxItem)l.first; v; v = (BoxItem)v.next)
87 #define FASTLIST_LOOPN(l, v, n) \
88 for(v = (BoxItem)l.first, n = (BoxItem)(v ? v.next : null); v; v = (BoxItem)next, n = (BoxItem)(v ? v.next : null))
91 #define ACCESS_ITEM(l, id) \
92 ((FastItem)(((id) == -1) ? null : (((byte *)((l).items)) + (id) * (l).itemSize)))
94 #define FASTLIST_LOOP(l, v) \
95 for(v = (void *)ACCESS_ITEM((l), (l).first); v; v = (void *)ACCESS_ITEM((l), v.next))
97 #define FASTLIST_LOOPN(l, v, n) \
98 for( v = (void *)ACCESS_ITEM((l), (l).first), \
99 n = v ? ((void *)ACCESS_ITEM((l), v.next)): null; \
100 v; v = n, n = n ? (void *)ACCESS_ITEM((l), n.next) : null)
103 private class FastItem : struct
108 private struct FastList
113 int count, size, itemSize;
120 first = last = free = -1;
128 // FASTLIST_LOOPN(this, item, next) { Delete(item); };
131 FastItem Add(uint itemSize)
134 if(free == -1 || !size)
141 newSize = (size + (size >> 1));
142 items = (FastItem)renew items byte[newSize * itemSize];
147 this.itemSize = itemSize;
148 items = (FastItem)new byte[newSize * itemSize];
151 for(c = size; c<newSize-1; c++)
153 ACCESS_ITEM(this, c).prev = -1;
154 ACCESS_ITEM(this, c).next = c+1;
156 ACCESS_ITEM(this, c).prev = -1;
157 ACCESS_ITEM(this, c).next = -1;
161 item = ACCESS_ITEM(this, free);
164 ACCESS_ITEM(this, item.prev).next = free;
174 void Delete(FastItem item)
177 ACCESS_ITEM(this, item.prev).next = item.next;
179 ACCESS_ITEM(this, item.next).prev = item.prev;
181 if(ACCESS_ITEM(this, first) == item)
183 if(ACCESS_ITEM(this, last) == item)
188 free = ((byte *)item - (byte *)items) / itemSize;
196 free = first = last = -1;
200 private class BoxItem : Item //FastItem
205 public /*private */struct Extent : OldList //FastList
214 //BoxItem extentBox = (BoxItem)Add(sizeof(class BoxItem));
215 Add(BoxItem { box = box });
218 void Copy(Extent source)
224 //FASTLIST_LOOP(source, extentBox)
225 for(extentBox = (BoxItem)source.first; extentBox; extentBox = (BoxItem)extentBox.next)
226 AddBox(extentBox.box);
229 void IntersectBox(Box box)
231 // Clip all boxes of extent against inside of the new box
232 BoxItem extentBox, next;
234 //FASTLIST_LOOPN(this, extentBox, next) // Macros still mess up the parser!
235 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
237 next = (BoxItem)extentBox.next;
238 if(box.left > extentBox.box.left) extentBox.box.left = box.left;
239 if(box.top > extentBox.box.top) extentBox.box.top = box.top;
240 if(box.right < extentBox.box.right) extentBox.box.right = box.right;
241 if(box.bottom < extentBox.box.bottom) extentBox.box.bottom = box.bottom;
242 if(extentBox.box.right < extentBox.box.left || extentBox.box.bottom < extentBox.box.top)
247 void ExcludeBox(Box box, Extent temp)
254 for(extentBox = (BoxItem)temp.first; extentBox; extentBox = (BoxItem)extentBox.next)
256 if(extentBox.box.left < box.right && extentBox.box.right > box.left &&
257 extentBox.box.top < box.bottom && extentBox.box.bottom > box.top)
260 if(extentBox.box.top < box.top && extentBox.box.bottom >= box.top)
264 extentBox.box.left, extentBox.box.top,
265 extentBox.box.right, Min(extentBox.box.bottom, box.top -1)
271 if(extentBox.box.bottom > box.bottom && extentBox.box.top <= box.bottom)
275 extentBox.box.left, Max(extentBox.box.top,box.bottom +1),
276 extentBox.box.right, extentBox.box.bottom
282 if(extentBox.box.bottom >= box.top && extentBox.box.top <= box.bottom)
285 if(extentBox.box.left < box.left && extentBox.box.right >= box.left)
289 extentBox.box.left, Max(extentBox.box.top, box.top),
290 Min(extentBox.box.right, box.left-1), Min(extentBox.box.bottom, box.bottom)
296 if(extentBox.box.right > box.right && extentBox.box.left <= box.right)
300 Max(extentBox.box.left, box.right+1), Max(extentBox.box.top, box.top),
301 extentBox.box.right, Min(extentBox.box.bottom, box.bottom)
309 AddBox(extentBox.box);
315 void UnionBox(Box box, Extent temp)
317 BoxItem extentBox, next;
319 // First pass: check if this box is not already covered by one of the extent's box
320 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
322 if(extentBox.box.left <= box.left && extentBox.box.right >= box.right &&
323 extentBox.box.top <= box.top && extentBox.box.bottom >= box.bottom)
330 // Second pass: only keep boxes not completely covered in the new box
331 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
333 next = (BoxItem)extentBox.next;
334 if(extentBox.box.left >= box.left && extentBox.box.right <= box.right &&
335 extentBox.box.top >= box.top && extentBox.box.bottom <= box.bottom)
339 // Add the exclusion to the extent
340 ExcludeBox(box, temp);
343 if(box.bottom >= box.top && box.right >= box.left)
345 // Optimization: if the resulting boxes touch, add them smarter
346 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
348 if(box.top == extentBox.box.top && box.bottom == extentBox.box.bottom)
350 if(Abs(box.right - extentBox.box.left) <= 1)
352 extentBox.box.left = box.left;
355 else if(Abs(box.left - extentBox.box.right) <= 1)
357 extentBox.box.right = box.right;
361 else if(box.left == extentBox.box.left && box.right == extentBox.box.right)
363 if(Abs(box.bottom - extentBox.box.top) <= 1)
365 extentBox.box.top = box.top;
368 else if(Abs(box.top - extentBox.box.bottom) <= 1)
370 extentBox.box.bottom = box.bottom;
382 void Union(Extent b, Extent temp)
386 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
387 UnionBox(extentBox.box, temp);
390 void Intersection(Extent b, Extent temp, Extent temp2, Extent temp3)
397 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
400 temp2.IntersectBox(extentBox.box);
407 void Exclusion(Extent b, Extent temp)
410 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
411 ExcludeBox(extentBox.box, temp);
414 void Offset(int x, int y)
417 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
419 extentBox.box.left += x;
420 extentBox.box.top += y;
421 extentBox.box.right += x;
422 extentBox.box.bottom += y;
427 private define MINIMIZED_WIDTH = 160;
428 private define CASCADE_SPACE = 16;
430 // namespace Windows;
432 private class ScrollFlags
434 bool snapX:1, snapY:1, dontHide:1;
437 public class BorderBits { public: bool contour:1, fixed:1, sizable:1, deep:1, bevel:1, thin:1; };
439 class WindowBits : BorderBits
441 BorderBits borderBits:6:0;
442 bool hidden:1, isActiveClient:1, hasHorzScroll:1, hasVertScroll:1, stayOnTop:1, modal:1, isDefault:1, inactive:1, isRemote:1, drawBehind:1;
443 bool interim:1, tabCycle:1, noCycle:1, dontScrollHorz:1, dontScrollVert:1, hasMaximize:1, hasMinimize:1, hasClose:1;
444 bool embedded:1, hasMenuBar:1, isDocument:1, showInTaskBar:1, hasStatusBar:1, nonClient:1, clickThrough:1;
447 public enum BorderStyle : BorderBits
450 contour = BorderBits { contour = true },
451 fixed = BorderBits { fixed = true } | contour,
452 sizable = BorderBits { sizable = true } | fixed,
453 thin = BorderBits { fixed = true, thin = true } | contour,
454 sizableThin = BorderBits { sizable = true } | thin,
455 deep = BorderBits { deep = true },
456 bevel = BorderBits { bevel = true },
457 sizableDeep = sizable|deep,
458 sizableBevel = sizable|bevel,
459 fixedDeep = fixed|deep,
460 fixedBevel = fixed|bevel,
461 deepContour = deep|contour
464 public enum CreationActivationOption
466 activate, flash, doNothing
469 public enum WindowState { normal, minimized, maximized };
471 private class ResPtr : struct
478 private class HotKeySlot : struct
480 HotKeySlot prev, next;
488 class_data char * icon;
490 class_default_property caption;
491 // class_initialize GuiApplication::Initialize;
492 class_designer FormDesigner;
493 class_property char * icon
495 set { class_data(icon) = value; }
496 get { return class_data(icon); }
501 if(guiApp) guiApp.Initialize(true);
503 if(guiApp && guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
505 if(_vTbl == ((subclass(Window))_class).pureVTbl)
507 _vTbl = _class._vTbl;
509 else if(_vTbl != _class._vTbl)
512 for(m = 0; m < _class.vTblSize; m++)
514 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
515 _vTbl[m] = _class._vTbl[m];
520 //tempExtents[0] = { /*first = -1, last = -1, free = -1*/ };
521 //tempExtents[1] = { /*first = -1, last = -1, free = -1*/ };
522 //tempExtents[2] = { /*first = -1, last = -1, free = -1*/ };
523 //tempExtents[3] = { /*first = -1, last = -1, free = -1*/ };
527 // caption = CopyString(class.name);
529 children.offset = (byte*)&prev - (byte*)this;
530 childrenOrder.circ = true;
531 childrenCycle.circ = true;
533 maxSize = Size { MAXINT, MAXINT };
537 //style.isActiveClient = true;
540 modifyVirtArea = true;
541 manageDisplay = true;
542 nativeDecorations = true;
544 // scrollFlags = ScrollFlags { snapX = true, snapY = true };
545 sbStep.x = sbStep.y = 8;
547 if(guiApp) // dynamic_cast<GuiApplication>(thisModule)
549 cursor = guiApp.GetCursor(arrow);
550 property::parent = guiApp.desktop;
562 stopwatching(parent, font);
563 if(parent.activeChild == this)
564 parent.activeChild = null;
565 if(parent.activeClient == this)
566 parent.activeClient = null;
571 // Prevent destructor from being called again...
577 /////////////////////////////////
580 OldLink slave = master.slaves.FindLink(this);
581 master.slaves.Delete(slave);
588 parent.childrenCycle.Remove(cycle);
590 parent.childrenOrder.Remove(order);
591 parent.children.Remove(this);
596 /////////////////////////////////
598 while(ptr = resources.first)
601 resources.Delete(ptr);
608 for(child = children.first; child; child = child.next)
610 // child.stopwatching(this, font);
612 eInstance_StopWatching(this, __ecereProp___ecereNameSpace__ecere__gui__Window_font, child);
613 // Don't want property here
614 *&child.parent = null;
617 while(slave = slaves.first)
619 // Don't want property here
620 *&((Window)slave.data).master = null;
621 slaves.Delete(slave);
624 // Because we do a decref in DestroyEx...
632 // Why was this commented?
633 //if(this != guiApp.desktop)
646 if(((subclass(Window))_class).pureVTbl)
648 if(_vTbl == _class._vTbl)
650 _vTbl = ((subclass(Window))_class).pureVTbl;
655 for(m = 0; m < _class.vTblSize; m++)
657 if(_vTbl[m] == _class._vTbl[m])
658 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
662 if(_vTbl == ((subclass(Window))_class).pureVTbl || _vTbl == _class._vTbl)
665 dirtyArea.Free(null);
666 renderArea.Free(null);
667 overRenderArea.Free(null);
668 clipExtent.Free(null);
669 scrollExtent.Free(null);
670 dirtyBack.Free(null);
674 tempExtents[0].Free(null);
675 tempExtents[1].Free(null);
676 tempExtents[2].Free(null);
677 tempExtents[3].Free(null);
682 //#if !defined(ECERE_VANILLA)
683 char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
685 if(this == activeDesigner)
689 char * name = property::name;
690 return name ? name : "";
695 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
696 bool OnGetDataFromString(char * string)
698 FormDesigner designer = (FormDesigner)activeDesigner.classDesigner;
701 if(!strcmp(string, "this") || !strcmp(string, designer.form.name))
702 this = designer.form;
703 else if(!strcmpi(string, "(Desktop)"))
704 this = activeDesigner;
706 return activeDesigner.FindObject(&this, string);
712 // --- Window updates system ---
714 // Setup a bitmap for Redrawing on client area of Window
715 Surface Redraw(Box box)
717 Surface surface = null;
719 Box clientArea = this.clientArea;
723 mox.left -= clientStart.x;
724 mox.top -= clientStart.y;
725 mox.right -= clientStart.x;
726 mox.bottom -= clientStart.y;
728 mox.Clip(clientArea);
729 // mox.ClipOffset(against, scrolledPos.x, scrolledPos.y);
731 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && mox.right >= mox.left && mox.bottom >= mox.top)
733 int x = absPosition.x + clientStart.x;
734 int y = absPosition.y + clientStart.y;
735 if(rootWindow.nativeDecorations)
737 x -= rootWindow.clientStart.x;
738 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
740 if(!guiApp.fullScreenMode || is3D)
742 x -= rootWindow.absPosition.x;
743 y -= rootWindow.absPosition.y;
747 x += rootWindow.parent.clientStart.x;
748 y += rootWindow.parent.clientStart.y;
750 mox.left += rootWindow.parent.clientStart.x;
751 mox.top += rootWindow.parent.clientStart.y;
752 mox.right += rootWindow.parent.clientStart.x;
753 mox.bottom += rootWindow.parent.clientStart.y;
758 surface = display.GetSurface(x, y, mox);
761 surface.width = clientSize.w;
762 surface.height = clientSize.h;
768 // Setup a bitmap for Redrawing on full Window
769 Surface RedrawFull(Box box)
771 Surface surface = null;
779 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && box.right >= box.left && box.bottom >= box.top)
781 int x = absPosition.x;
782 int y = absPosition.y;
783 if(rootWindow.nativeDecorations)
785 x -= rootWindow.clientStart.x;
786 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
788 if(!guiApp.fullScreenMode || is3D)
790 x -= rootWindow.absPosition.x;
791 y -= rootWindow.absPosition.y;
794 x += rootWindow.parent.clientStart.x;
795 y += rootWindow.parent.clientStart.y;
797 mox.left += rootWindow.parent.clientStart.x;
798 mox.top += rootWindow.parent.clientStart.y;
799 mox.right += rootWindow.parent.clientStart.x;
800 mox.bottom += rootWindow.parent.clientStart.y;
805 surface = display.GetSurface(x, y, mox);
808 surface.width = size.w;
809 surface.height = size.h;
815 void FigureCaption(char * caption)
817 Window activeClient = null;
821 strcpy(caption, this.caption);
822 if(style.isDocument || fileName)
824 if(caption[0]) strcat(caption, " - ");
826 strcat(caption, fileName);
830 sprintf(title, "Untitled %d", documentID);
831 strcat(caption, title);
834 strcat(caption, " *");
839 for(activeClient = this.activeClient; activeClient && !((BorderBits)activeClient.borderStyle).fixed; activeClient = activeClient.activeClient);
841 if(activeClient && activeClient.state == maximized)
843 if(activeClient.caption)
845 if(caption[0]) strcat(caption, " - ");
846 strcat(caption, activeClient.caption);
848 if(activeClient.style.isDocument || activeClient.fileName)
850 if(caption[0]) strcat(caption, " - ");
851 strcat(caption, "[");
852 if(activeClient.fileName)
853 strcat(caption, activeClient.fileName);
857 sprintf(title, "Untitled %d", activeClient.documentID);
858 strcat(caption, title);
860 if(activeClient.modifiedDocument)
861 strcat(caption, " *");
862 strcat(caption, "]");
867 // Code for returning dirty from ScrollDisplay:
869 for(d = 0; d<scrollExtent.count; d++)
871 Box * box = &scrollExtent.boxes[d];
877 Min(box.right, box.left-scroll.x),box.bottom
879 dirtyArea.UnionBox(update);
885 Max(box.left, box.right-scroll.x), box.top,
886 box.right, box.bottom
888 dirtyArea.UnionBox(update);
896 box.right, Min(box.bottom, box.top-scroll.y),
898 dirtyArea.UnionBox(update);
904 box.left, Max(box.top, box.bottom-scroll.y),
905 box.right, box.bottom
907 dirtyArea.UnionBox(update);
912 void UpdateDecorations(void)
914 // TODO: *** TEMPORARY HACK ***
921 Update({ -clientStart.x, -clientStart.y, -clientStart.x + size.w-1, 0 });
923 Update({ -clientStart.x, clientSize.h, -clientStart.x + size.w-1, -clientStart.y + size.h-1 });
925 Update({ -clientStart.x,0, -1, clientSize.h-1 });
927 Update({ clientSize.w, 0, -clientStart.x + size.w-1, clientSize.h-1 });
930 // Returns w & h for Position
931 void ComputeAnchors(Anchor anchor, SizeAnchor sizeAnchor, int *ox, int *oy, int *ow, int *oh)
933 Window parent = this.parent ? this.parent : guiApp.desktop;
934 int vpw = parent ? parent.clientSize.w : 0;
935 int vph = parent ? parent.clientSize.h : 0;
936 int pw = parent ? parent.clientSize.w : 0;
937 int ph = parent ? parent.clientSize.h : 0;
938 int w = sizeAnchor.size.w, h = sizeAnchor.size.h;
939 int x = anchor.left.distance, y = anchor.top.distance;
941 MinMaxValue ew = 0, eh = 0;
943 float cascadeW, cascadeH;
945 int tilingW, tilingH, tilingSplit, tilingLastH;
946 int addX = 0, addY = 0;
948 if(parent && rootWindow == this && guiApp && guiApp.interfaceDriver)
950 Window masterWindow = this;
951 Box box { addX, addY, addX + vpw - 1, addY + vph - 1 };
954 if(master == guiApp.desktop)
955 masterWindow = guiApp.desktop.activeChild;
957 masterWindow = master.rootWindow;
958 if(!masterWindow) masterWindow = this;
960 guiApp.interfaceDriver.GetScreenArea(masterWindow, box);
961 if((anchor.left.type == offset && anchor.right.type == offset) || anchor.left.type == none)
964 pw = vpw = box.right - box.left + 1;
966 if((anchor.top.type == offset && anchor.bottom.type == offset) || anchor.top.type == none)
969 ph = vph = box.bottom - box.top + 1;
985 vpw = pw = parent.size.w;
986 vph = ph = parent.size.h;
988 else if(!style.fixed /*|| style.isDocument*/)
990 if(!style.dontScrollHorz && parent.scrollArea.w) vpw = parent.scrollArea.w;
991 if(!style.dontScrollVert && parent.scrollArea.h) vph = parent.scrollArea.h;
993 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
996 Desktop3D_FixSize(&pw, &ph);
997 Desktop3D_FixSize(&vpw, &vph);
1000 if(pw < skinMinSize.w) pw = skinMinSize.w;
1001 if(ph < skinMinSize.h) ph = skinMinSize.h;
1002 if(vpw < skinMinSize.w) vpw = skinMinSize.w;
1003 if(vph < skinMinSize.h) vph = skinMinSize.h;
1005 // TODO: Must fix what we're snapping
1008 if(anchor.left.type)
1010 SNAPUP(x, textCellW);
1012 else if(anchor.right.type)
1014 SNAPDOWN(x, textCellW);
1019 SNAPUP(y, textCellH);
1021 else if(anchor.bottom.type)
1023 SNAPDOWN(y, textCellH);
1027 // This is required to get proper initial decoration size using native decorations on Windows
1028 if(nativeDecorations && guiApp && guiApp.interfaceDriver && !visible)
1029 guiApp.interfaceDriver.PositionRootWindow(this, x, y, Max(1, size.w), Max(1, size.h), true, true);
1030 GetDecorationsSize(&ew, &eh);
1032 if(anchor.left.type >= cascade && (state == normal /*|| state == Hidden*/))
1034 if(parent.sbv && !parent.sbv.style.hidden)
1035 pw += guiApp.currentSkin.VerticalSBW();
1036 if(parent.sbh && !parent.sbh.style.hidden)
1037 ph += guiApp.currentSkin.HorizontalSBH();
1039 if(anchor.left.type == cascade)
1041 w = (int)(pw * 0.80);
1042 h = (int)(ph * 0.80);
1044 else if(anchor.left.type >= vTiled)
1049 numTiling = parent.numPositions - parent.numIcons;
1050 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1051 if(anchor.left.type == vTiled)
1053 tilingH = (int)sqrt(numTiling);
1054 tilingW = numTiling / tilingH;
1058 tilingW = (int)sqrt(numTiling);
1059 tilingH = numTiling / tilingW;
1062 leftOver = numTiling - tilingH * tilingW;
1065 tilingSplit = (tilingW - leftOver) * tilingH;
1066 tilingLastH = tilingH+1;
1069 tilingSplit = numTiling;
1071 if(positionID >= tilingSplit)
1073 x = pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
1074 y = ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
1075 x2 = pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
1076 y2 = ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
1080 x = pw * (positionID / tilingH) / tilingW;
1081 y = ph * (positionID % tilingH) / tilingH;
1082 x2 = pw * (positionID / tilingH + 1) / tilingW;
1083 y2 = ph * ((positionID % tilingH) + 1) / tilingH;
1087 SNAPDOWN(x, textCellW);
1088 SNAPDOWN(y, textCellH);
1089 SNAPDOWN(x2, textCellW);
1090 SNAPDOWN(y2, textCellH);
1098 if(sizeAnchor.isClientW) w += ew;
1099 if(sizeAnchor.isClientH) h += eh;
1101 if(anchor.left.type == offset)
1102 x = anchor.left.distance;
1103 else if(anchor.left.type == relative)
1104 x = (anchor.left.percent < 0) ? ((int)(vpw * anchor.left.percent - 0.5)) : (int)(vpw * anchor.left.percent + 0.5);
1105 else if(anchor.right.type == relative)
1106 // ex = (anchor.right.percent < 0) ? ((int)(vpw * anchor.right.percent + 0)) : ((int)(vpw * anchor.right.percent + 0));
1107 ex = (anchor.right.percent < 0) ? ((int)(vpw * (1.0-anchor.right.percent) + 0)) : ((int)(vpw * (1.0-anchor.right.percent) + 0));
1108 else if(anchor.right.type == offset)
1109 ex = vpw - anchor.right.distance;
1111 if(anchor.top.type == offset)
1112 y = anchor.top.distance;
1113 else if(anchor.top.type == relative)
1114 y = (anchor.top.percent < 0) ? ((int)(vph * anchor.top.percent - 0.5)) : ((int)(vph * anchor.top.percent + 0.5));
1115 else if(anchor.bottom.type == relative)
1116 //ey = (anchor.bottom.percent < 0) ? ((int)(vph * anchor.bottom.percent + 0)) : ((int)(vph * anchor.bottom.percent + 0));
1117 ey = (anchor.bottom.percent < 0) ? ((int)(vph * (1.0-anchor.bottom.percent) + 0)) : ((int)(vph * (1.0-anchor.bottom.percent) + 0));
1118 else if(anchor.bottom.type == offset)
1119 ey = vph - anchor.bottom.distance;
1121 if(anchor.left.type && anchor.right.type)
1123 switch(anchor.right.type)
1126 ex = pw * (1.0f-anchor.right.percent);
1127 w = Max((int)(ex + 0.5) - x, 0);
1130 ex = vpw - anchor.right.distance;
1131 w = Max((int)(ex + 0.5) - x, 0);
1135 if(anchor.top.type && anchor.bottom.type)
1137 switch(anchor.bottom.type)
1140 ey = ph * (1.0f-anchor.bottom.percent);
1141 h = Max((int)(ey + 0.5) - y, 0);
1144 ey = vph - anchor.bottom.distance;
1145 h = Max((int)(ey + 0.5) - y, 0);
1154 if(state == normal /*|| state == Hidden*/)
1156 bool addSbV = false, addSbH = false;
1158 if(sizeAnchor.isClientW || (anchor.left.type && anchor.right.type)) w = Max(w, 1); else w = Max(w, 0);
1159 if(sizeAnchor.isClientH || (anchor.top.type && anchor.bottom.type)) h = Max(h, 1); else h = Max(h, 0);
1161 w = Max(w, minSize.w);
1162 h = Max(h, minSize.h);
1163 w = Min(w, maxSize.w);
1164 h = Min(h, maxSize.h);
1166 if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
1168 if(w) w -= guiApp.currentSkin.VerticalSBW();
1171 if((sizeAnchor.isClientH || !h || (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
1173 if(h) h -= guiApp.currentSkin.HorizontalSBH();
1177 if(!OnResizing(&w, &h))
1183 if((addSbV)) // || reqScrollArea.h > h) && sbv)
1184 w += guiApp.currentSkin.VerticalSBW();
1185 if((addSbH)) // || reqScrollArea.w > w) && sbh)
1186 h += guiApp.currentSkin.HorizontalSBH();
1188 w = Max(w, skinMinSize.w);
1189 h = Max(h, skinMinSize.h);
1202 SNAPDOWN(w, textCellW);
1203 SNAPDOWN(h, textCellH);
1206 if(anchor.left.type == cascade && (state == normal /*|| state == Hidden*/))
1208 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1211 (pw - w) / CASCADE_SPACE,
1212 (ph - h) / CASCADE_SPACE);
1218 cascW = (pw - w) / (numCascade-1);
1219 cascH = (ph - h) / (numCascade-1);
1220 SNAPDOWN(cascW, textCellW);
1221 SNAPDOWN(cascH, textCellH);
1222 cascadeW = (float)cascW;
1223 cascadeH = (float)cascH;
1227 numCascade = Max(numCascade, 2);
1228 cascadeW = (float)(pw - w) / (numCascade-1);
1229 cascadeH = (float)(ph - h) / (numCascade-1);
1232 x = (int)((positionID % numCascade) * cascadeW);
1233 y = (int)((positionID % numCascade) * cascadeH);
1235 else if(anchor.left.type < vTiled)
1237 if(!anchor.left.type || anchor.horz.type == middleRelative)
1239 if(!anchor.right.type)
1241 if(anchor.horz.type == middleRelative)
1242 x = (int)(vpw * (0.5 + anchor.horz.percent) - w / 2);
1244 x = vpw / 2 + anchor.horz.distance - w / 2;
1250 // case A_EDGE: x = x - w; break;
1252 if(!anchor.top.type || anchor.vert.type == middleRelative)
1254 if(!anchor.bottom.type)
1256 if(anchor.vert.type == middleRelative)
1257 y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
1259 y = vph / 2 + anchor.vert.distance - h / 2;
1265 // case A_EDGE: y = y - h; break;
1268 if((state == normal /*|| state == Hidden*/) && !OnMoving(&x, &y, w, h))
1276 SNAPDOWN(x, textCellW);
1277 SNAPDOWN(y, textCellH);
1289 if(anchored && style.fixed && style.isActiveClient)
1294 void UpdateCaret(bool forceUpdate, bool erase)
1296 static Window lastWindow = null;
1297 static int caretX, caretY, caretSize;
1299 if(guiApp && guiApp.caretOwner == this)
1301 int x = caretPos.x - scroll.x;
1302 int y = caretPos.y - scroll.y;
1304 if((erase || this.caretSize) &&
1305 x >= clientArea.left && x <= clientArea.right &&
1306 y >= clientArea.top && y <= clientArea.bottom)
1310 guiApp.interfaceDriver.SetCaret(
1311 x + absPosition.x + clientStart.x,
1312 y + absPosition.y + clientStart.y, this.caretSize);
1313 guiApp.caretEnabled = true;
1315 if(erase || lastWindow != this || caretX != x || caretY != y || caretSize != this.caretSize || forceUpdate)
1319 if(lastWindow != this)
1321 updateBox.left = x + 1;
1323 updateBox.right = x + 2;
1324 updateBox.bottom = y + this.caretSize - 1;
1328 updateBox.left = Min(x + 1, caretX + 1);
1329 updateBox.top = Min(y, caretY);
1330 updateBox.right = Max(x + 2, caretX + 2);
1331 updateBox.bottom = Max(y + this.caretSize - 1, caretY + caretSize - 1);
1334 guiApp.caretOwner.Update(updateBox);
1341 caretSize = this.caretSize;
1347 guiApp.interfaceDriver.SetCaret(0,0,0);
1348 guiApp.caretEnabled = false;
1354 void SetPosition(int x, int y, int w, int h, bool modifyArea, bool modifyThisArea, bool modifyClientArea)
1359 scrolledPos.x = position.x = x;
1360 scrolledPos.y = position.y = y;
1362 clientSize.w = size.w = w;
1363 clientSize.h = size.h = h;
1365 if(parent && !style.nonClient)
1367 //if(!style.fixed || style.isDocument)
1369 if(!style.dontScrollHorz) scrolledPos.x -= parent.scroll.x;
1370 if(!style.dontScrollVert) scrolledPos.y -= parent.scroll.y;
1374 clientStart.x = clientStart.y = 0;
1376 SetWindowArea(&clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1378 //if(!activeClient || activeClient.state != maximized)
1379 if(!noAutoScrollArea)
1381 // Check if scroll area must be modified
1382 if(guiApp && !guiApp.modeSwitching && (sbv || sbh))
1384 bool foundChild = false;
1386 int cw = clientSize.w;// + ((!sbv || sbv.range > 1) ? guiApp.currentSkin.VerticalSBW() : 0);
1387 int ch = clientSize.h;// + ((!sbh || sbh.rangw > 1) ? guiApp.currentSkin.HorizontalSBH() : 0);
1388 for(child = children.first; child; child = child.next)
1390 if(child.modifyVirtArea && !child.style.hidden && child.created && /*!child.anchored &&*/
1391 !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1393 if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == offset)
1394 w = Max(w, child.position.x + child.size.w);
1395 else if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == none)
1396 w = Max(w, Max(child.position.x, 0) + child.size.w);
1397 if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == offset)
1398 h = Max(h, child.position.y + child.size.h);
1399 else if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == none)
1400 h = Max(h, Max(child.position.y, 0) + child.size.h);
1405 if(foundChild && (w > cw || h > ch))
1407 //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
1409 int stepX = sbStep.x, stepY = sbStep.y;
1410 // Needed to make snapped down position match the skin's check of client area
1411 // against realvirtual
1414 SNAPDOWN(stepX, textCellW);
1415 SNAPDOWN(stepY, textCellH);
1416 stepX = Max(stepX, textCellW);
1417 stepY = Max(stepY, textCellH);
1419 if(scrollFlags.snapX)
1421 if(scrollFlags.snapY)
1424 reqScrollArea.w = w;
1425 reqScrollArea.h = h;
1428 else if(reqScrollArea.w || reqScrollArea.h)
1430 reqScrollArea.w = 0;
1431 reqScrollArea.h = 0;
1432 SetScrollPosition(0,0);
1437 // Automatic MDI Client Scrolling Area Adjustment
1438 if(parent && !parent.noAutoScrollArea)
1440 if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
1441 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
1443 Window parent = this.parent;
1444 int w = parent.reqScrollArea.w;
1445 int h = parent.reqScrollArea.h;
1447 if(stateAnchor.right.type == none && stateAnchor.left.type == offset)
1448 w = Max(w, position.x + size.w);
1449 else if(stateAnchor.right.type == none && stateAnchor.left.type == none)
1450 w = Max(w, Max(position.x, 0) + size.w);
1451 if(stateAnchor.bottom.type == none && stateAnchor.top.type == offset)
1452 h = Max(h, position.y + size.h);
1453 else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
1454 h = Max(h, Max(position.y, 0) + size.h);
1456 if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
1457 (h > parent.clientSize.h && h > parent.reqScrollArea.h))
1459 /*bool resize = false;
1460 int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
1461 // Needed to make snapped down position match the skin's check of client area
1462 // against realvirtual
1465 SNAPDOWN(stepX, textCellW);
1466 SNAPDOWN(stepY, textCellH);
1467 stepX = Max(stepX, textCellW);
1468 stepY = Max(stepY, textCellH);
1470 if(parent.scrollFlags.snapX)
1472 if(parent.scrollFlags.snapY)
1474 if(parent.reqScrollArea.w != w || parent.reqScrollArea.h != h)
1476 parent.reqScrollArea.w = w;
1477 parent.reqScrollArea.h = h;*/
1479 // parent.UpdateScrollBars(true, true);
1480 parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1481 false, true, true, true, false, false);
1486 GetRidOfVirtualArea();
1490 UpdateScrollBars(modifyThisArea, false);
1491 else if(guiApp.currentSkin)
1494 &clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1496 if(sbv && (scrollFlags.dontHide || sbv.range > 1))
1497 clientSize.w -= guiApp.currentSkin.VerticalSBW();
1498 if(sbh && (scrollFlags.dontHide || sbh.range > 1))
1499 clientSize.h -= guiApp.currentSkin.HorizontalSBH();
1502 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1503 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1505 absPosition = scrolledPos;
1506 if(guiApp && guiApp.driver != null && guiApp.interfaceDriver)
1507 guiApp.interfaceDriver.OffsetWindow(this, &absPosition.x, &absPosition.y);
1509 if(this != guiApp.desktop && parent)
1511 absPosition.x += parent.absPosition.x;
1512 absPosition.y += parent.absPosition.y;
1513 if(!style.nonClient && this != guiApp.desktop)
1515 absPosition.x += parent.clientStart.x;
1516 absPosition.y += parent.clientStart.y;
1520 box = Box { 0, 0, size.w - 1, size.h - 1 };
1525 // Clip against parent's client area
1526 box.ClipOffset(against, scrolledPos.x, scrolledPos.y);
1528 // Compute client area in this window coordinate system
1529 clientArea.left = 0;
1531 clientArea.right = clientSize.w - 1;
1532 clientArea.bottom = clientSize.h - 1;
1534 // Clip against parent's client area
1536 clientArea.ClipOffset(against, scrolledPos.x + clientStart.x, scrolledPos.y + clientStart.y);
1540 //absPosition.x -= parent.clientStart.x;
1541 //absPosition.y -= parent.clientStart.y;
1544 // Adjust all children
1545 for(child = children.first; child; child = child.next)
1546 child.SetPosition(child.position.x, child.position.y, child.size.w, child.size.h, false, true, true);
1548 UpdateCaret(false, false);
1551 void GetRidOfVirtualArea(void)
1553 if(parent && !parent.destroyed && style.fixed &&
1554 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient &&
1555 parent.reqScrollArea.w && parent.reqScrollArea.h)
1557 if(!parent.noAutoScrollArea)
1561 for(child = children.first; child; child = child.next)
1563 if(child.modifyVirtArea && !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1565 if(child.position.x + child.size.w > parent.clientSize.w + ((!parent.sbv || parent.sbv.style.hidden) ? 0 : guiApp.currentSkin.VerticalSBW()) ||
1566 child.position.y + child.size.h > parent.clientSize.h + ((!parent.sbh || parent.sbh.style.hidden) ? 0 : guiApp.currentSkin.HorizontalSBH()))
1575 Window parent = this.parent;
1577 parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1578 false, true, true, true, false, false);
1580 parent.SetScrollArea(0,0,true);
1581 parent.SetScrollPosition(0,0);
1587 public void ExternalPosition(int x, int y, int w, int h)
1589 Position(x, y, w, h, false, true, true, true, false, false);
1592 // (w, h): Full window size
1593 bool Position(int x, int y, int w, int h, bool force, bool processAnchors, bool modifyArea, bool updateScrollBars, bool thisOnly, bool changeRootWindow)
1595 bool result = false;
1596 int oldCW = clientSize.w, oldCH = clientSize.h;
1597 bool clientResized, windowResized, windowMoved;
1599 bool realResized = size.w != w || size.h != h;
1601 // TOCHECK: This wasn't in ecere.dll
1602 //if(!parent) return true;
1603 if(destroyed) return false;
1605 windowMoved = position.x != x || position.y != y || force;
1607 // windowResized = realResized || force;
1608 windowResized = size.w != w || size.h != h || force;
1610 if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
1616 scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
1617 scrolledPos.x - parent.clientStart.x + this.box.right,
1618 scrolledPos.y - parent.clientStart.y + this.box.bottom
1624 Box box { scrolledPos.x + this.box.left, scrolledPos.y + this.box.top, scrolledPos.x + this.box.right, scrolledPos.y + this.box.bottom};
1629 SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
1631 clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
1632 if(clientResized && this == rootWindow && nativeDecorations)
1633 windowResized = true;
1635 if(display && rootWindow != this)
1638 if(guiApp && guiApp.windowMoving)
1640 if(guiApp.windowMoving.style.nonClient)
1641 guiApp.windowMoving.parent.SetMouseRangeToWindow();
1643 guiApp.windowMoving.parent.SetMouseRangeToClient();
1653 // Buttons bitmap resources crash if we do this while switching mode
1654 if(!guiApp || !guiApp.modeSwitching)
1657 // Process Anchored Children
1661 for(child = children.first; child; child = child.next)
1664 ((child.stateAnchor.left.type != offset ||
1665 child.stateAnchor.top.type != offset ||
1666 child.stateAnchor.right.type != none ||
1667 child.stateAnchor.bottom.type != none) ||
1668 child.state == maximized || child.state == minimized))
1670 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1672 // child.Position(x, y, w, h, false, true, true, true, false);
1673 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1674 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1680 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1681 //if(updateScrollBars)
1683 OnResize(clientSize.w, clientSize.h);
1685 if((clientResized || windowMoved) && created)
1686 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1688 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1690 Window master = guiApp.interimWindow.master;
1691 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1694 if(rootWindow == this && !is3D)
1698 x -= guiApp.desktop.absPosition.x;
1699 y -= guiApp.desktop.absPosition.y;
1701 //guiApp.Log("Position %s\n", caption);
1702 if(windowResized || windowMoved)
1703 if(display && !display.flags.memBackBuffer && changeRootWindow)
1704 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1706 if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved))
1707 for(child = parent.children.first; child && child != this; child = child.next)
1708 if(child.rootWindow)
1709 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1713 if(windowMoved || windowResized)
1715 display.Lock(true /*false*/);
1718 display.Position(absPosition.x, absPosition.y);
1719 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1722 // result = realResized ? display.Resize(size.w, size.h) : true;
1723 if(nativeDecorations)
1725 int w = clientSize.w, h = clientSize.h;
1726 if(hasMenuBar) h += skinMenuHeight;
1727 if(hasStatusBar) h += statusBarHeight;
1728 if(sbv && sbv.visible) w += sbv.size.w;
1729 if(sbh && sbh.visible) h += sbh.size.h;
1730 result = manageDisplay ? display.Resize(w, h) : true;
1733 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1737 else if(clientResized)
1739 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1742 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1746 if(windowMoved || windowResized)
1751 if(guiApp.driver && changeRootWindow)
1753 if(windowResized || windowMoved)
1754 if(!display || display.flags.memBackBuffer)
1755 guiApp.interfaceDriver.PositionRootWindow(this,
1756 x, y, w, h, windowMoved, windowResized);
1757 guiApp.interfaceDriver.UpdateRootWindow(this);
1759 for(child = children.first; child; child = child.next)
1761 if(child.is3D && child.created)
1763 // Copy Display Content
1764 child.display.displaySystem = display.displaySystem;
1765 child.display.window = display.window;
1766 child.display.current = display.current;
1767 child.display.width = display.width;
1768 child.display.height = display.height;
1769 child.display.driverData = display.driverData;
1770 child.display.mutex = null;
1781 void UpdateScrollBars(bool flag, bool fullThing)
1784 bool resizeH = false, resizeV = false;
1785 bool scrolled = false;
1786 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1787 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1789 if(destroyed) return;
1790 if(guiApp.currentSkin)
1792 MinMaxValue cw = 0, ch = 0;
1793 bool sbvVisible, sbhVisible;
1795 int positionH, positionV;
1797 // First get client area with no respect to scroll bars
1802 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1804 if(scrollFlags.dontHide)
1807 cw -= guiApp.currentSkin.VerticalSBW();
1809 ch -= guiApp.currentSkin.HorizontalSBH();
1811 // Update the scrollbar visibility
1817 sbh.disabled = rangeH <= 1;
1818 if(sbh.style.hidden)
1828 sbv.disabled = rangeV <= 1;
1829 if(sbv.style.hidden)
1837 // Then start off with horizontal scrollbar range
1840 positionH = sbh.thumbPosition;
1845 ch -= guiApp.currentSkin.HorizontalSBH();
1848 // Do the same for vertical scrollbar
1851 positionV = sbv.thumbPosition;
1857 cw -= guiApp.currentSkin.VerticalSBW();
1858 // Maybe we need to set the range on the horizontal scrollbar again
1863 sbh.Action(setRange, positionH, 0);
1864 if(rangeH <= 1 && sbh.range > 1)
1866 ch -= guiApp.currentSkin.HorizontalSBH();
1870 sbv.Action(setRange, positionV, 0);
1877 // Update the scrollbar visibility
1878 if(!scrollFlags.dontHide)
1880 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
1884 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
1891 if(guiApp.currentSkin)
1898 sbhVisible = sbh.style.hidden ? true : false;
1900 sbvVisible = sbv.style.hidden ? true : false;
1902 // Do our resize here
1903 if(flag && (resizeH || resizeV) && fullThing)
1905 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
1910 OnResize(clientSize.w, clientSize.h);
1916 sbh.visible = sbhVisible;
1918 sbv.visible = sbvVisible;
1920 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1921 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1924 sbh.pageStep = clientSize.w;
1926 sbv.pageStep = clientSize.h;
1928 // Notify doesn't handle setRange anymore... process it here
1931 int positionH = sbh.thumbPosition;
1932 if(scroll.x != positionH)
1934 OnHScroll(setRange, positionH, 0);
1938 SNAPDOWN(positionH, textCellW);
1939 scroll.x = positionH;
1945 int seen = clientSize.w, total = reqScrollArea.w;
1948 if(scrollFlags.snapX)
1949 SNAPDOWN(seen, sbStep.x);
1951 if(!total) total = seen;
1952 range = total - seen + 1;
1954 range = Max(range, 1);
1956 if(x >= range) x = range - 1;
1958 if(scrollFlags.snapX)
1959 SNAPUP(x, sbStep.x);
1963 OnHScroll(setRange, x, 0);
1968 SNAPDOWN(x, textCellW);
1974 int positionV = sbv.thumbPosition;
1975 if(scroll.y != positionV)
1977 OnVScroll(setRange, positionV, 0);
1981 SNAPDOWN(positionV, textCellH);
1982 scroll.y = positionV;
1988 int seen = clientSize.h, total = reqScrollArea.h;
1991 if(scrollFlags.snapY)
1992 SNAPDOWN(seen, sbStep.y);
1994 if(!total) total = seen;
1995 range = total - seen + 1;
1996 range = Max(range, 1);
1998 if(y >= range) y = range - 1;
2000 if(scrollFlags.snapY)
2001 SNAPUP(y, sbStep.y);
2005 OnVScroll(setRange, y, 0);
2010 SNAPDOWN(y, textCellH);
2016 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2019 for(child = children.first; child; child = child.next)
2021 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2024 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2025 child.Position(x, y, w, h, false, true, false, true, false, false);
2032 // Process Scrollbars
2034 if(sbh) // && !sbh.style.hidden
2036 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2037 // Need to set the range again (should improve...) since the scrollbars didn't have
2038 // the right size when UpdateScrollArea set the range on it
2041 sbh.seen = clientSize.w;
2045 if(sbv) // && !sbv.state.hidden
2047 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2048 // Need to set the range again (should improve...) since the scrollbars didn't have
2049 // the right size when UpdateScrollArea set the range on it
2052 sbv.seen = clientSize.h;
2057 // TESTING THIS LOWER
2058 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2061 for(child = children.first; child; child = child.next)
2063 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2066 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2067 child.Position(x, y, w, h, false, true, false, true, false, false);
2073 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2075 SetState(maximized, false, mods);
2079 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2081 SetState(normal, false, mods);
2085 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2087 SetState(minimized, false, mods);
2088 parent.CycleChildren(false, true, false, true);
2092 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2095 // Scroll bar notifications
2096 if(action != setRange)
2098 bool changed = false;
2102 if(scroll.x != position)
2104 OnHScroll(action, position, keyFlags);
2109 SNAPDOWN(position, textCellW);
2111 scroll.x = position;
2115 if(scroll.y != position)
2117 OnVScroll(action, position, keyFlags);
2122 SNAPDOWN(position, textCellH);
2124 scroll.y = position;
2128 bool childMove = false;
2129 for(child = children.first; child; child = child.next)
2131 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2134 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2135 child.Position(x, y, w, h, false, true, false, true, false, false);
2139 // Testing this patch out to solve MDI workspace redraw bugs
2140 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2141 // Scroll offsets to blame?
2145 UpdateCaret(false, false);
2149 // Testing this patch out to solve MDI workspace redraw bugs
2150 for(child = children.first; child; child = child.next)
2152 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2161 Window GetParentMenuBar()
2163 Window menuBarParent;
2164 for(menuBarParent = this; menuBarParent; menuBarParent = menuBarParent.parent)
2166 if(menuBarParent.menuBar) break;
2167 if(menuBarParent.parent && /*menuBarParent != */!menuBarParent.parent.activeClient)
2169 menuBarParent = null;
2173 return menuBarParent ? menuBarParent.menuBar : null;
2176 void CreateSystemChildren(void)
2178 Window parent = this;
2179 bool scrollBarChanged = false;
2180 bool hasClose = false, hasMaxMin = false;
2181 Point scroll = this.scroll;
2183 if(state == maximized)
2184 parent = GetParentMenuBar();
2188 if(style.hasClose) hasClose = true;
2189 if(style.hasMaximize || style.hasMinimize)
2196 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2198 sysButtons[2].Destroy(0);
2199 sysButtons[2] = null;
2201 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2203 sysButtons[1].Destroy(0);
2204 sysButtons[1] = null;
2206 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2208 sysButtons[0].Destroy(0);
2209 sysButtons[0] = null;
2212 if(hasClose && parent)
2219 parent, master = this,
2220 inactive = true, nonClient = true, visible = false;
2222 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2228 if(this.parent == guiApp.desktop)
2229 sysButtons[2].hotKey = altF4;
2230 else if(style.isActiveClient)
2231 sysButtons[2].hotKey = ctrlF4;
2232 sysButtons[2].Create();
2235 sysButtons[2].symbol = 'X';
2236 sysButtons[2].disabled = !style.hasClose;
2239 if(hasMaxMin && parent)
2243 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2244 if(state == maximized)
2247 method = RestoreButtonClicked;
2253 method = MaximizeButtonClicked;
2261 parent, master = this,
2262 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2264 sysButtons[1].Create();
2266 sysButtons[1].NotifyClicked = method;
2268 sysButtons[1].symbol = symbol;
2269 sysButtons[1].disabled = !style.hasMaximize;
2272 if(hasMaxMin && parent)
2276 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2277 if (state == minimized)
2280 method = RestoreButtonClicked;
2286 method = MinimizeButtonClicked;
2294 parent, master = this,
2295 hotKey = altM, inactive = true, nonClient = true, visible = false
2297 sysButtons[0].Create();
2299 sysButtons[0].NotifyClicked = method;
2301 sysButtons[0].symbol = symbol;
2302 sysButtons[0].disabled = !style.hasMinimize;
2305 // Create the scrollbars
2306 if(style.hasHorzScroll && !sbh)
2312 direction = horizontal,
2316 snap = scrollFlags.snapX,
2317 NotifyScrolling = ScrollBarNotification
2320 scrollBarChanged = true;
2322 else if(sbh && !style.hasHorzScroll)
2328 if(style.hasVertScroll && !sbv)
2334 direction = vertical,
2338 snap = scrollFlags.snapY,
2339 NotifyScrolling = ScrollBarNotification
2342 scrollBarChanged = true;
2344 else if(sbv && !style.hasVertScroll)
2349 if(scrollBarChanged)
2351 SetScrollLineStep(sbStep.x, sbStep.y);
2352 UpdateScrollBars(true, true);
2356 if(scrollBarChanged)
2358 if(sbh) sbh.thumbPosition = scroll.x;
2359 if(sbv) sbv.thumbPosition = scroll.y;
2363 void UpdateCaption(void)
2365 if(rootWindow == this)
2368 FigureCaption(caption);
2369 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2371 UpdateDecorations();
2374 if(parent.rootWindow == parent && parent.activeClient == this) // Added this last check
2377 parent.FigureCaption(caption);
2378 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2380 parent.UpdateDecorations();
2384 void UpdateActiveDocument(Window previous)
2386 Window activeClient = this.activeClient;
2387 Window activeChild = this.activeChild;
2394 activeClient.CreateSystemChildren();
2396 previous.CreateSystemChildren();
2408 // Build window list
2411 Menu windowMenu = menu.FindMenu("Window");
2416 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2419 Window document = cycle.data;
2420 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2422 char name[2048], caption[2048];
2423 document.FigureCaption(caption);
2424 sprintf(name, "%d %s", id+1, caption);
2425 windowMenu.AddDynamic(MenuItem
2427 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2428 NotifySelect = MenuWindowSelectWindow
2432 if(activeClient.cycle == cycle) break;
2437 if((!previous && activeClient) || !activeClient)
2443 item = menu.FindItem(MenuWindowCloseAll, 0);
2444 if(item) item.disabled = false;
2445 item = menu.FindItem(MenuWindowNext, 0);
2446 if(item) item.disabled = false;
2447 item = menu.FindItem(MenuWindowPrevious, 0);
2448 if(item) item.disabled = false;
2449 item = menu.FindItem(MenuWindowCascade, 0);
2450 if(item) item.disabled = false;
2451 item = menu.FindItem(MenuWindowTileHorz, 0);
2452 if(item) item.disabled = false;
2453 item = menu.FindItem(MenuWindowTileVert, 0);
2454 if(item) item.disabled = false;
2455 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2456 if(item) item.disabled = false;
2457 item = menu.FindItem(MenuWindowWindows, 0);
2458 if(item) item.disabled = false;
2461 item = menu.FindItem(MenuFileClose, 0);
2462 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2463 item = menu.FindItem(MenuFileSaveAll, 0);
2464 if(item) item.disabled = numDocuments < 1;
2466 if(activeClient && activeClient.menu && activeClient.state != minimized)
2470 //activeClient.menu.Clean(activeClient);
2471 menu.Merge(activeClient.menu, true, activeClient);
2475 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2478 menu.Merge(activeChild.menu, true, activeChild);
2481 // This is called again for a child window change, with same active client
2482 OnActivateClient(activeClient, previous);
2483 if(!menuBar && !((BorderBits)borderStyle).fixed && parent && parent.activeClient == this)
2484 parent.UpdateActiveDocument(null);
2487 void _ShowDecorations(Box box, bool post)
2489 if(rootWindow == this && nativeDecorations) return;
2490 if(visible && this != guiApp.desktop)
2492 Surface surface = RedrawFull(box);
2496 FigureCaption(caption);
2499 ShowDecorations(captionFont.font,
2502 active, //parent.activeClient == this
2503 guiApp.windowMoving == this);
2505 PreShowDecorations(captionFont.font,
2508 active, //parent.activeClient == this
2509 guiApp.windowMoving == this);
2516 void UpdateExtent(Box refresh)
2518 Surface surface = null;
2520 if(!manageDisplay) { OnRedraw(null);return; }
2521 _ShowDecorations(refresh, false);
2523 surface = Redraw(refresh);
2524 // Opaque background: just fill before EW_REDRAW (clear?)
2527 surface.SetBackground(background);
2528 surface.SetForeground(foreground);
2529 surface.DrawingChar(' ');
2530 if(this == rootWindow)
2532 if(style.drawBehind || background.a)
2534 int a = background.a;
2535 // Premultiply alpha for clear color
2536 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2537 surface.Clear(colorBuffer);
2538 surface.SetBackground(background);
2541 else if(background.a)
2545 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2546 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2549 if(display.flags.alpha && background.a < 255 && background)
2551 surface.Area(0,0,clientSize.w, clientSize.h);
2552 /*if(style.clearDepthBuffer)
2553 surface.Clear(depthBuffer);*/
2555 else if(/*style.clearDepthBuffer || */background.a)
2557 int a = background.a;
2558 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2559 // Premultiply alpha for clear color
2560 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2561 surface.Clear(colorBuffer);
2562 surface.SetBackground(background);
2567 surface.TextFont(usedFont.font);
2568 surface.TextOpacity(false);
2572 // Draw the caret ...
2573 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2575 // surface.SetBackground(0xFFFFFF - background.color);
2576 surface.SetBackground(~background.color);
2578 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2579 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2585 void DrawOverChildren(Box refresh)
2587 Surface surface = Redraw(refresh);
2591 surface.DrawingChar(' ');
2592 surface.SetBackground(background);
2593 surface.SetForeground(foreground);
2595 surface.TextFont(usedFont.font);
2596 surface.TextOpacity(false);
2598 OnDrawOverChildren(surface);
2603 _ShowDecorations(refresh, true);
2606 void ComputeClipExtents(void)
2609 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2611 clipExtent.Copy(this.clipExtent);
2613 for(child = children.last; child; child = child.prev)
2615 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2617 bool opaque = child.IsOpaque(); // TODO: acess background directly
2618 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2620 child.clipExtent.Copy(clipExtent);
2621 child.clipExtent.Offset(-dx, -dy);
2622 child.clipExtent.IntersectBox(child.box);
2624 child.ComputeClipExtents();
2626 if(opaque && !child.style.nonClient)
2628 // Adjust the box for the parent:
2629 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2630 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2635 // ??? Only do this for overlapped window or if parent has with clip children flag
2637 // Do this if window has clip children flag on (default false?)
2638 // this.clipExtent = clipExtent;
2640 clipExtent.Free(null);
2643 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2645 bool opaque = IsOpaque();
2647 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2648 if(rootWindow.nativeDecorations)
2650 offsetX -= rootWindow.clientStart.x;
2651 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2655 for(child = children.last; child; child = child.prev)
2657 ColorAlpha background = *(ColorAlpha *)&child.background;
2658 bool opaque = child.IsOpaque();
2659 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2663 // Adjust renderArea to the root window level
2664 Extent * renderArea = &rootWindow.tempExtents[1];
2666 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2667 if(child.rootWindow.nativeDecorations)
2669 offsetX -= child.rootWindow.clientStart.x;
2670 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2674 Extent childRenderArea;
2676 if(backBufferUpdate != null)
2678 childRenderArea.Copy(backBufferUpdate);
2679 childRenderArea.Offset(-offsetX, -offsetY);
2682 childRenderArea.Copy(child.dirtyArea);
2684 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2685 renderArea.Copy(dirtyExtent);
2686 renderArea.Offset(-offsetX, -offsetY);
2687 childRenderArea.Union(renderArea);
2690 // Intersect with the clip extent
2691 childRenderArea.Intersection(child.clipExtent);
2694 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2695 renderArea->Offset(offsetX, offsetY);
2696 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2697 // overDirtyExtent.Union(renderArea);
2698 renderArea->Empty();
2699 // childRenderArea.Free();
2701 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2706 for(child = children.last; child; child = child.prev)
2708 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2710 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2715 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2717 bool opaque = IsOpaque();
2718 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2720 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2721 if(rootWindow.nativeDecorations)
2723 offsetX -= rootWindow.clientStart.x;
2724 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2728 for(child = children.last; child; child = child.prev)
2730 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2732 ColorAlpha background = *(ColorAlpha *)&child.background;
2733 bool opaque = child.IsOpaque();
2734 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2738 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2739 // Adjust renderArea to the root window level
2741 renderArea.Copy(child.dirtyArea);
2742 renderArea.Offset(offsetX, offsetY);
2743 dirtyExtent.Union(renderArea);
2744 overDirtyExtent.Union(renderArea);
2750 for(child = children.last; child; child = child.prev)
2752 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2754 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2758 if(backBufferUpdate != null)
2760 renderArea.Copy(backBufferUpdate);
2761 renderArea.Offset(-offsetX, -offsetY);
2763 overRenderArea.Copy(backBufferUpdate);
2764 overRenderArea.Offset(-offsetX, -offsetY);
2770 renderArea.Copy(dirtyArea);
2772 overRenderArea.Copy(dirtyArea);
2775 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2776 dirtyExtentWindow->Copy(dirtyExtent);
2777 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2778 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2779 dirtyExtentWindow->Empty();
2781 // Intersect with the clip extent
2782 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2785 if(renderArea.count > 10)
2788 printf("\nToo many extents (%d):\n", renderArea.count);
2790 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2791 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2796 for(c = 0; c<10; c++)
2799 FASTLIST_LOOP(renderArea, extentBox)
2801 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2803 renderArea.Copy(extent);
2805 FASTLIST_LOOP(renderArea, extentBox)
2808 printf("(%d, %d) - (%d, %d)\n",
2809 extentBox.box.left, extentBox.box.top,
2810 extentBox.box.right, extentBox.box.bottom);
2814 printf("\nNow %d\n", renderArea.count);
2820 // WHY WAS THIS COMMENTED ??
2822 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2823 dirtyExtentWindow->Copy(overDirtyExtent);
2824 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2825 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2826 dirtyExtentWindow->Empty();
2828 // Intersect with the clip extent
2829 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2835 if(scrollExtent.count)
2837 // Subtract render extent from scrolling extent
2838 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
2840 if(backBufferUpdate == null)
2842 Extent * dirty = &rootWindow.tempExtents[3];
2845 // Intersect scrolling extent with clip extent
2846 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2848 // offset this scroll to be at the root window level
2849 scrollExtent.Offset(offsetX, offsetY);
2850 // Add area that was scrolled to the dirty extents of the back buffer
2851 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
2855 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
2856 for(scrollBox = (BoxItem)scrollExtent.first; scrollBox; scrollBox = (BoxItem)scrollBox.next)
2857 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
2862 scrollExtent.Empty();
2864 // Add the exposed extent to the window render area
2865 dirty->Offset(-offsetX, -offsetY);
2866 renderArea.Union(dirty, rootWindow.tempExtents[0]);
2871 // Subtract the window's box from the transparency forced extent
2872 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
2878 renderArea.Copy(this.renderArea);
2879 renderArea.Offset(offsetX, offsetY);
2880 dirtyExtent.Union(renderArea);
2886 Extent renderArea { };
2888 renderArea.Copy(overRenderArea);
2889 renderArea.Offset(offsetX, offsetY);
2890 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2895 if(backBufferUpdate != null)
2897 // Remove render area from dirty area
2898 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
2900 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
2907 // Remove the window render area from the dirty extents of the back buffer
2908 rootWindow.dirtyBack.Exclusion(renderArea);
2912 void Render(Extent updateExtent)
2916 Window rootWindow = this.rootWindow;
2917 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2918 if(rootWindow.nativeDecorations)
2920 offsetX -= rootWindow.clientStart.x;
2921 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2924 if(rootWindow.fullRender)
2933 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2934 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
2939 /*if(renderArea.count)
2940 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
2943 for(extentBox = (BoxItem)renderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2945 Box box = extentBox.box;
2948 /*printf("(%d, %d) - (%d, %d)\n",
2949 extentBox.box.left, extentBox.box.top,
2950 extentBox.box.right, extentBox.box.bottom);*/
2955 box.left += offsetX;
2957 box.right += offsetX;
2958 box.bottom += offsetY;
2960 if(updateExtent != null)
2961 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2965 for(child = children.first; child; child = child.next)
2966 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
2967 child.Render(updateExtent);
2969 if(rootWindow.fullRender)
2970 DrawOverChildren(box);
2973 // TO DO: There's an issue about draw over children...
2974 // TO DO: Don't wanna go through this if method isn't used
2975 for(extentBox = (BoxItem)overRenderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2976 //FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
2978 Box box = extentBox.box;
2980 DrawOverChildren(box);
2982 box.left += offsetX;
2984 box.right += offsetX;
2985 box.bottom += offsetY;
2987 if(updateExtent != null)
2988 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2991 for(child = children.first; child; child = child.next)
2992 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
2993 child.Render(updateExtent);
2996 overRenderArea.Empty();
2999 public void UpdateDisplay(void)
3001 if(!manageDisplay) { OnRedraw(null);return; }
3002 if(rootWindow && this != rootWindow)
3003 rootWindow.UpdateDisplay();
3006 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
3007 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
3010 dirtyExtent.Clear();
3013 clipExtent.AddBox(box);
3015 display.StartUpdate();
3017 if(!rootWindow.fullRender)
3019 ComputeClipExtents();
3020 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
3021 ComputeRenderArea(dirtyExtent, overExtent, null);
3024 clipExtent.Free(null);
3026 dirtyExtent.Free(null);
3027 overExtent.Free(null);
3029 if(display.flags.flipping)
3032 display.Update(null);
3036 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
3037 updateExtent.Clear();
3039 Render(updateExtent);
3041 updateExtent.UnionBox(this.box, tempExtents[0]);
3044 //printf("\n\nUpdate:\n------------------------------------------\n");
3047 //FASTLIST_LOOP(updateExtent, extentBox)
3048 for(extentBox = (BoxItem)updateExtent.first; extentBox; extentBox = (BoxItem)extentBox.next)
3051 /*printf("Updating (%d, %d) - (%d, %d)\n",
3052 extentBox.box.left, extentBox.box.top,
3053 extentBox.box.right, extentBox.box.bottom);*/
3056 display.Update(extentBox.box);
3059 updateExtent.Free(null);
3062 display.EndUpdate();
3070 void UpdateBackDisplay(Box box)
3076 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3078 //printf("UpdateBackDisplay going through!\n");
3079 display.StartUpdate();
3083 intersection.Copy(dirtyBack);
3084 intersection.IntersectBox(box);
3086 dirtyExtent.Clear();
3089 clipExtent.AddBox(box);
3091 if(!rootWindow.fullRender)
3093 ComputeClipExtents();
3094 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3097 clipExtent.Free(null);
3099 intersection.Free(null);
3100 dirtyExtent.Free(null);
3101 overExtent.Free(null);
3106 if(display.flags.flipping)
3107 display.Update(null);
3110 rootWindow.display.Update(box);
3113 display.EndUpdate();
3117 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3118 if(dirtyBack.count > MAX_DIRTY_BACK)
3120 BoxItem extentBox, next;
3121 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3122 for(extentBox = (BoxItem)dirtyBack.first; extentBox; extentBox = next)
3124 next = (BoxItem)extentBox.next;
3125 if(extentBox != first)
3127 if(extentBox.box.left < first.box.left)
3128 first.box.left = extentBox.box.left;
3129 if(extentBox.box.top < first.box.top)
3130 first.box.top = extentBox.box.top;
3131 if(extentBox.box.right > first.box.right)
3132 first.box.right = extentBox.box.right;
3133 if(extentBox.box.bottom > first.box.bottom)
3134 first.box.bottom = extentBox.box.bottom;
3135 dirtyBack.Delete(extentBox);
3144 // --- Window positioning ---
3145 // --- Window identification ---
3147 // Returns window at position "Position"
3148 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3150 Window child, result = null;
3152 box.left += absPosition.x;
3153 box.right += absPosition.x;
3154 box.top += absPosition.y;
3155 box.bottom += absPosition.y;
3157 if(!destroyed && visible && (acceptDisabled || !disabled))
3159 int lx = x - absPosition.x;
3160 int ly = y - absPosition.y;
3161 if(IsInside(lx, ly))
3162 // if(box.IsPointInside(Point{x, y}))
3164 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3165 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3168 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3170 if(child != statusBar && child.rootWindow == rootWindow)
3172 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3179 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3181 if(child != statusBar && child.rootWindow == rootWindow)
3183 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3195 Window FindModal(void)
3197 Window modalWindow = this, check;
3198 Window check2 = null;
3199 for(check = this; check.master; check = check.master)
3201 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3203 modalWindow = check.master.modalSlave;
3204 check = modalWindow;
3206 // TESTING THIS FOR DROPBOX...
3207 if(!rootWindow || !rootWindow.style.interim)
3209 for(check2 = check; check2.activeChild; check2 = check2.activeChild)
3211 if(check2.modalSlave && check2.modalSlave.created)
3213 modalWindow = check2.modalSlave;
3221 if(modalWindow == this)
3223 for(check = this; check.activeChild; check = check.activeChild)
3225 if(check.modalSlave)
3227 modalWindow = check.modalSlave;
3233 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3234 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3237 void StopMoving(void)
3239 if(this == guiApp.windowMoving)
3241 guiApp.windowMoving = null;
3242 UpdateDecorations();
3243 SetMouseRange(null);
3246 if(rootWindow.active)
3247 guiApp.interfaceDriver.StopMoving(rootWindow);
3250 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3251 guiApp.windowIsResizing = false;
3255 void SelectMouseCursor(void)
3260 Window cursorWindow = null;
3261 bool rx, ry, rex, rey;
3263 guiApp.desktop.GetMousePosition(&x, &y);
3264 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3266 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3267 guiApp.SetCurrentCursor(guiApp.systemCursors[moving]);
3268 else if(mouseWindow)
3270 modalWindow = mouseWindow.FindModal();
3271 x -= mouseWindow.absPosition.x;
3272 y -= mouseWindow.absPosition.y;
3273 if(guiApp.windowIsResizing)
3275 rex = guiApp.resizeEndX;
3276 rey = guiApp.resizeEndY;
3277 rx = guiApp.resizeX;
3278 ry = guiApp.resizeY;
3279 if((rex && rey) || (rx && ry))
3280 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3281 else if((rex && ry) || (rx && rey))
3282 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3283 else if((ry || rey) && (!rx && !rex))
3284 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3285 else if((rx || rex) && (!ry && !rey))
3286 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3288 else if(!modalWindow && !guiApp.windowCaptured &&
3289 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3290 &rx, &ry, &rex, &rey))
3292 if((rex && rey) || (rx && ry))
3293 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3294 else if((rex && ry) || (rx && rey))
3295 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3296 else if((ry || rey) && (!rx && !rex))
3297 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3298 else if((rx || rex) && (!ry && !rey))
3299 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3301 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3303 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}))
3304 cursorWindow = mouseWindow.parent;
3306 cursorWindow = mouseWindow;
3308 else if(!guiApp.interimWindow)
3309 cursorWindow = guiApp.windowCaptured;
3312 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient; cursorWindow = cursorWindow.parent);
3313 guiApp.SetCurrentCursor(cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3315 else if(modalWindow)
3317 guiApp.SetCurrentCursor(guiApp.systemCursors[arrow]);
3319 else if(guiApp.interimWindow)
3321 if(guiApp.interimWindow.cursor)
3322 guiApp.SetCurrentCursor(guiApp.interimWindow.cursor);
3324 guiApp.SetCurrentCursor(mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3329 // --- State based input ---
3330 bool AcquireInputEx(bool state)
3335 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3336 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3338 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3340 guiApp.acquiredWindow = state ? this : null;
3343 SetMouseRangeToClient();
3344 guiApp.interfaceDriver.SetMouseCursor((SystemCursor)-1);
3349 SelectMouseCursor();
3351 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3355 // --- Window activation ---
3356 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3359 if(!parent || !parent.style.inactive)
3361 Window parent = this.parent;
3364 if(rootWindow == this)
3365 Log(active ? "active\n" : "inactive\n");
3368 // Testing this here...
3369 if(!parent || parent == guiApp.desktop || parent.active)
3371 this.active = active;
3374 // TESTING THIS HERE
3375 UpdateDecorations();
3376 if(result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master)
3377 result = NotifyActivate(master, this, active, previous);
3380 this.active = !active;
3385 if(!parent || parent == guiApp.desktop || parent.active)
3387 this.active = active;
3389 AcquireInputEx(active);
3394 if(guiApp.caretOwner)
3398 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3399 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3400 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3401 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3403 guiApp.caretOwner.Update(extent);
3406 if(visible || !guiApp.caretOwner)
3407 guiApp.caretOwner = this;
3408 UpdateCaret(false, false);
3414 this.active = false;
3416 AcquireInputEx(active);
3418 if(!active && guiApp.caretOwner == this)
3420 UpdateCaret(false, true);
3421 guiApp.caretOwner = null;
3422 guiApp.interfaceDriver.SetCaret(0,0,0);
3423 guiApp.caretEnabled = false;
3428 if(!active && parent && parent.activeChild && parent.activeChild != this)
3429 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3435 if(!active && menuBar)
3438 menuBar.OnActivate(false, null, &goOn, true);
3439 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3444 Window aChild = activeChild;
3446 if(!aChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3458 void ConsequentialMouseMove(bool kbMoving)
3462 if(kbMoving || !guiApp.windowMoving)
3466 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3468 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3470 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3471 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3477 bool IsDescendantOf(Window ancestor)
3480 for(window = this; window && window != ancestor; window = window.parent);
3481 return window == ancestor;
3484 bool IsSlaveOf(Window master)
3487 for(window = this; window && window != master; window = window.master);
3488 return window == master;
3491 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3495 if(this && !destroyed /*&& state != Hidden*/)
3497 Window swap = externalSwap;
3505 if(activateParent &&
3506 (parent.activeChild != this ||
3507 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3508 active && _isModal &&
3509 parent != master && master)
3510 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3516 bool real = parent.activeChild != this;
3518 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3519 if(/*activateParent && */guiApp.interimWindow &&
3520 !IsDescendantOf(guiApp.interimWindow) &&
3521 !IsSlaveOf(guiApp.interimWindow))
3523 Window interimWindow = guiApp.interimWindow;
3524 while(interimWindow && interimWindow != this)
3526 Window master = interimWindow.master;
3528 guiApp.interimWindow = null;
3529 if(guiApp.caretOwner)
3530 guiApp.caretOwner.UpdateCaret(false, false);
3532 incref interimWindow;
3533 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3538 delete interimWindow;
3539 interimWindow = (master && master.style.interim) ? master : null;
3544 guiApp.interimWindow = this;
3545 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3546 guiApp.caretEnabled = false;*/
3547 UpdateCaret(false, true);
3552 bool acquireInput = false;
3554 parent.activeChild &&
3555 parent.activeChild.state == maximized &&
3556 parent != guiApp.desktop;
3558 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3563 swap = parent.activeChild;
3564 if(swap && swap.destroyed) swap = null;
3565 if(swap && swap != this)
3568 if(!swap.PropagateActive(false, this, &goOn, true))
3569 swap = parent.activeChild;
3580 if(!parent || parent.activeChild != this || style.interim)
3583 result = PropagateActive(true, swap, &goOn, true);
3584 if(!result && !goOn)
3589 acquireInput = true;
3593 if(style.hasMaximize && parent != guiApp.desktop)
3596 SetState(maximized, false, 0);
3597 else if(state != maximized)
3600 for(child = parent.children.first; child; child = child.next)
3602 if(this != child && child.state == maximized)
3603 child.SetState(normal, false, 0);
3610 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3612 Window previous = parent.activeClient;
3613 parent.activeChild = this;
3614 if(!style.nonClient /*&& style.isActiveClient*/)
3618 if(style.isActiveClient)
3619 parent.activeClient = this;
3620 // Moved UpdateActiveDocument inside hidden check
3621 // To prevent activating previous window while creating a new one
3622 // (It was messing up the privateModule in the CodeEditor)
3623 parent.UpdateActiveDocument(previous);
3629 //if(!style.isRemote)
3631 if(rootWindow != this)
3633 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3634 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3636 else if(!guiApp.fullScreenMode)
3638 Window modalRoot = FindModal();
3639 if(!modalRoot) modalRoot = this;
3640 if(!modalRoot.isForegroundWindow)
3642 modalRoot.isForegroundWindow = true;
3643 // To check : Why is parent null?
3644 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3646 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3648 modalRoot.isForegroundWindow = false;
3653 if(result && real && (!style.inactive || moveInactive) && parent)
3655 Window last = parent.children.last;
3657 if(!style.stayOnTop)
3658 for(; last && last.style.stayOnTop; last = last.prev);
3660 parent.children.Move(this, last);
3662 // Definitely don't want that: why not?
3666 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3672 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3679 parent.activeChild = null;
3680 if(!style.nonClient /*&& style.isActiveClient*/)
3682 Window previous = parent.activeClient;
3683 if(style.isActiveClient)
3684 parent.activeClient = null;
3685 parent.UpdateActiveDocument(previous);
3689 if(this == guiApp.interimWindow)
3691 guiApp.interimWindow = null;
3692 if(guiApp.caretOwner)
3693 guiApp.caretOwner.UpdateCaret(false, false);
3695 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3702 if(!active || !swap)
3703 UpdateDecorations();
3705 swap.UpdateDecorations();
3707 if(active && rootWindow != this)
3708 ConsequentialMouseMove(false);
3715 // --- Input Messages ---
3716 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3718 static bool reEntrancy = false;
3719 if(reEntrancy) return;
3723 guiApp.cursorUpdate = true;
3724 if(guiApp.windowScrolling && !consequential)
3726 guiApp.windowScrolling.SetScrollPosition(
3727 (guiApp.windowScrolling.sbh) ?
3728 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3729 (guiApp.windowScrolling.sbv) ?
3730 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3732 if(guiApp.windowMoving)
3734 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3736 Window window = guiApp.windowMoving;
3738 int w = window.size.w;
3739 int h = window.size.h;
3744 rx = mouseX - guiApp.windowMovingStart.x;
3745 ry = mouseY - guiApp.windowMovingStart.y;
3748 window.GetDecorationsSize(&ew, &eh);
3750 if(guiApp.windowIsResizing)
3752 x = window.scrolledPos.x;
3753 y = window.scrolledPos.y;
3757 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3758 rx = guiApp.windowResizingBefore.w - aw;
3759 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3760 w = guiApp.windowResizingBefore.w - rx;
3764 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3765 ry = guiApp.windowResizingBefore.h - ah;
3766 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3767 ry = Max(ry, -guiApp.windowMovingBefore.y);
3768 h = guiApp.windowResizingBefore.h - ry;
3770 if(guiApp.resizeEndX)
3772 w = guiApp.windowResizingBefore.w + rx;
3775 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3783 w = Max(w, window.minSize.w);
3784 h = Max(h, window.minSize.h);
3785 w = Min(w, window.maxSize.w);
3786 h = Min(h, window.maxSize.h);
3788 if(!window.OnResizing(&w, &h))
3790 w = window.clientSize.w;
3791 h = window.clientSize.h;
3794 w = Max(w, window.skinMinSize.w);
3795 h = Max(h, window.skinMinSize.h);
3802 SNAPDOWN(w, textCellW);
3803 SNAPDOWN(h, textCellH);
3808 aw = Max(w,window.skinMinSize.w);
3809 rx = guiApp.windowResizingBefore.w - aw;
3810 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3811 w = guiApp.windowResizingBefore.w - rx;
3815 ah = Max(h,window.skinMinSize.h);
3816 ry = guiApp.windowResizingBefore.h - ah;
3817 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3818 ry = Max(ry, -guiApp.windowMovingBefore.y);
3819 h = guiApp.windowResizingBefore.h - ry;
3824 if(!guiApp.windowIsResizing || guiApp.resizeX)
3825 x = guiApp.windowMovingBefore.x + rx;
3826 if(!guiApp.windowIsResizing || guiApp.resizeY)
3827 y = guiApp.windowMovingBefore.y + ry;
3829 if(!guiApp.windowIsResizing)
3832 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
3834 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
3835 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
3836 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
3837 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
3841 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
3842 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
3848 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
3850 if(!window.OnMoving(&x, &y, w, h))
3852 x = window.scrolledPos.x;
3853 y = window.scrolledPos.y;
3859 SNAPDOWN(x, textCellW);
3860 SNAPDOWN(y, textCellH);
3863 if(!window.style.nonClient)
3865 if(!window.style.fixed /*|| window.style.isDocument*/)
3867 if(!window.style.dontScrollHorz)
3868 x += window.parent.scroll.x;
3869 if(!window.style.dontScrollVert)
3870 y += window.parent.scroll.y;
3874 // Break the anchors for moveable/resizable windows
3875 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
3876 if(window.style.fixed)
3878 if(window.state == normal)
3880 window.normalAnchor = Anchor { left = x, top = y };
3881 window.normalSizeAnchor = SizeAnchor { { w, h } };
3882 window.anchored = false;
3886 window.stateAnchor = Anchor { left = x, top = y };
3887 window.stateSizeAnchor = SizeAnchor { { w, h } };
3889 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
3890 // TOCHECK: Investigate why the following only redraws the scrollbars
3891 //window.Position(x, y, w, h, false, true, true, true, false, true);
3893 guiApp.movingLast.x = mouseX;
3894 guiApp.movingLast.y = mouseY;
3900 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
3903 bool wasMoving = guiApp.windowMoving ? true : false;
3904 bool wasScrolling = guiApp.windowScrolling ? true : false;
3906 while(result && w != this)
3908 Window msgWindow = GetAtPosition(x,y, false, true, w);
3909 Window trueWindow = GetAtPosition(x,y, false, false, w);
3910 bool windowDragged = false;
3915 window = (w && !w.disabled) ? w : null;
3917 if(trueWindow) incref trueWindow;
3919 if(consequential) mods->isSideEffect = true;
3921 UpdateMouseMove(x, y, consequential);
3923 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
3925 if(!guiApp.windowCaptured.isEnabled)
3926 guiApp.windowCaptured.ReleaseCapture();
3928 window = guiApp.windowCaptured;
3931 if(trueWindow && activate &&
3932 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3933 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3934 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3935 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3937 if(mods->alt && !mods->ctrl && !mods->shift)
3939 Window moved = trueWindow;
3940 for(moved = trueWindow; moved; moved = moved.parent)
3941 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3946 windowDragged = true;
3948 // Cancel the ALT menu toggling...
3949 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
3954 if(window && activate &&
3955 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3956 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3957 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3958 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3960 Window modalWindow = window.FindModal();
3962 /*if(mods->alt && !mods->shift && !mods->ctrl)
3964 Window moved = window;
3965 for(moved = window; moved; moved = moved.parent)
3966 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3971 windowDragged = true;
3973 // Cancel the ALT menu toggling...
3974 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
3980 Window activateWindow = modalWindow ? modalWindow : window;
3981 if(activateWindow && !activateWindow.isRemote)
3983 bool doActivation = true;
3984 //bool needToDoActivation = false;
3985 Window check = activateWindow;
3987 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
3989 if(!check.style.inactive)
3991 //needToDoActivation = true;
3993 doActivation = false;
3998 if(!needToDoActivation)
3999 doActivation = false;
4002 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
4003 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
4005 // Let the OnLeftButtonDown do the activating instead
4006 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4014 incref activateWindow;
4015 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
4017 delete activateWindow;
4021 if(activateWindow._refCount == 1)
4023 delete activateWindow;
4027 delete activateWindow;
4029 mods->isActivate = true;
4033 if(!modalWindow && window && !window.destroyed)
4035 if(!guiApp.windowCaptured || windowDragged)
4037 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
4039 bool moving = ((window.state != maximized &&
4040 window.IsMouseMoving(
4041 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4042 || (guiApp.windowMoving && !guiApp.windowIsResizing);
4044 if(!moving && window.IsMouseResizing(
4045 x - window.absPosition.x,
4046 y - window.absPosition.y,
4047 window.size.w, window.size.h,
4048 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
4050 guiApp.windowIsResizing = true;
4051 guiApp.windowResizingBefore.w = window.size.w;
4052 guiApp.windowResizingBefore.h = window.size.h;
4054 if(guiApp.windowIsResizing || windowDragged || moving)
4057 guiApp.windowMoving = window;
4058 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4059 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4060 guiApp.windowMovingBefore.x = window.position.x;//s;
4061 guiApp.windowMovingBefore.y = window.position.y;//s;
4062 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4063 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4066 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4068 if(window.style.fixed &&
4070 window.IsMouseMoving(
4071 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4073 window.ShowSysMenu(x, y);
4077 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4079 if(window.sbv || window.sbh)
4082 guiApp.windowScrolling = window;
4083 guiApp.windowScrollingStart.x = x;
4084 guiApp.windowScrollingStart.y = y;
4085 guiApp.windowScrollingBefore.x = window.scroll.x;
4086 guiApp.windowScrollingBefore.y = window.scroll.y;
4089 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4091 if(window.style.hasMaximize &&
4092 window.IsMouseMoving(
4093 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4096 (window.state == maximized) ? normal : maximized, false, *mods);
4104 if(guiApp.windowMoving)
4106 if(guiApp.windowMoving.parent)
4108 if(guiApp.windowMoving.style.nonClient)
4109 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4111 guiApp.windowMoving.parent.SetMouseRangeToClient();
4115 window.UpdateDecorations();
4118 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4120 // Log("\n*** LEFT BUTTON UP ***\n");
4121 if(guiApp.windowMoving)
4122 guiApp.windowMoving.StopMoving();
4124 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4126 if(guiApp.windowScrolling)
4128 Window windowScrolling = guiApp.windowScrolling;
4129 guiApp.windowScrolling = null;
4130 windowScrolling.ReleaseCapture();
4134 if(!result || (window && window.destroyed)) window = null;
4136 if(window && window.FindModal())
4139 if(trueWindow && trueWindow.FindModal())
4147 msgWindow = GetAtPosition(x,y, true, false);
4149 msgWindow.SelectMouseCursor();
4152 if(guiApp.windowCaptured || trueWindow)
4154 Window prevWindow = guiApp.prevWindow;
4155 if(guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4157 guiApp.prevWindow.mouseInside = false;
4158 guiApp.prevWindow = null;
4160 // Eventually fix this not to include captured?
4161 if(!prevWindow.OnMouseLeave(*mods))
4164 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4166 Box box = trueWindow.box;
4167 box.left += trueWindow.absPosition.x;
4168 box.right += trueWindow.absPosition.x;
4169 box.top += trueWindow.absPosition.y;
4170 box.bottom += trueWindow.absPosition.y;
4172 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4174 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4175 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4177 overX = Max(Min(overX, 32767),-32768);
4178 overY = Max(Min(overY, 32767),-32768);
4180 trueWindow.mouseInside = true;
4181 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4185 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4186 guiApp.prevWindow = trueWindow;
4188 guiApp.prevWindow = null;
4190 SelectMouseCursor();
4192 if(window && !guiApp.windowMoving && !wasMoving && !wasScrolling)
4194 int clientX = x - (window.absPosition.x + window.clientStart.x);
4195 int clientY = y - (window.absPosition.y + window.clientStart.y);
4197 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4199 clientX = Max(Min(clientX, 32767),-32768);
4200 clientY = Max(Min(clientY, 32767),-32768);
4202 MouseMethod = (void *)window._vTbl[method];
4204 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4207 if(!MouseMethod(window, clientX, clientY, *mods))
4214 if(result && w && w.clickThrough && w.parent)
4219 if(!result || !w || !w.clickThrough)
4226 // --- Mouse cursor management ---
4228 bool KeyMessage(uint method, Key key, unichar character)
4233 if(guiApp.interimWindow)
4234 this = guiApp.interimWindow;
4237 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4241 if(!style.inactive || rootWindow != this)
4243 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4244 Window modalWindow = FindModal();
4245 Window interimMaster = master ? master.rootWindow : null;
4249 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4250 status = OnSysKeyDown(key, character);
4251 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4252 status = OnSysKeyHit(key, character);
4253 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4254 status = OnSysKeyUp(key, character);
4261 // Process Key Message for Internal UI Keyboard actions
4262 if(status && !destroyed && menuBar && state != minimized)
4265 if((SmartKey)key != alt)
4266 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4269 SmartKey sk = (SmartKey) key;
4270 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4272 status = menuBar.KeyMessage(method, key, character);
4277 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4278 menuBar.OnKeyHit(escape, 0);
4280 if(!menuBar.focus && guiApp.caretOwner)
4281 guiApp.caretOwner.UpdateCaret(true, false);
4284 if(!destroyed && status)
4286 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4290 case left: case up: case right: case down:
4291 if(guiApp.windowMoving == this)
4294 int w = guiApp.windowMoving.size.w;
4295 int h = guiApp.windowMoving.size.h;
4296 int x = guiApp.windowMoving.scrolledPos.x;
4297 int y = guiApp.windowMoving.scrolledPos.y;
4301 if(key == down || key == up)
4302 step = Max(step, textCellH);
4304 step = Max(step, textCellW);
4307 if(guiApp.windowIsResizing)
4311 case left: w-=step; break;
4312 case right: w+=step; break;
4313 case up: h-=step; break;
4314 case down: h+=step; break;
4321 case left: x-=step; break;
4322 case right: x+=step; break;
4323 case up: y-=step; break;
4324 case down: y+=step; break;
4328 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4329 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4331 if(!guiApp.windowIsResizing || guiApp.resizeX)
4332 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4334 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4336 if(!guiApp.windowIsResizing || guiApp.resizeY)
4337 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4339 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4341 guiApp.interfaceDriver.SetMousePosition(x, y);
4342 ConsequentialMouseMove(true);
4350 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4352 guiApp.windowMoving.StopMoving();
4353 ConsequentialMouseMove(false);
4361 ShowSysMenu(absPosition.x, absPosition.y);
4369 if(!destroyed && status && state != minimized)
4371 // Process all the way down the children
4372 if(activeChild && !activeChild.disabled)
4374 status = activeChild.KeyMessage(method, key, character);
4376 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4377 key.code != left && key.code != right && key.code != up && key.code != down)
4379 status = activeClient.KeyMessage(method, key, character);
4383 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4385 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4386 // && defaultControl != activeChild)
4388 delete previousActive;
4389 previousActive = activeChild;
4390 if(previousActive) incref previousActive;
4392 ConsequentialMouseMove(false);
4393 if((defaultControl.active ||
4394 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4395 defaultControl.KeyMessage(method, defaultKey, character);
4401 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4403 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4410 ShowSysMenu(absPosition.x, absPosition.y);
4417 if(this != guiApp.desktop)
4419 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4421 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4423 MenuMoveOrSize(key.shift, true);
4427 else if(guiApp.windowMoving)
4429 guiApp.windowMoving.StopMoving();
4430 ConsequentialMouseMove(false);
4438 if(!destroyed && status && state != minimized)
4440 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4444 case tab: case shiftTab:
4446 Window cycleParent = this;
4447 if(this == guiApp.interimWindow && !master.style.interim && !cycleParent.style.tabCycle)
4448 cycleParent = master.parent;
4450 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4452 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4454 Window child = cycleParent.activeChild;
4456 // Scroll the window to include the active control
4458 if(cycleParent.sbh && !child.style.dontScrollHorz)
4460 if(child.scrolledPos.x < 0)
4461 cycleParent.sbh.Action(Position,
4462 cycleParent.scroll.x + child.scrolledPos.x, 0);
4463 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4464 cycleParent.sbh.Action(Position,
4465 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4467 if(cycleParent.sbv && !child.style.dontScrollVert)
4469 if(child.scrolledPos.y < 0)
4470 cycleParent.sbv.Action(Position,
4471 cycleParent.scroll.y + child.scrolledPos.y, 0);
4472 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4473 cycleParent.sbv.Action(Position,
4474 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4477 cycleParent.ConsequentialMouseMove(false);
4483 case f6: case shiftF6:
4484 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4486 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4487 if(parent == guiApp.desktop)
4488 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4498 if(CycleChildren(key.shift, true, false, true))
4506 // mIRC Style Window Shortcuts
4507 case alt1: case alt2: case alt3: case alt4: case alt5:
4508 case alt6: case alt7: case alt8: case alt9: case alt0:
4513 for(document = children.first; document; document = document.next)
4515 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4517 if(document == activeChild)
4519 if(document.state == minimized)
4520 document.SetState(normal, false, key);
4523 document.SetState(minimized, false, key);
4524 CycleChildren(false, true, false);
4529 if(activeChild.state == maximized && document.style.hasMaximize)
4530 document.SetState(maximized, false, key);
4531 else if(document.state == minimized)
4532 document.SetState(normal, false, key);
4533 document.Activate();
4548 if(!destroyed && status)
4550 if(state == minimized)
4555 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4557 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4559 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4560 previousActive.ActivateEx(true, false, false, true, null, null);
4561 delete previousActive;
4567 if(!destroyed && status)
4569 status = ProcessHotKeys(method, key, character);
4571 if(!destroyed && status && !modalWindow && state != minimized)
4574 status = KeyMethod(this, key, character);
4575 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4576 status = OnKeyHit(key, character);
4577 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4579 bool result = false;
4582 case ctrlUp: case ctrlDown:
4583 if(sbv && !guiApp.windowScrolling)
4584 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4586 case wheelUp: case wheelDown:
4587 if(sbv && !guiApp.windowScrolling)
4589 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4590 // Do we want to do a consequential move regardless of result in this case?
4591 ConsequentialMouseMove(false);
4594 case ctrlPageUp: case ctrlPageDown:
4595 if(sbh && !guiApp.windowScrolling)
4596 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4601 ConsequentialMouseMove(false);
4606 if(status && !destroyed && menuBar && state != minimized)
4607 status = menuBar.KeyMessage(method, key, character);
4609 if(style.interim && /*destroyed && */status && interimMaster)
4611 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4612 status = interimMaster.KeyMessage(method, key, character);
4619 bool ProcessHotKeys(uint method, Key key, unichar character)
4624 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4625 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4626 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4628 Window hotKeyWindow = hotKey.window;
4629 Window parent = hotKeyWindow.parent;
4630 Window prevActiveWindow = activeChild;
4632 // Don't process non-visible buttons, but make an exception for the Alt-F4 with Native Decorations turned on
4633 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1] )))
4636 if(prevActiveWindow) incref prevActiveWindow;
4637 incref hotKeyWindow;
4638 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient)
4639 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4642 delete hotKeyWindow;
4643 delete prevActiveWindow;
4647 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4648 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4649 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4651 // ********* WORKING ON THIS ***********
4652 if(prevActiveWindow && !guiApp.interimWindow)
4653 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4656 else if(hotKeyWindow.style.inactive)
4657 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4659 delete prevActiveWindow;
4660 delete hotKeyWindow;
4661 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4662 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4666 if(status && tabCycle)
4669 for(child = children.first; child; child = child.next)
4671 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4682 // --- Windows and graphics initialization / termination ---
4683 bool SetupRoot(void)
4687 // Setup relationship with outside world (bb root || !bb)
4688 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4689 (_displayDriver && dispDriver != parent.dispDriver))
4693 tempExtents = new0 Extent[4];
4698 /*if(guiApp.fullScreenMode)
4699 rootWindow = guiApp.desktop;
4701 //rootWindow = parent.created ? parent.rootWindow : null;
4702 rootWindow = parent.rootWindow;
4705 against = &parent.box;
4707 against = &parent.clientArea;
4710 for(child = children.first; child; child = child.next)
4713 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
4716 bool Setup(bool positionChildren)
4718 bool result = false;
4721 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && dispDriver != parent.dispDriver))))
4723 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
4724 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
4726 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
4728 // This was here, is it really needed?
4729 //guiApp.interfaceDriver.ActivateRootWindow(this);
4733 displaySystem = DisplaySystem {};
4734 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
4736 delete displaySystem;
4741 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData };
4742 if(display.Create(displaySystem, windowHandle))
4749 guiApp.interfaceDriver.SetIcon(this, icon);
4751 else if(this != guiApp.desktop)
4753 display = rootWindow ? rootWindow.display : null;
4759 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
4760 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
4762 for(child = children.first; child; child = child.next)
4764 if(child.created && !child.Setup(false))
4770 bool SetupDisplay(void)
4772 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
4773 if(is3D) return Window3D_SetupDisplay(this); else
4780 class_data void ** pureVTbl;
4782 bool LoadGraphics(bool creation, bool resetAnchors)
4784 bool result = false;
4785 bool success = false;
4787 WindowState stateBackup = state;
4790 if(!rootWindow.created)
4794 if(((subclass(Window))_class).pureVTbl)
4796 if(_vTbl == _class._vTbl)
4798 _vTbl = ((subclass(Window))_class).pureVTbl;
4803 for(m = 0; m < _class.vTblSize; m++)
4805 if(_vTbl[m] == _class._vTbl[m])
4806 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
4810 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
4812 if(_vTbl == ((subclass(Window))_class).pureVTbl)
4814 _vTbl = _class._vTbl;
4819 for(m = 0; m < _class.vTblSize; m++)
4821 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
4822 _vTbl[m] = _class._vTbl[m];
4827 if(guiApp.fullScreenMode || this != guiApp.desktop)
4829 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
4835 display.Lock(false);
4836 if(rootWindow == this)
4838 // Set Color Palette
4839 display.SetPalette(palette, true);
4843 if(guiApp.fullScreenMode && this == guiApp.desktop)
4848 for(c=0; c<SystemCursor::enumSize; c++)
4849 if(!guiApp.systemCursors[c].bitmap)
4851 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
4852 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
4853 if(guiApp.systemCursors[c].bitmapName)
4855 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
4856 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
4857 if(guiApp.systemCursors[c].bitmap)
4858 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
4863 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
4865 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
4866 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
4868 cursor.bitmap.paletteShades = cursor.paletteShades;
4872 guiApp.cursorUpdate = true;
4875 ConsequentialMouseMove(false);
4881 // Load Window Graphic Resources
4884 if(usedFont == setFont || usedFont == window.systemFont)
4885 RemoveResource(usedFont);
4888 RemoveResource(setFont); // TESTING setFont instead of usedFont);
4891 RemoveResource(systemFont);
4894 RemoveResource(captionFont);
4896 for(ptr = resources.first; ptr; ptr = ptr.next)
4898 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
4901 AddResource(setFont);
4903 AddResource(systemFont);
4905 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
4912 //if(master && master.font)
4913 if(parent && parent.font)
4917 faceName = parent.font.faceName,
4918 size = parent.font.size,
4919 bold = parent.font.bold,
4920 italic = parent.font.italic,
4921 underline = parent.font.underline
4923 //font = parent.font;
4924 watch(parent) { font { } };
4927 font = guiApp.currentSkin.SystemFont();
4934 captionFont = guiApp.currentSkin.CaptionFont();
4935 AddResource(captionFont);
4937 if(OnLoadGraphics())
4943 //SetScrollLineStep(sbStep.x, sbStep.y);
4945 if(this != guiApp.desktop)
4949 normalAnchor = anchor;
4950 normalSizeAnchor = sizeAnchor;
4953 // Break the anchors for moveable/resizable windows
4955 if(style.fixed && style.isDocument)
4957 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
4969 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
4970 stateSizeAnchor = SizeAnchor {};
4975 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
4980 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
4981 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
4984 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
4988 stateAnchor = normalAnchor;
4989 stateSizeAnchor = normalSizeAnchor;
4992 position = Point { };
4993 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5004 if(Position(x, y, w, h, true, false, true, true, true, true))
5006 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
5009 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
5026 success = result = true;
5029 if(!creation && result)
5031 // Load menu bar first because sys buttons are on it...
5034 if(!menuBar.LoadGraphics(false, resetAnchors))
5040 for(child = children.first; child; child = child.next)
5042 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
5049 CreateSystemChildren();
5053 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5056 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5061 //guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, caption);
5062 guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, class.name);
5065 // Do this here to avoid problems on Windows
5066 if(stateBackup == maximized)
5067 property::state = maximized;
5071 void UnloadGraphics(bool destroyWindows)
5075 // Free children's graphics
5076 for(child = children.first; child; child = child.next)
5077 child.UnloadGraphics(destroyWindows);
5080 display.Lock(false);
5083 if(guiApp.fullScreenMode && this == guiApp.desktop)
5088 for(c=0; c<SystemCursor::enumSize; c++)
5089 if(guiApp.systemCursors[c].bitmap)
5090 delete guiApp.systemCursors[c].bitmap;
5092 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5093 delete cursor.bitmap;
5095 guiApp.cursorBackground.Free();
5098 if(display && display.displaySystem)
5102 for(ptr = resources.first; ptr; ptr = ptr.next)
5106 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5111 // Free window graphics
5114 // Free skin graphics
5115 if(rootWindow == this)
5117 DisplaySystem displaySystem = display.displaySystem;
5120 display.driverData = null;
5121 display.displaySystem = null;
5125 if(displaySystem && !displaySystem.numDisplays && !is3D)
5126 delete displaySystem;
5135 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5136 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5138 if(this == guiApp.desktop || parent == guiApp.desktop)
5140 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5141 guiApp.interfaceDriver.DestroyRootWindow(this);
5145 // --- Window Hiding ---
5147 void SetVisibility(bool state)
5149 bool visible = (style.hidden || !created) ? false : state;
5150 if(visible != this.visible)
5154 this.visible = visible;
5155 for(child = children.first; child; child = child.next)
5156 child.SetVisibility(visible);
5158 ConsequentialMouseMove(false);
5159 if(parent && !nonClient) parent.OnChildVisibilityToggled(this, visible);
5163 // --- Windows and graphics initialization / termination ---
5165 bool DisplayModeChanged(void)
5167 bool result = false;
5168 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5170 guiApp.modeSwitching = true;
5171 UnloadGraphics(false);
5173 if(LoadGraphics(false, false))
5175 guiApp.modeSwitching = false;
5180 // --- Window updates system ---
5182 void UpdateDirty(Box updateBox)
5184 if(!manageDisplay) { OnRedraw(null);return; }
5187 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5190 if(display.flags.flipping)
5193 rootWindow.UpdateDisplay();
5196 UpdateBackDisplay(updateBox);
5198 if(guiApp.fullScreenMode)
5200 guiApp.cursorUpdate = true;
5201 guiApp.PreserveAndDrawCursor();
5203 if(guiApp.fullScreenMode)
5204 guiApp.RestoreCursorBackground();
5210 // This function is strictly called as a result of system window activation
5211 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5214 Window interimMaster = null;
5215 Window interimWindow = guiApp.interimWindow;
5216 if(interimWindow && interimWindow.master)
5217 interimMaster = interimWindow.master.rootWindow;
5219 if(active && state == minimized) // && (!window.nativeDecorations || window.rootWindow != window)
5220 // SetState(normal, false, 0);
5221 SetState(lastState, false, 0);
5223 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5227 /* WTH is this doing here?
5228 while(swap && swap.activeChild)
5230 swap = swap.activeChild;
5233 // TESTING THIS BEFORE...
5234 if(interimWindow && this == interimMaster)
5238 // Window interimSwap = this;
5239 Window menuBar = this.menuBar;
5240 if(menuBar && interimWindow.master == menuBar)
5243 while(interimSwap && interimSwap.activeChild)
5244 interimSwap = interimSwap.activeChild;
5246 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5247 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5249 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5250 //result = ActivateEx(true, true, false, activateRoot, window, null);
5255 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5256 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5258 if(interimWindow == this && interimMaster && !active)
5260 while(interimMaster && interimMaster.interim && interimMaster.master)
5262 // printf("Going up one master %s\n", interimMaster._class.name);
5263 interimMaster = interimMaster.master.rootWindow;
5265 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5266 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5272 bool DestroyEx(int returnCode)
5275 Timer timer, nextTimer;
5277 OldLink prevOrder = null;
5278 Window client = null;
5280 if(parent) stopwatching(parent, font);
5282 // if(window.modalSlave) return false;
5283 if(destroyed || !created)
5290 OldLink slave = master.slaves.FindLink(this);
5291 master.slaves.Delete(slave);
5294 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5300 this.returnCode = (DialogResult)returnCode;
5302 AcquireInput(false);
5307 master.hotKeys.Delete(hotKey);
5311 if(guiApp.prevWindow == this)
5313 guiApp.prevWindow = null;
5316 if(guiApp.caretOwner == this)
5318 guiApp.interfaceDriver.SetCaret(0,0,0);
5319 UpdateCaret(false, true);
5320 guiApp.caretEnabled = false;
5325 parent.childrenCycle.Remove(cycle);
5329 OldLink tmpPrev = order.prev;
5330 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5331 prevOrder = tmpPrev;
5334 client = tmpPrev ? tmpPrev.data : null;
5335 if(client == this) { client = null; break; }
5336 if(client && (client.style.hidden || client.destroyed || !client.created))
5337 tmpPrev = client.order.prev;
5341 prevOrder = tmpPrev;
5346 // If this window can be an active client, make sure the next window we activate can also be one
5347 if(!style.nonClient && style.isActiveClient)
5349 tmpPrev = prevOrder;
5352 client = tmpPrev ? tmpPrev.data : null;
5353 if(client == this) { client = null; break; }
5354 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5355 tmpPrev = client.order.prev;
5359 prevOrder = tmpPrev;
5363 if(client && client.style.hidden) client = null;
5365 // parent.childrenOrder.Remove(order);
5368 if(parent && style.isActiveClient && visible)
5370 if(state == minimized) parent.numIcons--;
5371 parent.numPositions--;
5374 // TESTING THIS HERE!
5378 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5379 // to create a window inside a rootwindow that's being destroyed)
5380 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5382 if(master && !master.destroyed /*&&
5383 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5385 if(master.defaultControl == this)
5386 master.defaultControl = null;
5388 if(parent && !parent.destroyed /*&&
5389 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5391 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5393 if(order && prevOrder && prevOrder.data != this && active)
5395 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5397 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5398 if(parent.activeClient == this)
5400 parent.activeClient = null;
5401 parent.UpdateActiveDocument(null);
5406 if(guiApp.interimWindow == this)
5409 PropagateActive(false, null, &goOn, true);
5413 //if(window.parent.activeChild == window)
5414 parent.activeChild = null;
5415 if(!style.nonClient /*&& style.isActiveClient*/)
5417 Window previous = parent.activeClient;
5418 if(style.isActiveClient)
5419 parent.activeClient = null;
5420 parent.UpdateActiveDocument(previous);
5425 else if(parent.activeClient == this)
5427 parent.activeClient = client;
5428 parent.UpdateActiveDocument(this);
5432 if(guiApp.interimWindow == this)
5434 guiApp.interimWindow = null;
5435 if(guiApp.caretOwner)
5437 Window desktop = guiApp.desktop;
5438 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5439 guiApp.caretOwner.UpdateCaret(false, false);
5444 if(_isModal && master && master.modalSlave == this)
5445 master.modalSlave = null;
5449 if(!guiApp.caretOwner && parent.caretSize)
5451 guiApp.caretOwner = parent;
5452 parent.UpdateCaret(false, false);
5453 parent.Update(null);
5456 // Why was this commented out?
5457 GetRidOfVirtualArea();
5463 dirtyArea.Free(null);
5464 dirtyBack.Free(null);
5465 scrollExtent.Free(null);
5467 /* ATTEMPTING TO MOVE THAT ABOVE
5476 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5477 for(;(child = window.children.first);)
5479 for(; child && (child.destroyed || !child.created); child = child.next);
5488 UnloadGraphics(true);
5491 delete previousActive;
5494 // statusBar = null;
5497 if(master && !master.destroyed)
5499 //master.NotifyDestroyed(this, this.returnCode);
5500 NotifyDestroyed(master, this, this.returnCode);
5503 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5505 nextTimer = timer.next;
5506 if(timer.window == this)
5508 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5509 // timer.window = null;
5515 if(this == guiApp.windowMoving)
5518 if(guiApp.windowCaptured == this)
5520 //guiApp.windowCaptured = null;
5522 if(rootWindow != this && rootWindow)
5523 rootWindow.ConsequentialMouseMove(false);
5531 //for(child = children.first; next = child ? child.next : null, child; child = next)
5532 for(;(child = children.first); )
5534 for(; child && (child.destroyed || !child.created); child = child.next);
5544 /* // MOVED THIS UP...
5547 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5548 for(;(child = window.children.first); )
5550 for(; child && (child.destroyed || !child.created); child = child.next);
5559 while((slave = slaves.first))
5561 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5563 ((Window)slave.data).DestroyEx(0);
5568 if(guiApp.caretOwner == this)
5569 guiApp.caretOwner = null;
5571 sysButtons[0] = null;
5572 sysButtons[1] = null;
5573 sysButtons[2] = null;
5576 if(rootWindow != this)
5578 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5581 box.left -= parent.clientStart.x;
5582 box.top -= parent.clientStart.y;
5583 box.right -= parent.clientStart.x;
5584 box.bottom -= parent.clientStart.y;
5586 if(parent) parent.Update(box);
5591 OldLink slave = master.slaves.FindVoid(this);
5592 master.slaves.Delete(slave);
5598 parent.children.Remove(this);
5603 //autoCreate = false;
5606 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5607 if(((subclass(Window))_class).pureVTbl)
5609 if(_vTbl == _class._vTbl)
5611 _vTbl = ((subclass(Window))_class).pureVTbl;
5616 for(m = 0; m < _class.vTblSize; m++)
5618 if(_vTbl[m] == _class._vTbl[m])
5619 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5628 void SetStateEx(WindowState newState, bool activate)
5631 WindowState prevState = state;
5635 if(prevState != newState)
5636 lastState = prevState;
5638 if(rootWindow != this || !nativeDecorations)
5640 if(style.isActiveClient && !style.hidden && prevState == minimized)
5643 // This block used to be at the end of the function... moved it for flicker problem in X
5644 // ------------------------------------------------------
5648 stateAnchor = normalAnchor;
5649 stateSizeAnchor = normalSizeAnchor;
5652 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5653 stateSizeAnchor = SizeAnchor {};
5657 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5660 byte * idBuffer = new0 byte[size];
5662 for(child = parent.children.first; child; child = child.next)
5664 if(child != this && child.state == minimized)
5666 if(child.iconID > size - 2)
5668 idBuffer = renew0 idBuffer byte[size*2];
5669 memset(idBuffer + size, 0, size);
5672 idBuffer[child.iconID] = (byte)bool::true;
5675 for(c = 0; c<size; c++)
5680 if(style.isActiveClient && !style.hidden)
5683 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5684 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5688 // TOCHECK: Why was this here?
5689 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5690 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5691 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5693 Position(x, y, w, h, true, true, true, true, false, true);
5695 if(!style.inactive && !style.interim && this == parent.activeClient)
5696 parent.UpdateActiveDocument(null);
5699 CreateSystemChildren();
5700 // ------------------------------------------------------
5703 int GetPositionID(Window forChild)
5707 byte * idBuffer = new0 byte[size];
5710 for(child = children.first; child; child = child.next)
5712 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
5714 if(child.positionID > size - 2)
5716 idBuffer = renew0 idBuffer byte[size*2];
5717 memset(idBuffer + size, 0, size);
5720 idBuffer[child.positionID] = (byte)bool::true;
5723 for(c = 0; c<size; c++)
5730 // --- Window related graphics ---
5732 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
5734 palette = newPalette;
5735 if(rootWindow.display)
5736 rootWindow.display.SetPalette(palette, colorMatch);
5739 public bool AcquireInput(bool acquired)
5742 if(acquiredInput != acquired)
5744 if(active || (!visible && creationActivation == activate))
5745 result = AcquireInputEx(acquired);
5750 acquiredInput = acquired ? result : !result;
5755 void ListChildren(ListBox listBox)
5759 for(child = children.first; child; child = child.next)
5761 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
5763 DataRow row = listBox.AddRow();
5764 row.tag = (int)child;
5765 child.FigureCaption(caption);
5766 row.SetData(null, caption);
5771 void UpdateVisual(Box extent)
5773 if(guiApp.driver != null)
5775 if(guiApp.fullScreenMode && guiApp.desktop.display)
5777 guiApp.desktop.mutex.Wait();
5778 guiApp.desktop.display.Lock(true);
5781 if(guiApp.desktop.active)
5783 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
5785 if(guiApp.desktop.display.flags.flipping)
5786 guiApp.desktop.Update(null);
5787 guiApp.desktop.UpdateDisplay();
5788 guiApp.cursorUpdate = true;
5790 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
5792 guiApp.PreserveAndDrawCursor();
5793 // guiApp.desktop.display.ShowScreen();
5794 guiApp.cursorUpdate = false;
5795 guiApp.desktop.dirty = false;
5796 guiApp.RestoreCursorBackground();
5800 guiApp.desktop.display.Unlock();
5801 guiApp.desktop.mutex.Release();
5805 Window rootWindow = this.rootWindow;
5806 rootWindow.mutex.Wait();
5811 guiApp.SignalEvent();
5814 guiApp.waitMutex.Wait();
5815 guiApp.interfaceDriver.Lock(rootWindow);
5816 if(!rootWindow.style.hidden && rootWindow.dirty)
5818 if(rootWindow.display)
5820 rootWindow.UpdateDisplay();
5821 //rootWindow.display.ShowScreen(null);
5823 rootWindow.dirty = false;
5825 guiApp.interfaceDriver.Unlock(rootWindow);
5826 guiApp.waitMutex.Release();
5829 rootWindow.mutex.Release();
5834 void UnlockDisplay(void)
5836 guiApp.interfaceDriver.Unlock(rootWindow);
5839 void LockDisplay(void)
5841 guiApp.interfaceDriver.Lock(rootWindow);
5844 Surface GetSurface(Box box)
5846 return Redraw((box == null) ? this.box : box);
5849 void SetMousePosition(int x, int y)
5851 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
5855 void IntegrationActivate(bool active)
5857 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
5859 isForegroundWindow = true;
5860 ActivateEx(active, active, false, false, null, null);
5861 isForegroundWindow = false;
5866 Window QueryCapture(void)
5868 return guiApp.windowCaptured;
5871 int GetDocumentID(void)
5875 byte * idBuffer = new0 byte[size];
5878 for(child = children.first; child; child = child.next)
5880 // TO CHECK: Do we want a documentID when we already have a file name?
5881 if(child.style.isDocument && !child.fileName)
5883 if(child.documentID-1 > size - 2)
5885 idBuffer = renew0 idBuffer byte[size*2];
5886 memset(idBuffer + size, 0, size);
5889 idBuffer[child.documentID-1] = 1;
5892 for(c = 0; c<size; c++)
5900 void SetInitSize(Size size)
5903 sizeAnchor.size = size;
5904 normalSizeAnchor = sizeAnchor;
5906 // Break the anchors for moveable/resizable windows
5907 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
5909 stateAnchor = normalAnchor;
5910 stateSizeAnchor = normalSizeAnchor;
5912 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5913 Position(x,y, w, h, true, true, true, true, false, true);
5917 void MenuMoveOrSize(bool resize, bool setCursorPosition)
5919 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
5921 guiApp.windowIsResizing = resize;
5922 guiApp.windowMoving = this;
5923 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
5924 if(guiApp.windowIsResizing)
5926 guiApp.windowMovingStart.x += size.w - 1;
5927 guiApp.windowMovingStart.y += size.h - 1;
5929 guiApp.windowMovingBefore = scrolledPos;
5930 guiApp.windowResizingBefore = size;
5931 guiApp.windowMoving.UpdateDecorations();
5932 if(guiApp.windowIsResizing)
5933 guiApp.resizeEndX = guiApp.resizeEndY = true;
5935 if(setCursorPosition)
5936 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
5940 guiApp.interfaceDriver.GetMousePosition(&x, &y);
5941 guiApp.windowMovingStart.x += x - absPosition.x;
5942 guiApp.windowMovingStart.y += y - absPosition.y;
5945 if(guiApp.windowMoving)
5947 if(guiApp.windowMoving.style.nonClient)
5948 guiApp.windowMoving.parent.SetMouseRangeToWindow();
5950 guiApp.windowMoving.parent.SetMouseRangeToClient();
5955 if(this == rootWindow)
5956 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
5964 bool result = false;
5968 else if(guiApp && guiApp.driver != null)
5970 void * systemParent = null;
5971 OldLink slaveHolder;
5973 bool visible = !style.hidden;
5977 systemParent = parent;
5978 parent = guiApp.desktop;
5980 last = parent ? parent.children.last : null;
5982 if((parent && parent != guiApp.desktop && !parent.created) ||
5983 (master && master != guiApp.desktop && !master.created))
5987 property::parent = guiApp.desktop;
5988 if(!master) master = parent;
5990 if(_isModal && master.modalSlave)
5991 property::master = master.modalSlave;
5995 parent.children.Remove(this);
5998 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
5999 if(slaveHolder.data == this)
6001 master.slaves.Delete(slaveHolder);
6006 if(parent == guiApp.desktop && !mutex)
6009 if(style.isDocument)
6012 parent.numDocuments--;
6013 documentID = parent.GetDocumentID();
6016 if(!style.stayOnTop)
6017 for(; last && last.style.stayOnTop; last = last.prev);
6019 parent.children.Insert((last == this) ? null : last, this);
6020 //parent.children.Add(this);
6023 dispDriver = parent.dispDriver;
6026 master.modalSlave = this;
6028 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
6033 master.slaves.Add(slaveHolder = OldLink { data = this });
6038 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
6040 if(style.isDefault && !master.defaultControl)
6041 master.defaultControl = this;
6043 stateAnchor = normalAnchor = anchor;
6044 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
6046 // TOCHECK: Why is this here?
6047 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
6048 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
6050 this.visible = false;
6051 style.hidden = true;
6054 // autoCreate = true;
6062 if(parent == guiApp.desktop)
6063 Log("LoadGraphics %s\n", caption);
6065 if(LoadGraphics(true, false))
6073 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6080 if(style.hasMenuBar /*&& menu*/)
6086 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6087 interim = false, inactive = true, nonClient = true, size.h = 24
6095 // Create the system buttons
6096 CreateSystemChildren();
6098 UpdateActiveDocument(null);
6100 if(style.isDocument)
6104 MenuItem item = menu.FindItem(MenuFileSave, 0);
6105 if(item) item.disabled = !modifiedDocument && fileName;
6110 if(parent == guiApp.desktop)
6111 Log("Preemptive SetState %s\n", caption);
6114 // Preemptive Set State to ensure proper anchoring
6115 SetStateEx(state, false);
6117 style.hidden = true;
6123 for(child = children.first; child; child = next)
6126 if(!child.created && (child.autoCreate || child.wasCreated))
6133 for(link = slaves.first; link; link = next)
6135 Window slave = link.data;
6137 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6146 if(parent == guiApp.desktop)
6147 Log("Real SetState %s\n", caption);
6150 if(isActiveClient && visible)
6152 parent.numPositions--;
6153 if(state == minimized) parent.numIcons--;
6156 // Real set state & activate for proper display & activation
6157 property::visible = visible;
6158 // SetState(state & 0x00000003, true, 0);
6163 /*if(rootWindow == this)
6164 guiApp.interfaceDriver.ActivateRootWindow(this);
6166 if(creationActivation == activate)
6167 ActivateEx(true, false, true, true, null, null);
6168 else if(creationActivation == flash)
6173 rootWindow.ConsequentialMouseMove(false);
6184 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6190 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6192 //style.hidden = true; // !visible;
6193 style.hidden = !visible;
6194 if(master.modalSlave == this)
6195 master.modalSlave = null;
6202 void WriteCaption(Surface surface, int x, int y)
6205 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6208 void Update(Box region)
6214 rootWindow = this.rootWindow;
6216 // rootWindow.mutex.Wait();
6217 if(!destroyed && visible && display)
6222 // Testing this to avoid repetitve full update to take time...
6223 if(dirtyArea.count == 1)
6225 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6226 if(item.box.left <= box.left &&
6227 item.box.top <= box.top &&
6228 item.box.right >= box.right &&
6229 item.box.bottom >= box.bottom)
6231 rootWindow.dirty = true;
6236 if(display.flags.flipping && !rootWindow.dirty)
6238 if(this == rootWindow)
6242 rootWindow.Update(null);
6247 rootWindow.dirty = true;
6252 realBox.left += clientStart.x;
6253 realBox.top += clientStart.y;
6254 realBox.right += clientStart.x;
6255 realBox.bottom += clientStart.y;
6261 if(realBox.right >= realBox.left &&
6262 realBox.bottom >= realBox.top)
6264 // if(!rootWindow.fullRender)
6265 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6267 for(child = children.first; child; child = child.next)
6272 box.left -= child.absPosition.x - absPosition.x;
6273 box.top -= child.absPosition.y - absPosition.y;
6274 box.right -= child.absPosition.x - absPosition.x;
6275 box.bottom -= child.absPosition.y - absPosition.y;
6276 if(box.right >= child.box.left && box.left <= child.box.right &&
6277 box.bottom >= child.box.top && box.top <= child.box.bottom)
6279 box.left -= child.clientStart.x;
6280 box.top -= child.clientStart.y;
6281 box.right -= child.clientStart.x;
6282 box.bottom -= child.clientStart.y;
6288 realBox.left += absPosition.x - rootWindow.absPosition.x;
6289 realBox.top += absPosition.y - rootWindow.absPosition.y;
6290 realBox.right += absPosition.x - rootWindow.absPosition.x;
6291 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6292 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6295 else if(this == guiApp.desktop)
6298 for(window = children.first; window; window = window.next)
6304 Box childBox = region;
6306 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6307 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6308 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6309 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6311 window.Update(childBox);
6314 window.Update(null);
6319 // rootWindow.mutex.Release();
6326 if(guiApp.windowCaptured != this)
6328 if(guiApp.windowCaptured)
6332 //Logf("Captured %s (%s)\n", caption, class.name);
6333 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6334 guiApp.windowCaptured = this;
6340 bool Destroy(int code)
6345 if(!destroyed && !CloseConfirmation(false)) return false;
6349 // TOCHECK: Should autoCreate be set to false here?
6360 void Move(int x, int y, int w, int h)
6362 normalAnchor = Anchor { left = x, top = y };
6363 normalSizeAnchor = SizeAnchor { size = { w, h } };
6365 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6367 if(destroyed) return;
6369 stateAnchor = normalAnchor;
6370 stateSizeAnchor = normalSizeAnchor;
6372 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6373 Position(x,y, w, h, true, true, true, true, false, true);
6377 DialogResult Modal(void)
6383 // FIXES MEMORY LEAK IF Create() FAILED
6389 void SetScrollArea(int width, int height, bool snapToStep)
6391 bool resize = false;
6394 int stepX = sbStep.x, stepY = sbStep.y;
6395 // Needed to make snapped down position match the skin's check of client area
6396 // against realvirtual
6399 SNAPDOWN(stepX, textCellW);
6400 SNAPDOWN(stepY, textCellH);
6401 stepX = Max(stepX, textCellW);
6402 stepY = Max(stepY, textCellH);
6404 if(scrollFlags.snapX)
6405 SNAPUP(width, stepX);
6406 if(scrollFlags.snapY)
6407 SNAPUP(height, stepY);
6410 reqScrollArea.w = width;
6411 reqScrollArea.h = height;
6412 noAutoScrollArea = (width > 0 || height > 0);
6414 UpdateScrollBars(true, true);
6417 void SetScrollPosition(int x, int y)
6420 sbh.Action(setPosition, x, 0);
6424 int seen = clientSize.w, total = reqScrollArea.w;
6426 if(scrollFlags.snapX)
6427 SNAPDOWN(seen, sbStep.x);
6429 if(!total) total = seen;
6430 range = total - seen + 1;
6431 range = Max(range, 1);
6433 if(x >= range) x = range - 1;
6435 if(scrollFlags.snapX)
6436 SNAPUP(x, sbStep.x);
6439 OnHScroll(setPosition, x, 0);
6443 SNAPDOWN(x, textCellW);
6449 sbv.Action(setPosition, y, 0);
6453 int seen = clientSize.h, total = reqScrollArea.h;
6456 if(scrollFlags.snapY)
6457 SNAPDOWN(seen, sbStep.y);
6459 if(!total) total = seen;
6460 range = total - seen + 1;
6461 range = Max(range, 1);
6463 if(y >= range) y = range - 1;
6465 if(scrollFlags.snapY)
6466 SNAPUP(y, sbStep.y);
6469 OnVScroll(setPosition, y, 0);
6472 SNAPDOWN(y, textCellH);
6477 UpdateCaret(false, false);
6480 void SetScrollLineStep(int stepX, int stepY)
6486 SNAPDOWN(stepX, textCellW);
6487 SNAPDOWN(stepY, textCellH);
6488 stepX = Max(stepX, textCellW);
6489 stepY = Max(stepY, textCellH);
6492 sbh.lineStep = stepX;
6494 sbv.lineStep = stepY;
6497 void SetState(WindowState newState, bool activate, Modifiers mods)
6501 if(state == newState || OnStateChange(newState, mods))
6503 WindowState prevState = state;
6507 // This used to be at the end of the brackets... moved for X, testing...
6508 // This has the effect of activating the window through the system...
6509 if(rootWindow == this)
6510 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6512 SetStateEx(newState, activate);
6514 if(rootWindow == this && !rootWindow.nativeDecorations)
6516 int x = position.x, y = position.y;
6519 x -= guiApp.desktop.absPosition.x;
6520 y -= guiApp.desktop.absPosition.y;
6522 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6526 //state = prevState;
6528 if(state != maximized && style.hasMaximize)
6531 for(child = parent.children.first; child; child = child.next)
6533 if(child != this && child.state == maximized)
6534 child.SetStateEx(normal, false);
6538 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6539 parent.UpdateScrollBars(true, true);
6542 // Do we really need this stuff here?
6543 // Shouldn't the Activate stuff take care of it?
6544 if(parent.rootWindow == parent && style)
6547 parent.FigureCaption(caption);
6548 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6549 parent.UpdateDecorations();
6553 rootWindow.ConsequentialMouseMove(false);
6560 BitmapResource GetIcon(SkinBitmap iconID)
6562 return guiApp.currentSkin.GetBitmap(iconID);
6565 void SetMouseRange(Box range)
6567 if(range || guiApp.fullScreenMode)
6572 clip.left = range.left + absPosition.x + clientStart.x;
6573 clip.top = range.top + absPosition.y + clientStart.y;
6574 clip.right = range.right + absPosition.x + clientStart.x;
6575 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6579 clip.left = guiApp.desktop.box.left;
6580 clip.top = guiApp.desktop.box.top;
6581 clip.right = guiApp.desktop.box.right;
6582 clip.bottom = guiApp.desktop.box.bottom;
6584 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6587 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6590 void SetMouseRangeToClient(void)
6592 if(guiApp.fullScreenMode || this != guiApp.desktop)
6594 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6595 box.Clip(clientArea);
6599 SetMouseRange(null);
6602 void SetMouseRangeToWindow(void)
6604 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6605 if(this == guiApp.desktop)
6606 SetMouseRangeToClient();
6611 // x, y: Desktop Coordinates
6612 void ShowSysMenu(int x, int y)
6615 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6618 menu, $"Restore", r, NotifySelect = MenuWindowRestore,
6619 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6623 menu, $"Move", m, NotifySelect = MenuWindowMove,
6624 disabled = !style.fixed || state == maximized
6628 menu, $"Size", s, NotifySelect = MenuWindowSize,
6629 disabled = !style.sizable || state != normal
6633 menu, $"Minimize", n, NotifySelect = MenuWindowMinimize,
6634 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6638 menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6639 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6643 menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6644 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6646 MenuDivider { menu };
6649 menu, $"Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6650 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6652 windowMenu.Create();
6657 ActivateEx(true, true, true, true, null, null);
6660 void MakeActive(void)
6662 ActivateEx(true, false, true, false, null, null);
6665 void SoftActivate(void)
6667 if(guiApp.desktop.active)
6673 void Deactivate(void)
6675 ActivateEx(false, true, true, true, null, null);
6680 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
6683 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
6685 bool result = false;
6686 if(activeChild && activeChild.cycle)
6688 Window modalWindow, child = activeChild;
6689 if(!clientOnly /*&& parent.tabCycle*/)
6691 Window next = child;
6694 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
6698 if(parent && parent.CycleChildren(backward, false, true, true))
6706 next = next.cycle.prev.data;
6708 next = next.cycle.next.data;
6709 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
6714 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
6715 parent.tabCycle && parent.CycleChildren(backward, false, false))
6719 if(tabCycleOnly && !tabCycle) return false;
6726 child = child.cycle.prev.data;
6728 child = child.cycle.next.data;
6729 if(child == child.parent.activeChild)
6731 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
6734 modalWindow = child.FindModal();
6737 // Scroll the window to include the active control
6738 if(sbh && !child.style.dontScrollHorz)
6740 if(child.scrolledPos.x < 0)
6741 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
6742 else if(child.scrolledPos.x + child.size.w > clientSize.w)
6743 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
6745 if(sbv && !child.style.dontScrollVert)
6747 if(child.scrolledPos.y < 0)
6748 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
6749 else if(child.scrolledPos.y + child.size.h > clientSize.h)
6750 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
6754 child = modalWindow ? modalWindow : child;
6755 child.ActivateEx(true, true, true, true, null, null);
6756 if(child.tabCycle && child.childrenCycle.first)
6757 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
6765 ConsequentialMouseMove(false);
6769 void AddResource(Resource resource)
6773 ResPtr ptr { resource = resource };
6777 // Load Graphics here if window is created already
6778 if(/*created && */display)
6780 display.Lock(false);
6781 ptr.loaded = display.displaySystem.LoadResource(resource);
6785 // Temporary hack to load font right away for listbox in dropbox ...
6786 else if(master && master.display)
6788 master.display.Lock(false);
6789 master.display.displaySystem.LoadResource(resource);
6790 master.display.Unlock();
6796 void RemoveResource(Resource resource)
6801 for(ptr = resources.first; ptr; ptr = ptr.next)
6803 if(ptr.resource == resource)
6809 // Unload Graphics here if window is created already
6810 if(/*created && */display)
6814 display.Lock(false);
6815 display.displaySystem.UnloadResource(resource, ptr.loaded);
6821 resources.Delete(ptr);
6826 void SetCaret(int x, int y, int size)
6833 if(active && !style.interim)
6835 if(visible || !guiApp.caretOwner)
6836 guiApp.caretOwner = size ? this : null;
6838 UpdateCaret(false, false);
6841 guiApp.interfaceDriver.SetCaret(0,0,0);
6842 UpdateCaret(false, true);
6843 guiApp.caretEnabled = false;
6846 else if(style.inactive && active)
6848 guiApp.interfaceDriver.SetCaret(0,0,0);
6849 UpdateCaret(false, true);
6850 guiApp.caretEnabled = false;
6855 void Scroll(int x, int y)
6857 bool opaque = !style.drawBehind || background.a;
6858 if(opaque && display && display.flags.scrolling)
6860 Box box = clientArea;
6861 box.left += clientStart.x;
6862 box.top += clientStart.y;
6863 box.right += clientStart.x;
6864 box.bottom += clientStart.y;
6866 //scrollExtent.Free(null);
6867 scrollExtent.AddBox(box);
6868 scrolledArea.x += x;
6869 scrolledArea.y += y;
6871 //scrollExtent.Free();
6872 //scrollExtent.AddBox(clientArea);
6873 //scrollExtent.Offset(clientStart.x, clientStart.y);
6874 //scrolledArea.x = x;
6875 //scrolledArea.y = y;
6881 rootWindow.dirty = true;
6884 void ReleaseCapture()
6886 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
6888 Window oldCaptured = guiApp.windowCaptured;
6889 guiApp.windowCaptured = null;
6890 guiApp.prevWindow = null;
6893 //guiApp.Log("Released Capture\n");
6895 guiApp.interfaceDriver.SetMouseCapture(null);
6897 //oldCaptured.OnMouseCaptureLost();
6900 oldCaptured.ConsequentialMouseMove(false);
6905 void SetText(char * format, ...)
6912 char caption[MAX_F_STRING];
6914 va_start(args, format);
6915 vsprintf(caption, format, args);
6918 this.caption = new char[strlen(caption)+1];
6920 strcpy(this.caption, caption);
6929 bool Grab(Bitmap bitmap, Box box, bool decorations)
6931 bool result = false;
6932 if(display || this == guiApp.desktop)
6934 Box clip = {MININT, MININT, MAXINT, MAXINT};
6940 clip.Clip(clientArea);
6942 clip.Clip(this.box);
6944 if(rootWindow != this)
6946 clip.left += absPosition.y;
6947 clip.top += absPosition.y;
6948 clip.right += absPosition.x;
6949 clip.bottom += absPosition.y;
6952 clip.left += decorations ? 0 : clientStart.x;
6953 clip.top += decorations ? 0 : clientStart.y;
6954 clip.right += decorations ? 0 : clientStart.x;
6955 clip.bottom += decorations ? 0 : clientStart.y;
6957 if(display && display.flags.flipping)
6959 rootWindow.Update(null);
6960 rootWindow.UpdateDisplay();
6967 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
6968 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6972 result = display.Grab(bitmap, clip.left, clip.top,
6973 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6975 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
6977 if(!bitmap.Convert(null, pixelFormat888, null))
6984 void GetMousePosition(int * x, int * y)
6986 int mouseX = 0, mouseY = 0;
6987 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
6990 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
6991 if(this != guiApp.desktop)
6993 mouseX -= absPosition.x + clientStart.x;
6994 mouseY -= absPosition.y + clientStart.y;
7001 DialogResult DoModal()
7003 DialogResult returnCode = 0;
7004 int terminated = terminateX;
7007 while(!destroyed && guiApp.driver != null)
7009 if(terminateX != terminated)
7011 terminated = terminateX;
7012 guiApp.desktop.Destroy(0);
7013 if(guiApp.desktop.created)
7016 //printf("Resetting terminate X to 0\n");
7022 guiApp.UpdateDisplay();
7023 if(!guiApp.ProcessInput(false))
7026 returnCode = this.returnCode;
7039 return !destroyed && guiApp.driver != null && terminateX < 2;
7042 DialogResult DoModalEnd()
7044 DialogResult returnCode = this.returnCode;
7049 // --- Window manipulation ---
7050 /*bool GetDisabled()
7052 bool disabled = this.disabled;
7054 for(window = this; (window = window.master); )
7065 // --- Mouse Manipulation ---
7066 void GetNCMousePosition(int * x, int * y)
7068 GetMousePosition(x, y);
7069 if(x) *x += clientStart.x;
7070 if(y) *y += clientStart.y;
7073 // --- Carets manipulation ---
7074 void GetCaretPosition(Point caretPos)
7076 caretPos = this.caretPos;
7079 int GetCaretSize(void)
7084 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7090 bool CloseConfirmation(bool parentClosing)
7103 if(!OnClose(parentClosing))
7106 // If you want to skip this, simply set modifiedDocument to false in OnClose
7107 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7109 DialogResult dialogRes;
7112 sprintf(message, $"Save changes to %s?", fileName);
7114 sprintf(message, $"Save changes to Untitled %d?", documentID);
7116 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption, contents = message }.Modal();
7118 if(dialogRes == yes)
7120 // TOFIX: Precomp error if brackets are taken out
7121 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7123 else if(dialogRes == cancel)
7129 for(slave = slaves.first; slave; slave = slave.next)
7130 if(!((Window)slave.data).CloseConfirmation(true))
7132 // ((Window)slave.data).CloseConfirmation(true);
7140 for(child = children.first; child; child = child.next)
7141 if(child.master != this && !child.CloseConfirmation(true))
7151 // Static methods... move them somewhere else?
7152 void ::RestoreCaret()
7154 if(guiApp.caretOwner)
7155 guiApp.caretOwner.UpdateCaret(false, false);
7158 void ::FreeMouseRange()
7160 guiApp.interfaceDriver.SetMouseRange(null, null);
7164 bool MenuFileClose(MenuItem selection, Modifiers mods)
7166 Window document = activeChild;
7168 document.Destroy(0);
7172 bool MenuFileExit(MenuItem selection, Modifiers mods)
7178 bool MenuFileSave(MenuItem selection, Modifiers mods)
7182 fileMonitor.fileName = null;
7185 if(OnSaveFile(fileName))
7187 //if(OnFileModified != Window::OnFileModified)
7190 fileMonitor.fileName = fileName;
7196 MessageBox dialog { master = master, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7197 DialogResult answer = dialog.Modal();
7199 if(answer != yes) return (bool)answer;
7202 return MenuFileSaveAs(selection, mods);
7205 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7207 DialogResult result = (DialogResult)bool::true;
7208 FileDialog fileDialog = saveDialog;
7211 fileDialog = FileDialog {};
7216 fileDialog.filePath = fileName;
7219 char filePath[MAX_FILENAME];
7220 sprintf(filePath, "Untitled %d", documentID);
7221 fileDialog.filePath = filePath;
7223 fileMonitor.fileName = null;
7225 fileDialog.type = save;
7226 fileDialog.text = $"Save As";
7230 fileDialog.master = master.parent ? master : this;
7231 if(fileDialog.Modal() == ok)
7233 char * filePath = fileDialog.filePath;
7235 if(OnSaveFile(filePath))
7238 property::fileName = filePath;
7239 NotifySaved(master, this, filePath);
7244 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7245 DialogResult answer = dialog.Modal();
7260 //if(OnFileModified != Window::OnFileModified && fileName)
7263 fileMonitor.fileName = fileName;
7267 return (bool)result; // Actually returning result from Yes/NoCancel message box
7270 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7272 Window document = activeChild;
7274 for(document = children.first; document; document = next)
7276 next = document.next;
7277 if(document.style.isDocument || document.fileName)
7278 document.MenuFileSave(selection, mods);
7283 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7287 for(document = children.first; document; document = document.next)
7288 //if(document.style.isDocument && document.state == minimized)
7289 if(document.style.isActiveClient && document.state == minimized)
7290 document.SetState(minimized, false, mods);
7294 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7296 Window document = activeChild;
7299 Window firstDocument = null;
7301 OldLink cycle = document.cycle.prev;
7306 if(child.style.isActiveClient && !child.style.hidden)
7310 firstDocument = child;
7311 if(child.state == minimized)
7312 child.SetState(minimized, false, mods);
7315 child.positionID = id++;
7316 child.SetState(normal, false, mods);
7317 child.anchor.left.type = cascade;
7320 child.normalSizeAnchor = *&child.sizeAnchor;
7321 child.normalAnchor = child.anchor;
7323 // Break the anchors for moveable/resizable windows
7324 if(child.style.fixed)
7326 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7328 (*&child.normalAnchor).left = x;
7329 (*&child.normalAnchor).top = y;
7330 (*&child.normalAnchor).right.type = none;
7331 (*&child.normalAnchor).bottom.type = none;
7333 child.normalSizeAnchor.isClientW = false;
7334 child.normalSizeAnchor.isClientH = false;
7335 child.normalSizeAnchor.size.w = w;
7336 child.normalSizeAnchor.size.h = h;
7337 child.anchored = false;
7340 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7342 child.stateAnchor = child.normalAnchor;
7343 child.stateSizeAnchor = child.normalSizeAnchor;
7345 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7346 child.Position(x, y, w, h, true, true, true, true, false, false);
7351 last = children.last;
7352 if(!child.style.stayOnTop)
7353 for(; last && last.style.stayOnTop; last = last.prev);
7354 children.Move(child, last);
7355 childrenOrder.Move(child.order, childrenOrder.last);
7357 if(cycle == document.cycle) break;
7361 firstDocument.Activate();
7366 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7373 // Close all closes all active clients, not all documents
7374 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7376 Window next, document;
7378 for(document = children.first; document; document = next)
7380 for(next = document.next; next && !(next.style.isActiveClient; next = next.next);
7381 if(document.style.isActiveClient)
7382 if(!document.Destroy(0) && !document.style.hidden)
7388 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7390 if(style.hasMaximize && state != maximized)
7391 SetState(maximized, 0, 0);
7395 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7397 if(style.hasMinimize && state != minimized)
7399 SetState(minimized, 0, 0);
7400 parent.CycleChildren(false, true, false, true);
7405 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7407 MenuMoveOrSize(false, selection ? true : false);
7411 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7413 CycleChildren(false, true, false, true);
7417 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7419 CycleChildren(true, true, false, true);
7423 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7425 MenuMoveOrSize(true, true);
7429 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7432 SetState(normal, 0, 0);
7436 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7439 int id = selection.id;
7440 OldLink cycle = activeClient.cycle;
7442 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7445 Window sibling = cycle.data;
7446 if(sibling.style.isActiveClient && sibling.visible && !sibling.style.nonClient)
7454 document = cycle.data;
7455 document.Activate();
7457 //if(activeChild.state == maximized)
7458 // document.SetState(maximized, false, mods);
7459 //else if(document.state == minimized)
7460 // document.SetState(normal, false, mods);
7464 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7466 stayOnTop = !style.stayOnTop;
7470 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7472 Window document = activeChild;
7475 Window firstDocument = null;
7476 OldLink cycle = document.cycle;
7480 Window child = cycle.data;
7481 if(child.style.isActiveClient && !child.style.hidden)
7483 if(!firstDocument) firstDocument = child;
7484 if(child.state == minimized)
7485 child.SetState(minimized, false, mods);
7488 child.positionID = id++;
7489 child.SetState(normal, false, mods);
7490 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7492 child.anchor.left.type = hTiled;
7495 child.normalSizeAnchor = *&child.sizeAnchor;
7496 child.normalAnchor = child.anchor;
7498 // Break the anchors for moveable/resizable windows
7499 if(child.style.fixed)
7501 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7503 (*&child.normalAnchor).left = x;
7504 (*&child.normalAnchor).top = y;
7505 (*&child.normalAnchor).right.type = none;
7506 (*&child.normalAnchor).bottom.type = none;
7507 child.normalSizeAnchor.isClientW = false;
7508 child.normalSizeAnchor.isClientH = false;
7509 child.normalSizeAnchor.size.w = w;
7510 child.normalSizeAnchor.size.h = h;
7511 child.anchored = false;
7514 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7516 child.stateAnchor = child.normalAnchor;
7517 child.stateSizeAnchor = child.normalSizeAnchor;
7519 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7520 child.Position(x,y, w, h, true, true, true, true, false, true);
7525 if((cycle = cycle.next) == document.cycle) break;
7528 firstDocument.Activate();
7533 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7535 Window document = activeChild;
7538 Window firstDocument = null;
7540 OldLink cycle = document.cycle;
7545 //if(child.style.isDocument)
7546 if(child.style.isActiveClient && !child.style.hidden)
7548 if(!firstDocument) firstDocument = child;
7549 if(child.state == minimized)
7550 child.SetState(minimized, false, mods);
7553 child.positionID = id++;
7554 child.SetState(normal, false, mods);
7555 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7557 child.anchor.left.type = vTiled;
7560 child.normalSizeAnchor = *&child.sizeAnchor;
7561 child.normalAnchor = child.anchor;
7563 // Break the anchors for moveable/resizable windows
7564 if(child.style.fixed)
7566 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7568 (*&child.normalAnchor).left = x;
7569 (*&child.normalAnchor).top = y;
7570 (*&child.normalAnchor).right.type = none;
7571 (*&child.normalAnchor).bottom.type = none;
7572 child.normalSizeAnchor.isClientW = false;
7573 child.normalSizeAnchor.isClientH = false;
7574 child.normalSizeAnchor.size.w = w;
7575 child.normalSizeAnchor.size.h = h;
7576 child.anchored = false;
7579 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7581 child.stateAnchor = child.normalAnchor;
7582 child.stateSizeAnchor = child.normalSizeAnchor;
7584 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7585 child.Position(x,y, w, h, true, true, true, true, false, true);
7590 if((cycle = cycle.next) == document.cycle) break;
7593 firstDocument.Activate();
7598 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7600 WindowList dialog { master = this };
7601 Window document = (Window)dialog.Modal();
7604 if(activeChild.state == maximized)
7605 document.SetState(maximized, false, mods);
7606 else if(document.state == minimized)
7607 document.SetState(normal, false, mods);
7608 document.Activate();
7614 virtual bool OnCreate(void);
7615 virtual void OnDestroy(void);
7616 virtual void OnDestroyed(void);
7617 virtual bool OnClose(bool parentClosing);
7618 virtual bool OnStateChange(WindowState state, Modifiers mods);
7619 virtual bool OnPostCreate(void);
7620 virtual bool OnMoving(int *x, int *y, int w, int h);
7621 virtual bool OnResizing(int *width, int *height);
7622 virtual void OnResize(int width, int height);
7623 virtual void OnPosition(int x, int y, int width, int height);
7624 virtual bool OnLoadGraphics(void);
7625 virtual void OnApplyGraphics(void);
7626 virtual void OnUnloadGraphics(void);
7627 virtual void OnRedraw(Surface surface);
7628 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7629 virtual void OnActivateClient(Window client, Window previous);
7630 virtual bool OnKeyDown(Key key, unichar ch);
7631 virtual bool OnKeyUp(Key key, unichar ch);
7632 virtual bool OnKeyHit(Key key, unichar ch);
7633 virtual bool OnSysKeyDown(Key key, unichar ch);
7634 virtual bool OnSysKeyUp(Key key, unichar ch);
7635 virtual bool OnSysKeyHit(Key key, unichar ch);
7636 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7637 virtual bool OnMouseLeave(Modifiers mods);
7638 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7639 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7640 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
7641 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
7642 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
7643 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
7644 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
7645 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
7646 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
7647 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
7648 virtual void OnMouseCaptureLost(void);
7649 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
7650 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
7651 virtual void OnDrawOverChildren(Surface surface);
7652 virtual bool OnFileModified(FileChange fileChange, char * param);
7653 virtual bool OnSaveFile(char * fileName);
7655 // Virtual Methods -- Children management (To support Stacker, for lack of built-in auto-layout)
7656 // Note: A 'client' would refer to isActiveClient, rather than
7657 // being confined to the 'client area' (nonClient == false)
7658 virtual void OnChildAddedOrRemoved(Window child, bool removed);
7659 virtual void OnChildVisibilityToggled(Window child, bool visible);
7660 virtual void OnChildResized(Window child, int x, int y, int w, int h);
7662 // Skins Virtual Functions
7663 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
7664 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
7665 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
7670 virtual void ShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7671 virtual void PreShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7672 virtual bool IsMouseMoving(int x, int y, int w, int h);
7673 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY);
7674 virtual void UpdateNonClient();
7675 virtual void SetBox(Box box);
7676 virtual bool IsInside(int x, int y)
7678 return box.IsPointInside({x, y});
7680 virtual bool IsOpaque()
7682 return (!style.drawBehind || background.a == 255);
7686 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
7687 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
7688 virtual void Window::NotifySaved(Window window, char * filePath);
7693 property Window parent
7695 property_category $"Layout"
7698 if(value || guiApp.desktop)
7701 Window oldParent = parent;
7702 Anchor anchor = this.anchor;
7704 if(value && value.IsDescendantOf(this)) return;
7705 if(value && value == this)
7707 if(!value) value = guiApp.desktop;
7709 if(value == oldParent) return;
7711 if(!master || (master == this.parent && master == guiApp.desktop))
7712 property::master = value;
7716 parent.children.Remove(this);
7717 parent.OnChildAddedOrRemoved(this, true);
7721 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7722 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
7723 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7724 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
7728 last = value.children.last;
7730 if(style.isDocument)
7733 parent.numDocuments--;
7734 documentID = value.GetDocumentID();
7737 if(style.isActiveClient && !style.hidden)
7739 if(parent && parent != guiApp.desktop && !(style.hidden))
7741 if(state == minimized) parent.numIcons--;
7742 parent.numPositions--;
7746 if(!style.stayOnTop)
7747 for(; last && last.style.stayOnTop; last = last.prev);
7749 value.children.Insert(last, this);
7751 // *** NEW HERE: ***
7753 parent.childrenCycle.Delete(cycle);
7755 parent.childrenOrder.Delete(order);
7763 int x = position.x, y = position.y, w = size.w, h = size.h;
7767 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
7768 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
7770 vpw = value.clientSize.w;
7771 vph = value.clientSize.h;
7777 else if(style.fixed)
7779 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
7780 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
7783 anchor = this.anchor;
7785 if(anchor.left.type == offset) anchor.left.distance = x;
7786 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
7787 if(anchor.top.type == offset) anchor.top.distance = y;
7788 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
7789 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
7790 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
7791 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
7792 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
7793 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
7794 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
7796 if(!anchor.left.type && !anchor.right.type)
7798 anchor.horz.distance = (x + w / 2) - (vpw / 2);
7799 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
7801 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
7802 if(!anchor.top.type && !anchor.bottom.type)
7804 anchor.vert.distance = (y + h / 2) - (vph / 2);
7805 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
7807 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
7810 parent.OnChildAddedOrRemoved(this, false);
7816 parent.childrenCycle.Insert(
7817 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
7818 cycle = OldLink { data = this });
7819 parent.childrenOrder.Insert(
7820 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
7821 order = OldLink { data = this });
7824 if(!style.hidden && style.isActiveClient)
7826 positionID = parent.GetPositionID(this);
7827 parent.numPositions++;
7828 if(state == minimized) parent.numIcons--;
7831 // *** FONT INHERITANCE ***
7832 if(!setFont && oldParent)
7833 stopwatching(oldParent, font);
7837 RemoveResource(systemFont);
7840 // TESTING WITH WATCHERS:
7841 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7842 // usedFont = setFont ? setFont : (systemFont);
7846 if(guiApp.currentSkin)
7848 systemFont = guiApp.currentSkin.SystemFont();
7851 usedFont = systemFont;
7852 AddResource(systemFont);
7860 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7869 if(value.rootWindow && value.rootWindow.display && rootWindow)
7871 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
7872 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
7875 UnloadGraphics(false);
7878 LoadGraphics(false, false);
7881 if(value.rootWindow != rootWindow)
7882 DisplayModeChanged();
7886 scrolledPos.x = MININT; // Prevent parent update
7887 property::anchor = anchor;
7891 if(guiApp.currentSkin)
7892 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
7894 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7895 Position(x, y, w, h, true, true, true, true, false, true);
7900 // else parent = value;
7903 get { return parent; }
7906 property Window master
7908 property_category $"Behavior"
7911 //if(this == value) return;
7912 if(value && value.IsSlaveOf(this)) return;
7918 OldLink slaveHolder;
7919 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
7920 if(slaveHolder.data == this)
7922 master.slaves.Delete(slaveHolder);
7929 value.slaves.Add(OldLink { data = this });
7934 master.hotKeys.Remove(hotKey);
7935 value.hotKeys.Add(hotKey);
7938 if(master && master.defaultControl == this)
7939 master.defaultControl = null;
7941 if(style.isDefault && !value.defaultControl)
7942 value.defaultControl = this;
7947 get { return master ? master : parent; }
7950 property char * caption
7952 property_category $"Appearance"
7959 caption = new char[strlen(value)+1];
7961 strcpy(caption, value);
7966 get { return caption; }
7971 property_category $"Behavior"
7980 master.hotKeys.Add(hotKey = HotKeySlot { });
7984 hotKey.window = this;
7989 master.hotKeys.Delete(hotKey);
7994 get { return hotKey ? hotKey.key : 0; }
7997 property Color background
7999 property_category $"Appearance"
8002 background.color = value;
8007 if(this == rootWindow)
8008 guiApp.interfaceDriver.SetRootWindowColor(this);
8011 get { return background.color; }
8014 property Percentage opacity
8016 property_category $"Appearance"
8019 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
8020 drawBehind = background.a ? false : true;
8022 get { return background.a / 255.0f; }
8025 property Color foreground
8027 property_category $"Appearance"
8035 get { return foreground; }
8038 property BorderStyle borderStyle
8040 property_category $"Appearance"
8043 if(!((BorderBits)value).fixed)
8045 style.hasClose = false;
8046 style.hasMaximize = false;
8047 style.hasMinimize = false;
8048 nativeDecorations = false;
8050 style.borderBits = value;
8054 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8056 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8057 Position(x, y, w, h, true, true, true, true, false, true);
8058 CreateSystemChildren();
8061 get { return (BorderStyle)style.borderBits; }
8064 property Size minClientSize
8066 property_category $"Layout"
8067 set { minSize = value; }
8068 get { value = minSize; }
8071 property Size maxClientSize
8073 property_category $"Layout"
8074 set { maxSize = value; }
8075 get { value = maxSize; }
8078 property bool hasMaximize
8080 property_category $"Window Style"
8083 style.hasMaximize = value;
8084 if(value) { style.fixed = true; style.contour = true; }
8088 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8090 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8091 Position(x, y, w, h, true, true, true, true, false, true);
8093 CreateSystemChildren();
8096 get { return style.hasMaximize; }
8099 property bool hasMinimize
8101 property_category $"Window Style"
8104 style.hasMinimize = value;
8105 if(value) { style.fixed = true; style.contour = true; }
8109 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8111 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8112 Position(x, y, w, h, true, true, true, true, false, true);
8114 CreateSystemChildren();
8117 get { return style.hasMinimize; }
8120 property bool hasClose
8122 property_category $"Window Style"
8125 style.hasClose = value;
8126 if(value) { style.fixed = true; style.contour = true; }
8130 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8131 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8132 Position(x, y, w, h, true, true, true, true, false, true);
8133 CreateSystemChildren();
8136 get { return style.hasClose; }
8139 property bool nonClient
8141 property_category $"Layout"
8144 style.nonClient = value;
8146 style.stayOnTop = true;
8148 get { return style.nonClient; }
8151 property bool inactive
8153 property_category $"Behavior"
8158 // *** NEW HERE: ***
8162 parent.childrenCycle.Delete(cycle);
8164 parent.childrenOrder.Delete(order);
8171 active = false; // true;
8172 if(parent.activeChild == this)
8173 parent.activeChild = null;
8174 if(parent.activeClient == this)
8175 parent.activeClient = null;
8184 parent.childrenCycle.Insert(
8185 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8186 cycle = OldLink { data = this });
8188 parent.childrenOrder.Insert(
8189 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8190 order = OldLink { data = this });
8193 style.inactive = value;
8195 get { return style.inactive; }
8198 property bool clickThrough
8200 property_category $"Behavior"
8201 set { style.clickThrough = value; }
8202 get { return style.clickThrough; }
8205 property bool isRemote
8207 property_category $"Behavior"
8208 set { style.isRemote = value; }
8209 get { return style.isRemote; }
8212 property bool noCycle
8214 property_category $"Behavior"
8215 set { style.noCycle = value; }
8216 get { return style.noCycle; }
8219 property bool isModal
8221 property_category $"Behavior"
8222 set { style.modal = value; }
8223 get { return style.modal; }
8226 property bool interim
8228 property_category $"Behavior"
8229 set { style.interim = value; }
8230 get { return style.interim; }
8233 property bool tabCycle
8235 property_category $"Behavior"
8236 set { style.tabCycle = value; }
8237 get { return style.tabCycle; }
8240 property bool isDefault
8242 property_category $"Behavior"
8250 /*for(sibling = parent.children.first; sibling; sibling = sibling.next)
8251 if(sibling != this && sibling.style.isDefault)
8252 sibling.style.isDefault = false;*/
8253 if(master.defaultControl)
8254 master.defaultControl.style.isDefault = false;
8255 master.defaultControl = this;
8257 else if(master.defaultControl == this)
8258 master.defaultControl = null;
8262 style.isDefault = value;
8264 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8266 get { return style.isDefault; }
8269 property bool drawBehind
8271 property_category $"Window Style"
8272 set { style.drawBehind = value; }
8273 get { return style.drawBehind; }
8276 property bool hasMenuBar
8278 property_category $"Window Style"
8288 if(created && !menuBar)
8295 anchor = Anchor { top = 23, left = 1, right = 1 },
8297 inactive = true, nonClient = true
8302 else if(created && menuBar)
8307 style.hasMenuBar = value;
8309 get { return style.hasMenuBar; }
8312 property bool hasStatusBar
8314 property_category $"Window Style"
8321 statusBar = StatusBar { this };
8329 style.hasStatusBar = value;
8331 get { return style.hasStatusBar; }
8333 property bool stayOnTop
8335 property_category $"Window Style"
8340 if(created && !style.stayOnTop)
8342 if(rootWindow == this)
8343 guiApp.interfaceDriver.OrderRootWindow(this, true);
8344 else if(parent.children.last != this)
8346 parent.children.Move(this, parent.children.last);
8350 style.stayOnTop = true;
8354 if(created && style.stayOnTop)
8356 if(rootWindow == this)
8357 guiApp.interfaceDriver.OrderRootWindow(this, false);
8364 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8365 order && ((Window)order.data).style.stayOnTop;
8366 order = (order == parent.childrenOrder.first) ? null : order.prev);
8367 last = order ? order.data : null;
8371 for(last = parent.children.last;
8372 last && last.style.stayOnTop;
8376 parent.children.Move(this, last);
8380 style.stayOnTop = false;
8383 get { return style.stayOnTop; }
8388 property_category $"Window Style"
8398 if(menuBar && !value)
8405 if(!menuBar && style.hasMenuBar && value)
8409 this, menu = value, isMenuBar = true,
8410 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8411 inactive = true, nonClient = true
8415 UpdateActiveDocument(null);
8418 get { return menu; }
8421 property FontResource font
8423 property_category $"Appearance"
8425 isset { return setFont ? true : false; }
8430 if(value && !setFont) { stopwatching(parent, font); }
8431 else if(!value && setFont)
8437 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8446 RemoveResource(setFont);
8451 RemoveResource(systemFont);
8458 AddResource(setFont);
8461 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8464 systemFont = guiApp.currentSkin.SystemFont();
8466 usedFont = systemFont;
8467 AddResource(systemFont);
8475 get { return usedFont; }
8478 property SizeAnchor sizeAnchor
8480 property_category $"Layout"
8483 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8484 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8485 sizeAnchor.isClientW != sizeAnchor.isClientH;
8492 normalSizeAnchor = sizeAnchor;
8494 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8496 stateAnchor = normalAnchor;
8497 stateSizeAnchor = normalSizeAnchor;
8499 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8500 Position(x,y, w, h, true, true, true, true, false, true);
8507 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8508 sizeAnchor.isClientW,
8509 sizeAnchor.isClientH
8516 property_category $"Layout"
8519 Anchor thisAnchor = anchor;
8520 SizeAnchor thisSizeAnchor = sizeAnchor;
8521 bool leftRight = (anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none);
8522 bool topBottom = (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none);
8523 bool isClient = !sizeAnchor.isClientW && !sizeAnchor.isClientH;
8524 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8525 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8526 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8532 sizeAnchor.isClientW = false;
8533 sizeAnchor.isClientH = false;
8534 sizeAnchor.size = value;
8536 normalSizeAnchor = sizeAnchor;
8538 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8540 stateAnchor = normalAnchor;
8541 stateSizeAnchor = normalSizeAnchor;
8543 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8544 Position(x, y, w, h, true, true, true, true, false, true);
8545 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
8548 get { value = size; }
8551 property Size clientSize
8553 property_category $"Layout"
8556 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8557 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8558 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8563 sizeAnchor.isClientW = true;
8564 sizeAnchor.isClientH = true;
8565 sizeAnchor.size = value;
8567 normalSizeAnchor = sizeAnchor;
8569 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8571 stateAnchor = normalAnchor;
8572 stateSizeAnchor = normalSizeAnchor;
8574 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8575 Position(x,y, w, h, true, true, true, true, false, true);
8578 get { value = clientSize; }
8581 property Size initSize { get { value = sizeAnchor.size; } };
8583 property Anchor anchor
8585 property_category $"Layout"
8586 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8592 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8594 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8595 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8597 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8599 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8600 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8604 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8606 anchor.left.distance = 0;
8607 anchor.horz.type = 0;
8609 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8611 anchor.top.distance = 0;
8612 anchor.vert.type = 0;
8621 normalAnchor = anchor;
8623 // Break the anchors for moveable/resizable windows
8624 /*if(style.fixed ) //&& value.left.type == cascade)
8626 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
8628 this.anchor = normalAnchor = Anchor { left = x, top = y };
8629 normalSizeAnchor = SizeAnchor { { w, h } };
8632 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8634 stateAnchor = normalAnchor;
8635 stateSizeAnchor = normalSizeAnchor;
8637 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8638 Position(x, y, w, h, true, true, true, true, false, true);
8647 get { value = this ? anchor : Anchor { }; }
8650 property Point position
8652 property_category $"Layout"
8655 if(value == null) return;
8657 anchor.left = value.x;
8658 anchor.top = value.y;
8659 anchor.right.type = none;
8660 anchor.bottom.type = none;
8665 normalAnchor = anchor;
8667 // Break the anchors for moveable/resizable windows
8671 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8673 normalAnchor.left = x;
8674 normalAnchor.top = y;
8675 normalAnchor.right.type = none;
8676 normalAnchor.bottom.type = none;
8677 normalSizeAnchor.size.width = w;
8678 normalSizeAnchor.size.height = h;
8682 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8684 stateAnchor = normalAnchor;
8685 stateSizeAnchor = normalSizeAnchor;
8687 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8688 Position(x,y, w, h, true, true, true, true, false, true);
8692 get { value = position; }
8695 property bool disabled
8697 property_category $"Behavior"
8700 if(this && disabled != value)
8707 get { return (bool)disabled; }
8710 property bool isEnabled
8715 for(parent = this; parent; parent = parent.parent)
8722 property WindowState state
8724 property_category $"Behavior"
8725 set { SetState(value, false, 0); }
8726 get { return this ? state : 0; }
8729 property bool visible
8731 property_category $"Behavior"
8734 if(this && !value && !style.hidden && parent)
8736 bool wasActiveChild = parent.activeChild == this;
8737 Window client = null;
8739 style.hidden = true;
8740 if(style.isActiveClient)
8742 parent.numPositions--;
8743 if(state == minimized) parent.numIcons--;
8748 OldLink prevOrder = null;
8750 if(rootWindow == this)
8751 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
8754 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
8757 box.left -= parent.clientStart.x;
8758 box.top -= parent.clientStart.y;
8759 box.right -= parent.clientStart.x;
8760 box.bottom -= parent.clientStart.y;
8764 if(_isModal && master && master.modalSlave == this)
8765 master.modalSlave = null;
8769 OldLink tmpPrev = order.prev;
8770 client = tmpPrev ? tmpPrev.data : null;
8771 if(client && !client.style.hidden && !client.destroyed && client.created)
8772 prevOrder = tmpPrev;
8775 client = tmpPrev ? tmpPrev.data : null;
8776 if(client == this) { client = null; break; }
8777 if(client && ((client.style.hidden) || client.destroyed || !client.created))
8779 tmpPrev = client.order.prev;
8784 prevOrder = tmpPrev;
8789 // If this window can be an active client, make sure the next window we activate can also be one
8790 if(!style.nonClient && style.isActiveClient)
8792 tmpPrev = prevOrder;
8795 client = tmpPrev ? tmpPrev.data : null;
8796 if(client == this) { client = null; break; }
8797 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
8799 tmpPrev = client.order.prev;
8804 prevOrder = tmpPrev;
8808 if(client && client.style.hidden) client = null;
8812 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
8814 if(order && prevOrder && prevOrder.data != this)
8815 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
8817 ActivateEx(false, false, false, true, null, null);
8819 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
8820 if(parent.activeClient == this)
8822 parent.activeClient = null;
8823 parent.UpdateActiveDocument(null);
8826 else if(parent.activeClient == this)
8828 parent.activeClient = client;
8829 parent.UpdateActiveDocument(this);
8832 // *** Not doing this anymore ***
8835 parent.childrenCycle.Delete(cycle);
8837 parent.childrenOrder.Delete(order);
8842 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8847 else if(this && value && style.hidden)
8849 style.hidden = false;
8852 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8853 if(rootWindow == this)
8854 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
8856 if(_isModal && master)
8857 master.modalSlave = this;
8859 if(style.isActiveClient)
8861 positionID = parent.GetPositionID(this);
8862 parent.numPositions++;
8863 if(state == minimized) parent.numIcons++;
8866 // *** NOT DOING THIS ANYMORE ***
8868 if(!(style.inactive))
8870 if(!(style.noCycle))
8872 cycle = parent.childrenCycle.AddAfter(
8873 (parent.activeChild && parent.activeChild.cycle) ?
8874 parent.activeChild.cycle.prev : null, sizeof(OldLink));
8877 order = parent.childrenOrder.AddAfter(
8878 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8885 if(true || !parent.activeChild)
8886 ActivateEx(true, false, true, true, null, null);
8888 if(creationActivation == activate)
8889 ActivateEx(true, false, true, true, null, null);
8890 else if(creationActivation == flash && !object)
8893 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8897 ConsequentialMouseMove(false);
8903 style.hidden = !value;
8906 get { return (style.hidden || !setVisible) ? false : true; }
8909 property bool isDocument
8911 property_category $"Document"
8912 set { style.isDocument = value; }
8913 get { return style.isDocument; }
8916 property bool mergeMenus
8918 property_category $"Window Style"
8919 set { mergeMenus = value; }
8920 get { return (bool)mergeMenus; }
8923 property bool hasHorzScroll
8925 property_category $"Window Style"
8930 if(!style.hasHorzScroll && created)
8932 CreateSystemChildren();
8933 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8936 else if(style.hasHorzScroll)
8940 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8942 style.hasHorzScroll = value;
8945 get { return style.hasHorzScroll; }
8948 property bool hasVertScroll
8950 property_category $"Window Style"
8955 if(!style.hasVertScroll && created)
8957 style.hasVertScroll = true;
8958 CreateSystemChildren();
8959 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8962 else if(style.hasVertScroll)
8966 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8968 style.hasVertScroll = value;
8970 get { return style.hasVertScroll; }
8973 property bool dontHideScroll
8975 property_category $"Behavior"
8978 scrollFlags.dontHide = value;
8981 //UpdateScrollBars(true, true);
8982 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8986 // UpdateScrollBars(true, true);
8987 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8990 get { return scrollFlags.dontHide; }
8993 property bool dontScrollVert
8995 property_category $"Behavior"
8996 set { style.dontScrollVert = value; }
8997 get { return style.dontScrollVert; }
8999 property bool dontScrollHorz
9001 property_category $"Behavior"
9002 set { style.dontScrollHorz = value; }
9003 get { return style.dontScrollHorz; }
9006 property bool snapVertScroll
9008 property_category $"Behavior"
9011 scrollFlags.snapY = value;
9012 if(sbv) sbv.snap = value;
9014 get { return scrollFlags.snapY; }
9016 property bool snapHorzScroll
9018 property_category $"Behavior"
9021 scrollFlags.snapX = value;
9022 if(sbh) sbh.snap = value;
9024 get { return scrollFlags.snapX; }
9027 property Point scroll
9029 property_category $"Behavior"
9033 // TESTING THIS IMPLEMENTATION:
9034 SetScrollPosition(value.x, value.y);
9036 get { value = scroll; }
9039 property bool modifyVirtualArea
9041 property_category $"Behavior"
9042 set { modifyVirtArea = value; }
9043 get { return (bool)modifyVirtArea; }
9046 property char * fileName
9048 property_category $"Document"
9051 if(menu && ((!fileName && value) || (fileName && !value)))
9053 MenuItem item = menu.FindItem(MenuFileSave, 0);
9054 if(item) item.disabled = !modifiedDocument && value;
9059 if(value && value[0])
9060 fileName = CopyString(value);
9062 if(parent && this == parent.activeClient)
9063 parent.UpdateActiveDocument(null);
9067 // if(style.isDocument)
9069 fileMonitor.fileName = value;
9071 get { return fileName; }
9076 property_category $"Data"
9081 property bool modifiedDocument
9083 property_category $"Document"
9086 if(style.isDocument || fileName)
9090 MenuItem item = menu.FindItem(MenuFileSave, 0);
9091 if(item) item.disabled = !value && fileName;
9095 if(modifiedDocument != value)
9097 modifiedDocument = value;
9098 if(style.isDocument || fileName)
9102 get { return (bool)modifiedDocument; }
9105 property bool showInTaskBar
9107 property_category $"Window Style"
9108 set { style.showInTaskBar = value; }
9109 get { return (style.showInTaskBar; }
9111 property FileDialog saveDialog { set { saveDialog = value; } };
9112 property bool isActiveClient
9114 property_category $"Behavior"
9115 set { style.isActiveClient = value; }
9116 get { return style.isActiveClient; }
9119 property Cursor cursor
9121 property_category $"Appearance"
9125 SelectMouseCursor();
9127 get { return cursor; }
9130 //#if !defined(ECERE_VANILLA)
9131 property char * name
9133 property_category $"Design"
9136 return (this && object) ? object.name : null;
9141 activeDesigner.RenameObject(object, value);
9145 property char * displayDriver
9147 property_category $"Behavior"
9150 dispDriver = GetDisplayDriver(value);
9151 //DisplayModeChanged();
9155 return dispDriver ? dispDriver.name : null;
9159 // RUNTIME PROPERTIES
9160 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9161 property Size scrollArea
9163 property_category $"Behavior"
9167 SetScrollArea(value.w, value.h, false);
9169 SetScrollArea(0,0, true);
9171 get { value = scrollArea; }
9174 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9179 property_category $"Layout"
9180 set { if(this) is3D = value; }
9181 get { return (bool)is3D; }
9184 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9186 // Will be merged with font later
9187 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9188 property Point clientStart { get { value = clientStart; } };
9189 property Point absPosition { get { value = absPosition; } };
9190 property Anchor normalAnchor { get {value = normalAnchor; } };
9191 // property Size normalSizeAnchor { get { value = normalSizeAnchor; } };
9192 property bool active { get { return (bool)active; } };
9193 property bool created { get { return (bool)created; } };
9194 property bool destroyed { get { return (bool)destroyed; } };
9195 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9196 property Window firstChild { get { return children.first; } };
9197 property Window lastChild { get { return children.last; } };
9198 property Window activeClient { get { return activeClient; } };
9199 property Window activeChild { get { return activeChild; } };
9200 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9201 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9202 property ScrollBar horzScroll { get { return sbh; } };
9203 property ScrollBar vertScroll { get { return sbv; } };
9204 property StatusBar statusBar { get { return statusBar; } };
9205 property Window rootWindow { get { return rootWindow; } };
9206 property bool closing { get { return (bool)closing; } set { closing = value; } };
9207 property int documentID { get { return documentID; } };
9208 property Window previous { get { return prev; } }
9209 property Window next { get { return next; } }
9210 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9211 property PopupMenu menuBar { get { return menuBar; } }
9212 property ScrollBar sbv { get { return sbv; } }
9213 property ScrollBar sbh { get { return sbh; } }
9214 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9215 property void * systemHandle { get { return windowHandle; } }
9216 property Button minimizeButton { get { return sysButtons[0]; } };
9217 property Button maximizeButton { get { return sysButtons[1]; } };
9218 property Button closeButton { get { return sysButtons[2]; } };
9219 property BitmapResource icon
9221 get { return icon; }
9225 if(icon) incref icon;
9227 guiApp.interfaceDriver.SetIcon(this, value);
9230 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9231 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } };
9232 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9233 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9234 property bool nativeDecorations
9236 get { return (bool)nativeDecorations; }
9237 set { nativeDecorations = value; }
9238 #ifndef ECERE_VANILLA
9239 isset { return (nativeDecorations && (rootWindow == this || (formDesigner && activeDesigner && parent == ((FormDesigner)activeDesigner.classDesigner).form.parent))) != style.fixed; }
9242 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9244 property char * text
9246 property_category $"Deprecated"
9248 set { property::caption = value; }
9249 get { return property::caption; }
9255 WindowBits style; // Window Style
9256 char * caption; // Name / Caption
9257 Window parent; // Parent window
9258 OldList children; // List of children in Z order
9259 Window activeChild; // Child window having focus
9260 Window activeClient;
9261 Window previousActive; // Child active prior to activating the default child
9262 Window master; // Window owning and receiving notifications concerning this window
9263 OldList slaves; // List of windows belonging to this window
9264 Display display; // Display this window is drawn into
9266 Point position; // Position in parent window client area
9267 Point absPosition; // Absolute position
9268 Point clientStart; // Client area position from (0,0) in this window
9270 Size clientSize; // Client area size
9271 Size scrollArea; // Virtual Scroll area size
9272 Size reqScrollArea; // Requested virtual area size
9273 Point scroll; // Virtual area scrolling position
9274 public ScrollBar sbh, sbv; // Scrollbar window handles
9275 Cursor cursor; // Mouse cursor used for this window
9278 StatusBar statusBar;
9279 Button sysButtons[3];
9281 Box clientArea; // Client Area box clipped to parent
9283 HotKeySlot hotKey; // HotKey for this window
9287 ScrollFlags scrollFlags;// Window Scrollbar Flags
9288 int id; // Control ID
9290 ColorAlpha background; // Background color used to draw the window area
9292 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9293 OldList childrenCycle; // Cycling order
9294 OldLink cycle; // Element of parent's cycling order
9295 OldList childrenOrder; // Circular Z-Order
9296 OldLink order; // Element of parent's circular Z-Order
9297 Window modalSlave; // Slave window blocking this window's interaction
9299 Window rootWindow; // Topmost system managed window
9300 void * windowHandle; // System window handle
9302 DialogResult returnCode;// Return code for modal windows
9304 Point sbStep; // Scrollbar line scrolling steps
9307 SizeAnchor stateSizeAnchor;
9309 Anchor normalAnchor;
9310 SizeAnchor normalSizeAnchor;
9312 Size skinMinSize; // Minimal window size based on style
9313 Point scrolledPos; // Scrolled position
9314 Box box; // Window box clipped to parent
9315 Box * against; // What to clip the box to
9317 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9318 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9319 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9320 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9321 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9322 Point scrolledArea; // Distance to scroll area by
9323 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9325 OldList hotKeys; // List of the hotkeys of all children
9326 Window defaultControl; // Default child control
9330 ColorAlpha * palette; // Color palette used for this window
9332 int caretSize; // Size of caret, non zero if a caret is present
9333 Point caretPos; // Caret position
9335 void * systemParent; // Parent System Window for embedded windows
9342 WindowState lastState;
9344 FileMonitor fileMonitor
9346 this, FileChange { modified = true };
9348 bool OnFileNotify(FileChange action, char * param)
9351 fileMonitor.StopMonitoring();
9352 if(OnFileModified(action, param))
9353 fileMonitor.StartMonitoring();
9358 FontResource setFont, systemFont;
9359 FontResource usedFont;
9360 FontResource captionFont;
9362 FileDialog saveDialog;
9364 SizeAnchor sizeAnchor;
9366 // FormDesigner data
9369 Extent * tempExtents; //[4];
9370 BitmapResource icon;
9372 CreationActivationOption creationActivation;
9375 bool active:1; // true if window and ancestors are active
9376 bool acquiredInput:1; // true if the window is processing state based input
9377 bool modifiedDocument:1;
9378 bool disabled:1; // true if window cannot interact
9379 bool isForegroundWindow:1;// true while a root window is being activated
9380 bool visible:1; // Visibility flag
9381 bool destroyed:1; // true if window is being destroyed
9382 bool anchored:1; // true if this window is repositioned when the parent resizes
9383 bool dirty:1; // Flag set to true if any descendant must be redrawn
9389 bool modifyVirtArea:1;
9390 bool noAutoScrollArea:1;
9393 bool setVisible:1; // FOR FORM DESIGNER
9399 bool useSharedMemory:1;
9402 bool nativeDecorations:1;
9403 bool manageDisplay:1;
9404 bool formDesigner:1; // True if we this is running in the form editor
9407 // Checks used internally for them not to take effect in FormDesigner
9408 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9409 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9411 WindowController controller;
9412 public property WindowController controller { get { return controller; } set { delete controller; controller = value; if(controller) incref controller; } }
9415 public class CommonControl : Window
9417 // creationActivation = doNothing;
9420 public property String toolTip
9422 property_category $"Appearance"
9425 if(created) CommonControl::OnDestroy();
9427 toolTip = value ? ToolTip { tip = value; } : null;
9429 if(created) CommonControl::OnCreate();
9431 get { return toolTip ? toolTip.tip : null; }
9437 // (Very) Ugly work around for the fact that the parent watcher
9438 // won't fire when it's already been disconnected...
9439 eInstance_FireSelfWatchers(toolTip,
9440 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
9446 toolTip.parent = this;
9455 public class Percentage : float
9457 char * OnGetString(char * string, float * fieldData, bool * needClass)
9461 sprintf(string, "%.2f", this);
9462 c = strlen(string)-1;
9465 if(string[c] != '0')
9466 last = Max(last, c);
9467 if(string[c] == '.')
9480 public void ApplySkin(Class c, char * name, void ** vTbl)
9482 char className[1024];
9487 subclass(Window) wc = (subclass(Window))c;
9488 subclass(Window) base = (subclass(Window))c.base;
9490 sprintf(className, "%sSkin_%s", name, c.name);
9491 wc.pureVTbl = c._vTbl;
9492 c._vTbl = new void *[c.vTblSize];
9493 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9494 sc = eSystem_FindClass(c.module.application, className);
9498 for(m = 0; m < c.base.vTblSize; m++)
9500 if(c._vTbl[m] == base.pureVTbl[m])
9501 c._vTbl[m] = vTbl[m];
9506 for(m = 0; m < c.vTblSize; m++)
9508 if(sc._vTbl[m] != wc.pureVTbl[m])
9509 c._vTbl[m] = sc._vTbl[m];
9513 for(d = c.derivatives.first; d; d = d.next)
9515 ApplySkin(d.data, name, c._vTbl);
9519 public void UnapplySkin(Class c)
9521 char className[1024];
9523 subclass(Window) wc = (subclass(Window))c;
9524 subclass(Window) base = (subclass(Window))c.base;
9527 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9530 c._vTbl = wc.pureVTbl;
9534 for(d = c.derivatives.first; d; d = d.next)
9536 UnapplySkin(d.data);
9540 void CheckFontIntegrity(Window window)
9545 if(window.usedFont && window.usedFont.font == 0xecececec)
9547 FontResource uf = window.usedFont;
9548 char * className = window._class.name;
9549 char * text = window.text;
9552 for(c = window.firstChild; c; c = c.next)
9553 CheckFontIntegrity(c);
9557 public class ControllableWindow : Window
9559 /*WindowController controller;
9560 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9561 ~ControllableWindow() { delete controller; }*/
9564 class WindowControllerInterface : ControllableWindow
9566 bool OnKeyDown(Key key, unichar ch)
9568 bool result = ((int(*)())(void *)controller.OnKeyDown)((void *)controller.controlled, (void *)controller, key, ch);
9570 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown](controller.window, key, ch);
9574 bool OnKeyUp(Key key, unichar ch)
9576 bool result = ((int(*)())(void *)controller.OnKeyUp)((void *)controller.controlled, (void *)controller, key, ch);
9578 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp](controller.window, key, ch);
9582 bool OnKeyHit(Key key, unichar ch)
9584 bool result = ((int(*)())(void *)controller.OnKeyHit)((void *)controller.controlled, (void *)controller, key, ch);
9586 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit](controller.window, key, ch);
9590 bool OnMouseMove(int x, int y, Modifiers mods)
9592 bool result = ((int(*)())(void *)controller.OnMouseMove)((void *)controller.controlled, (void *)controller, x, y, mods);
9594 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove](controller.window, x, y, mods);
9598 bool OnLeftButtonDown(int x, int y, Modifiers mods)
9600 bool result = ((int(*)())(void *)controller.OnLeftButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9602 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown](controller.window, x, y, mods);
9606 bool OnLeftButtonUp(int x, int y, Modifiers mods)
9608 bool result = ((int(*)())(void *)controller.OnLeftButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9610 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp](controller.window, x, y, mods);
9614 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
9616 bool result = ((int(*)())(void *)controller.OnLeftDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9618 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick](controller.window, x, y, mods);
9622 bool OnRightButtonDown(int x, int y, Modifiers mods)
9624 bool result = ((int(*)())(void *)controller.OnRightButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9626 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown](controller.window, x, y, mods);
9630 bool OnRightButtonUp(int x, int y, Modifiers mods)
9632 bool result = ((int(*)())(void *)controller.OnRightButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9634 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp](controller.window, x, y, mods);
9638 bool OnRightDoubleClick(int x, int y, Modifiers mods)
9640 bool result = ((int(*)())(void *)controller.OnRightDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9642 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick](controller.window, x, y, mods);
9646 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
9648 bool result = ((int(*)())(void *)controller.OnMiddleButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9650 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown](controller.window, x, y, mods);
9654 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
9656 bool result = ((int(*)())(void *)controller.OnMiddleButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9658 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp](controller.window, x, y, mods);
9662 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
9664 bool result = ((int(*)())(void *)controller.OnMiddleDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9666 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick](controller.window, x, y, mods);
9670 void OnResize(int width, int height)
9672 ((int(*)())(void *)controller.OnResize)((void *)controller.controlled, (void *)controller, width, height);
9673 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize](controller.window, width, height);
9676 void OnRedraw(Surface surface)
9678 ((int(*)())(void *)controller.OnRedraw)((void *)controller.controlled, (void *)controller, surface);
9679 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw](controller.window, surface);
9684 bool result = ((int(*)())(void *)controller.OnCreate)((void *)controller.controlled, (void *)controller);
9686 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
9691 public class WindowController<class V>
9694 property Window window
9698 uint size = class(Window).vTblSize;
9701 windowVTbl = new void *[size];
9702 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
9703 if(value._vTbl == value._class._vTbl)
9705 value._vTbl = new void *[value._class.vTblSize];
9706 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
9710 for(c = 0; c < size; c++)
9712 void * function = class(WindowControllerInterface)._vTbl[c];
9713 if(function != DefaultFunction)
9714 value._vTbl[c] = function;
9716 value._vTbl[c] = windowVTbl[c];
9721 memcpy(value._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
9724 get { return window; }
9726 property V controlled
9728 set { controlled = value; }
9729 get { return controlled; }
9731 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
9732 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
9733 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
9734 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
9735 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
9736 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
9737 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9738 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
9739 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
9740 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9741 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
9742 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
9743 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9744 virtual void V::OnResize(WindowController controller, int width, int height);
9745 virtual void V::OnRedraw(WindowController controller, Surface surface);
9746 virtual bool V::OnCreate(WindowController controller);
9749 int (** windowVTbl)();