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))
6140 // Things might have happened that invalidated 'next'...
6141 // Start over the search for slaves to create.
6142 // (Added this to fix crash with Stacker & Toolbar)
6143 next = slaves.first;
6152 if(parent == guiApp.desktop)
6153 Log("Real SetState %s\n", caption);
6156 if(isActiveClient && visible)
6158 parent.numPositions--;
6159 if(state == minimized) parent.numIcons--;
6162 // Real set state & activate for proper display & activation
6163 property::visible = visible;
6164 // SetState(state & 0x00000003, true, 0);
6169 /*if(rootWindow == this)
6170 guiApp.interfaceDriver.ActivateRootWindow(this);
6172 if(creationActivation == activate)
6173 ActivateEx(true, false, true, true, null, null);
6174 else if(creationActivation == flash)
6179 rootWindow.ConsequentialMouseMove(false);
6190 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6196 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6198 //style.hidden = true; // !visible;
6199 style.hidden = !visible;
6200 if(master.modalSlave == this)
6201 master.modalSlave = null;
6208 void WriteCaption(Surface surface, int x, int y)
6211 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6214 void Update(Box region)
6220 rootWindow = this.rootWindow;
6222 // rootWindow.mutex.Wait();
6223 if(!destroyed && visible && display)
6228 // Testing this to avoid repetitve full update to take time...
6229 if(dirtyArea.count == 1)
6231 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6232 if(item.box.left <= box.left &&
6233 item.box.top <= box.top &&
6234 item.box.right >= box.right &&
6235 item.box.bottom >= box.bottom)
6237 rootWindow.dirty = true;
6242 if(display.flags.flipping && !rootWindow.dirty)
6244 if(this == rootWindow)
6248 rootWindow.Update(null);
6253 rootWindow.dirty = true;
6258 realBox.left += clientStart.x;
6259 realBox.top += clientStart.y;
6260 realBox.right += clientStart.x;
6261 realBox.bottom += clientStart.y;
6267 if(realBox.right >= realBox.left &&
6268 realBox.bottom >= realBox.top)
6270 // if(!rootWindow.fullRender)
6271 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6273 for(child = children.first; child; child = child.next)
6278 box.left -= child.absPosition.x - absPosition.x;
6279 box.top -= child.absPosition.y - absPosition.y;
6280 box.right -= child.absPosition.x - absPosition.x;
6281 box.bottom -= child.absPosition.y - absPosition.y;
6282 if(box.right >= child.box.left && box.left <= child.box.right &&
6283 box.bottom >= child.box.top && box.top <= child.box.bottom)
6285 box.left -= child.clientStart.x;
6286 box.top -= child.clientStart.y;
6287 box.right -= child.clientStart.x;
6288 box.bottom -= child.clientStart.y;
6294 realBox.left += absPosition.x - rootWindow.absPosition.x;
6295 realBox.top += absPosition.y - rootWindow.absPosition.y;
6296 realBox.right += absPosition.x - rootWindow.absPosition.x;
6297 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6298 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6301 else if(this == guiApp.desktop)
6304 for(window = children.first; window; window = window.next)
6310 Box childBox = region;
6312 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6313 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6314 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6315 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6317 window.Update(childBox);
6320 window.Update(null);
6325 // rootWindow.mutex.Release();
6332 if(guiApp.windowCaptured != this)
6334 if(guiApp.windowCaptured)
6338 //Logf("Captured %s (%s)\n", caption, class.name);
6339 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6340 guiApp.windowCaptured = this;
6346 bool Destroy(int code)
6351 if(!destroyed && !CloseConfirmation(false)) return false;
6355 // TOCHECK: Should autoCreate be set to false here?
6366 void Move(int x, int y, int w, int h)
6368 normalAnchor = Anchor { left = x, top = y };
6369 normalSizeAnchor = SizeAnchor { size = { w, h } };
6371 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6373 if(destroyed) return;
6375 stateAnchor = normalAnchor;
6376 stateSizeAnchor = normalSizeAnchor;
6378 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6379 Position(x,y, w, h, true, true, true, true, false, true);
6383 DialogResult Modal(void)
6389 // FIXES MEMORY LEAK IF Create() FAILED
6395 void SetScrollArea(int width, int height, bool snapToStep)
6397 bool resize = false;
6400 int stepX = sbStep.x, stepY = sbStep.y;
6401 // Needed to make snapped down position match the skin's check of client area
6402 // against realvirtual
6405 SNAPDOWN(stepX, textCellW);
6406 SNAPDOWN(stepY, textCellH);
6407 stepX = Max(stepX, textCellW);
6408 stepY = Max(stepY, textCellH);
6410 if(scrollFlags.snapX)
6411 SNAPUP(width, stepX);
6412 if(scrollFlags.snapY)
6413 SNAPUP(height, stepY);
6416 reqScrollArea.w = width;
6417 reqScrollArea.h = height;
6418 noAutoScrollArea = (width > 0 || height > 0);
6420 UpdateScrollBars(true, true);
6423 void SetScrollPosition(int x, int y)
6426 sbh.Action(setPosition, x, 0);
6430 int seen = clientSize.w, total = reqScrollArea.w;
6432 if(scrollFlags.snapX)
6433 SNAPDOWN(seen, sbStep.x);
6435 if(!total) total = seen;
6436 range = total - seen + 1;
6437 range = Max(range, 1);
6439 if(x >= range) x = range - 1;
6441 if(scrollFlags.snapX)
6442 SNAPUP(x, sbStep.x);
6445 OnHScroll(setPosition, x, 0);
6449 SNAPDOWN(x, textCellW);
6455 sbv.Action(setPosition, y, 0);
6459 int seen = clientSize.h, total = reqScrollArea.h;
6462 if(scrollFlags.snapY)
6463 SNAPDOWN(seen, sbStep.y);
6465 if(!total) total = seen;
6466 range = total - seen + 1;
6467 range = Max(range, 1);
6469 if(y >= range) y = range - 1;
6471 if(scrollFlags.snapY)
6472 SNAPUP(y, sbStep.y);
6475 OnVScroll(setPosition, y, 0);
6478 SNAPDOWN(y, textCellH);
6483 UpdateCaret(false, false);
6486 void SetScrollLineStep(int stepX, int stepY)
6492 SNAPDOWN(stepX, textCellW);
6493 SNAPDOWN(stepY, textCellH);
6494 stepX = Max(stepX, textCellW);
6495 stepY = Max(stepY, textCellH);
6498 sbh.lineStep = stepX;
6500 sbv.lineStep = stepY;
6503 void SetState(WindowState newState, bool activate, Modifiers mods)
6507 if(state == newState || OnStateChange(newState, mods))
6509 WindowState prevState = state;
6513 // This used to be at the end of the brackets... moved for X, testing...
6514 // This has the effect of activating the window through the system...
6515 if(rootWindow == this)
6516 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6518 SetStateEx(newState, activate);
6520 if(rootWindow == this && !rootWindow.nativeDecorations)
6522 int x = position.x, y = position.y;
6525 x -= guiApp.desktop.absPosition.x;
6526 y -= guiApp.desktop.absPosition.y;
6528 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6532 //state = prevState;
6534 if(state != maximized && style.hasMaximize)
6537 for(child = parent.children.first; child; child = child.next)
6539 if(child != this && child.state == maximized)
6540 child.SetStateEx(normal, false);
6544 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6545 parent.UpdateScrollBars(true, true);
6548 // Do we really need this stuff here?
6549 // Shouldn't the Activate stuff take care of it?
6550 if(parent.rootWindow == parent && style)
6553 parent.FigureCaption(caption);
6554 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6555 parent.UpdateDecorations();
6559 rootWindow.ConsequentialMouseMove(false);
6566 BitmapResource GetIcon(SkinBitmap iconID)
6568 return guiApp.currentSkin.GetBitmap(iconID);
6571 void SetMouseRange(Box range)
6573 if(range || guiApp.fullScreenMode)
6578 clip.left = range.left + absPosition.x + clientStart.x;
6579 clip.top = range.top + absPosition.y + clientStart.y;
6580 clip.right = range.right + absPosition.x + clientStart.x;
6581 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6585 clip.left = guiApp.desktop.box.left;
6586 clip.top = guiApp.desktop.box.top;
6587 clip.right = guiApp.desktop.box.right;
6588 clip.bottom = guiApp.desktop.box.bottom;
6590 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6593 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6596 void SetMouseRangeToClient(void)
6598 if(guiApp.fullScreenMode || this != guiApp.desktop)
6600 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6601 box.Clip(clientArea);
6605 SetMouseRange(null);
6608 void SetMouseRangeToWindow(void)
6610 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6611 if(this == guiApp.desktop)
6612 SetMouseRangeToClient();
6617 // x, y: Desktop Coordinates
6618 void ShowSysMenu(int x, int y)
6621 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6624 menu, $"Restore", r, NotifySelect = MenuWindowRestore,
6625 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6629 menu, $"Move", m, NotifySelect = MenuWindowMove,
6630 disabled = !style.fixed || state == maximized
6634 menu, $"Size", s, NotifySelect = MenuWindowSize,
6635 disabled = !style.sizable || state != normal
6639 menu, $"Minimize", n, NotifySelect = MenuWindowMinimize,
6640 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6644 menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6645 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6649 menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6650 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6652 MenuDivider { menu };
6655 menu, $"Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6656 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6658 windowMenu.Create();
6663 ActivateEx(true, true, true, true, null, null);
6666 void MakeActive(void)
6668 ActivateEx(true, false, true, false, null, null);
6671 void SoftActivate(void)
6673 if(guiApp.desktop.active)
6679 void Deactivate(void)
6681 ActivateEx(false, true, true, true, null, null);
6686 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
6689 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
6691 bool result = false;
6692 if(activeChild && activeChild.cycle)
6694 Window modalWindow, child = activeChild;
6695 if(!clientOnly /*&& parent.tabCycle*/)
6697 Window next = child;
6700 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
6704 if(parent && parent.CycleChildren(backward, false, true, true))
6712 next = next.cycle.prev.data;
6714 next = next.cycle.next.data;
6715 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
6720 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
6721 parent.tabCycle && parent.CycleChildren(backward, false, false))
6725 if(tabCycleOnly && !tabCycle) return false;
6732 child = child.cycle.prev.data;
6734 child = child.cycle.next.data;
6735 if(child == child.parent.activeChild)
6737 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
6740 modalWindow = child.FindModal();
6743 // Scroll the window to include the active control
6744 if(sbh && !child.style.dontScrollHorz)
6746 if(child.scrolledPos.x < 0)
6747 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
6748 else if(child.scrolledPos.x + child.size.w > clientSize.w)
6749 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
6751 if(sbv && !child.style.dontScrollVert)
6753 if(child.scrolledPos.y < 0)
6754 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
6755 else if(child.scrolledPos.y + child.size.h > clientSize.h)
6756 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
6760 child = modalWindow ? modalWindow : child;
6761 child.ActivateEx(true, true, true, true, null, null);
6762 if(child.tabCycle && child.childrenCycle.first)
6763 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
6771 ConsequentialMouseMove(false);
6775 void AddResource(Resource resource)
6779 ResPtr ptr { resource = resource };
6783 // Load Graphics here if window is created already
6784 if(/*created && */display)
6786 display.Lock(false);
6787 ptr.loaded = display.displaySystem.LoadResource(resource);
6791 // Temporary hack to load font right away for listbox in dropbox ...
6792 else if(master && master.display)
6794 master.display.Lock(false);
6795 master.display.displaySystem.LoadResource(resource);
6796 master.display.Unlock();
6802 void RemoveResource(Resource resource)
6807 for(ptr = resources.first; ptr; ptr = ptr.next)
6809 if(ptr.resource == resource)
6815 // Unload Graphics here if window is created already
6816 if(/*created && */display)
6820 display.Lock(false);
6821 display.displaySystem.UnloadResource(resource, ptr.loaded);
6827 resources.Delete(ptr);
6832 void SetCaret(int x, int y, int size)
6839 if(active && !style.interim)
6841 if(visible || !guiApp.caretOwner)
6842 guiApp.caretOwner = size ? this : null;
6844 UpdateCaret(false, false);
6847 guiApp.interfaceDriver.SetCaret(0,0,0);
6848 UpdateCaret(false, true);
6849 guiApp.caretEnabled = false;
6852 else if(style.inactive && active)
6854 guiApp.interfaceDriver.SetCaret(0,0,0);
6855 UpdateCaret(false, true);
6856 guiApp.caretEnabled = false;
6861 void Scroll(int x, int y)
6863 bool opaque = !style.drawBehind || background.a;
6864 if(opaque && display && display.flags.scrolling)
6866 Box box = clientArea;
6867 box.left += clientStart.x;
6868 box.top += clientStart.y;
6869 box.right += clientStart.x;
6870 box.bottom += clientStart.y;
6872 //scrollExtent.Free(null);
6873 scrollExtent.AddBox(box);
6874 scrolledArea.x += x;
6875 scrolledArea.y += y;
6877 //scrollExtent.Free();
6878 //scrollExtent.AddBox(clientArea);
6879 //scrollExtent.Offset(clientStart.x, clientStart.y);
6880 //scrolledArea.x = x;
6881 //scrolledArea.y = y;
6887 rootWindow.dirty = true;
6890 void ReleaseCapture()
6892 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
6894 Window oldCaptured = guiApp.windowCaptured;
6895 guiApp.windowCaptured = null;
6896 guiApp.prevWindow = null;
6899 //guiApp.Log("Released Capture\n");
6901 guiApp.interfaceDriver.SetMouseCapture(null);
6903 //oldCaptured.OnMouseCaptureLost();
6906 oldCaptured.ConsequentialMouseMove(false);
6911 void SetText(char * format, ...)
6918 char caption[MAX_F_STRING];
6920 va_start(args, format);
6921 vsprintf(caption, format, args);
6924 this.caption = new char[strlen(caption)+1];
6926 strcpy(this.caption, caption);
6935 bool Grab(Bitmap bitmap, Box box, bool decorations)
6937 bool result = false;
6938 if(display || this == guiApp.desktop)
6940 Box clip = {MININT, MININT, MAXINT, MAXINT};
6946 clip.Clip(clientArea);
6948 clip.Clip(this.box);
6950 if(rootWindow != this)
6952 clip.left += absPosition.y;
6953 clip.top += absPosition.y;
6954 clip.right += absPosition.x;
6955 clip.bottom += absPosition.y;
6958 clip.left += decorations ? 0 : clientStart.x;
6959 clip.top += decorations ? 0 : clientStart.y;
6960 clip.right += decorations ? 0 : clientStart.x;
6961 clip.bottom += decorations ? 0 : clientStart.y;
6963 if(display && display.flags.flipping)
6965 rootWindow.Update(null);
6966 rootWindow.UpdateDisplay();
6973 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
6974 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6978 result = display.Grab(bitmap, clip.left, clip.top,
6979 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6981 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
6983 if(!bitmap.Convert(null, pixelFormat888, null))
6990 void GetMousePosition(int * x, int * y)
6992 int mouseX = 0, mouseY = 0;
6993 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
6996 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
6997 if(this != guiApp.desktop)
6999 mouseX -= absPosition.x + clientStart.x;
7000 mouseY -= absPosition.y + clientStart.y;
7007 DialogResult DoModal()
7009 DialogResult returnCode = 0;
7010 int terminated = terminateX;
7013 while(!destroyed && guiApp.driver != null)
7015 if(terminateX != terminated)
7017 terminated = terminateX;
7018 guiApp.desktop.Destroy(0);
7019 if(guiApp.desktop.created)
7022 //printf("Resetting terminate X to 0\n");
7028 guiApp.UpdateDisplay();
7029 if(!guiApp.ProcessInput(false))
7032 returnCode = this.returnCode;
7045 return !destroyed && guiApp.driver != null && terminateX < 2;
7048 DialogResult DoModalEnd()
7050 DialogResult returnCode = this.returnCode;
7055 // --- Window manipulation ---
7056 /*bool GetDisabled()
7058 bool disabled = this.disabled;
7060 for(window = this; (window = window.master); )
7071 // --- Mouse Manipulation ---
7072 void GetNCMousePosition(int * x, int * y)
7074 GetMousePosition(x, y);
7075 if(x) *x += clientStart.x;
7076 if(y) *y += clientStart.y;
7079 // --- Carets manipulation ---
7080 void GetCaretPosition(Point caretPos)
7082 caretPos = this.caretPos;
7085 int GetCaretSize(void)
7090 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7096 bool CloseConfirmation(bool parentClosing)
7109 if(!OnClose(parentClosing))
7112 // If you want to skip this, simply set modifiedDocument to false in OnClose
7113 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7115 DialogResult dialogRes;
7118 sprintf(message, $"Save changes to %s?", fileName);
7120 sprintf(message, $"Save changes to Untitled %d?", documentID);
7122 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = message }.Modal();
7124 if(dialogRes == yes)
7126 // TOFIX: Precomp error if brackets are taken out
7127 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7129 else if(dialogRes == cancel)
7135 for(slave = slaves.first; slave; slave = slave.next)
7137 Window w = slave.data;
7138 if((w.parent == this || !w.IsDescendantOf(this)) && !w.CloseConfirmation(true))
7140 // ((Window)slave.data).CloseConfirmation(true);
7149 for(child = children.first; child; child = child.next)
7150 if(child.master != this && !child.CloseConfirmation(true))
7160 // Static methods... move them somewhere else?
7161 void ::RestoreCaret()
7163 if(guiApp.caretOwner)
7164 guiApp.caretOwner.UpdateCaret(false, false);
7167 void ::FreeMouseRange()
7169 guiApp.interfaceDriver.SetMouseRange(null, null);
7173 bool MenuFileClose(MenuItem selection, Modifiers mods)
7175 Window document = activeChild;
7177 document.Destroy(0);
7181 bool MenuFileExit(MenuItem selection, Modifiers mods)
7187 bool MenuFileSave(MenuItem selection, Modifiers mods)
7191 fileMonitor.fileName = null;
7194 if(OnSaveFile(fileName))
7196 //if(OnFileModified != Window::OnFileModified)
7199 fileMonitor.fileName = fileName;
7205 MessageBox dialog { master = master, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7206 DialogResult answer = dialog.Modal();
7208 if(answer != yes) return (bool)answer;
7211 return MenuFileSaveAs(selection, mods);
7214 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7216 DialogResult result = (DialogResult)bool::true;
7217 FileDialog fileDialog = saveDialog;
7220 fileDialog = FileDialog {};
7225 fileDialog.filePath = fileName;
7228 char filePath[MAX_FILENAME];
7229 sprintf(filePath, "Untitled %d", documentID);
7230 fileDialog.filePath = filePath;
7232 fileMonitor.fileName = null;
7234 fileDialog.type = save;
7235 fileDialog.text = $"Save As";
7239 fileDialog.master = master.parent ? master : this;
7240 if(fileDialog.Modal() == ok)
7242 char * filePath = fileDialog.filePath;
7244 if(OnSaveFile(filePath))
7247 property::fileName = filePath;
7248 NotifySaved(master, this, filePath);
7253 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7254 DialogResult answer = dialog.Modal();
7269 //if(OnFileModified != Window::OnFileModified && fileName)
7272 fileMonitor.fileName = fileName;
7276 return (bool)result; // Actually returning result from Yes/NoCancel message box
7279 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7281 Window document = activeChild;
7283 for(document = children.first; document; document = next)
7285 next = document.next;
7286 if(document.style.isDocument || document.fileName)
7287 document.MenuFileSave(selection, mods);
7292 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7296 for(document = children.first; document; document = document.next)
7297 //if(document.style.isDocument && document.state == minimized)
7298 if(document.style.isActiveClient && document.state == minimized)
7299 document.SetState(minimized, false, mods);
7303 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7305 Window document = activeChild;
7308 Window firstDocument = null;
7310 OldLink cycle = document.cycle.prev;
7315 if(child.style.isActiveClient && !child.style.hidden)
7319 firstDocument = child;
7320 if(child.state == minimized)
7321 child.SetState(minimized, false, mods);
7324 child.positionID = id++;
7325 child.SetState(normal, false, mods);
7326 child.anchor.left.type = cascade;
7329 child.normalSizeAnchor = *&child.sizeAnchor;
7330 child.normalAnchor = child.anchor;
7332 // Break the anchors for moveable/resizable windows
7333 if(child.style.fixed)
7335 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7337 (*&child.normalAnchor).left = x;
7338 (*&child.normalAnchor).top = y;
7339 (*&child.normalAnchor).right.type = none;
7340 (*&child.normalAnchor).bottom.type = none;
7342 child.normalSizeAnchor.isClientW = false;
7343 child.normalSizeAnchor.isClientH = false;
7344 child.normalSizeAnchor.size.w = w;
7345 child.normalSizeAnchor.size.h = h;
7346 child.anchored = false;
7349 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7351 child.stateAnchor = child.normalAnchor;
7352 child.stateSizeAnchor = child.normalSizeAnchor;
7354 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7355 child.Position(x, y, w, h, true, true, true, true, false, false);
7360 last = children.last;
7361 if(!child.style.stayOnTop)
7362 for(; last && last.style.stayOnTop; last = last.prev);
7363 children.Move(child, last);
7364 childrenOrder.Move(child.order, childrenOrder.last);
7366 if(cycle == document.cycle) break;
7370 firstDocument.Activate();
7375 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7382 // Close all closes all active clients, not all documents
7383 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7385 Window next, document;
7387 for(document = children.first; document; document = next)
7389 for(next = document.next; next && !(next.style.isActiveClient; next = next.next);
7390 if(document.style.isActiveClient)
7391 if(!document.Destroy(0) && !document.style.hidden)
7397 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7399 if(style.hasMaximize && state != maximized)
7400 SetState(maximized, 0, 0);
7404 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7406 if(style.hasMinimize && state != minimized)
7408 SetState(minimized, 0, 0);
7409 parent.CycleChildren(false, true, false, true);
7414 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7416 MenuMoveOrSize(false, selection ? true : false);
7420 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7422 CycleChildren(false, true, false, true);
7426 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7428 CycleChildren(true, true, false, true);
7432 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7434 MenuMoveOrSize(true, true);
7438 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7441 SetState(normal, 0, 0);
7445 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7448 int id = selection.id;
7449 OldLink cycle = activeClient.cycle;
7451 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7454 Window sibling = cycle.data;
7455 if(sibling.style.isActiveClient && sibling.visible && !sibling.style.nonClient)
7463 document = cycle.data;
7464 document.Activate();
7466 //if(activeChild.state == maximized)
7467 // document.SetState(maximized, false, mods);
7468 //else if(document.state == minimized)
7469 // document.SetState(normal, false, mods);
7473 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7475 stayOnTop = !style.stayOnTop;
7479 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7481 Window document = activeChild;
7484 Window firstDocument = null;
7485 OldLink cycle = document.cycle;
7489 Window child = cycle.data;
7490 if(child.style.isActiveClient && !child.style.hidden)
7492 if(!firstDocument) firstDocument = child;
7493 if(child.state == minimized)
7494 child.SetState(minimized, false, mods);
7497 child.positionID = id++;
7498 child.SetState(normal, false, mods);
7499 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7501 child.anchor.left.type = hTiled;
7504 child.normalSizeAnchor = *&child.sizeAnchor;
7505 child.normalAnchor = child.anchor;
7507 // Break the anchors for moveable/resizable windows
7508 if(child.style.fixed)
7510 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7512 (*&child.normalAnchor).left = x;
7513 (*&child.normalAnchor).top = y;
7514 (*&child.normalAnchor).right.type = none;
7515 (*&child.normalAnchor).bottom.type = none;
7516 child.normalSizeAnchor.isClientW = false;
7517 child.normalSizeAnchor.isClientH = false;
7518 child.normalSizeAnchor.size.w = w;
7519 child.normalSizeAnchor.size.h = h;
7520 child.anchored = false;
7523 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7525 child.stateAnchor = child.normalAnchor;
7526 child.stateSizeAnchor = child.normalSizeAnchor;
7528 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7529 child.Position(x,y, w, h, true, true, true, true, false, true);
7534 if((cycle = cycle.next) == document.cycle) break;
7537 firstDocument.Activate();
7542 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7544 Window document = activeChild;
7547 Window firstDocument = null;
7549 OldLink cycle = document.cycle;
7554 //if(child.style.isDocument)
7555 if(child.style.isActiveClient && !child.style.hidden)
7557 if(!firstDocument) firstDocument = child;
7558 if(child.state == minimized)
7559 child.SetState(minimized, false, mods);
7562 child.positionID = id++;
7563 child.SetState(normal, false, mods);
7564 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7566 child.anchor.left.type = vTiled;
7569 child.normalSizeAnchor = *&child.sizeAnchor;
7570 child.normalAnchor = child.anchor;
7572 // Break the anchors for moveable/resizable windows
7573 if(child.style.fixed)
7575 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7577 (*&child.normalAnchor).left = x;
7578 (*&child.normalAnchor).top = y;
7579 (*&child.normalAnchor).right.type = none;
7580 (*&child.normalAnchor).bottom.type = none;
7581 child.normalSizeAnchor.isClientW = false;
7582 child.normalSizeAnchor.isClientH = false;
7583 child.normalSizeAnchor.size.w = w;
7584 child.normalSizeAnchor.size.h = h;
7585 child.anchored = false;
7588 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7590 child.stateAnchor = child.normalAnchor;
7591 child.stateSizeAnchor = child.normalSizeAnchor;
7593 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7594 child.Position(x,y, w, h, true, true, true, true, false, true);
7599 if((cycle = cycle.next) == document.cycle) break;
7602 firstDocument.Activate();
7607 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7609 WindowList dialog { master = this };
7610 Window document = (Window)dialog.Modal();
7613 if(activeChild.state == maximized)
7614 document.SetState(maximized, false, mods);
7615 else if(document.state == minimized)
7616 document.SetState(normal, false, mods);
7617 document.Activate();
7623 virtual bool OnCreate(void);
7624 virtual void OnDestroy(void);
7625 virtual void OnDestroyed(void);
7626 virtual bool OnClose(bool parentClosing);
7627 virtual bool OnStateChange(WindowState state, Modifiers mods);
7628 virtual bool OnPostCreate(void);
7629 virtual bool OnMoving(int *x, int *y, int w, int h);
7630 virtual bool OnResizing(int *width, int *height);
7631 virtual void OnResize(int width, int height);
7632 virtual void OnPosition(int x, int y, int width, int height);
7633 virtual bool OnLoadGraphics(void);
7634 virtual void OnApplyGraphics(void);
7635 virtual void OnUnloadGraphics(void);
7636 virtual void OnRedraw(Surface surface);
7637 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7638 virtual void OnActivateClient(Window client, Window previous);
7639 virtual bool OnKeyDown(Key key, unichar ch);
7640 virtual bool OnKeyUp(Key key, unichar ch);
7641 virtual bool OnKeyHit(Key key, unichar ch);
7642 virtual bool OnSysKeyDown(Key key, unichar ch);
7643 virtual bool OnSysKeyUp(Key key, unichar ch);
7644 virtual bool OnSysKeyHit(Key key, unichar ch);
7645 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7646 virtual bool OnMouseLeave(Modifiers mods);
7647 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7648 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7649 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
7650 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
7651 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
7652 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
7653 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
7654 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
7655 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
7656 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
7657 virtual void OnMouseCaptureLost(void);
7658 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
7659 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
7660 virtual void OnDrawOverChildren(Surface surface);
7661 virtual bool OnFileModified(FileChange fileChange, char * param);
7662 virtual bool OnSaveFile(char * fileName);
7664 // Virtual Methods -- Children management (To support Stacker, for lack of built-in auto-layout)
7665 // Note: A 'client' would refer to isActiveClient, rather than
7666 // being confined to the 'client area' (nonClient == false)
7667 virtual void OnChildAddedOrRemoved(Window child, bool removed);
7668 virtual void OnChildVisibilityToggled(Window child, bool visible);
7669 virtual void OnChildResized(Window child, int x, int y, int w, int h);
7671 // Skins Virtual Functions
7672 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
7673 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
7674 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
7679 virtual void ShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7680 virtual void PreShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7681 virtual bool IsMouseMoving(int x, int y, int w, int h);
7682 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY);
7683 virtual void UpdateNonClient();
7684 virtual void SetBox(Box box);
7685 virtual bool IsInside(int x, int y)
7687 return box.IsPointInside({x, y});
7689 virtual bool IsOpaque()
7691 return (!style.drawBehind || background.a == 255);
7695 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
7696 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
7697 virtual void Window::NotifySaved(Window window, char * filePath);
7702 property Window parent
7704 property_category $"Layout"
7707 if(value || guiApp.desktop)
7710 Window oldParent = parent;
7711 Anchor anchor = this.anchor;
7713 if(value && value.IsDescendantOf(this)) return;
7714 if(value && value == this)
7716 if(!value) value = guiApp.desktop;
7718 if(value == oldParent) return;
7720 if(!master || (master == this.parent && master == guiApp.desktop))
7721 property::master = value;
7725 parent.children.Remove(this);
7726 parent.OnChildAddedOrRemoved(this, true);
7730 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7731 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
7732 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7733 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
7737 last = value.children.last;
7739 if(style.isDocument)
7742 parent.numDocuments--;
7743 documentID = value.GetDocumentID();
7746 if(style.isActiveClient && !style.hidden)
7748 if(parent && parent != guiApp.desktop && !(style.hidden))
7750 if(state == minimized) parent.numIcons--;
7751 parent.numPositions--;
7755 if(!style.stayOnTop)
7756 for(; last && last.style.stayOnTop; last = last.prev);
7758 value.children.Insert(last, this);
7760 // *** NEW HERE: ***
7762 parent.childrenCycle.Delete(cycle);
7764 parent.childrenOrder.Delete(order);
7772 int x = position.x, y = position.y, w = size.w, h = size.h;
7776 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
7777 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
7779 vpw = value.clientSize.w;
7780 vph = value.clientSize.h;
7786 else if(style.fixed)
7788 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
7789 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
7792 anchor = this.anchor;
7794 if(anchor.left.type == offset) anchor.left.distance = x;
7795 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
7796 if(anchor.top.type == offset) anchor.top.distance = y;
7797 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
7798 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
7799 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
7800 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
7801 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
7802 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
7803 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
7805 if(!anchor.left.type && !anchor.right.type)
7807 anchor.horz.distance = (x + w / 2) - (vpw / 2);
7808 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
7810 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
7811 if(!anchor.top.type && !anchor.bottom.type)
7813 anchor.vert.distance = (y + h / 2) - (vph / 2);
7814 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
7816 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
7819 parent.OnChildAddedOrRemoved(this, false);
7825 parent.childrenCycle.Insert(
7826 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
7827 cycle = OldLink { data = this });
7828 parent.childrenOrder.Insert(
7829 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
7830 order = OldLink { data = this });
7833 if(!style.hidden && style.isActiveClient)
7835 positionID = parent.GetPositionID(this);
7836 parent.numPositions++;
7837 if(state == minimized) parent.numIcons--;
7840 // *** FONT INHERITANCE ***
7841 if(!setFont && oldParent)
7842 stopwatching(oldParent, font);
7846 RemoveResource(systemFont);
7849 // TESTING WITH WATCHERS:
7850 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7851 // usedFont = setFont ? setFont : (systemFont);
7855 if(guiApp.currentSkin)
7857 systemFont = guiApp.currentSkin.SystemFont();
7860 usedFont = systemFont;
7861 AddResource(systemFont);
7869 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7878 if(value.rootWindow && value.rootWindow.display && rootWindow)
7880 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
7881 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
7884 UnloadGraphics(false);
7887 LoadGraphics(false, false);
7890 if(value.rootWindow != rootWindow)
7891 DisplayModeChanged();
7895 scrolledPos.x = MININT; // Prevent parent update
7896 property::anchor = anchor;
7900 if(guiApp.currentSkin)
7901 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
7903 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7904 Position(x, y, w, h, true, true, true, true, false, true);
7909 // else parent = value;
7912 get { return parent; }
7915 property Window master
7917 property_category $"Behavior"
7920 //if(this == value) return;
7921 if(value && value.IsSlaveOf(this)) return;
7927 OldLink slaveHolder;
7928 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
7929 if(slaveHolder.data == this)
7931 master.slaves.Delete(slaveHolder);
7938 value.slaves.Add(OldLink { data = this });
7943 master.hotKeys.Remove(hotKey);
7944 value.hotKeys.Add(hotKey);
7947 if(master && master.defaultControl == this)
7948 master.defaultControl = null;
7950 if(style.isDefault && !value.defaultControl)
7951 value.defaultControl = this;
7956 get { return master ? master : parent; }
7959 property char * caption
7961 property_category $"Appearance"
7968 caption = new char[strlen(value)+1];
7970 strcpy(caption, value);
7975 get { return caption; }
7980 property_category $"Behavior"
7989 master.hotKeys.Add(hotKey = HotKeySlot { });
7993 hotKey.window = this;
7998 master.hotKeys.Delete(hotKey);
8003 get { return hotKey ? hotKey.key : 0; }
8006 property Color background
8008 property_category $"Appearance"
8011 background.color = value;
8016 if(this == rootWindow)
8017 guiApp.interfaceDriver.SetRootWindowColor(this);
8020 get { return background.color; }
8023 property Percentage opacity
8025 property_category $"Appearance"
8028 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
8029 drawBehind = background.a ? false : true;
8031 get { return background.a / 255.0f; }
8034 property Color foreground
8036 property_category $"Appearance"
8044 get { return foreground; }
8047 property BorderStyle borderStyle
8049 property_category $"Appearance"
8052 if(!((BorderBits)value).fixed)
8054 style.hasClose = false;
8055 style.hasMaximize = false;
8056 style.hasMinimize = false;
8057 nativeDecorations = false;
8059 style.borderBits = value;
8063 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8065 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8066 Position(x, y, w, h, true, true, true, true, false, true);
8067 CreateSystemChildren();
8070 get { return (BorderStyle)style.borderBits; }
8073 property Size minClientSize
8075 property_category $"Layout"
8076 set { minSize = value; }
8077 get { value = minSize; }
8080 property Size maxClientSize
8082 property_category $"Layout"
8083 set { maxSize = value; }
8084 get { value = maxSize; }
8087 property bool hasMaximize
8089 property_category $"Window Style"
8092 style.hasMaximize = value;
8093 if(value) { style.fixed = true; style.contour = true; }
8097 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8099 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8100 Position(x, y, w, h, true, true, true, true, false, true);
8102 CreateSystemChildren();
8105 get { return style.hasMaximize; }
8108 property bool hasMinimize
8110 property_category $"Window Style"
8113 style.hasMinimize = value;
8114 if(value) { style.fixed = true; style.contour = true; }
8118 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8120 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8121 Position(x, y, w, h, true, true, true, true, false, true);
8123 CreateSystemChildren();
8126 get { return style.hasMinimize; }
8129 property bool hasClose
8131 property_category $"Window Style"
8134 style.hasClose = value;
8135 if(value) { style.fixed = true; style.contour = true; }
8139 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8140 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8141 Position(x, y, w, h, true, true, true, true, false, true);
8142 CreateSystemChildren();
8145 get { return style.hasClose; }
8148 property bool nonClient
8150 property_category $"Layout"
8153 style.nonClient = value;
8155 style.stayOnTop = true;
8157 get { return style.nonClient; }
8160 property bool inactive
8162 property_category $"Behavior"
8167 // *** NEW HERE: ***
8171 parent.childrenCycle.Delete(cycle);
8173 parent.childrenOrder.Delete(order);
8180 active = false; // true;
8181 if(parent.activeChild == this)
8182 parent.activeChild = null;
8183 if(parent.activeClient == this)
8184 parent.activeClient = null;
8193 parent.childrenCycle.Insert(
8194 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8195 cycle = OldLink { data = this });
8197 parent.childrenOrder.Insert(
8198 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8199 order = OldLink { data = this });
8202 style.inactive = value;
8204 get { return style.inactive; }
8207 property bool clickThrough
8209 property_category $"Behavior"
8210 set { style.clickThrough = value; }
8211 get { return style.clickThrough; }
8214 property bool isRemote
8216 property_category $"Behavior"
8217 set { style.isRemote = value; }
8218 get { return style.isRemote; }
8221 property bool noCycle
8223 property_category $"Behavior"
8224 set { style.noCycle = value; }
8225 get { return style.noCycle; }
8228 property bool isModal
8230 property_category $"Behavior"
8231 set { style.modal = value; }
8232 get { return style.modal; }
8235 property bool interim
8237 property_category $"Behavior"
8238 set { style.interim = value; }
8239 get { return style.interim; }
8242 property bool tabCycle
8244 property_category $"Behavior"
8245 set { style.tabCycle = value; }
8246 get { return style.tabCycle; }
8249 property bool isDefault
8251 property_category $"Behavior"
8259 /*for(sibling = parent.children.first; sibling; sibling = sibling.next)
8260 if(sibling != this && sibling.style.isDefault)
8261 sibling.style.isDefault = false;*/
8262 if(master.defaultControl)
8263 master.defaultControl.style.isDefault = false;
8264 master.defaultControl = this;
8266 else if(master.defaultControl == this)
8267 master.defaultControl = null;
8271 style.isDefault = value;
8273 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8275 get { return style.isDefault; }
8278 property bool drawBehind
8280 property_category $"Window Style"
8281 set { style.drawBehind = value; }
8282 get { return style.drawBehind; }
8285 property bool hasMenuBar
8287 property_category $"Window Style"
8297 if(created && !menuBar)
8304 anchor = Anchor { top = 23, left = 1, right = 1 },
8306 inactive = true, nonClient = true
8311 else if(created && menuBar)
8316 style.hasMenuBar = value;
8318 get { return style.hasMenuBar; }
8321 property bool hasStatusBar
8323 property_category $"Window Style"
8330 statusBar = StatusBar { this };
8338 style.hasStatusBar = value;
8340 get { return style.hasStatusBar; }
8342 property bool stayOnTop
8344 property_category $"Window Style"
8349 if(created && !style.stayOnTop)
8351 if(rootWindow == this)
8352 guiApp.interfaceDriver.OrderRootWindow(this, true);
8353 else if(parent.children.last != this)
8355 parent.children.Move(this, parent.children.last);
8359 style.stayOnTop = true;
8363 if(created && style.stayOnTop)
8365 if(rootWindow == this)
8366 guiApp.interfaceDriver.OrderRootWindow(this, false);
8373 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8374 order && ((Window)order.data).style.stayOnTop;
8375 order = (order == parent.childrenOrder.first) ? null : order.prev);
8376 last = order ? order.data : null;
8380 for(last = parent.children.last;
8381 last && last.style.stayOnTop;
8385 parent.children.Move(this, last);
8389 style.stayOnTop = false;
8392 get { return style.stayOnTop; }
8397 property_category $"Window Style"
8407 if(menuBar && !value)
8414 if(!menuBar && style.hasMenuBar && value)
8418 this, menu = value, isMenuBar = true,
8419 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8420 inactive = true, nonClient = true
8424 UpdateActiveDocument(null);
8427 get { return menu; }
8430 property FontResource font
8432 property_category $"Appearance"
8434 isset { return setFont ? true : false; }
8439 if(value && !setFont) { stopwatching(parent, font); }
8440 else if(!value && setFont)
8446 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8455 RemoveResource(setFont);
8460 RemoveResource(systemFont);
8467 AddResource(setFont);
8470 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8473 systemFont = guiApp.currentSkin.SystemFont();
8475 usedFont = systemFont;
8476 AddResource(systemFont);
8484 get { return usedFont; }
8487 property SizeAnchor sizeAnchor
8489 property_category $"Layout"
8492 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8493 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8494 sizeAnchor.isClientW != sizeAnchor.isClientH;
8501 normalSizeAnchor = sizeAnchor;
8503 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8505 stateAnchor = normalAnchor;
8506 stateSizeAnchor = normalSizeAnchor;
8508 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8509 Position(x,y, w, h, true, true, true, true, false, true);
8516 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8517 sizeAnchor.isClientW,
8518 sizeAnchor.isClientH
8525 property_category $"Layout"
8528 Anchor thisAnchor = anchor;
8529 SizeAnchor thisSizeAnchor = sizeAnchor;
8530 bool leftRight = (anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none);
8531 bool topBottom = (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none);
8532 bool isClient = !sizeAnchor.isClientW && !sizeAnchor.isClientH;
8533 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8534 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8535 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8541 sizeAnchor.isClientW = false;
8542 sizeAnchor.isClientH = false;
8543 sizeAnchor.size = value;
8545 normalSizeAnchor = sizeAnchor;
8547 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8549 stateAnchor = normalAnchor;
8550 stateSizeAnchor = normalSizeAnchor;
8552 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8553 Position(x, y, w, h, true, true, true, true, false, true);
8554 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
8557 get { value = size; }
8560 property Size clientSize
8562 property_category $"Layout"
8565 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8566 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8567 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8572 sizeAnchor.isClientW = true;
8573 sizeAnchor.isClientH = true;
8574 sizeAnchor.size = value;
8576 normalSizeAnchor = sizeAnchor;
8578 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8580 stateAnchor = normalAnchor;
8581 stateSizeAnchor = normalSizeAnchor;
8583 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8584 Position(x,y, w, h, true, true, true, true, false, true);
8587 get { value = clientSize; }
8590 property Size initSize { get { value = sizeAnchor.size; } };
8592 property Anchor anchor
8594 property_category $"Layout"
8595 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8601 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8603 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8604 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8606 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8608 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8609 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8613 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8615 anchor.left.distance = 0;
8616 anchor.horz.type = 0;
8618 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8620 anchor.top.distance = 0;
8621 anchor.vert.type = 0;
8630 normalAnchor = anchor;
8632 // Break the anchors for moveable/resizable windows
8633 /*if(style.fixed ) //&& value.left.type == cascade)
8635 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
8637 this.anchor = normalAnchor = Anchor { left = x, top = y };
8638 normalSizeAnchor = SizeAnchor { { w, h } };
8641 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8643 stateAnchor = normalAnchor;
8644 stateSizeAnchor = normalSizeAnchor;
8646 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8647 Position(x, y, w, h, true, true, true, true, false, true);
8656 get { value = this ? anchor : Anchor { }; }
8659 property Point position
8661 property_category $"Layout"
8664 if(value == null) return;
8666 anchor.left = value.x;
8667 anchor.top = value.y;
8668 anchor.right.type = none;
8669 anchor.bottom.type = none;
8674 normalAnchor = anchor;
8676 // Break the anchors for moveable/resizable windows
8680 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8682 normalAnchor.left = x;
8683 normalAnchor.top = y;
8684 normalAnchor.right.type = none;
8685 normalAnchor.bottom.type = none;
8686 normalSizeAnchor.size.width = w;
8687 normalSizeAnchor.size.height = h;
8691 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8693 stateAnchor = normalAnchor;
8694 stateSizeAnchor = normalSizeAnchor;
8696 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8697 Position(x,y, w, h, true, true, true, true, false, true);
8701 get { value = position; }
8704 property bool disabled
8706 property_category $"Behavior"
8709 if(this && disabled != value)
8716 get { return (bool)disabled; }
8719 property bool isEnabled
8724 for(parent = this; parent; parent = parent.parent)
8731 property WindowState state
8733 property_category $"Behavior"
8734 set { SetState(value, false, 0); }
8735 get { return this ? state : 0; }
8738 property bool visible
8740 property_category $"Behavior"
8743 if(this && !value && !style.hidden && parent)
8745 bool wasActiveChild = parent.activeChild == this;
8746 Window client = null;
8748 style.hidden = true;
8749 if(style.isActiveClient)
8751 parent.numPositions--;
8752 if(state == minimized) parent.numIcons--;
8757 OldLink prevOrder = null;
8759 if(rootWindow == this)
8760 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
8763 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
8766 box.left -= parent.clientStart.x;
8767 box.top -= parent.clientStart.y;
8768 box.right -= parent.clientStart.x;
8769 box.bottom -= parent.clientStart.y;
8773 if(_isModal && master && master.modalSlave == this)
8774 master.modalSlave = null;
8778 OldLink tmpPrev = order.prev;
8779 client = tmpPrev ? tmpPrev.data : null;
8780 if(client && !client.style.hidden && !client.destroyed && client.created)
8781 prevOrder = tmpPrev;
8784 client = tmpPrev ? tmpPrev.data : null;
8785 if(client == this) { client = null; break; }
8786 if(client && ((client.style.hidden) || client.destroyed || !client.created))
8788 tmpPrev = client.order.prev;
8793 prevOrder = tmpPrev;
8798 // If this window can be an active client, make sure the next window we activate can also be one
8799 if(!style.nonClient && style.isActiveClient)
8801 tmpPrev = prevOrder;
8804 client = tmpPrev ? tmpPrev.data : null;
8805 if(client == this) { client = null; break; }
8806 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
8808 tmpPrev = client.order.prev;
8813 prevOrder = tmpPrev;
8817 if(client && client.style.hidden) client = null;
8821 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
8823 if(order && prevOrder && prevOrder.data != this)
8824 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
8826 ActivateEx(false, false, false, true, null, null);
8828 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
8829 if(parent.activeClient == this)
8831 parent.activeClient = null;
8832 parent.UpdateActiveDocument(null);
8835 else if(parent.activeClient == this)
8837 parent.activeClient = client;
8838 parent.UpdateActiveDocument(this);
8841 // *** Not doing this anymore ***
8844 parent.childrenCycle.Delete(cycle);
8846 parent.childrenOrder.Delete(order);
8851 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8856 else if(this && value && style.hidden)
8858 style.hidden = false;
8861 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8862 if(rootWindow == this)
8863 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
8865 if(_isModal && master)
8866 master.modalSlave = this;
8868 if(style.isActiveClient)
8870 positionID = parent.GetPositionID(this);
8871 parent.numPositions++;
8872 if(state == minimized) parent.numIcons++;
8875 // *** NOT DOING THIS ANYMORE ***
8877 if(!(style.inactive))
8879 if(!(style.noCycle))
8881 cycle = parent.childrenCycle.AddAfter(
8882 (parent.activeChild && parent.activeChild.cycle) ?
8883 parent.activeChild.cycle.prev : null, sizeof(OldLink));
8886 order = parent.childrenOrder.AddAfter(
8887 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8894 if(true || !parent.activeChild)
8895 ActivateEx(true, false, true, true, null, null);
8897 if(creationActivation == activate)
8898 ActivateEx(true, false, true, true, null, null);
8899 else if(creationActivation == flash && !object)
8902 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8906 ConsequentialMouseMove(false);
8912 style.hidden = !value;
8915 get { return (style.hidden || !setVisible) ? false : true; }
8918 property bool isDocument
8920 property_category $"Document"
8921 set { style.isDocument = value; }
8922 get { return style.isDocument; }
8925 property bool mergeMenus
8927 property_category $"Window Style"
8928 set { mergeMenus = value; }
8929 get { return (bool)mergeMenus; }
8932 property bool hasHorzScroll
8934 property_category $"Window Style"
8939 if(!style.hasHorzScroll && created)
8941 CreateSystemChildren();
8942 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8945 else if(style.hasHorzScroll)
8949 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8951 style.hasHorzScroll = value;
8954 get { return style.hasHorzScroll; }
8957 property bool hasVertScroll
8959 property_category $"Window Style"
8964 if(!style.hasVertScroll && created)
8966 style.hasVertScroll = true;
8967 CreateSystemChildren();
8968 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8971 else if(style.hasVertScroll)
8975 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8977 style.hasVertScroll = value;
8979 get { return style.hasVertScroll; }
8982 property bool dontHideScroll
8984 property_category $"Behavior"
8987 scrollFlags.dontHide = value;
8990 //UpdateScrollBars(true, true);
8991 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8995 // UpdateScrollBars(true, true);
8996 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8999 get { return scrollFlags.dontHide; }
9002 property bool dontScrollVert
9004 property_category $"Behavior"
9005 set { style.dontScrollVert = value; }
9006 get { return style.dontScrollVert; }
9008 property bool dontScrollHorz
9010 property_category $"Behavior"
9011 set { style.dontScrollHorz = value; }
9012 get { return style.dontScrollHorz; }
9015 property bool snapVertScroll
9017 property_category $"Behavior"
9020 scrollFlags.snapY = value;
9021 if(sbv) sbv.snap = value;
9023 get { return scrollFlags.snapY; }
9025 property bool snapHorzScroll
9027 property_category $"Behavior"
9030 scrollFlags.snapX = value;
9031 if(sbh) sbh.snap = value;
9033 get { return scrollFlags.snapX; }
9036 property Point scroll
9038 property_category $"Behavior"
9042 // TESTING THIS IMPLEMENTATION:
9043 SetScrollPosition(value.x, value.y);
9045 get { value = scroll; }
9048 property bool modifyVirtualArea
9050 property_category $"Behavior"
9051 set { modifyVirtArea = value; }
9052 get { return (bool)modifyVirtArea; }
9055 property char * fileName
9057 property_category $"Document"
9060 if(menu && ((!fileName && value) || (fileName && !value)))
9062 MenuItem item = menu.FindItem(MenuFileSave, 0);
9063 if(item) item.disabled = !modifiedDocument && value;
9068 if(value && value[0])
9069 fileName = CopyString(value);
9071 if(parent && this == parent.activeClient)
9072 parent.UpdateActiveDocument(null);
9076 // if(style.isDocument)
9078 fileMonitor.fileName = value;
9080 get { return fileName; }
9085 property_category $"Data"
9090 property bool modifiedDocument
9092 property_category $"Document"
9095 if(style.isDocument || fileName)
9099 MenuItem item = menu.FindItem(MenuFileSave, 0);
9100 if(item) item.disabled = !value && fileName;
9104 if(modifiedDocument != value)
9106 modifiedDocument = value;
9107 if(style.isDocument || fileName)
9111 get { return (bool)modifiedDocument; }
9114 property bool showInTaskBar
9116 property_category $"Window Style"
9117 set { style.showInTaskBar = value; }
9118 get { return (style.showInTaskBar; }
9120 property FileDialog saveDialog { set { saveDialog = value; } };
9121 property bool isActiveClient
9123 property_category $"Behavior"
9124 set { style.isActiveClient = value; }
9125 get { return style.isActiveClient; }
9128 property Cursor cursor
9130 property_category $"Appearance"
9134 SelectMouseCursor();
9136 get { return cursor; }
9139 //#if !defined(ECERE_VANILLA)
9140 property char * name
9142 property_category $"Design"
9145 return (this && object) ? object.name : null;
9150 activeDesigner.RenameObject(object, value);
9154 property char * displayDriver
9156 property_category $"Behavior"
9159 dispDriver = GetDisplayDriver(value);
9160 //DisplayModeChanged();
9164 return dispDriver ? dispDriver.name : null;
9168 // RUNTIME PROPERTIES
9169 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9170 property Size scrollArea
9172 property_category $"Behavior"
9176 SetScrollArea(value.w, value.h, false);
9178 SetScrollArea(0,0, true);
9180 get { value = scrollArea; }
9183 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9188 property_category $"Layout"
9189 set { if(this) is3D = value; }
9190 get { return (bool)is3D; }
9193 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9195 // Will be merged with font later
9196 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9197 property Point clientStart { get { value = clientStart; } };
9198 property Point absPosition { get { value = absPosition; } };
9199 property Anchor normalAnchor { get {value = normalAnchor; } };
9200 // property Size normalSizeAnchor { get { value = normalSizeAnchor; } };
9201 property bool active { get { return (bool)active; } };
9202 property bool created { get { return (bool)created; } };
9203 property bool destroyed { get { return (bool)destroyed; } };
9204 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9205 property Window firstChild { get { return children.first; } };
9206 property Window lastChild { get { return children.last; } };
9207 property Window activeClient { get { return activeClient; } };
9208 property Window activeChild { get { return activeChild; } };
9209 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9210 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9211 property ScrollBar horzScroll { get { return sbh; } };
9212 property ScrollBar vertScroll { get { return sbv; } };
9213 property StatusBar statusBar { get { return statusBar; } };
9214 property Window rootWindow { get { return rootWindow; } };
9215 property bool closing { get { return (bool)closing; } set { closing = value; } };
9216 property int documentID { get { return documentID; } };
9217 property Window previous { get { return prev; } }
9218 property Window next { get { return next; } }
9219 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9220 property PopupMenu menuBar { get { return menuBar; } }
9221 property ScrollBar sbv { get { return sbv; } }
9222 property ScrollBar sbh { get { return sbh; } }
9223 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9224 property void * systemHandle { get { return windowHandle; } }
9225 property Button minimizeButton { get { return sysButtons[0]; } };
9226 property Button maximizeButton { get { return sysButtons[1]; } };
9227 property Button closeButton { get { return sysButtons[2]; } };
9228 property BitmapResource icon
9230 get { return icon; }
9234 if(icon) incref icon;
9236 guiApp.interfaceDriver.SetIcon(this, value);
9239 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9240 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } };
9241 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9242 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9243 property bool nativeDecorations
9245 get { return (bool)nativeDecorations; }
9246 set { nativeDecorations = value; }
9247 #ifndef ECERE_VANILLA
9248 isset { return (nativeDecorations && (rootWindow == this || (formDesigner && activeDesigner && ((FormDesigner)activeDesigner.classDesigner).form && parent == ((FormDesigner)activeDesigner.classDesigner).form.parent))) != style.fixed; }
9251 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9253 property char * text
9255 property_category $"Deprecated"
9257 set { property::caption = value; }
9258 get { return property::caption; }
9264 WindowBits style; // Window Style
9265 char * caption; // Name / Caption
9266 Window parent; // Parent window
9267 OldList children; // List of children in Z order
9268 Window activeChild; // Child window having focus
9269 Window activeClient;
9270 Window previousActive; // Child active prior to activating the default child
9271 Window master; // Window owning and receiving notifications concerning this window
9272 OldList slaves; // List of windows belonging to this window
9273 Display display; // Display this window is drawn into
9275 Point position; // Position in parent window client area
9276 Point absPosition; // Absolute position
9277 Point clientStart; // Client area position from (0,0) in this window
9279 Size clientSize; // Client area size
9280 Size scrollArea; // Virtual Scroll area size
9281 Size reqScrollArea; // Requested virtual area size
9282 Point scroll; // Virtual area scrolling position
9283 public ScrollBar sbh, sbv; // Scrollbar window handles
9284 Cursor cursor; // Mouse cursor used for this window
9287 StatusBar statusBar;
9288 Button sysButtons[3];
9290 Box clientArea; // Client Area box clipped to parent
9292 HotKeySlot hotKey; // HotKey for this window
9296 ScrollFlags scrollFlags;// Window Scrollbar Flags
9297 int id; // Control ID
9299 ColorAlpha background; // Background color used to draw the window area
9301 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9302 OldList childrenCycle; // Cycling order
9303 OldLink cycle; // Element of parent's cycling order
9304 OldList childrenOrder; // Circular Z-Order
9305 OldLink order; // Element of parent's circular Z-Order
9306 Window modalSlave; // Slave window blocking this window's interaction
9308 Window rootWindow; // Topmost system managed window
9309 void * windowHandle; // System window handle
9311 DialogResult returnCode;// Return code for modal windows
9313 Point sbStep; // Scrollbar line scrolling steps
9316 SizeAnchor stateSizeAnchor;
9318 Anchor normalAnchor;
9319 SizeAnchor normalSizeAnchor;
9321 Size skinMinSize; // Minimal window size based on style
9322 Point scrolledPos; // Scrolled position
9323 Box box; // Window box clipped to parent
9324 Box * against; // What to clip the box to
9326 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9327 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9328 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9329 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9330 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9331 Point scrolledArea; // Distance to scroll area by
9332 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9334 OldList hotKeys; // List of the hotkeys of all children
9335 Window defaultControl; // Default child control
9339 ColorAlpha * palette; // Color palette used for this window
9341 int caretSize; // Size of caret, non zero if a caret is present
9342 Point caretPos; // Caret position
9344 void * systemParent; // Parent System Window for embedded windows
9351 WindowState lastState;
9353 FileMonitor fileMonitor
9355 this, FileChange { modified = true };
9357 bool OnFileNotify(FileChange action, char * param)
9360 fileMonitor.StopMonitoring();
9361 if(OnFileModified(action, param))
9362 fileMonitor.StartMonitoring();
9367 FontResource setFont, systemFont;
9368 FontResource usedFont;
9369 FontResource captionFont;
9371 FileDialog saveDialog;
9373 SizeAnchor sizeAnchor;
9375 // FormDesigner data
9378 Extent * tempExtents; //[4];
9379 BitmapResource icon;
9381 CreationActivationOption creationActivation;
9384 bool active:1; // true if window and ancestors are active
9385 bool acquiredInput:1; // true if the window is processing state based input
9386 bool modifiedDocument:1;
9387 bool disabled:1; // true if window cannot interact
9388 bool isForegroundWindow:1;// true while a root window is being activated
9389 bool visible:1; // Visibility flag
9390 bool destroyed:1; // true if window is being destroyed
9391 bool anchored:1; // true if this window is repositioned when the parent resizes
9392 bool dirty:1; // Flag set to true if any descendant must be redrawn
9398 bool modifyVirtArea:1;
9399 bool noAutoScrollArea:1;
9402 bool setVisible:1; // FOR FORM DESIGNER
9408 bool useSharedMemory:1;
9411 bool nativeDecorations:1;
9412 bool manageDisplay:1;
9413 bool formDesigner:1; // True if we this is running in the form editor
9416 // Checks used internally for them not to take effect in FormDesigner
9417 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9418 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9420 WindowController controller;
9421 public property WindowController controller { get { return controller; } set { delete controller; controller = value; if(controller) incref controller; } }
9424 public class CommonControl : Window
9426 // creationActivation = doNothing;
9429 public property String toolTip
9431 property_category $"Appearance"
9434 if(created) CommonControl::OnDestroy();
9436 toolTip = value ? ToolTip { tip = value; } : null;
9438 if(created) CommonControl::OnCreate();
9440 get { return toolTip ? toolTip.tip : null; }
9446 // (Very) Ugly work around for the fact that the parent watcher
9447 // won't fire when it's already been disconnected...
9448 eInstance_FireSelfWatchers(toolTip,
9449 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
9455 toolTip.parent = this;
9464 public class Percentage : float
9466 char * OnGetString(char * string, float * fieldData, bool * needClass)
9470 sprintf(string, "%.2f", this);
9471 c = strlen(string)-1;
9474 if(string[c] != '0')
9475 last = Max(last, c);
9476 if(string[c] == '.')
9489 public void ApplySkin(Class c, char * name, void ** vTbl)
9491 char className[1024];
9496 subclass(Window) wc = (subclass(Window))c;
9497 subclass(Window) base = (subclass(Window))c.base;
9499 sprintf(className, "%sSkin_%s", name, c.name);
9500 wc.pureVTbl = c._vTbl;
9501 c._vTbl = new void *[c.vTblSize];
9502 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9503 sc = eSystem_FindClass(c.module.application, className);
9507 for(m = 0; m < c.base.vTblSize; m++)
9509 if(c._vTbl[m] == base.pureVTbl[m])
9510 c._vTbl[m] = vTbl[m];
9515 for(m = 0; m < c.vTblSize; m++)
9517 if(sc._vTbl[m] != wc.pureVTbl[m])
9518 c._vTbl[m] = sc._vTbl[m];
9522 for(d = c.derivatives.first; d; d = d.next)
9524 ApplySkin(d.data, name, c._vTbl);
9528 public void UnapplySkin(Class c)
9530 char className[1024];
9532 subclass(Window) wc = (subclass(Window))c;
9533 subclass(Window) base = (subclass(Window))c.base;
9536 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9539 c._vTbl = wc.pureVTbl;
9543 for(d = c.derivatives.first; d; d = d.next)
9545 UnapplySkin(d.data);
9549 void CheckFontIntegrity(Window window)
9554 if(window.usedFont && window.usedFont.font == 0xecececec)
9556 FontResource uf = window.usedFont;
9557 char * className = window._class.name;
9558 char * text = window.text;
9561 for(c = window.firstChild; c; c = c.next)
9562 CheckFontIntegrity(c);
9566 public class ControllableWindow : Window
9568 /*WindowController controller;
9569 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9570 ~ControllableWindow() { delete controller; }*/
9573 class WindowControllerInterface : ControllableWindow
9575 bool OnKeyDown(Key key, unichar ch)
9577 bool result = ((int(*)())(void *)controller.OnKeyDown)((void *)controller.controlled, (void *)controller, key, ch);
9579 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown](controller.window, key, ch);
9583 bool OnKeyUp(Key key, unichar ch)
9585 bool result = ((int(*)())(void *)controller.OnKeyUp)((void *)controller.controlled, (void *)controller, key, ch);
9587 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp](controller.window, key, ch);
9591 bool OnKeyHit(Key key, unichar ch)
9593 bool result = ((int(*)())(void *)controller.OnKeyHit)((void *)controller.controlled, (void *)controller, key, ch);
9595 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit](controller.window, key, ch);
9599 bool OnMouseMove(int x, int y, Modifiers mods)
9601 bool result = ((int(*)())(void *)controller.OnMouseMove)((void *)controller.controlled, (void *)controller, x, y, mods);
9603 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove](controller.window, x, y, mods);
9607 bool OnLeftButtonDown(int x, int y, Modifiers mods)
9609 bool result = ((int(*)())(void *)controller.OnLeftButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9611 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown](controller.window, x, y, mods);
9615 bool OnLeftButtonUp(int x, int y, Modifiers mods)
9617 bool result = ((int(*)())(void *)controller.OnLeftButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9619 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp](controller.window, x, y, mods);
9623 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
9625 bool result = ((int(*)())(void *)controller.OnLeftDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9627 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick](controller.window, x, y, mods);
9631 bool OnRightButtonDown(int x, int y, Modifiers mods)
9633 bool result = ((int(*)())(void *)controller.OnRightButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9635 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown](controller.window, x, y, mods);
9639 bool OnRightButtonUp(int x, int y, Modifiers mods)
9641 bool result = ((int(*)())(void *)controller.OnRightButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9643 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp](controller.window, x, y, mods);
9647 bool OnRightDoubleClick(int x, int y, Modifiers mods)
9649 bool result = ((int(*)())(void *)controller.OnRightDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9651 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick](controller.window, x, y, mods);
9655 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
9657 bool result = ((int(*)())(void *)controller.OnMiddleButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9659 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown](controller.window, x, y, mods);
9663 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
9665 bool result = ((int(*)())(void *)controller.OnMiddleButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9667 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp](controller.window, x, y, mods);
9671 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
9673 bool result = ((int(*)())(void *)controller.OnMiddleDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9675 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick](controller.window, x, y, mods);
9679 void OnResize(int width, int height)
9681 ((int(*)())(void *)controller.OnResize)((void *)controller.controlled, (void *)controller, width, height);
9682 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize](controller.window, width, height);
9685 void OnRedraw(Surface surface)
9687 ((int(*)())(void *)controller.OnRedraw)((void *)controller.controlled, (void *)controller, surface);
9688 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw](controller.window, surface);
9693 bool result = ((int(*)())(void *)controller.OnCreate)((void *)controller.controlled, (void *)controller);
9695 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
9700 public class WindowController<class V>
9703 property Window window
9707 uint size = class(Window).vTblSize;
9710 windowVTbl = new void *[size];
9711 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
9712 if(value._vTbl == value._class._vTbl)
9714 value._vTbl = new void *[value._class.vTblSize];
9715 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
9719 for(c = 0; c < size; c++)
9721 void * function = class(WindowControllerInterface)._vTbl[c];
9722 if(function != DefaultFunction)
9723 value._vTbl[c] = function;
9725 value._vTbl[c] = windowVTbl[c];
9730 memcpy(value._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
9733 get { return window; }
9735 property V controlled
9737 set { controlled = value; }
9738 get { return controlled; }
9740 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
9741 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
9742 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
9743 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
9744 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
9745 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
9746 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9747 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
9748 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
9749 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9750 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
9751 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
9752 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9753 virtual void V::OnResize(WindowController controller, int width, int height);
9754 virtual void V::OnRedraw(WindowController controller, Surface surface);
9755 virtual bool V::OnCreate(WindowController controller);
9758 int (** windowVTbl)();