7 import "GuiApplication"
28 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
32 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
41 // Had to define this here for native decorations support, because the menu bar is part of total decoration's size, but not part of the system decorations
42 define skinMenuHeight = 25;
43 define statusBarHeight = 18;
45 default extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
47 public enum DialogResult { cancel, yes, no, ok };
49 public class MouseButtons
52 bool left:1, right:1, middle:1;
55 public struct SizeAnchor
58 bool isClientW, isClientH;
63 #define SNAPDOWN(x, d) \
66 if(x < 0) x -= ((d) - Abs(x) % (d)); else x -= x % (d); \
69 #define SNAPUP(x, d) \
72 if(x > 0) x += ((d) - Abs(x) % (d)); else x += x % (d); \
75 /*static */define MAX_DIRTY_BACK = 10;
77 /////////////////////////////////////////////////////////////////////////////
78 ////////// EXTENT MANIPULATION //////////////////////////////////////////////
79 /////////////////////////////////////////////////////////////////////////////
81 #define ACCESS_ITEM(l, id) \
84 #define FASTLIST_LOOP(l, v) \
85 for(v = (BoxItem)l.first; v; v = (BoxItem)v.next)
87 #define FASTLIST_LOOPN(l, v, n) \
88 for(v = (BoxItem)l.first, n = (BoxItem)(v ? v.next : null); v; v = (BoxItem)next, n = (BoxItem)(v ? v.next : null))
91 #define ACCESS_ITEM(l, id) \
92 ((FastItem)(((id) == -1) ? null : (((byte *)((l).items)) + (id) * (l).itemSize)))
94 #define FASTLIST_LOOP(l, v) \
95 for(v = (void *)ACCESS_ITEM((l), (l).first); v; v = (void *)ACCESS_ITEM((l), v.next))
97 #define FASTLIST_LOOPN(l, v, n) \
98 for( v = (void *)ACCESS_ITEM((l), (l).first), \
99 n = v ? ((void *)ACCESS_ITEM((l), v.next)): null; \
100 v; v = n, n = n ? (void *)ACCESS_ITEM((l), n.next) : null)
103 private class FastItem : struct
108 private struct FastList
113 int count, size, itemSize;
120 first = last = free = -1;
128 // FASTLIST_LOOPN(this, item, next) { Delete(item); };
131 FastItem Add(uint itemSize)
134 if(free == -1 || !size)
141 newSize = (size + (size >> 1));
142 items = (FastItem)renew items byte[newSize * itemSize];
147 this.itemSize = itemSize;
148 items = (FastItem)new byte[newSize * itemSize];
151 for(c = size; c<newSize-1; c++)
153 ACCESS_ITEM(this, c).prev = -1;
154 ACCESS_ITEM(this, c).next = c+1;
156 ACCESS_ITEM(this, c).prev = -1;
157 ACCESS_ITEM(this, c).next = -1;
161 item = ACCESS_ITEM(this, free);
164 ACCESS_ITEM(this, item.prev).next = free;
174 void Delete(FastItem item)
177 ACCESS_ITEM(this, item.prev).next = item.next;
179 ACCESS_ITEM(this, item.next).prev = item.prev;
181 if(ACCESS_ITEM(this, first) == item)
183 if(ACCESS_ITEM(this, last) == item)
188 free = ((byte *)item - (byte *)items) / itemSize;
196 free = first = last = -1;
200 private class BoxItem : Item //FastItem
205 public /*private */struct Extent : OldList //FastList
214 //BoxItem extentBox = (BoxItem)Add(sizeof(class BoxItem));
215 Add(BoxItem { box = box });
218 void Copy(Extent source)
224 //FASTLIST_LOOP(source, extentBox)
225 for(extentBox = (BoxItem)source.first; extentBox; extentBox = (BoxItem)extentBox.next)
226 AddBox(extentBox.box);
229 void IntersectBox(Box box)
231 // Clip all boxes of extent against inside of the new box
232 BoxItem extentBox, next;
234 //FASTLIST_LOOPN(this, extentBox, next) // Macros still mess up the parser!
235 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
237 next = (BoxItem)extentBox.next;
238 if(box.left > extentBox.box.left) extentBox.box.left = box.left;
239 if(box.top > extentBox.box.top) extentBox.box.top = box.top;
240 if(box.right < extentBox.box.right) extentBox.box.right = box.right;
241 if(box.bottom < extentBox.box.bottom) extentBox.box.bottom = box.bottom;
242 if(extentBox.box.right < extentBox.box.left || extentBox.box.bottom < extentBox.box.top)
247 void ExcludeBox(Box box, Extent temp)
254 for(extentBox = (BoxItem)temp.first; extentBox; extentBox = (BoxItem)extentBox.next)
256 if(extentBox.box.left < box.right && extentBox.box.right > box.left &&
257 extentBox.box.top < box.bottom && extentBox.box.bottom > box.top)
260 if(extentBox.box.top < box.top && extentBox.box.bottom >= box.top)
264 extentBox.box.left, extentBox.box.top,
265 extentBox.box.right, Min(extentBox.box.bottom, box.top -1)
271 if(extentBox.box.bottom > box.bottom && extentBox.box.top <= box.bottom)
275 extentBox.box.left, Max(extentBox.box.top,box.bottom +1),
276 extentBox.box.right, extentBox.box.bottom
282 if(extentBox.box.bottom >= box.top && extentBox.box.top <= box.bottom)
285 if(extentBox.box.left < box.left && extentBox.box.right >= box.left)
289 extentBox.box.left, Max(extentBox.box.top, box.top),
290 Min(extentBox.box.right, box.left-1), Min(extentBox.box.bottom, box.bottom)
296 if(extentBox.box.right > box.right && extentBox.box.left <= box.right)
300 Max(extentBox.box.left, box.right+1), Max(extentBox.box.top, box.top),
301 extentBox.box.right, Min(extentBox.box.bottom, box.bottom)
309 AddBox(extentBox.box);
315 void UnionBox(Box box, Extent temp)
317 BoxItem extentBox, next;
319 // First pass: check if this box is not already covered by one of the extent's box
320 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
322 if(extentBox.box.left <= box.left && extentBox.box.right >= box.right &&
323 extentBox.box.top <= box.top && extentBox.box.bottom >= box.bottom)
330 // Second pass: only keep boxes not completely covered in the new box
331 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
333 next = (BoxItem)extentBox.next;
334 if(extentBox.box.left >= box.left && extentBox.box.right <= box.right &&
335 extentBox.box.top >= box.top && extentBox.box.bottom <= box.bottom)
339 // Add the exclusion to the extent
340 ExcludeBox(box, temp);
343 if(box.bottom >= box.top && box.right >= box.left)
345 // Optimization: if the resulting boxes touch, add them smarter
346 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
348 if(box.top == extentBox.box.top && box.bottom == extentBox.box.bottom)
350 if(Abs(box.right - extentBox.box.left) <= 1)
352 extentBox.box.left = box.left;
355 else if(Abs(box.left - extentBox.box.right) <= 1)
357 extentBox.box.right = box.right;
361 else if(box.left == extentBox.box.left && box.right == extentBox.box.right)
363 if(Abs(box.bottom - extentBox.box.top) <= 1)
365 extentBox.box.top = box.top;
368 else if(Abs(box.top - extentBox.box.bottom) <= 1)
370 extentBox.box.bottom = box.bottom;
382 void Union(Extent b, Extent temp)
386 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
387 UnionBox(extentBox.box, temp);
390 void Intersection(Extent b, Extent temp, Extent temp2, Extent temp3)
397 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
400 temp2.IntersectBox(extentBox.box);
407 void Exclusion(Extent b, Extent temp)
410 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
411 ExcludeBox(extentBox.box, temp);
414 void Offset(int x, int y)
417 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
419 extentBox.box.left += x;
420 extentBox.box.top += y;
421 extentBox.box.right += x;
422 extentBox.box.bottom += y;
427 private define MINIMIZED_WIDTH = 160;
428 private define CASCADE_SPACE = 16;
430 // namespace Windows;
432 private class ScrollFlags
434 bool snapX:1, snapY:1, dontHide:1;
437 public class BorderBits { public: bool contour:1, fixed:1, sizable:1, deep:1, bevel:1, thin:1; };
439 class WindowBits : BorderBits
441 BorderBits borderBits:6:0;
442 bool hidden:1, isActiveClient:1, hasHorzScroll:1, hasVertScroll:1, stayOnTop:1, modal:1, isDefault:1, inactive:1, isRemote:1, drawBehind:1;
443 bool interim:1, tabCycle:1, noCycle:1, dontScrollHorz:1, dontScrollVert:1, hasMaximize:1, hasMinimize:1, hasClose:1;
444 bool embedded:1, hasMenuBar:1, isDocument:1, showInTaskBar:1, hasStatusBar:1, nonClient:1, clickThrough:1;
447 public enum BorderStyle : BorderBits
450 contour = BorderBits { contour = true },
451 fixed = BorderBits { fixed = true } | contour,
452 sizable = BorderBits { sizable = true } | fixed,
453 thin = BorderBits { fixed = true, thin = true } | contour,
454 sizableThin = BorderBits { sizable = true } | thin,
455 deep = BorderBits { deep = true },
456 bevel = BorderBits { bevel = true },
457 sizableDeep = sizable|deep,
458 sizableBevel = sizable|bevel,
459 fixedDeep = fixed|deep,
460 fixedBevel = fixed|bevel,
461 deepContour = deep|contour
464 public enum CreationActivationOption
466 activate, flash, doNothing
469 public enum WindowState { normal, minimized, maximized };
471 private class ResPtr : struct
478 private class HotKeySlot : struct
480 HotKeySlot prev, next;
488 class_data char * icon;
490 class_default_property caption;
491 // class_initialize GuiApplication::Initialize;
492 class_designer FormDesigner;
493 class_property char * icon
495 set { class_data(icon) = value; }
496 get { return class_data(icon); }
501 if(guiApp) guiApp.Initialize(true);
503 if(guiApp && guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
505 if(_vTbl == ((subclass(Window))_class).pureVTbl)
507 _vTbl = _class._vTbl;
509 else if(_vTbl != _class._vTbl)
512 for(m = 0; m < _class.vTblSize; m++)
514 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
515 _vTbl[m] = _class._vTbl[m];
520 //tempExtents[0] = { /*first = -1, last = -1, free = -1*/ };
521 //tempExtents[1] = { /*first = -1, last = -1, free = -1*/ };
522 //tempExtents[2] = { /*first = -1, last = -1, free = -1*/ };
523 //tempExtents[3] = { /*first = -1, last = -1, free = -1*/ };
527 // caption = CopyString(class.name);
529 children.offset = (byte*)&prev - (byte*)this;
530 childrenOrder.circ = true;
531 childrenCycle.circ = true;
533 maxSize = Size { MAXINT, MAXINT };
537 //style.isActiveClient = true;
540 modifyVirtArea = true;
541 manageDisplay = true;
542 nativeDecorations = true;
544 // scrollFlags = ScrollFlags { snapX = true, snapY = true };
545 sbStep.x = sbStep.y = 8;
547 if(guiApp) // dynamic_cast<GuiApplication>(thisModule)
549 cursor = guiApp.GetCursor(arrow);
550 property::parent = guiApp.desktop;
562 stopwatching(parent, font);
563 if(parent.activeChild == this)
564 parent.activeChild = null;
565 if(parent.activeClient == this)
566 parent.activeClient = null;
571 // Prevent destructor from being called again...
577 /////////////////////////////////
580 OldLink slave = master.slaves.FindLink(this);
581 master.slaves.Delete(slave);
588 parent.childrenCycle.Remove(cycle);
590 parent.childrenOrder.Remove(order);
591 parent.children.Remove(this);
596 /////////////////////////////////
598 while(ptr = resources.first)
601 resources.Delete(ptr);
608 for(child = children.first; child; child = child.next)
610 // child.stopwatching(this, font);
612 eInstance_StopWatching(this, __ecereProp___ecereNameSpace__ecere__gui__Window_font, child);
613 // Don't want property here
614 *&child.parent = null;
617 while(slave = slaves.first)
619 // Don't want property here
620 *&((Window)slave.data).master = null;
621 slaves.Delete(slave);
624 // Because we do a decref in DestroyEx...
632 // Why was this commented?
633 //if(this != guiApp.desktop)
646 if(((subclass(Window))_class).pureVTbl)
648 if(_vTbl == _class._vTbl)
650 _vTbl = ((subclass(Window))_class).pureVTbl;
655 for(m = 0; m < _class.vTblSize; m++)
657 if(_vTbl[m] == _class._vTbl[m])
658 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
662 if(_vTbl == ((subclass(Window))_class).pureVTbl || _vTbl == _class._vTbl)
665 dirtyArea.Free(null);
666 renderArea.Free(null);
667 overRenderArea.Free(null);
668 clipExtent.Free(null);
669 scrollExtent.Free(null);
670 dirtyBack.Free(null);
674 tempExtents[0].Free(null);
675 tempExtents[1].Free(null);
676 tempExtents[2].Free(null);
677 tempExtents[3].Free(null);
682 //#if !defined(ECERE_VANILLA)
683 char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
685 if(this == activeDesigner)
689 char * name = property::name;
690 return name ? name : "";
695 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
696 bool OnGetDataFromString(char * string)
698 FormDesigner designer = (FormDesigner)activeDesigner.classDesigner;
701 if(!strcmp(string, "this") || !strcmp(string, designer.form.name))
702 this = designer.form;
703 else if(!strcmpi(string, "(Desktop)"))
704 this = activeDesigner;
706 return activeDesigner.FindObject(&this, string);
712 // --- Window updates system ---
714 // Setup a bitmap for Redrawing on client area of Window
715 Surface Redraw(Box box)
717 Surface surface = null;
719 Box clientArea = this.clientArea;
723 mox.left -= clientStart.x;
724 mox.top -= clientStart.y;
725 mox.right -= clientStart.x;
726 mox.bottom -= clientStart.y;
728 mox.Clip(clientArea);
729 // mox.ClipOffset(against, scrolledPos.x, scrolledPos.y);
731 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && mox.right >= mox.left && mox.bottom >= mox.top)
733 int x = absPosition.x + clientStart.x;
734 int y = absPosition.y + clientStart.y;
735 if(rootWindow.nativeDecorations)
737 x -= rootWindow.clientStart.x;
738 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
740 if(!guiApp.fullScreenMode || is3D)
742 x -= rootWindow.absPosition.x;
743 y -= rootWindow.absPosition.y;
747 x += rootWindow.parent.clientStart.x;
748 y += rootWindow.parent.clientStart.y;
750 mox.left += rootWindow.parent.clientStart.x;
751 mox.top += rootWindow.parent.clientStart.y;
752 mox.right += rootWindow.parent.clientStart.x;
753 mox.bottom += rootWindow.parent.clientStart.y;
758 surface = display.GetSurface(x, y, mox);
761 surface.width = clientSize.w;
762 surface.height = clientSize.h;
768 // Setup a bitmap for Redrawing on full Window
769 Surface RedrawFull(Box box)
771 Surface surface = null;
779 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && box.right >= box.left && box.bottom >= box.top)
781 int x = absPosition.x;
782 int y = absPosition.y;
783 if(rootWindow.nativeDecorations)
785 x -= rootWindow.clientStart.x;
786 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
788 if(!guiApp.fullScreenMode || is3D)
790 x -= rootWindow.absPosition.x;
791 y -= rootWindow.absPosition.y;
794 x += rootWindow.parent.clientStart.x;
795 y += rootWindow.parent.clientStart.y;
797 mox.left += rootWindow.parent.clientStart.x;
798 mox.top += rootWindow.parent.clientStart.y;
799 mox.right += rootWindow.parent.clientStart.x;
800 mox.bottom += rootWindow.parent.clientStart.y;
805 surface = display.GetSurface(x, y, mox);
808 surface.width = size.w;
809 surface.height = size.h;
815 void FigureCaption(char * caption)
817 Window activeClient = null;
821 strcpy(caption, this.caption);
822 if(style.isDocument || fileName)
824 if(caption[0]) strcat(caption, " - ");
826 strcat(caption, fileName);
830 sprintf(title, "Untitled %d", documentID);
831 strcat(caption, title);
834 strcat(caption, " *");
839 for(activeClient = this.activeClient; activeClient && !((BorderBits)activeClient.borderStyle).fixed; activeClient = activeClient.activeClient);
841 if(activeClient && activeClient.state == maximized)
843 if(activeClient.caption)
845 if(caption[0]) strcat(caption, " - ");
846 strcat(caption, activeClient.caption);
848 if(activeClient.style.isDocument || activeClient.fileName)
850 if(caption[0]) strcat(caption, " - ");
851 strcat(caption, "[");
852 if(activeClient.fileName)
853 strcat(caption, activeClient.fileName);
857 sprintf(title, "Untitled %d", activeClient.documentID);
858 strcat(caption, title);
860 if(activeClient.modifiedDocument)
861 strcat(caption, " *");
862 strcat(caption, "]");
867 // Code for returning dirty from ScrollDisplay:
869 for(d = 0; d<scrollExtent.count; d++)
871 Box * box = &scrollExtent.boxes[d];
877 Min(box.right, box.left-scroll.x),box.bottom
879 dirtyArea.UnionBox(update);
885 Max(box.left, box.right-scroll.x), box.top,
886 box.right, box.bottom
888 dirtyArea.UnionBox(update);
896 box.right, Min(box.bottom, box.top-scroll.y),
898 dirtyArea.UnionBox(update);
904 box.left, Max(box.top, box.bottom-scroll.y),
905 box.right, box.bottom
907 dirtyArea.UnionBox(update);
912 void UpdateDecorations(void)
914 // TODO: *** TEMPORARY HACK ***
921 Update({ -clientStart.x, -clientStart.y, -clientStart.x + size.w-1, 0 });
923 Update({ -clientStart.x, clientSize.h, -clientStart.x + size.w-1, -clientStart.y + size.h-1 });
925 Update({ -clientStart.x,0, -1, clientSize.h-1 });
927 Update({ clientSize.w, 0, -clientStart.x + size.w-1, clientSize.h-1 });
930 // Returns w & h for Position
931 void ComputeAnchors(Anchor anchor, SizeAnchor sizeAnchor, int *ox, int *oy, int *ow, int *oh)
933 Window parent = this.parent ? this.parent : guiApp.desktop;
934 int vpw = parent ? parent.clientSize.w : 0;
935 int vph = parent ? parent.clientSize.h : 0;
936 int pw = parent ? parent.clientSize.w : 0;
937 int ph = parent ? parent.clientSize.h : 0;
938 int w = sizeAnchor.size.w, h = sizeAnchor.size.h;
939 int x = anchor.left.distance, y = anchor.top.distance;
941 MinMaxValue ew = 0, eh = 0;
943 float cascadeW, cascadeH;
945 int tilingW, tilingH, tilingSplit, tilingLastH;
946 int addX = 0, addY = 0;
948 if(parent && rootWindow == this && guiApp && guiApp.interfaceDriver)
950 Window masterWindow = this;
951 Box box { addX, addY, addX + vpw - 1, addY + vph - 1 };
954 if(master == guiApp.desktop)
955 masterWindow = guiApp.desktop.activeChild;
957 masterWindow = master.rootWindow;
958 if(!masterWindow) masterWindow = this;
960 guiApp.interfaceDriver.GetScreenArea(masterWindow, box);
961 if((anchor.left.type == offset && anchor.right.type == offset) || anchor.left.type == none)
964 pw = vpw = box.right - box.left + 1;
966 if((anchor.top.type == offset && anchor.bottom.type == offset) || anchor.top.type == none)
969 ph = vph = box.bottom - box.top + 1;
985 vpw = pw = parent.size.w;
986 vph = ph = parent.size.h;
988 else if(!style.fixed /*|| style.isDocument*/)
990 if(!style.dontScrollHorz && parent.scrollArea.w) vpw = parent.scrollArea.w;
991 if(!style.dontScrollVert && parent.scrollArea.h) vph = parent.scrollArea.h;
993 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
996 Desktop3D_FixSize(&pw, &ph);
997 Desktop3D_FixSize(&vpw, &vph);
1000 if(pw < skinMinSize.w) pw = skinMinSize.w;
1001 if(ph < skinMinSize.h) ph = skinMinSize.h;
1002 if(vpw < skinMinSize.w) vpw = skinMinSize.w;
1003 if(vph < skinMinSize.h) vph = skinMinSize.h;
1005 // TODO: Must fix what we're snapping
1008 if(anchor.left.type)
1010 SNAPUP(x, textCellW);
1012 else if(anchor.right.type)
1014 SNAPDOWN(x, textCellW);
1019 SNAPUP(y, textCellH);
1021 else if(anchor.bottom.type)
1023 SNAPDOWN(y, textCellH);
1027 // This is required to get proper initial decoration size using native decorations on Windows
1028 if(nativeDecorations && guiApp && guiApp.interfaceDriver && !visible)
1029 guiApp.interfaceDriver.PositionRootWindow(this, x, y, Max(1, size.w), Max(1, size.h), true, true);
1030 GetDecorationsSize(&ew, &eh);
1032 if(anchor.left.type >= cascade && (state == normal /*|| state == Hidden*/))
1034 if(parent.sbv && !parent.sbv.style.hidden)
1035 pw += guiApp.currentSkin.VerticalSBW();
1036 if(parent.sbh && !parent.sbh.style.hidden)
1037 ph += guiApp.currentSkin.HorizontalSBH();
1039 if(anchor.left.type == cascade)
1041 w = (int)(pw * 0.80);
1042 h = (int)(ph * 0.80);
1044 else if(anchor.left.type >= vTiled)
1049 numTiling = parent.numPositions - parent.numIcons;
1050 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1051 if(anchor.left.type == vTiled)
1053 tilingH = (int)sqrt(numTiling);
1054 tilingW = numTiling / tilingH;
1058 tilingW = (int)sqrt(numTiling);
1059 tilingH = numTiling / tilingW;
1062 leftOver = numTiling - tilingH * tilingW;
1065 tilingSplit = (tilingW - leftOver) * tilingH;
1066 tilingLastH = tilingH+1;
1069 tilingSplit = numTiling;
1071 if(positionID >= tilingSplit)
1073 x = pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
1074 y = ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
1075 x2 = pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
1076 y2 = ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
1080 x = pw * (positionID / tilingH) / tilingW;
1081 y = ph * (positionID % tilingH) / tilingH;
1082 x2 = pw * (positionID / tilingH + 1) / tilingW;
1083 y2 = ph * ((positionID % tilingH) + 1) / tilingH;
1087 SNAPDOWN(x, textCellW);
1088 SNAPDOWN(y, textCellH);
1089 SNAPDOWN(x2, textCellW);
1090 SNAPDOWN(y2, textCellH);
1098 if(sizeAnchor.isClientW) w += ew;
1099 if(sizeAnchor.isClientH) h += eh;
1101 if(anchor.left.type == offset)
1102 x = anchor.left.distance;
1103 else if(anchor.left.type == relative)
1104 x = (anchor.left.percent < 0) ? ((int)(vpw * anchor.left.percent - 0.5)) : (int)(vpw * anchor.left.percent + 0.5);
1105 else if(anchor.right.type == relative)
1106 // ex = (anchor.right.percent < 0) ? ((int)(vpw * anchor.right.percent + 0)) : ((int)(vpw * anchor.right.percent + 0));
1107 ex = (anchor.right.percent < 0) ? ((int)(vpw * (1.0-anchor.right.percent) + 0)) : ((int)(vpw * (1.0-anchor.right.percent) + 0));
1108 else if(anchor.right.type == offset)
1109 ex = vpw - anchor.right.distance;
1111 if(anchor.top.type == offset)
1112 y = anchor.top.distance;
1113 else if(anchor.top.type == relative)
1114 y = (anchor.top.percent < 0) ? ((int)(vph * anchor.top.percent - 0.5)) : ((int)(vph * anchor.top.percent + 0.5));
1115 else if(anchor.bottom.type == relative)
1116 //ey = (anchor.bottom.percent < 0) ? ((int)(vph * anchor.bottom.percent + 0)) : ((int)(vph * anchor.bottom.percent + 0));
1117 ey = (anchor.bottom.percent < 0) ? ((int)(vph * (1.0-anchor.bottom.percent) + 0)) : ((int)(vph * (1.0-anchor.bottom.percent) + 0));
1118 else if(anchor.bottom.type == offset)
1119 ey = vph - anchor.bottom.distance;
1121 if(anchor.left.type && anchor.right.type)
1123 switch(anchor.right.type)
1126 ex = pw * (1.0f-anchor.right.percent);
1127 w = Max((int)(ex + 0.5) - x, 0);
1130 ex = vpw - anchor.right.distance;
1131 w = Max((int)(ex + 0.5) - x, 0);
1135 if(anchor.top.type && anchor.bottom.type)
1137 switch(anchor.bottom.type)
1140 ey = ph * (1.0f-anchor.bottom.percent);
1141 h = Max((int)(ey + 0.5) - y, 0);
1144 ey = vph - anchor.bottom.distance;
1145 h = Max((int)(ey + 0.5) - y, 0);
1154 if(state == normal /*|| state == Hidden*/)
1156 bool addSbV = false, addSbH = false;
1158 if(sizeAnchor.isClientW || (anchor.left.type && anchor.right.type)) w = Max(w, 1); else w = Max(w, 0);
1159 if(sizeAnchor.isClientH || (anchor.top.type && anchor.bottom.type)) h = Max(h, 1); else h = Max(h, 0);
1161 w = Max(w, minSize.w);
1162 h = Max(h, minSize.h);
1163 w = Min(w, maxSize.w);
1164 h = Min(h, maxSize.h);
1166 if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
1168 if(w) w -= guiApp.currentSkin.VerticalSBW();
1171 if((sizeAnchor.isClientH || !h || (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
1173 if(h) h -= guiApp.currentSkin.HorizontalSBH();
1177 if(!OnResizing(&w, &h))
1183 if((addSbV)) // || reqScrollArea.h > h) && sbv)
1184 w += guiApp.currentSkin.VerticalSBW();
1185 if((addSbH)) // || reqScrollArea.w > w) && sbh)
1186 h += guiApp.currentSkin.HorizontalSBH();
1188 w = Max(w, skinMinSize.w);
1189 h = Max(h, skinMinSize.h);
1202 SNAPDOWN(w, textCellW);
1203 SNAPDOWN(h, textCellH);
1206 if(anchor.left.type == cascade && (state == normal /*|| state == Hidden*/))
1208 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1211 (pw - w) / CASCADE_SPACE,
1212 (ph - h) / CASCADE_SPACE);
1218 cascW = (pw - w) / (numCascade-1);
1219 cascH = (ph - h) / (numCascade-1);
1220 SNAPDOWN(cascW, textCellW);
1221 SNAPDOWN(cascH, textCellH);
1222 cascadeW = (float)cascW;
1223 cascadeH = (float)cascH;
1227 numCascade = Max(numCascade, 2);
1228 cascadeW = (float)(pw - w) / (numCascade-1);
1229 cascadeH = (float)(ph - h) / (numCascade-1);
1232 x = (int)((positionID % numCascade) * cascadeW);
1233 y = (int)((positionID % numCascade) * cascadeH);
1235 else if(anchor.left.type < vTiled)
1237 if(!anchor.left.type || anchor.horz.type == middleRelative)
1239 if(!anchor.right.type)
1241 if(anchor.horz.type == middleRelative)
1242 x = (int)(vpw * (0.5 + anchor.horz.percent) - w / 2);
1244 x = vpw / 2 + anchor.horz.distance - w / 2;
1250 // case A_EDGE: x = x - w; break;
1252 if(!anchor.top.type || anchor.vert.type == middleRelative)
1254 if(!anchor.bottom.type)
1256 if(anchor.vert.type == middleRelative)
1257 y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
1259 y = vph / 2 + anchor.vert.distance - h / 2;
1265 // case A_EDGE: y = y - h; break;
1268 if((state == normal /*|| state == Hidden*/) && !OnMoving(&x, &y, w, h))
1276 SNAPDOWN(x, textCellW);
1277 SNAPDOWN(y, textCellH);
1289 if(anchored && style.fixed && style.isActiveClient)
1294 void UpdateCaret(bool forceUpdate, bool erase)
1296 static Window lastWindow = null;
1297 static int caretX, caretY, caretSize;
1299 if(guiApp && guiApp.caretOwner == this)
1301 int x = caretPos.x - scroll.x;
1302 int y = caretPos.y - scroll.y;
1304 if((erase || this.caretSize) &&
1305 x >= clientArea.left && x <= clientArea.right &&
1306 y >= clientArea.top && y <= clientArea.bottom)
1310 guiApp.interfaceDriver.SetCaret(
1311 x + absPosition.x + clientStart.x,
1312 y + absPosition.y + clientStart.y, this.caretSize);
1313 guiApp.caretEnabled = true;
1315 if(erase || lastWindow != this || caretX != x || caretY != y || caretSize != this.caretSize || forceUpdate)
1319 if(lastWindow != this)
1321 updateBox.left = x + 1;
1323 updateBox.right = x + 2;
1324 updateBox.bottom = y + this.caretSize - 1;
1328 updateBox.left = Min(x + 1, caretX + 1);
1329 updateBox.top = Min(y, caretY);
1330 updateBox.right = Max(x + 2, caretX + 2);
1331 updateBox.bottom = Max(y + this.caretSize - 1, caretY + caretSize - 1);
1334 guiApp.caretOwner.Update(updateBox);
1341 caretSize = this.caretSize;
1347 guiApp.interfaceDriver.SetCaret(0,0,0);
1348 guiApp.caretEnabled = false;
1354 void SetPosition(int x, int y, int w, int h, bool modifyArea, bool modifyThisArea, bool modifyClientArea)
1359 scrolledPos.x = position.x = x;
1360 scrolledPos.y = position.y = y;
1362 clientSize.w = size.w = w;
1363 clientSize.h = size.h = h;
1365 if(parent && !style.nonClient)
1367 //if(!style.fixed || style.isDocument)
1369 if(!style.dontScrollHorz) scrolledPos.x -= parent.scroll.x;
1370 if(!style.dontScrollVert) scrolledPos.y -= parent.scroll.y;
1374 clientStart.x = clientStart.y = 0;
1376 SetWindowArea(&clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1378 //if(!activeClient || activeClient.state != maximized)
1379 if(!noAutoScrollArea)
1381 // Check if scroll area must be modified
1382 if(guiApp && !guiApp.modeSwitching && (sbv || sbh))
1384 bool foundChild = false;
1386 int cw = clientSize.w;// + ((!sbv || sbv.range > 1) ? guiApp.currentSkin.VerticalSBW() : 0);
1387 int ch = clientSize.h;// + ((!sbh || sbh.rangw > 1) ? guiApp.currentSkin.HorizontalSBH() : 0);
1388 for(child = children.first; child; child = child.next)
1390 if(child.modifyVirtArea && !child.style.hidden && child.created && /*!child.anchored &&*/
1391 !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1393 if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == offset)
1394 w = Max(w, child.position.x + child.size.w);
1395 else if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == none)
1396 w = Max(w, Max(child.position.x, 0) + child.size.w);
1397 if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == offset)
1398 h = Max(h, child.position.y + child.size.h);
1399 else if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == none)
1400 h = Max(h, Max(child.position.y, 0) + child.size.h);
1405 if(foundChild && (w > cw || h > ch))
1407 //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
1409 int stepX = sbStep.x, stepY = sbStep.y;
1410 // Needed to make snapped down position match the skin's check of client area
1411 // against realvirtual
1414 SNAPDOWN(stepX, textCellW);
1415 SNAPDOWN(stepY, textCellH);
1416 stepX = Max(stepX, textCellW);
1417 stepY = Max(stepY, textCellH);
1419 if(scrollFlags.snapX)
1421 if(scrollFlags.snapY)
1424 reqScrollArea.w = w;
1425 reqScrollArea.h = h;
1428 else if(reqScrollArea.w || reqScrollArea.h)
1430 reqScrollArea.w = 0;
1431 reqScrollArea.h = 0;
1432 SetScrollPosition(0,0);
1437 // Automatic MDI Client Scrolling Area Adjustment
1438 if(parent && !parent.noAutoScrollArea)
1440 if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
1441 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
1443 Window parent = this.parent;
1444 int w = parent.reqScrollArea.w;
1445 int h = parent.reqScrollArea.h;
1447 if(stateAnchor.right.type == none && stateAnchor.left.type == offset)
1448 w = Max(w, position.x + size.w);
1449 else if(stateAnchor.right.type == none && stateAnchor.left.type == none)
1450 w = Max(w, Max(position.x, 0) + size.w);
1451 if(stateAnchor.bottom.type == none && stateAnchor.top.type == offset)
1452 h = Max(h, position.y + size.h);
1453 else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
1454 h = Max(h, Max(position.y, 0) + size.h);
1456 if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
1457 (h > parent.clientSize.h && h > parent.reqScrollArea.h))
1459 /*bool resize = false;
1460 int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
1461 // Needed to make snapped down position match the skin's check of client area
1462 // against realvirtual
1465 SNAPDOWN(stepX, textCellW);
1466 SNAPDOWN(stepY, textCellH);
1467 stepX = Max(stepX, textCellW);
1468 stepY = Max(stepY, textCellH);
1470 if(parent.scrollFlags.snapX)
1472 if(parent.scrollFlags.snapY)
1474 if(parent.reqScrollArea.w != w || parent.reqScrollArea.h != h)
1476 parent.reqScrollArea.w = w;
1477 parent.reqScrollArea.h = h;*/
1479 // parent.UpdateScrollBars(true, true);
1480 parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1481 false, true, true, true, false, false);
1486 GetRidOfVirtualArea();
1490 UpdateScrollBars(modifyThisArea, false);
1491 else if(guiApp.currentSkin)
1494 &clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1496 if(sbv && (scrollFlags.dontHide || sbv.range > 1))
1497 clientSize.w -= guiApp.currentSkin.VerticalSBW();
1498 if(sbh && (scrollFlags.dontHide || sbh.range > 1))
1499 clientSize.h -= guiApp.currentSkin.HorizontalSBH();
1502 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1503 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1505 absPosition = scrolledPos;
1506 if(guiApp && guiApp.driver != null && guiApp.interfaceDriver)
1507 guiApp.interfaceDriver.OffsetWindow(this, &absPosition.x, &absPosition.y);
1509 if(this != guiApp.desktop && parent)
1511 absPosition.x += parent.absPosition.x;
1512 absPosition.y += parent.absPosition.y;
1513 if(!style.nonClient && this != guiApp.desktop)
1515 absPosition.x += parent.clientStart.x;
1516 absPosition.y += parent.clientStart.y;
1520 box = Box { 0, 0, size.w - 1, size.h - 1 };
1525 // Clip against parent's client area
1526 box.ClipOffset(against, scrolledPos.x, scrolledPos.y);
1528 // Compute client area in this window coordinate system
1529 clientArea.left = 0;
1531 clientArea.right = clientSize.w - 1;
1532 clientArea.bottom = clientSize.h - 1;
1534 // Clip against parent's client area
1536 clientArea.ClipOffset(against, scrolledPos.x + clientStart.x, scrolledPos.y + clientStart.y);
1540 //absPosition.x -= parent.clientStart.x;
1541 //absPosition.y -= parent.clientStart.y;
1544 // Adjust all children
1545 for(child = children.first; child; child = child.next)
1546 child.SetPosition(child.position.x, child.position.y, child.size.w, child.size.h, false, true, true);
1548 UpdateCaret(false, false);
1551 void GetRidOfVirtualArea(void)
1553 if(parent && !parent.destroyed && style.fixed &&
1554 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient &&
1555 parent.reqScrollArea.w && parent.reqScrollArea.h)
1557 if(!parent.noAutoScrollArea)
1561 for(child = children.first; child; child = child.next)
1563 if(child.modifyVirtArea && !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1565 if(child.position.x + child.size.w > parent.clientSize.w + ((!parent.sbv || parent.sbv.style.hidden) ? 0 : guiApp.currentSkin.VerticalSBW()) ||
1566 child.position.y + child.size.h > parent.clientSize.h + ((!parent.sbh || parent.sbh.style.hidden) ? 0 : guiApp.currentSkin.HorizontalSBH()))
1575 Window parent = this.parent;
1577 parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1578 false, true, true, true, false, false);
1580 parent.SetScrollArea(0,0,true);
1581 parent.SetScrollPosition(0,0);
1587 public void ExternalPosition(int x, int y, int w, int h)
1589 Position(x, y, w, h, false, true, true, true, false, false);
1592 // (w, h): Full window size
1593 bool Position(int x, int y, int w, int h, bool force, bool processAnchors, bool modifyArea, bool updateScrollBars, bool thisOnly, bool changeRootWindow)
1595 bool result = false;
1596 int oldCW = clientSize.w, oldCH = clientSize.h;
1597 bool clientResized, windowResized, windowMoved;
1599 bool realResized = size.w != w || size.h != h;
1601 // TOCHECK: This wasn't in ecere.dll
1602 //if(!parent) return true;
1603 if(destroyed) return false;
1605 windowMoved = position.x != x || position.y != y || force;
1607 // windowResized = realResized || force;
1608 windowResized = size.w != w || size.h != h || force;
1610 if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
1616 scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
1617 scrolledPos.x - parent.clientStart.x + this.box.right,
1618 scrolledPos.y - parent.clientStart.y + this.box.bottom
1624 Box box { scrolledPos.x + this.box.left, scrolledPos.y + this.box.top, scrolledPos.x + this.box.right, scrolledPos.y + this.box.bottom};
1629 SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
1631 clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
1632 if(clientResized && this == rootWindow && nativeDecorations)
1633 windowResized = true;
1635 if(display && rootWindow != this)
1638 if(guiApp && guiApp.windowMoving)
1640 if(guiApp.windowMoving.style.nonClient)
1641 guiApp.windowMoving.parent.SetMouseRangeToWindow();
1643 guiApp.windowMoving.parent.SetMouseRangeToClient();
1653 // Buttons bitmap resources crash if we do this while switching mode
1654 if(!guiApp || !guiApp.modeSwitching)
1657 // Process Anchored Children
1661 for(child = children.first; child; child = child.next)
1664 ((child.stateAnchor.left.type != offset ||
1665 child.stateAnchor.top.type != offset ||
1666 child.stateAnchor.right.type != none ||
1667 child.stateAnchor.bottom.type != none) ||
1668 child.state == maximized || child.state == minimized))
1670 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1672 // child.Position(x, y, w, h, false, true, true, true, false);
1673 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1674 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1680 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1681 //if(updateScrollBars)
1683 OnResize(clientSize.w, clientSize.h);
1685 if((clientResized || windowMoved) && created)
1686 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1688 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1690 Window master = guiApp.interimWindow.master;
1691 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1694 if(rootWindow == this && !is3D)
1698 x -= guiApp.desktop.absPosition.x;
1699 y -= guiApp.desktop.absPosition.y;
1701 //guiApp.Log("Position %s\n", caption);
1702 if(windowResized || windowMoved)
1703 if(display && !display.flags.memBackBuffer && changeRootWindow)
1704 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1706 if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved))
1707 for(child = parent.children.first; child && child != this; child = child.next)
1708 if(child.rootWindow)
1709 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1713 if(windowMoved || windowResized)
1715 display.Lock(true /*false*/);
1718 display.Position(absPosition.x, absPosition.y);
1719 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1722 // result = realResized ? display.Resize(size.w, size.h) : true;
1723 if(nativeDecorations)
1725 int w = clientSize.w, h = clientSize.h;
1726 if(hasMenuBar) h += skinMenuHeight;
1727 if(hasStatusBar) h += statusBarHeight;
1728 if(sbv && sbv.visible) w += sbv.size.w;
1729 if(sbh && sbh.visible) h += sbh.size.h;
1730 result = manageDisplay ? display.Resize(w, h) : true;
1733 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1737 else if(clientResized)
1739 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1742 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1746 if(windowMoved || windowResized)
1751 if(guiApp.driver && changeRootWindow)
1753 if(windowResized || windowMoved)
1754 if(!display || display.flags.memBackBuffer)
1755 guiApp.interfaceDriver.PositionRootWindow(this,
1756 x, y, w, h, windowMoved, windowResized);
1757 guiApp.interfaceDriver.UpdateRootWindow(this);
1759 for(child = children.first; child; child = child.next)
1761 if(child.is3D && child.created)
1763 // Copy Display Content
1764 child.display.displaySystem = display.displaySystem;
1765 child.display.window = display.window;
1766 child.display.current = display.current;
1767 child.display.width = display.width;
1768 child.display.height = display.height;
1769 child.display.driverData = display.driverData;
1770 child.display.mutex = null;
1781 void UpdateScrollBars(bool flag, bool fullThing)
1784 bool resizeH = false, resizeV = false;
1785 bool scrolled = false;
1786 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1787 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1789 if(destroyed) return;
1790 if(guiApp.currentSkin)
1792 MinMaxValue cw = 0, ch = 0;
1793 bool sbvVisible, sbhVisible;
1795 int positionH, positionV;
1797 // First get client area with no respect to scroll bars
1802 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1804 if(scrollFlags.dontHide)
1807 cw -= guiApp.currentSkin.VerticalSBW();
1809 ch -= guiApp.currentSkin.HorizontalSBH();
1811 // Update the scrollbar visibility
1817 sbh.disabled = rangeH <= 1;
1818 if(sbh.style.hidden)
1828 sbv.disabled = rangeV <= 1;
1829 if(sbv.style.hidden)
1837 // Then start off with horizontal scrollbar range
1840 positionH = sbh.thumbPosition;
1845 ch -= guiApp.currentSkin.HorizontalSBH();
1848 // Do the same for vertical scrollbar
1851 positionV = sbv.thumbPosition;
1857 cw -= guiApp.currentSkin.VerticalSBW();
1858 // Maybe we need to set the range on the horizontal scrollbar again
1863 sbh.Action(setRange, positionH, 0);
1864 if(rangeH <= 1 && sbh.range > 1)
1866 ch -= guiApp.currentSkin.HorizontalSBH();
1870 sbv.Action(setRange, positionV, 0);
1877 // Update the scrollbar visibility
1878 if(!scrollFlags.dontHide)
1880 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
1884 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
1891 if(guiApp.currentSkin)
1898 sbhVisible = sbh.style.hidden ? true : false;
1900 sbvVisible = sbv.style.hidden ? true : false;
1902 // Do our resize here
1903 if(flag && (resizeH || resizeV) && fullThing)
1905 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
1910 OnResize(clientSize.w, clientSize.h);
1916 sbh.visible = sbhVisible;
1918 sbv.visible = sbvVisible;
1920 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1921 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1924 sbh.pageStep = clientSize.w;
1926 sbv.pageStep = clientSize.h;
1928 // Notify doesn't handle setRange anymore... process it here
1931 int positionH = sbh.thumbPosition;
1932 if(scroll.x != positionH)
1934 OnHScroll(setRange, positionH, 0);
1938 SNAPDOWN(positionH, textCellW);
1939 scroll.x = positionH;
1945 int seen = clientSize.w, total = reqScrollArea.w;
1948 if(scrollFlags.snapX)
1949 SNAPDOWN(seen, sbStep.x);
1951 if(!total) total = seen;
1952 range = total - seen + 1;
1954 range = Max(range, 1);
1956 if(x >= range) x = range - 1;
1958 if(scrollFlags.snapX)
1959 SNAPUP(x, sbStep.x);
1963 OnHScroll(setRange, x, 0);
1968 SNAPDOWN(x, textCellW);
1974 int positionV = sbv.thumbPosition;
1975 if(scroll.y != positionV)
1977 OnVScroll(setRange, positionV, 0);
1981 SNAPDOWN(positionV, textCellH);
1982 scroll.y = positionV;
1988 int seen = clientSize.h, total = reqScrollArea.h;
1991 if(scrollFlags.snapY)
1992 SNAPDOWN(seen, sbStep.y);
1994 if(!total) total = seen;
1995 range = total - seen + 1;
1996 range = Max(range, 1);
1998 if(y >= range) y = range - 1;
2000 if(scrollFlags.snapY)
2001 SNAPUP(y, sbStep.y);
2005 OnVScroll(setRange, y, 0);
2010 SNAPDOWN(y, textCellH);
2016 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2019 for(child = children.first; child; child = child.next)
2021 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2024 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2025 child.Position(x, y, w, h, false, true, false, true, false, false);
2032 // Process Scrollbars
2034 if(sbh) // && !sbh.style.hidden
2036 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2037 // Need to set the range again (should improve...) since the scrollbars didn't have
2038 // the right size when UpdateScrollArea set the range on it
2041 sbh.seen = clientSize.w;
2045 if(sbv) // && !sbv.state.hidden
2047 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2048 // Need to set the range again (should improve...) since the scrollbars didn't have
2049 // the right size when UpdateScrollArea set the range on it
2052 sbv.seen = clientSize.h;
2057 // TESTING THIS LOWER
2058 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2061 for(child = children.first; child; child = child.next)
2063 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2066 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2067 child.Position(x, y, w, h, false, true, false, true, false, false);
2073 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2075 SetState(maximized, false, mods);
2079 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2081 SetState(normal, false, mods);
2085 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2087 SetState(minimized, false, mods);
2088 parent.CycleChildren(false, true, false, true);
2092 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2095 // Scroll bar notifications
2096 if(action != setRange)
2098 bool changed = false;
2102 if(scroll.x != position)
2104 OnHScroll(action, position, keyFlags);
2109 SNAPDOWN(position, textCellW);
2111 scroll.x = position;
2115 if(scroll.y != position)
2117 OnVScroll(action, position, keyFlags);
2122 SNAPDOWN(position, textCellH);
2124 scroll.y = position;
2128 bool childMove = false;
2129 for(child = children.first; child; child = child.next)
2131 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2134 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2135 child.Position(x, y, w, h, false, true, false, true, false, false);
2139 // Testing this patch out to solve MDI workspace redraw bugs
2140 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2141 // Scroll offsets to blame?
2145 UpdateCaret(false, false);
2149 // Testing this patch out to solve MDI workspace redraw bugs
2150 for(child = children.first; child; child = child.next)
2152 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2161 Window GetParentMenuBar()
2163 Window menuBarParent;
2164 for(menuBarParent = this; menuBarParent; menuBarParent = menuBarParent.parent)
2166 if(menuBarParent.menuBar) break;
2167 if(menuBarParent.parent && /*menuBarParent != */!menuBarParent.parent.activeClient)
2169 menuBarParent = null;
2173 return menuBarParent ? menuBarParent.menuBar : null;
2176 void CreateSystemChildren(void)
2178 Window parent = this;
2179 bool scrollBarChanged = false;
2180 bool hasClose = false, hasMaxMin = false;
2181 Point scroll = this.scroll;
2183 if(state == maximized)
2184 parent = GetParentMenuBar();
2188 if(style.hasClose) hasClose = true;
2189 if(style.hasMaximize || style.hasMinimize)
2196 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2198 sysButtons[2].Destroy(0);
2199 sysButtons[2] = null;
2201 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2203 sysButtons[1].Destroy(0);
2204 sysButtons[1] = null;
2206 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2208 sysButtons[0].Destroy(0);
2209 sysButtons[0] = null;
2212 if(hasClose && parent)
2219 parent, master = this,
2220 inactive = true, nonClient = true, visible = false;
2222 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2228 if(this.parent == guiApp.desktop)
2229 sysButtons[2].hotKey = altF4;
2230 else if(style.isActiveClient)
2231 sysButtons[2].hotKey = ctrlF4;
2232 sysButtons[2].Create();
2235 sysButtons[2].symbol = 'X';
2236 sysButtons[2].disabled = !style.hasClose;
2239 if(hasMaxMin && parent)
2243 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2244 if(state == maximized)
2247 method = RestoreButtonClicked;
2253 method = MaximizeButtonClicked;
2261 parent, master = this,
2262 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2264 sysButtons[1].Create();
2266 sysButtons[1].NotifyClicked = method;
2268 sysButtons[1].symbol = symbol;
2269 sysButtons[1].disabled = !style.hasMaximize;
2272 if(hasMaxMin && parent)
2276 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2277 if (state == minimized)
2280 method = RestoreButtonClicked;
2286 method = MinimizeButtonClicked;
2294 parent, master = this,
2295 hotKey = altM, inactive = true, nonClient = true, visible = false
2297 sysButtons[0].Create();
2299 sysButtons[0].NotifyClicked = method;
2301 sysButtons[0].symbol = symbol;
2302 sysButtons[0].disabled = !style.hasMinimize;
2305 // Create the scrollbars
2306 if(style.hasHorzScroll && !sbh)
2312 direction = horizontal,
2316 snap = scrollFlags.snapX,
2317 NotifyScrolling = ScrollBarNotification
2320 scrollBarChanged = true;
2322 else if(sbh && !style.hasHorzScroll)
2328 if(style.hasVertScroll && !sbv)
2334 direction = vertical,
2338 snap = scrollFlags.snapY,
2339 NotifyScrolling = ScrollBarNotification
2342 scrollBarChanged = true;
2344 else if(sbv && !style.hasVertScroll)
2349 if(scrollBarChanged)
2351 SetScrollLineStep(sbStep.x, sbStep.y);
2352 UpdateScrollBars(true, true);
2356 if(scrollBarChanged)
2358 if(sbh) sbh.thumbPosition = scroll.x;
2359 if(sbv) sbv.thumbPosition = scroll.y;
2363 void UpdateCaption(void)
2365 if(rootWindow == this)
2368 FigureCaption(caption);
2369 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2371 UpdateDecorations();
2374 if(parent.activeClient == this) // Added this last check
2376 if(parent.rootWindow == parent)
2379 parent.FigureCaption(caption);
2380 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2383 parent.UpdateCaption();
2385 parent.UpdateDecorations();
2389 void UpdateActiveDocument(Window previous)
2391 Window activeClient = this.activeClient;
2392 Window activeChild = this.activeChild;
2399 activeClient.CreateSystemChildren();
2401 previous.CreateSystemChildren();
2413 // Build window list
2416 Menu windowMenu = menu.FindMenu("Window");
2421 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2424 Window document = cycle.data;
2425 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2427 char name[2048], caption[2048];
2428 document.FigureCaption(caption);
2429 sprintf(name, "%d %s", id+1, caption);
2430 windowMenu.AddDynamic(MenuItem
2432 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2433 NotifySelect = MenuWindowSelectWindow
2437 if(activeClient.cycle == cycle) break;
2442 if((!previous && activeClient) || !activeClient)
2448 item = menu.FindItem(MenuWindowCloseAll, 0);
2449 if(item) item.disabled = false;
2450 item = menu.FindItem(MenuWindowNext, 0);
2451 if(item) item.disabled = false;
2452 item = menu.FindItem(MenuWindowPrevious, 0);
2453 if(item) item.disabled = false;
2454 item = menu.FindItem(MenuWindowCascade, 0);
2455 if(item) item.disabled = false;
2456 item = menu.FindItem(MenuWindowTileHorz, 0);
2457 if(item) item.disabled = false;
2458 item = menu.FindItem(MenuWindowTileVert, 0);
2459 if(item) item.disabled = false;
2460 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2461 if(item) item.disabled = false;
2462 item = menu.FindItem(MenuWindowWindows, 0);
2463 if(item) item.disabled = false;
2466 item = menu.FindItem(MenuFileClose, 0);
2467 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2468 item = menu.FindItem(MenuFileSaveAll, 0);
2469 if(item) item.disabled = numDocuments < 1;
2471 if(activeClient && activeClient.menu && activeClient.state != minimized)
2475 //activeClient.menu.Clean(activeClient);
2476 menu.Merge(activeClient.menu, true, activeClient);
2480 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2483 menu.Merge(activeChild.menu, true, activeChild);
2486 // This is called again for a child window change, with same active client
2487 OnActivateClient(activeClient, previous);
2488 if(!menuBar && !((BorderBits)borderStyle).fixed && parent && parent.activeClient == this)
2489 parent.UpdateActiveDocument(null);
2492 void _ShowDecorations(Box box, bool post)
2494 if(rootWindow == this && nativeDecorations) return;
2495 if(visible && this != guiApp.desktop)
2497 Surface surface = RedrawFull(box);
2501 FigureCaption(caption);
2504 ShowDecorations(captionFont.font,
2507 active, //parent.activeClient == this
2508 guiApp.windowMoving == this);
2510 PreShowDecorations(captionFont.font,
2513 active, //parent.activeClient == this
2514 guiApp.windowMoving == this);
2521 void UpdateExtent(Box refresh)
2523 Surface surface = null;
2525 if(!manageDisplay) { OnRedraw(null);return; }
2526 _ShowDecorations(refresh, false);
2528 surface = Redraw(refresh);
2529 // Opaque background: just fill before EW_REDRAW (clear?)
2532 surface.SetBackground(background);
2533 surface.SetForeground(foreground);
2534 surface.DrawingChar(' ');
2535 if(this == rootWindow)
2537 if(style.drawBehind || background.a)
2539 int a = background.a;
2540 // Premultiply alpha for clear color
2541 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2542 surface.Clear(colorBuffer);
2543 surface.SetBackground(background);
2546 else if(background.a)
2550 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2551 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2554 if(display.flags.alpha && background.a < 255 && background)
2556 surface.Area(0,0,clientSize.w, clientSize.h);
2557 /*if(style.clearDepthBuffer)
2558 surface.Clear(depthBuffer);*/
2560 else if(/*style.clearDepthBuffer || */background.a)
2562 int a = background.a;
2563 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2564 // Premultiply alpha for clear color
2565 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2566 surface.Clear(colorBuffer);
2567 surface.SetBackground(background);
2572 surface.TextFont(usedFont.font);
2573 surface.TextOpacity(false);
2577 // Draw the caret ...
2578 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2580 // surface.SetBackground(0xFFFFFF - background.color);
2581 surface.SetBackground(~background.color);
2583 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2584 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2590 void DrawOverChildren(Box refresh)
2592 Surface surface = Redraw(refresh);
2596 surface.DrawingChar(' ');
2597 surface.SetBackground(background);
2598 surface.SetForeground(foreground);
2600 surface.TextFont(usedFont.font);
2601 surface.TextOpacity(false);
2603 OnDrawOverChildren(surface);
2608 _ShowDecorations(refresh, true);
2611 void ComputeClipExtents(void)
2614 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2616 clipExtent.Copy(this.clipExtent);
2618 for(child = children.last; child; child = child.prev)
2620 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2622 bool opaque = child.IsOpaque(); // TODO: acess background directly
2623 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2625 child.clipExtent.Copy(clipExtent);
2626 child.clipExtent.Offset(-dx, -dy);
2627 child.clipExtent.IntersectBox(child.box);
2629 child.ComputeClipExtents();
2631 if(opaque && !child.style.nonClient)
2633 // Adjust the box for the parent:
2634 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2635 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2640 // ??? Only do this for overlapped window or if parent has with clip children flag
2642 // Do this if window has clip children flag on (default false?)
2643 // this.clipExtent = clipExtent;
2645 clipExtent.Free(null);
2648 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2650 bool opaque = IsOpaque();
2652 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2653 if(rootWindow.nativeDecorations)
2655 offsetX -= rootWindow.clientStart.x;
2656 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2660 for(child = children.last; child; child = child.prev)
2662 ColorAlpha background = *(ColorAlpha *)&child.background;
2663 bool opaque = child.IsOpaque();
2664 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2668 // Adjust renderArea to the root window level
2669 Extent * renderArea = &rootWindow.tempExtents[1];
2671 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2672 if(child.rootWindow.nativeDecorations)
2674 offsetX -= child.rootWindow.clientStart.x;
2675 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2679 Extent childRenderArea;
2681 if(backBufferUpdate != null)
2683 childRenderArea.Copy(backBufferUpdate);
2684 childRenderArea.Offset(-offsetX, -offsetY);
2687 childRenderArea.Copy(child.dirtyArea);
2689 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2690 renderArea.Copy(dirtyExtent);
2691 renderArea.Offset(-offsetX, -offsetY);
2692 childRenderArea.Union(renderArea);
2695 // Intersect with the clip extent
2696 childRenderArea.Intersection(child.clipExtent);
2699 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2700 renderArea->Offset(offsetX, offsetY);
2701 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2702 // overDirtyExtent.Union(renderArea);
2703 renderArea->Empty();
2704 // childRenderArea.Free();
2706 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2711 for(child = children.last; child; child = child.prev)
2713 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2715 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2720 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2722 bool opaque = IsOpaque();
2723 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2725 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2726 if(rootWindow.nativeDecorations)
2728 offsetX -= rootWindow.clientStart.x;
2729 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2733 for(child = children.last; child; child = child.prev)
2735 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2737 ColorAlpha background = *(ColorAlpha *)&child.background;
2738 bool opaque = child.IsOpaque();
2739 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2743 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2744 // Adjust renderArea to the root window level
2746 renderArea.Copy(child.dirtyArea);
2747 renderArea.Offset(offsetX, offsetY);
2748 dirtyExtent.Union(renderArea);
2749 overDirtyExtent.Union(renderArea);
2755 for(child = children.last; child; child = child.prev)
2757 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2759 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2763 if(backBufferUpdate != null)
2765 renderArea.Copy(backBufferUpdate);
2766 renderArea.Offset(-offsetX, -offsetY);
2768 overRenderArea.Copy(backBufferUpdate);
2769 overRenderArea.Offset(-offsetX, -offsetY);
2775 renderArea.Copy(dirtyArea);
2777 overRenderArea.Copy(dirtyArea);
2780 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2781 dirtyExtentWindow->Copy(dirtyExtent);
2782 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2783 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2784 dirtyExtentWindow->Empty();
2786 // Intersect with the clip extent
2787 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2790 if(renderArea.count > 10)
2793 printf("\nToo many extents (%d):\n", renderArea.count);
2795 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2796 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2801 for(c = 0; c<10; c++)
2804 FASTLIST_LOOP(renderArea, extentBox)
2806 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2808 renderArea.Copy(extent);
2810 FASTLIST_LOOP(renderArea, extentBox)
2813 printf("(%d, %d) - (%d, %d)\n",
2814 extentBox.box.left, extentBox.box.top,
2815 extentBox.box.right, extentBox.box.bottom);
2819 printf("\nNow %d\n", renderArea.count);
2825 // WHY WAS THIS COMMENTED ??
2827 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2828 dirtyExtentWindow->Copy(overDirtyExtent);
2829 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2830 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2831 dirtyExtentWindow->Empty();
2833 // Intersect with the clip extent
2834 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2840 if(scrollExtent.count)
2842 // Subtract render extent from scrolling extent
2843 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
2845 if(backBufferUpdate == null)
2847 Extent * dirty = &rootWindow.tempExtents[3];
2850 // Intersect scrolling extent with clip extent
2851 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2853 // offset this scroll to be at the root window level
2854 scrollExtent.Offset(offsetX, offsetY);
2855 // Add area that was scrolled to the dirty extents of the back buffer
2856 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
2860 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
2861 for(scrollBox = (BoxItem)scrollExtent.first; scrollBox; scrollBox = (BoxItem)scrollBox.next)
2862 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
2867 scrollExtent.Empty();
2869 // Add the exposed extent to the window render area
2870 dirty->Offset(-offsetX, -offsetY);
2871 renderArea.Union(dirty, rootWindow.tempExtents[0]);
2876 // Subtract the window's box from the transparency forced extent
2877 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
2883 renderArea.Copy(this.renderArea);
2884 renderArea.Offset(offsetX, offsetY);
2885 dirtyExtent.Union(renderArea);
2891 Extent renderArea { };
2893 renderArea.Copy(overRenderArea);
2894 renderArea.Offset(offsetX, offsetY);
2895 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2900 if(backBufferUpdate != null)
2902 // Remove render area from dirty area
2903 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
2905 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
2912 // Remove the window render area from the dirty extents of the back buffer
2913 rootWindow.dirtyBack.Exclusion(renderArea);
2917 void Render(Extent updateExtent)
2921 Window rootWindow = this.rootWindow;
2922 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2923 if(rootWindow.nativeDecorations)
2925 offsetX -= rootWindow.clientStart.x;
2926 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2929 if(rootWindow.fullRender)
2938 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2939 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
2944 /*if(renderArea.count)
2945 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
2948 for(extentBox = (BoxItem)renderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2950 Box box = extentBox.box;
2953 /*printf("(%d, %d) - (%d, %d)\n",
2954 extentBox.box.left, extentBox.box.top,
2955 extentBox.box.right, extentBox.box.bottom);*/
2960 box.left += offsetX;
2962 box.right += offsetX;
2963 box.bottom += offsetY;
2965 if(updateExtent != null)
2966 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2970 for(child = children.first; child; child = child.next)
2971 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
2972 child.Render(updateExtent);
2974 if(rootWindow.fullRender)
2975 DrawOverChildren(box);
2978 // TO DO: There's an issue about draw over children...
2979 // TO DO: Don't wanna go through this if method isn't used
2980 for(extentBox = (BoxItem)overRenderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2981 //FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
2983 Box box = extentBox.box;
2985 DrawOverChildren(box);
2987 box.left += offsetX;
2989 box.right += offsetX;
2990 box.bottom += offsetY;
2992 if(updateExtent != null)
2993 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2996 for(child = children.first; child; child = child.next)
2997 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
2998 child.Render(updateExtent);
3001 overRenderArea.Empty();
3004 public void UpdateDisplay(void)
3006 if(!manageDisplay) { OnRedraw(null);return; }
3007 if(rootWindow && this != rootWindow)
3008 rootWindow.UpdateDisplay();
3011 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
3012 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
3015 dirtyExtent.Clear();
3018 clipExtent.AddBox(box);
3020 display.StartUpdate();
3022 if(!rootWindow.fullRender)
3024 ComputeClipExtents();
3025 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
3026 ComputeRenderArea(dirtyExtent, overExtent, null);
3029 clipExtent.Free(null);
3031 dirtyExtent.Free(null);
3032 overExtent.Free(null);
3034 if(display.flags.flipping)
3037 display.Update(null);
3041 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
3042 updateExtent.Clear();
3044 Render(updateExtent);
3046 updateExtent.UnionBox(this.box, tempExtents[0]);
3049 //printf("\n\nUpdate:\n------------------------------------------\n");
3052 //FASTLIST_LOOP(updateExtent, extentBox)
3053 for(extentBox = (BoxItem)updateExtent.first; extentBox; extentBox = (BoxItem)extentBox.next)
3056 /*printf("Updating (%d, %d) - (%d, %d)\n",
3057 extentBox.box.left, extentBox.box.top,
3058 extentBox.box.right, extentBox.box.bottom);*/
3061 display.Update(extentBox.box);
3064 updateExtent.Free(null);
3067 display.EndUpdate();
3075 void UpdateBackDisplay(Box box)
3081 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3083 //printf("UpdateBackDisplay going through!\n");
3084 display.StartUpdate();
3088 intersection.Copy(dirtyBack);
3089 intersection.IntersectBox(box);
3091 dirtyExtent.Clear();
3094 clipExtent.AddBox(box);
3096 if(!rootWindow.fullRender)
3098 ComputeClipExtents();
3099 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3102 clipExtent.Free(null);
3104 intersection.Free(null);
3105 dirtyExtent.Free(null);
3106 overExtent.Free(null);
3111 if(display.flags.flipping)
3112 display.Update(null);
3115 rootWindow.display.Update(box);
3118 display.EndUpdate();
3122 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3123 if(dirtyBack.count > MAX_DIRTY_BACK)
3125 BoxItem extentBox, next;
3126 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3127 for(extentBox = (BoxItem)dirtyBack.first; extentBox; extentBox = next)
3129 next = (BoxItem)extentBox.next;
3130 if(extentBox != first)
3132 if(extentBox.box.left < first.box.left)
3133 first.box.left = extentBox.box.left;
3134 if(extentBox.box.top < first.box.top)
3135 first.box.top = extentBox.box.top;
3136 if(extentBox.box.right > first.box.right)
3137 first.box.right = extentBox.box.right;
3138 if(extentBox.box.bottom > first.box.bottom)
3139 first.box.bottom = extentBox.box.bottom;
3140 dirtyBack.Delete(extentBox);
3149 // --- Window positioning ---
3150 // --- Window identification ---
3152 // Returns window at position "Position"
3153 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3155 Window child, result = null;
3157 box.left += absPosition.x;
3158 box.right += absPosition.x;
3159 box.top += absPosition.y;
3160 box.bottom += absPosition.y;
3162 if(!destroyed && visible && (acceptDisabled || !disabled))
3164 int lx = x - absPosition.x;
3165 int ly = y - absPosition.y;
3166 if(IsInside(lx, ly))
3167 // if(box.IsPointInside(Point{x, y}))
3169 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3170 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3173 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3175 if(child != statusBar && child.rootWindow == rootWindow)
3177 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3184 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3186 if(child != statusBar && child.rootWindow == rootWindow)
3188 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3200 Window FindModal(void)
3202 Window modalWindow = this, check;
3203 Window check2 = null;
3204 for(check = this; check.master; check = check.master)
3206 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3208 modalWindow = check.master.modalSlave;
3209 check = modalWindow;
3211 // TESTING THIS FOR DROPBOX...
3212 if(!rootWindow || !rootWindow.style.interim)
3214 for(check2 = check; check2.activeChild; check2 = check2.activeChild)
3216 if(check2.modalSlave && check2.modalSlave.created)
3218 modalWindow = check2.modalSlave;
3226 if(modalWindow == this)
3228 for(check = this; check.activeChild; check = check.activeChild)
3230 if(check.modalSlave)
3232 modalWindow = check.modalSlave;
3238 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3239 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3242 void StopMoving(void)
3244 if(this == guiApp.windowMoving)
3246 guiApp.windowMoving = null;
3247 UpdateDecorations();
3248 SetMouseRange(null);
3251 if(rootWindow.active)
3252 guiApp.interfaceDriver.StopMoving(rootWindow);
3255 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3256 guiApp.windowIsResizing = false;
3260 void SelectMouseCursor(void)
3265 Window cursorWindow = null;
3266 bool rx, ry, rex, rey;
3268 guiApp.desktop.GetMousePosition(&x, &y);
3269 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3271 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3272 guiApp.SetCurrentCursor(guiApp.systemCursors[moving]);
3273 else if(mouseWindow)
3275 modalWindow = mouseWindow.FindModal();
3276 x -= mouseWindow.absPosition.x;
3277 y -= mouseWindow.absPosition.y;
3278 if(guiApp.windowIsResizing)
3280 rex = guiApp.resizeEndX;
3281 rey = guiApp.resizeEndY;
3282 rx = guiApp.resizeX;
3283 ry = guiApp.resizeY;
3284 if((rex && rey) || (rx && ry))
3285 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3286 else if((rex && ry) || (rx && rey))
3287 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3288 else if((ry || rey) && (!rx && !rex))
3289 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3290 else if((rx || rex) && (!ry && !rey))
3291 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3293 else if(!modalWindow && !guiApp.windowCaptured &&
3294 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3295 &rx, &ry, &rex, &rey))
3297 if((rex && rey) || (rx && ry))
3298 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3299 else if((rex && ry) || (rx && rey))
3300 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3301 else if((ry || rey) && (!rx && !rex))
3302 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3303 else if((rx || rex) && (!ry && !rey))
3304 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3306 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3308 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}))
3309 cursorWindow = mouseWindow.parent;
3311 cursorWindow = mouseWindow;
3313 else if(!guiApp.interimWindow)
3314 cursorWindow = guiApp.windowCaptured;
3317 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient; cursorWindow = cursorWindow.parent);
3318 guiApp.SetCurrentCursor(cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3320 else if(modalWindow)
3322 guiApp.SetCurrentCursor(guiApp.systemCursors[arrow]);
3324 else if(guiApp.interimWindow)
3326 if(guiApp.interimWindow.cursor)
3327 guiApp.SetCurrentCursor(guiApp.interimWindow.cursor);
3329 guiApp.SetCurrentCursor(mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3334 // --- State based input ---
3335 bool AcquireInputEx(bool state)
3340 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3341 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3343 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3345 guiApp.acquiredWindow = state ? this : null;
3348 SetMouseRangeToClient();
3349 guiApp.interfaceDriver.SetMouseCursor((SystemCursor)-1);
3354 SelectMouseCursor();
3356 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3360 // --- Window activation ---
3361 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3364 if(!parent || !parent.style.inactive)
3366 Window parent = this.parent;
3369 if(rootWindow == this)
3370 Log(active ? "active\n" : "inactive\n");
3373 // Testing this here...
3374 if(!parent || parent == guiApp.desktop || parent.active)
3376 this.active = active;
3379 // TESTING THIS HERE
3380 UpdateDecorations();
3381 if(result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master)
3382 result = NotifyActivate(master, this, active, previous);
3385 this.active = !active;
3390 if(!parent || parent == guiApp.desktop || parent.active)
3392 this.active = active;
3394 AcquireInputEx(active);
3399 if(guiApp.caretOwner)
3403 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3404 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3405 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3406 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3408 guiApp.caretOwner.Update(extent);
3411 if(visible || !guiApp.caretOwner)
3412 guiApp.caretOwner = this;
3413 UpdateCaret(false, false);
3419 this.active = false;
3421 AcquireInputEx(active);
3423 if(!active && guiApp.caretOwner == this)
3425 UpdateCaret(false, true);
3426 guiApp.caretOwner = null;
3427 guiApp.interfaceDriver.SetCaret(0,0,0);
3428 guiApp.caretEnabled = false;
3433 if(!active && parent && parent.activeChild && parent.activeChild != this)
3434 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3440 if(!active && menuBar)
3443 menuBar.OnActivate(false, null, &goOn, true);
3444 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3449 Window aChild = activeChild;
3451 if(!aChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3463 void ConsequentialMouseMove(bool kbMoving)
3467 if(kbMoving || !guiApp.windowMoving)
3471 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3473 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3475 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3476 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3482 bool IsDescendantOf(Window ancestor)
3485 for(window = this; window && window != ancestor; window = window.parent);
3486 return window == ancestor;
3489 bool IsSlaveOf(Window master)
3492 for(window = this; window && window != master; window = window.master);
3493 return window == master;
3496 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3500 if(this && !destroyed /*&& state != Hidden*/)
3502 Window swap = externalSwap;
3510 if(activateParent &&
3511 (parent.activeChild != this ||
3512 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3513 active && _isModal &&
3514 parent != master && master)
3515 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3521 bool real = parent.activeChild != this;
3523 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3524 if(/*activateParent && */guiApp.interimWindow &&
3525 !IsDescendantOf(guiApp.interimWindow) &&
3526 !IsSlaveOf(guiApp.interimWindow))
3528 Window interimWindow = guiApp.interimWindow;
3529 while(interimWindow && interimWindow != this)
3531 Window master = interimWindow.master;
3533 guiApp.interimWindow = null;
3534 if(guiApp.caretOwner)
3535 guiApp.caretOwner.UpdateCaret(false, false);
3537 incref interimWindow;
3538 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3543 delete interimWindow;
3544 interimWindow = (master && master.style.interim) ? master : null;
3549 guiApp.interimWindow = this;
3550 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3551 guiApp.caretEnabled = false;*/
3552 UpdateCaret(false, true);
3557 bool acquireInput = false;
3559 parent.activeChild &&
3560 parent.activeChild.state == maximized &&
3561 parent != guiApp.desktop;
3563 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3568 swap = parent.activeChild;
3569 if(swap && swap.destroyed) swap = null;
3570 if(swap && swap != this)
3573 if(!swap.PropagateActive(false, this, &goOn, true))
3574 swap = parent.activeChild;
3585 if(!parent || parent.activeChild != this || style.interim)
3588 result = PropagateActive(true, swap, &goOn, true);
3589 if(!result && !goOn)
3594 acquireInput = true;
3598 if(style.hasMaximize && parent != guiApp.desktop)
3601 SetState(maximized, false, 0);
3602 else if(state != maximized)
3605 for(child = parent.children.first; child; child = child.next)
3607 if(this != child && child.state == maximized)
3608 child.SetState(normal, false, 0);
3615 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3617 Window previous = parent.activeClient;
3618 parent.activeChild = this;
3619 if(!style.nonClient /*&& style.isActiveClient*/)
3623 if(style.isActiveClient)
3624 parent.activeClient = this;
3625 // Moved UpdateActiveDocument inside hidden check
3626 // To prevent activating previous window while creating a new one
3627 // (It was messing up the privateModule in the CodeEditor)
3628 parent.UpdateActiveDocument(previous);
3634 //if(!style.isRemote)
3636 if(rootWindow != this)
3638 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3639 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3641 else if(!guiApp.fullScreenMode)
3643 Window modalRoot = FindModal();
3644 if(!modalRoot) modalRoot = this;
3645 if(!modalRoot.isForegroundWindow)
3647 modalRoot.isForegroundWindow = true;
3648 // To check : Why is parent null?
3649 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3651 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3653 modalRoot.isForegroundWindow = false;
3658 if(result && real && (!style.inactive || moveInactive) && parent)
3660 Window last = parent.children.last;
3662 if(!style.stayOnTop)
3663 for(; last && last.style.stayOnTop; last = last.prev);
3665 parent.children.Move(this, last);
3667 // Definitely don't want that: why not?
3671 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3677 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3684 parent.activeChild = null;
3685 if(!style.nonClient /*&& style.isActiveClient*/)
3687 Window previous = parent.activeClient;
3688 if(style.isActiveClient)
3689 parent.activeClient = null;
3690 parent.UpdateActiveDocument(previous);
3694 if(this == guiApp.interimWindow)
3696 guiApp.interimWindow = null;
3697 if(guiApp.caretOwner)
3698 guiApp.caretOwner.UpdateCaret(false, false);
3700 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3707 if(!active || !swap)
3708 UpdateDecorations();
3710 swap.UpdateDecorations();
3712 if(active && rootWindow != this)
3713 ConsequentialMouseMove(false);
3720 // --- Input Messages ---
3721 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3723 static bool reEntrancy = false;
3724 if(reEntrancy) return;
3728 guiApp.cursorUpdate = true;
3729 if(guiApp.windowScrolling && !consequential)
3731 guiApp.windowScrolling.SetScrollPosition(
3732 (guiApp.windowScrolling.sbh) ?
3733 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3734 (guiApp.windowScrolling.sbv) ?
3735 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3737 if(guiApp.windowMoving)
3739 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3741 Window window = guiApp.windowMoving;
3743 int w = window.size.w;
3744 int h = window.size.h;
3749 rx = mouseX - guiApp.windowMovingStart.x;
3750 ry = mouseY - guiApp.windowMovingStart.y;
3753 window.GetDecorationsSize(&ew, &eh);
3755 if(guiApp.windowIsResizing)
3757 x = window.scrolledPos.x;
3758 y = window.scrolledPos.y;
3762 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3763 rx = guiApp.windowResizingBefore.w - aw;
3764 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3765 w = guiApp.windowResizingBefore.w - rx;
3769 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3770 ry = guiApp.windowResizingBefore.h - ah;
3771 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3772 ry = Max(ry, -guiApp.windowMovingBefore.y);
3773 h = guiApp.windowResizingBefore.h - ry;
3775 if(guiApp.resizeEndX)
3777 w = guiApp.windowResizingBefore.w + rx;
3780 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3788 w = Max(w, window.minSize.w);
3789 h = Max(h, window.minSize.h);
3790 w = Min(w, window.maxSize.w);
3791 h = Min(h, window.maxSize.h);
3793 if(!window.OnResizing(&w, &h))
3795 w = window.clientSize.w;
3796 h = window.clientSize.h;
3799 w = Max(w, window.skinMinSize.w);
3800 h = Max(h, window.skinMinSize.h);
3807 SNAPDOWN(w, textCellW);
3808 SNAPDOWN(h, textCellH);
3813 aw = Max(w,window.skinMinSize.w);
3814 rx = guiApp.windowResizingBefore.w - aw;
3815 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3816 w = guiApp.windowResizingBefore.w - rx;
3820 ah = Max(h,window.skinMinSize.h);
3821 ry = guiApp.windowResizingBefore.h - ah;
3822 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3823 ry = Max(ry, -guiApp.windowMovingBefore.y);
3824 h = guiApp.windowResizingBefore.h - ry;
3829 if(!guiApp.windowIsResizing || guiApp.resizeX)
3830 x = guiApp.windowMovingBefore.x + rx;
3831 if(!guiApp.windowIsResizing || guiApp.resizeY)
3832 y = guiApp.windowMovingBefore.y + ry;
3834 if(!guiApp.windowIsResizing)
3837 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
3839 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
3840 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
3841 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
3842 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
3846 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
3847 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
3853 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
3855 if(!window.OnMoving(&x, &y, w, h))
3857 x = window.scrolledPos.x;
3858 y = window.scrolledPos.y;
3864 SNAPDOWN(x, textCellW);
3865 SNAPDOWN(y, textCellH);
3868 if(!window.style.nonClient)
3870 if(!window.style.fixed /*|| window.style.isDocument*/)
3872 if(!window.style.dontScrollHorz)
3873 x += window.parent.scroll.x;
3874 if(!window.style.dontScrollVert)
3875 y += window.parent.scroll.y;
3879 // Break the anchors for moveable/resizable windows
3880 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
3881 if(window.style.fixed)
3883 if(window.state == normal)
3885 window.normalAnchor = Anchor { left = x, top = y };
3886 window.normalSizeAnchor = SizeAnchor { { w, h } };
3887 window.anchored = false;
3891 window.stateAnchor = Anchor { left = x, top = y };
3892 window.stateSizeAnchor = SizeAnchor { { w, h } };
3894 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
3895 // TOCHECK: Investigate why the following only redraws the scrollbars
3896 //window.Position(x, y, w, h, false, true, true, true, false, true);
3898 guiApp.movingLast.x = mouseX;
3899 guiApp.movingLast.y = mouseY;
3905 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
3908 bool wasMoving = guiApp.windowMoving ? true : false;
3909 bool wasScrolling = guiApp.windowScrolling ? true : false;
3911 while(result && w != this)
3913 Window msgWindow = GetAtPosition(x,y, false, true, w);
3914 Window trueWindow = GetAtPosition(x,y, false, false, w);
3915 bool windowDragged = false;
3920 window = (w && !w.disabled) ? w : null;
3922 if(trueWindow) incref trueWindow;
3924 if(consequential) mods->isSideEffect = true;
3926 UpdateMouseMove(x, y, consequential);
3928 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
3930 if(!guiApp.windowCaptured.isEnabled)
3931 guiApp.windowCaptured.ReleaseCapture();
3933 window = guiApp.windowCaptured;
3936 if(trueWindow && activate &&
3937 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3938 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3939 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3940 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3942 if(mods->alt && !mods->ctrl && !mods->shift)
3944 Window moved = trueWindow;
3945 for(moved = trueWindow; moved; moved = moved.parent)
3946 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3951 windowDragged = true;
3953 // Cancel the ALT menu toggling...
3954 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
3959 if(window && activate &&
3960 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3961 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3962 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3963 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3965 Window modalWindow = window.FindModal();
3967 /*if(mods->alt && !mods->shift && !mods->ctrl)
3969 Window moved = window;
3970 for(moved = window; moved; moved = moved.parent)
3971 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3976 windowDragged = true;
3978 // Cancel the ALT menu toggling...
3979 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
3985 Window activateWindow = modalWindow ? modalWindow : window;
3986 if(activateWindow && !activateWindow.isRemote)
3988 bool doActivation = true;
3989 //bool needToDoActivation = false;
3990 Window check = activateWindow;
3992 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
3994 if(!check.style.inactive)
3996 //needToDoActivation = true;
3998 doActivation = false;
4003 if(!needToDoActivation)
4004 doActivation = false;
4007 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
4008 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
4010 // Let the OnLeftButtonDown do the activating instead
4011 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4019 incref activateWindow;
4020 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
4022 delete activateWindow;
4026 if(activateWindow._refCount == 1)
4028 delete activateWindow;
4032 delete activateWindow;
4034 mods->isActivate = true;
4038 if(!modalWindow && window && !window.destroyed)
4040 if(!guiApp.windowCaptured || windowDragged)
4042 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
4044 bool moving = ((window.state != maximized &&
4045 window.IsMouseMoving(
4046 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4047 || (guiApp.windowMoving && !guiApp.windowIsResizing);
4049 if(!moving && window.IsMouseResizing(
4050 x - window.absPosition.x,
4051 y - window.absPosition.y,
4052 window.size.w, window.size.h,
4053 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
4055 guiApp.windowIsResizing = true;
4056 guiApp.windowResizingBefore.w = window.size.w;
4057 guiApp.windowResizingBefore.h = window.size.h;
4059 if(guiApp.windowIsResizing || windowDragged || moving)
4062 guiApp.windowMoving = window;
4063 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4064 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4065 guiApp.windowMovingBefore.x = window.position.x;//s;
4066 guiApp.windowMovingBefore.y = window.position.y;//s;
4067 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4068 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4071 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4073 if(window.style.fixed &&
4075 window.IsMouseMoving(
4076 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4078 window.ShowSysMenu(x, y);
4082 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4084 if(window.sbv || window.sbh)
4087 guiApp.windowScrolling = window;
4088 guiApp.windowScrollingStart.x = x;
4089 guiApp.windowScrollingStart.y = y;
4090 guiApp.windowScrollingBefore.x = window.scroll.x;
4091 guiApp.windowScrollingBefore.y = window.scroll.y;
4094 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4096 if(window.style.hasMaximize &&
4097 window.IsMouseMoving(
4098 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4101 (window.state == maximized) ? normal : maximized, false, *mods);
4109 if(guiApp.windowMoving)
4111 if(guiApp.windowMoving.parent)
4113 if(guiApp.windowMoving.style.nonClient)
4114 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4116 guiApp.windowMoving.parent.SetMouseRangeToClient();
4120 window.UpdateDecorations();
4123 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4125 // Log("\n*** LEFT BUTTON UP ***\n");
4126 if(guiApp.windowMoving)
4127 guiApp.windowMoving.StopMoving();
4129 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4131 if(guiApp.windowScrolling)
4133 Window windowScrolling = guiApp.windowScrolling;
4134 guiApp.windowScrolling = null;
4135 windowScrolling.ReleaseCapture();
4139 if(!result || (window && window.destroyed)) window = null;
4141 if(window && window.FindModal())
4144 if(trueWindow && trueWindow.FindModal())
4152 msgWindow = GetAtPosition(x,y, true, false);
4154 msgWindow.SelectMouseCursor();
4157 if(guiApp.windowCaptured || trueWindow)
4159 Window prevWindow = guiApp.prevWindow;
4160 if(guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4162 guiApp.prevWindow.mouseInside = false;
4163 guiApp.prevWindow = null;
4165 // Eventually fix this not to include captured?
4166 if(!prevWindow.OnMouseLeave(*mods))
4169 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4171 Box box = trueWindow.box;
4172 box.left += trueWindow.absPosition.x;
4173 box.right += trueWindow.absPosition.x;
4174 box.top += trueWindow.absPosition.y;
4175 box.bottom += trueWindow.absPosition.y;
4177 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4179 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4180 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4182 overX = Max(Min(overX, 32767),-32768);
4183 overY = Max(Min(overY, 32767),-32768);
4185 trueWindow.mouseInside = true;
4186 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4190 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4191 guiApp.prevWindow = trueWindow;
4193 guiApp.prevWindow = null;
4195 SelectMouseCursor();
4197 if(window && !guiApp.windowMoving && !wasMoving && !wasScrolling)
4199 int clientX = x - (window.absPosition.x + window.clientStart.x);
4200 int clientY = y - (window.absPosition.y + window.clientStart.y);
4202 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4204 clientX = Max(Min(clientX, 32767),-32768);
4205 clientY = Max(Min(clientY, 32767),-32768);
4207 MouseMethod = (void *)window._vTbl[method];
4209 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4212 if(!MouseMethod(window, clientX, clientY, *mods))
4219 if(result && w && w.clickThrough && w.parent)
4224 if(!result || !w || !w.clickThrough)
4231 // --- Mouse cursor management ---
4233 bool KeyMessage(uint method, Key key, unichar character)
4238 if(guiApp.interimWindow)
4239 this = guiApp.interimWindow;
4242 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4246 if(!style.inactive || rootWindow != this)
4248 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4249 Window modalWindow = FindModal();
4250 Window interimMaster = master ? master.rootWindow : null;
4254 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4255 status = OnSysKeyDown(key, character);
4256 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4257 status = OnSysKeyHit(key, character);
4258 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4259 status = OnSysKeyUp(key, character);
4266 // Process Key Message for Internal UI Keyboard actions
4267 if(status && !destroyed && menuBar && state != minimized)
4270 if((SmartKey)key != alt)
4271 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4274 SmartKey sk = (SmartKey) key;
4275 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4277 status = menuBar.KeyMessage(method, key, character);
4282 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4283 menuBar.OnKeyHit(escape, 0);
4285 if(!menuBar.focus && guiApp.caretOwner)
4286 guiApp.caretOwner.UpdateCaret(true, false);
4289 if(!destroyed && status)
4291 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4295 case left: case up: case right: case down:
4296 if(guiApp.windowMoving == this)
4299 int w = guiApp.windowMoving.size.w;
4300 int h = guiApp.windowMoving.size.h;
4301 int x = guiApp.windowMoving.scrolledPos.x;
4302 int y = guiApp.windowMoving.scrolledPos.y;
4306 if(key == down || key == up)
4307 step = Max(step, textCellH);
4309 step = Max(step, textCellW);
4312 if(guiApp.windowIsResizing)
4316 case left: w-=step; break;
4317 case right: w+=step; break;
4318 case up: h-=step; break;
4319 case down: h+=step; break;
4326 case left: x-=step; break;
4327 case right: x+=step; break;
4328 case up: y-=step; break;
4329 case down: y+=step; break;
4333 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4334 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4336 if(!guiApp.windowIsResizing || guiApp.resizeX)
4337 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4339 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4341 if(!guiApp.windowIsResizing || guiApp.resizeY)
4342 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4344 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4346 guiApp.interfaceDriver.SetMousePosition(x, y);
4347 ConsequentialMouseMove(true);
4355 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4357 guiApp.windowMoving.StopMoving();
4358 ConsequentialMouseMove(false);
4366 ShowSysMenu(absPosition.x, absPosition.y);
4374 if(!destroyed && status && state != minimized)
4376 // Process all the way down the children
4377 if(activeChild && !activeChild.disabled)
4379 status = activeChild.KeyMessage(method, key, character);
4381 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4382 key.code != left && key.code != right && key.code != up && key.code != down)
4384 status = activeClient.KeyMessage(method, key, character);
4388 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4390 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4391 // && defaultControl != activeChild)
4393 delete previousActive;
4394 previousActive = activeChild;
4395 if(previousActive) incref previousActive;
4397 ConsequentialMouseMove(false);
4398 if((defaultControl.active ||
4399 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4400 defaultControl.KeyMessage(method, defaultKey, character);
4406 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4408 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4415 ShowSysMenu(absPosition.x, absPosition.y);
4422 if(this != guiApp.desktop)
4424 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4426 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4428 MenuMoveOrSize(key.shift, true);
4432 else if(guiApp.windowMoving)
4434 guiApp.windowMoving.StopMoving();
4435 ConsequentialMouseMove(false);
4443 if(!destroyed && status && state != minimized)
4445 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4449 case tab: case shiftTab:
4451 Window cycleParent = this;
4452 if(this == guiApp.interimWindow && !master.style.interim && !cycleParent.style.tabCycle)
4453 cycleParent = master.parent;
4455 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4457 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4459 Window child = cycleParent.activeChild;
4461 // Scroll the window to include the active control
4463 if(cycleParent.sbh && !child.style.dontScrollHorz)
4465 if(child.scrolledPos.x < 0)
4466 cycleParent.sbh.Action(Position,
4467 cycleParent.scroll.x + child.scrolledPos.x, 0);
4468 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4469 cycleParent.sbh.Action(Position,
4470 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4472 if(cycleParent.sbv && !child.style.dontScrollVert)
4474 if(child.scrolledPos.y < 0)
4475 cycleParent.sbv.Action(Position,
4476 cycleParent.scroll.y + child.scrolledPos.y, 0);
4477 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4478 cycleParent.sbv.Action(Position,
4479 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4482 cycleParent.ConsequentialMouseMove(false);
4488 case f6: case shiftF6:
4489 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4491 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4492 if(parent == guiApp.desktop)
4493 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4503 if(CycleChildren(key.shift, true, false, true))
4511 // mIRC Style Window Shortcuts
4512 case alt1: case alt2: case alt3: case alt4: case alt5:
4513 case alt6: case alt7: case alt8: case alt9: case alt0:
4518 for(document = children.first; document; document = document.next)
4520 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4522 if(document == activeChild)
4524 if(document.state == minimized)
4525 document.SetState(normal, false, key);
4528 document.SetState(minimized, false, key);
4529 CycleChildren(false, true, false);
4534 if(activeChild.state == maximized && document.style.hasMaximize)
4535 document.SetState(maximized, false, key);
4536 else if(document.state == minimized)
4537 document.SetState(normal, false, key);
4538 document.Activate();
4553 if(!destroyed && status)
4555 if(state == minimized)
4560 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4562 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4564 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4565 previousActive.ActivateEx(true, false, false, true, null, null);
4566 delete previousActive;
4572 if(!destroyed && status)
4574 status = ProcessHotKeys(method, key, character);
4576 if(!destroyed && status && !modalWindow && state != minimized)
4579 status = KeyMethod(this, key, character);
4580 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4581 status = OnKeyHit(key, character);
4582 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4584 bool result = false;
4587 case ctrlUp: case ctrlDown:
4588 if(sbv && !guiApp.windowScrolling)
4589 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4591 case wheelUp: case wheelDown:
4592 if(sbv && !guiApp.windowScrolling)
4594 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4595 // Do we want to do a consequential move regardless of result in this case?
4596 ConsequentialMouseMove(false);
4599 case ctrlPageUp: case ctrlPageDown:
4600 if(sbh && !guiApp.windowScrolling)
4601 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4606 ConsequentialMouseMove(false);
4611 if(status && !destroyed && menuBar && state != minimized)
4612 status = menuBar.KeyMessage(method, key, character);
4614 if(style.interim && /*destroyed && */status && interimMaster)
4616 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4617 status = interimMaster.KeyMessage(method, key, character);
4624 bool ProcessHotKeys(uint method, Key key, unichar character)
4629 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4630 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4631 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4633 Window hotKeyWindow = hotKey.window;
4634 Window parent = hotKeyWindow.parent;
4635 Window prevActiveWindow = activeChild;
4637 // Don't process non-visible buttons, but make an exception for the Alt-F4 with Native Decorations turned on
4638 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1] )))
4641 if(prevActiveWindow) incref prevActiveWindow;
4642 incref hotKeyWindow;
4643 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient)
4644 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4647 delete hotKeyWindow;
4648 delete prevActiveWindow;
4652 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4653 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4654 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4656 // ********* WORKING ON THIS ***********
4657 if(prevActiveWindow && !guiApp.interimWindow)
4658 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4661 else if(hotKeyWindow.style.inactive)
4662 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4664 delete prevActiveWindow;
4665 delete hotKeyWindow;
4666 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4667 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4671 if(status && tabCycle)
4674 for(child = children.first; child; child = child.next)
4676 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4687 // --- Windows and graphics initialization / termination ---
4688 bool SetupRoot(void)
4692 // Setup relationship with outside world (bb root || !bb)
4693 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4694 (_displayDriver && dispDriver != parent.dispDriver))
4698 tempExtents = new0 Extent[4];
4703 /*if(guiApp.fullScreenMode)
4704 rootWindow = guiApp.desktop;
4706 //rootWindow = parent.created ? parent.rootWindow : null;
4707 rootWindow = parent.rootWindow;
4710 against = &parent.box;
4712 against = &parent.clientArea;
4715 for(child = children.first; child; child = child.next)
4718 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
4721 bool Setup(bool positionChildren)
4723 bool result = false;
4726 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && dispDriver != parent.dispDriver))))
4728 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
4729 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
4731 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
4733 // This was here, is it really needed?
4734 //guiApp.interfaceDriver.ActivateRootWindow(this);
4738 displaySystem = DisplaySystem {};
4739 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
4741 delete displaySystem;
4746 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData };
4747 if(display.Create(displaySystem, windowHandle))
4754 guiApp.interfaceDriver.SetIcon(this, icon);
4756 else if(this != guiApp.desktop)
4758 display = rootWindow ? rootWindow.display : null;
4764 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
4765 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
4767 for(child = children.first; child; child = child.next)
4769 if(child.created && !child.Setup(false))
4775 bool SetupDisplay(void)
4777 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
4778 if(is3D) return Window3D_SetupDisplay(this); else
4785 class_data void ** pureVTbl;
4787 bool LoadGraphics(bool creation, bool resetAnchors)
4789 bool result = false;
4790 bool success = false;
4792 WindowState stateBackup = state;
4795 if(!rootWindow.created)
4799 if(((subclass(Window))_class).pureVTbl)
4801 if(_vTbl == _class._vTbl)
4803 _vTbl = ((subclass(Window))_class).pureVTbl;
4808 for(m = 0; m < _class.vTblSize; m++)
4810 if(_vTbl[m] == _class._vTbl[m])
4811 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
4815 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
4817 if(_vTbl == ((subclass(Window))_class).pureVTbl)
4819 _vTbl = _class._vTbl;
4824 for(m = 0; m < _class.vTblSize; m++)
4826 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
4827 _vTbl[m] = _class._vTbl[m];
4832 if(guiApp.fullScreenMode || this != guiApp.desktop)
4834 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
4840 display.Lock(false);
4841 if(rootWindow == this)
4843 // Set Color Palette
4844 display.SetPalette(palette, true);
4848 if(guiApp.fullScreenMode && this == guiApp.desktop)
4853 for(c=0; c<SystemCursor::enumSize; c++)
4854 if(!guiApp.systemCursors[c].bitmap)
4856 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
4857 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
4858 if(guiApp.systemCursors[c].bitmapName)
4860 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
4861 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
4862 if(guiApp.systemCursors[c].bitmap)
4863 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
4868 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
4870 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
4871 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
4873 cursor.bitmap.paletteShades = cursor.paletteShades;
4877 guiApp.cursorUpdate = true;
4880 ConsequentialMouseMove(false);
4886 // Load Window Graphic Resources
4889 if(usedFont == setFont || usedFont == window.systemFont)
4890 RemoveResource(usedFont);
4893 RemoveResource(setFont); // TESTING setFont instead of usedFont);
4896 RemoveResource(systemFont);
4899 RemoveResource(captionFont);
4901 for(ptr = resources.first; ptr; ptr = ptr.next)
4903 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
4906 AddResource(setFont);
4908 AddResource(systemFont);
4910 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
4917 //if(master && master.font)
4918 if(parent && parent.font)
4922 faceName = parent.font.faceName,
4923 size = parent.font.size,
4924 bold = parent.font.bold,
4925 italic = parent.font.italic,
4926 underline = parent.font.underline
4928 //font = parent.font;
4929 watch(parent) { font { } };
4932 font = guiApp.currentSkin.SystemFont();
4939 captionFont = guiApp.currentSkin.CaptionFont();
4940 AddResource(captionFont);
4942 if(OnLoadGraphics())
4948 //SetScrollLineStep(sbStep.x, sbStep.y);
4950 if(this != guiApp.desktop)
4954 normalAnchor = anchor;
4955 normalSizeAnchor = sizeAnchor;
4958 // Break the anchors for moveable/resizable windows
4960 if(style.fixed && style.isDocument)
4962 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
4974 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
4975 stateSizeAnchor = SizeAnchor {};
4980 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
4985 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
4986 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
4989 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
4993 stateAnchor = normalAnchor;
4994 stateSizeAnchor = normalSizeAnchor;
4997 position = Point { };
4998 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5009 if(Position(x, y, w, h, true, false, true, true, true, true))
5011 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
5014 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
5031 success = result = true;
5034 if(!creation && result)
5036 // Load menu bar first because sys buttons are on it...
5039 if(!menuBar.LoadGraphics(false, resetAnchors))
5045 for(child = children.first; child; child = child.next)
5047 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
5054 CreateSystemChildren();
5058 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5061 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5066 //guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, caption);
5067 guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, class.name);
5070 // Do this here to avoid problems on Windows
5071 if(stateBackup == maximized)
5072 property::state = maximized;
5076 void UnloadGraphics(bool destroyWindows)
5080 // Free children's graphics
5081 for(child = children.first; child; child = child.next)
5082 child.UnloadGraphics(destroyWindows);
5085 display.Lock(false);
5088 if(guiApp.fullScreenMode && this == guiApp.desktop)
5093 for(c=0; c<SystemCursor::enumSize; c++)
5094 if(guiApp.systemCursors[c].bitmap)
5095 delete guiApp.systemCursors[c].bitmap;
5097 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5098 delete cursor.bitmap;
5100 guiApp.cursorBackground.Free();
5103 if(display && display.displaySystem)
5107 for(ptr = resources.first; ptr; ptr = ptr.next)
5111 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5116 // Free window graphics
5119 // Free skin graphics
5120 if(rootWindow == this)
5122 DisplaySystem displaySystem = display.displaySystem;
5125 display.driverData = null;
5126 display.displaySystem = null;
5130 if(displaySystem && !displaySystem.numDisplays && !is3D)
5131 delete displaySystem;
5140 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5141 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5143 if(this == guiApp.desktop || parent == guiApp.desktop)
5145 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5146 guiApp.interfaceDriver.DestroyRootWindow(this);
5150 // --- Window Hiding ---
5152 void SetVisibility(bool state)
5154 bool visible = (style.hidden || !created) ? false : state;
5155 if(visible != this.visible)
5159 this.visible = visible;
5160 for(child = children.first; child; child = child.next)
5161 child.SetVisibility(visible);
5163 ConsequentialMouseMove(false);
5164 if(parent && !nonClient) parent.OnChildVisibilityToggled(this, visible);
5168 // --- Windows and graphics initialization / termination ---
5170 bool DisplayModeChanged(void)
5172 bool result = false;
5173 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5175 guiApp.modeSwitching = true;
5176 UnloadGraphics(false);
5178 if(LoadGraphics(false, false))
5180 guiApp.modeSwitching = false;
5185 // --- Window updates system ---
5187 void UpdateDirty(Box updateBox)
5189 if(!manageDisplay) { OnRedraw(null);return; }
5192 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5195 if(display.flags.flipping)
5198 rootWindow.UpdateDisplay();
5201 UpdateBackDisplay(updateBox);
5203 if(guiApp.fullScreenMode)
5205 guiApp.cursorUpdate = true;
5206 guiApp.PreserveAndDrawCursor();
5208 if(guiApp.fullScreenMode)
5209 guiApp.RestoreCursorBackground();
5215 // This function is strictly called as a result of system window activation
5216 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5219 Window interimMaster = null;
5220 Window interimWindow = guiApp.interimWindow;
5221 if(interimWindow && interimWindow.master)
5222 interimMaster = interimWindow.master.rootWindow;
5224 if(active && state == minimized) // && (!window.nativeDecorations || window.rootWindow != window)
5225 // SetState(normal, false, 0);
5226 SetState(lastState, false, 0);
5228 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5232 /* WTH is this doing here?
5233 while(swap && swap.activeChild)
5235 swap = swap.activeChild;
5238 // TESTING THIS BEFORE...
5239 if(interimWindow && this == interimMaster)
5243 // Window interimSwap = this;
5244 Window menuBar = this.menuBar;
5245 if(menuBar && interimWindow.master == menuBar)
5248 while(interimSwap && interimSwap.activeChild)
5249 interimSwap = interimSwap.activeChild;
5251 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5252 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5254 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5255 //result = ActivateEx(true, true, false, activateRoot, window, null);
5260 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5261 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5263 if(interimWindow == this && interimMaster && !active)
5265 while(interimMaster && interimMaster.interim && interimMaster.master)
5267 // printf("Going up one master %s\n", interimMaster._class.name);
5268 interimMaster = interimMaster.master.rootWindow;
5270 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5271 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5277 bool DestroyEx(int returnCode)
5280 Timer timer, nextTimer;
5282 OldLink prevOrder = null;
5283 Window client = null;
5285 if(parent) stopwatching(parent, font);
5287 // if(window.modalSlave) return false;
5288 if(destroyed || !created)
5295 OldLink slave = master.slaves.FindLink(this);
5296 master.slaves.Delete(slave);
5299 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5305 this.returnCode = (DialogResult)returnCode;
5307 AcquireInput(false);
5312 master.hotKeys.Delete(hotKey);
5316 if(guiApp.prevWindow == this)
5318 guiApp.prevWindow = null;
5321 if(guiApp.caretOwner == this)
5323 guiApp.interfaceDriver.SetCaret(0,0,0);
5324 UpdateCaret(false, true);
5325 guiApp.caretEnabled = false;
5330 parent.childrenCycle.Remove(cycle);
5334 OldLink tmpPrev = order.prev;
5335 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5336 prevOrder = tmpPrev;
5339 client = tmpPrev ? tmpPrev.data : null;
5340 if(client == this) { client = null; break; }
5341 if(client && (client.style.hidden || client.destroyed || !client.created))
5342 tmpPrev = client.order.prev;
5346 prevOrder = tmpPrev;
5351 // If this window can be an active client, make sure the next window we activate can also be one
5352 if(!style.nonClient && style.isActiveClient)
5354 tmpPrev = prevOrder;
5357 client = tmpPrev ? tmpPrev.data : null;
5358 if(client == this) { client = null; break; }
5359 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5360 tmpPrev = client.order.prev;
5364 prevOrder = tmpPrev;
5368 if(client && client.style.hidden) client = null;
5370 // parent.childrenOrder.Remove(order);
5373 if(parent && style.isActiveClient && visible)
5375 if(state == minimized) parent.numIcons--;
5376 parent.numPositions--;
5379 // TESTING THIS HERE!
5383 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5384 // to create a window inside a rootwindow that's being destroyed)
5385 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5387 if(master && !master.destroyed /*&&
5388 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5390 if(master.defaultControl == this)
5391 master.defaultControl = null;
5393 if(parent && !parent.destroyed /*&&
5394 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5396 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5398 if(order && prevOrder && prevOrder.data != this && active)
5400 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5402 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5403 if(parent.activeClient == this)
5405 parent.activeClient = null;
5406 parent.UpdateActiveDocument(null);
5411 if(guiApp.interimWindow == this)
5414 PropagateActive(false, null, &goOn, true);
5418 //if(window.parent.activeChild == window)
5419 parent.activeChild = null;
5420 if(!style.nonClient /*&& style.isActiveClient*/)
5422 Window previous = parent.activeClient;
5423 if(style.isActiveClient)
5424 parent.activeClient = null;
5425 parent.UpdateActiveDocument(previous);
5430 else if(parent.activeClient == this)
5432 parent.activeClient = client;
5433 parent.UpdateActiveDocument(this);
5437 if(guiApp.interimWindow == this)
5439 guiApp.interimWindow = null;
5440 if(guiApp.caretOwner)
5442 Window desktop = guiApp.desktop;
5443 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5444 guiApp.caretOwner.UpdateCaret(false, false);
5449 if(_isModal && master && master.modalSlave == this)
5450 master.modalSlave = null;
5454 if(!guiApp.caretOwner && parent.caretSize)
5456 guiApp.caretOwner = parent;
5457 parent.UpdateCaret(false, false);
5458 parent.Update(null);
5461 // Why was this commented out?
5462 GetRidOfVirtualArea();
5468 dirtyArea.Free(null);
5469 dirtyBack.Free(null);
5470 scrollExtent.Free(null);
5472 /* ATTEMPTING TO MOVE THAT ABOVE
5481 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5482 for(;(child = window.children.first);)
5484 for(; child && (child.destroyed || !child.created); child = child.next);
5493 UnloadGraphics(true);
5496 delete previousActive;
5499 // statusBar = null;
5502 if(master && !master.destroyed)
5504 //master.NotifyDestroyed(this, this.returnCode);
5505 NotifyDestroyed(master, this, this.returnCode);
5508 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5510 nextTimer = timer.next;
5511 if(timer.window == this)
5513 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5514 // timer.window = null;
5520 if(this == guiApp.windowMoving)
5523 if(guiApp.windowCaptured == this)
5525 //guiApp.windowCaptured = null;
5527 if(rootWindow != this && rootWindow)
5528 rootWindow.ConsequentialMouseMove(false);
5536 //for(child = children.first; next = child ? child.next : null, child; child = next)
5537 for(;(child = children.first); )
5539 for(; child && (child.destroyed || !child.created); child = child.next);
5549 /* // MOVED THIS UP...
5552 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5553 for(;(child = window.children.first); )
5555 for(; child && (child.destroyed || !child.created); child = child.next);
5564 while((slave = slaves.first))
5566 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5568 ((Window)slave.data).DestroyEx(0);
5573 if(guiApp.caretOwner == this)
5574 guiApp.caretOwner = null;
5576 sysButtons[0] = null;
5577 sysButtons[1] = null;
5578 sysButtons[2] = null;
5581 if(rootWindow != this)
5583 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5586 box.left -= parent.clientStart.x;
5587 box.top -= parent.clientStart.y;
5588 box.right -= parent.clientStart.x;
5589 box.bottom -= parent.clientStart.y;
5591 if(parent) parent.Update(box);
5596 OldLink slave = master.slaves.FindVoid(this);
5597 master.slaves.Delete(slave);
5603 parent.children.Remove(this);
5608 //autoCreate = false;
5611 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5612 if(((subclass(Window))_class).pureVTbl)
5614 if(_vTbl == _class._vTbl)
5616 _vTbl = ((subclass(Window))_class).pureVTbl;
5621 for(m = 0; m < _class.vTblSize; m++)
5623 if(_vTbl[m] == _class._vTbl[m])
5624 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5633 void SetStateEx(WindowState newState, bool activate)
5636 WindowState prevState = state;
5640 if(prevState != newState)
5641 lastState = prevState;
5643 if(rootWindow != this || !nativeDecorations)
5645 if(style.isActiveClient && !style.hidden && prevState == minimized)
5648 // This block used to be at the end of the function... moved it for flicker problem in X
5649 // ------------------------------------------------------
5653 stateAnchor = normalAnchor;
5654 stateSizeAnchor = normalSizeAnchor;
5657 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5658 stateSizeAnchor = SizeAnchor {};
5662 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5665 byte * idBuffer = new0 byte[size];
5667 for(child = parent.children.first; child; child = child.next)
5669 if(child != this && child.state == minimized)
5671 if(child.iconID > size - 2)
5673 idBuffer = renew0 idBuffer byte[size*2];
5674 memset(idBuffer + size, 0, size);
5677 idBuffer[child.iconID] = (byte)bool::true;
5680 for(c = 0; c<size; c++)
5685 if(style.isActiveClient && !style.hidden)
5688 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5689 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5693 // TOCHECK: Why was this here?
5694 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5695 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5696 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5698 Position(x, y, w, h, true, true, true, true, false, true);
5700 if(!style.inactive && !style.interim && this == parent.activeClient)
5701 parent.UpdateActiveDocument(null);
5704 CreateSystemChildren();
5705 // ------------------------------------------------------
5708 int GetPositionID(Window forChild)
5712 byte * idBuffer = new0 byte[size];
5715 for(child = children.first; child; child = child.next)
5717 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
5719 if(child.positionID > size - 2)
5721 idBuffer = renew0 idBuffer byte[size*2];
5722 memset(idBuffer + size, 0, size);
5725 idBuffer[child.positionID] = (byte)bool::true;
5728 for(c = 0; c<size; c++)
5735 // --- Window related graphics ---
5737 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
5739 palette = newPalette;
5740 if(rootWindow.display)
5741 rootWindow.display.SetPalette(palette, colorMatch);
5744 public bool AcquireInput(bool acquired)
5747 if(acquiredInput != acquired)
5749 if(active || (!visible && creationActivation == activate))
5750 result = AcquireInputEx(acquired);
5755 acquiredInput = acquired ? result : !result;
5760 void ListChildren(ListBox listBox)
5764 for(child = children.first; child; child = child.next)
5766 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
5768 DataRow row = listBox.AddRow();
5769 row.tag = (int)child;
5770 child.FigureCaption(caption);
5771 row.SetData(null, caption);
5776 void UpdateVisual(Box extent)
5778 if(guiApp.driver != null)
5780 if(guiApp.fullScreenMode && guiApp.desktop.display)
5782 guiApp.desktop.mutex.Wait();
5783 guiApp.desktop.display.Lock(true);
5786 if(guiApp.desktop.active)
5788 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
5790 if(guiApp.desktop.display.flags.flipping)
5791 guiApp.desktop.Update(null);
5792 guiApp.desktop.UpdateDisplay();
5793 guiApp.cursorUpdate = true;
5795 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
5797 guiApp.PreserveAndDrawCursor();
5798 // guiApp.desktop.display.ShowScreen();
5799 guiApp.cursorUpdate = false;
5800 guiApp.desktop.dirty = false;
5801 guiApp.RestoreCursorBackground();
5805 guiApp.desktop.display.Unlock();
5806 guiApp.desktop.mutex.Release();
5810 Window rootWindow = this.rootWindow;
5811 rootWindow.mutex.Wait();
5816 guiApp.SignalEvent();
5819 guiApp.waitMutex.Wait();
5820 guiApp.interfaceDriver.Lock(rootWindow);
5821 if(!rootWindow.style.hidden && rootWindow.dirty)
5823 if(rootWindow.display)
5825 rootWindow.UpdateDisplay();
5826 //rootWindow.display.ShowScreen(null);
5828 rootWindow.dirty = false;
5830 guiApp.interfaceDriver.Unlock(rootWindow);
5831 guiApp.waitMutex.Release();
5834 rootWindow.mutex.Release();
5839 void UnlockDisplay(void)
5841 guiApp.interfaceDriver.Unlock(rootWindow);
5844 void LockDisplay(void)
5846 guiApp.interfaceDriver.Lock(rootWindow);
5849 Surface GetSurface(Box box)
5851 return Redraw((box == null) ? this.box : box);
5854 void SetMousePosition(int x, int y)
5856 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
5860 void IntegrationActivate(bool active)
5862 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
5864 isForegroundWindow = true;
5865 ActivateEx(active, active, false, false, null, null);
5866 isForegroundWindow = false;
5871 Window QueryCapture(void)
5873 return guiApp.windowCaptured;
5876 int GetDocumentID(void)
5880 byte * idBuffer = new0 byte[size];
5883 for(child = children.first; child; child = child.next)
5885 // TO CHECK: Do we want a documentID when we already have a file name?
5886 if(child.style.isDocument && !child.fileName)
5888 if(child.documentID-1 > size - 2)
5890 idBuffer = renew0 idBuffer byte[size*2];
5891 memset(idBuffer + size, 0, size);
5894 idBuffer[child.documentID-1] = 1;
5897 for(c = 0; c<size; c++)
5905 void SetInitSize(Size size)
5908 sizeAnchor.size = size;
5909 normalSizeAnchor = sizeAnchor;
5911 // Break the anchors for moveable/resizable windows
5912 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
5914 stateAnchor = normalAnchor;
5915 stateSizeAnchor = normalSizeAnchor;
5917 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5918 Position(x,y, w, h, true, true, true, true, false, true);
5922 void MenuMoveOrSize(bool resize, bool setCursorPosition)
5924 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
5926 guiApp.windowIsResizing = resize;
5927 guiApp.windowMoving = this;
5928 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
5929 if(guiApp.windowIsResizing)
5931 guiApp.windowMovingStart.x += size.w - 1;
5932 guiApp.windowMovingStart.y += size.h - 1;
5934 guiApp.windowMovingBefore = scrolledPos;
5935 guiApp.windowResizingBefore = size;
5936 guiApp.windowMoving.UpdateDecorations();
5937 if(guiApp.windowIsResizing)
5938 guiApp.resizeEndX = guiApp.resizeEndY = true;
5940 if(setCursorPosition)
5941 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
5945 guiApp.interfaceDriver.GetMousePosition(&x, &y);
5946 guiApp.windowMovingStart.x += x - absPosition.x;
5947 guiApp.windowMovingStart.y += y - absPosition.y;
5950 if(guiApp.windowMoving)
5952 if(guiApp.windowMoving.style.nonClient)
5953 guiApp.windowMoving.parent.SetMouseRangeToWindow();
5955 guiApp.windowMoving.parent.SetMouseRangeToClient();
5960 if(this == rootWindow)
5961 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
5969 bool result = false;
5973 else if(guiApp && guiApp.driver != null)
5975 void * systemParent = null;
5976 OldLink slaveHolder;
5978 bool visible = !style.hidden;
5982 systemParent = parent;
5983 parent = guiApp.desktop;
5985 last = parent ? parent.children.last : null;
5987 if((parent && parent != guiApp.desktop && !parent.created) ||
5988 (master && master != guiApp.desktop && !master.created))
5992 property::parent = guiApp.desktop;
5993 if(!master) master = parent;
5995 if(_isModal && master.modalSlave)
5996 property::master = master.modalSlave;
6000 parent.children.Remove(this);
6003 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
6004 if(slaveHolder.data == this)
6006 master.slaves.Delete(slaveHolder);
6011 if(parent == guiApp.desktop && !mutex)
6014 if(style.isDocument)
6017 parent.numDocuments--;
6018 documentID = parent.GetDocumentID();
6021 if(!style.stayOnTop)
6022 for(; last && last.style.stayOnTop; last = last.prev);
6024 parent.children.Insert((last == this) ? null : last, this);
6025 //parent.children.Add(this);
6028 dispDriver = parent.dispDriver;
6031 master.modalSlave = this;
6033 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
6038 master.slaves.Add(slaveHolder = OldLink { data = this });
6043 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
6045 if(style.isDefault && !master.defaultControl)
6046 master.defaultControl = this;
6048 stateAnchor = normalAnchor = anchor;
6049 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
6051 // TOCHECK: Why is this here?
6052 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
6053 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
6055 this.visible = false;
6056 style.hidden = true;
6059 // autoCreate = true;
6067 if(parent == guiApp.desktop)
6068 Log("LoadGraphics %s\n", caption);
6070 if(LoadGraphics(true, false))
6078 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6085 if(style.hasMenuBar /*&& menu*/)
6091 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6092 interim = false, inactive = true, nonClient = true, size.h = 24
6100 // Create the system buttons
6101 CreateSystemChildren();
6103 UpdateActiveDocument(null);
6105 if(style.isDocument)
6109 MenuItem item = menu.FindItem(MenuFileSave, 0);
6110 if(item) item.disabled = !modifiedDocument && fileName;
6115 if(parent == guiApp.desktop)
6116 Log("Preemptive SetState %s\n", caption);
6119 // Preemptive Set State to ensure proper anchoring
6120 SetStateEx(state, false);
6122 style.hidden = true;
6128 for(child = children.first; child; child = next)
6131 if(!child.created && (child.autoCreate || child.wasCreated))
6138 for(link = slaves.first; link; link = next)
6140 Window slave = link.data;
6142 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6145 // Things might have happened that invalidated 'next'...
6146 // Start over the search for slaves to create.
6147 // (Added this to fix crash with Stacker & Toolbar)
6148 next = slaves.first;
6157 if(parent == guiApp.desktop)
6158 Log("Real SetState %s\n", caption);
6161 if(isActiveClient && visible)
6163 parent.numPositions--;
6164 if(state == minimized) parent.numIcons--;
6167 // Real set state & activate for proper display & activation
6168 property::visible = visible;
6169 // SetState(state & 0x00000003, true, 0);
6174 /*if(rootWindow == this)
6175 guiApp.interfaceDriver.ActivateRootWindow(this);
6177 if(creationActivation == activate)
6178 ActivateEx(true, false, true, true, null, null);
6179 else if(creationActivation == flash)
6184 rootWindow.ConsequentialMouseMove(false);
6195 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6201 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6203 //style.hidden = true; // !visible;
6204 style.hidden = !visible;
6205 if(master.modalSlave == this)
6206 master.modalSlave = null;
6213 void WriteCaption(Surface surface, int x, int y)
6216 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6219 void Update(Box region)
6225 rootWindow = this.rootWindow;
6227 // rootWindow.mutex.Wait();
6228 if(!destroyed && visible && display)
6233 // Testing this to avoid repetitve full update to take time...
6234 if(dirtyArea.count == 1)
6236 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6237 if(item.box.left <= box.left &&
6238 item.box.top <= box.top &&
6239 item.box.right >= box.right &&
6240 item.box.bottom >= box.bottom)
6242 rootWindow.dirty = true;
6247 if(display.flags.flipping && !rootWindow.dirty)
6249 if(this == rootWindow)
6253 rootWindow.Update(null);
6258 rootWindow.dirty = true;
6263 realBox.left += clientStart.x;
6264 realBox.top += clientStart.y;
6265 realBox.right += clientStart.x;
6266 realBox.bottom += clientStart.y;
6272 if(realBox.right >= realBox.left &&
6273 realBox.bottom >= realBox.top)
6275 // if(!rootWindow.fullRender)
6276 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6278 for(child = children.first; child; child = child.next)
6283 box.left -= child.absPosition.x - absPosition.x;
6284 box.top -= child.absPosition.y - absPosition.y;
6285 box.right -= child.absPosition.x - absPosition.x;
6286 box.bottom -= child.absPosition.y - absPosition.y;
6287 if(box.right >= child.box.left && box.left <= child.box.right &&
6288 box.bottom >= child.box.top && box.top <= child.box.bottom)
6290 box.left -= child.clientStart.x;
6291 box.top -= child.clientStart.y;
6292 box.right -= child.clientStart.x;
6293 box.bottom -= child.clientStart.y;
6299 realBox.left += absPosition.x - rootWindow.absPosition.x;
6300 realBox.top += absPosition.y - rootWindow.absPosition.y;
6301 realBox.right += absPosition.x - rootWindow.absPosition.x;
6302 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6303 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6306 else if(this == guiApp.desktop)
6309 for(window = children.first; window; window = window.next)
6315 Box childBox = region;
6317 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6318 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6319 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6320 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6322 window.Update(childBox);
6325 window.Update(null);
6330 // rootWindow.mutex.Release();
6337 if(guiApp.windowCaptured != this)
6339 if(guiApp.windowCaptured)
6343 //Logf("Captured %s (%s)\n", caption, class.name);
6344 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6345 guiApp.windowCaptured = this;
6351 bool Destroy(int code)
6356 if(!destroyed && !CloseConfirmation(false)) return false;
6360 // TOCHECK: Should autoCreate be set to false here?
6371 void Move(int x, int y, int w, int h)
6373 normalAnchor = Anchor { left = x, top = y };
6374 normalSizeAnchor = SizeAnchor { size = { w, h } };
6376 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6378 if(destroyed) return;
6380 stateAnchor = normalAnchor;
6381 stateSizeAnchor = normalSizeAnchor;
6383 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6384 Position(x,y, w, h, true, true, true, true, false, true);
6388 DialogResult Modal(void)
6394 // FIXES MEMORY LEAK IF Create() FAILED
6400 void SetScrollArea(int width, int height, bool snapToStep)
6402 bool resize = false;
6405 int stepX = sbStep.x, stepY = sbStep.y;
6406 // Needed to make snapped down position match the skin's check of client area
6407 // against realvirtual
6410 SNAPDOWN(stepX, textCellW);
6411 SNAPDOWN(stepY, textCellH);
6412 stepX = Max(stepX, textCellW);
6413 stepY = Max(stepY, textCellH);
6415 if(scrollFlags.snapX)
6416 SNAPUP(width, stepX);
6417 if(scrollFlags.snapY)
6418 SNAPUP(height, stepY);
6421 reqScrollArea.w = width;
6422 reqScrollArea.h = height;
6423 noAutoScrollArea = (width > 0 || height > 0);
6425 UpdateScrollBars(true, true);
6428 void SetScrollPosition(int x, int y)
6431 sbh.Action(setPosition, x, 0);
6435 int seen = clientSize.w, total = reqScrollArea.w;
6437 if(scrollFlags.snapX)
6438 SNAPDOWN(seen, sbStep.x);
6440 if(!total) total = seen;
6441 range = total - seen + 1;
6442 range = Max(range, 1);
6444 if(x >= range) x = range - 1;
6446 if(scrollFlags.snapX)
6447 SNAPUP(x, sbStep.x);
6450 OnHScroll(setPosition, x, 0);
6454 SNAPDOWN(x, textCellW);
6460 sbv.Action(setPosition, y, 0);
6464 int seen = clientSize.h, total = reqScrollArea.h;
6467 if(scrollFlags.snapY)
6468 SNAPDOWN(seen, sbStep.y);
6470 if(!total) total = seen;
6471 range = total - seen + 1;
6472 range = Max(range, 1);
6474 if(y >= range) y = range - 1;
6476 if(scrollFlags.snapY)
6477 SNAPUP(y, sbStep.y);
6480 OnVScroll(setPosition, y, 0);
6483 SNAPDOWN(y, textCellH);
6488 UpdateCaret(false, false);
6491 void SetScrollLineStep(int stepX, int stepY)
6497 SNAPDOWN(stepX, textCellW);
6498 SNAPDOWN(stepY, textCellH);
6499 stepX = Max(stepX, textCellW);
6500 stepY = Max(stepY, textCellH);
6503 sbh.lineStep = stepX;
6505 sbv.lineStep = stepY;
6508 void SetState(WindowState newState, bool activate, Modifiers mods)
6512 if(state == newState || OnStateChange(newState, mods))
6514 WindowState prevState = state;
6518 // This used to be at the end of the brackets... moved for X, testing...
6519 // This has the effect of activating the window through the system...
6520 if(rootWindow == this)
6521 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6523 SetStateEx(newState, activate);
6525 if(rootWindow == this && !rootWindow.nativeDecorations)
6527 int x = position.x, y = position.y;
6530 x -= guiApp.desktop.absPosition.x;
6531 y -= guiApp.desktop.absPosition.y;
6533 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6537 //state = prevState;
6539 if(state != maximized && style.hasMaximize)
6542 for(child = parent.children.first; child; child = child.next)
6544 if(child != this && child.state == maximized)
6545 child.SetStateEx(normal, false);
6549 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6550 parent.UpdateScrollBars(true, true);
6553 // Do we really need this stuff here?
6554 // Shouldn't the Activate stuff take care of it?
6555 if(parent.rootWindow == parent && style)
6558 parent.FigureCaption(caption);
6559 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6560 parent.UpdateDecorations();
6564 rootWindow.ConsequentialMouseMove(false);
6571 BitmapResource GetIcon(SkinBitmap iconID)
6573 return guiApp.currentSkin.GetBitmap(iconID);
6576 void SetMouseRange(Box range)
6578 if(range || guiApp.fullScreenMode)
6583 clip.left = range.left + absPosition.x + clientStart.x;
6584 clip.top = range.top + absPosition.y + clientStart.y;
6585 clip.right = range.right + absPosition.x + clientStart.x;
6586 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6590 clip.left = guiApp.desktop.box.left;
6591 clip.top = guiApp.desktop.box.top;
6592 clip.right = guiApp.desktop.box.right;
6593 clip.bottom = guiApp.desktop.box.bottom;
6595 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6598 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6601 void SetMouseRangeToClient(void)
6603 if(guiApp.fullScreenMode || this != guiApp.desktop)
6605 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6606 box.Clip(clientArea);
6610 SetMouseRange(null);
6613 void SetMouseRangeToWindow(void)
6615 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6616 if(this == guiApp.desktop)
6617 SetMouseRangeToClient();
6622 // x, y: Desktop Coordinates
6623 void ShowSysMenu(int x, int y)
6626 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6629 menu, $"Restore", r, NotifySelect = MenuWindowRestore,
6630 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6634 menu, $"Move", m, NotifySelect = MenuWindowMove,
6635 disabled = !style.fixed || state == maximized
6639 menu, $"Size", s, NotifySelect = MenuWindowSize,
6640 disabled = !style.sizable || state != normal
6644 menu, $"Minimize", n, NotifySelect = MenuWindowMinimize,
6645 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6649 menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6650 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6654 menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6655 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6657 MenuDivider { menu };
6660 menu, $"Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6661 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6663 windowMenu.Create();
6668 ActivateEx(true, true, true, true, null, null);
6671 void MakeActive(void)
6673 ActivateEx(true, false, true, false, null, null);
6676 void SoftActivate(void)
6678 if(guiApp.desktop.active)
6684 void Deactivate(void)
6686 ActivateEx(false, true, true, true, null, null);
6691 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
6694 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
6696 bool result = false;
6697 if(activeChild && activeChild.cycle)
6699 Window modalWindow, child = activeChild;
6700 if(!clientOnly /*&& parent.tabCycle*/)
6702 Window next = child;
6705 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
6709 if(parent && parent.CycleChildren(backward, false, true, true))
6717 next = next.cycle.prev.data;
6719 next = next.cycle.next.data;
6720 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
6725 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
6726 parent.tabCycle && parent.CycleChildren(backward, false, false))
6730 if(tabCycleOnly && !tabCycle) return false;
6737 child = child.cycle.prev.data;
6739 child = child.cycle.next.data;
6740 if(child == child.parent.activeChild)
6742 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
6745 modalWindow = child.FindModal();
6748 // Scroll the window to include the active control
6749 if(sbh && !child.style.dontScrollHorz)
6751 if(child.scrolledPos.x < 0)
6752 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
6753 else if(child.scrolledPos.x + child.size.w > clientSize.w)
6754 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
6756 if(sbv && !child.style.dontScrollVert)
6758 if(child.scrolledPos.y < 0)
6759 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
6760 else if(child.scrolledPos.y + child.size.h > clientSize.h)
6761 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
6765 child = modalWindow ? modalWindow : child;
6766 child.ActivateEx(true, true, true, true, null, null);
6767 if(child.tabCycle && child.childrenCycle.first)
6768 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
6776 ConsequentialMouseMove(false);
6780 void AddResource(Resource resource)
6784 ResPtr ptr { resource = resource };
6788 // Load Graphics here if window is created already
6789 if(/*created && */display)
6791 display.Lock(false);
6792 ptr.loaded = display.displaySystem.LoadResource(resource);
6796 // Temporary hack to load font right away for listbox in dropbox ...
6797 else if(master && master.display)
6799 master.display.Lock(false);
6800 master.display.displaySystem.LoadResource(resource);
6801 master.display.Unlock();
6807 void RemoveResource(Resource resource)
6812 for(ptr = resources.first; ptr; ptr = ptr.next)
6814 if(ptr.resource == resource)
6820 // Unload Graphics here if window is created already
6821 if(/*created && */display)
6825 display.Lock(false);
6826 display.displaySystem.UnloadResource(resource, ptr.loaded);
6832 resources.Delete(ptr);
6837 void SetCaret(int x, int y, int size)
6844 if(active && !style.interim)
6846 if(visible || !guiApp.caretOwner)
6847 guiApp.caretOwner = size ? this : null;
6849 UpdateCaret(false, false);
6852 guiApp.interfaceDriver.SetCaret(0,0,0);
6853 UpdateCaret(false, true);
6854 guiApp.caretEnabled = false;
6857 else if(style.inactive && active)
6859 guiApp.interfaceDriver.SetCaret(0,0,0);
6860 UpdateCaret(false, true);
6861 guiApp.caretEnabled = false;
6866 void Scroll(int x, int y)
6868 bool opaque = !style.drawBehind || background.a;
6869 if(opaque && display && display.flags.scrolling)
6871 Box box = clientArea;
6872 box.left += clientStart.x;
6873 box.top += clientStart.y;
6874 box.right += clientStart.x;
6875 box.bottom += clientStart.y;
6877 //scrollExtent.Free(null);
6878 scrollExtent.AddBox(box);
6879 scrolledArea.x += x;
6880 scrolledArea.y += y;
6882 //scrollExtent.Free();
6883 //scrollExtent.AddBox(clientArea);
6884 //scrollExtent.Offset(clientStart.x, clientStart.y);
6885 //scrolledArea.x = x;
6886 //scrolledArea.y = y;
6892 rootWindow.dirty = true;
6895 void ReleaseCapture()
6897 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
6899 Window oldCaptured = guiApp.windowCaptured;
6900 guiApp.windowCaptured = null;
6901 guiApp.prevWindow = null;
6904 //guiApp.Log("Released Capture\n");
6906 guiApp.interfaceDriver.SetMouseCapture(null);
6908 //oldCaptured.OnMouseCaptureLost();
6911 oldCaptured.ConsequentialMouseMove(false);
6916 void SetText(char * format, ...)
6923 char caption[MAX_F_STRING];
6925 va_start(args, format);
6926 vsprintf(caption, format, args);
6929 this.caption = new char[strlen(caption)+1];
6931 strcpy(this.caption, caption);
6940 bool Grab(Bitmap bitmap, Box box, bool decorations)
6942 bool result = false;
6943 if(display || this == guiApp.desktop)
6945 Box clip = {MININT, MININT, MAXINT, MAXINT};
6951 clip.Clip(clientArea);
6953 clip.Clip(this.box);
6955 if(rootWindow != this)
6957 clip.left += absPosition.y;
6958 clip.top += absPosition.y;
6959 clip.right += absPosition.x;
6960 clip.bottom += absPosition.y;
6963 clip.left += decorations ? 0 : clientStart.x;
6964 clip.top += decorations ? 0 : clientStart.y;
6965 clip.right += decorations ? 0 : clientStart.x;
6966 clip.bottom += decorations ? 0 : clientStart.y;
6968 if(display && display.flags.flipping)
6970 rootWindow.Update(null);
6971 rootWindow.UpdateDisplay();
6978 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
6979 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6983 result = display.Grab(bitmap, clip.left, clip.top,
6984 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6986 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
6988 if(!bitmap.Convert(null, pixelFormat888, null))
6995 void GetMousePosition(int * x, int * y)
6997 int mouseX = 0, mouseY = 0;
6998 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
7001 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
7002 if(this != guiApp.desktop)
7004 mouseX -= absPosition.x + clientStart.x;
7005 mouseY -= absPosition.y + clientStart.y;
7012 DialogResult DoModal()
7014 DialogResult returnCode = 0;
7015 int terminated = terminateX;
7018 while(!destroyed && guiApp.driver != null)
7020 if(terminateX != terminated)
7022 terminated = terminateX;
7023 guiApp.desktop.Destroy(0);
7024 if(guiApp.desktop.created)
7027 //printf("Resetting terminate X to 0\n");
7033 guiApp.UpdateDisplay();
7034 if(!guiApp.ProcessInput(false))
7037 returnCode = this.returnCode;
7050 return !destroyed && guiApp.driver != null && terminateX < 2;
7053 DialogResult DoModalEnd()
7055 DialogResult returnCode = this.returnCode;
7060 // --- Window manipulation ---
7061 /*bool GetDisabled()
7063 bool disabled = this.disabled;
7065 for(window = this; (window = window.master); )
7076 // --- Mouse Manipulation ---
7077 void GetNCMousePosition(int * x, int * y)
7079 GetMousePosition(x, y);
7080 if(x) *x += clientStart.x;
7081 if(y) *y += clientStart.y;
7084 // --- Carets manipulation ---
7085 void GetCaretPosition(Point caretPos)
7087 caretPos = this.caretPos;
7090 int GetCaretSize(void)
7095 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7101 bool CloseConfirmation(bool parentClosing)
7114 if(!OnClose(parentClosing))
7117 // If you want to skip this, simply set modifiedDocument to false in OnClose
7118 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7120 DialogResult dialogRes;
7123 sprintf(message, $"Save changes to %s?", fileName);
7125 sprintf(message, $"Save changes to Untitled %d?", documentID);
7127 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = message }.Modal();
7129 if(dialogRes == yes)
7131 // TOFIX: Precomp error if brackets are taken out
7132 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7134 else if(dialogRes == cancel)
7140 for(slave = slaves.first; slave; slave = slave.next)
7142 Window w = slave.data;
7143 if((w.parent == this || !w.IsDescendantOf(this)) && !w.CloseConfirmation(true))
7145 // ((Window)slave.data).CloseConfirmation(true);
7154 for(child = children.first; child; child = child.next)
7155 if(child.master != this && !child.CloseConfirmation(true))
7165 // Static methods... move them somewhere else?
7166 void ::RestoreCaret()
7168 if(guiApp.caretOwner)
7169 guiApp.caretOwner.UpdateCaret(false, false);
7172 void ::FreeMouseRange()
7174 guiApp.interfaceDriver.SetMouseRange(null, null);
7178 bool MenuFileClose(MenuItem selection, Modifiers mods)
7180 Window document = activeChild;
7182 document.Destroy(0);
7186 bool MenuFileExit(MenuItem selection, Modifiers mods)
7192 bool MenuFileSave(MenuItem selection, Modifiers mods)
7196 fileMonitor.fileName = null;
7199 if(OnSaveFile(fileName))
7201 //if(OnFileModified != Window::OnFileModified)
7204 fileMonitor.fileName = fileName;
7210 MessageBox dialog { master = master, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7211 DialogResult answer = dialog.Modal();
7213 if(answer != yes) return (bool)answer;
7216 return MenuFileSaveAs(selection, mods);
7219 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7221 DialogResult result = (DialogResult)bool::true;
7222 FileDialog fileDialog = saveDialog;
7225 fileDialog = FileDialog {};
7230 fileDialog.filePath = fileName;
7233 char filePath[MAX_FILENAME];
7234 sprintf(filePath, "Untitled %d", documentID);
7235 fileDialog.filePath = filePath;
7237 fileMonitor.fileName = null;
7239 fileDialog.type = save;
7240 fileDialog.text = $"Save As";
7244 fileDialog.master = master.parent ? master : this;
7245 if(fileDialog.Modal() == ok)
7247 char * filePath = fileDialog.filePath;
7249 if(OnSaveFile(filePath))
7252 property::fileName = filePath;
7253 NotifySaved(master, this, filePath);
7258 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7259 DialogResult answer = dialog.Modal();
7274 //if(OnFileModified != Window::OnFileModified && fileName)
7277 fileMonitor.fileName = fileName;
7281 return (bool)result; // Actually returning result from Yes/NoCancel message box
7284 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7286 Window document = activeChild;
7288 for(document = children.first; document; document = next)
7290 next = document.next;
7291 if(document.style.isDocument || document.fileName)
7292 document.MenuFileSave(selection, mods);
7297 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7301 for(document = children.first; document; document = document.next)
7302 //if(document.style.isDocument && document.state == minimized)
7303 if(document.style.isActiveClient && document.state == minimized)
7304 document.SetState(minimized, false, mods);
7308 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7310 Window document = activeChild;
7313 Window firstDocument = null;
7315 OldLink cycle = document.cycle.prev;
7320 if(child.style.isActiveClient && !child.style.hidden)
7324 firstDocument = child;
7325 if(child.state == minimized)
7326 child.SetState(minimized, false, mods);
7329 child.positionID = id++;
7330 child.SetState(normal, false, mods);
7331 child.anchor.left.type = cascade;
7334 child.normalSizeAnchor = *&child.sizeAnchor;
7335 child.normalAnchor = child.anchor;
7337 // Break the anchors for moveable/resizable windows
7338 if(child.style.fixed)
7340 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7342 (*&child.normalAnchor).left = x;
7343 (*&child.normalAnchor).top = y;
7344 (*&child.normalAnchor).right.type = none;
7345 (*&child.normalAnchor).bottom.type = none;
7347 child.normalSizeAnchor.isClientW = false;
7348 child.normalSizeAnchor.isClientH = false;
7349 child.normalSizeAnchor.size.w = w;
7350 child.normalSizeAnchor.size.h = h;
7351 child.anchored = false;
7354 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7356 child.stateAnchor = child.normalAnchor;
7357 child.stateSizeAnchor = child.normalSizeAnchor;
7359 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7360 child.Position(x, y, w, h, true, true, true, true, false, false);
7365 last = children.last;
7366 if(!child.style.stayOnTop)
7367 for(; last && last.style.stayOnTop; last = last.prev);
7368 children.Move(child, last);
7369 childrenOrder.Move(child.order, childrenOrder.last);
7371 if(cycle == document.cycle) break;
7375 firstDocument.Activate();
7380 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7387 // Close all closes all active clients, not all documents
7388 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7390 Window next, document;
7392 for(document = children.first; document; document = next)
7394 for(next = document.next; next && !(next.style.isActiveClient; next = next.next);
7395 if(document.style.isActiveClient)
7396 if(!document.Destroy(0) && !document.style.hidden)
7402 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7404 if(style.hasMaximize && state != maximized)
7405 SetState(maximized, 0, 0);
7409 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7411 if(style.hasMinimize && state != minimized)
7413 SetState(minimized, 0, 0);
7414 parent.CycleChildren(false, true, false, true);
7419 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7421 MenuMoveOrSize(false, selection ? true : false);
7425 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7427 CycleChildren(false, true, false, true);
7431 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7433 CycleChildren(true, true, false, true);
7437 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7439 MenuMoveOrSize(true, true);
7443 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7446 SetState(normal, 0, 0);
7450 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7453 int id = selection.id;
7454 OldLink cycle = activeClient.cycle;
7456 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7459 Window sibling = cycle.data;
7460 if(sibling.style.isActiveClient && sibling.visible && !sibling.style.nonClient)
7468 document = cycle.data;
7469 document.Activate();
7471 //if(activeChild.state == maximized)
7472 // document.SetState(maximized, false, mods);
7473 //else if(document.state == minimized)
7474 // document.SetState(normal, false, mods);
7478 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7480 stayOnTop = !style.stayOnTop;
7484 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7486 Window document = activeChild;
7489 Window firstDocument = null;
7490 OldLink cycle = document.cycle;
7494 Window child = cycle.data;
7495 if(child.style.isActiveClient && !child.style.hidden)
7497 if(!firstDocument) firstDocument = child;
7498 if(child.state == minimized)
7499 child.SetState(minimized, false, mods);
7502 child.positionID = id++;
7503 child.SetState(normal, false, mods);
7504 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7506 child.anchor.left.type = hTiled;
7509 child.normalSizeAnchor = *&child.sizeAnchor;
7510 child.normalAnchor = child.anchor;
7512 // Break the anchors for moveable/resizable windows
7513 if(child.style.fixed)
7515 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7517 (*&child.normalAnchor).left = x;
7518 (*&child.normalAnchor).top = y;
7519 (*&child.normalAnchor).right.type = none;
7520 (*&child.normalAnchor).bottom.type = none;
7521 child.normalSizeAnchor.isClientW = false;
7522 child.normalSizeAnchor.isClientH = false;
7523 child.normalSizeAnchor.size.w = w;
7524 child.normalSizeAnchor.size.h = h;
7525 child.anchored = false;
7528 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7530 child.stateAnchor = child.normalAnchor;
7531 child.stateSizeAnchor = child.normalSizeAnchor;
7533 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7534 child.Position(x,y, w, h, true, true, true, true, false, true);
7539 if((cycle = cycle.next) == document.cycle) break;
7542 firstDocument.Activate();
7547 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7549 Window document = activeChild;
7552 Window firstDocument = null;
7554 OldLink cycle = document.cycle;
7559 //if(child.style.isDocument)
7560 if(child.style.isActiveClient && !child.style.hidden)
7562 if(!firstDocument) firstDocument = child;
7563 if(child.state == minimized)
7564 child.SetState(minimized, false, mods);
7567 child.positionID = id++;
7568 child.SetState(normal, false, mods);
7569 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7571 child.anchor.left.type = vTiled;
7574 child.normalSizeAnchor = *&child.sizeAnchor;
7575 child.normalAnchor = child.anchor;
7577 // Break the anchors for moveable/resizable windows
7578 if(child.style.fixed)
7580 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7582 (*&child.normalAnchor).left = x;
7583 (*&child.normalAnchor).top = y;
7584 (*&child.normalAnchor).right.type = none;
7585 (*&child.normalAnchor).bottom.type = none;
7586 child.normalSizeAnchor.isClientW = false;
7587 child.normalSizeAnchor.isClientH = false;
7588 child.normalSizeAnchor.size.w = w;
7589 child.normalSizeAnchor.size.h = h;
7590 child.anchored = false;
7593 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7595 child.stateAnchor = child.normalAnchor;
7596 child.stateSizeAnchor = child.normalSizeAnchor;
7598 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7599 child.Position(x,y, w, h, true, true, true, true, false, true);
7604 if((cycle = cycle.next) == document.cycle) break;
7607 firstDocument.Activate();
7612 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7614 WindowList dialog { master = this };
7615 Window document = (Window)dialog.Modal();
7618 if(activeChild.state == maximized)
7619 document.SetState(maximized, false, mods);
7620 else if(document.state == minimized)
7621 document.SetState(normal, false, mods);
7622 document.Activate();
7628 virtual bool OnCreate(void);
7629 virtual void OnDestroy(void);
7630 virtual void OnDestroyed(void);
7631 virtual bool OnClose(bool parentClosing);
7632 virtual bool OnStateChange(WindowState state, Modifiers mods);
7633 virtual bool OnPostCreate(void);
7634 virtual bool OnMoving(int *x, int *y, int w, int h);
7635 virtual bool OnResizing(int *width, int *height);
7636 virtual void OnResize(int width, int height);
7637 virtual void OnPosition(int x, int y, int width, int height);
7638 virtual bool OnLoadGraphics(void);
7639 virtual void OnApplyGraphics(void);
7640 virtual void OnUnloadGraphics(void);
7641 virtual void OnRedraw(Surface surface);
7642 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7643 virtual void OnActivateClient(Window client, Window previous);
7644 virtual bool OnKeyDown(Key key, unichar ch);
7645 virtual bool OnKeyUp(Key key, unichar ch);
7646 virtual bool OnKeyHit(Key key, unichar ch);
7647 virtual bool OnSysKeyDown(Key key, unichar ch);
7648 virtual bool OnSysKeyUp(Key key, unichar ch);
7649 virtual bool OnSysKeyHit(Key key, unichar ch);
7650 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7651 virtual bool OnMouseLeave(Modifiers mods);
7652 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7653 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7654 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
7655 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
7656 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
7657 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
7658 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
7659 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
7660 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
7661 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
7662 virtual void OnMouseCaptureLost(void);
7663 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
7664 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
7665 virtual void OnDrawOverChildren(Surface surface);
7666 virtual bool OnFileModified(FileChange fileChange, char * param);
7667 virtual bool OnSaveFile(char * fileName);
7669 // Virtual Methods -- Children management (To support Stacker, for lack of built-in auto-layout)
7670 // Note: A 'client' would refer to isActiveClient, rather than
7671 // being confined to the 'client area' (nonClient == false)
7672 virtual void OnChildAddedOrRemoved(Window child, bool removed);
7673 virtual void OnChildVisibilityToggled(Window child, bool visible);
7674 virtual void OnChildResized(Window child, int x, int y, int w, int h);
7676 // Skins Virtual Functions
7677 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
7678 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
7679 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
7684 virtual void ShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7685 virtual void PreShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7686 virtual bool IsMouseMoving(int x, int y, int w, int h);
7687 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY);
7688 virtual void UpdateNonClient();
7689 virtual void SetBox(Box box);
7690 virtual bool IsInside(int x, int y)
7692 return box.IsPointInside({x, y});
7694 virtual bool IsOpaque()
7696 return (!style.drawBehind || background.a == 255);
7700 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
7701 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
7702 virtual void Window::NotifySaved(Window window, char * filePath);
7707 property Window parent
7709 property_category $"Layout"
7712 if(value || guiApp.desktop)
7715 Window oldParent = parent;
7716 Anchor anchor = this.anchor;
7718 if(value && value.IsDescendantOf(this)) return;
7719 if(value && value == this)
7721 if(!value) value = guiApp.desktop;
7723 if(value == oldParent) return;
7725 if(!master || (master == this.parent && master == guiApp.desktop))
7726 property::master = value;
7730 parent.children.Remove(this);
7731 parent.OnChildAddedOrRemoved(this, true);
7735 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7736 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
7737 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7738 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
7742 last = value.children.last;
7744 if(style.isDocument)
7747 parent.numDocuments--;
7748 documentID = value.GetDocumentID();
7751 if(style.isActiveClient && !style.hidden)
7753 if(parent && parent != guiApp.desktop && !(style.hidden))
7755 if(state == minimized) parent.numIcons--;
7756 parent.numPositions--;
7760 if(!style.stayOnTop)
7761 for(; last && last.style.stayOnTop; last = last.prev);
7763 value.children.Insert(last, this);
7765 // *** NEW HERE: ***
7767 parent.childrenCycle.Delete(cycle);
7769 parent.childrenOrder.Delete(order);
7777 int x = position.x, y = position.y, w = size.w, h = size.h;
7781 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
7782 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
7784 vpw = value.clientSize.w;
7785 vph = value.clientSize.h;
7791 else if(style.fixed)
7793 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
7794 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
7797 anchor = this.anchor;
7799 if(anchor.left.type == offset) anchor.left.distance = x;
7800 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
7801 if(anchor.top.type == offset) anchor.top.distance = y;
7802 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
7803 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
7804 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
7805 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
7806 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
7807 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
7808 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
7810 if(!anchor.left.type && !anchor.right.type)
7812 anchor.horz.distance = (x + w / 2) - (vpw / 2);
7813 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
7815 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
7816 if(!anchor.top.type && !anchor.bottom.type)
7818 anchor.vert.distance = (y + h / 2) - (vph / 2);
7819 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
7821 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
7824 parent.OnChildAddedOrRemoved(this, false);
7830 parent.childrenCycle.Insert(
7831 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
7832 cycle = OldLink { data = this });
7833 parent.childrenOrder.Insert(
7834 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
7835 order = OldLink { data = this });
7838 if(!style.hidden && style.isActiveClient)
7840 positionID = parent.GetPositionID(this);
7841 parent.numPositions++;
7842 if(state == minimized) parent.numIcons--;
7845 // *** FONT INHERITANCE ***
7846 if(!setFont && oldParent)
7847 stopwatching(oldParent, font);
7851 RemoveResource(systemFont);
7854 // TESTING WITH WATCHERS:
7855 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7856 // usedFont = setFont ? setFont : (systemFont);
7860 if(guiApp.currentSkin)
7862 systemFont = guiApp.currentSkin.SystemFont();
7865 usedFont = systemFont;
7866 AddResource(systemFont);
7874 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7883 if(value.rootWindow && value.rootWindow.display && rootWindow)
7885 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
7886 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
7889 UnloadGraphics(false);
7892 LoadGraphics(false, false);
7895 if(value.rootWindow != rootWindow)
7896 DisplayModeChanged();
7900 scrolledPos.x = MININT; // Prevent parent update
7901 property::anchor = anchor;
7905 if(guiApp.currentSkin)
7906 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
7908 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7909 Position(x, y, w, h, true, true, true, true, false, true);
7914 // else parent = value;
7917 get { return parent; }
7920 property Window master
7922 property_category $"Behavior"
7925 //if(this == value) return;
7926 if(value && value.IsSlaveOf(this)) return;
7932 OldLink slaveHolder;
7933 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
7934 if(slaveHolder.data == this)
7936 master.slaves.Delete(slaveHolder);
7943 value.slaves.Add(OldLink { data = this });
7948 master.hotKeys.Remove(hotKey);
7949 value.hotKeys.Add(hotKey);
7952 if(master && master.defaultControl == this)
7953 master.defaultControl = null;
7955 if(style.isDefault && !value.defaultControl)
7956 value.defaultControl = this;
7961 get { return master ? master : parent; }
7964 property char * caption
7966 property_category $"Appearance"
7973 caption = new char[strlen(value)+1];
7975 strcpy(caption, value);
7980 get { return caption; }
7985 property_category $"Behavior"
7994 master.hotKeys.Add(hotKey = HotKeySlot { });
7998 hotKey.window = this;
8003 master.hotKeys.Delete(hotKey);
8008 get { return hotKey ? hotKey.key : 0; }
8011 property Color background
8013 property_category $"Appearance"
8016 background.color = value;
8021 if(this == rootWindow)
8022 guiApp.interfaceDriver.SetRootWindowColor(this);
8025 get { return background.color; }
8028 property Percentage opacity
8030 property_category $"Appearance"
8033 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
8034 drawBehind = background.a ? false : true;
8036 get { return background.a / 255.0f; }
8039 property Color foreground
8041 property_category $"Appearance"
8049 get { return foreground; }
8052 property BorderStyle borderStyle
8054 property_category $"Appearance"
8057 if(!((BorderBits)value).fixed)
8059 style.hasClose = false;
8060 style.hasMaximize = false;
8061 style.hasMinimize = false;
8062 nativeDecorations = false;
8064 style.borderBits = value;
8068 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8070 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8071 Position(x, y, w, h, true, true, true, true, false, true);
8072 CreateSystemChildren();
8075 get { return (BorderStyle)style.borderBits; }
8078 property Size minClientSize
8080 property_category $"Layout"
8081 set { minSize = value; }
8082 get { value = minSize; }
8085 property Size maxClientSize
8087 property_category $"Layout"
8088 set { maxSize = value; }
8089 get { value = maxSize; }
8092 property bool hasMaximize
8094 property_category $"Window Style"
8097 style.hasMaximize = value;
8098 if(value) { style.fixed = true; style.contour = true; }
8102 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8104 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8105 Position(x, y, w, h, true, true, true, true, false, true);
8107 CreateSystemChildren();
8110 get { return style.hasMaximize; }
8113 property bool hasMinimize
8115 property_category $"Window Style"
8118 style.hasMinimize = value;
8119 if(value) { style.fixed = true; style.contour = true; }
8123 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8125 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8126 Position(x, y, w, h, true, true, true, true, false, true);
8128 CreateSystemChildren();
8131 get { return style.hasMinimize; }
8134 property bool hasClose
8136 property_category $"Window Style"
8139 style.hasClose = value;
8140 if(value) { style.fixed = true; style.contour = true; }
8144 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8145 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8146 Position(x, y, w, h, true, true, true, true, false, true);
8147 CreateSystemChildren();
8150 get { return style.hasClose; }
8153 property bool nonClient
8155 property_category $"Layout"
8158 style.nonClient = value;
8160 style.stayOnTop = true;
8162 get { return style.nonClient; }
8165 property bool inactive
8167 property_category $"Behavior"
8172 // *** NEW HERE: ***
8176 parent.childrenCycle.Delete(cycle);
8178 parent.childrenOrder.Delete(order);
8185 active = false; // true;
8186 if(parent.activeChild == this)
8187 parent.activeChild = null;
8188 if(parent.activeClient == this)
8189 parent.activeClient = null;
8198 parent.childrenCycle.Insert(
8199 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8200 cycle = OldLink { data = this });
8202 parent.childrenOrder.Insert(
8203 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8204 order = OldLink { data = this });
8207 style.inactive = value;
8209 get { return style.inactive; }
8212 property bool clickThrough
8214 property_category $"Behavior"
8215 set { style.clickThrough = value; }
8216 get { return style.clickThrough; }
8219 property bool isRemote
8221 property_category $"Behavior"
8222 set { style.isRemote = value; }
8223 get { return style.isRemote; }
8226 property bool noCycle
8228 property_category $"Behavior"
8229 set { style.noCycle = value; }
8230 get { return style.noCycle; }
8233 property bool isModal
8235 property_category $"Behavior"
8236 set { style.modal = value; }
8237 get { return style.modal; }
8240 property bool interim
8242 property_category $"Behavior"
8243 set { style.interim = value; }
8244 get { return style.interim; }
8247 property bool tabCycle
8249 property_category $"Behavior"
8250 set { style.tabCycle = value; }
8251 get { return style.tabCycle; }
8254 property bool isDefault
8256 property_category $"Behavior"
8264 /*for(sibling = parent.children.first; sibling; sibling = sibling.next)
8265 if(sibling != this && sibling.style.isDefault)
8266 sibling.style.isDefault = false;*/
8267 if(master.defaultControl)
8268 master.defaultControl.style.isDefault = false;
8269 master.defaultControl = this;
8271 else if(master.defaultControl == this)
8272 master.defaultControl = null;
8276 style.isDefault = value;
8278 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8280 get { return style.isDefault; }
8283 property bool drawBehind
8285 property_category $"Window Style"
8286 set { style.drawBehind = value; }
8287 get { return style.drawBehind; }
8290 property bool hasMenuBar
8292 property_category $"Window Style"
8302 if(created && !menuBar)
8309 anchor = Anchor { top = 23, left = 1, right = 1 },
8311 inactive = true, nonClient = true
8316 else if(created && menuBar)
8321 style.hasMenuBar = value;
8323 get { return style.hasMenuBar; }
8326 property bool hasStatusBar
8328 property_category $"Window Style"
8335 statusBar = StatusBar { this };
8343 style.hasStatusBar = value;
8345 get { return style.hasStatusBar; }
8347 property bool stayOnTop
8349 property_category $"Window Style"
8354 if(created && !style.stayOnTop)
8356 if(rootWindow == this)
8357 guiApp.interfaceDriver.OrderRootWindow(this, true);
8358 else if(parent.children.last != this)
8360 parent.children.Move(this, parent.children.last);
8364 style.stayOnTop = true;
8368 if(created && style.stayOnTop)
8370 if(rootWindow == this)
8371 guiApp.interfaceDriver.OrderRootWindow(this, false);
8378 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8379 order && ((Window)order.data).style.stayOnTop;
8380 order = (order == parent.childrenOrder.first) ? null : order.prev);
8381 last = order ? order.data : null;
8385 for(last = parent.children.last;
8386 last && last.style.stayOnTop;
8390 parent.children.Move(this, last);
8394 style.stayOnTop = false;
8397 get { return style.stayOnTop; }
8402 property_category $"Window Style"
8412 if(menuBar && !value)
8419 if(!menuBar && style.hasMenuBar && value)
8423 this, menu = value, isMenuBar = true,
8424 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8425 inactive = true, nonClient = true
8429 UpdateActiveDocument(null);
8432 get { return menu; }
8435 property FontResource font
8437 property_category $"Appearance"
8439 isset { return setFont ? true : false; }
8444 if(value && !setFont) { stopwatching(parent, font); }
8445 else if(!value && setFont)
8451 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8460 RemoveResource(setFont);
8465 RemoveResource(systemFont);
8472 AddResource(setFont);
8475 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8478 systemFont = guiApp.currentSkin.SystemFont();
8480 usedFont = systemFont;
8481 AddResource(systemFont);
8489 get { return usedFont; }
8492 property SizeAnchor sizeAnchor
8494 property_category $"Layout"
8497 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8498 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8499 sizeAnchor.isClientW != sizeAnchor.isClientH;
8506 normalSizeAnchor = sizeAnchor;
8508 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8510 stateAnchor = normalAnchor;
8511 stateSizeAnchor = normalSizeAnchor;
8513 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8514 Position(x,y, w, h, true, true, true, true, false, true);
8521 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8522 sizeAnchor.isClientW,
8523 sizeAnchor.isClientH
8530 property_category $"Layout"
8533 Anchor thisAnchor = anchor;
8534 SizeAnchor thisSizeAnchor = sizeAnchor;
8535 bool leftRight = (anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none);
8536 bool topBottom = (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none);
8537 bool isClient = !sizeAnchor.isClientW && !sizeAnchor.isClientH;
8538 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8539 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8540 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8546 sizeAnchor.isClientW = false;
8547 sizeAnchor.isClientH = false;
8548 sizeAnchor.size = value;
8550 normalSizeAnchor = sizeAnchor;
8552 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8554 stateAnchor = normalAnchor;
8555 stateSizeAnchor = normalSizeAnchor;
8557 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8558 Position(x, y, w, h, true, true, true, true, false, true);
8559 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
8562 get { value = size; }
8565 property Size clientSize
8567 property_category $"Layout"
8570 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8571 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8572 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8577 sizeAnchor.isClientW = true;
8578 sizeAnchor.isClientH = true;
8579 sizeAnchor.size = value;
8581 normalSizeAnchor = sizeAnchor;
8583 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8585 stateAnchor = normalAnchor;
8586 stateSizeAnchor = normalSizeAnchor;
8588 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8589 Position(x,y, w, h, true, true, true, true, false, true);
8592 get { value = clientSize; }
8595 property Size initSize { get { value = sizeAnchor.size; } };
8597 property Anchor anchor
8599 property_category $"Layout"
8600 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8606 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8608 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8609 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8611 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8613 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8614 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8618 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8620 anchor.left.distance = 0;
8621 anchor.horz.type = 0;
8623 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8625 anchor.top.distance = 0;
8626 anchor.vert.type = 0;
8635 normalAnchor = anchor;
8637 // Break the anchors for moveable/resizable windows
8638 /*if(style.fixed ) //&& value.left.type == cascade)
8640 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
8642 this.anchor = normalAnchor = Anchor { left = x, top = y };
8643 normalSizeAnchor = SizeAnchor { { w, h } };
8646 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8648 stateAnchor = normalAnchor;
8649 stateSizeAnchor = normalSizeAnchor;
8651 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8652 Position(x, y, w, h, true, true, true, true, false, true);
8661 get { value = this ? anchor : Anchor { }; }
8664 property Point position
8666 property_category $"Layout"
8669 if(value == null) return;
8671 anchor.left = value.x;
8672 anchor.top = value.y;
8673 anchor.right.type = none;
8674 anchor.bottom.type = none;
8679 normalAnchor = anchor;
8681 // Break the anchors for moveable/resizable windows
8685 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8687 normalAnchor.left = x;
8688 normalAnchor.top = y;
8689 normalAnchor.right.type = none;
8690 normalAnchor.bottom.type = none;
8691 normalSizeAnchor.size.width = w;
8692 normalSizeAnchor.size.height = h;
8696 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8698 stateAnchor = normalAnchor;
8699 stateSizeAnchor = normalSizeAnchor;
8701 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8702 Position(x,y, w, h, true, true, true, true, false, true);
8706 get { value = position; }
8709 property bool disabled
8711 property_category $"Behavior"
8714 if(this && disabled != value)
8721 get { return (bool)disabled; }
8724 property bool isEnabled
8729 for(parent = this; parent; parent = parent.parent)
8736 property WindowState state
8738 property_category $"Behavior"
8739 set { SetState(value, false, 0); }
8740 get { return this ? state : 0; }
8743 property bool visible
8745 property_category $"Behavior"
8748 if(this && !value && !style.hidden && parent)
8750 bool wasActiveChild = parent.activeChild == this;
8751 Window client = null;
8753 style.hidden = true;
8754 if(style.isActiveClient)
8756 parent.numPositions--;
8757 if(state == minimized) parent.numIcons--;
8762 OldLink prevOrder = null;
8764 if(rootWindow == this)
8765 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
8768 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
8771 box.left -= parent.clientStart.x;
8772 box.top -= parent.clientStart.y;
8773 box.right -= parent.clientStart.x;
8774 box.bottom -= parent.clientStart.y;
8778 if(_isModal && master && master.modalSlave == this)
8779 master.modalSlave = null;
8783 OldLink tmpPrev = order.prev;
8784 client = tmpPrev ? tmpPrev.data : null;
8785 if(client && !client.style.hidden && !client.destroyed && client.created)
8786 prevOrder = tmpPrev;
8789 client = tmpPrev ? tmpPrev.data : null;
8790 if(client == this) { client = null; break; }
8791 if(client && ((client.style.hidden) || client.destroyed || !client.created))
8793 tmpPrev = client.order.prev;
8798 prevOrder = tmpPrev;
8803 // If this window can be an active client, make sure the next window we activate can also be one
8804 if(!style.nonClient && style.isActiveClient)
8806 tmpPrev = prevOrder;
8809 client = tmpPrev ? tmpPrev.data : null;
8810 if(client == this) { client = null; break; }
8811 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
8813 tmpPrev = client.order.prev;
8818 prevOrder = tmpPrev;
8822 if(client && client.style.hidden) client = null;
8826 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
8828 if(order && prevOrder && prevOrder.data != this)
8829 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
8831 ActivateEx(false, false, false, true, null, null);
8833 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
8834 if(parent.activeClient == this)
8836 parent.activeClient = null;
8837 parent.UpdateActiveDocument(null);
8840 else if(parent.activeClient == this)
8842 parent.activeClient = client;
8843 parent.UpdateActiveDocument(this);
8846 // *** Not doing this anymore ***
8849 parent.childrenCycle.Delete(cycle);
8851 parent.childrenOrder.Delete(order);
8856 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8861 else if(this && value && style.hidden)
8863 style.hidden = false;
8866 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8867 if(rootWindow == this)
8868 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
8870 if(_isModal && master)
8871 master.modalSlave = this;
8873 if(style.isActiveClient)
8875 positionID = parent.GetPositionID(this);
8876 parent.numPositions++;
8877 if(state == minimized) parent.numIcons++;
8880 // *** NOT DOING THIS ANYMORE ***
8882 if(!(style.inactive))
8884 if(!(style.noCycle))
8886 cycle = parent.childrenCycle.AddAfter(
8887 (parent.activeChild && parent.activeChild.cycle) ?
8888 parent.activeChild.cycle.prev : null, sizeof(OldLink));
8891 order = parent.childrenOrder.AddAfter(
8892 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8899 if(true || !parent.activeChild)
8900 ActivateEx(true, false, true, true, null, null);
8902 if(creationActivation == activate)
8903 ActivateEx(true, false, true, true, null, null);
8904 else if(creationActivation == flash && !object)
8907 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8911 ConsequentialMouseMove(false);
8917 style.hidden = !value;
8920 get { return (style.hidden || !setVisible) ? false : true; }
8923 property bool isDocument
8925 property_category $"Document"
8926 set { style.isDocument = value; }
8927 get { return style.isDocument; }
8930 property bool mergeMenus
8932 property_category $"Window Style"
8933 set { mergeMenus = value; }
8934 get { return (bool)mergeMenus; }
8937 property bool hasHorzScroll
8939 property_category $"Window Style"
8944 if(!style.hasHorzScroll && created)
8946 CreateSystemChildren();
8947 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8950 else if(style.hasHorzScroll)
8954 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8956 style.hasHorzScroll = value;
8959 get { return style.hasHorzScroll; }
8962 property bool hasVertScroll
8964 property_category $"Window Style"
8969 if(!style.hasVertScroll && created)
8971 style.hasVertScroll = true;
8972 CreateSystemChildren();
8973 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8976 else if(style.hasVertScroll)
8980 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8982 style.hasVertScroll = value;
8984 get { return style.hasVertScroll; }
8987 property bool dontHideScroll
8989 property_category $"Behavior"
8992 scrollFlags.dontHide = value;
8995 //UpdateScrollBars(true, true);
8996 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9000 // UpdateScrollBars(true, true);
9001 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9004 get { return scrollFlags.dontHide; }
9007 property bool dontScrollVert
9009 property_category $"Behavior"
9010 set { style.dontScrollVert = value; }
9011 get { return style.dontScrollVert; }
9013 property bool dontScrollHorz
9015 property_category $"Behavior"
9016 set { style.dontScrollHorz = value; }
9017 get { return style.dontScrollHorz; }
9020 property bool snapVertScroll
9022 property_category $"Behavior"
9025 scrollFlags.snapY = value;
9026 if(sbv) sbv.snap = value;
9028 get { return scrollFlags.snapY; }
9030 property bool snapHorzScroll
9032 property_category $"Behavior"
9035 scrollFlags.snapX = value;
9036 if(sbh) sbh.snap = value;
9038 get { return scrollFlags.snapX; }
9041 property Point scroll
9043 property_category $"Behavior"
9047 // TESTING THIS IMPLEMENTATION:
9048 SetScrollPosition(value.x, value.y);
9050 get { value = scroll; }
9053 property bool modifyVirtualArea
9055 property_category $"Behavior"
9056 set { modifyVirtArea = value; }
9057 get { return (bool)modifyVirtArea; }
9060 property char * fileName
9062 property_category $"Document"
9065 if(menu && ((!fileName && value) || (fileName && !value)))
9067 MenuItem item = menu.FindItem(MenuFileSave, 0);
9068 if(item) item.disabled = !modifiedDocument && value;
9073 if(value && value[0])
9074 fileName = CopyString(value);
9076 if(parent && this == parent.activeClient)
9077 parent.UpdateActiveDocument(null);
9081 // if(style.isDocument)
9083 fileMonitor.fileName = value;
9085 get { return fileName; }
9090 property_category $"Data"
9095 property bool modifiedDocument
9097 property_category $"Document"
9100 if(style.isDocument || fileName)
9104 MenuItem item = menu.FindItem(MenuFileSave, 0);
9105 if(item) item.disabled = !value && fileName;
9109 if(modifiedDocument != value)
9111 modifiedDocument = value;
9112 if(style.isDocument || fileName)
9116 get { return (bool)modifiedDocument; }
9119 property bool showInTaskBar
9121 property_category $"Window Style"
9122 set { style.showInTaskBar = value; }
9123 get { return (style.showInTaskBar; }
9125 property FileDialog saveDialog { set { saveDialog = value; } };
9126 property bool isActiveClient
9128 property_category $"Behavior"
9129 set { style.isActiveClient = value; }
9130 get { return style.isActiveClient; }
9133 property Cursor cursor
9135 property_category $"Appearance"
9139 SelectMouseCursor();
9141 get { return cursor; }
9144 //#if !defined(ECERE_VANILLA)
9145 property char * name
9147 property_category $"Design"
9150 return (this && object) ? object.name : null;
9155 activeDesigner.RenameObject(object, value);
9159 property char * displayDriver
9161 property_category $"Behavior"
9164 dispDriver = GetDisplayDriver(value);
9165 //DisplayModeChanged();
9169 return dispDriver ? dispDriver.name : null;
9173 // RUNTIME PROPERTIES
9174 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9175 property Size scrollArea
9177 property_category $"Behavior"
9181 SetScrollArea(value.w, value.h, false);
9183 SetScrollArea(0,0, true);
9185 get { value = scrollArea; }
9188 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9193 property_category $"Layout"
9194 set { if(this) is3D = value; }
9195 get { return (bool)is3D; }
9198 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9200 // Will be merged with font later
9201 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9202 property Point clientStart { get { value = clientStart; } };
9203 property Point absPosition { get { value = absPosition; } };
9204 property Anchor normalAnchor { get {value = normalAnchor; } };
9205 // property Size normalSizeAnchor { get { value = normalSizeAnchor; } };
9206 property bool active { get { return (bool)active; } };
9207 property bool created { get { return (bool)created; } };
9208 property bool destroyed { get { return (bool)destroyed; } };
9209 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9210 property Window firstChild { get { return children.first; } };
9211 property Window lastChild { get { return children.last; } };
9212 property Window activeClient { get { return activeClient; } };
9213 property Window activeChild { get { return activeChild; } };
9214 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9215 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9216 property ScrollBar horzScroll { get { return sbh; } };
9217 property ScrollBar vertScroll { get { return sbv; } };
9218 property StatusBar statusBar { get { return statusBar; } };
9219 property Window rootWindow { get { return rootWindow; } };
9220 property bool closing { get { return (bool)closing; } set { closing = value; } };
9221 property int documentID { get { return documentID; } };
9222 property Window previous { get { return prev; } }
9223 property Window next { get { return next; } }
9224 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9225 property PopupMenu menuBar { get { return menuBar; } }
9226 property ScrollBar sbv { get { return sbv; } }
9227 property ScrollBar sbh { get { return sbh; } }
9228 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9229 property void * systemHandle { get { return windowHandle; } }
9230 property Button minimizeButton { get { return sysButtons[0]; } };
9231 property Button maximizeButton { get { return sysButtons[1]; } };
9232 property Button closeButton { get { return sysButtons[2]; } };
9233 property BitmapResource icon
9235 get { return icon; }
9239 if(icon) incref icon;
9241 guiApp.interfaceDriver.SetIcon(this, value);
9244 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9245 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } };
9246 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9247 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9248 property bool nativeDecorations
9250 get { return (bool)nativeDecorations; }
9251 set { nativeDecorations = value; }
9252 #ifndef ECERE_VANILLA
9253 isset { return (nativeDecorations && (rootWindow == this || (formDesigner && activeDesigner && ((FormDesigner)activeDesigner.classDesigner).form && parent == ((FormDesigner)activeDesigner.classDesigner).form.parent))) != style.fixed; }
9256 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9258 property char * text
9260 property_category $"Deprecated"
9262 set { property::caption = value; }
9263 get { return property::caption; }
9269 WindowBits style; // Window Style
9270 char * caption; // Name / Caption
9271 Window parent; // Parent window
9272 OldList children; // List of children in Z order
9273 Window activeChild; // Child window having focus
9274 Window activeClient;
9275 Window previousActive; // Child active prior to activating the default child
9276 Window master; // Window owning and receiving notifications concerning this window
9277 OldList slaves; // List of windows belonging to this window
9278 Display display; // Display this window is drawn into
9280 Point position; // Position in parent window client area
9281 Point absPosition; // Absolute position
9282 Point clientStart; // Client area position from (0,0) in this window
9284 Size clientSize; // Client area size
9285 Size scrollArea; // Virtual Scroll area size
9286 Size reqScrollArea; // Requested virtual area size
9287 Point scroll; // Virtual area scrolling position
9288 public ScrollBar sbh, sbv; // Scrollbar window handles
9289 Cursor cursor; // Mouse cursor used for this window
9292 StatusBar statusBar;
9293 Button sysButtons[3];
9295 Box clientArea; // Client Area box clipped to parent
9297 HotKeySlot hotKey; // HotKey for this window
9301 ScrollFlags scrollFlags;// Window Scrollbar Flags
9302 int id; // Control ID
9304 ColorAlpha background; // Background color used to draw the window area
9306 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9307 OldList childrenCycle; // Cycling order
9308 OldLink cycle; // Element of parent's cycling order
9309 OldList childrenOrder; // Circular Z-Order
9310 OldLink order; // Element of parent's circular Z-Order
9311 Window modalSlave; // Slave window blocking this window's interaction
9313 Window rootWindow; // Topmost system managed window
9314 void * windowHandle; // System window handle
9316 DialogResult returnCode;// Return code for modal windows
9318 Point sbStep; // Scrollbar line scrolling steps
9321 SizeAnchor stateSizeAnchor;
9323 Anchor normalAnchor;
9324 SizeAnchor normalSizeAnchor;
9326 Size skinMinSize; // Minimal window size based on style
9327 Point scrolledPos; // Scrolled position
9328 Box box; // Window box clipped to parent
9329 Box * against; // What to clip the box to
9331 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9332 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9333 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9334 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9335 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9336 Point scrolledArea; // Distance to scroll area by
9337 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9339 OldList hotKeys; // List of the hotkeys of all children
9340 Window defaultControl; // Default child control
9344 ColorAlpha * palette; // Color palette used for this window
9346 int caretSize; // Size of caret, non zero if a caret is present
9347 Point caretPos; // Caret position
9349 void * systemParent; // Parent System Window for embedded windows
9356 WindowState lastState;
9358 FileMonitor fileMonitor
9360 this, FileChange { modified = true };
9362 bool OnFileNotify(FileChange action, char * param)
9365 fileMonitor.StopMonitoring();
9366 if(OnFileModified(action, param))
9367 fileMonitor.StartMonitoring();
9372 FontResource setFont, systemFont;
9373 FontResource usedFont;
9374 FontResource captionFont;
9376 FileDialog saveDialog;
9378 SizeAnchor sizeAnchor;
9380 // FormDesigner data
9383 Extent * tempExtents; //[4];
9384 BitmapResource icon;
9386 CreationActivationOption creationActivation;
9389 bool active:1; // true if window and ancestors are active
9390 bool acquiredInput:1; // true if the window is processing state based input
9391 bool modifiedDocument:1;
9392 bool disabled:1; // true if window cannot interact
9393 bool isForegroundWindow:1;// true while a root window is being activated
9394 bool visible:1; // Visibility flag
9395 bool destroyed:1; // true if window is being destroyed
9396 bool anchored:1; // true if this window is repositioned when the parent resizes
9397 bool dirty:1; // Flag set to true if any descendant must be redrawn
9403 bool modifyVirtArea:1;
9404 bool noAutoScrollArea:1;
9407 bool setVisible:1; // FOR FORM DESIGNER
9413 bool useSharedMemory:1;
9416 bool nativeDecorations:1;
9417 bool manageDisplay:1;
9418 bool formDesigner:1; // True if we this is running in the form editor
9421 // Checks used internally for them not to take effect in FormDesigner
9422 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9423 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9425 WindowController controller;
9426 public property WindowController controller { get { return controller; } set { delete controller; controller = value; if(controller) incref controller; } }
9429 public class CommonControl : Window
9431 // creationActivation = doNothing;
9434 public property String toolTip
9436 property_category $"Appearance"
9439 if(created) CommonControl::OnDestroy();
9441 toolTip = value ? ToolTip { tip = value; } : null;
9443 if(created) CommonControl::OnCreate();
9445 get { return toolTip ? toolTip.tip : null; }
9451 // (Very) Ugly work around for the fact that the parent watcher
9452 // won't fire when it's already been disconnected...
9453 eInstance_FireSelfWatchers(toolTip,
9454 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
9460 toolTip.parent = this;
9469 public class Percentage : float
9471 char * OnGetString(char * string, float * fieldData, bool * needClass)
9475 sprintf(string, "%.2f", this);
9476 c = strlen(string)-1;
9479 if(string[c] != '0')
9480 last = Max(last, c);
9481 if(string[c] == '.')
9494 public void ApplySkin(Class c, char * name, void ** vTbl)
9496 char className[1024];
9501 subclass(Window) wc = (subclass(Window))c;
9502 subclass(Window) base = (subclass(Window))c.base;
9504 sprintf(className, "%sSkin_%s", name, c.name);
9505 wc.pureVTbl = c._vTbl;
9506 c._vTbl = new void *[c.vTblSize];
9507 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9508 sc = eSystem_FindClass(c.module.application, className);
9512 for(m = 0; m < c.base.vTblSize; m++)
9514 if(c._vTbl[m] == base.pureVTbl[m])
9515 c._vTbl[m] = vTbl[m];
9520 for(m = 0; m < c.vTblSize; m++)
9522 if(sc._vTbl[m] != wc.pureVTbl[m])
9523 c._vTbl[m] = sc._vTbl[m];
9527 for(d = c.derivatives.first; d; d = d.next)
9529 ApplySkin(d.data, name, c._vTbl);
9533 public void UnapplySkin(Class c)
9535 char className[1024];
9537 subclass(Window) wc = (subclass(Window))c;
9538 subclass(Window) base = (subclass(Window))c.base;
9541 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9544 c._vTbl = wc.pureVTbl;
9548 for(d = c.derivatives.first; d; d = d.next)
9550 UnapplySkin(d.data);
9554 void CheckFontIntegrity(Window window)
9559 if(window.usedFont && window.usedFont.font == 0xecececec)
9561 FontResource uf = window.usedFont;
9562 char * className = window._class.name;
9563 char * text = window.text;
9566 for(c = window.firstChild; c; c = c.next)
9567 CheckFontIntegrity(c);
9571 public class ControllableWindow : Window
9573 /*WindowController controller;
9574 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9575 ~ControllableWindow() { delete controller; }*/
9578 class WindowControllerInterface : ControllableWindow
9580 bool OnKeyDown(Key key, unichar ch)
9582 bool result = ((int(*)())(void *)controller.OnKeyDown)((void *)controller.controlled, (void *)controller, key, ch);
9584 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown](controller.window, key, ch);
9588 bool OnKeyUp(Key key, unichar ch)
9590 bool result = ((int(*)())(void *)controller.OnKeyUp)((void *)controller.controlled, (void *)controller, key, ch);
9592 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp](controller.window, key, ch);
9596 bool OnKeyHit(Key key, unichar ch)
9598 bool result = ((int(*)())(void *)controller.OnKeyHit)((void *)controller.controlled, (void *)controller, key, ch);
9600 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit](controller.window, key, ch);
9604 bool OnMouseMove(int x, int y, Modifiers mods)
9606 bool result = ((int(*)())(void *)controller.OnMouseMove)((void *)controller.controlled, (void *)controller, x, y, mods);
9608 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove](controller.window, x, y, mods);
9612 bool OnLeftButtonDown(int x, int y, Modifiers mods)
9614 bool result = ((int(*)())(void *)controller.OnLeftButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9616 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown](controller.window, x, y, mods);
9620 bool OnLeftButtonUp(int x, int y, Modifiers mods)
9622 bool result = ((int(*)())(void *)controller.OnLeftButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9624 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp](controller.window, x, y, mods);
9628 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
9630 bool result = ((int(*)())(void *)controller.OnLeftDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9632 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick](controller.window, x, y, mods);
9636 bool OnRightButtonDown(int x, int y, Modifiers mods)
9638 bool result = ((int(*)())(void *)controller.OnRightButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9640 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown](controller.window, x, y, mods);
9644 bool OnRightButtonUp(int x, int y, Modifiers mods)
9646 bool result = ((int(*)())(void *)controller.OnRightButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9648 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp](controller.window, x, y, mods);
9652 bool OnRightDoubleClick(int x, int y, Modifiers mods)
9654 bool result = ((int(*)())(void *)controller.OnRightDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9656 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick](controller.window, x, y, mods);
9660 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
9662 bool result = ((int(*)())(void *)controller.OnMiddleButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9664 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown](controller.window, x, y, mods);
9668 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
9670 bool result = ((int(*)())(void *)controller.OnMiddleButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9672 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp](controller.window, x, y, mods);
9676 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
9678 bool result = ((int(*)())(void *)controller.OnMiddleDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9680 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick](controller.window, x, y, mods);
9684 void OnResize(int width, int height)
9686 ((int(*)())(void *)controller.OnResize)((void *)controller.controlled, (void *)controller, width, height);
9687 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize](controller.window, width, height);
9690 void OnRedraw(Surface surface)
9692 ((int(*)())(void *)controller.OnRedraw)((void *)controller.controlled, (void *)controller, surface);
9693 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw](controller.window, surface);
9698 bool result = ((int(*)())(void *)controller.OnCreate)((void *)controller.controlled, (void *)controller);
9700 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
9705 public class WindowController<class V>
9708 property Window window
9712 uint size = class(Window).vTblSize;
9715 windowVTbl = new void *[size];
9716 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
9717 if(value._vTbl == value._class._vTbl)
9719 value._vTbl = new void *[value._class.vTblSize];
9720 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
9724 for(c = 0; c < size; c++)
9726 void * function = class(WindowControllerInterface)._vTbl[c];
9727 if(function != DefaultFunction)
9728 value._vTbl[c] = function;
9730 value._vTbl[c] = windowVTbl[c];
9735 memcpy(value._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
9738 get { return window; }
9740 property V controlled
9742 set { controlled = value; }
9743 get { return controlled; }
9745 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
9746 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
9747 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
9748 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
9749 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
9750 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
9751 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9752 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
9753 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
9754 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9755 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
9756 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
9757 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9758 virtual void V::OnResize(WindowController controller, int width, int height);
9759 virtual void V::OnRedraw(WindowController controller, Surface surface);
9760 virtual bool V::OnCreate(WindowController controller);
9763 int (** windowVTbl)();