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)
819 strcpy(caption, this.caption);
820 if(style.isDocument || fileName)
822 if(caption[0]) strcat(caption, " - ");
824 strcat(caption, fileName);
828 sprintf(title, "Untitled %d", documentID);
829 strcat(caption, title);
832 strcat(caption, " *");
834 if(activeClient && menuBar &&
835 activeClient.state == maximized)
837 if(activeClient.caption)
839 if(caption[0]) strcat(caption, " - ");
840 strcat(caption, activeClient.caption);
842 if(activeClient.style.isDocument || activeClient.fileName)
844 if(caption[0]) strcat(caption, " - ");
845 strcat(caption, "[");
846 if(activeClient.fileName)
847 strcat(caption, activeClient.fileName);
851 sprintf(title, "Untitled %d", activeClient.documentID);
852 strcat(caption, title);
854 if(activeClient.modifiedDocument)
855 strcat(caption, " *");
856 strcat(caption, "]");
861 // Code for returning dirty from ScrollDisplay:
863 for(d = 0; d<scrollExtent.count; d++)
865 Box * box = &scrollExtent.boxes[d];
871 Min(box.right, box.left-scroll.x),box.bottom
873 dirtyArea.UnionBox(update);
879 Max(box.left, box.right-scroll.x), box.top,
880 box.right, box.bottom
882 dirtyArea.UnionBox(update);
890 box.right, Min(box.bottom, box.top-scroll.y),
892 dirtyArea.UnionBox(update);
898 box.left, Max(box.top, box.bottom-scroll.y),
899 box.right, box.bottom
901 dirtyArea.UnionBox(update);
906 void UpdateDecorations(void)
908 // TODO: *** TEMPORARY HACK ***
915 Update({ -clientStart.x, -clientStart.y, -clientStart.x + size.w-1, 0 });
917 Update({ -clientStart.x, clientSize.h, -clientStart.x + size.w-1, -clientStart.y + size.h-1 });
919 Update({ -clientStart.x,0, -1, clientSize.h-1 });
921 Update({ clientSize.w, 0, -clientStart.x + size.w-1, clientSize.h-1 });
924 // Returns w & h for Position
925 void ComputeAnchors(Anchor anchor, SizeAnchor sizeAnchor, int *ox, int *oy, int *ow, int *oh)
927 Window parent = this.parent ? this.parent : guiApp.desktop;
928 int vpw = parent ? parent.clientSize.w : 0;
929 int vph = parent ? parent.clientSize.h : 0;
930 int pw = parent ? parent.clientSize.w : 0;
931 int ph = parent ? parent.clientSize.h : 0;
932 int w = sizeAnchor.size.w, h = sizeAnchor.size.h;
933 int x = anchor.left.distance, y = anchor.top.distance;
935 MinMaxValue ew = 0, eh = 0;
937 float cascadeW, cascadeH;
939 int tilingW, tilingH, tilingSplit, tilingLastH;
940 int addX = 0, addY = 0;
942 if(parent && rootWindow == this && guiApp && guiApp.interfaceDriver)
944 Window masterWindow = this;
945 Box box { addX, addY, addX + vpw - 1, addY + vph - 1 };
948 if(master == guiApp.desktop)
949 masterWindow = guiApp.desktop.activeChild;
951 masterWindow = master.rootWindow;
952 if(!masterWindow) masterWindow = this;
954 guiApp.interfaceDriver.GetScreenArea(masterWindow, box);
955 if((anchor.left.type == offset && anchor.right.type == offset) || anchor.left.type == none)
958 pw = vpw = box.right - box.left + 1;
960 if((anchor.top.type == offset && anchor.bottom.type == offset) || anchor.top.type == none)
963 ph = vph = box.bottom - box.top + 1;
979 vpw = pw = parent.size.w;
980 vph = ph = parent.size.h;
982 else if(!style.fixed /*|| style.isDocument*/)
984 if(!style.dontScrollHorz && parent.scrollArea.w) vpw = parent.scrollArea.w;
985 if(!style.dontScrollVert && parent.scrollArea.h) vph = parent.scrollArea.h;
987 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
990 Desktop3D_FixSize(&pw, &ph);
991 Desktop3D_FixSize(&vpw, &vph);
994 if(pw < skinMinSize.w) pw = skinMinSize.w;
995 if(ph < skinMinSize.h) ph = skinMinSize.h;
996 if(vpw < skinMinSize.w) vpw = skinMinSize.w;
997 if(vph < skinMinSize.h) vph = skinMinSize.h;
999 // TODO: Must fix what we're snapping
1002 if(anchor.left.type)
1004 SNAPUP(x, textCellW);
1006 else if(anchor.right.type)
1008 SNAPDOWN(x, textCellW);
1013 SNAPUP(y, textCellH);
1015 else if(anchor.bottom.type)
1017 SNAPDOWN(y, textCellH);
1021 // This is required to get proper initial decoration size using native decorations on Windows
1022 if(nativeDecorations && guiApp && guiApp.interfaceDriver && !visible)
1023 guiApp.interfaceDriver.PositionRootWindow(this, x, y, Max(1, size.w), Max(1, size.h), true, true);
1024 GetDecorationsSize(&ew, &eh);
1026 if(anchor.left.type >= cascade && (state == normal /*|| state == Hidden*/))
1028 if(parent.sbv && !parent.sbv.style.hidden)
1029 pw += guiApp.currentSkin.VerticalSBW();
1030 if(parent.sbh && !parent.sbh.style.hidden)
1031 ph += guiApp.currentSkin.HorizontalSBH();
1033 if(anchor.left.type == cascade)
1035 w = (int)(pw * 0.80);
1036 h = (int)(ph * 0.80);
1038 else if(anchor.left.type >= vTiled)
1043 numTiling = parent.numPositions - parent.numIcons;
1044 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1045 if(anchor.left.type == vTiled)
1047 tilingH = (int)sqrt(numTiling);
1048 tilingW = numTiling / tilingH;
1052 tilingW = (int)sqrt(numTiling);
1053 tilingH = numTiling / tilingW;
1056 leftOver = numTiling - tilingH * tilingW;
1059 tilingSplit = (tilingW - leftOver) * tilingH;
1060 tilingLastH = tilingH+1;
1063 tilingSplit = numTiling;
1065 if(positionID >= tilingSplit)
1067 x = pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
1068 y = ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
1069 x2 = pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
1070 y2 = ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
1074 x = pw * (positionID / tilingH) / tilingW;
1075 y = ph * (positionID % tilingH) / tilingH;
1076 x2 = pw * (positionID / tilingH + 1) / tilingW;
1077 y2 = ph * ((positionID % tilingH) + 1) / tilingH;
1081 SNAPDOWN(x, textCellW);
1082 SNAPDOWN(y, textCellH);
1083 SNAPDOWN(x2, textCellW);
1084 SNAPDOWN(y2, textCellH);
1092 if(sizeAnchor.isClientW) w += ew;
1093 if(sizeAnchor.isClientH) h += eh;
1095 if(anchor.left.type == offset)
1096 x = anchor.left.distance;
1097 else if(anchor.left.type == relative)
1098 x = (anchor.left.percent < 0) ? ((int)(vpw * anchor.left.percent - 0.5)) : (int)(vpw * anchor.left.percent + 0.5);
1099 else if(anchor.right.type == relative)
1100 // ex = (anchor.right.percent < 0) ? ((int)(vpw * anchor.right.percent + 0)) : ((int)(vpw * anchor.right.percent + 0));
1101 ex = (anchor.right.percent < 0) ? ((int)(vpw * (1.0-anchor.right.percent) + 0)) : ((int)(vpw * (1.0-anchor.right.percent) + 0));
1102 else if(anchor.right.type == offset)
1103 ex = vpw - anchor.right.distance;
1105 if(anchor.top.type == offset)
1106 y = anchor.top.distance;
1107 else if(anchor.top.type == relative)
1108 y = (anchor.top.percent < 0) ? ((int)(vph * anchor.top.percent - 0.5)) : ((int)(vph * anchor.top.percent + 0.5));
1109 else if(anchor.bottom.type == relative)
1110 //ey = (anchor.bottom.percent < 0) ? ((int)(vph * anchor.bottom.percent + 0)) : ((int)(vph * anchor.bottom.percent + 0));
1111 ey = (anchor.bottom.percent < 0) ? ((int)(vph * (1.0-anchor.bottom.percent) + 0)) : ((int)(vph * (1.0-anchor.bottom.percent) + 0));
1112 else if(anchor.bottom.type == offset)
1113 ey = vph - anchor.bottom.distance;
1115 if(anchor.left.type && anchor.right.type)
1117 switch(anchor.right.type)
1120 ex = pw * (1.0f-anchor.right.percent);
1121 w = Max((int)(ex + 0.5) - x, 0);
1124 ex = vpw - anchor.right.distance;
1125 w = Max((int)(ex + 0.5) - x, 0);
1129 if(anchor.top.type && anchor.bottom.type)
1131 switch(anchor.bottom.type)
1134 ey = ph * (1.0f-anchor.bottom.percent);
1135 h = Max((int)(ey + 0.5) - y, 0);
1138 ey = vph - anchor.bottom.distance;
1139 h = Max((int)(ey + 0.5) - y, 0);
1148 if(state == normal /*|| state == Hidden*/)
1150 bool addSbV = false, addSbH = false;
1152 if(sizeAnchor.isClientW || (anchor.left.type && anchor.right.type)) w = Max(w, 1); else w = Max(w, 0);
1153 if(sizeAnchor.isClientH || (anchor.top.type && anchor.bottom.type)) h = Max(h, 1); else h = Max(h, 0);
1155 w = Max(w, minSize.w);
1156 h = Max(h, minSize.h);
1157 w = Min(w, maxSize.w);
1158 h = Min(h, maxSize.h);
1160 if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
1162 if(w) w -= guiApp.currentSkin.VerticalSBW();
1165 if((sizeAnchor.isClientH || !h || (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
1167 if(h) h -= guiApp.currentSkin.HorizontalSBH();
1171 if(!OnResizing(&w, &h))
1177 if((addSbV)) // || reqScrollArea.h > h) && sbv)
1178 w += guiApp.currentSkin.VerticalSBW();
1179 if((addSbH)) // || reqScrollArea.w > w) && sbh)
1180 h += guiApp.currentSkin.HorizontalSBH();
1182 w = Max(w, skinMinSize.w);
1183 h = Max(h, skinMinSize.h);
1196 SNAPDOWN(w, textCellW);
1197 SNAPDOWN(h, textCellH);
1200 if(anchor.left.type == cascade && (state == normal /*|| state == Hidden*/))
1202 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1205 (pw - w) / CASCADE_SPACE,
1206 (ph - h) / CASCADE_SPACE);
1212 cascW = (pw - w) / (numCascade-1);
1213 cascH = (ph - h) / (numCascade-1);
1214 SNAPDOWN(cascW, textCellW);
1215 SNAPDOWN(cascH, textCellH);
1216 cascadeW = (float)cascW;
1217 cascadeH = (float)cascH;
1221 numCascade = Max(numCascade, 2);
1222 cascadeW = (float)(pw - w) / (numCascade-1);
1223 cascadeH = (float)(ph - h) / (numCascade-1);
1226 x = (int)((positionID % numCascade) * cascadeW);
1227 y = (int)((positionID % numCascade) * cascadeH);
1229 else if(anchor.left.type < vTiled)
1231 if(!anchor.left.type || anchor.horz.type == middleRelative)
1233 if(!anchor.right.type)
1235 if(anchor.horz.type == middleRelative)
1236 x = (int)(vpw * (0.5 + anchor.horz.percent) - w / 2);
1238 x = vpw / 2 + anchor.horz.distance - w / 2;
1244 // case A_EDGE: x = x - w; break;
1246 if(!anchor.top.type || anchor.vert.type == middleRelative)
1248 if(!anchor.bottom.type)
1250 if(anchor.vert.type == middleRelative)
1251 y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
1253 y = vph / 2 + anchor.vert.distance - h / 2;
1259 // case A_EDGE: y = y - h; break;
1262 if((state == normal /*|| state == Hidden*/) && !OnMoving(&x, &y, w, h))
1270 SNAPDOWN(x, textCellW);
1271 SNAPDOWN(y, textCellH);
1283 if(anchored && style.fixed && style.isActiveClient)
1288 void UpdateCaret(bool forceUpdate, bool erase)
1290 static Window lastWindow = null;
1291 static int caretX, caretY, caretSize;
1293 if(guiApp && guiApp.caretOwner == this)
1295 int x = caretPos.x - scroll.x;
1296 int y = caretPos.y - scroll.y;
1298 if((erase || this.caretSize) &&
1299 x >= clientArea.left && x <= clientArea.right &&
1300 y >= clientArea.top && y <= clientArea.bottom)
1304 guiApp.interfaceDriver.SetCaret(
1305 x + absPosition.x + clientStart.x,
1306 y + absPosition.y + clientStart.y, this.caretSize);
1307 guiApp.caretEnabled = true;
1309 if(erase || lastWindow != this || caretX != x || caretY != y || caretSize != this.caretSize || forceUpdate)
1313 if(lastWindow != this)
1315 updateBox.left = x + 1;
1317 updateBox.right = x + 2;
1318 updateBox.bottom = y + this.caretSize - 1;
1322 updateBox.left = Min(x + 1, caretX + 1);
1323 updateBox.top = Min(y, caretY);
1324 updateBox.right = Max(x + 2, caretX + 2);
1325 updateBox.bottom = Max(y + this.caretSize - 1, caretY + caretSize - 1);
1328 guiApp.caretOwner.Update(updateBox);
1335 caretSize = this.caretSize;
1341 guiApp.interfaceDriver.SetCaret(0,0,0);
1342 guiApp.caretEnabled = false;
1348 void SetPosition(int x, int y, int w, int h, bool modifyArea, bool modifyThisArea, bool modifyClientArea)
1353 scrolledPos.x = position.x = x;
1354 scrolledPos.y = position.y = y;
1356 clientSize.w = size.w = w;
1357 clientSize.h = size.h = h;
1359 if(parent && !style.nonClient)
1361 //if(!style.fixed || style.isDocument)
1363 if(!style.dontScrollHorz) scrolledPos.x -= parent.scroll.x;
1364 if(!style.dontScrollVert) scrolledPos.y -= parent.scroll.y;
1368 clientStart.x = clientStart.y = 0;
1370 SetWindowArea(&clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1372 //if(!activeClient || activeClient.state != maximized)
1373 if(!noAutoScrollArea)
1375 // Check if scroll area must be modified
1376 if(guiApp && !guiApp.modeSwitching && (sbv || sbh))
1378 bool foundChild = false;
1380 int cw = clientSize.w;// + ((!sbv || sbv.range > 1) ? guiApp.currentSkin.VerticalSBW() : 0);
1381 int ch = clientSize.h;// + ((!sbh || sbh.rangw > 1) ? guiApp.currentSkin.HorizontalSBH() : 0);
1382 for(child = children.first; child; child = child.next)
1384 if(child.modifyVirtArea && !child.style.hidden && child.created && /*!child.anchored &&*/
1385 !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1387 if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == offset)
1388 w = Max(w, child.position.x + child.size.w);
1389 else if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == none)
1390 w = Max(w, Max(child.position.x, 0) + child.size.w);
1391 if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == offset)
1392 h = Max(h, child.position.y + child.size.h);
1393 else if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == none)
1394 h = Max(h, Max(child.position.y, 0) + child.size.h);
1399 if(foundChild && (w > cw || h > ch))
1401 //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
1403 int stepX = sbStep.x, stepY = sbStep.y;
1404 // Needed to make snapped down position match the skin's check of client area
1405 // against realvirtual
1408 SNAPDOWN(stepX, textCellW);
1409 SNAPDOWN(stepY, textCellH);
1410 stepX = Max(stepX, textCellW);
1411 stepY = Max(stepY, textCellH);
1413 if(scrollFlags.snapX)
1415 if(scrollFlags.snapY)
1418 reqScrollArea.w = w;
1419 reqScrollArea.h = h;
1422 else if(reqScrollArea.w || reqScrollArea.h)
1424 reqScrollArea.w = 0;
1425 reqScrollArea.h = 0;
1426 SetScrollPosition(0,0);
1431 // Automatic MDI Client Scrolling Area Adjustment
1432 if(parent && !parent.noAutoScrollArea)
1434 if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
1435 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
1437 Window parent = this.parent;
1438 int w = parent.reqScrollArea.w;
1439 int h = parent.reqScrollArea.h;
1441 if(stateAnchor.right.type == none && stateAnchor.left.type == offset)
1442 w = Max(w, position.x + size.w);
1443 else if(stateAnchor.right.type == none && stateAnchor.left.type == none)
1444 w = Max(w, Max(position.x, 0) + size.w);
1445 if(stateAnchor.bottom.type == none && stateAnchor.top.type == offset)
1446 h = Max(h, position.y + size.h);
1447 else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
1448 h = Max(h, Max(position.y, 0) + size.h);
1450 if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
1451 (h > parent.clientSize.h && h > parent.reqScrollArea.h))
1453 /*bool resize = false;
1454 int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
1455 // Needed to make snapped down position match the skin's check of client area
1456 // against realvirtual
1459 SNAPDOWN(stepX, textCellW);
1460 SNAPDOWN(stepY, textCellH);
1461 stepX = Max(stepX, textCellW);
1462 stepY = Max(stepY, textCellH);
1464 if(parent.scrollFlags.snapX)
1466 if(parent.scrollFlags.snapY)
1468 if(parent.reqScrollArea.w != w || parent.reqScrollArea.h != h)
1470 parent.reqScrollArea.w = w;
1471 parent.reqScrollArea.h = h;*/
1473 // parent.UpdateScrollBars(true, true);
1474 parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1475 false, true, true, true, false, false);
1480 GetRidOfVirtualArea();
1484 UpdateScrollBars(modifyThisArea, false);
1485 else if(guiApp.currentSkin)
1488 &clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1490 if(sbv && (scrollFlags.dontHide || sbv.range > 1))
1491 clientSize.w -= guiApp.currentSkin.VerticalSBW();
1492 if(sbh && (scrollFlags.dontHide || sbh.range > 1))
1493 clientSize.h -= guiApp.currentSkin.HorizontalSBH();
1496 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1497 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1499 absPosition = scrolledPos;
1500 if(guiApp && guiApp.driver != null && guiApp.interfaceDriver)
1501 guiApp.interfaceDriver.OffsetWindow(this, &absPosition.x, &absPosition.y);
1503 if(this != guiApp.desktop && parent)
1505 absPosition.x += parent.absPosition.x;
1506 absPosition.y += parent.absPosition.y;
1507 if(!style.nonClient && this != guiApp.desktop)
1509 absPosition.x += parent.clientStart.x;
1510 absPosition.y += parent.clientStart.y;
1514 box = Box { 0, 0, size.w - 1, size.h - 1 };
1519 // Clip against parent's client area
1520 box.ClipOffset(against, scrolledPos.x, scrolledPos.y);
1522 // Compute client area in this window coordinate system
1523 clientArea.left = 0;
1525 clientArea.right = clientSize.w - 1;
1526 clientArea.bottom = clientSize.h - 1;
1528 // Clip against parent's client area
1530 clientArea.ClipOffset(against, scrolledPos.x + clientStart.x, scrolledPos.y + clientStart.y);
1534 //absPosition.x -= parent.clientStart.x;
1535 //absPosition.y -= parent.clientStart.y;
1538 // Adjust all children
1539 for(child = children.first; child; child = child.next)
1540 child.SetPosition(child.position.x, child.position.y, child.size.w, child.size.h, false, true, true);
1542 UpdateCaret(false, false);
1545 void GetRidOfVirtualArea(void)
1547 if(parent && !parent.destroyed && style.fixed &&
1548 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient &&
1549 parent.reqScrollArea.w && parent.reqScrollArea.h)
1551 if(!parent.noAutoScrollArea)
1555 for(child = children.first; child; child = child.next)
1557 if(child.modifyVirtArea && !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1559 if(child.position.x + child.size.w > parent.clientSize.w + ((!parent.sbv || parent.sbv.style.hidden) ? 0 : guiApp.currentSkin.VerticalSBW()) ||
1560 child.position.y + child.size.h > parent.clientSize.h + ((!parent.sbh || parent.sbh.style.hidden) ? 0 : guiApp.currentSkin.HorizontalSBH()))
1569 Window parent = this.parent;
1571 parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1572 false, true, true, true, false, false);
1574 parent.SetScrollArea(0,0,true);
1575 parent.SetScrollPosition(0,0);
1581 public void ExternalPosition(int x, int y, int w, int h)
1583 Position(x, y, w, h, false, true, true, true, false, false);
1586 // (w, h): Full window size
1587 bool Position(int x, int y, int w, int h, bool force, bool processAnchors, bool modifyArea, bool updateScrollBars, bool thisOnly, bool changeRootWindow)
1589 bool result = false;
1590 int oldCW = clientSize.w, oldCH = clientSize.h;
1591 bool clientResized, windowResized, windowMoved;
1593 bool realResized = size.w != w || size.h != h;
1595 // TOCHECK: This wasn't in ecere.dll
1596 //if(!parent) return true;
1597 if(destroyed) return false;
1599 windowMoved = position.x != x || position.y != y || force;
1601 // windowResized = realResized || force;
1602 windowResized = size.w != w || size.h != h || force;
1604 if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
1610 scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
1611 scrolledPos.x - parent.clientStart.x + this.box.right,
1612 scrolledPos.y - parent.clientStart.y + this.box.bottom
1618 Box box { scrolledPos.x + this.box.left, scrolledPos.y + this.box.top, scrolledPos.x + this.box.right, scrolledPos.y + this.box.bottom};
1623 SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
1625 clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
1626 if(clientResized && this == rootWindow && nativeDecorations)
1627 windowResized = true;
1629 if(display && rootWindow != this)
1632 if(guiApp && guiApp.windowMoving)
1634 if(guiApp.windowMoving.style.nonClient)
1635 guiApp.windowMoving.parent.SetMouseRangeToWindow();
1637 guiApp.windowMoving.parent.SetMouseRangeToClient();
1647 // Buttons bitmap resources crash if we do this while switching mode
1648 if(!guiApp || !guiApp.modeSwitching)
1651 // Process Anchored Children
1655 for(child = children.first; child; child = child.next)
1658 ((child.stateAnchor.left.type != offset ||
1659 child.stateAnchor.top.type != offset ||
1660 child.stateAnchor.right.type != none ||
1661 child.stateAnchor.bottom.type != none) ||
1662 child.state == maximized || child.state == minimized))
1664 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1666 // child.Position(x, y, w, h, false, true, true, true, false);
1667 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1668 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1674 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1675 //if(updateScrollBars)
1677 OnResize(clientSize.w, clientSize.h);
1679 if((clientResized || windowMoved) && created)
1680 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1682 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1684 Window master = guiApp.interimWindow.master;
1685 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1688 if(rootWindow == this && !is3D)
1692 x -= guiApp.desktop.absPosition.x;
1693 y -= guiApp.desktop.absPosition.y;
1695 //guiApp.Log("Position %s\n", caption);
1696 if(windowResized || windowMoved)
1697 if(display && !display.flags.memBackBuffer && changeRootWindow)
1698 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1700 if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved))
1701 for(child = parent.children.first; child && child != this; child = child.next)
1702 if(child.rootWindow)
1703 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1707 if(windowMoved || windowResized)
1709 display.Lock(true /*false*/);
1712 display.Position(absPosition.x, absPosition.y);
1713 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1716 // result = realResized ? display.Resize(size.w, size.h) : true;
1717 if(nativeDecorations)
1719 int w = clientSize.w, h = clientSize.h;
1720 if(hasMenuBar) h += skinMenuHeight;
1721 if(hasStatusBar) h += statusBarHeight;
1722 if(sbv && sbv.visible) w += sbv.size.w;
1723 if(sbh && sbh.visible) h += sbh.size.h;
1724 result = manageDisplay ? display.Resize(w, h) : true;
1727 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1731 else if(clientResized)
1733 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1736 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1740 if(windowMoved || windowResized)
1745 if(guiApp.driver && changeRootWindow)
1747 if(windowResized || windowMoved)
1748 if(!display || display.flags.memBackBuffer)
1749 guiApp.interfaceDriver.PositionRootWindow(this,
1750 x, y, w, h, windowMoved, windowResized);
1751 guiApp.interfaceDriver.UpdateRootWindow(this);
1753 for(child = children.first; child; child = child.next)
1755 if(child.is3D && child.created)
1757 // Copy Display Content
1758 child.display.displaySystem = display.displaySystem;
1759 child.display.window = display.window;
1760 child.display.current = display.current;
1761 child.display.width = display.width;
1762 child.display.height = display.height;
1763 child.display.driverData = display.driverData;
1764 child.display.mutex = null;
1775 void UpdateScrollBars(bool flag, bool fullThing)
1778 bool resizeH = false, resizeV = false;
1779 bool scrolled = false;
1780 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1781 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1783 if(destroyed) return;
1784 if(guiApp.currentSkin)
1786 MinMaxValue cw = 0, ch = 0;
1787 bool sbvVisible, sbhVisible;
1789 int positionH, positionV;
1791 // First get client area with no respect to scroll bars
1796 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1798 if(scrollFlags.dontHide)
1801 cw -= guiApp.currentSkin.VerticalSBW();
1803 ch -= guiApp.currentSkin.HorizontalSBH();
1805 // Update the scrollbar visibility
1811 sbh.disabled = rangeH <= 1;
1812 if(sbh.style.hidden)
1822 sbv.disabled = rangeV <= 1;
1823 if(sbv.style.hidden)
1831 // Then start off with horizontal scrollbar range
1834 positionH = sbh.thumbPosition;
1839 ch -= guiApp.currentSkin.HorizontalSBH();
1842 // Do the same for vertical scrollbar
1845 positionV = sbv.thumbPosition;
1851 cw -= guiApp.currentSkin.VerticalSBW();
1852 // Maybe we need to set the range on the horizontal scrollbar again
1857 sbh.Action(setRange, positionH, 0);
1858 if(rangeH <= 1 && sbh.range > 1)
1860 ch -= guiApp.currentSkin.HorizontalSBH();
1864 sbv.Action(setRange, positionV, 0);
1871 // Update the scrollbar visibility
1872 if(!scrollFlags.dontHide)
1874 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
1878 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
1885 if(guiApp.currentSkin)
1892 sbhVisible = sbh.style.hidden ? true : false;
1894 sbvVisible = sbv.style.hidden ? true : false;
1896 // Do our resize here
1897 if(flag && (resizeH || resizeV) && fullThing)
1899 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
1904 OnResize(clientSize.w, clientSize.h);
1910 sbh.visible = sbhVisible;
1912 sbv.visible = sbvVisible;
1914 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1915 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1918 sbh.pageStep = clientSize.w;
1920 sbv.pageStep = clientSize.h;
1922 // Notify doesn't handle setRange anymore... process it here
1925 int positionH = sbh.thumbPosition;
1926 if(scroll.x != positionH)
1928 OnHScroll(setRange, positionH, 0);
1932 SNAPDOWN(positionH, textCellW);
1933 scroll.x = positionH;
1939 int seen = clientSize.w, total = reqScrollArea.w;
1942 if(scrollFlags.snapX)
1943 SNAPDOWN(seen, sbStep.x);
1945 if(!total) total = seen;
1946 range = total - seen + 1;
1948 range = Max(range, 1);
1950 if(x >= range) x = range - 1;
1952 if(scrollFlags.snapX)
1953 SNAPUP(x, sbStep.x);
1957 OnHScroll(setRange, x, 0);
1962 SNAPDOWN(x, textCellW);
1968 int positionV = sbv.thumbPosition;
1969 if(scroll.y != positionV)
1971 OnVScroll(setRange, positionV, 0);
1975 SNAPDOWN(positionV, textCellH);
1976 scroll.y = positionV;
1982 int seen = clientSize.h, total = reqScrollArea.h;
1985 if(scrollFlags.snapY)
1986 SNAPDOWN(seen, sbStep.y);
1988 if(!total) total = seen;
1989 range = total - seen + 1;
1990 range = Max(range, 1);
1992 if(y >= range) y = range - 1;
1994 if(scrollFlags.snapY)
1995 SNAPUP(y, sbStep.y);
1999 OnVScroll(setRange, y, 0);
2004 SNAPDOWN(y, textCellH);
2010 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2013 for(child = children.first; child; child = child.next)
2015 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2018 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2019 child.Position(x, y, w, h, false, true, false, true, false, false);
2026 // Process Scrollbars
2028 if(sbh) // && !sbh.style.hidden
2030 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2031 // Need to set the range again (should improve...) since the scrollbars didn't have
2032 // the right size when UpdateScrollArea set the range on it
2035 sbh.seen = clientSize.w;
2039 if(sbv) // && !sbv.state.hidden
2041 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2042 // Need to set the range again (should improve...) since the scrollbars didn't have
2043 // the right size when UpdateScrollArea set the range on it
2046 sbv.seen = clientSize.h;
2051 // TESTING THIS LOWER
2052 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2055 for(child = children.first; child; child = child.next)
2057 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2060 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2061 child.Position(x, y, w, h, false, true, false, true, false, false);
2067 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2069 SetState(maximized, false, mods);
2073 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2075 SetState(normal, false, mods);
2079 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2081 SetState(minimized, false, mods);
2082 parent.CycleChildren(false, true, false, true);
2086 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2089 // Scroll bar notifications
2090 if(action != setRange)
2092 bool changed = false;
2096 if(scroll.x != position)
2098 OnHScroll(action, position, keyFlags);
2103 SNAPDOWN(position, textCellW);
2105 scroll.x = position;
2109 if(scroll.y != position)
2111 OnVScroll(action, position, keyFlags);
2116 SNAPDOWN(position, textCellH);
2118 scroll.y = position;
2122 bool childMove = false;
2123 for(child = children.first; child; child = child.next)
2125 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2128 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2129 child.Position(x, y, w, h, false, true, false, true, false, false);
2133 // Testing this patch out to solve MDI workspace redraw bugs
2134 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2135 // Scroll offsets to blame?
2139 UpdateCaret(false, false);
2143 // Testing this patch out to solve MDI workspace redraw bugs
2144 for(child = children.first; child; child = child.next)
2146 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2155 void CreateSystemChildren(void)
2157 Window parent = this;
2158 bool scrollBarChanged = false;
2159 bool hasClose = false, hasMaxMin = false;
2160 Point scroll = this.scroll;
2162 if(state == maximized && this.parent.menuBar)
2164 if(this.parent.activeClient == this)
2165 parent = this.parent.menuBar;
2172 if(style.hasClose) hasClose = true;
2173 if(style.hasMaximize || style.hasMinimize)
2180 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2182 sysButtons[2].Destroy(0);
2183 sysButtons[2] = null;
2185 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2187 sysButtons[1].Destroy(0);
2188 sysButtons[1] = null;
2190 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2192 sysButtons[0].Destroy(0);
2193 sysButtons[0] = null;
2196 if(hasClose && parent)
2203 parent, master = this,
2204 inactive = true, nonClient = true, visible = false;
2206 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2212 if(this.parent == guiApp.desktop)
2213 sysButtons[2].hotKey = altF4;
2214 else if(style.isActiveClient)
2215 sysButtons[2].hotKey = ctrlF4;
2216 sysButtons[2].Create();
2219 sysButtons[2].symbol = 'X';
2220 sysButtons[2].disabled = !style.hasClose;
2223 if(hasMaxMin && parent)
2227 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2228 if(state == maximized)
2231 method = RestoreButtonClicked;
2237 method = MaximizeButtonClicked;
2245 parent, master = this,
2246 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2248 sysButtons[1].Create();
2250 sysButtons[1].NotifyClicked = method;
2252 sysButtons[1].symbol = symbol;
2253 sysButtons[1].disabled = !style.hasMaximize;
2256 if(hasMaxMin && parent)
2260 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2261 if (state == minimized)
2264 method = RestoreButtonClicked;
2270 method = MinimizeButtonClicked;
2278 parent, master = this,
2279 hotKey = altM, inactive = true, nonClient = true, visible = false
2281 sysButtons[0].Create();
2283 sysButtons[0].NotifyClicked = method;
2285 sysButtons[0].symbol = symbol;
2286 sysButtons[0].disabled = !style.hasMinimize;
2289 // Create the scrollbars
2290 if(style.hasHorzScroll && !sbh)
2296 direction = horizontal,
2300 snap = scrollFlags.snapX,
2301 NotifyScrolling = ScrollBarNotification
2304 scrollBarChanged = true;
2306 else if(sbh && !style.hasHorzScroll)
2312 if(style.hasVertScroll && !sbv)
2318 direction = vertical,
2322 snap = scrollFlags.snapY,
2323 NotifyScrolling = ScrollBarNotification
2326 scrollBarChanged = true;
2328 else if(sbv && !style.hasVertScroll)
2333 if(scrollBarChanged)
2335 SetScrollLineStep(sbStep.x, sbStep.y);
2336 UpdateScrollBars(true, true);
2340 if(scrollBarChanged)
2342 if(sbh) sbh.thumbPosition = scroll.x;
2343 if(sbv) sbv.thumbPosition = scroll.y;
2347 void UpdateCaption(void)
2349 if(rootWindow == this)
2352 FigureCaption(caption);
2353 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2355 UpdateDecorations();
2358 if(parent.rootWindow == parent && parent.activeClient == this) // Added this last check
2361 parent.FigureCaption(caption);
2362 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2364 parent.UpdateDecorations();
2368 void UpdateActiveDocument(Window previous)
2370 Window activeClient = this.activeClient;
2371 Window activeChild = this.activeChild;
2378 activeClient.CreateSystemChildren();
2380 previous.CreateSystemChildren();
2391 if(activeClient && activeClient.menu && activeClient.state != minimized)
2395 //activeClient.menu.Clean(activeClient);
2396 menu.Merge(activeClient.menu, true, activeClient);
2400 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2403 menu.Merge(activeChild.menu, true, activeChild);
2406 // Build window list
2409 Menu windowMenu = menu.FindMenu("Window");
2414 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2417 Window document = cycle.data;
2418 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2420 char name[2048], caption[2048];
2421 document.FigureCaption(caption);
2422 sprintf(name, "%d %s", id+1, caption);
2423 windowMenu.AddDynamic(MenuItem
2425 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2426 NotifySelect = MenuWindowSelectWindow
2430 if(activeClient.cycle == cycle) break;
2435 if((!previous && activeClient) || !activeClient)
2441 item = menu.FindItem(MenuWindowCloseAll, 0);
2442 if(item) item.disabled = false;
2443 item = menu.FindItem(MenuWindowNext, 0);
2444 if(item) item.disabled = false;
2445 item = menu.FindItem(MenuWindowPrevious, 0);
2446 if(item) item.disabled = false;
2447 item = menu.FindItem(MenuWindowCascade, 0);
2448 if(item) item.disabled = false;
2449 item = menu.FindItem(MenuWindowTileHorz, 0);
2450 if(item) item.disabled = false;
2451 item = menu.FindItem(MenuWindowTileVert, 0);
2452 if(item) item.disabled = false;
2453 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2454 if(item) item.disabled = false;
2455 item = menu.FindItem(MenuWindowWindows, 0);
2456 if(item) item.disabled = false;
2459 item = menu.FindItem(MenuFileClose, 0);
2460 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2461 item = menu.FindItem(MenuFileSaveAll, 0);
2462 if(item) item.disabled = numDocuments < 1;
2464 // This is called again for a child window change, with same active client
2465 OnActivateClient(activeClient, previous);
2468 void _ShowDecorations(Box box, bool post)
2470 if(rootWindow == this && nativeDecorations) return;
2471 if(visible && this != guiApp.desktop)
2473 Surface surface = RedrawFull(box);
2477 FigureCaption(caption);
2480 ShowDecorations(captionFont.font,
2483 active, //parent.activeClient == this
2484 guiApp.windowMoving == this);
2486 PreShowDecorations(captionFont.font,
2489 active, //parent.activeClient == this
2490 guiApp.windowMoving == this);
2497 void UpdateExtent(Box refresh)
2499 Surface surface = null;
2501 if(!manageDisplay) { OnRedraw(null);return; }
2502 _ShowDecorations(refresh, false);
2504 surface = Redraw(refresh);
2505 // Opaque background: just fill before EW_REDRAW (clear?)
2508 surface.SetBackground(background);
2509 surface.SetForeground(foreground);
2510 surface.DrawingChar(' ');
2511 if(this == rootWindow)
2513 if(style.drawBehind || background.a)
2514 surface.Clear(colorBuffer);
2516 else if(background.a)
2520 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2521 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2524 if(display.flags.alpha && background.a < 255 && background)
2526 surface.Area(0,0,clientSize.w, clientSize.h);
2527 /*if(style.clearDepthBuffer)
2528 surface.Clear(depthBuffer);*/
2530 else if(/*style.clearDepthBuffer || */background.a)
2532 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2533 surface.Clear(colorBuffer);
2538 surface.TextFont(usedFont.font);
2539 surface.TextOpacity(false);
2543 // Draw the caret ...
2544 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2546 // surface.SetBackground(0xFFFFFF - background.color);
2547 surface.SetBackground(~background.color);
2549 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2550 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2556 void DrawOverChildren(Box refresh)
2558 Surface surface = Redraw(refresh);
2562 surface.DrawingChar(' ');
2563 surface.SetBackground(background);
2564 surface.SetForeground(foreground);
2566 surface.TextFont(usedFont.font);
2567 surface.TextOpacity(false);
2569 OnDrawOverChildren(surface);
2574 _ShowDecorations(refresh, true);
2577 void ComputeClipExtents(void)
2580 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2582 clipExtent.Copy(this.clipExtent);
2584 for(child = children.last; child; child = child.prev)
2586 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2588 bool opaque = child.IsOpaque(); // TODO: acess background directly
2589 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2591 child.clipExtent.Copy(clipExtent);
2592 child.clipExtent.Offset(-dx, -dy);
2593 child.clipExtent.IntersectBox(child.box);
2595 child.ComputeClipExtents();
2597 if(opaque && !child.style.nonClient)
2599 // Adjust the box for the parent:
2600 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2601 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2606 // ??? Only do this for overlapped window or if parent has with clip children flag
2608 // Do this if window has clip children flag on (default false?)
2609 // this.clipExtent = clipExtent;
2611 clipExtent.Free(null);
2614 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2616 bool opaque = IsOpaque();
2618 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2619 if(rootWindow.nativeDecorations)
2621 offsetX -= rootWindow.clientStart.x;
2622 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2626 for(child = children.last; child; child = child.prev)
2628 ColorAlpha background = *(ColorAlpha *)&child.background;
2629 bool opaque = child.IsOpaque();
2630 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2634 // Adjust renderArea to the root window level
2635 Extent * renderArea = &rootWindow.tempExtents[1];
2637 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2638 if(child.rootWindow.nativeDecorations)
2640 offsetX -= child.rootWindow.clientStart.x;
2641 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2645 Extent childRenderArea;
2647 if(backBufferUpdate != null)
2649 childRenderArea.Copy(backBufferUpdate);
2650 childRenderArea.Offset(-offsetX, -offsetY);
2653 childRenderArea.Copy(child.dirtyArea);
2655 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2656 renderArea.Copy(dirtyExtent);
2657 renderArea.Offset(-offsetX, -offsetY);
2658 childRenderArea.Union(renderArea);
2661 // Intersect with the clip extent
2662 childRenderArea.Intersection(child.clipExtent);
2665 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2666 renderArea->Offset(offsetX, offsetY);
2667 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2668 // overDirtyExtent.Union(renderArea);
2669 renderArea->Empty();
2670 // childRenderArea.Free();
2672 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2677 for(child = children.last; child; child = child.prev)
2679 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2681 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2686 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2688 bool opaque = IsOpaque();
2689 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2691 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2692 if(rootWindow.nativeDecorations)
2694 offsetX -= rootWindow.clientStart.x;
2695 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2699 for(child = children.last; child; child = child.prev)
2701 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2703 ColorAlpha background = *(ColorAlpha *)&child.background;
2704 bool opaque = child.IsOpaque();
2705 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2709 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2710 // Adjust renderArea to the root window level
2712 renderArea.Copy(child.dirtyArea);
2713 renderArea.Offset(offsetX, offsetY);
2714 dirtyExtent.Union(renderArea);
2715 overDirtyExtent.Union(renderArea);
2721 for(child = children.last; child; child = child.prev)
2723 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2725 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2729 if(backBufferUpdate != null)
2731 renderArea.Copy(backBufferUpdate);
2732 renderArea.Offset(-offsetX, -offsetY);
2734 overRenderArea.Copy(backBufferUpdate);
2735 overRenderArea.Offset(-offsetX, -offsetY);
2741 renderArea.Copy(dirtyArea);
2743 overRenderArea.Copy(dirtyArea);
2746 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2747 dirtyExtentWindow->Copy(dirtyExtent);
2748 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2749 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2750 dirtyExtentWindow->Empty();
2752 // Intersect with the clip extent
2753 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2756 if(renderArea.count > 10)
2759 printf("\nToo many extents (%d):\n", renderArea.count);
2761 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2762 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2767 for(c = 0; c<10; c++)
2770 FASTLIST_LOOP(renderArea, extentBox)
2772 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2774 renderArea.Copy(extent);
2776 FASTLIST_LOOP(renderArea, extentBox)
2779 printf("(%d, %d) - (%d, %d)\n",
2780 extentBox.box.left, extentBox.box.top,
2781 extentBox.box.right, extentBox.box.bottom);
2785 printf("\nNow %d\n", renderArea.count);
2791 // WHY WAS THIS COMMENTED ??
2793 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2794 dirtyExtentWindow->Copy(overDirtyExtent);
2795 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2796 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2797 dirtyExtentWindow->Empty();
2799 // Intersect with the clip extent
2800 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2806 if(scrollExtent.count)
2808 // Subtract render extent from scrolling extent
2809 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
2811 if(backBufferUpdate == null)
2813 Extent * dirty = &rootWindow.tempExtents[3];
2816 // Intersect scrolling extent with clip extent
2817 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2819 // offset this scroll to be at the root window level
2820 scrollExtent.Offset(offsetX, offsetY);
2821 // Add area that was scrolled to the dirty extents of the back buffer
2822 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
2826 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
2827 for(scrollBox = (BoxItem)scrollExtent.first; scrollBox; scrollBox = (BoxItem)scrollBox.next)
2828 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
2833 scrollExtent.Empty();
2835 // Add the exposed extent to the window render area
2836 dirty->Offset(-offsetX, -offsetY);
2837 renderArea.Union(dirty, rootWindow.tempExtents[0]);
2842 // Subtract the window's box from the transparency forced extent
2843 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
2849 renderArea.Copy(this.renderArea);
2850 renderArea.Offset(offsetX, offsetY);
2851 dirtyExtent.Union(renderArea);
2857 Extent renderArea { };
2859 renderArea.Copy(overRenderArea);
2860 renderArea.Offset(offsetX, offsetY);
2861 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2866 if(backBufferUpdate != null)
2868 // Remove render area from dirty area
2869 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
2871 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
2878 // Remove the window render area from the dirty extents of the back buffer
2879 rootWindow.dirtyBack.Exclusion(renderArea);
2883 void Render(Extent updateExtent)
2887 Window rootWindow = this.rootWindow;
2888 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2889 if(rootWindow.nativeDecorations)
2891 offsetX -= rootWindow.clientStart.x;
2892 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2895 if(rootWindow.fullRender)
2904 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2905 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
2910 /*if(renderArea.count)
2911 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
2914 for(extentBox = (BoxItem)renderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2916 Box box = extentBox.box;
2919 /*printf("(%d, %d) - (%d, %d)\n",
2920 extentBox.box.left, extentBox.box.top,
2921 extentBox.box.right, extentBox.box.bottom);*/
2926 box.left += offsetX;
2928 box.right += offsetX;
2929 box.bottom += offsetY;
2931 if(updateExtent != null)
2932 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2936 for(child = children.first; child; child = child.next)
2937 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
2938 child.Render(updateExtent);
2940 if(rootWindow.fullRender)
2941 DrawOverChildren(box);
2944 // TO DO: There's an issue about draw over children...
2945 // TO DO: Don't wanna go through this if method isn't used
2946 for(extentBox = (BoxItem)overRenderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2947 //FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
2949 Box box = extentBox.box;
2951 DrawOverChildren(box);
2953 box.left += offsetX;
2955 box.right += offsetX;
2956 box.bottom += offsetY;
2958 if(updateExtent != null)
2959 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2962 for(child = children.first; child; child = child.next)
2963 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
2964 child.Render(updateExtent);
2967 overRenderArea.Empty();
2970 public void UpdateDisplay(void)
2972 if(!manageDisplay) { OnRedraw(null);return; }
2973 if(rootWindow && this != rootWindow)
2974 rootWindow.UpdateDisplay();
2977 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
2978 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
2981 dirtyExtent.Clear();
2984 clipExtent.AddBox(box);
2986 display.StartUpdate();
2988 if(!rootWindow.fullRender)
2990 ComputeClipExtents();
2991 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
2992 ComputeRenderArea(dirtyExtent, overExtent, null);
2995 clipExtent.Free(null);
2997 dirtyExtent.Free(null);
2998 overExtent.Free(null);
3000 if(display.flags.flipping)
3003 display.Update(null);
3007 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
3008 updateExtent.Clear();
3010 Render(updateExtent);
3012 updateExtent.UnionBox(this.box, tempExtents[0]);
3015 //printf("\n\nUpdate:\n------------------------------------------\n");
3018 //FASTLIST_LOOP(updateExtent, extentBox)
3019 for(extentBox = (BoxItem)updateExtent.first; extentBox; extentBox = (BoxItem)extentBox.next)
3022 /*printf("Updating (%d, %d) - (%d, %d)\n",
3023 extentBox.box.left, extentBox.box.top,
3024 extentBox.box.right, extentBox.box.bottom);*/
3027 display.Update(extentBox.box);
3030 updateExtent.Free(null);
3033 display.EndUpdate();
3041 void UpdateBackDisplay(Box box)
3047 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3049 //printf("UpdateBackDisplay going through!\n");
3050 display.StartUpdate();
3054 intersection.Copy(dirtyBack);
3055 intersection.IntersectBox(box);
3057 dirtyExtent.Clear();
3060 clipExtent.AddBox(box);
3062 if(!rootWindow.fullRender)
3064 ComputeClipExtents();
3065 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3068 clipExtent.Free(null);
3070 intersection.Free(null);
3071 dirtyExtent.Free(null);
3072 overExtent.Free(null);
3077 if(display.flags.flipping)
3078 display.Update(null);
3081 rootWindow.display.Update(box);
3084 display.EndUpdate();
3088 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3089 if(dirtyBack.count > MAX_DIRTY_BACK)
3091 BoxItem extentBox, next;
3092 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3093 for(extentBox = (BoxItem)dirtyBack.first; extentBox; extentBox = next)
3095 next = (BoxItem)extentBox.next;
3096 if(extentBox != first)
3098 if(extentBox.box.left < first.box.left)
3099 first.box.left = extentBox.box.left;
3100 if(extentBox.box.top < first.box.top)
3101 first.box.top = extentBox.box.top;
3102 if(extentBox.box.right > first.box.right)
3103 first.box.right = extentBox.box.right;
3104 if(extentBox.box.bottom > first.box.bottom)
3105 first.box.bottom = extentBox.box.bottom;
3106 dirtyBack.Delete(extentBox);
3115 // --- Window positioning ---
3116 // --- Window identification ---
3118 // Returns window at position "Position"
3119 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3121 Window child, result = null;
3123 box.left += absPosition.x;
3124 box.right += absPosition.x;
3125 box.top += absPosition.y;
3126 box.bottom += absPosition.y;
3128 if(!destroyed && visible && (acceptDisabled || !disabled))
3130 int lx = x - absPosition.x;
3131 int ly = y - absPosition.y;
3132 if(IsInside(lx, ly))
3133 // if(box.IsPointInside(Point{x, y}))
3135 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3136 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3139 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3141 if(child != statusBar && child.rootWindow == rootWindow)
3143 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3150 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3152 if(child != statusBar && child.rootWindow == rootWindow)
3154 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3166 Window FindModal(void)
3168 Window modalWindow = this, check;
3169 Window check2 = null;
3170 for(check = this; check.master; check = check.master)
3172 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3174 modalWindow = check.master.modalSlave;
3175 check = modalWindow;
3177 // TESTING THIS FOR DROPBOX...
3178 if(!rootWindow || !rootWindow.style.interim)
3180 for(check2 = check; check2.activeChild; check2 = check2.activeChild)
3182 if(check2.modalSlave && check2.modalSlave.created)
3184 modalWindow = check2.modalSlave;
3192 if(modalWindow == this)
3194 for(check = this; check.activeChild; check = check.activeChild)
3196 if(check.modalSlave)
3198 modalWindow = check.modalSlave;
3204 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3205 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3208 void StopMoving(void)
3210 if(this == guiApp.windowMoving)
3212 guiApp.windowMoving = null;
3213 UpdateDecorations();
3214 SetMouseRange(null);
3217 if(rootWindow.active)
3218 guiApp.interfaceDriver.StopMoving(rootWindow);
3221 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3222 guiApp.windowIsResizing = false;
3226 void SelectMouseCursor(void)
3231 Window cursorWindow = null;
3232 bool rx, ry, rex, rey;
3234 guiApp.desktop.GetMousePosition(&x, &y);
3235 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3237 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3238 guiApp.SetCurrentCursor(guiApp.systemCursors[moving]);
3239 else if(mouseWindow)
3241 modalWindow = mouseWindow.FindModal();
3242 x -= mouseWindow.absPosition.x;
3243 y -= mouseWindow.absPosition.y;
3244 if(guiApp.windowIsResizing)
3246 rex = guiApp.resizeEndX;
3247 rey = guiApp.resizeEndY;
3248 rx = guiApp.resizeX;
3249 ry = guiApp.resizeY;
3250 if((rex && rey) || (rx && ry))
3251 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3252 else if((rex && ry) || (rx && rey))
3253 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3254 else if((ry || rey) && (!rx && !rex))
3255 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3256 else if((rx || rex) && (!ry && !rey))
3257 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3259 else if(!modalWindow && !guiApp.windowCaptured &&
3260 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3261 &rx, &ry, &rex, &rey))
3263 if((rex && rey) || (rx && ry))
3264 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3265 else if((rex && ry) || (rx && rey))
3266 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3267 else if((ry || rey) && (!rx && !rex))
3268 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3269 else if((rx || rex) && (!ry && !rey))
3270 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3272 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3274 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}))
3275 cursorWindow = mouseWindow.parent;
3277 cursorWindow = mouseWindow;
3279 else if(!guiApp.interimWindow)
3280 cursorWindow = guiApp.windowCaptured;
3283 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient; cursorWindow = cursorWindow.parent);
3284 guiApp.SetCurrentCursor(cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3286 else if(modalWindow)
3288 guiApp.SetCurrentCursor(guiApp.systemCursors[arrow]);
3290 else if(guiApp.interimWindow)
3292 if(guiApp.interimWindow.cursor)
3293 guiApp.SetCurrentCursor(guiApp.interimWindow.cursor);
3295 guiApp.SetCurrentCursor(mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3300 // --- State based input ---
3301 bool AcquireInputEx(bool state)
3306 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3307 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3309 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3311 guiApp.acquiredWindow = state ? this : null;
3314 SetMouseRangeToClient();
3315 guiApp.interfaceDriver.SetMouseCursor((SystemCursor)-1);
3320 SelectMouseCursor();
3322 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3326 // --- Window activation ---
3327 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3330 if(!parent || !parent.style.inactive)
3332 Window parent = this.parent;
3335 if(rootWindow == this)
3336 Log(active ? "active\n" : "inactive\n");
3339 // Testing this here...
3340 if(!parent || parent == guiApp.desktop || parent.active)
3342 this.active = active;
3345 // TESTING THIS HERE
3346 UpdateDecorations();
3347 if(result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master)
3348 result = NotifyActivate(master, this, active, previous);
3351 this.active = !active;
3356 if(!parent || parent == guiApp.desktop || parent.active)
3358 this.active = active;
3360 AcquireInputEx(active);
3365 if(guiApp.caretOwner)
3369 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3370 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3371 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3372 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3374 guiApp.caretOwner.Update(extent);
3377 if(visible || !guiApp.caretOwner)
3378 guiApp.caretOwner = this;
3379 UpdateCaret(false, false);
3385 this.active = false;
3387 AcquireInputEx(active);
3389 if(!active && guiApp.caretOwner == this)
3391 UpdateCaret(false, true);
3392 guiApp.caretOwner = null;
3393 guiApp.interfaceDriver.SetCaret(0,0,0);
3394 guiApp.caretEnabled = false;
3399 if(!active && parent && parent.activeChild && parent.activeChild != this)
3400 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3406 if(!active && menuBar)
3409 menuBar.OnActivate(false, null, &goOn, true);
3410 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3415 Window aChild = activeChild;
3417 if(!aChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3429 void ConsequentialMouseMove(bool kbMoving)
3433 if(kbMoving || !guiApp.windowMoving)
3437 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3439 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3441 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3442 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3448 bool IsDescendantOf(Window ancestor)
3451 for(window = this; window && window != ancestor; window = window.parent);
3452 return window == ancestor;
3455 bool IsSlaveOf(Window master)
3458 for(window = this; window && window != master; window = window.master);
3459 return window == master;
3462 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3466 if(this && !destroyed /*&& state != Hidden*/)
3468 Window swap = externalSwap;
3476 if(activateParent &&
3477 (parent.activeChild != this ||
3478 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3479 active && _isModal &&
3480 parent != master && master)
3481 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3487 bool real = parent.activeChild != this;
3489 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3490 if(/*activateParent && */guiApp.interimWindow &&
3491 !IsDescendantOf(guiApp.interimWindow) &&
3492 !IsSlaveOf(guiApp.interimWindow))
3494 Window interimWindow = guiApp.interimWindow;
3495 while(interimWindow && interimWindow != this)
3497 Window master = interimWindow.master;
3499 guiApp.interimWindow = null;
3500 if(guiApp.caretOwner)
3501 guiApp.caretOwner.UpdateCaret(false, false);
3503 incref interimWindow;
3504 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3509 delete interimWindow;
3510 interimWindow = (master && master.style.interim) ? master : null;
3515 guiApp.interimWindow = this;
3516 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3517 guiApp.caretEnabled = false;*/
3518 UpdateCaret(false, true);
3523 bool acquireInput = false;
3525 parent.activeChild &&
3526 parent.activeChild.state == maximized &&
3527 parent != guiApp.desktop;
3529 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3534 swap = parent.activeChild;
3535 if(swap && swap.destroyed) swap = null;
3536 if(swap && swap != this)
3539 if(!swap.PropagateActive(false, this, &goOn, true))
3540 swap = parent.activeChild;
3551 if(!parent || parent.activeChild != this || style.interim)
3554 result = PropagateActive(true, swap, &goOn, true);
3555 if(!result && !goOn)
3560 acquireInput = true;
3564 if(style.hasMaximize && parent != guiApp.desktop)
3567 SetState(maximized, false, 0);
3568 else if(state != maximized)
3571 for(child = parent.children.first; child; child = child.next)
3573 if(this != child && child.state == maximized)
3574 child.SetState(normal, false, 0);
3581 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3583 Window previous = parent.activeClient;
3584 parent.activeChild = this;
3585 if(!style.nonClient /*&& style.isActiveClient*/)
3589 if(style.isActiveClient)
3590 parent.activeClient = this;
3591 // Moved UpdateActiveDocument inside hidden check
3592 // To prevent activating previous window while creating a new one
3593 // (It was messing up the privateModule in the CodeEditor)
3594 parent.UpdateActiveDocument(previous);
3600 //if(!style.isRemote)
3602 if(rootWindow != this)
3604 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3605 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3607 else if(!guiApp.fullScreenMode)
3609 Window modalRoot = FindModal();
3610 if(!modalRoot) modalRoot = this;
3611 if(!modalRoot.isForegroundWindow)
3613 modalRoot.isForegroundWindow = true;
3614 // To check : Why is parent null?
3615 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3617 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3619 modalRoot.isForegroundWindow = false;
3624 if(result && real && (!style.inactive || moveInactive) && parent)
3626 Window last = parent.children.last;
3628 if(!style.stayOnTop)
3629 for(; last && last.style.stayOnTop; last = last.prev);
3631 parent.children.Move(this, last);
3633 // Definitely don't want that: why not?
3637 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3643 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3650 parent.activeChild = null;
3651 if(!style.nonClient /*&& style.isActiveClient*/)
3653 Window previous = parent.activeClient;
3654 if(style.isActiveClient)
3655 parent.activeClient = null;
3656 parent.UpdateActiveDocument(previous);
3660 if(this == guiApp.interimWindow)
3662 guiApp.interimWindow = null;
3663 if(guiApp.caretOwner)
3664 guiApp.caretOwner.UpdateCaret(false, false);
3666 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3673 if(!active || !swap)
3674 UpdateDecorations();
3676 swap.UpdateDecorations();
3678 if(active && rootWindow != this)
3679 ConsequentialMouseMove(false);
3686 // --- Input Messages ---
3687 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3689 static bool reEntrancy = false;
3690 if(reEntrancy) return;
3694 guiApp.cursorUpdate = true;
3695 if(guiApp.windowScrolling && !consequential)
3697 guiApp.windowScrolling.SetScrollPosition(
3698 (guiApp.windowScrolling.sbh) ?
3699 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3700 (guiApp.windowScrolling.sbv) ?
3701 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3703 if(guiApp.windowMoving)
3705 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3707 Window window = guiApp.windowMoving;
3709 int w = window.size.w;
3710 int h = window.size.h;
3715 rx = mouseX - guiApp.windowMovingStart.x;
3716 ry = mouseY - guiApp.windowMovingStart.y;
3719 window.GetDecorationsSize(&ew, &eh);
3721 if(guiApp.windowIsResizing)
3723 x = window.scrolledPos.x;
3724 y = window.scrolledPos.y;
3728 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3729 rx = guiApp.windowResizingBefore.w - aw;
3730 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3731 w = guiApp.windowResizingBefore.w - rx;
3735 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3736 ry = guiApp.windowResizingBefore.h - ah;
3737 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3738 ry = Max(ry, -guiApp.windowMovingBefore.y);
3739 h = guiApp.windowResizingBefore.h - ry;
3741 if(guiApp.resizeEndX)
3743 w = guiApp.windowResizingBefore.w + rx;
3746 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3754 w = Max(w, window.minSize.w);
3755 h = Max(h, window.minSize.h);
3756 w = Min(w, window.maxSize.w);
3757 h = Min(h, window.maxSize.h);
3759 if(!window.OnResizing(&w, &h))
3761 w = window.clientSize.w;
3762 h = window.clientSize.h;
3765 w = Max(w, window.skinMinSize.w);
3766 h = Max(h, window.skinMinSize.h);
3773 SNAPDOWN(w, textCellW);
3774 SNAPDOWN(h, textCellH);
3779 aw = Max(w,window.skinMinSize.w);
3780 rx = guiApp.windowResizingBefore.w - aw;
3781 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3782 w = guiApp.windowResizingBefore.w - rx;
3786 ah = Max(h,window.skinMinSize.h);
3787 ry = guiApp.windowResizingBefore.h - ah;
3788 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3789 ry = Max(ry, -guiApp.windowMovingBefore.y);
3790 h = guiApp.windowResizingBefore.h - ry;
3795 if(!guiApp.windowIsResizing || guiApp.resizeX)
3796 x = guiApp.windowMovingBefore.x + rx;
3797 if(!guiApp.windowIsResizing || guiApp.resizeY)
3798 y = guiApp.windowMovingBefore.y + ry;
3800 if(!guiApp.windowIsResizing)
3803 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
3805 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
3806 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
3807 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
3808 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
3812 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
3813 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
3819 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
3821 if(!window.OnMoving(&x, &y, w, h))
3823 x = window.scrolledPos.x;
3824 y = window.scrolledPos.y;
3830 SNAPDOWN(x, textCellW);
3831 SNAPDOWN(y, textCellH);
3834 if(!window.style.nonClient)
3836 if(!window.style.fixed /*|| window.style.isDocument*/)
3838 if(!window.style.dontScrollHorz)
3839 x += window.parent.scroll.x;
3840 if(!window.style.dontScrollVert)
3841 y += window.parent.scroll.y;
3845 // Break the anchors for moveable/resizable windows
3846 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
3847 if(window.style.fixed)
3849 if(window.state == normal)
3851 window.normalAnchor = Anchor { left = x, top = y };
3852 window.normalSizeAnchor = SizeAnchor { { w, h } };
3853 window.anchored = false;
3857 window.stateAnchor = Anchor { left = x, top = y };
3858 window.stateSizeAnchor = SizeAnchor { { w, h } };
3860 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
3861 // TOCHECK: Investigate why the following only redraws the scrollbars
3862 //window.Position(x, y, w, h, false, true, true, true, false, true);
3864 guiApp.movingLast.x = mouseX;
3865 guiApp.movingLast.y = mouseY;
3871 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
3874 bool wasMoving = guiApp.windowMoving ? true : false;
3875 bool wasScrolling = guiApp.windowScrolling ? true : false;
3877 while(result && w != this)
3879 Window msgWindow = GetAtPosition(x,y, false, true, w);
3880 Window trueWindow = GetAtPosition(x,y, false, false, w);
3881 bool windowDragged = false;
3886 window = (w && !w.disabled) ? w : null;
3888 if(trueWindow) incref trueWindow;
3890 if(consequential) mods->isSideEffect = true;
3892 UpdateMouseMove(x, y, consequential);
3894 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
3896 if(!guiApp.windowCaptured.isEnabled)
3897 guiApp.windowCaptured.ReleaseCapture();
3899 window = guiApp.windowCaptured;
3902 if(trueWindow && activate &&
3903 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3904 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3905 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3906 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3908 if(mods->alt && !mods->ctrl && !mods->shift)
3910 Window moved = trueWindow;
3911 for(moved = trueWindow; moved; moved = moved.parent)
3912 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3917 windowDragged = true;
3919 // Cancel the ALT menu toggling...
3920 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
3925 if(window && activate &&
3926 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3927 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3928 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3929 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3931 Window modalWindow = window.FindModal();
3933 /*if(mods->alt && !mods->shift && !mods->ctrl)
3935 Window moved = window;
3936 for(moved = window; moved; moved = moved.parent)
3937 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3942 windowDragged = true;
3944 // Cancel the ALT menu toggling...
3945 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
3951 Window activateWindow = modalWindow ? modalWindow : window;
3952 if(activateWindow && !activateWindow.isRemote)
3954 bool doActivation = true;
3955 //bool needToDoActivation = false;
3956 Window check = activateWindow;
3958 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
3960 if(!check.style.inactive)
3962 //needToDoActivation = true;
3964 doActivation = false;
3969 if(!needToDoActivation)
3970 doActivation = false;
3973 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
3974 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
3976 // Let the OnLeftButtonDown do the activating instead
3977 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
3985 incref activateWindow;
3986 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
3988 delete activateWindow;
3992 if(activateWindow._refCount == 1)
3994 delete activateWindow;
3998 delete activateWindow;
4000 mods->isActivate = true;
4004 if(!modalWindow && window && !window.destroyed)
4006 if(!guiApp.windowCaptured || windowDragged)
4008 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
4010 bool moving = ((window.state != maximized &&
4011 window.IsMouseMoving(
4012 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4013 || (guiApp.windowMoving && !guiApp.windowIsResizing);
4015 if(!moving && window.IsMouseResizing(
4016 x - window.absPosition.x,
4017 y - window.absPosition.y,
4018 window.size.w, window.size.h,
4019 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
4021 guiApp.windowIsResizing = true;
4022 guiApp.windowResizingBefore.w = window.size.w;
4023 guiApp.windowResizingBefore.h = window.size.h;
4025 if(guiApp.windowIsResizing || windowDragged || moving)
4028 guiApp.windowMoving = window;
4029 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4030 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4031 guiApp.windowMovingBefore.x = window.position.x;//s;
4032 guiApp.windowMovingBefore.y = window.position.y;//s;
4033 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4034 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4037 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4039 if(window.style.fixed &&
4041 window.IsMouseMoving(
4042 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4044 window.ShowSysMenu(x, y);
4048 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4050 if(window.sbv || window.sbh)
4053 guiApp.windowScrolling = window;
4054 guiApp.windowScrollingStart.x = x;
4055 guiApp.windowScrollingStart.y = y;
4056 guiApp.windowScrollingBefore.x = window.scroll.x;
4057 guiApp.windowScrollingBefore.y = window.scroll.y;
4060 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4062 if(window.style.hasMaximize &&
4063 window.IsMouseMoving(
4064 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4067 (window.state == maximized) ? normal : maximized, false, *mods);
4075 if(guiApp.windowMoving)
4077 if(guiApp.windowMoving.parent)
4079 if(guiApp.windowMoving.style.nonClient)
4080 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4082 guiApp.windowMoving.parent.SetMouseRangeToClient();
4086 window.UpdateDecorations();
4089 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4091 // Log("\n*** LEFT BUTTON UP ***\n");
4092 if(guiApp.windowMoving)
4093 guiApp.windowMoving.StopMoving();
4095 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4097 if(guiApp.windowScrolling)
4099 Window windowScrolling = guiApp.windowScrolling;
4100 guiApp.windowScrolling = null;
4101 windowScrolling.ReleaseCapture();
4105 if(!result || (window && window.destroyed)) window = null;
4107 if(window && window.FindModal())
4110 if(trueWindow && trueWindow.FindModal())
4118 msgWindow = GetAtPosition(x,y, true, false);
4120 msgWindow.SelectMouseCursor();
4123 if(guiApp.windowCaptured || trueWindow)
4125 Window prevWindow = guiApp.prevWindow;
4126 if(guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4128 guiApp.prevWindow.mouseInside = false;
4129 guiApp.prevWindow = null;
4131 // Eventually fix this not to include captured?
4132 if(!prevWindow.OnMouseLeave(*mods))
4135 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4137 Box box = trueWindow.box;
4138 box.left += trueWindow.absPosition.x;
4139 box.right += trueWindow.absPosition.x;
4140 box.top += trueWindow.absPosition.y;
4141 box.bottom += trueWindow.absPosition.y;
4143 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4145 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4146 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4148 overX = Max(Min(overX, 32767),-32768);
4149 overY = Max(Min(overY, 32767),-32768);
4151 trueWindow.mouseInside = true;
4152 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4156 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4157 guiApp.prevWindow = trueWindow;
4159 guiApp.prevWindow = null;
4161 SelectMouseCursor();
4163 if(window && !guiApp.windowMoving && !wasMoving && !wasScrolling)
4165 int clientX = x - (window.absPosition.x + window.clientStart.x);
4166 int clientY = y - (window.absPosition.y + window.clientStart.y);
4168 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4170 clientX = Max(Min(clientX, 32767),-32768);
4171 clientY = Max(Min(clientY, 32767),-32768);
4173 MouseMethod = (void *)window._vTbl[method];
4175 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4178 if(!MouseMethod(window, clientX, clientY, *mods))
4185 if(result && w && w.clickThrough && w.parent)
4190 if(!result || !w || !w.clickThrough)
4197 // --- Mouse cursor management ---
4199 bool KeyMessage(uint method, Key key, unichar character)
4204 if(guiApp.interimWindow)
4205 this = guiApp.interimWindow;
4208 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4212 if(!style.inactive || rootWindow != this)
4214 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4215 Window modalWindow = FindModal();
4216 Window interimMaster = master ? master.rootWindow : null;
4220 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4221 status = OnSysKeyDown(key, character);
4222 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4223 status = OnSysKeyHit(key, character);
4224 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4225 status = OnSysKeyUp(key, character);
4232 // Process Key Message for Internal UI Keyboard actions
4233 if(status && !destroyed && menuBar && state != minimized)
4236 if((SmartKey)key != alt)
4237 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4240 SmartKey sk = (SmartKey) key;
4241 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4243 status = menuBar.KeyMessage(method, key, character);
4248 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4249 menuBar.OnKeyHit(escape, 0);
4251 if(!menuBar.focus && guiApp.caretOwner)
4252 guiApp.caretOwner.UpdateCaret(true, false);
4255 if(!destroyed && status)
4257 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4261 case left: case up: case right: case down:
4262 if(guiApp.windowMoving == this)
4265 int w = guiApp.windowMoving.size.w;
4266 int h = guiApp.windowMoving.size.h;
4267 int x = guiApp.windowMoving.scrolledPos.x;
4268 int y = guiApp.windowMoving.scrolledPos.y;
4272 if(key == down || key == up)
4273 step = Max(step, textCellH);
4275 step = Max(step, textCellW);
4278 if(guiApp.windowIsResizing)
4282 case left: w-=step; break;
4283 case right: w+=step; break;
4284 case up: h-=step; break;
4285 case down: h+=step; break;
4292 case left: x-=step; break;
4293 case right: x+=step; break;
4294 case up: y-=step; break;
4295 case down: y+=step; break;
4299 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4300 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4302 if(!guiApp.windowIsResizing || guiApp.resizeX)
4303 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4305 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4307 if(!guiApp.windowIsResizing || guiApp.resizeY)
4308 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4310 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4312 guiApp.interfaceDriver.SetMousePosition(x, y);
4313 ConsequentialMouseMove(true);
4321 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4323 guiApp.windowMoving.StopMoving();
4324 ConsequentialMouseMove(false);
4332 ShowSysMenu(absPosition.x, absPosition.y);
4340 if(!destroyed && status && state != minimized)
4342 // Process all the way down the children
4343 if(activeChild && !activeChild.disabled)
4345 status = activeChild.KeyMessage(method, key, character);
4347 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4348 key.code != left && key.code != right && key.code != up && key.code != down)
4350 status = activeClient.KeyMessage(method, key, character);
4354 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4356 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4357 // && defaultControl != activeChild)
4359 delete previousActive;
4360 previousActive = activeChild;
4361 if(previousActive) incref previousActive;
4363 ConsequentialMouseMove(false);
4364 if((defaultControl.active ||
4365 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4366 defaultControl.KeyMessage(method, defaultKey, character);
4372 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4374 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4381 ShowSysMenu(absPosition.x, absPosition.y);
4388 if(this != guiApp.desktop)
4390 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4392 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4394 MenuMoveOrSize(key.shift, true);
4398 else if(guiApp.windowMoving)
4400 guiApp.windowMoving.StopMoving();
4401 ConsequentialMouseMove(false);
4409 if(!destroyed && status && state != minimized)
4411 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4415 case tab: case shiftTab:
4417 Window cycleParent = this;
4418 if(this == guiApp.interimWindow && !master.style.interim && !cycleParent.style.tabCycle)
4419 cycleParent = master.parent;
4421 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4423 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4425 Window child = cycleParent.activeChild;
4427 // Scroll the window to include the active control
4429 if(cycleParent.sbh && !child.style.dontScrollHorz)
4431 if(child.scrolledPos.x < 0)
4432 cycleParent.sbh.Action(Position,
4433 cycleParent.scroll.x + child.scrolledPos.x, 0);
4434 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4435 cycleParent.sbh.Action(Position,
4436 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4438 if(cycleParent.sbv && !child.style.dontScrollVert)
4440 if(child.scrolledPos.y < 0)
4441 cycleParent.sbv.Action(Position,
4442 cycleParent.scroll.y + child.scrolledPos.y, 0);
4443 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4444 cycleParent.sbv.Action(Position,
4445 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4448 cycleParent.ConsequentialMouseMove(false);
4454 case f6: case shiftF6:
4455 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4457 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4458 if(parent == guiApp.desktop)
4459 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4464 if(style.tabCycle ||
4465 CycleChildren(key.shift, true, false, true))
4473 // mIRC Style Window Shortcuts
4474 case alt1: case alt2: case alt3: case alt4: case alt5:
4475 case alt6: case alt7: case alt8: case alt9: case alt0:
4480 for(document = children.first; document; document = document.next)
4482 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4484 if(document == activeChild)
4486 if(document.state == minimized)
4487 document.SetState(normal, false, key);
4490 document.SetState(minimized, false, key);
4491 CycleChildren(false, true, false);
4496 if(activeChild.state == maximized && document.style.hasMaximize)
4497 document.SetState(maximized, false, key);
4498 else if(document.state == minimized)
4499 document.SetState(normal, false, key);
4500 document.Activate();
4515 if(!destroyed && status)
4517 if(state == minimized)
4522 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4524 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4526 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4527 previousActive.ActivateEx(true, false, false, true, null, null);
4528 delete previousActive;
4534 if(!destroyed && status)
4536 status = ProcessHotKeys(method, key, character);
4538 if(!destroyed && status && !modalWindow && state != minimized)
4541 status = KeyMethod(this, key, character);
4542 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4543 status = OnKeyHit(key, character);
4544 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4546 bool result = false;
4549 case ctrlUp: case ctrlDown:
4550 if(sbv && !guiApp.windowScrolling)
4551 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4553 case wheelUp: case wheelDown:
4554 if(sbv && !guiApp.windowScrolling)
4556 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4557 // Do we want to do a consequential move regardless of result in this case?
4558 ConsequentialMouseMove(false);
4561 case ctrlPageUp: case ctrlPageDown:
4562 if(sbh && !guiApp.windowScrolling)
4563 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4568 ConsequentialMouseMove(false);
4573 if(status && !destroyed && menuBar && state != minimized)
4574 status = menuBar.KeyMessage(method, key, character);
4576 if(style.interim && /*destroyed && */status && interimMaster)
4578 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4579 status = interimMaster.KeyMessage(method, key, character);
4586 bool ProcessHotKeys(uint method, Key key, unichar character)
4591 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4592 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4593 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4595 Window hotKeyWindow = hotKey.window;
4596 Window parent = hotKeyWindow.parent;
4597 Window prevActiveWindow = activeChild;
4599 // Don't process non-visible buttons, but make an exception for the Alt-F4 with Native Decorations turned on
4600 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1] )))
4603 if(prevActiveWindow) incref prevActiveWindow;
4604 incref hotKeyWindow;
4605 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient)
4606 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4609 delete hotKeyWindow;
4610 delete prevActiveWindow;
4614 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4615 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4616 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4618 // ********* WORKING ON THIS ***********
4619 if(prevActiveWindow && !guiApp.interimWindow)
4620 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4623 else if(hotKeyWindow.style.inactive)
4624 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4626 delete prevActiveWindow;
4627 delete hotKeyWindow;
4628 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4629 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4633 if(status && tabCycle)
4636 for(child = children.first; child; child = child.next)
4638 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4649 // --- Windows and graphics initialization / termination ---
4650 bool SetupRoot(void)
4654 // Setup relationship with outside world (bb root || !bb)
4655 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4656 (_displayDriver && dispDriver != parent.dispDriver))
4660 tempExtents = new0 Extent[4];
4665 /*if(guiApp.fullScreenMode)
4666 rootWindow = guiApp.desktop;
4668 //rootWindow = parent.created ? parent.rootWindow : null;
4669 rootWindow = parent.rootWindow;
4672 against = &parent.box;
4674 against = &parent.clientArea;
4677 for(child = children.first; child; child = child.next)
4680 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
4683 bool Setup(bool positionChildren)
4685 bool result = false;
4688 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && dispDriver != parent.dispDriver))))
4690 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
4691 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
4693 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
4695 // This was here, is it really needed?
4696 //guiApp.interfaceDriver.ActivateRootWindow(this);
4700 displaySystem = DisplaySystem {};
4701 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
4703 delete displaySystem;
4708 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData };
4709 if(display.Create(displaySystem, windowHandle))
4716 guiApp.interfaceDriver.SetIcon(this, icon);
4718 else if(this != guiApp.desktop)
4720 display = rootWindow ? rootWindow.display : null;
4726 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
4727 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
4729 for(child = children.first; child; child = child.next)
4731 if(child.created && !child.Setup(false))
4737 bool SetupDisplay(void)
4739 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
4740 if(is3D) return Window3D_SetupDisplay(this); else
4747 class_data void ** pureVTbl;
4749 bool LoadGraphics(bool creation, bool resetAnchors)
4751 bool result = false;
4752 bool success = false;
4754 WindowState stateBackup = state;
4757 if(!rootWindow.created)
4761 if(((subclass(Window))_class).pureVTbl)
4763 if(_vTbl == _class._vTbl)
4765 _vTbl = ((subclass(Window))_class).pureVTbl;
4770 for(m = 0; m < _class.vTblSize; m++)
4772 if(_vTbl[m] == _class._vTbl[m])
4773 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
4777 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
4779 if(_vTbl == ((subclass(Window))_class).pureVTbl)
4781 _vTbl = _class._vTbl;
4786 for(m = 0; m < _class.vTblSize; m++)
4788 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
4789 _vTbl[m] = _class._vTbl[m];
4794 if(guiApp.fullScreenMode || this != guiApp.desktop)
4796 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
4802 display.Lock(false);
4803 if(rootWindow == this)
4805 // Set Color Palette
4806 display.SetPalette(palette, true);
4810 if(guiApp.fullScreenMode && this == guiApp.desktop)
4815 for(c=0; c<SystemCursor::enumSize; c++)
4816 if(!guiApp.systemCursors[c].bitmap)
4818 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
4819 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
4820 if(guiApp.systemCursors[c].bitmapName)
4822 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
4823 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
4824 if(guiApp.systemCursors[c].bitmap)
4825 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
4830 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
4832 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
4833 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
4835 cursor.bitmap.paletteShades = cursor.paletteShades;
4839 guiApp.cursorUpdate = true;
4842 ConsequentialMouseMove(false);
4848 // Load Window Graphic Resources
4851 if(usedFont == setFont || usedFont == window.systemFont)
4852 RemoveResource(usedFont);
4855 RemoveResource(setFont); // TESTING setFont instead of usedFont);
4858 RemoveResource(systemFont);
4861 RemoveResource(captionFont);
4863 for(ptr = resources.first; ptr; ptr = ptr.next)
4865 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
4868 AddResource(setFont);
4870 AddResource(systemFont);
4872 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
4879 //if(master && master.font)
4880 if(parent && parent.font)
4884 faceName = parent.font.faceName,
4885 size = parent.font.size,
4886 bold = parent.font.bold,
4887 italic = parent.font.italic,
4888 underline = parent.font.underline
4890 //font = parent.font;
4891 watch(parent) { font { } };
4894 font = guiApp.currentSkin.SystemFont();
4901 captionFont = guiApp.currentSkin.CaptionFont();
4902 AddResource(captionFont);
4904 if(OnLoadGraphics())
4910 //SetScrollLineStep(sbStep.x, sbStep.y);
4912 if(this != guiApp.desktop)
4916 normalAnchor = anchor;
4917 normalSizeAnchor = sizeAnchor;
4920 // Break the anchors for moveable/resizable windows
4922 if(style.fixed && style.isDocument)
4924 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
4936 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
4937 stateSizeAnchor = SizeAnchor {};
4942 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
4947 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
4948 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
4951 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
4955 stateAnchor = normalAnchor;
4956 stateSizeAnchor = normalSizeAnchor;
4959 position = Point { };
4960 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
4971 if(Position(x, y, w, h, true, false, true, true, true, true))
4973 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
4976 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
4993 success = result = true;
4996 if(!creation && result)
4998 // Load menu bar first because sys buttons are on it...
5001 if(!menuBar.LoadGraphics(false, resetAnchors))
5007 for(child = children.first; child; child = child.next)
5009 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
5016 CreateSystemChildren();
5020 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5023 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5028 //guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, caption);
5029 guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, class.name);
5032 // Do this here to avoid problems on Windows
5033 if(stateBackup == maximized)
5034 property::state = maximized;
5038 void UnloadGraphics(bool destroyWindows)
5042 // Free children's graphics
5043 for(child = children.first; child; child = child.next)
5044 child.UnloadGraphics(destroyWindows);
5047 display.Lock(false);
5050 if(guiApp.fullScreenMode && this == guiApp.desktop)
5055 for(c=0; c<SystemCursor::enumSize; c++)
5056 if(guiApp.systemCursors[c].bitmap)
5057 delete guiApp.systemCursors[c].bitmap;
5059 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5060 delete cursor.bitmap;
5062 guiApp.cursorBackground.Free();
5065 if(display && display.displaySystem)
5069 for(ptr = resources.first; ptr; ptr = ptr.next)
5073 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5078 // Free window graphics
5081 // Free skin graphics
5082 if(rootWindow == this)
5084 DisplaySystem displaySystem = display.displaySystem;
5087 display.driverData = null;
5088 display.displaySystem = null;
5092 if(displaySystem && !displaySystem.numDisplays && !is3D)
5093 delete displaySystem;
5102 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5103 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5105 if(this == guiApp.desktop || parent == guiApp.desktop)
5107 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5108 guiApp.interfaceDriver.DestroyRootWindow(this);
5112 // --- Window Hiding ---
5114 void SetVisibility(bool state)
5116 bool visible = (style.hidden || !created) ? false : state;
5117 if(visible != this.visible)
5121 this.visible = visible;
5122 for(child = children.first; child; child = child.next)
5123 child.SetVisibility(visible);
5125 ConsequentialMouseMove(false);
5126 if(parent && !nonClient) parent.OnChildVisibilityToggled(this, visible);
5130 // --- Windows and graphics initialization / termination ---
5132 bool DisplayModeChanged(void)
5134 bool result = false;
5135 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5137 guiApp.modeSwitching = true;
5138 UnloadGraphics(false);
5140 if(LoadGraphics(false, false))
5142 guiApp.modeSwitching = false;
5147 // --- Window updates system ---
5149 void UpdateDirty(Box updateBox)
5151 if(!manageDisplay) { OnRedraw(null);return; }
5154 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5157 if(display.flags.flipping)
5160 rootWindow.UpdateDisplay();
5163 UpdateBackDisplay(updateBox);
5165 if(guiApp.fullScreenMode)
5167 guiApp.cursorUpdate = true;
5168 guiApp.PreserveAndDrawCursor();
5170 if(guiApp.fullScreenMode)
5171 guiApp.RestoreCursorBackground();
5177 // This function is strictly called as a result of system window activation
5178 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5181 Window interimMaster = null;
5182 Window interimWindow = guiApp.interimWindow;
5183 if(interimWindow && interimWindow.master)
5184 interimMaster = interimWindow.master.rootWindow;
5186 if(active && state == minimized) // && (!window.nativeDecorations || window.rootWindow != window)
5187 // SetState(normal, false, 0);
5188 SetState(lastState, false, 0);
5190 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5194 /* WTH is this doing here?
5195 while(swap && swap.activeChild)
5197 swap = swap.activeChild;
5200 // TESTING THIS BEFORE...
5201 if(interimWindow && this == interimMaster)
5205 // Window interimSwap = this;
5206 Window menuBar = this.menuBar;
5207 if(menuBar && interimWindow.master == menuBar)
5210 while(interimSwap && interimSwap.activeChild)
5211 interimSwap = interimSwap.activeChild;
5213 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5214 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5216 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5217 //result = ActivateEx(true, true, false, activateRoot, window, null);
5222 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5223 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5225 if(interimWindow == this && interimMaster && !active)
5227 while(interimMaster && interimMaster.interim && interimMaster.master)
5229 // printf("Going up one master %s\n", interimMaster._class.name);
5230 interimMaster = interimMaster.master.rootWindow;
5232 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5233 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5239 bool DestroyEx(int returnCode)
5242 Timer timer, nextTimer;
5244 OldLink prevOrder = null;
5245 Window client = null;
5247 if(parent) stopwatching(parent, font);
5249 // if(window.modalSlave) return false;
5250 if(destroyed || !created)
5257 OldLink slave = master.slaves.FindLink(this);
5258 master.slaves.Delete(slave);
5261 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5267 this.returnCode = (DialogResult)returnCode;
5269 AcquireInput(false);
5274 master.hotKeys.Delete(hotKey);
5278 if(guiApp.prevWindow == this)
5280 guiApp.prevWindow = null;
5283 if(guiApp.caretOwner == this)
5285 guiApp.interfaceDriver.SetCaret(0,0,0);
5286 UpdateCaret(false, true);
5287 guiApp.caretEnabled = false;
5292 parent.childrenCycle.Remove(cycle);
5296 OldLink tmpPrev = order.prev;
5297 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5298 prevOrder = tmpPrev;
5301 client = tmpPrev ? tmpPrev.data : null;
5302 if(client == this) { client = null; break; }
5303 if(client && (client.style.hidden || client.destroyed || !client.created))
5304 tmpPrev = client.order.prev;
5308 prevOrder = tmpPrev;
5313 // If this window can be an active client, make sure the next window we activate can also be one
5314 if(!style.nonClient && style.isActiveClient)
5316 tmpPrev = prevOrder;
5319 client = tmpPrev ? tmpPrev.data : null;
5320 if(client == this) { client = null; break; }
5321 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5322 tmpPrev = client.order.prev;
5326 prevOrder = tmpPrev;
5330 if(client && client.style.hidden) client = null;
5332 // parent.childrenOrder.Remove(order);
5335 if(parent && style.isActiveClient && visible)
5337 if(state == minimized) parent.numIcons--;
5338 parent.numPositions--;
5341 // TESTING THIS HERE!
5345 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5346 // to create a window inside a rootwindow that's being destroyed)
5347 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5349 if(master && !master.destroyed /*&&
5350 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5352 if(master.defaultControl == this)
5353 master.defaultControl = null;
5355 if(parent && !parent.destroyed /*&&
5356 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5358 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5360 if(order && prevOrder && prevOrder.data != this && active)
5362 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5364 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5365 if(parent.activeClient == this)
5367 parent.activeClient = null;
5368 parent.UpdateActiveDocument(null);
5373 if(guiApp.interimWindow == this)
5376 PropagateActive(false, null, &goOn, true);
5380 //if(window.parent.activeChild == window)
5381 parent.activeChild = null;
5382 if(!style.nonClient /*&& style.isActiveClient*/)
5384 Window previous = parent.activeClient;
5385 if(style.isActiveClient)
5386 parent.activeClient = null;
5387 parent.UpdateActiveDocument(previous);
5392 else if(parent.activeClient == this)
5394 parent.activeClient = client;
5395 parent.UpdateActiveDocument(this);
5399 if(guiApp.interimWindow == this)
5401 guiApp.interimWindow = null;
5402 if(guiApp.caretOwner)
5404 Window desktop = guiApp.desktop;
5405 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5406 guiApp.caretOwner.UpdateCaret(false, false);
5411 if(_isModal && master && master.modalSlave == this)
5412 master.modalSlave = null;
5416 if(!guiApp.caretOwner && parent.caretSize)
5418 guiApp.caretOwner = parent;
5419 parent.UpdateCaret(false, false);
5420 parent.Update(null);
5423 // Why was this commented out?
5424 GetRidOfVirtualArea();
5430 dirtyArea.Free(null);
5431 dirtyBack.Free(null);
5432 scrollExtent.Free(null);
5434 /* ATTEMPTING TO MOVE THAT ABOVE
5443 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5444 for(;(child = window.children.first);)
5446 for(; child && (child.destroyed || !child.created); child = child.next);
5455 UnloadGraphics(true);
5458 delete previousActive;
5461 // statusBar = null;
5464 if(master && !master.destroyed)
5466 //master.NotifyDestroyed(this, this.returnCode);
5467 NotifyDestroyed(master, this, this.returnCode);
5470 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5472 nextTimer = timer.next;
5473 if(timer.window == this)
5475 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5476 // timer.window = null;
5482 if(this == guiApp.windowMoving)
5485 if(guiApp.windowCaptured == this)
5487 //guiApp.windowCaptured = null;
5489 if(rootWindow != this && rootWindow)
5490 rootWindow.ConsequentialMouseMove(false);
5498 //for(child = children.first; next = child ? child.next : null, child; child = next)
5499 for(;(child = children.first); )
5501 for(; child && (child.destroyed || !child.created); child = child.next);
5511 /* // MOVED THIS UP...
5514 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5515 for(;(child = window.children.first); )
5517 for(; child && (child.destroyed || !child.created); child = child.next);
5526 while((slave = slaves.first))
5528 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5530 ((Window)slave.data).DestroyEx(0);
5535 if(guiApp.caretOwner == this)
5536 guiApp.caretOwner = null;
5538 sysButtons[0] = null;
5539 sysButtons[1] = null;
5540 sysButtons[2] = null;
5543 if(rootWindow != this)
5545 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5548 box.left -= parent.clientStart.x;
5549 box.top -= parent.clientStart.y;
5550 box.right -= parent.clientStart.x;
5551 box.bottom -= parent.clientStart.y;
5553 if(parent) parent.Update(box);
5558 OldLink slave = master.slaves.FindVoid(this);
5559 master.slaves.Delete(slave);
5565 parent.children.Remove(this);
5570 //autoCreate = false;
5573 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5574 if(((subclass(Window))_class).pureVTbl)
5576 if(_vTbl == _class._vTbl)
5578 _vTbl = ((subclass(Window))_class).pureVTbl;
5583 for(m = 0; m < _class.vTblSize; m++)
5585 if(_vTbl[m] == _class._vTbl[m])
5586 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5595 void SetStateEx(WindowState newState, bool activate)
5598 WindowState prevState = state;
5602 if(prevState != newState)
5603 lastState = prevState;
5605 if(rootWindow != this || !nativeDecorations)
5607 if(style.isActiveClient && !style.hidden && prevState == minimized)
5610 // This block used to be at the end of the function... moved it for flicker problem in X
5611 // ------------------------------------------------------
5615 stateAnchor = normalAnchor;
5616 stateSizeAnchor = normalSizeAnchor;
5619 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5620 stateSizeAnchor = SizeAnchor {};
5624 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5627 byte * idBuffer = new0 byte[size];
5629 for(child = parent.children.first; child; child = child.next)
5631 if(child != this && child.state == minimized)
5633 if(child.iconID > size - 2)
5635 idBuffer = renew0 idBuffer byte[size*2];
5636 memset(idBuffer + size, 0, size);
5639 idBuffer[child.iconID] = (byte)bool::true;
5642 for(c = 0; c<size; c++)
5647 if(style.isActiveClient && !style.hidden)
5650 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5651 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5655 // TOCHECK: Why was this here?
5656 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5657 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5658 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5660 Position(x, y, w, h, true, true, true, true, false, true);
5662 if(!style.inactive && !style.interim && this == parent.activeClient)
5663 parent.UpdateActiveDocument(null);
5666 CreateSystemChildren();
5667 // ------------------------------------------------------
5670 int GetPositionID(Window forChild)
5674 byte * idBuffer = new0 byte[size];
5677 for(child = children.first; child; child = child.next)
5679 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
5681 if(child.positionID > size - 2)
5683 idBuffer = renew0 idBuffer byte[size*2];
5684 memset(idBuffer + size, 0, size);
5687 idBuffer[child.positionID] = (byte)bool::true;
5690 for(c = 0; c<size; c++)
5697 // --- Window related graphics ---
5699 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
5701 palette = newPalette;
5702 if(rootWindow.display)
5703 rootWindow.display.SetPalette(palette, colorMatch);
5706 public bool AcquireInput(bool acquired)
5709 if(acquiredInput != acquired)
5711 if(active || (!visible && creationActivation == activate))
5712 result = AcquireInputEx(acquired);
5717 acquiredInput = acquired ? result : !result;
5722 void ListChildren(ListBox listBox)
5726 for(child = children.first; child; child = child.next)
5728 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
5730 DataRow row = listBox.AddRow();
5731 row.tag = (int)child;
5732 child.FigureCaption(caption);
5733 row.SetData(null, caption);
5738 void UpdateVisual(Box extent)
5740 if(guiApp.driver != null)
5742 if(guiApp.fullScreenMode && guiApp.desktop.display)
5744 guiApp.desktop.mutex.Wait();
5745 guiApp.desktop.display.Lock(true);
5748 if(guiApp.desktop.active)
5750 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
5752 if(guiApp.desktop.display.flags.flipping)
5753 guiApp.desktop.Update(null);
5754 guiApp.desktop.UpdateDisplay();
5755 guiApp.cursorUpdate = true;
5757 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
5759 guiApp.PreserveAndDrawCursor();
5760 // guiApp.desktop.display.ShowScreen();
5761 guiApp.cursorUpdate = false;
5762 guiApp.desktop.dirty = false;
5763 guiApp.RestoreCursorBackground();
5767 guiApp.desktop.display.Unlock();
5768 guiApp.desktop.mutex.Release();
5772 Window rootWindow = this.rootWindow;
5773 rootWindow.mutex.Wait();
5778 guiApp.SignalEvent();
5781 guiApp.waitMutex.Wait();
5782 guiApp.interfaceDriver.Lock(rootWindow);
5783 if(!rootWindow.style.hidden && rootWindow.dirty)
5785 if(rootWindow.display)
5787 rootWindow.UpdateDisplay();
5788 //rootWindow.display.ShowScreen(null);
5790 rootWindow.dirty = false;
5792 guiApp.interfaceDriver.Unlock(rootWindow);
5793 guiApp.waitMutex.Release();
5796 rootWindow.mutex.Release();
5801 void UnlockDisplay(void)
5803 guiApp.interfaceDriver.Unlock(rootWindow);
5806 void LockDisplay(void)
5808 guiApp.interfaceDriver.Lock(rootWindow);
5811 Surface GetSurface(Box box)
5813 return Redraw((box == null) ? this.box : box);
5816 void SetMousePosition(int x, int y)
5818 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
5822 void IntegrationActivate(bool active)
5824 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
5826 isForegroundWindow = true;
5827 ActivateEx(active, active, false, false, null, null);
5828 isForegroundWindow = false;
5833 Window QueryCapture(void)
5835 return guiApp.windowCaptured;
5838 int GetDocumentID(void)
5842 byte * idBuffer = new0 byte[size];
5845 for(child = children.first; child; child = child.next)
5847 if(child.style.isDocument)
5849 if(child.documentID-1 > size - 2)
5851 idBuffer = renew0 idBuffer byte[size*2];
5852 memset(idBuffer + size, 0, size);
5855 idBuffer[child.documentID-1] = 1;
5858 for(c = 0; c<size; c++)
5866 void SetInitSize(Size size)
5869 sizeAnchor.size = size;
5870 normalSizeAnchor = sizeAnchor;
5872 // Break the anchors for moveable/resizable windows
5873 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
5875 stateAnchor = normalAnchor;
5876 stateSizeAnchor = normalSizeAnchor;
5878 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5879 Position(x,y, w, h, true, true, true, true, false, true);
5883 void MenuMoveOrSize(bool resize, bool setCursorPosition)
5885 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
5887 guiApp.windowIsResizing = resize;
5888 guiApp.windowMoving = this;
5889 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
5890 if(guiApp.windowIsResizing)
5892 guiApp.windowMovingStart.x += size.w - 1;
5893 guiApp.windowMovingStart.y += size.h - 1;
5895 guiApp.windowMovingBefore = scrolledPos;
5896 guiApp.windowResizingBefore = size;
5897 guiApp.windowMoving.UpdateDecorations();
5898 if(guiApp.windowIsResizing)
5899 guiApp.resizeEndX = guiApp.resizeEndY = true;
5901 if(setCursorPosition)
5902 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
5906 guiApp.interfaceDriver.GetMousePosition(&x, &y);
5907 guiApp.windowMovingStart.x += x - absPosition.x;
5908 guiApp.windowMovingStart.y += y - absPosition.y;
5911 if(guiApp.windowMoving)
5913 if(guiApp.windowMoving.style.nonClient)
5914 guiApp.windowMoving.parent.SetMouseRangeToWindow();
5916 guiApp.windowMoving.parent.SetMouseRangeToClient();
5921 if(this == rootWindow)
5922 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
5930 bool result = false;
5934 else if(guiApp && guiApp.driver != null)
5936 void * systemParent = null;
5937 OldLink slaveHolder;
5939 bool visible = !style.hidden;
5943 systemParent = parent;
5944 parent = guiApp.desktop;
5946 last = parent ? parent.children.last : null;
5948 if((parent && parent != guiApp.desktop && !parent.created) ||
5949 (master && master != guiApp.desktop && !master.created))
5953 property::parent = guiApp.desktop;
5954 if(!master) master = parent;
5956 if(_isModal && master.modalSlave)
5957 property::master = master.modalSlave;
5961 parent.children.Remove(this);
5964 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
5965 if(slaveHolder.data == this)
5967 master.slaves.Delete(slaveHolder);
5972 if(parent == guiApp.desktop && !mutex)
5975 if(style.isDocument)
5978 parent.numDocuments--;
5979 documentID = parent.GetDocumentID();
5982 if(!style.stayOnTop)
5983 for(; last && last.style.stayOnTop; last = last.prev);
5985 parent.children.Insert((last == this) ? null : last, this);
5986 //parent.children.Add(this);
5989 dispDriver = parent.dispDriver;
5992 master.modalSlave = this;
5994 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
5999 master.slaves.Add(slaveHolder = OldLink { data = this });
6004 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
6006 if(style.isDefault && !master.defaultControl)
6007 master.defaultControl = this;
6009 stateAnchor = normalAnchor = anchor;
6010 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
6012 // TOCHECK: Why is this here?
6013 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
6014 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
6016 this.visible = false;
6017 style.hidden = true;
6020 // autoCreate = true;
6028 if(parent == guiApp.desktop)
6029 Log("LoadGraphics %s\n", caption);
6031 if(LoadGraphics(true, false))
6039 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6046 if(style.hasMenuBar /*&& menu*/)
6052 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6053 interim = false, inactive = true, nonClient = true, size.h = 24
6061 // Create the system buttons
6062 CreateSystemChildren();
6064 UpdateActiveDocument(null);
6066 if(style.isDocument)
6070 MenuItem item = menu.FindItem(MenuFileSave, 0);
6071 if(item) item.disabled = !modifiedDocument && fileName;
6076 if(parent == guiApp.desktop)
6077 Log("Preemptive SetState %s\n", caption);
6080 // Preemptive Set State to ensure proper anchoring
6081 SetStateEx(state, false);
6083 style.hidden = true;
6089 for(child = children.first; child; child = next)
6092 if(!child.created && (child.autoCreate || child.wasCreated))
6099 for(link = slaves.first; link; link = next)
6101 Window slave = link.data;
6103 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6112 if(parent == guiApp.desktop)
6113 Log("Real SetState %s\n", caption);
6116 if(isActiveClient && visible)
6118 parent.numPositions--;
6119 if(state == minimized) parent.numIcons--;
6122 // Real set state & activate for proper display & activation
6123 property::visible = visible;
6124 // SetState(state & 0x00000003, true, 0);
6129 /*if(rootWindow == this)
6130 guiApp.interfaceDriver.ActivateRootWindow(this);
6132 if(creationActivation == activate)
6133 ActivateEx(true, false, true, true, null, null);
6134 else if(creationActivation == flash)
6139 rootWindow.ConsequentialMouseMove(false);
6150 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6156 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6158 //style.hidden = true; // !visible;
6159 style.hidden = !visible;
6160 if(master.modalSlave == this)
6161 master.modalSlave = null;
6168 void WriteCaption(Surface surface, int x, int y)
6171 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6174 void Update(Box region)
6180 rootWindow = this.rootWindow;
6182 // rootWindow.mutex.Wait();
6183 if(!destroyed && visible && display)
6188 // Testing this to avoid repetitve full update to take time...
6189 if(dirtyArea.count == 1)
6191 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6192 if(item.box.left <= box.left &&
6193 item.box.top <= box.top &&
6194 item.box.right >= box.right &&
6195 item.box.bottom >= box.bottom)
6197 rootWindow.dirty = true;
6202 if(display.flags.flipping && !rootWindow.dirty)
6204 if(this == rootWindow)
6208 rootWindow.Update(null);
6213 rootWindow.dirty = true;
6218 realBox.left += clientStart.x;
6219 realBox.top += clientStart.y;
6220 realBox.right += clientStart.x;
6221 realBox.bottom += clientStart.y;
6227 if(realBox.right >= realBox.left &&
6228 realBox.bottom >= realBox.top)
6230 // if(!rootWindow.fullRender)
6231 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6233 for(child = children.first; child; child = child.next)
6238 box.left -= child.absPosition.x - absPosition.x;
6239 box.top -= child.absPosition.y - absPosition.y;
6240 box.right -= child.absPosition.x - absPosition.x;
6241 box.bottom -= child.absPosition.y - absPosition.y;
6242 if(box.right >= child.box.left && box.left <= child.box.right &&
6243 box.bottom >= child.box.top && box.top <= child.box.bottom)
6245 box.left -= child.clientStart.x;
6246 box.top -= child.clientStart.y;
6247 box.right -= child.clientStart.x;
6248 box.bottom -= child.clientStart.y;
6254 realBox.left += absPosition.x - rootWindow.absPosition.x;
6255 realBox.top += absPosition.y - rootWindow.absPosition.y;
6256 realBox.right += absPosition.x - rootWindow.absPosition.x;
6257 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6258 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6261 else if(this == guiApp.desktop)
6264 for(window = children.first; window; window = window.next)
6270 Box childBox = region;
6272 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6273 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6274 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6275 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6277 window.Update(childBox);
6280 window.Update(null);
6285 // rootWindow.mutex.Release();
6292 if(guiApp.windowCaptured != this)
6294 if(guiApp.windowCaptured)
6298 //Logf("Captured %s (%s)\n", caption, class.name);
6299 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6300 guiApp.windowCaptured = this;
6306 bool Destroy(int code)
6311 if(!destroyed && !CloseConfirmation(false)) return false;
6315 // TOCHECK: Should autoCreate be set to false here?
6326 void Move(int x, int y, int w, int h)
6328 normalAnchor = Anchor { left = x, top = y };
6329 normalSizeAnchor = SizeAnchor { size = { w, h } };
6331 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6333 if(destroyed) return;
6335 stateAnchor = normalAnchor;
6336 stateSizeAnchor = normalSizeAnchor;
6338 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6339 Position(x,y, w, h, true, true, true, true, false, true);
6343 DialogResult Modal(void)
6349 // FIXES MEMORY LEAK IF Create() FAILED
6355 void SetScrollArea(int width, int height, bool snapToStep)
6357 bool resize = false;
6360 int stepX = sbStep.x, stepY = sbStep.y;
6361 // Needed to make snapped down position match the skin's check of client area
6362 // against realvirtual
6365 SNAPDOWN(stepX, textCellW);
6366 SNAPDOWN(stepY, textCellH);
6367 stepX = Max(stepX, textCellW);
6368 stepY = Max(stepY, textCellH);
6370 if(scrollFlags.snapX)
6371 SNAPUP(width, stepX);
6372 if(scrollFlags.snapY)
6373 SNAPUP(height, stepY);
6376 reqScrollArea.w = width;
6377 reqScrollArea.h = height;
6378 noAutoScrollArea = (width > 0 || height > 0);
6380 UpdateScrollBars(true, true);
6383 void SetScrollPosition(int x, int y)
6386 sbh.Action(setPosition, x, 0);
6390 int seen = clientSize.w, total = reqScrollArea.w;
6392 if(scrollFlags.snapX)
6393 SNAPDOWN(seen, sbStep.x);
6395 if(!total) total = seen;
6396 range = total - seen + 1;
6397 range = Max(range, 1);
6399 if(x >= range) x = range - 1;
6401 if(scrollFlags.snapX)
6402 SNAPUP(x, sbStep.x);
6405 OnHScroll(setPosition, x, 0);
6409 SNAPDOWN(x, textCellW);
6415 sbv.Action(setPosition, y, 0);
6419 int seen = clientSize.h, total = reqScrollArea.h;
6422 if(scrollFlags.snapY)
6423 SNAPDOWN(seen, sbStep.y);
6425 if(!total) total = seen;
6426 range = total - seen + 1;
6427 range = Max(range, 1);
6429 if(y >= range) y = range - 1;
6431 if(scrollFlags.snapY)
6432 SNAPUP(y, sbStep.y);
6435 OnVScroll(setPosition, y, 0);
6438 SNAPDOWN(y, textCellH);
6443 UpdateCaret(false, false);
6446 void SetScrollLineStep(int stepX, int stepY)
6452 SNAPDOWN(stepX, textCellW);
6453 SNAPDOWN(stepY, textCellH);
6454 stepX = Max(stepX, textCellW);
6455 stepY = Max(stepY, textCellH);
6458 sbh.lineStep = stepX;
6460 sbv.lineStep = stepY;
6463 void SetState(WindowState newState, bool activate, Modifiers mods)
6467 if(state == newState || OnStateChange(newState, mods))
6469 WindowState prevState = state;
6473 // This used to be at the end of the brackets... moved for X, testing...
6474 // This has the effect of activating the window through the system...
6475 if(rootWindow == this)
6476 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6478 SetStateEx(newState, activate);
6480 if(rootWindow == this && !rootWindow.nativeDecorations)
6482 int x = position.x, y = position.y;
6485 x -= guiApp.desktop.absPosition.x;
6486 y -= guiApp.desktop.absPosition.y;
6488 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6492 //state = prevState;
6494 if(state != maximized && style.hasMaximize)
6497 for(child = parent.children.first; child; child = child.next)
6499 if(child != this && child.state == maximized)
6500 child.SetStateEx(normal, false);
6504 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6505 parent.UpdateScrollBars(true, true);
6508 // Do we really need this stuff here?
6509 // Shouldn't the Activate stuff take care of it?
6510 if(parent.rootWindow == parent && style)
6513 parent.FigureCaption(caption);
6514 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6515 parent.UpdateDecorations();
6519 rootWindow.ConsequentialMouseMove(false);
6526 BitmapResource GetIcon(SkinBitmap iconID)
6528 return guiApp.currentSkin.GetBitmap(iconID);
6531 void SetMouseRange(Box range)
6533 if(range || guiApp.fullScreenMode)
6538 clip.left = range.left + absPosition.x + clientStart.x;
6539 clip.top = range.top + absPosition.y + clientStart.y;
6540 clip.right = range.right + absPosition.x + clientStart.x;
6541 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6545 clip.left = guiApp.desktop.box.left;
6546 clip.top = guiApp.desktop.box.top;
6547 clip.right = guiApp.desktop.box.right;
6548 clip.bottom = guiApp.desktop.box.bottom;
6550 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6553 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6556 void SetMouseRangeToClient(void)
6558 if(guiApp.fullScreenMode || this != guiApp.desktop)
6560 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6561 box.Clip(clientArea);
6565 SetMouseRange(null);
6568 void SetMouseRangeToWindow(void)
6570 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6571 if(this == guiApp.desktop)
6572 SetMouseRangeToClient();
6577 // x, y: Desktop Coordinates
6578 void ShowSysMenu(int x, int y)
6581 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6584 menu, $"Restore", r, NotifySelect = MenuWindowRestore,
6585 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6589 menu, $"Move", m, NotifySelect = MenuWindowMove,
6590 disabled = !style.fixed || state == maximized
6594 menu, $"Size", s, NotifySelect = MenuWindowSize,
6595 disabled = !style.sizable || state != normal
6599 menu, $"Minimize", n, NotifySelect = MenuWindowMinimize,
6600 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6604 menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6605 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6609 menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6610 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6612 MenuDivider { menu };
6615 menu, $"Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6616 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6618 windowMenu.Create();
6623 ActivateEx(true, true, true, true, null, null);
6626 void MakeActive(void)
6628 ActivateEx(true, false, true, false, null, null);
6631 void SoftActivate(void)
6633 if(guiApp.desktop.active)
6639 void Deactivate(void)
6641 ActivateEx(false, true, true, true, null, null);
6646 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
6649 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
6651 bool result = false;
6652 if(activeChild && activeChild.cycle)
6654 Window modalWindow, child = activeChild;
6655 if(!clientOnly /*&& parent.tabCycle*/)
6657 Window next = child;
6660 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
6664 if(parent && parent.CycleChildren(backward, false, true, true))
6672 next = next.cycle.prev.data;
6674 next = next.cycle.next.data;
6675 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
6680 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
6681 parent.tabCycle && parent.CycleChildren(backward, false, false))
6685 if(tabCycleOnly && !tabCycle) return false;
6692 child = child.cycle.prev.data;
6694 child = child.cycle.next.data;
6695 if(child == child.parent.activeChild)
6697 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
6700 modalWindow = child.FindModal();
6703 // Scroll the window to include the active control
6704 if(sbh && !child.style.dontScrollHorz)
6706 if(child.scrolledPos.x < 0)
6707 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
6708 else if(child.scrolledPos.x + child.size.w > clientSize.w)
6709 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
6711 if(sbv && !child.style.dontScrollVert)
6713 if(child.scrolledPos.y < 0)
6714 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
6715 else if(child.scrolledPos.y + child.size.h > clientSize.h)
6716 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
6720 child = modalWindow ? modalWindow : child;
6721 child.ActivateEx(true, true, true, true, null, null);
6722 if(child.tabCycle && child.childrenCycle.first)
6723 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
6731 ConsequentialMouseMove(false);
6735 void AddResource(Resource resource)
6739 ResPtr ptr { resource = resource };
6743 // Load Graphics here if window is created already
6744 if(/*created && */display)
6746 display.Lock(false);
6747 ptr.loaded = display.displaySystem.LoadResource(resource);
6751 // Temporary hack to load font right away for listbox in dropbox ...
6752 else if(master && master.display)
6754 master.display.Lock(false);
6755 master.display.displaySystem.LoadResource(resource);
6756 master.display.Unlock();
6762 void RemoveResource(Resource resource)
6767 for(ptr = resources.first; ptr; ptr = ptr.next)
6769 if(ptr.resource == resource)
6775 // Unload Graphics here if window is created already
6776 if(/*created && */display)
6780 display.Lock(false);
6781 display.displaySystem.UnloadResource(resource, ptr.loaded);
6787 resources.Delete(ptr);
6792 void SetCaret(int x, int y, int size)
6799 if(active && !style.interim)
6801 if(visible || !guiApp.caretOwner)
6802 guiApp.caretOwner = size ? this : null;
6804 UpdateCaret(false, false);
6807 guiApp.interfaceDriver.SetCaret(0,0,0);
6808 UpdateCaret(false, true);
6809 guiApp.caretEnabled = false;
6812 else if(style.inactive && active)
6814 guiApp.interfaceDriver.SetCaret(0,0,0);
6815 UpdateCaret(false, true);
6816 guiApp.caretEnabled = false;
6821 void Scroll(int x, int y)
6823 bool opaque = !style.drawBehind || background.a;
6824 if(opaque && display && display.flags.scrolling)
6826 Box box = clientArea;
6827 box.left += clientStart.x;
6828 box.top += clientStart.y;
6829 box.right += clientStart.x;
6830 box.bottom += clientStart.y;
6832 //scrollExtent.Free(null);
6833 scrollExtent.AddBox(box);
6834 scrolledArea.x += x;
6835 scrolledArea.y += y;
6837 //scrollExtent.Free();
6838 //scrollExtent.AddBox(clientArea);
6839 //scrollExtent.Offset(clientStart.x, clientStart.y);
6840 //scrolledArea.x = x;
6841 //scrolledArea.y = y;
6847 rootWindow.dirty = true;
6850 void ReleaseCapture()
6852 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
6854 Window oldCaptured = guiApp.windowCaptured;
6855 guiApp.windowCaptured = null;
6856 guiApp.prevWindow = null;
6859 //guiApp.Log("Released Capture\n");
6861 guiApp.interfaceDriver.SetMouseCapture(null);
6863 //oldCaptured.OnMouseCaptureLost();
6866 oldCaptured.ConsequentialMouseMove(false);
6871 void SetText(char * format, ...)
6878 char caption[MAX_F_STRING];
6880 va_start(args, format);
6881 vsprintf(caption, format, args);
6884 this.caption = new char[strlen(caption)+1];
6886 strcpy(this.caption, caption);
6895 bool Grab(Bitmap bitmap, Box box, bool decorations)
6897 bool result = false;
6898 if(display || this == guiApp.desktop)
6900 Box clip = {MININT, MININT, MAXINT, MAXINT};
6906 clip.Clip(clientArea);
6908 clip.Clip(this.box);
6910 if(rootWindow != this)
6912 clip.left += absPosition.y;
6913 clip.top += absPosition.y;
6914 clip.right += absPosition.x;
6915 clip.bottom += absPosition.y;
6918 clip.left += decorations ? 0 : clientStart.x;
6919 clip.top += decorations ? 0 : clientStart.y;
6920 clip.right += decorations ? 0 : clientStart.x;
6921 clip.bottom += decorations ? 0 : clientStart.y;
6923 if(display && display.flags.flipping)
6925 rootWindow.Update(null);
6926 rootWindow.UpdateDisplay();
6933 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
6934 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6938 result = display.Grab(bitmap, clip.left, clip.top,
6939 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6941 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
6943 if(!bitmap.Convert(null, pixelFormat888, null))
6950 void GetMousePosition(int * x, int * y)
6952 int mouseX = 0, mouseY = 0;
6953 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
6956 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
6957 if(this != guiApp.desktop)
6959 mouseX -= absPosition.x + clientStart.x;
6960 mouseY -= absPosition.y + clientStart.y;
6967 DialogResult DoModal()
6969 DialogResult returnCode = 0;
6970 int terminated = terminateX;
6973 while(!destroyed && guiApp.driver != null)
6975 if(terminateX != terminated)
6977 terminated = terminateX;
6978 guiApp.desktop.Destroy(0);
6979 if(guiApp.desktop.created)
6982 //printf("Resetting terminate X to 0\n");
6988 guiApp.UpdateDisplay();
6989 if(!guiApp.ProcessInput(false))
6992 returnCode = this.returnCode;
7005 return !destroyed && guiApp.driver != null && terminateX < 2;
7008 DialogResult DoModalEnd()
7010 DialogResult returnCode = this.returnCode;
7015 // --- Window manipulation ---
7016 /*bool GetDisabled()
7018 bool disabled = this.disabled;
7020 for(window = this; (window = window.master); )
7031 // --- Mouse Manipulation ---
7032 void GetNCMousePosition(int * x, int * y)
7034 GetMousePosition(x, y);
7035 if(x) *x += clientStart.x;
7036 if(y) *y += clientStart.y;
7039 // --- Carets manipulation ---
7040 void GetCaretPosition(Point caretPos)
7042 caretPos = this.caretPos;
7045 int GetCaretSize(void)
7050 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7056 bool CloseConfirmation(bool parentClosing)
7069 if(!OnClose(parentClosing))
7072 // If you want to skip this, simply set modifiedDocument to false in OnClose
7073 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7075 DialogResult dialogRes;
7078 sprintf(message, $"Save changes to %s?", fileName);
7080 sprintf(message, $"Save changes to Untitled %d?", documentID);
7082 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption, contents = message }.Modal();
7084 if(dialogRes == yes)
7086 // TOFIX: Precomp error if brackets are taken out
7087 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7089 else if(dialogRes == cancel)
7095 for(slave = slaves.first; slave; slave = slave.next)
7096 if(!((Window)slave.data).CloseConfirmation(true))
7098 // ((Window)slave.data).CloseConfirmation(true);
7106 for(child = children.first; child; child = child.next)
7107 if(child.master != this && !child.CloseConfirmation(true))
7117 // Static methods... move them somewhere else?
7118 void ::RestoreCaret()
7120 if(guiApp.caretOwner)
7121 guiApp.caretOwner.UpdateCaret(false, false);
7124 void ::FreeMouseRange()
7126 guiApp.interfaceDriver.SetMouseRange(null, null);
7130 bool MenuFileClose(MenuItem selection, Modifiers mods)
7132 Window document = activeChild;
7134 document.Destroy(0);
7138 bool MenuFileExit(MenuItem selection, Modifiers mods)
7144 bool MenuFileSave(MenuItem selection, Modifiers mods)
7148 fileMonitor.fileName = null;
7151 if(OnSaveFile(fileName))
7153 //if(OnFileModified != Window::OnFileModified)
7156 fileMonitor.fileName = fileName;
7162 MessageBox dialog { master = master, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7163 DialogResult answer = dialog.Modal();
7165 if(answer != yes) return (bool)answer;
7168 return MenuFileSaveAs(selection, mods);
7171 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7173 DialogResult result = (DialogResult)bool::true;
7174 FileDialog fileDialog = saveDialog;
7177 fileDialog = FileDialog {};
7182 fileDialog.filePath = fileName;
7185 char filePath[MAX_FILENAME];
7186 sprintf(filePath, "Untitled %d", documentID);
7187 fileDialog.filePath = filePath;
7189 fileMonitor.fileName = null;
7191 fileDialog.type = save;
7192 fileDialog.text = $"Save As";
7196 fileDialog.master = master.parent ? master : this;
7197 if(fileDialog.Modal() == ok)
7199 char * filePath = fileDialog.filePath;
7201 if(OnSaveFile(filePath))
7204 property::fileName = filePath;
7205 NotifySaved(master, this, filePath);
7210 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7211 DialogResult answer = dialog.Modal();
7226 //if(OnFileModified != Window::OnFileModified && fileName)
7229 fileMonitor.fileName = fileName;
7233 return (bool)result; // Actually returning result from Yes/NoCancel message box
7236 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7238 Window document = activeChild;
7240 for(document = children.first; document; document = next)
7242 next = document.next;
7243 if(document.style.isDocument || document.fileName)
7244 document.MenuFileSave(selection, mods);
7249 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7253 for(document = children.first; document; document = document.next)
7254 //if(document.style.isDocument && document.state == minimized)
7255 if(document.style.isActiveClient && document.state == minimized)
7256 document.SetState(minimized, false, mods);
7260 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7262 Window document = activeChild;
7265 Window firstDocument = null;
7267 OldLink cycle = document.cycle.prev;
7272 if(child.style.isActiveClient && !child.style.hidden)
7276 firstDocument = child;
7277 if(child.state == minimized)
7278 child.SetState(minimized, false, mods);
7281 child.positionID = id++;
7282 child.SetState(normal, false, mods);
7283 child.anchor.left.type = cascade;
7286 child.normalSizeAnchor = *&child.sizeAnchor;
7287 child.normalAnchor = child.anchor;
7289 // Break the anchors for moveable/resizable windows
7290 if(child.style.fixed)
7292 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7294 (*&child.normalAnchor).left = x;
7295 (*&child.normalAnchor).top = y;
7296 (*&child.normalAnchor).right.type = none;
7297 (*&child.normalAnchor).bottom.type = none;
7299 child.normalSizeAnchor.isClientW = false;
7300 child.normalSizeAnchor.isClientH = false;
7301 child.normalSizeAnchor.size.w = w;
7302 child.normalSizeAnchor.size.h = h;
7303 child.anchored = false;
7306 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7308 child.stateAnchor = child.normalAnchor;
7309 child.stateSizeAnchor = child.normalSizeAnchor;
7311 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7312 child.Position(x, y, w, h, true, true, true, true, false, false);
7317 last = children.last;
7318 if(!child.style.stayOnTop)
7319 for(; last && last.style.stayOnTop; last = last.prev);
7320 children.Move(child, last);
7321 childrenOrder.Move(child.order, childrenOrder.last);
7323 if(cycle == document.cycle) break;
7327 firstDocument.Activate();
7332 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7339 // Close all closes all active clients, not all documents
7340 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7342 Window next, document;
7344 for(document = children.first; document; document = next)
7346 for(next = document.next; next && !(next.style.isActiveClient; next = next.next);
7347 if(document.style.isActiveClient)
7348 if(!document.Destroy(0) && !document.style.hidden)
7354 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7356 if(style.hasMaximize && state != maximized)
7357 SetState(maximized, 0, 0);
7361 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7363 if(style.hasMinimize && state != minimized)
7365 SetState(minimized, 0, 0);
7366 parent.CycleChildren(false, true, false, true);
7371 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7373 MenuMoveOrSize(false, selection ? true : false);
7377 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7379 CycleChildren(false, true, false, true);
7383 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7385 CycleChildren(true, true, false, true);
7389 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7391 MenuMoveOrSize(true, true);
7395 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7398 SetState(normal, 0, 0);
7402 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7405 int id = selection.id;
7406 OldLink cycle = activeClient.cycle;
7408 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7411 Window sibling = cycle.data;
7412 if(sibling.style.isActiveClient)
7420 document = cycle.data;
7421 document.Activate();
7423 //if(activeChild.state == maximized)
7424 // document.SetState(maximized, false, mods);
7425 //else if(document.state == minimized)
7426 // document.SetState(normal, false, mods);
7430 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7432 stayOnTop = !style.stayOnTop;
7436 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7438 Window document = activeChild;
7441 Window firstDocument = null;
7442 OldLink cycle = document.cycle;
7446 Window child = cycle.data;
7447 if(child.style.isActiveClient && !child.style.hidden)
7449 if(!firstDocument) firstDocument = child;
7450 if(child.state == minimized)
7451 child.SetState(minimized, false, mods);
7454 child.positionID = id++;
7455 child.SetState(normal, false, mods);
7456 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7458 child.anchor.left.type = hTiled;
7461 child.normalSizeAnchor = *&child.sizeAnchor;
7462 child.normalAnchor = child.anchor;
7464 // Break the anchors for moveable/resizable windows
7465 if(child.style.fixed)
7467 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7469 (*&child.normalAnchor).left = x;
7470 (*&child.normalAnchor).top = y;
7471 (*&child.normalAnchor).right.type = none;
7472 (*&child.normalAnchor).bottom.type = none;
7473 child.normalSizeAnchor.isClientW = false;
7474 child.normalSizeAnchor.isClientH = false;
7475 child.normalSizeAnchor.size.w = w;
7476 child.normalSizeAnchor.size.h = h;
7477 child.anchored = false;
7480 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7482 child.stateAnchor = child.normalAnchor;
7483 child.stateSizeAnchor = child.normalSizeAnchor;
7485 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7486 child.Position(x,y, w, h, true, true, true, true, false, true);
7491 if((cycle = cycle.next) == document.cycle) break;
7494 firstDocument.Activate();
7499 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7501 Window document = activeChild;
7504 Window firstDocument = null;
7506 OldLink cycle = document.cycle;
7511 //if(child.style.isDocument)
7512 if(child.style.isActiveClient && !child.style.hidden)
7514 if(!firstDocument) firstDocument = child;
7515 if(child.state == minimized)
7516 child.SetState(minimized, false, mods);
7519 child.positionID = id++;
7520 child.SetState(normal, false, mods);
7521 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7523 child.anchor.left.type = vTiled;
7526 child.normalSizeAnchor = *&child.sizeAnchor;
7527 child.normalAnchor = child.anchor;
7529 // Break the anchors for moveable/resizable windows
7530 if(child.style.fixed)
7532 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7534 (*&child.normalAnchor).left = x;
7535 (*&child.normalAnchor).top = y;
7536 (*&child.normalAnchor).right.type = none;
7537 (*&child.normalAnchor).bottom.type = none;
7538 child.normalSizeAnchor.isClientW = false;
7539 child.normalSizeAnchor.isClientH = false;
7540 child.normalSizeAnchor.size.w = w;
7541 child.normalSizeAnchor.size.h = h;
7542 child.anchored = false;
7545 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7547 child.stateAnchor = child.normalAnchor;
7548 child.stateSizeAnchor = child.normalSizeAnchor;
7550 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7551 child.Position(x,y, w, h, true, true, true, true, false, true);
7556 if((cycle = cycle.next) == document.cycle) break;
7559 firstDocument.Activate();
7564 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7566 WindowList dialog { master = this };
7567 Window document = (Window)dialog.Modal();
7570 if(activeChild.state == maximized)
7571 document.SetState(maximized, false, mods);
7572 else if(document.state == minimized)
7573 document.SetState(normal, false, mods);
7574 document.Activate();
7580 virtual bool OnCreate(void);
7581 virtual void OnDestroy(void);
7582 virtual void OnDestroyed(void);
7583 virtual bool OnClose(bool parentClosing);
7584 virtual bool OnStateChange(WindowState state, Modifiers mods);
7585 virtual bool OnPostCreate(void);
7586 virtual bool OnMoving(int *x, int *y, int w, int h);
7587 virtual bool OnResizing(int *width, int *height);
7588 virtual void OnResize(int width, int height);
7589 virtual void OnPosition(int x, int y, int width, int height);
7590 virtual bool OnLoadGraphics(void);
7591 virtual void OnApplyGraphics(void);
7592 virtual void OnUnloadGraphics(void);
7593 virtual void OnRedraw(Surface surface);
7594 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7595 virtual void OnActivateClient(Window client, Window previous);
7596 virtual bool OnKeyDown(Key key, unichar ch);
7597 virtual bool OnKeyUp(Key key, unichar ch);
7598 virtual bool OnKeyHit(Key key, unichar ch);
7599 virtual bool OnSysKeyDown(Key key, unichar ch);
7600 virtual bool OnSysKeyUp(Key key, unichar ch);
7601 virtual bool OnSysKeyHit(Key key, unichar ch);
7602 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7603 virtual bool OnMouseLeave(Modifiers mods);
7604 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7605 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7606 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
7607 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
7608 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
7609 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
7610 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
7611 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
7612 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
7613 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
7614 virtual void OnMouseCaptureLost(void);
7615 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
7616 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
7617 virtual void OnDrawOverChildren(Surface surface);
7618 virtual bool OnFileModified(FileChange fileChange, char * param);
7619 virtual bool OnSaveFile(char * fileName);
7621 // Virtual Methods -- Children management (To support Stacker, for lack of built-in auto-layout)
7622 // Note: A 'client' would refer to isActiveClient, rather than
7623 // being confined to the 'client area' (nonClient == false)
7624 virtual void OnChildAddedOrRemoved(Window child, bool removed);
7625 virtual void OnChildVisibilityToggled(Window child, bool visible);
7626 virtual void OnChildResized(Window child, int x, int y, int w, int h);
7628 // Skins Virtual Functions
7629 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
7630 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
7631 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
7636 virtual void ShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7637 virtual void PreShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7638 virtual bool IsMouseMoving(int x, int y, int w, int h);
7639 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY);
7640 virtual void UpdateNonClient();
7641 virtual void SetBox(Box box);
7642 virtual bool IsInside(int x, int y)
7644 return box.IsPointInside({x, y});
7646 virtual bool IsOpaque()
7648 return (!style.drawBehind || background.a == 255);
7652 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
7653 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
7654 virtual void Window::NotifySaved(Window window, char * filePath);
7659 property Window parent
7661 property_category $"Layout"
7664 if(value || guiApp.desktop)
7667 Window oldParent = parent;
7668 Anchor anchor = this.anchor;
7670 if(value && value.IsDescendantOf(this)) return;
7671 if(value && value == this)
7673 if(!value) value = guiApp.desktop;
7675 if(value == oldParent) return;
7677 if(!master || (master == this.parent && master == guiApp.desktop))
7678 property::master = value;
7682 parent.children.Remove(this);
7683 parent.OnChildAddedOrRemoved(this, true);
7687 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7688 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
7689 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7690 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
7694 last = value.children.last;
7696 if(style.isDocument)
7699 parent.numDocuments--;
7700 documentID = value.GetDocumentID();
7703 if(style.isActiveClient && !style.hidden)
7705 if(parent && parent != guiApp.desktop && !(style.hidden))
7707 if(state == minimized) parent.numIcons--;
7708 parent.numPositions--;
7712 if(!style.stayOnTop)
7713 for(; last && last.style.stayOnTop; last = last.prev);
7715 value.children.Insert(last, this);
7717 // *** NEW HERE: ***
7719 parent.childrenCycle.Delete(cycle);
7721 parent.childrenOrder.Delete(order);
7729 int x = position.x, y = position.y, w = size.w, h = size.h;
7733 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
7734 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
7736 vpw = value.clientSize.w;
7737 vph = value.clientSize.h;
7743 else if(style.fixed)
7745 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
7746 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
7749 anchor = this.anchor;
7751 if(anchor.left.type == offset) anchor.left.distance = x;
7752 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
7753 if(anchor.top.type == offset) anchor.top.distance = y;
7754 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
7755 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
7756 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
7757 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
7758 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
7759 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
7760 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
7762 if(!anchor.left.type && !anchor.right.type)
7764 anchor.horz.distance = (x + w / 2) - (vpw / 2);
7765 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
7767 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
7768 if(!anchor.top.type && !anchor.bottom.type)
7770 anchor.vert.distance = (y + h / 2) - (vph / 2);
7771 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
7773 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
7776 parent.OnChildAddedOrRemoved(this, false);
7782 parent.childrenCycle.Insert(
7783 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
7784 cycle = OldLink { data = this });
7785 parent.childrenOrder.Insert(
7786 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
7787 order = OldLink { data = this });
7790 if(!style.hidden && style.isActiveClient)
7792 positionID = parent.GetPositionID(this);
7793 parent.numPositions++;
7794 if(state == minimized) parent.numIcons--;
7797 // *** FONT INHERITANCE ***
7798 if(!setFont && oldParent)
7799 stopwatching(oldParent, font);
7803 RemoveResource(systemFont);
7806 // TESTING WITH WATCHERS:
7807 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7808 // usedFont = setFont ? setFont : (systemFont);
7812 if(guiApp.currentSkin)
7814 systemFont = guiApp.currentSkin.SystemFont();
7817 usedFont = systemFont;
7818 AddResource(systemFont);
7826 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7835 if(value.rootWindow && value.rootWindow.display && rootWindow)
7837 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
7838 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
7841 UnloadGraphics(false);
7844 LoadGraphics(false, false);
7847 if(value.rootWindow != rootWindow)
7848 DisplayModeChanged();
7852 scrolledPos.x = MININT; // Prevent parent update
7853 property::anchor = anchor;
7857 if(guiApp.currentSkin)
7858 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
7860 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7861 Position(x, y, w, h, true, true, true, true, false, true);
7866 // else parent = value;
7869 get { return parent; }
7872 property Window master
7874 property_category $"Behavior"
7877 //if(this == value) return;
7878 if(value && value.IsSlaveOf(this)) return;
7884 OldLink slaveHolder;
7885 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
7886 if(slaveHolder.data == this)
7888 master.slaves.Delete(slaveHolder);
7895 value.slaves.Add(OldLink { data = this });
7900 master.hotKeys.Remove(hotKey);
7901 value.hotKeys.Add(hotKey);
7904 if(master && master.defaultControl == this)
7905 master.defaultControl = null;
7907 if(style.isDefault && !value.defaultControl)
7908 value.defaultControl = this;
7913 get { return master ? master : parent; }
7916 property char * caption
7918 property_category $"Appearance"
7925 caption = new char[strlen(value)+1];
7927 strcpy(caption, value);
7932 get { return caption; }
7937 property_category $"Behavior"
7946 master.hotKeys.Add(hotKey = HotKeySlot { });
7950 hotKey.window = this;
7955 master.hotKeys.Delete(hotKey);
7960 get { return hotKey ? hotKey.key : 0; }
7963 property Color background
7965 property_category $"Appearance"
7968 background.color = value;
7973 if(this == rootWindow)
7974 guiApp.interfaceDriver.SetRootWindowColor(this);
7977 get { return background.color; }
7980 property Percentage opacity
7982 property_category $"Appearance"
7985 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
7986 drawBehind = background.a ? false : true;
7988 get { return background.a / 255.0f; }
7991 property Color foreground
7993 property_category $"Appearance"
8001 get { return foreground; }
8004 property BorderStyle borderStyle
8006 property_category $"Appearance"
8009 if(!((BorderBits)value).fixed)
8011 style.hasClose = false;
8012 style.hasMaximize = false;
8013 style.hasMinimize = false;
8014 nativeDecorations = false;
8016 style.borderBits = value;
8020 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8022 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8023 Position(x, y, w, h, true, true, true, true, false, true);
8024 CreateSystemChildren();
8027 get { return (BorderStyle)style.borderBits; }
8030 property Size minClientSize
8032 property_category $"Layout"
8033 set { minSize = value; }
8034 get { value = minSize; }
8037 property Size maxClientSize
8039 property_category $"Layout"
8040 set { maxSize = value; }
8041 get { value = maxSize; }
8044 property bool hasMaximize
8046 property_category $"Window Style"
8049 style.hasMaximize = value;
8050 if(value) { style.fixed = true; style.contour = true; }
8054 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8056 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8057 Position(x, y, w, h, true, true, true, true, false, true);
8059 CreateSystemChildren();
8062 get { return style.hasMaximize; }
8065 property bool hasMinimize
8067 property_category $"Window Style"
8070 style.hasMinimize = value;
8071 if(value) { style.fixed = true; style.contour = true; }
8075 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8077 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8078 Position(x, y, w, h, true, true, true, true, false, true);
8080 CreateSystemChildren();
8083 get { return style.hasMinimize; }
8086 property bool hasClose
8088 property_category $"Window Style"
8091 style.hasClose = value;
8092 if(value) { style.fixed = true; style.contour = true; }
8096 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8097 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8098 Position(x, y, w, h, true, true, true, true, false, true);
8099 CreateSystemChildren();
8102 get { return style.hasClose; }
8105 property bool nonClient
8107 property_category $"Layout"
8110 style.nonClient = value;
8112 style.stayOnTop = true;
8114 get { return style.nonClient; }
8117 property bool inactive
8119 property_category $"Behavior"
8124 // *** NEW HERE: ***
8128 parent.childrenCycle.Delete(cycle);
8130 parent.childrenOrder.Delete(order);
8137 active = false; // true;
8138 if(parent.activeChild == this)
8139 parent.activeChild = null;
8140 if(parent.activeClient == this)
8141 parent.activeClient = null;
8150 parent.childrenCycle.Insert(
8151 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8152 cycle = OldLink { data = this });
8154 parent.childrenOrder.Insert(
8155 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8156 order = OldLink { data = this });
8159 style.inactive = value;
8161 get { return style.inactive; }
8164 property bool clickThrough
8166 property_category $"Behavior"
8167 set { style.clickThrough = value; }
8168 get { return style.clickThrough; }
8171 property bool isRemote
8173 property_category $"Behavior"
8174 set { style.isRemote = value; }
8175 get { return style.isRemote; }
8178 property bool noCycle
8180 property_category $"Behavior"
8181 set { style.noCycle = value; }
8182 get { return style.noCycle; }
8185 property bool isModal
8187 property_category $"Behavior"
8188 set { style.modal = value; }
8189 get { return style.modal; }
8192 property bool interim
8194 property_category $"Behavior"
8195 set { style.interim = value; }
8196 get { return style.interim; }
8199 property bool tabCycle
8201 property_category $"Behavior"
8202 set { style.tabCycle = value; }
8203 get { return style.tabCycle; }
8206 property bool isDefault
8208 property_category $"Behavior"
8216 /*for(sibling = parent.children.first; sibling; sibling = sibling.next)
8217 if(sibling != this && sibling.style.isDefault)
8218 sibling.style.isDefault = false;*/
8219 if(master.defaultControl)
8220 master.defaultControl.style.isDefault = false;
8221 master.defaultControl = this;
8223 else if(master.defaultControl == this)
8224 master.defaultControl = null;
8228 style.isDefault = value;
8230 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8232 get { return style.isDefault; }
8235 property bool drawBehind
8237 property_category $"Window Style"
8238 set { style.drawBehind = value; }
8239 get { return style.drawBehind; }
8242 property bool hasMenuBar
8244 property_category $"Window Style"
8254 if(created && !menuBar)
8261 anchor = Anchor { top = 23, left = 1, right = 1 },
8263 inactive = true, nonClient = true
8268 else if(created && menuBar)
8273 style.hasMenuBar = value;
8275 get { return style.hasMenuBar; }
8278 property bool hasStatusBar
8280 property_category $"Window Style"
8287 statusBar = StatusBar { this };
8295 style.hasStatusBar = value;
8297 get { return style.hasStatusBar; }
8299 property bool stayOnTop
8301 property_category $"Window Style"
8306 if(created && !style.stayOnTop)
8308 if(rootWindow == this)
8309 guiApp.interfaceDriver.OrderRootWindow(this, true);
8310 else if(parent.children.last != this)
8312 parent.children.Move(this, parent.children.last);
8316 style.stayOnTop = true;
8320 if(created && style.stayOnTop)
8322 if(rootWindow == this)
8323 guiApp.interfaceDriver.OrderRootWindow(this, false);
8330 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8331 order && ((Window)order.data).style.stayOnTop;
8332 order = (order == parent.childrenOrder.first) ? null : order.prev);
8333 last = order ? order.data : null;
8337 for(last = parent.children.last;
8338 last && last.style.stayOnTop;
8342 parent.children.Move(this, last);
8346 style.stayOnTop = false;
8349 get { return style.stayOnTop; }
8354 property_category $"Window Style"
8364 if(menuBar && !value)
8371 if(!menuBar && style.hasMenuBar && value)
8375 this, menu = value, isMenuBar = true,
8376 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8377 inactive = true, nonClient = true
8381 UpdateActiveDocument(null);
8384 get { return menu; }
8387 property FontResource font
8389 property_category $"Appearance"
8391 isset { return setFont ? true : false; }
8396 if(value && !setFont) { stopwatching(parent, font); }
8397 else if(!value && setFont)
8403 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8412 RemoveResource(setFont);
8417 RemoveResource(systemFont);
8424 AddResource(setFont);
8427 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8430 systemFont = guiApp.currentSkin.SystemFont();
8432 usedFont = systemFont;
8433 AddResource(systemFont);
8441 get { return usedFont; }
8444 property SizeAnchor sizeAnchor
8446 property_category $"Layout"
8449 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8450 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8451 sizeAnchor.isClientW != sizeAnchor.isClientH;
8458 normalSizeAnchor = sizeAnchor;
8460 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8462 stateAnchor = normalAnchor;
8463 stateSizeAnchor = normalSizeAnchor;
8465 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8466 Position(x,y, w, h, true, true, true, true, false, true);
8473 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8474 sizeAnchor.isClientW,
8475 sizeAnchor.isClientH
8482 property_category $"Layout"
8485 Anchor thisAnchor = anchor;
8486 SizeAnchor thisSizeAnchor = sizeAnchor;
8487 bool leftRight = (anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none);
8488 bool topBottom = (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none);
8489 bool isClient = !sizeAnchor.isClientW && !sizeAnchor.isClientH;
8490 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8491 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8492 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8498 sizeAnchor.isClientW = false;
8499 sizeAnchor.isClientH = false;
8500 sizeAnchor.size = value;
8502 normalSizeAnchor = sizeAnchor;
8504 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8506 stateAnchor = normalAnchor;
8507 stateSizeAnchor = normalSizeAnchor;
8509 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8510 Position(x, y, w, h, true, true, true, true, false, true);
8511 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
8514 get { value = size; }
8517 property Size clientSize
8519 property_category $"Layout"
8522 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8523 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8524 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8529 sizeAnchor.isClientW = true;
8530 sizeAnchor.isClientH = true;
8531 sizeAnchor.size = value;
8533 normalSizeAnchor = sizeAnchor;
8535 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8537 stateAnchor = normalAnchor;
8538 stateSizeAnchor = normalSizeAnchor;
8540 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8541 Position(x,y, w, h, true, true, true, true, false, true);
8544 get { value = clientSize; }
8547 property Size initSize { get { value = sizeAnchor.size; } };
8549 property Anchor anchor
8551 property_category $"Layout"
8552 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8558 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8560 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8561 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8563 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8565 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8566 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8570 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8572 anchor.left.distance = 0;
8573 anchor.horz.type = 0;
8575 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8577 anchor.top.distance = 0;
8578 anchor.vert.type = 0;
8587 normalAnchor = anchor;
8589 // Break the anchors for moveable/resizable windows
8590 /*if(style.fixed ) //&& value.left.type == cascade)
8592 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
8594 this.anchor = normalAnchor = Anchor { left = x, top = y };
8595 normalSizeAnchor = SizeAnchor { { w, h } };
8598 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8600 stateAnchor = normalAnchor;
8601 stateSizeAnchor = normalSizeAnchor;
8603 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8604 Position(x, y, w, h, true, true, true, true, false, true);
8613 get { value = this ? anchor : Anchor { }; }
8616 property Point position
8618 property_category $"Layout"
8621 if(value == null) return;
8623 anchor.left = value.x;
8624 anchor.top = value.y;
8625 anchor.right.type = none;
8626 anchor.bottom.type = none;
8631 normalAnchor = anchor;
8633 // Break the anchors for moveable/resizable windows
8637 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8639 normalAnchor.left = x;
8640 normalAnchor.top = y;
8641 normalAnchor.right.type = none;
8642 normalAnchor.bottom.type = none;
8643 normalSizeAnchor.size.width = w;
8644 normalSizeAnchor.size.height = h;
8648 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8650 stateAnchor = normalAnchor;
8651 stateSizeAnchor = normalSizeAnchor;
8653 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8654 Position(x,y, w, h, true, true, true, true, false, true);
8658 get { value = position; }
8661 property bool disabled
8663 property_category $"Behavior"
8666 if(this && disabled != value)
8673 get { return (bool)disabled; }
8676 property bool isEnabled
8681 for(parent = this; parent; parent = parent.parent)
8688 property WindowState state
8690 property_category $"Behavior"
8691 set { SetState(value, false, 0); }
8692 get { return this ? state : 0; }
8695 property bool visible
8697 property_category $"Behavior"
8700 if(this && !value && !style.hidden && parent)
8702 bool wasActiveChild = parent.activeChild == this;
8703 Window client = null;
8705 style.hidden = true;
8706 if(style.isActiveClient)
8708 parent.numPositions--;
8709 if(state == minimized) parent.numIcons--;
8714 OldLink prevOrder = null;
8716 if(rootWindow == this)
8717 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
8720 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
8723 box.left -= parent.clientStart.x;
8724 box.top -= parent.clientStart.y;
8725 box.right -= parent.clientStart.x;
8726 box.bottom -= parent.clientStart.y;
8730 if(_isModal && master && master.modalSlave == this)
8731 master.modalSlave = null;
8735 OldLink tmpPrev = order.prev;
8736 client = tmpPrev ? tmpPrev.data : null;
8737 if(client && !client.style.hidden && !client.destroyed && client.created)
8738 prevOrder = tmpPrev;
8741 client = tmpPrev ? tmpPrev.data : null;
8742 if(client == this) { client = null; break; }
8743 if(client && ((client.style.hidden) || client.destroyed || !client.created))
8745 tmpPrev = client.order.prev;
8750 prevOrder = tmpPrev;
8755 // If this window can be an active client, make sure the next window we activate can also be one
8756 if(!style.nonClient && style.isActiveClient)
8758 tmpPrev = prevOrder;
8761 client = tmpPrev ? tmpPrev.data : null;
8762 if(client == this) { client = null; break; }
8763 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
8765 tmpPrev = client.order.prev;
8770 prevOrder = tmpPrev;
8774 if(client && client.style.hidden) client = null;
8778 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
8780 if(order && prevOrder && prevOrder.data != this)
8781 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
8783 ActivateEx(false, false, false, true, null, null);
8785 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
8786 if(parent.activeClient == this)
8788 parent.activeClient = null;
8789 parent.UpdateActiveDocument(null);
8792 else if(parent.activeClient == this)
8794 parent.activeClient = client;
8795 parent.UpdateActiveDocument(this);
8798 // *** Not doing this anymore ***
8801 parent.childrenCycle.Delete(cycle);
8803 parent.childrenOrder.Delete(order);
8808 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8813 else if(this && value && style.hidden)
8815 style.hidden = false;
8818 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8819 if(rootWindow == this)
8820 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
8822 if(_isModal && master)
8823 master.modalSlave = this;
8825 if(style.isActiveClient)
8827 positionID = parent.GetPositionID(this);
8828 parent.numPositions++;
8829 if(state == minimized) parent.numIcons++;
8832 // *** NOT DOING THIS ANYMORE ***
8834 if(!(style.inactive))
8836 if(!(style.noCycle))
8838 cycle = parent.childrenCycle.AddAfter(
8839 (parent.activeChild && parent.activeChild.cycle) ?
8840 parent.activeChild.cycle.prev : null, sizeof(OldLink));
8843 order = parent.childrenOrder.AddAfter(
8844 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8851 if(true || !parent.activeChild)
8852 ActivateEx(true, false, true, true, null, null);
8854 if(creationActivation == activate)
8855 ActivateEx(true, false, true, true, null, null);
8856 else if(creationActivation == flash && !object)
8859 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8863 ConsequentialMouseMove(false);
8869 style.hidden = !value;
8872 get { return (style.hidden || !setVisible) ? false : true; }
8875 property bool isDocument
8877 property_category $"Document"
8878 set { style.isDocument = value; }
8879 get { return style.isDocument; }
8882 property bool mergeMenus
8884 property_category $"Window Style"
8885 set { mergeMenus = value; }
8886 get { return (bool)mergeMenus; }
8889 property bool hasHorzScroll
8891 property_category $"Window Style"
8896 if(!style.hasHorzScroll && created)
8898 CreateSystemChildren();
8899 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8902 else if(style.hasHorzScroll)
8906 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8908 style.hasHorzScroll = value;
8911 get { return style.hasHorzScroll; }
8914 property bool hasVertScroll
8916 property_category $"Window Style"
8921 if(!style.hasVertScroll && created)
8923 style.hasVertScroll = true;
8924 CreateSystemChildren();
8925 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8928 else if(style.hasVertScroll)
8932 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8934 style.hasVertScroll = value;
8936 get { return style.hasVertScroll; }
8939 property bool dontHideScroll
8941 property_category $"Behavior"
8944 scrollFlags.dontHide = value;
8947 //UpdateScrollBars(true, true);
8948 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8952 // UpdateScrollBars(true, true);
8953 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8956 get { return scrollFlags.dontHide; }
8959 property bool dontScrollVert
8961 property_category $"Behavior"
8962 set { style.dontScrollVert = value; }
8963 get { return style.dontScrollVert; }
8965 property bool dontScrollHorz
8967 property_category $"Behavior"
8968 set { style.dontScrollHorz = value; }
8969 get { return style.dontScrollHorz; }
8972 property bool snapVertScroll
8974 property_category $"Behavior"
8977 scrollFlags.snapY = value;
8978 if(sbv) sbv.snap = value;
8980 get { return scrollFlags.snapY; }
8982 property bool snapHorzScroll
8984 property_category $"Behavior"
8987 scrollFlags.snapX = value;
8988 if(sbh) sbh.snap = value;
8990 get { return scrollFlags.snapX; }
8993 property Point scroll
8995 property_category $"Behavior"
8999 // TESTING THIS IMPLEMENTATION:
9000 SetScrollPosition(value.x, value.y);
9002 get { value = scroll; }
9005 property bool modifyVirtualArea
9007 property_category $"Behavior"
9008 set { modifyVirtArea = value; }
9009 get { return (bool)modifyVirtArea; }
9012 property char * fileName
9014 property_category $"Document"
9017 if(menu && ((!fileName && value) || (fileName && !value)))
9019 MenuItem item = menu.FindItem(MenuFileSave, 0);
9020 if(item) item.disabled = !modifiedDocument && value;
9025 if(value && value[0])
9026 fileName = CopyString(value);
9028 if(parent && this == parent.activeClient)
9029 parent.UpdateActiveDocument(null);
9033 // if(style.isDocument)
9035 fileMonitor.fileName = value;
9037 get { return fileName; }
9042 property_category $"Data"
9047 property bool modifiedDocument
9049 property_category $"Document"
9052 if(style.isDocument || fileName)
9056 MenuItem item = menu.FindItem(MenuFileSave, 0);
9057 if(item) item.disabled = !value && fileName;
9061 if(modifiedDocument != value)
9063 modifiedDocument = value;
9064 if(style.isDocument || fileName)
9068 get { return (bool)modifiedDocument; }
9071 property bool showInTaskBar
9073 property_category $"Window Style"
9074 set { style.showInTaskBar = value; }
9075 get { return (style.showInTaskBar; }
9077 property FileDialog saveDialog { set { saveDialog = value; } };
9078 property bool isActiveClient
9080 property_category $"Behavior"
9081 set { style.isActiveClient = value; }
9082 get { return style.isActiveClient; }
9085 property Cursor cursor
9087 property_category $"Appearance"
9091 SelectMouseCursor();
9093 get { return cursor; }
9096 //#if !defined(ECERE_VANILLA)
9097 property char * name
9099 property_category $"Design"
9102 return (this && object) ? object.name : null;
9107 activeDesigner.RenameObject(object, value);
9111 property char * displayDriver
9113 property_category $"Behavior"
9116 dispDriver = GetDisplayDriver(value);
9117 //DisplayModeChanged();
9121 return dispDriver ? dispDriver.name : null;
9125 // RUNTIME PROPERTIES
9126 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9127 property Size scrollArea
9129 property_category $"Behavior"
9133 SetScrollArea(value.w, value.h, false);
9135 SetScrollArea(0,0, true);
9137 get { value = scrollArea; }
9140 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9145 property_category $"Layout"
9146 set { if(this) is3D = value; }
9147 get { return (bool)is3D; }
9150 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9152 // Will be merged with font later
9153 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9154 property Point clientStart { get { value = clientStart; } };
9155 property Point absPosition { get { value = absPosition; } };
9156 property Anchor normalAnchor { get {value = normalAnchor; } };
9157 // property Size normalSizeAnchor { get { value = normalSizeAnchor; } };
9158 property bool active { get { return (bool)active; } };
9159 property bool created { get { return (bool)created; } };
9160 property bool destroyed { get { return (bool)destroyed; } };
9161 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9162 property Window firstChild { get { return children.first; } };
9163 property Window lastChild { get { return children.last; } };
9164 property Window activeClient { get { return activeClient; } };
9165 property Window activeChild { get { return activeChild; } };
9166 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9167 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9168 property ScrollBar horzScroll { get { return sbh; } };
9169 property ScrollBar vertScroll { get { return sbv; } };
9170 property StatusBar statusBar { get { return statusBar; } };
9171 property Window rootWindow { get { return rootWindow; } };
9172 property bool closing { get { return (bool)closing; } set { closing = value; } };
9173 property int documentID { get { return documentID; } };
9174 property Window previous { get { return prev; } }
9175 property Window next { get { return next; } }
9176 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9177 property PopupMenu menuBar { get { return menuBar; } }
9178 property ScrollBar sbv { get { return sbv; } }
9179 property ScrollBar sbh { get { return sbh; } }
9180 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9181 property void * systemHandle { get { return windowHandle; } }
9182 property Button minimizeButton { get { return sysButtons[0]; } };
9183 property Button maximizeButton { get { return sysButtons[1]; } };
9184 property Button closeButton { get { return sysButtons[2]; } };
9185 property BitmapResource icon
9187 get { return icon; }
9191 if(icon) incref icon;
9193 guiApp.interfaceDriver.SetIcon(this, value);
9196 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9197 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } };
9198 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9199 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9200 property bool nativeDecorations
9202 get { return (bool)nativeDecorations && (formDesigner || rootWindow == this); }
9203 set { nativeDecorations = value; }
9204 isset { return nativeDecorations != style.fixed; }
9206 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9208 property char * text
9210 property_category $"Deprecated"
9212 set { property::caption = value; }
9213 get { return property::caption; }
9219 WindowBits style; // Window Style
9220 char * caption; // Name / Caption
9221 Window parent; // Parent window
9222 OldList children; // List of children in Z order
9223 Window activeChild; // Child window having focus
9224 Window activeClient;
9225 Window previousActive; // Child active prior to activating the default child
9226 Window master; // Window owning and receiving notifications concerning this window
9227 OldList slaves; // List of windows belonging to this window
9228 Display display; // Display this window is drawn into
9230 Point position; // Position in parent window client area
9231 Point absPosition; // Absolute position
9232 Point clientStart; // Client area position from (0,0) in this window
9234 Size clientSize; // Client area size
9235 Size scrollArea; // Virtual Scroll area size
9236 Size reqScrollArea; // Requested virtual area size
9237 Point scroll; // Virtual area scrolling position
9238 public ScrollBar sbh, sbv; // Scrollbar window handles
9239 Cursor cursor; // Mouse cursor used for this window
9242 StatusBar statusBar;
9243 Button sysButtons[3];
9245 Box clientArea; // Client Area box clipped to parent
9247 HotKeySlot hotKey; // HotKey for this window
9251 ScrollFlags scrollFlags;// Window Scrollbar Flags
9252 int id; // Control ID
9254 ColorAlpha background; // Background color used to draw the window area
9256 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9257 OldList childrenCycle; // Cycling order
9258 OldLink cycle; // Element of parent's cycling order
9259 OldList childrenOrder; // Circular Z-Order
9260 OldLink order; // Element of parent's circular Z-Order
9261 Window modalSlave; // Slave window blocking this window's interaction
9263 Window rootWindow; // Topmost system managed window
9264 void * windowHandle; // System window handle
9266 DialogResult returnCode;// Return code for modal windows
9268 Point sbStep; // Scrollbar line scrolling steps
9271 SizeAnchor stateSizeAnchor;
9273 Anchor normalAnchor;
9274 SizeAnchor normalSizeAnchor;
9276 Size skinMinSize; // Minimal window size based on style
9277 Point scrolledPos; // Scrolled position
9278 Box box; // Window box clipped to parent
9279 Box * against; // What to clip the box to
9281 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9282 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9283 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9284 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9285 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9286 Point scrolledArea; // Distance to scroll area by
9287 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9289 OldList hotKeys; // List of the hotkeys of all children
9290 Window defaultControl; // Default child control
9294 ColorAlpha * palette; // Color palette used for this window
9296 int caretSize; // Size of caret, non zero if a caret is present
9297 Point caretPos; // Caret position
9299 void * systemParent; // Parent System Window for embedded windows
9306 WindowState lastState;
9308 FileMonitor fileMonitor
9310 this, FileChange { modified = true };
9312 bool OnFileNotify(FileChange action, char * param)
9315 fileMonitor.StopMonitoring();
9316 if(OnFileModified(action, param))
9317 fileMonitor.StartMonitoring();
9322 FontResource setFont, systemFont;
9323 FontResource usedFont;
9324 FontResource captionFont;
9326 FileDialog saveDialog;
9328 SizeAnchor sizeAnchor;
9330 // FormDesigner data
9333 Extent * tempExtents; //[4];
9334 BitmapResource icon;
9336 CreationActivationOption creationActivation;
9339 bool active:1; // true if window and ancestors are active
9340 bool acquiredInput:1; // true if the window is processing state based input
9341 bool modifiedDocument:1;
9342 bool disabled:1; // true if window cannot interact
9343 bool isForegroundWindow:1;// true while a root window is being activated
9344 bool visible:1; // Visibility flag
9345 bool destroyed:1; // true if window is being destroyed
9346 bool anchored:1; // true if this window is repositioned when the parent resizes
9347 bool dirty:1; // Flag set to true if any descendant must be redrawn
9353 bool modifyVirtArea:1;
9354 bool noAutoScrollArea:1;
9357 bool setVisible:1; // FOR FORM DESIGNER
9363 bool useSharedMemory:1;
9366 bool nativeDecorations:1;
9367 bool manageDisplay:1;
9368 bool formDesigner:1; // True if we this is running in the form editor
9371 // Checks used internally for them not to take effect in FormDesigner
9372 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9373 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9375 WindowController controller;
9376 public property WindowController controller { get { return controller; } set { delete controller; controller = value; if(controller) incref controller; } }
9379 public class CommonControl : Window
9381 // creationActivation = doNothing;
9384 public property String toolTip
9386 property_category $"Appearance"
9389 if(created) CommonControl::OnDestroy();
9391 toolTip = value ? ToolTip { tip = value; } : null;
9393 if(created) CommonControl::OnCreate();
9395 get { return toolTip ? toolTip.tip : null; }
9401 // (Very) Ugly work around for the fact that the parent watcher
9402 // won't fire when it's already been disconnected...
9403 eInstance_FireSelfWatchers(toolTip,
9404 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
9410 toolTip.parent = this;
9419 public class Percentage : float
9421 char * OnGetString(char * string, float * fieldData, bool * needClass)
9425 sprintf(string, "%.2f", this);
9426 c = strlen(string)-1;
9429 if(string[c] != '0')
9430 last = Max(last, c);
9431 if(string[c] == '.')
9444 public void ApplySkin(Class c, char * name, void ** vTbl)
9446 char className[1024];
9451 subclass(Window) wc = (subclass(Window))c;
9452 subclass(Window) base = (subclass(Window))c.base;
9454 sprintf(className, "%sSkin_%s", name, c.name);
9455 wc.pureVTbl = c._vTbl;
9456 c._vTbl = new void *[c.vTblSize];
9457 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9458 sc = eSystem_FindClass(c.module.application, className);
9462 for(m = 0; m < c.base.vTblSize; m++)
9464 if(c._vTbl[m] == base.pureVTbl[m])
9465 c._vTbl[m] = vTbl[m];
9470 for(m = 0; m < c.vTblSize; m++)
9472 if(sc._vTbl[m] != wc.pureVTbl[m])
9473 c._vTbl[m] = sc._vTbl[m];
9477 for(d = c.derivatives.first; d; d = d.next)
9479 ApplySkin(d.data, name, c._vTbl);
9483 public void UnapplySkin(Class c)
9485 char className[1024];
9487 subclass(Window) wc = (subclass(Window))c;
9488 subclass(Window) base = (subclass(Window))c.base;
9491 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9494 c._vTbl = wc.pureVTbl;
9498 for(d = c.derivatives.first; d; d = d.next)
9500 UnapplySkin(d.data);
9504 void CheckFontIntegrity(Window window)
9509 if(window.usedFont && window.usedFont.font == 0xecececec)
9511 FontResource uf = window.usedFont;
9512 char * className = window._class.name;
9513 char * text = window.text;
9516 for(c = window.firstChild; c; c = c.next)
9517 CheckFontIntegrity(c);
9521 public class ControllableWindow : Window
9523 /*WindowController controller;
9524 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9525 ~ControllableWindow() { delete controller; }*/
9528 class WindowControllerInterface : ControllableWindow
9530 bool OnKeyDown(Key key, unichar ch)
9532 bool result = ((int(*)())(void *)controller.OnKeyDown)((void *)controller.controlled, (void *)controller, key, ch);
9534 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown](controller.window, key, ch);
9538 bool OnKeyUp(Key key, unichar ch)
9540 bool result = ((int(*)())(void *)controller.OnKeyUp)((void *)controller.controlled, (void *)controller, key, ch);
9542 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp](controller.window, key, ch);
9546 bool OnKeyHit(Key key, unichar ch)
9548 bool result = ((int(*)())(void *)controller.OnKeyHit)((void *)controller.controlled, (void *)controller, key, ch);
9550 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit](controller.window, key, ch);
9554 bool OnMouseMove(int x, int y, Modifiers mods)
9556 bool result = ((int(*)())(void *)controller.OnMouseMove)((void *)controller.controlled, (void *)controller, x, y, mods);
9558 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove](controller.window, x, y, mods);
9562 bool OnLeftButtonDown(int x, int y, Modifiers mods)
9564 bool result = ((int(*)())(void *)controller.OnLeftButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9566 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown](controller.window, x, y, mods);
9570 bool OnLeftButtonUp(int x, int y, Modifiers mods)
9572 bool result = ((int(*)())(void *)controller.OnLeftButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9574 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp](controller.window, x, y, mods);
9578 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
9580 bool result = ((int(*)())(void *)controller.OnLeftDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9582 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick](controller.window, x, y, mods);
9586 bool OnRightButtonDown(int x, int y, Modifiers mods)
9588 bool result = ((int(*)())(void *)controller.OnRightButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9590 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown](controller.window, x, y, mods);
9594 bool OnRightButtonUp(int x, int y, Modifiers mods)
9596 bool result = ((int(*)())(void *)controller.OnRightButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9598 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp](controller.window, x, y, mods);
9602 bool OnRightDoubleClick(int x, int y, Modifiers mods)
9604 bool result = ((int(*)())(void *)controller.OnRightDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9606 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick](controller.window, x, y, mods);
9610 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
9612 bool result = ((int(*)())(void *)controller.OnMiddleButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9614 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown](controller.window, x, y, mods);
9618 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
9620 bool result = ((int(*)())(void *)controller.OnMiddleButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9622 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp](controller.window, x, y, mods);
9626 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
9628 bool result = ((int(*)())(void *)controller.OnMiddleDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9630 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick](controller.window, x, y, mods);
9634 void OnResize(int width, int height)
9636 ((int(*)())(void *)controller.OnResize)((void *)controller.controlled, (void *)controller, width, height);
9637 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize](controller.window, width, height);
9640 void OnRedraw(Surface surface)
9642 ((int(*)())(void *)controller.OnRedraw)((void *)controller.controlled, (void *)controller, surface);
9643 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw](controller.window, surface);
9648 bool result = ((int(*)())(void *)controller.OnCreate)((void *)controller.controlled, (void *)controller);
9650 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
9655 public class WindowController<class V>
9658 property Window window
9662 uint size = class(Window).vTblSize;
9665 windowVTbl = new void *[size];
9666 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
9667 if(value._vTbl == value._class._vTbl)
9669 value._vTbl = new void *[value._class.vTblSize];
9670 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
9674 for(c = 0; c < size; c++)
9676 void * function = class(WindowControllerInterface)._vTbl[c];
9677 if(function != DefaultFunction)
9678 value._vTbl[c] = function;
9680 value._vTbl[c] = windowVTbl[c];
9685 memcpy(value._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
9688 get { return window; }
9690 property V controlled
9692 set { controlled = value; }
9693 get { return controlled; }
9695 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
9696 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
9697 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
9698 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
9699 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
9700 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
9701 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9702 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
9703 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
9704 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9705 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
9706 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
9707 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9708 virtual void V::OnResize(WindowController controller, int width, int height);
9709 virtual void V::OnRedraw(WindowController controller, Surface surface);
9710 virtual bool V::OnCreate(WindowController controller);
9713 int (** windowVTbl)();