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 && rootWindow.windowHandle)
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 && rootWindow.windowHandle)
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 && windowHandle && 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 && rootWindow.windowHandle)
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);
1704 if(windowResized || windowMoved)
1705 if(display && !display.flags.memBackBuffer && changeRootWindow)
1706 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1708 if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved))
1709 for(child = parent.children.first; child && child != this; child = child.next)
1710 if(child.rootWindow)
1711 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1716 if(windowMoved || windowResized)
1718 display.Lock(true /*false*/);
1721 display.Position(absPosition.x, absPosition.y);
1722 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1725 // result = realResized ? display.Resize(size.w, size.h) : true;
1726 if(nativeDecorations && rootWindow.windowHandle)
1728 int w = clientSize.w, h = clientSize.h;
1729 if(hasMenuBar) h += skinMenuHeight;
1730 if(hasStatusBar) h += statusBarHeight;
1731 if(sbv && sbv.visible) w += sbv.size.w;
1732 if(sbh && sbh.visible) h += sbh.size.h;
1733 result = manageDisplay ? display.Resize(w, h) : true;
1736 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1740 else if(clientResized)
1742 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1745 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1749 if(windowMoved || windowResized)
1754 if(guiApp.driver && changeRootWindow && windowHandle)
1756 if(windowResized || windowMoved)
1757 if(!display || display.flags.memBackBuffer)
1758 guiApp.interfaceDriver.PositionRootWindow(this,
1759 x, y, w, h, windowMoved, windowResized);
1760 guiApp.interfaceDriver.UpdateRootWindow(this);
1762 for(child = children.first; child; child = child.next)
1764 if(child.is3D && child.created)
1766 // Copy Display Content
1767 child.display.displaySystem = display.displaySystem;
1768 child.display.window = display.window;
1769 child.display.current = display.current;
1770 child.display.width = display.width;
1771 child.display.height = display.height;
1772 child.display.driverData = display.driverData;
1773 child.display.mutex = null;
1784 void UpdateScrollBars(bool flag, bool fullThing)
1787 bool resizeH = false, resizeV = false;
1788 bool scrolled = false;
1789 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1790 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1792 if(destroyed) return;
1793 if(guiApp.currentSkin)
1795 MinMaxValue cw = 0, ch = 0;
1796 bool sbvVisible, sbhVisible;
1798 int positionH, positionV;
1800 // First get client area with no respect to scroll bars
1805 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1807 if(scrollFlags.dontHide)
1810 cw -= guiApp.currentSkin.VerticalSBW();
1812 ch -= guiApp.currentSkin.HorizontalSBH();
1814 // Update the scrollbar visibility
1820 sbh.disabled = rangeH <= 1;
1821 if(sbh.style.hidden)
1831 sbv.disabled = rangeV <= 1;
1832 if(sbv.style.hidden)
1840 int oldHRange = sbh ? sbh.range : 0;
1841 int oldVRange = sbv ? sbv.range : 0;
1842 // Then start off with horizontal scrollbar range
1845 positionH = sbh.thumbPosition;
1852 SBSetTotal(sbh, rvw);
1855 ch -= guiApp.currentSkin.HorizontalSBH();
1858 // Do the same for vertical scrollbar
1861 positionV = sbv.thumbPosition;
1867 SBSetTotal(sbv, rvh);
1871 cw -= guiApp.currentSkin.VerticalSBW();
1872 // Maybe we need to set the range on the horizontal scrollbar again
1880 SBSetTotal(sbh, rvw);
1881 //sbh.Action(setRange, positionH, 0);
1882 if(rangeH <= 1 && sbh.range > 1)
1884 ch -= guiApp.currentSkin.HorizontalSBH();
1890 SBSetTotal(sbv, rvh);
1892 //sbv.Action(setRange, positionV, 0);
1897 if(sbh && sbh.range != oldHRange) sbh.Action(setRange, positionH, 0);
1898 if(sbv && sbv.range != oldVRange) sbv.Action(setRange, positionV, 0);
1901 // Update the scrollbar visibility
1902 if(!scrollFlags.dontHide)
1904 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
1908 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
1915 if(guiApp.currentSkin)
1922 sbhVisible = sbh.style.hidden ? true : false;
1924 sbvVisible = sbv.style.hidden ? true : false;
1926 // Do our resize here
1927 if(flag && (resizeH || resizeV) && fullThing)
1929 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
1934 OnResize(clientSize.w, clientSize.h);
1940 sbh.visible = sbhVisible;
1942 sbv.visible = sbvVisible;
1944 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1945 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1948 sbh.pageStep = clientSize.w;
1950 sbv.pageStep = clientSize.h;
1952 // Notify doesn't handle setRange anymore... process it here
1955 int positionH = sbh.thumbPosition;
1956 if(scroll.x != positionH)
1958 OnHScroll(setRange, positionH, 0);
1962 SNAPDOWN(positionH, textCellW);
1963 scroll.x = positionH;
1969 int seen = clientSize.w, total = reqScrollArea.w;
1972 if(scrollFlags.snapX)
1973 SNAPDOWN(seen, sbStep.x);
1975 if(!total) total = seen;
1976 range = total - seen + 1;
1978 range = Max(range, 1);
1980 if(x >= range) x = range - 1;
1982 if(scrollFlags.snapX)
1983 SNAPUP(x, sbStep.x);
1987 OnHScroll(setRange, x, 0);
1992 SNAPDOWN(x, textCellW);
1998 int positionV = sbv.thumbPosition;
1999 if(scroll.y != positionV)
2001 OnVScroll(setRange, positionV, 0);
2005 SNAPDOWN(positionV, textCellH);
2006 scroll.y = positionV;
2012 int seen = clientSize.h, total = reqScrollArea.h;
2015 if(scrollFlags.snapY)
2016 SNAPDOWN(seen, sbStep.y);
2018 if(!total) total = seen;
2019 range = total - seen + 1;
2020 range = Max(range, 1);
2022 if(y >= range) y = range - 1;
2024 if(scrollFlags.snapY)
2025 SNAPUP(y, sbStep.y);
2029 OnVScroll(setRange, y, 0);
2034 SNAPDOWN(y, textCellH);
2040 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2043 for(child = children.first; child; child = child.next)
2045 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2048 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2049 child.Position(x, y, w, h, false, true, false, true, false, false);
2056 // Process Scrollbars
2058 if(sbh) // && !sbh.style.hidden
2060 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2061 // Need to set the range again (should improve...) since the scrollbars didn't have
2062 // the right size when UpdateScrollArea set the range on it
2065 sbh.seen = clientSize.w;
2069 if(sbv) // && !sbv.state.hidden
2071 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2072 // Need to set the range again (should improve...) since the scrollbars didn't have
2073 // the right size when UpdateScrollArea set the range on it
2076 sbv.seen = clientSize.h;
2081 // TESTING THIS LOWER
2082 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2085 for(child = children.first; child; child = child.next)
2087 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2090 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2091 child.Position(x, y, w, h, false, true, false, true, false, false);
2097 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2099 SetState(maximized, false, mods);
2103 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2105 SetState(normal, false, mods);
2109 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2111 SetState(minimized, false, mods);
2112 parent.CycleChildren(false, true, false, true);
2116 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2119 // Scroll bar notifications
2120 if(action != setRange)
2122 bool changed = false;
2126 if(scroll.x != position)
2128 OnHScroll(action, position, keyFlags);
2133 SNAPDOWN(position, textCellW);
2135 scroll.x = position;
2139 if(scroll.y != position)
2141 OnVScroll(action, position, keyFlags);
2146 SNAPDOWN(position, textCellH);
2148 scroll.y = position;
2152 bool childMove = false;
2153 for(child = children.first; child; child = child.next)
2155 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2158 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2159 child.Position(x, y, w, h, false, true, false, true, false, false);
2163 // Testing this patch out to solve MDI workspace redraw bugs
2164 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2165 // Scroll offsets to blame?
2169 UpdateCaret(false, false);
2173 // Testing this patch out to solve MDI workspace redraw bugs
2174 for(child = children.first; child; child = child.next)
2176 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2185 Window GetParentMenuBar()
2187 Window menuBarParent;
2188 for(menuBarParent = this; menuBarParent; menuBarParent = menuBarParent.parent)
2190 if(menuBarParent.menuBar) break;
2191 if(menuBarParent.parent && /*menuBarParent != */!menuBarParent.parent.activeClient)
2193 menuBarParent = null;
2197 return menuBarParent ? menuBarParent.menuBar : null;
2200 void CreateSystemChildren(void)
2202 Window parent = this;
2203 bool scrollBarChanged = false;
2204 bool hasClose = false, hasMaxMin = false;
2205 Point scroll = this.scroll;
2207 if(state == maximized)
2208 parent = GetParentMenuBar();
2212 if(style.hasClose) hasClose = true;
2213 if(style.hasMaximize || style.hasMinimize)
2220 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2222 sysButtons[2].Destroy(0);
2223 sysButtons[2] = null;
2225 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2227 sysButtons[1].Destroy(0);
2228 sysButtons[1] = null;
2230 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2232 sysButtons[0].Destroy(0);
2233 sysButtons[0] = null;
2236 if(hasClose && parent)
2243 parent, master = this,
2244 inactive = true, nonClient = true, visible = false;
2246 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2252 if(this.parent == guiApp.desktop)
2253 sysButtons[2].hotKey = altF4;
2254 else if(style.isActiveClient)
2255 sysButtons[2].hotKey = ctrlF4;
2256 sysButtons[2].Create();
2259 sysButtons[2].symbol = 'X';
2260 sysButtons[2].disabled = !style.hasClose;
2263 if(hasMaxMin && parent)
2267 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2268 if(state == maximized)
2271 method = RestoreButtonClicked;
2277 method = MaximizeButtonClicked;
2285 parent, master = this,
2286 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2288 sysButtons[1].Create();
2290 sysButtons[1].NotifyClicked = method;
2292 sysButtons[1].symbol = symbol;
2293 sysButtons[1].disabled = !style.hasMaximize;
2296 if(hasMaxMin && parent)
2300 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2301 if (state == minimized)
2304 method = RestoreButtonClicked;
2310 method = MinimizeButtonClicked;
2318 parent, master = this,
2319 hotKey = altM, inactive = true, nonClient = true, visible = false
2321 sysButtons[0].Create();
2323 sysButtons[0].NotifyClicked = method;
2325 sysButtons[0].symbol = symbol;
2326 sysButtons[0].disabled = !style.hasMinimize;
2329 // Create the scrollbars
2330 if(style.hasHorzScroll && !sbh)
2336 direction = horizontal,
2340 snap = scrollFlags.snapX,
2341 NotifyScrolling = ScrollBarNotification
2344 scrollBarChanged = true;
2346 else if(sbh && !style.hasHorzScroll)
2352 if(style.hasVertScroll && !sbv)
2358 direction = vertical,
2362 snap = scrollFlags.snapY,
2363 NotifyScrolling = ScrollBarNotification
2366 scrollBarChanged = true;
2368 else if(sbv && !style.hasVertScroll)
2373 if(scrollBarChanged)
2375 SetScrollLineStep(sbStep.x, sbStep.y);
2376 UpdateScrollBars(true, true);
2380 if(scrollBarChanged)
2382 if(sbh) sbh.thumbPosition = scroll.x;
2383 if(sbv) sbv.thumbPosition = scroll.y;
2387 void UpdateCaption(void)
2389 if(rootWindow == this)
2392 FigureCaption(caption);
2393 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2395 UpdateDecorations();
2398 if(parent.activeClient == this) // Added this last check
2400 if(parent.rootWindow == parent)
2403 parent.FigureCaption(caption);
2404 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2407 parent.UpdateCaption();
2409 parent.UpdateDecorations();
2413 void UpdateActiveDocument(Window previous)
2415 Window activeClient = this.activeClient;
2416 Window activeChild = this.activeChild;
2423 activeClient.CreateSystemChildren();
2425 previous.CreateSystemChildren();
2437 // Build window list
2440 Menu windowMenu = menu.FindMenu("Window");
2445 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2448 Window document = cycle.data;
2449 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2451 char name[2048], caption[2048];
2452 document.FigureCaption(caption);
2453 sprintf(name, "%d %s", id+1, caption);
2454 windowMenu.AddDynamic(MenuItem
2456 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2457 NotifySelect = MenuWindowSelectWindow
2461 if(activeClient.cycle == cycle) break;
2466 if((!previous && activeClient) || !activeClient)
2472 item = menu.FindItem(MenuWindowCloseAll, 0);
2473 if(item) item.disabled = false;
2474 item = menu.FindItem(MenuWindowNext, 0);
2475 if(item) item.disabled = false;
2476 item = menu.FindItem(MenuWindowPrevious, 0);
2477 if(item) item.disabled = false;
2478 item = menu.FindItem(MenuWindowCascade, 0);
2479 if(item) item.disabled = false;
2480 item = menu.FindItem(MenuWindowTileHorz, 0);
2481 if(item) item.disabled = false;
2482 item = menu.FindItem(MenuWindowTileVert, 0);
2483 if(item) item.disabled = false;
2484 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2485 if(item) item.disabled = false;
2486 item = menu.FindItem(MenuWindowWindows, 0);
2487 if(item) item.disabled = false;
2490 item = menu.FindItem(MenuFileClose, 0);
2491 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2492 item = menu.FindItem(MenuFileSaveAll, 0);
2493 if(item) item.disabled = numDocuments < 1;
2495 if(activeClient && activeClient.menu && activeClient.state != minimized)
2499 //activeClient.menu.Clean(activeClient);
2500 menu.Merge(activeClient.menu, true, activeClient);
2504 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2507 menu.Merge(activeChild.menu, true, activeChild);
2510 // This is called again for a child window change, with same active client
2511 OnActivateClient(activeClient, previous);
2512 if(!menuBar && !((BorderBits)borderStyle).fixed && parent && parent.activeClient == this)
2513 parent.UpdateActiveDocument(null);
2516 void _ShowDecorations(Box box, bool post)
2518 if(rootWindow == this && nativeDecorations) return;
2519 if(visible && this != guiApp.desktop)
2521 Surface surface = RedrawFull(box);
2525 FigureCaption(caption);
2528 ShowDecorations(captionFont.font,
2531 active, //parent.activeClient == this
2532 guiApp.windowMoving == this);
2534 PreShowDecorations(captionFont.font,
2537 active, //parent.activeClient == this
2538 guiApp.windowMoving == this);
2545 void UpdateExtent(Box refresh)
2547 Surface surface = null;
2549 if(!manageDisplay) { OnRedraw(null);return; }
2550 _ShowDecorations(refresh, false);
2552 surface = Redraw(refresh);
2553 // Opaque background: just fill before EW_REDRAW (clear?)
2556 surface.SetBackground(background);
2557 surface.SetForeground(foreground);
2558 surface.DrawingChar(' ');
2559 if(this == rootWindow)
2561 if(style.drawBehind || background.a)
2563 int a = background.a;
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);
2570 else if(background.a)
2574 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2575 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2578 if(display.flags.alpha && background.a < 255 && background)
2580 surface.Area(0,0,clientSize.w, clientSize.h);
2581 /*if(style.clearDepthBuffer)
2582 surface.Clear(depthBuffer);*/
2584 else if(/*style.clearDepthBuffer || */background.a)
2586 int a = background.a;
2587 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2588 // Premultiply alpha for clear color
2589 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2590 surface.Clear(colorBuffer);
2591 surface.SetBackground(background);
2596 surface.TextFont(usedFont.font);
2597 surface.TextOpacity(false);
2601 // Draw the caret ...
2602 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2604 // surface.SetBackground(0xFFFFFF - background.color);
2605 surface.SetBackground(~background.color);
2607 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2608 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2614 void DrawOverChildren(Box refresh)
2616 Surface surface = Redraw(refresh);
2620 surface.DrawingChar(' ');
2621 surface.SetBackground(background);
2622 surface.SetForeground(foreground);
2624 surface.TextFont(usedFont.font);
2625 surface.TextOpacity(false);
2627 OnDrawOverChildren(surface);
2632 _ShowDecorations(refresh, true);
2635 void ComputeClipExtents(void)
2638 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2640 clipExtent.Copy(this.clipExtent);
2642 for(child = children.last; child; child = child.prev)
2644 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2646 bool opaque = child.IsOpaque(); // TODO: acess background directly
2647 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2649 child.clipExtent.Copy(clipExtent);
2650 child.clipExtent.Offset(-dx, -dy);
2651 child.clipExtent.IntersectBox(child.box);
2653 child.ComputeClipExtents();
2655 if(opaque && !child.style.nonClient)
2657 // Adjust the box for the parent:
2658 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2659 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2664 // ??? Only do this for overlapped window or if parent has with clip children flag
2666 // Do this if window has clip children flag on (default false?)
2667 // this.clipExtent = clipExtent;
2669 clipExtent.Free(null);
2672 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2674 bool opaque = IsOpaque();
2676 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2677 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2679 offsetX -= rootWindow.clientStart.x;
2680 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2684 for(child = children.last; child; child = child.prev)
2686 ColorAlpha background = *(ColorAlpha *)&child.background;
2687 bool opaque = child.IsOpaque();
2688 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2692 // Adjust renderArea to the root window level
2693 Extent * renderArea = &rootWindow.tempExtents[1];
2695 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2696 if(child.rootWindow.nativeDecorations && rootWindow.windowHandle)
2698 offsetX -= child.rootWindow.clientStart.x;
2699 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2703 Extent childRenderArea;
2705 if(backBufferUpdate != null)
2707 childRenderArea.Copy(backBufferUpdate);
2708 childRenderArea.Offset(-offsetX, -offsetY);
2711 childRenderArea.Copy(child.dirtyArea);
2713 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2714 renderArea.Copy(dirtyExtent);
2715 renderArea.Offset(-offsetX, -offsetY);
2716 childRenderArea.Union(renderArea);
2719 // Intersect with the clip extent
2720 childRenderArea.Intersection(child.clipExtent);
2723 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2724 renderArea->Offset(offsetX, offsetY);
2725 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2726 // overDirtyExtent.Union(renderArea);
2727 renderArea->Empty();
2728 // childRenderArea.Free();
2730 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2735 for(child = children.last; child; child = child.prev)
2737 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2739 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2744 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2746 bool opaque = IsOpaque();
2747 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2749 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2750 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2752 offsetX -= rootWindow.clientStart.x;
2753 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2757 for(child = children.last; child; child = child.prev)
2759 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2761 ColorAlpha background = *(ColorAlpha *)&child.background;
2762 bool opaque = child.IsOpaque();
2763 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2767 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2768 // Adjust renderArea to the root window level
2770 renderArea.Copy(child.dirtyArea);
2771 renderArea.Offset(offsetX, offsetY);
2772 dirtyExtent.Union(renderArea);
2773 overDirtyExtent.Union(renderArea);
2779 for(child = children.last; child; child = child.prev)
2781 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2783 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2787 if(backBufferUpdate != null)
2789 renderArea.Copy(backBufferUpdate);
2790 renderArea.Offset(-offsetX, -offsetY);
2792 overRenderArea.Copy(backBufferUpdate);
2793 overRenderArea.Offset(-offsetX, -offsetY);
2799 renderArea.Copy(dirtyArea);
2801 overRenderArea.Copy(dirtyArea);
2804 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2805 dirtyExtentWindow->Copy(dirtyExtent);
2806 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2807 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2808 dirtyExtentWindow->Empty();
2810 // Intersect with the clip extent
2811 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2814 if(renderArea.count > 10)
2817 printf("\nToo many extents (%d):\n", renderArea.count);
2819 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2820 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2825 for(c = 0; c<10; c++)
2828 FASTLIST_LOOP(renderArea, extentBox)
2830 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2832 renderArea.Copy(extent);
2834 FASTLIST_LOOP(renderArea, extentBox)
2837 printf("(%d, %d) - (%d, %d)\n",
2838 extentBox.box.left, extentBox.box.top,
2839 extentBox.box.right, extentBox.box.bottom);
2843 printf("\nNow %d\n", renderArea.count);
2849 // WHY WAS THIS COMMENTED ??
2851 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2852 dirtyExtentWindow->Copy(overDirtyExtent);
2853 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2854 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2855 dirtyExtentWindow->Empty();
2857 // Intersect with the clip extent
2858 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2864 if(scrollExtent.count)
2866 // Subtract render extent from scrolling extent
2867 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
2869 if(backBufferUpdate == null)
2871 Extent * dirty = &rootWindow.tempExtents[3];
2874 // Intersect scrolling extent with clip extent
2875 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2877 // offset this scroll to be at the root window level
2878 scrollExtent.Offset(offsetX, offsetY);
2879 // Add area that was scrolled to the dirty extents of the back buffer
2880 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
2884 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
2885 for(scrollBox = (BoxItem)scrollExtent.first; scrollBox; scrollBox = (BoxItem)scrollBox.next)
2886 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
2891 scrollExtent.Empty();
2893 // Add the exposed extent to the window render area
2894 dirty->Offset(-offsetX, -offsetY);
2895 renderArea.Union(dirty, rootWindow.tempExtents[0]);
2900 // Subtract the window's box from the transparency forced extent
2901 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
2907 renderArea.Copy(this.renderArea);
2908 renderArea.Offset(offsetX, offsetY);
2909 dirtyExtent.Union(renderArea);
2915 Extent renderArea { };
2917 renderArea.Copy(overRenderArea);
2918 renderArea.Offset(offsetX, offsetY);
2919 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2924 if(backBufferUpdate != null)
2926 // Remove render area from dirty area
2927 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
2929 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
2936 // Remove the window render area from the dirty extents of the back buffer
2937 rootWindow.dirtyBack.Exclusion(renderArea);
2941 void Render(Extent updateExtent)
2945 Window rootWindow = this.rootWindow;
2946 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2947 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2949 offsetX -= rootWindow.clientStart.x;
2950 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2953 if(rootWindow.fullRender)
2962 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2963 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
2968 /*if(renderArea.count)
2969 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
2972 for(extentBox = (BoxItem)renderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2974 Box box = extentBox.box;
2977 /*printf("(%d, %d) - (%d, %d)\n",
2978 extentBox.box.left, extentBox.box.top,
2979 extentBox.box.right, extentBox.box.bottom);*/
2984 box.left += offsetX;
2986 box.right += offsetX;
2987 box.bottom += offsetY;
2989 if(updateExtent != null)
2990 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2994 for(child = children.first; child; child = child.next)
2995 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
2996 child.Render(updateExtent);
2998 if(rootWindow.fullRender)
2999 DrawOverChildren(box);
3002 // TO DO: There's an issue about draw over children...
3003 // TO DO: Don't wanna go through this if method isn't used
3004 for(extentBox = (BoxItem)overRenderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
3005 //FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
3007 Box box = extentBox.box;
3009 DrawOverChildren(box);
3011 box.left += offsetX;
3013 box.right += offsetX;
3014 box.bottom += offsetY;
3016 if(updateExtent != null)
3017 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
3020 for(child = children.first; child; child = child.next)
3021 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
3022 child.Render(updateExtent);
3025 overRenderArea.Empty();
3028 public void UpdateDisplay(void)
3030 if(!manageDisplay) { OnRedraw(null);return; }
3031 if(rootWindow && this != rootWindow)
3032 rootWindow.UpdateDisplay();
3035 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
3036 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
3039 dirtyExtent.Clear();
3042 clipExtent.AddBox(box);
3044 display.StartUpdate();
3046 if(!rootWindow.fullRender)
3048 ComputeClipExtents();
3049 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
3050 ComputeRenderArea(dirtyExtent, overExtent, null);
3053 clipExtent.Free(null);
3055 dirtyExtent.Free(null);
3056 overExtent.Free(null);
3058 if(display.flags.flipping)
3061 display.Update(null);
3065 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
3066 updateExtent.Clear();
3068 Render(updateExtent);
3070 updateExtent.UnionBox(this.box, tempExtents[0]);
3073 //printf("\n\nUpdate:\n------------------------------------------\n");
3076 //FASTLIST_LOOP(updateExtent, extentBox)
3077 for(extentBox = (BoxItem)updateExtent.first; extentBox; extentBox = (BoxItem)extentBox.next)
3080 /*printf("Updating (%d, %d) - (%d, %d)\n",
3081 extentBox.box.left, extentBox.box.top,
3082 extentBox.box.right, extentBox.box.bottom);*/
3085 display.Update(extentBox.box);
3088 updateExtent.Free(null);
3091 display.EndUpdate();
3099 void UpdateBackDisplay(Box box)
3105 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3107 //printf("UpdateBackDisplay going through!\n");
3108 display.StartUpdate();
3112 intersection.Copy(dirtyBack);
3113 intersection.IntersectBox(box);
3115 dirtyExtent.Clear();
3118 clipExtent.AddBox(box);
3120 if(!rootWindow.fullRender)
3122 ComputeClipExtents();
3123 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3126 clipExtent.Free(null);
3128 intersection.Free(null);
3129 dirtyExtent.Free(null);
3130 overExtent.Free(null);
3135 if(display.flags.flipping)
3136 display.Update(null);
3139 rootWindow.display.Update(box);
3142 display.EndUpdate();
3146 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3147 if(dirtyBack.count > MAX_DIRTY_BACK)
3149 BoxItem extentBox, next;
3150 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3151 for(extentBox = (BoxItem)dirtyBack.first; extentBox; extentBox = next)
3153 next = (BoxItem)extentBox.next;
3154 if(extentBox != first)
3156 if(extentBox.box.left < first.box.left)
3157 first.box.left = extentBox.box.left;
3158 if(extentBox.box.top < first.box.top)
3159 first.box.top = extentBox.box.top;
3160 if(extentBox.box.right > first.box.right)
3161 first.box.right = extentBox.box.right;
3162 if(extentBox.box.bottom > first.box.bottom)
3163 first.box.bottom = extentBox.box.bottom;
3164 dirtyBack.Delete(extentBox);
3173 // --- Window positioning ---
3174 // --- Window identification ---
3176 // Returns window at position "Position"
3177 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3179 Window child, result = null;
3181 box.left += absPosition.x;
3182 box.right += absPosition.x;
3183 box.top += absPosition.y;
3184 box.bottom += absPosition.y;
3186 if(!destroyed && visible && (acceptDisabled || !disabled))
3188 int lx = x - absPosition.x;
3189 int ly = y - absPosition.y;
3190 if(IsInside(lx, ly))
3191 // if(box.IsPointInside(Point{x, y}))
3193 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3194 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3197 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3199 if(child != statusBar && child.rootWindow == rootWindow)
3201 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3208 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3210 if(child != statusBar && child.rootWindow == rootWindow)
3212 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3224 Window FindModal(void)
3226 Window modalWindow = this, check;
3227 Window check2 = null;
3228 for(check = this; check.master; check = check.master)
3230 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3232 modalWindow = check.master.modalSlave;
3233 check = modalWindow;
3235 // TESTING THIS FOR DROPBOX...
3236 if(!rootWindow || !rootWindow.style.interim)
3238 for(check2 = check; check2.activeChild; check2 = check2.activeChild)
3240 if(check2.modalSlave && check2.modalSlave.created)
3242 modalWindow = check2.modalSlave;
3250 if(modalWindow == this)
3252 for(check = this; check.activeChild; check = check.activeChild)
3254 if(check.modalSlave)
3256 modalWindow = check.modalSlave;
3262 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3263 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3266 void StopMoving(void)
3268 if(this == guiApp.windowMoving)
3270 guiApp.windowMoving = null;
3271 UpdateDecorations();
3272 SetMouseRange(null);
3275 if(rootWindow.active)
3276 guiApp.interfaceDriver.StopMoving(rootWindow);
3279 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3280 guiApp.windowIsResizing = false;
3284 void SelectMouseCursor(void)
3289 Window cursorWindow = null;
3290 bool rx, ry, rex, rey;
3292 guiApp.desktop.GetMousePosition(&x, &y);
3293 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3295 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3296 guiApp.SetCurrentCursor(guiApp.systemCursors[moving]);
3297 else if(mouseWindow)
3299 modalWindow = mouseWindow.FindModal();
3300 x -= mouseWindow.absPosition.x;
3301 y -= mouseWindow.absPosition.y;
3302 if(guiApp.windowIsResizing)
3304 rex = guiApp.resizeEndX;
3305 rey = guiApp.resizeEndY;
3306 rx = guiApp.resizeX;
3307 ry = guiApp.resizeY;
3308 if((rex && rey) || (rx && ry))
3309 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3310 else if((rex && ry) || (rx && rey))
3311 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3312 else if((ry || rey) && (!rx && !rex))
3313 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3314 else if((rx || rex) && (!ry && !rey))
3315 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3317 else if(!modalWindow && !guiApp.windowCaptured &&
3318 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3319 &rx, &ry, &rex, &rey))
3321 if((rex && rey) || (rx && ry))
3322 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3323 else if((rex && ry) || (rx && rey))
3324 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3325 else if((ry || rey) && (!rx && !rex))
3326 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3327 else if((rx || rex) && (!ry && !rey))
3328 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3330 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3332 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}))
3333 cursorWindow = mouseWindow.parent;
3335 cursorWindow = mouseWindow;
3337 else if(!guiApp.interimWindow)
3338 cursorWindow = guiApp.windowCaptured;
3341 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient; cursorWindow = cursorWindow.parent);
3342 guiApp.SetCurrentCursor(cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3344 else if(modalWindow)
3346 guiApp.SetCurrentCursor(guiApp.systemCursors[arrow]);
3348 else if(guiApp.interimWindow)
3350 if(guiApp.interimWindow.cursor)
3351 guiApp.SetCurrentCursor(guiApp.interimWindow.cursor);
3353 guiApp.SetCurrentCursor(mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3358 // --- State based input ---
3359 bool AcquireInputEx(bool state)
3364 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3365 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3367 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3369 guiApp.acquiredWindow = state ? this : null;
3372 SetMouseRangeToClient();
3373 guiApp.interfaceDriver.SetMouseCursor((SystemCursor)-1);
3378 SelectMouseCursor();
3380 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3384 // --- Window activation ---
3385 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3388 if(!parent || !parent.style.inactive)
3390 Window parent = this.parent;
3393 if(rootWindow == this)
3394 Log(active ? "active\n" : "inactive\n");
3397 // Testing this here...
3398 if(!parent || parent == guiApp.desktop || parent.active)
3400 this.active = active;
3403 // TESTING THIS HERE
3404 UpdateDecorations();
3405 if(result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master)
3406 result = NotifyActivate(master, this, active, previous);
3409 this.active = !active;
3414 if(!parent || parent == guiApp.desktop || parent.active)
3416 this.active = active;
3418 AcquireInputEx(active);
3423 if(guiApp.caretOwner)
3427 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3428 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3429 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3430 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3432 guiApp.caretOwner.Update(extent);
3435 if(visible || !guiApp.caretOwner)
3436 guiApp.caretOwner = this;
3437 UpdateCaret(false, false);
3443 this.active = false;
3445 AcquireInputEx(active);
3447 if(!active && guiApp.caretOwner == this)
3449 UpdateCaret(false, true);
3450 guiApp.caretOwner = null;
3451 guiApp.interfaceDriver.SetCaret(0,0,0);
3452 guiApp.caretEnabled = false;
3457 if(!active && parent && parent.activeChild && parent.activeChild != this)
3458 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3464 if(!active && menuBar)
3467 menuBar.OnActivate(false, null, &goOn, true);
3468 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3473 Window aChild = activeChild;
3475 if(!aChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3487 void ConsequentialMouseMove(bool kbMoving)
3491 if(kbMoving || !guiApp.windowMoving)
3495 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3497 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3499 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3500 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3506 bool IsDescendantOf(Window ancestor)
3509 for(window = this; window && window != ancestor; window = window.parent);
3510 return window == ancestor;
3513 bool IsSlaveOf(Window master)
3516 for(window = this; window && window != master; window = window.master);
3517 return window == master;
3520 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3524 if(this && !destroyed /*&& state != Hidden*/)
3526 Window swap = externalSwap;
3534 if(activateParent &&
3535 (parent.activeChild != this ||
3536 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3537 active && _isModal &&
3538 parent != master && master)
3539 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3545 bool real = parent.activeChild != this;
3547 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3548 if(!style.inactive && /*activateParent && */guiApp.interimWindow &&
3549 !IsDescendantOf(guiApp.interimWindow) &&
3550 !IsSlaveOf(guiApp.interimWindow))
3552 Window interimWindow = guiApp.interimWindow;
3553 while(interimWindow && interimWindow != this)
3555 Window master = interimWindow.master;
3557 guiApp.interimWindow = null;
3558 if(guiApp.caretOwner)
3559 guiApp.caretOwner.UpdateCaret(false, false);
3561 incref interimWindow;
3562 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3567 delete interimWindow;
3568 interimWindow = (master && master.style.interim) ? master : null;
3573 guiApp.interimWindow = this;
3574 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3575 guiApp.caretEnabled = false;*/
3576 UpdateCaret(false, true);
3581 bool acquireInput = false;
3583 parent.activeChild &&
3584 parent.activeChild.state == maximized &&
3585 parent != guiApp.desktop;
3587 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3592 swap = parent.activeChild;
3593 if(swap && swap.destroyed) swap = null;
3594 if(swap && swap != this)
3597 if(!swap.PropagateActive(false, this, &goOn, true))
3598 swap = parent.activeChild;
3609 if(!parent || parent.activeChild != this || style.interim)
3612 result = PropagateActive(true, swap, &goOn, true);
3613 if(!result && !goOn)
3618 acquireInput = true;
3622 if(style.hasMaximize && parent != guiApp.desktop)
3625 SetState(maximized, false, 0);
3626 else if(state != maximized)
3629 for(child = parent.children.first; child; child = child.next)
3631 if(this != child && child.state == maximized)
3632 child.SetState(normal, false, 0);
3639 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3641 Window previous = parent.activeClient;
3642 parent.activeChild = this;
3643 if(!style.nonClient /*&& style.isActiveClient*/)
3647 if(style.isActiveClient)
3648 parent.activeClient = this;
3649 // Moved UpdateActiveDocument inside hidden check
3650 // To prevent activating previous window while creating a new one
3651 // (It was messing up the privateModule in the CodeEditor)
3652 parent.UpdateActiveDocument(previous);
3658 //if(!style.isRemote)
3660 if(rootWindow != this)
3662 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3663 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3665 else if(!guiApp.fullScreenMode)
3667 Window modalRoot = FindModal();
3668 if(!modalRoot) modalRoot = this;
3669 if(!modalRoot.isForegroundWindow)
3671 modalRoot.isForegroundWindow = true;
3672 // To check : Why is parent null?
3673 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3675 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3677 modalRoot.isForegroundWindow = false;
3682 if(result && real && (!style.inactive || moveInactive) && parent)
3684 Window last = parent.children.last;
3686 if(!style.stayOnTop)
3687 for(; last && last.style.stayOnTop; last = last.prev);
3689 parent.children.Move(this, last);
3691 // Definitely don't want that: why not?
3695 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3701 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3708 parent.activeChild = null;
3709 if(!style.nonClient /*&& style.isActiveClient*/)
3711 Window previous = parent.activeClient;
3712 if(style.isActiveClient)
3713 parent.activeClient = null;
3714 parent.UpdateActiveDocument(previous);
3718 if(this == guiApp.interimWindow)
3720 guiApp.interimWindow = null;
3721 if(guiApp.caretOwner)
3722 guiApp.caretOwner.UpdateCaret(false, false);
3724 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3731 if(!active || !swap)
3732 UpdateDecorations();
3734 swap.UpdateDecorations();
3736 if(active && rootWindow != this)
3737 ConsequentialMouseMove(false);
3744 // --- Input Messages ---
3745 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3747 static bool reEntrancy = false;
3748 if(reEntrancy) return;
3752 guiApp.cursorUpdate = true;
3753 if(guiApp.windowScrolling && !consequential)
3755 guiApp.windowScrolling.SetScrollPosition(
3756 (guiApp.windowScrolling.sbh) ?
3757 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3758 (guiApp.windowScrolling.sbv) ?
3759 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3761 if(guiApp.windowMoving)
3763 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3765 Window window = guiApp.windowMoving;
3767 int w = window.size.w;
3768 int h = window.size.h;
3773 rx = mouseX - guiApp.windowMovingStart.x;
3774 ry = mouseY - guiApp.windowMovingStart.y;
3777 window.GetDecorationsSize(&ew, &eh);
3779 if(guiApp.windowIsResizing)
3781 x = window.scrolledPos.x;
3782 y = window.scrolledPos.y;
3786 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3787 rx = guiApp.windowResizingBefore.w - aw;
3788 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3789 w = guiApp.windowResizingBefore.w - rx;
3793 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3794 ry = guiApp.windowResizingBefore.h - ah;
3795 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3796 ry = Max(ry, -guiApp.windowMovingBefore.y);
3797 h = guiApp.windowResizingBefore.h - ry;
3799 if(guiApp.resizeEndX)
3801 w = guiApp.windowResizingBefore.w + rx;
3804 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3812 w = Max(w, window.minSize.w);
3813 h = Max(h, window.minSize.h);
3814 w = Min(w, window.maxSize.w);
3815 h = Min(h, window.maxSize.h);
3817 if(!window.OnResizing(&w, &h))
3819 w = window.clientSize.w;
3820 h = window.clientSize.h;
3823 w = Max(w, window.skinMinSize.w);
3824 h = Max(h, window.skinMinSize.h);
3831 SNAPDOWN(w, textCellW);
3832 SNAPDOWN(h, textCellH);
3837 aw = Max(w,window.skinMinSize.w);
3838 rx = guiApp.windowResizingBefore.w - aw;
3839 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3840 w = guiApp.windowResizingBefore.w - rx;
3844 ah = Max(h,window.skinMinSize.h);
3845 ry = guiApp.windowResizingBefore.h - ah;
3846 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3847 ry = Max(ry, -guiApp.windowMovingBefore.y);
3848 h = guiApp.windowResizingBefore.h - ry;
3853 if(!guiApp.windowIsResizing || guiApp.resizeX)
3854 x = guiApp.windowMovingBefore.x + rx;
3855 if(!guiApp.windowIsResizing || guiApp.resizeY)
3856 y = guiApp.windowMovingBefore.y + ry;
3858 if(!guiApp.windowIsResizing)
3861 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
3863 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
3864 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
3865 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
3866 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
3870 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
3871 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
3877 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
3879 if(!window.OnMoving(&x, &y, w, h))
3881 x = window.scrolledPos.x;
3882 y = window.scrolledPos.y;
3888 SNAPDOWN(x, textCellW);
3889 SNAPDOWN(y, textCellH);
3892 if(!window.style.nonClient)
3894 if(!window.style.fixed /*|| window.style.isDocument*/)
3896 if(!window.style.dontScrollHorz)
3897 x += window.parent.scroll.x;
3898 if(!window.style.dontScrollVert)
3899 y += window.parent.scroll.y;
3903 // Break the anchors for moveable/resizable windows
3904 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
3905 if(window.style.fixed)
3907 if(window.state == normal)
3909 window.normalAnchor = Anchor { left = x, top = y };
3910 window.normalSizeAnchor = SizeAnchor { { w, h } };
3911 window.anchored = false;
3915 window.stateAnchor = Anchor { left = x, top = y };
3916 window.stateSizeAnchor = SizeAnchor { { w, h } };
3918 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
3919 // TOCHECK: Investigate why the following only redraws the scrollbars
3920 //window.Position(x, y, w, h, false, true, true, true, false, true);
3922 guiApp.movingLast.x = mouseX;
3923 guiApp.movingLast.y = mouseY;
3929 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
3932 bool wasMoving = guiApp.windowMoving ? true : false;
3933 bool wasScrolling = guiApp.windowScrolling ? true : false;
3935 while(result && w != this)
3937 Window msgWindow = GetAtPosition(x,y, false, true, w);
3938 Window trueWindow = GetAtPosition(x,y, false, false, w);
3939 bool windowDragged = false;
3944 window = (w && !w.disabled) ? w : null;
3946 if(trueWindow) incref trueWindow;
3948 if(consequential) mods->isSideEffect = true;
3950 UpdateMouseMove(x, y, consequential);
3952 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
3954 if(!guiApp.windowCaptured.isEnabled)
3955 guiApp.windowCaptured.ReleaseCapture();
3957 window = guiApp.windowCaptured;
3960 if(trueWindow && activate &&
3961 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3962 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3963 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3964 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3966 if(mods->alt && !mods->ctrl && !mods->shift)
3968 Window moved = trueWindow;
3969 for(moved = trueWindow; moved; moved = moved.parent)
3970 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3975 windowDragged = true;
3977 // Cancel the ALT menu toggling...
3978 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
3983 if(window && activate &&
3984 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3985 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3986 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3987 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3989 Window modalWindow = window.FindModal();
3991 /*if(mods->alt && !mods->shift && !mods->ctrl)
3993 Window moved = window;
3994 for(moved = window; moved; moved = moved.parent)
3995 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
4000 windowDragged = true;
4002 // Cancel the ALT menu toggling...
4003 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
4009 Window activateWindow = modalWindow ? modalWindow : window;
4010 if(activateWindow && !activateWindow.isRemote)
4012 bool doActivation = true;
4013 //bool needToDoActivation = false;
4014 Window check = activateWindow;
4016 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
4018 if(!check.style.inactive)
4020 //needToDoActivation = true;
4022 doActivation = false;
4027 if(!needToDoActivation)
4028 doActivation = false;
4031 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
4032 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
4034 // Let the OnLeftButtonDown do the activating instead
4035 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4043 incref activateWindow;
4044 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
4046 delete activateWindow;
4050 if(activateWindow._refCount == 1)
4052 delete activateWindow;
4056 delete activateWindow;
4058 mods->isActivate = true;
4062 if(!modalWindow && window && !window.destroyed)
4064 if(!guiApp.windowCaptured || windowDragged)
4066 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
4068 bool moving = ((window.state != maximized &&
4069 window.IsMouseMoving(
4070 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4071 || (guiApp.windowMoving && !guiApp.windowIsResizing);
4073 if(!moving && window.IsMouseResizing(
4074 x - window.absPosition.x,
4075 y - window.absPosition.y,
4076 window.size.w, window.size.h,
4077 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
4079 guiApp.windowIsResizing = true;
4080 guiApp.windowResizingBefore.w = window.size.w;
4081 guiApp.windowResizingBefore.h = window.size.h;
4083 if(guiApp.windowIsResizing || windowDragged || moving)
4086 guiApp.windowMoving = window;
4087 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4088 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4089 guiApp.windowMovingBefore.x = window.position.x;//s;
4090 guiApp.windowMovingBefore.y = window.position.y;//s;
4091 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4092 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4095 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4097 if(window.style.fixed &&
4099 window.IsMouseMoving(
4100 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4102 window.ShowSysMenu(x, y);
4106 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4108 if(window.sbv || window.sbh)
4111 guiApp.windowScrolling = window;
4112 guiApp.windowScrollingStart.x = x;
4113 guiApp.windowScrollingStart.y = y;
4114 guiApp.windowScrollingBefore.x = window.scroll.x;
4115 guiApp.windowScrollingBefore.y = window.scroll.y;
4118 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4120 if(window.style.hasMaximize &&
4121 window.IsMouseMoving(
4122 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4125 (window.state == maximized) ? normal : maximized, false, *mods);
4133 if(guiApp.windowMoving)
4135 if(guiApp.windowMoving.parent)
4137 if(guiApp.windowMoving.style.nonClient)
4138 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4140 guiApp.windowMoving.parent.SetMouseRangeToClient();
4144 window.UpdateDecorations();
4147 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4149 // Log("\n*** LEFT BUTTON UP ***\n");
4150 if(guiApp.windowMoving)
4151 guiApp.windowMoving.StopMoving();
4153 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4155 if(guiApp.windowScrolling)
4157 Window windowScrolling = guiApp.windowScrolling;
4158 guiApp.windowScrolling = null;
4159 windowScrolling.ReleaseCapture();
4163 if(!result || (window && window.destroyed)) window = null;
4165 if(window && window.FindModal())
4168 if(trueWindow && trueWindow.FindModal())
4176 msgWindow = GetAtPosition(x,y, true, false);
4178 msgWindow.SelectMouseCursor();
4181 if(guiApp.windowCaptured || trueWindow)
4183 Window prevWindow = guiApp.prevWindow;
4184 if(guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4186 guiApp.prevWindow.mouseInside = false;
4187 guiApp.prevWindow = null;
4189 // Eventually fix this not to include captured?
4190 if(!prevWindow.OnMouseLeave(*mods))
4193 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4195 Box box = trueWindow.box;
4196 box.left += trueWindow.absPosition.x;
4197 box.right += trueWindow.absPosition.x;
4198 box.top += trueWindow.absPosition.y;
4199 box.bottom += trueWindow.absPosition.y;
4201 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4203 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4204 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4206 overX = Max(Min(overX, 32767),-32768);
4207 overY = Max(Min(overY, 32767),-32768);
4209 trueWindow.mouseInside = true;
4210 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4214 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4215 guiApp.prevWindow = trueWindow;
4217 guiApp.prevWindow = null;
4219 SelectMouseCursor();
4221 if(window && !guiApp.windowMoving && !wasMoving && !wasScrolling)
4223 int clientX = x - (window.absPosition.x + window.clientStart.x);
4224 int clientY = y - (window.absPosition.y + window.clientStart.y);
4226 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4228 clientX = Max(Min(clientX, 32767),-32768);
4229 clientY = Max(Min(clientY, 32767),-32768);
4231 MouseMethod = (void *)window._vTbl[method];
4233 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4236 if(!MouseMethod(window, clientX, clientY, *mods))
4243 if(result && w && w.clickThrough && w.parent)
4248 if(!result || !w || !w.clickThrough)
4255 // --- Mouse cursor management ---
4257 bool KeyMessage(uint method, Key key, unichar character)
4262 if(guiApp.interimWindow)
4263 this = guiApp.interimWindow;
4266 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4270 if(!style.inactive || rootWindow != this)
4272 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4273 Window modalWindow = FindModal();
4274 Window interimMaster = master ? master.rootWindow : null;
4278 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4279 status = OnSysKeyDown(key, character);
4280 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4281 status = OnSysKeyHit(key, character);
4282 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4283 status = OnSysKeyUp(key, character);
4290 // Process Key Message for Internal UI Keyboard actions
4291 if(status && !destroyed && menuBar && state != minimized)
4294 if((SmartKey)key != alt)
4295 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4298 SmartKey sk = (SmartKey) key;
4299 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4301 status = menuBar.KeyMessage(method, key, character);
4306 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4307 menuBar.OnKeyHit(escape, 0);
4309 if(!menuBar.focus && guiApp.caretOwner)
4310 guiApp.caretOwner.UpdateCaret(true, false);
4313 if(!destroyed && status)
4315 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4319 case left: case up: case right: case down:
4320 if(guiApp.windowMoving == this)
4323 int w = guiApp.windowMoving.size.w;
4324 int h = guiApp.windowMoving.size.h;
4325 int x = guiApp.windowMoving.scrolledPos.x;
4326 int y = guiApp.windowMoving.scrolledPos.y;
4330 if(key == down || key == up)
4331 step = Max(step, textCellH);
4333 step = Max(step, textCellW);
4336 if(guiApp.windowIsResizing)
4340 case left: w-=step; break;
4341 case right: w+=step; break;
4342 case up: h-=step; break;
4343 case down: h+=step; break;
4350 case left: x-=step; break;
4351 case right: x+=step; break;
4352 case up: y-=step; break;
4353 case down: y+=step; break;
4357 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4358 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4360 if(!guiApp.windowIsResizing || guiApp.resizeX)
4361 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4363 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4365 if(!guiApp.windowIsResizing || guiApp.resizeY)
4366 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4368 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4370 guiApp.interfaceDriver.SetMousePosition(x, y);
4371 ConsequentialMouseMove(true);
4379 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4381 guiApp.windowMoving.StopMoving();
4382 ConsequentialMouseMove(false);
4390 ShowSysMenu(absPosition.x, absPosition.y);
4398 if(!destroyed && status && state != minimized)
4400 // Process all the way down the children
4401 if(activeChild && !activeChild.disabled)
4403 status = activeChild.KeyMessage(method, key, character);
4405 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4406 key.code != left && key.code != right && key.code != up && key.code != down)
4408 status = activeClient.KeyMessage(method, key, character);
4412 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4414 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4415 // && defaultControl != activeChild)
4417 delete previousActive;
4418 previousActive = activeChild;
4419 if(previousActive) incref previousActive;
4421 ConsequentialMouseMove(false);
4422 if((defaultControl.active ||
4423 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4424 defaultControl.KeyMessage(method, defaultKey, character);
4430 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4432 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4439 ShowSysMenu(absPosition.x, absPosition.y);
4446 if(this != guiApp.desktop)
4448 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4450 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4452 MenuMoveOrSize(key.shift, true);
4456 else if(guiApp.windowMoving)
4458 guiApp.windowMoving.StopMoving();
4459 ConsequentialMouseMove(false);
4467 if(!destroyed && status && state != minimized)
4469 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4473 case tab: case shiftTab:
4475 Window cycleParent = this;
4476 if(this == guiApp.interimWindow && !master.style.interim && !cycleParent.style.tabCycle)
4477 cycleParent = master.parent;
4479 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4481 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4483 Window child = cycleParent.activeChild;
4485 // Scroll the window to include the active control
4487 if(cycleParent.sbh && !child.style.dontScrollHorz)
4489 if(child.scrolledPos.x < 0)
4490 cycleParent.sbh.Action(Position,
4491 cycleParent.scroll.x + child.scrolledPos.x, 0);
4492 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4493 cycleParent.sbh.Action(Position,
4494 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4496 if(cycleParent.sbv && !child.style.dontScrollVert)
4498 if(child.scrolledPos.y < 0)
4499 cycleParent.sbv.Action(Position,
4500 cycleParent.scroll.y + child.scrolledPos.y, 0);
4501 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4502 cycleParent.sbv.Action(Position,
4503 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4506 cycleParent.ConsequentialMouseMove(false);
4512 case f6: case shiftF6:
4513 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4515 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4516 if(parent == guiApp.desktop)
4517 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4527 if(CycleChildren(key.shift, true, false, true))
4535 // mIRC Style Window Shortcuts
4536 case alt1: case alt2: case alt3: case alt4: case alt5:
4537 case alt6: case alt7: case alt8: case alt9: case alt0:
4542 for(document = children.first; document; document = document.next)
4544 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4546 if(document == activeChild)
4548 if(document.state == minimized)
4549 document.SetState(normal, false, key);
4552 document.SetState(minimized, false, key);
4553 CycleChildren(false, true, false);
4558 if(activeChild.state == maximized && document.style.hasMaximize)
4559 document.SetState(maximized, false, key);
4560 else if(document.state == minimized)
4561 document.SetState(normal, false, key);
4562 document.Activate();
4577 if(!destroyed && status)
4579 if(state == minimized)
4584 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4586 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4588 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4589 previousActive.ActivateEx(true, false, false, true, null, null);
4590 delete previousActive;
4596 if(!destroyed && status)
4598 status = ProcessHotKeys(method, key, character);
4600 if(!destroyed && status && !modalWindow && state != minimized)
4603 status = KeyMethod(this, key, character);
4604 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4605 status = OnKeyHit(key, character);
4606 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4608 bool result = false;
4611 case ctrlUp: case ctrlDown:
4612 if(sbv && !guiApp.windowScrolling)
4613 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4615 case wheelUp: case wheelDown:
4616 if(sbv && !guiApp.windowScrolling)
4618 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4619 // Do we want to do a consequential move regardless of result in this case?
4620 ConsequentialMouseMove(false);
4623 case ctrlPageUp: case ctrlPageDown:
4624 if(sbh && !guiApp.windowScrolling)
4625 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4630 ConsequentialMouseMove(false);
4635 if(status && !destroyed && menuBar && state != minimized)
4636 status = menuBar.KeyMessage(method, key, character);
4638 if(style.interim && /*destroyed && */status && interimMaster)
4640 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4641 status = interimMaster.KeyMessage(method, key, character);
4648 bool ProcessHotKeys(uint method, Key key, unichar character)
4653 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4654 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4655 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4657 Window hotKeyWindow = hotKey.window;
4658 Window parent = hotKeyWindow.parent;
4659 Window prevActiveWindow = activeChild;
4661 // Don't process non-visible buttons, but make an exception for the Alt-F4 with Native Decorations turned on
4662 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1] )))
4665 if(prevActiveWindow) incref prevActiveWindow;
4666 incref hotKeyWindow;
4667 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient)
4668 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4671 delete hotKeyWindow;
4672 delete prevActiveWindow;
4676 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4677 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4678 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4680 // ********* WORKING ON THIS ***********
4681 if(prevActiveWindow && !guiApp.interimWindow)
4682 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4685 else if(hotKeyWindow.style.inactive)
4686 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4688 delete prevActiveWindow;
4689 delete hotKeyWindow;
4690 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4691 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4695 if(status && tabCycle)
4698 for(child = children.first; child; child = child.next)
4700 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4711 // --- Windows and graphics initialization / termination ---
4712 bool SetupRoot(void)
4716 // Setup relationship with outside world (bb root || !bb)
4717 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4718 (_displayDriver && dispDriver != parent.dispDriver))
4722 tempExtents = new0 Extent[4];
4727 /*if(guiApp.fullScreenMode)
4728 rootWindow = guiApp.desktop;
4730 //rootWindow = parent.created ? parent.rootWindow : null;
4731 rootWindow = parent.rootWindow;
4734 against = &parent.box;
4736 against = &parent.clientArea;
4739 for(child = children.first; child; child = child.next)
4742 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
4745 bool Setup(bool positionChildren)
4747 bool result = false;
4750 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && dispDriver != parent.dispDriver))))
4752 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
4753 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
4755 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
4757 // This was here, is it really needed?
4758 //guiApp.interfaceDriver.ActivateRootWindow(this);
4762 displaySystem = DisplaySystem {};
4763 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
4765 delete displaySystem;
4770 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData };
4771 if(display.Create(displaySystem, windowHandle))
4778 // Sometimes icon does not show up on Windows XP if we set here...
4779 // guiApp.interfaceDriver.SetIcon(this, icon);
4781 else if(this != guiApp.desktop)
4783 display = rootWindow ? rootWindow.display : null;
4789 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
4790 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
4792 for(child = children.first; child; child = child.next)
4794 if(child.created && !child.Setup(false))
4800 bool SetupDisplay(void)
4802 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
4803 if(is3D) return Window3D_SetupDisplay(this); else
4810 class_data void ** pureVTbl;
4812 bool LoadGraphics(bool creation, bool resetAnchors)
4814 bool result = false;
4815 bool success = false;
4817 WindowState stateBackup = state;
4820 if(!rootWindow.created)
4824 if(((subclass(Window))_class).pureVTbl)
4826 if(_vTbl == _class._vTbl)
4828 _vTbl = ((subclass(Window))_class).pureVTbl;
4833 for(m = 0; m < _class.vTblSize; m++)
4835 if(_vTbl[m] == _class._vTbl[m])
4836 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
4840 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
4842 if(_vTbl == ((subclass(Window))_class).pureVTbl)
4844 _vTbl = _class._vTbl;
4849 for(m = 0; m < _class.vTblSize; m++)
4851 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
4852 _vTbl[m] = _class._vTbl[m];
4857 if(guiApp.fullScreenMode || this != guiApp.desktop)
4859 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
4865 display.Lock(false);
4866 if(rootWindow == this)
4868 // Set Color Palette
4869 display.SetPalette(palette, true);
4873 if(guiApp.fullScreenMode && this == guiApp.desktop)
4878 for(c=0; c<SystemCursor::enumSize; c++)
4879 if(!guiApp.systemCursors[c].bitmap)
4881 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
4882 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
4883 if(guiApp.systemCursors[c].bitmapName)
4885 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
4886 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
4887 if(guiApp.systemCursors[c].bitmap)
4888 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
4893 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
4895 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
4896 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
4898 cursor.bitmap.paletteShades = cursor.paletteShades;
4902 guiApp.cursorUpdate = true;
4905 ConsequentialMouseMove(false);
4911 // Load Window Graphic Resources
4914 if(usedFont == setFont || usedFont == window.systemFont)
4915 RemoveResource(usedFont);
4918 RemoveResource(setFont); // TESTING setFont instead of usedFont);
4921 RemoveResource(systemFont);
4924 RemoveResource(captionFont);
4926 for(ptr = resources.first; ptr; ptr = ptr.next)
4928 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
4931 AddResource(setFont);
4933 AddResource(systemFont);
4935 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
4942 //if(master && master.font)
4943 if(parent && parent.font)
4947 faceName = parent.font.faceName,
4948 size = parent.font.size,
4949 bold = parent.font.bold,
4950 italic = parent.font.italic,
4951 underline = parent.font.underline
4953 //font = parent.font;
4954 watch(parent) { font { } };
4957 font = guiApp.currentSkin.SystemFont();
4964 captionFont = guiApp.currentSkin.CaptionFont();
4965 AddResource(captionFont);
4967 if(OnLoadGraphics())
4973 //SetScrollLineStep(sbStep.x, sbStep.y);
4975 if(this != guiApp.desktop)
4979 normalAnchor = anchor;
4980 normalSizeAnchor = sizeAnchor;
4983 // Break the anchors for moveable/resizable windows
4985 if(style.fixed && style.isDocument)
4987 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
4999 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5000 stateSizeAnchor = SizeAnchor {};
5005 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5010 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
5011 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
5014 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5018 stateAnchor = normalAnchor;
5019 stateSizeAnchor = normalSizeAnchor;
5022 position = Point { };
5023 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5034 if(Position(x, y, w, h, true, false, true, true, true, true))
5036 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
5039 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
5056 success = result = true;
5059 if(!creation && result)
5061 // Load menu bar first because sys buttons are on it...
5064 if(!menuBar.LoadGraphics(false, resetAnchors))
5070 for(child = children.first; child; child = child.next)
5072 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
5079 CreateSystemChildren();
5083 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5086 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5091 //guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, caption);
5092 guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, class.name);
5095 // Do this here to avoid problems on Windows
5096 if(stateBackup == maximized)
5097 property::state = maximized;
5101 void UnloadGraphics(bool destroyWindows)
5105 // Free children's graphics
5106 for(child = children.first; child; child = child.next)
5107 child.UnloadGraphics(destroyWindows);
5110 display.Lock(false);
5113 if(guiApp.fullScreenMode && this == guiApp.desktop)
5118 for(c=0; c<SystemCursor::enumSize; c++)
5119 if(guiApp.systemCursors[c].bitmap)
5120 delete guiApp.systemCursors[c].bitmap;
5122 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5123 delete cursor.bitmap;
5125 guiApp.cursorBackground.Free();
5128 if(display && display.displaySystem)
5132 for(ptr = resources.first; ptr; ptr = ptr.next)
5136 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5141 // Free window graphics
5144 // Free skin graphics
5145 if(rootWindow == this)
5147 DisplaySystem displaySystem = display.displaySystem;
5150 display.driverData = null;
5151 display.displaySystem = null;
5155 if(displaySystem && !displaySystem.numDisplays && !is3D)
5156 delete displaySystem;
5165 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5166 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5168 if(this == guiApp.desktop || parent == guiApp.desktop)
5170 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5171 guiApp.interfaceDriver.DestroyRootWindow(this);
5175 // --- Window Hiding ---
5177 void SetVisibility(bool state)
5179 bool visible = (style.hidden || !created) ? false : state;
5180 if(visible != this.visible)
5184 this.visible = visible;
5185 for(child = children.first; child; child = child.next)
5186 child.SetVisibility(visible);
5188 ConsequentialMouseMove(false);
5189 if(parent && !nonClient) parent.OnChildVisibilityToggled(this, visible);
5193 // --- Windows and graphics initialization / termination ---
5195 bool DisplayModeChanged(void)
5197 bool result = false;
5198 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5200 guiApp.modeSwitching = true;
5201 UnloadGraphics(false);
5203 if(LoadGraphics(false, false))
5205 guiApp.modeSwitching = false;
5210 // --- Window updates system ---
5212 void UpdateDirty(Box updateBox)
5214 if(!manageDisplay) { OnRedraw(null);return; }
5217 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5220 if(display.flags.flipping)
5223 rootWindow.UpdateDisplay();
5226 UpdateBackDisplay(updateBox);
5228 if(guiApp.fullScreenMode)
5230 guiApp.cursorUpdate = true;
5231 guiApp.PreserveAndDrawCursor();
5233 if(guiApp.fullScreenMode)
5234 guiApp.RestoreCursorBackground();
5240 // This function is strictly called as a result of system window activation
5241 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5244 Window interimMaster = null;
5245 Window interimWindow = guiApp.interimWindow;
5246 if(interimWindow && interimWindow.master)
5247 interimMaster = interimWindow.master.rootWindow;
5249 if(active && state == minimized) // && (!window.nativeDecorations || window.rootWindow != window)
5250 // SetState(normal, false, 0);
5251 SetState(lastState, false, 0);
5253 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5257 /* WTH is this doing here?
5258 while(swap && swap.activeChild)
5260 swap = swap.activeChild;
5263 // TESTING THIS BEFORE...
5264 if(interimWindow && this == interimMaster)
5268 // Window interimSwap = this;
5269 Window menuBar = this.menuBar;
5270 if(menuBar && interimWindow.master == menuBar)
5273 while(interimSwap && interimSwap.activeChild)
5274 interimSwap = interimSwap.activeChild;
5276 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5277 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5279 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5280 //result = ActivateEx(true, true, false, activateRoot, window, null);
5285 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5286 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5288 if(interimWindow == this && interimMaster && !active)
5290 while(interimMaster && interimMaster.interim && interimMaster.master)
5292 // printf("Going up one master %s\n", interimMaster._class.name);
5293 interimMaster = interimMaster.master.rootWindow;
5295 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5296 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5302 bool DestroyEx(int returnCode)
5305 Timer timer, nextTimer;
5307 OldLink prevOrder = null;
5308 Window client = null;
5310 if(parent) stopwatching(parent, font);
5312 // if(window.modalSlave) return false;
5313 if(destroyed || !created)
5320 OldLink slave = master.slaves.FindLink(this);
5321 master.slaves.Delete(slave);
5324 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5330 this.returnCode = (DialogResult)returnCode;
5332 AcquireInput(false);
5337 master.hotKeys.Delete(hotKey);
5341 if(guiApp.prevWindow == this)
5343 guiApp.prevWindow = null;
5346 if(guiApp.caretOwner == this)
5348 guiApp.interfaceDriver.SetCaret(0,0,0);
5349 UpdateCaret(false, true);
5350 guiApp.caretEnabled = false;
5355 parent.childrenCycle.Remove(cycle);
5359 OldLink tmpPrev = order.prev;
5360 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5361 prevOrder = tmpPrev;
5364 client = tmpPrev ? tmpPrev.data : null;
5365 if(client == this) { client = null; break; }
5366 if(client && (client.style.hidden || client.destroyed || !client.created))
5367 tmpPrev = client.order.prev;
5371 prevOrder = tmpPrev;
5376 // If this window can be an active client, make sure the next window we activate can also be one
5377 if(!style.nonClient && style.isActiveClient)
5379 tmpPrev = prevOrder;
5382 client = tmpPrev ? tmpPrev.data : null;
5383 if(client == this) { client = null; break; }
5384 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5385 tmpPrev = client.order.prev;
5389 prevOrder = tmpPrev;
5393 if(client && client.style.hidden) client = null;
5395 // parent.childrenOrder.Remove(order);
5398 if(parent && style.isActiveClient && visible)
5400 if(state == minimized) parent.numIcons--;
5401 parent.numPositions--;
5404 // TESTING THIS HERE!
5408 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5409 // to create a window inside a rootwindow that's being destroyed)
5410 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5412 if(master && !master.destroyed /*&&
5413 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5415 if(master.defaultControl == this)
5416 master.defaultControl = null;
5418 if(parent && !parent.destroyed /*&&
5419 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5421 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5423 if(order && prevOrder && prevOrder.data != this && active)
5425 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5427 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5428 if(parent.activeClient == this)
5430 parent.activeClient = null;
5431 parent.UpdateActiveDocument(null);
5436 if(guiApp.interimWindow == this)
5439 PropagateActive(false, null, &goOn, true);
5443 //if(window.parent.activeChild == window)
5444 parent.activeChild = null;
5445 if(!style.nonClient /*&& style.isActiveClient*/)
5447 Window previous = parent.activeClient;
5448 if(style.isActiveClient)
5449 parent.activeClient = null;
5450 parent.UpdateActiveDocument(previous);
5455 else if(parent.activeClient == this)
5457 parent.activeClient = client;
5458 parent.UpdateActiveDocument(this);
5462 if(guiApp.interimWindow == this)
5464 guiApp.interimWindow = null;
5465 if(guiApp.caretOwner)
5467 Window desktop = guiApp.desktop;
5468 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5469 guiApp.caretOwner.UpdateCaret(false, false);
5474 if(_isModal && master && master.modalSlave == this)
5475 master.modalSlave = null;
5479 if(!guiApp.caretOwner && parent.caretSize)
5481 guiApp.caretOwner = parent;
5482 parent.UpdateCaret(false, false);
5483 parent.Update(null);
5486 // Why was this commented out?
5487 GetRidOfVirtualArea();
5493 dirtyArea.Free(null);
5494 dirtyBack.Free(null);
5495 scrollExtent.Free(null);
5497 /* ATTEMPTING TO MOVE THAT ABOVE
5506 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5507 for(;(child = window.children.first);)
5509 for(; child && (child.destroyed || !child.created); child = child.next);
5518 UnloadGraphics(true);
5521 delete previousActive;
5524 // statusBar = null;
5527 if(master && !master.destroyed)
5529 //master.NotifyDestroyed(this, this.returnCode);
5530 NotifyDestroyed(master, this, this.returnCode);
5533 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5535 nextTimer = timer.next;
5536 if(timer.window == this)
5538 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5539 // timer.window = null;
5545 if(this == guiApp.windowMoving)
5548 if(guiApp.windowCaptured == this)
5550 //guiApp.windowCaptured = null;
5552 if(rootWindow != this && rootWindow)
5553 rootWindow.ConsequentialMouseMove(false);
5561 //for(child = children.first; next = child ? child.next : null, child; child = next)
5562 for(;(child = children.first); )
5564 for(; child && (child.destroyed || !child.created); child = child.next);
5574 /* // MOVED THIS UP...
5577 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5578 for(;(child = window.children.first); )
5580 for(; child && (child.destroyed || !child.created); child = child.next);
5589 while((slave = slaves.first))
5591 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5593 ((Window)slave.data).DestroyEx(0);
5598 if(guiApp.caretOwner == this)
5599 guiApp.caretOwner = null;
5601 sysButtons[0] = null;
5602 sysButtons[1] = null;
5603 sysButtons[2] = null;
5606 if(rootWindow != this)
5608 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5611 box.left -= parent.clientStart.x;
5612 box.top -= parent.clientStart.y;
5613 box.right -= parent.clientStart.x;
5614 box.bottom -= parent.clientStart.y;
5616 if(parent) parent.Update(box);
5621 OldLink slave = master.slaves.FindVoid(this);
5622 master.slaves.Delete(slave);
5628 parent.children.Remove(this);
5633 //autoCreate = false;
5636 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5637 if(((subclass(Window))_class).pureVTbl)
5639 if(_vTbl == _class._vTbl)
5641 _vTbl = ((subclass(Window))_class).pureVTbl;
5646 for(m = 0; m < _class.vTblSize; m++)
5648 if(_vTbl[m] == _class._vTbl[m])
5649 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5658 void SetStateEx(WindowState newState, bool activate)
5661 WindowState prevState = state;
5665 if(prevState != newState)
5666 lastState = prevState;
5668 if(rootWindow != this || !nativeDecorations || !windowHandle)
5670 if(style.isActiveClient && !style.hidden && prevState == minimized)
5673 // This block used to be at the end of the function... moved it for flicker problem in X
5674 // ------------------------------------------------------
5678 stateAnchor = normalAnchor;
5679 stateSizeAnchor = normalSizeAnchor;
5682 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5683 stateSizeAnchor = SizeAnchor {};
5687 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5690 byte * idBuffer = new0 byte[size];
5692 for(child = parent.children.first; child; child = child.next)
5694 if(child != this && child.state == minimized)
5696 if(child.iconID > size - 2)
5698 idBuffer = renew0 idBuffer byte[size*2];
5699 memset(idBuffer + size, 0, size);
5702 idBuffer[child.iconID] = (byte)bool::true;
5705 for(c = 0; c<size; c++)
5710 if(style.isActiveClient && !style.hidden)
5713 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5714 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5718 // TOCHECK: Why was this here?
5719 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5720 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5721 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5723 Position(x, y, w, h, true, true, true, true, false, true);
5725 if(!style.inactive && !style.interim && this == parent.activeClient)
5726 parent.UpdateActiveDocument(null);
5729 CreateSystemChildren();
5730 // ------------------------------------------------------
5733 int GetPositionID(Window forChild)
5737 byte * idBuffer = new0 byte[size];
5740 for(child = children.first; child; child = child.next)
5742 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
5744 if(child.positionID > size - 2)
5746 idBuffer = renew0 idBuffer byte[size*2];
5747 memset(idBuffer + size, 0, size);
5750 idBuffer[child.positionID] = (byte)bool::true;
5753 for(c = 0; c<size; c++)
5760 // --- Window related graphics ---
5762 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
5764 palette = newPalette;
5765 if(rootWindow.display)
5766 rootWindow.display.SetPalette(palette, colorMatch);
5769 public bool AcquireInput(bool acquired)
5772 if(acquiredInput != acquired)
5774 if(active || (!visible && creationActivation == activate))
5775 result = AcquireInputEx(acquired);
5780 acquiredInput = acquired ? result : !result;
5785 void ListChildren(ListBox listBox)
5789 for(child = children.first; child; child = child.next)
5791 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
5793 DataRow row = listBox.AddRow();
5794 row.tag = (int)child;
5795 child.FigureCaption(caption);
5796 row.SetData(null, caption);
5801 void UpdateVisual(Box extent)
5803 if(guiApp.driver != null)
5805 if(guiApp.fullScreenMode && guiApp.desktop.display)
5807 guiApp.desktop.mutex.Wait();
5808 guiApp.desktop.display.Lock(true);
5811 if(guiApp.desktop.active)
5813 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
5815 if(guiApp.desktop.display.flags.flipping)
5816 guiApp.desktop.Update(null);
5817 guiApp.desktop.UpdateDisplay();
5818 guiApp.cursorUpdate = true;
5820 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
5822 guiApp.PreserveAndDrawCursor();
5823 // guiApp.desktop.display.ShowScreen();
5824 guiApp.cursorUpdate = false;
5825 guiApp.desktop.dirty = false;
5826 guiApp.RestoreCursorBackground();
5830 guiApp.desktop.display.Unlock();
5831 guiApp.desktop.mutex.Release();
5835 Window rootWindow = this.rootWindow;
5836 rootWindow.mutex.Wait();
5841 guiApp.SignalEvent();
5844 guiApp.waitMutex.Wait();
5845 guiApp.interfaceDriver.Lock(rootWindow);
5846 if(!rootWindow.style.hidden && rootWindow.dirty)
5848 if(rootWindow.display)
5850 rootWindow.UpdateDisplay();
5851 //rootWindow.display.ShowScreen(null);
5853 rootWindow.dirty = false;
5855 guiApp.interfaceDriver.Unlock(rootWindow);
5856 guiApp.waitMutex.Release();
5859 rootWindow.mutex.Release();
5864 void UnlockDisplay(void)
5866 guiApp.interfaceDriver.Unlock(rootWindow);
5869 void LockDisplay(void)
5871 guiApp.interfaceDriver.Lock(rootWindow);
5874 Surface GetSurface(Box box)
5876 return Redraw((box == null) ? this.box : box);
5879 void SetMousePosition(int x, int y)
5881 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
5885 void IntegrationActivate(bool active)
5887 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
5889 isForegroundWindow = true;
5890 ActivateEx(active, active, false, false, null, null);
5891 isForegroundWindow = false;
5896 Window QueryCapture(void)
5898 return guiApp.windowCaptured;
5901 int GetDocumentID(void)
5905 byte * idBuffer = new0 byte[size];
5908 for(child = children.first; child; child = child.next)
5910 // TO CHECK: Do we want a documentID when we already have a file name?
5911 if(child.style.isDocument && !child.fileName)
5913 if(child.documentID-1 > size - 2)
5915 idBuffer = renew0 idBuffer byte[size*2];
5916 memset(idBuffer + size, 0, size);
5919 idBuffer[child.documentID-1] = 1;
5922 for(c = 0; c<size; c++)
5930 void SetInitSize(Size size)
5933 sizeAnchor.size = size;
5934 normalSizeAnchor = sizeAnchor;
5936 // Break the anchors for moveable/resizable windows
5937 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
5939 stateAnchor = normalAnchor;
5940 stateSizeAnchor = normalSizeAnchor;
5942 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5943 Position(x,y, w, h, true, true, true, true, false, true);
5947 void MenuMoveOrSize(bool resize, bool setCursorPosition)
5949 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
5951 guiApp.windowIsResizing = resize;
5952 guiApp.windowMoving = this;
5953 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
5954 if(guiApp.windowIsResizing)
5956 guiApp.windowMovingStart.x += size.w - 1;
5957 guiApp.windowMovingStart.y += size.h - 1;
5959 guiApp.windowMovingBefore = scrolledPos;
5960 guiApp.windowResizingBefore = size;
5961 guiApp.windowMoving.UpdateDecorations();
5962 if(guiApp.windowIsResizing)
5963 guiApp.resizeEndX = guiApp.resizeEndY = true;
5965 if(setCursorPosition)
5966 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
5970 guiApp.interfaceDriver.GetMousePosition(&x, &y);
5971 guiApp.windowMovingStart.x += x - absPosition.x;
5972 guiApp.windowMovingStart.y += y - absPosition.y;
5975 if(guiApp.windowMoving)
5977 if(guiApp.windowMoving.style.nonClient)
5978 guiApp.windowMoving.parent.SetMouseRangeToWindow();
5980 guiApp.windowMoving.parent.SetMouseRangeToClient();
5985 if(this == rootWindow)
5986 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
5994 bool result = false;
5998 else if(guiApp && guiApp.driver != null)
6000 void * systemParent = null;
6001 OldLink slaveHolder;
6003 bool visible = !style.hidden;
6007 systemParent = parent;
6008 parent = guiApp.desktop;
6010 last = parent ? parent.children.last : null;
6012 if((parent && parent != guiApp.desktop && !parent.created) ||
6013 (master && master != guiApp.desktop && !master.created))
6017 property::parent = guiApp.desktop;
6018 if(!master) master = parent;
6020 if(_isModal && master.modalSlave)
6021 property::master = master.modalSlave;
6025 parent.children.Remove(this);
6028 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
6029 if(slaveHolder.data == this)
6031 master.slaves.Delete(slaveHolder);
6036 if(parent == guiApp.desktop && !mutex)
6039 if(style.isDocument)
6042 parent.numDocuments--;
6043 documentID = parent.GetDocumentID();
6046 if(!style.stayOnTop)
6047 for(; last && last.style.stayOnTop; last = last.prev);
6049 parent.children.Insert((last == this) ? null : last, this);
6050 //parent.children.Add(this);
6053 dispDriver = parent.dispDriver;
6056 master.modalSlave = this;
6058 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
6063 master.slaves.Add(slaveHolder = OldLink { data = this });
6068 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
6070 if(style.isDefault && !master.defaultControl)
6071 master.defaultControl = this;
6073 stateAnchor = normalAnchor = anchor;
6074 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
6076 // TOCHECK: Why is this here?
6077 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
6078 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
6080 this.visible = false;
6081 style.hidden = true;
6084 // autoCreate = true;
6092 if(parent == guiApp.desktop)
6093 Log("LoadGraphics %s\n", caption);
6095 if(LoadGraphics(true, false))
6103 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6110 if(style.hasMenuBar /*&& menu*/)
6116 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6117 interim = false, inactive = true, nonClient = true, size.h = 24
6125 // Create the system buttons
6126 CreateSystemChildren();
6128 UpdateActiveDocument(null);
6130 if(style.isDocument)
6134 MenuItem item = menu.FindItem(MenuFileSave, 0);
6135 if(item) item.disabled = !modifiedDocument && fileName;
6140 if(parent == guiApp.desktop)
6141 Log("Preemptive SetState %s\n", caption);
6144 // Preemptive Set State to ensure proper anchoring
6145 SetStateEx(state, false);
6147 style.hidden = true;
6153 for(child = children.first; child; child = next)
6156 if(!child.created && (child.autoCreate || child.wasCreated))
6163 for(link = slaves.first; link; link = next)
6165 Window slave = link.data;
6167 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6170 // Things might have happened that invalidated 'next'...
6171 // Start over the search for slaves to create.
6172 // (Added this to fix crash with Stacker & Toolbar)
6173 next = slaves.first;
6182 if(parent == guiApp.desktop)
6183 Log("Real SetState %s\n", caption);
6186 if(isActiveClient && visible)
6188 parent.numPositions--;
6189 if(state == minimized) parent.numIcons--;
6192 // Real set state & activate for proper display & activation
6193 property::visible = visible;
6194 // SetState(state & 0x00000003, true, 0);
6195 guiApp.interfaceDriver.SetIcon(this, icon);
6200 /*if(rootWindow == this)
6201 guiApp.interfaceDriver.ActivateRootWindow(this);
6203 if(creationActivation == activate)
6204 ActivateEx(true, false, true, true, null, null);
6205 else if(creationActivation == flash)
6210 rootWindow.ConsequentialMouseMove(false);
6221 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6227 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6229 //style.hidden = true; // !visible;
6230 style.hidden = !visible;
6231 if(master.modalSlave == this)
6232 master.modalSlave = null;
6239 void WriteCaption(Surface surface, int x, int y)
6242 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6245 void Update(Box region)
6251 rootWindow = this.rootWindow;
6253 // rootWindow.mutex.Wait();
6254 if(!destroyed && visible && display)
6259 // Testing this to avoid repetitve full update to take time...
6260 if(dirtyArea.count == 1)
6262 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6263 if(item.box.left <= box.left &&
6264 item.box.top <= box.top &&
6265 item.box.right >= box.right &&
6266 item.box.bottom >= box.bottom)
6268 rootWindow.dirty = true;
6273 if(display.flags.flipping && !rootWindow.dirty)
6275 if(this == rootWindow)
6279 rootWindow.Update(null);
6284 rootWindow.dirty = true;
6289 realBox.left += clientStart.x;
6290 realBox.top += clientStart.y;
6291 realBox.right += clientStart.x;
6292 realBox.bottom += clientStart.y;
6298 if(realBox.right >= realBox.left &&
6299 realBox.bottom >= realBox.top)
6301 // if(!rootWindow.fullRender)
6302 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6304 for(child = children.first; child; child = child.next)
6309 box.left -= child.absPosition.x - absPosition.x;
6310 box.top -= child.absPosition.y - absPosition.y;
6311 box.right -= child.absPosition.x - absPosition.x;
6312 box.bottom -= child.absPosition.y - absPosition.y;
6313 if(box.right >= child.box.left && box.left <= child.box.right &&
6314 box.bottom >= child.box.top && box.top <= child.box.bottom)
6316 box.left -= child.clientStart.x;
6317 box.top -= child.clientStart.y;
6318 box.right -= child.clientStart.x;
6319 box.bottom -= child.clientStart.y;
6325 realBox.left += absPosition.x - rootWindow.absPosition.x;
6326 realBox.top += absPosition.y - rootWindow.absPosition.y;
6327 realBox.right += absPosition.x - rootWindow.absPosition.x;
6328 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6329 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6332 else if(this == guiApp.desktop)
6335 for(window = children.first; window; window = window.next)
6341 Box childBox = region;
6343 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6344 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6345 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6346 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6348 window.Update(childBox);
6351 window.Update(null);
6356 // rootWindow.mutex.Release();
6363 if(guiApp.windowCaptured != this)
6365 if(guiApp.windowCaptured)
6369 //Logf("Captured %s (%s)\n", caption, class.name);
6370 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6371 guiApp.windowCaptured = this;
6377 bool Destroy(int code)
6382 if(!destroyed && !CloseConfirmation(false)) return false;
6386 // TOCHECK: Should autoCreate be set to false here?
6397 void Move(int x, int y, int w, int h)
6399 normalAnchor = Anchor { left = x, top = y };
6400 normalSizeAnchor = SizeAnchor { size = { w, h } };
6402 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6404 if(destroyed) return;
6406 stateAnchor = normalAnchor;
6407 stateSizeAnchor = normalSizeAnchor;
6409 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6410 Position(x,y, w, h, true, true, true, true, false, true);
6414 DialogResult Modal(void)
6420 // FIXES MEMORY LEAK IF Create() FAILED
6426 void SetScrollArea(int width, int height, bool snapToStep)
6428 bool resize = false;
6431 int stepX = sbStep.x, stepY = sbStep.y;
6432 // Needed to make snapped down position match the skin's check of client area
6433 // against realvirtual
6436 SNAPDOWN(stepX, textCellW);
6437 SNAPDOWN(stepY, textCellH);
6438 stepX = Max(stepX, textCellW);
6439 stepY = Max(stepY, textCellH);
6441 if(scrollFlags.snapX)
6442 SNAPUP(width, stepX);
6443 if(scrollFlags.snapY)
6444 SNAPUP(height, stepY);
6447 reqScrollArea.w = width;
6448 reqScrollArea.h = height;
6449 noAutoScrollArea = (width > 0 || height > 0);
6451 UpdateScrollBars(true, true);
6454 void SetScrollPosition(int x, int y)
6457 sbh.Action(setPosition, x, 0);
6461 int seen = clientSize.w, total = reqScrollArea.w;
6463 if(scrollFlags.snapX)
6464 SNAPDOWN(seen, sbStep.x);
6466 if(!total) total = seen;
6467 range = total - seen + 1;
6468 range = Max(range, 1);
6470 if(x >= range) x = range - 1;
6472 if(scrollFlags.snapX)
6473 SNAPUP(x, sbStep.x);
6476 OnHScroll(setPosition, x, 0);
6480 SNAPDOWN(x, textCellW);
6486 sbv.Action(setPosition, y, 0);
6490 int seen = clientSize.h, total = reqScrollArea.h;
6493 if(scrollFlags.snapY)
6494 SNAPDOWN(seen, sbStep.y);
6496 if(!total) total = seen;
6497 range = total - seen + 1;
6498 range = Max(range, 1);
6500 if(y >= range) y = range - 1;
6502 if(scrollFlags.snapY)
6503 SNAPUP(y, sbStep.y);
6506 OnVScroll(setPosition, y, 0);
6509 SNAPDOWN(y, textCellH);
6514 UpdateCaret(false, false);
6517 void SetScrollLineStep(int stepX, int stepY)
6523 SNAPDOWN(stepX, textCellW);
6524 SNAPDOWN(stepY, textCellH);
6525 stepX = Max(stepX, textCellW);
6526 stepY = Max(stepY, textCellH);
6529 sbh.lineStep = stepX;
6531 sbv.lineStep = stepY;
6534 void SetState(WindowState newState, bool activate, Modifiers mods)
6538 if(state == newState || OnStateChange(newState, mods))
6540 WindowState prevState = state;
6544 // This used to be at the end of the brackets... moved for X, testing...
6545 // This has the effect of activating the window through the system...
6546 if(rootWindow == this)
6547 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6549 SetStateEx(newState, activate);
6551 if(rootWindow == this && !rootWindow.nativeDecorations)
6553 int x = position.x, y = position.y;
6556 x -= guiApp.desktop.absPosition.x;
6557 y -= guiApp.desktop.absPosition.y;
6559 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6563 //state = prevState;
6565 if(state != maximized && style.hasMaximize)
6568 for(child = parent.children.first; child; child = child.next)
6570 if(child != this && child.state == maximized)
6571 child.SetStateEx(normal, false);
6575 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6576 parent.UpdateScrollBars(true, true);
6579 // Do we really need this stuff here?
6580 // Shouldn't the Activate stuff take care of it?
6581 if(parent.rootWindow == parent && style)
6584 parent.FigureCaption(caption);
6585 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6586 parent.UpdateDecorations();
6590 rootWindow.ConsequentialMouseMove(false);
6597 BitmapResource GetIcon(SkinBitmap iconID)
6599 return guiApp.currentSkin.GetBitmap(iconID);
6602 void SetMouseRange(Box range)
6604 if(range || guiApp.fullScreenMode)
6609 clip.left = range.left + absPosition.x + clientStart.x;
6610 clip.top = range.top + absPosition.y + clientStart.y;
6611 clip.right = range.right + absPosition.x + clientStart.x;
6612 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6616 clip.left = guiApp.desktop.box.left;
6617 clip.top = guiApp.desktop.box.top;
6618 clip.right = guiApp.desktop.box.right;
6619 clip.bottom = guiApp.desktop.box.bottom;
6621 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6624 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6627 void SetMouseRangeToClient(void)
6629 if(guiApp.fullScreenMode || this != guiApp.desktop)
6631 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6632 box.Clip(clientArea);
6636 SetMouseRange(null);
6639 void SetMouseRangeToWindow(void)
6641 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6642 if(this == guiApp.desktop)
6643 SetMouseRangeToClient();
6648 // x, y: Desktop Coordinates
6649 void ShowSysMenu(int x, int y)
6652 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6655 menu, $"Restore", r, NotifySelect = MenuWindowRestore,
6656 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6660 menu, $"Move", m, NotifySelect = MenuWindowMove,
6661 disabled = !style.fixed || state == maximized
6665 menu, $"Size", s, NotifySelect = MenuWindowSize,
6666 disabled = !style.sizable || state != normal
6670 menu, $"Minimize", n, NotifySelect = MenuWindowMinimize,
6671 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6675 menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6676 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6680 menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6681 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6683 MenuDivider { menu };
6686 menu, $"Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6687 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6689 windowMenu.Create();
6694 ActivateEx(true, true, true, true, null, null);
6697 void MakeActive(void)
6699 ActivateEx(true, false, true, false, null, null);
6702 void SoftActivate(void)
6704 if(guiApp.desktop.active)
6710 void Deactivate(void)
6712 ActivateEx(false, true, true, true, null, null);
6717 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
6720 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
6722 bool result = false;
6723 if(activeChild && activeChild.cycle)
6725 Window modalWindow, child = activeChild;
6726 if(!clientOnly /*&& parent.tabCycle*/)
6728 Window next = child;
6731 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
6735 if(parent && parent.CycleChildren(backward, false, true, true))
6743 next = next.cycle.prev.data;
6745 next = next.cycle.next.data;
6746 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
6751 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
6752 parent.tabCycle && parent.CycleChildren(backward, false, false))
6756 if(tabCycleOnly && !tabCycle) return false;
6763 child = child.cycle.prev.data;
6765 child = child.cycle.next.data;
6766 if(child == child.parent.activeChild)
6768 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
6771 modalWindow = child.FindModal();
6774 // Scroll the window to include the active control
6775 if(sbh && !child.style.dontScrollHorz)
6777 if(child.scrolledPos.x < 0)
6778 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
6779 else if(child.scrolledPos.x + child.size.w > clientSize.w)
6780 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
6782 if(sbv && !child.style.dontScrollVert)
6784 if(child.scrolledPos.y < 0)
6785 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
6786 else if(child.scrolledPos.y + child.size.h > clientSize.h)
6787 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
6791 child = modalWindow ? modalWindow : child;
6792 child.ActivateEx(true, true, true, true, null, null);
6793 if(child.tabCycle && child.childrenCycle.first)
6794 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
6802 ConsequentialMouseMove(false);
6806 void AddResource(Resource resource)
6810 ResPtr ptr { resource = resource };
6814 // Load Graphics here if window is created already
6815 if(/*created && */display)
6817 display.Lock(false);
6818 ptr.loaded = display.displaySystem.LoadResource(resource);
6822 // Temporary hack to load font right away for listbox in dropbox ...
6823 else if(master && master.display)
6825 master.display.Lock(false);
6826 master.display.displaySystem.LoadResource(resource);
6827 master.display.Unlock();
6833 void RemoveResource(Resource resource)
6838 for(ptr = resources.first; ptr; ptr = ptr.next)
6840 if(ptr.resource == resource)
6846 // Unload Graphics here if window is created already
6847 if(/*created && */display)
6851 display.Lock(false);
6852 display.displaySystem.UnloadResource(resource, ptr.loaded);
6858 resources.Delete(ptr);
6863 void SetCaret(int x, int y, int size)
6870 if(active && !style.interim)
6872 if(visible || !guiApp.caretOwner)
6873 guiApp.caretOwner = size ? this : null;
6875 UpdateCaret(false, false);
6878 guiApp.interfaceDriver.SetCaret(0,0,0);
6879 UpdateCaret(false, true);
6880 guiApp.caretEnabled = false;
6883 else if(style.inactive && active)
6885 guiApp.interfaceDriver.SetCaret(0,0,0);
6886 UpdateCaret(false, true);
6887 guiApp.caretEnabled = false;
6892 void Scroll(int x, int y)
6894 bool opaque = !style.drawBehind || background.a;
6895 if(opaque && display && display.flags.scrolling)
6897 Box box = clientArea;
6898 box.left += clientStart.x;
6899 box.top += clientStart.y;
6900 box.right += clientStart.x;
6901 box.bottom += clientStart.y;
6903 //scrollExtent.Free(null);
6904 scrollExtent.AddBox(box);
6905 scrolledArea.x += x;
6906 scrolledArea.y += y;
6908 //scrollExtent.Free();
6909 //scrollExtent.AddBox(clientArea);
6910 //scrollExtent.Offset(clientStart.x, clientStart.y);
6911 //scrolledArea.x = x;
6912 //scrolledArea.y = y;
6918 rootWindow.dirty = true;
6921 void ReleaseCapture()
6923 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
6925 Window oldCaptured = guiApp.windowCaptured;
6926 guiApp.windowCaptured = null;
6927 guiApp.prevWindow = null;
6930 //guiApp.Log("Released Capture\n");
6932 guiApp.interfaceDriver.SetMouseCapture(null);
6934 //oldCaptured.OnMouseCaptureLost();
6937 oldCaptured.ConsequentialMouseMove(false);
6942 void SetText(char * format, ...)
6949 char caption[MAX_F_STRING];
6951 va_start(args, format);
6952 vsprintf(caption, format, args);
6955 this.caption = new char[strlen(caption)+1];
6957 strcpy(this.caption, caption);
6966 bool Grab(Bitmap bitmap, Box box, bool decorations)
6968 bool result = false;
6969 if(display || this == guiApp.desktop)
6971 Box clip = {MININT, MININT, MAXINT, MAXINT};
6977 clip.Clip(clientArea);
6979 clip.Clip(this.box);
6981 if(rootWindow != this)
6983 clip.left += absPosition.y;
6984 clip.top += absPosition.y;
6985 clip.right += absPosition.x;
6986 clip.bottom += absPosition.y;
6989 clip.left += decorations ? 0 : clientStart.x;
6990 clip.top += decorations ? 0 : clientStart.y;
6991 clip.right += decorations ? 0 : clientStart.x;
6992 clip.bottom += decorations ? 0 : clientStart.y;
6994 if(display && display.flags.flipping)
6996 rootWindow.Update(null);
6997 rootWindow.UpdateDisplay();
7004 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
7005 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7009 result = display.Grab(bitmap, clip.left, clip.top,
7010 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
7012 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
7014 if(!bitmap.Convert(null, pixelFormat888, null))
7021 void GetMousePosition(int * x, int * y)
7023 int mouseX = 0, mouseY = 0;
7024 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
7027 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
7028 if(this != guiApp.desktop)
7030 mouseX -= absPosition.x + clientStart.x;
7031 mouseY -= absPosition.y + clientStart.y;
7038 DialogResult DoModal()
7040 DialogResult returnCode = 0;
7041 int terminated = terminateX;
7044 while(!destroyed && guiApp.driver != null)
7046 if(terminateX != terminated)
7048 terminated = terminateX;
7049 guiApp.desktop.Destroy(0);
7050 if(guiApp.desktop.created)
7053 //printf("Resetting terminate X to 0\n");
7059 guiApp.UpdateDisplay();
7060 if(!guiApp.ProcessInput(false))
7063 returnCode = this.returnCode;
7076 return !destroyed && guiApp.driver != null && terminateX < 2;
7079 DialogResult DoModalEnd()
7081 DialogResult returnCode = this.returnCode;
7086 // --- Window manipulation ---
7087 /*bool GetDisabled()
7089 bool disabled = this.disabled;
7091 for(window = this; (window = window.master); )
7102 // --- Mouse Manipulation ---
7103 void GetNCMousePosition(int * x, int * y)
7105 GetMousePosition(x, y);
7106 if(x) *x += clientStart.x;
7107 if(y) *y += clientStart.y;
7110 // --- Carets manipulation ---
7111 void GetCaretPosition(Point caretPos)
7113 caretPos = this.caretPos;
7116 int GetCaretSize(void)
7121 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7127 bool CloseConfirmation(bool parentClosing)
7140 if(!OnClose(parentClosing))
7143 // If you want to skip this, simply set modifiedDocument to false in OnClose
7144 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7146 DialogResult dialogRes;
7149 sprintf(message, $"Save changes to %s?", fileName);
7151 sprintf(message, $"Save changes to Untitled %d?", documentID);
7153 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = message }.Modal();
7155 if(dialogRes == yes)
7157 // TOFIX: Precomp error if brackets are taken out
7158 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7160 else if(dialogRes == cancel)
7166 for(slave = slaves.first; slave; slave = slave.next)
7168 Window w = slave.data;
7169 if((w.parent == this || !w.IsDescendantOf(this)) && !w.CloseConfirmation(true))
7171 // ((Window)slave.data).CloseConfirmation(true);
7180 for(child = children.first; child; child = child.next)
7181 if(child.master != this && !child.CloseConfirmation(true))
7191 // Static methods... move them somewhere else?
7192 void ::RestoreCaret()
7194 if(guiApp.caretOwner)
7195 guiApp.caretOwner.UpdateCaret(false, false);
7198 void ::FreeMouseRange()
7200 guiApp.interfaceDriver.SetMouseRange(null, null);
7204 bool MenuFileClose(MenuItem selection, Modifiers mods)
7206 Window document = activeChild;
7208 document.Destroy(0);
7212 bool MenuFileExit(MenuItem selection, Modifiers mods)
7218 bool MenuFileSave(MenuItem selection, Modifiers mods)
7222 fileMonitor.fileName = null;
7225 if(OnSaveFile(fileName))
7227 //if(OnFileModified != Window::OnFileModified)
7230 fileMonitor.fileName = fileName;
7236 MessageBox dialog { master = master, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7237 DialogResult answer = dialog.Modal();
7239 if(answer != yes) return (bool)answer;
7242 return MenuFileSaveAs(selection, mods);
7245 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7247 DialogResult result = (DialogResult)bool::true;
7248 FileDialog fileDialog = saveDialog;
7251 fileDialog = FileDialog {};
7256 fileDialog.filePath = fileName;
7259 char filePath[MAX_FILENAME];
7260 sprintf(filePath, "Untitled %d", documentID);
7261 fileDialog.filePath = filePath;
7263 fileMonitor.fileName = null;
7265 fileDialog.type = save;
7266 fileDialog.text = $"Save As";
7270 fileDialog.master = master.parent ? master : this;
7271 if(fileDialog.Modal() == ok)
7273 char * filePath = fileDialog.filePath;
7275 if(OnSaveFile(filePath))
7278 property::fileName = filePath;
7279 NotifySaved(master, this, filePath);
7284 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7285 DialogResult answer = dialog.Modal();
7300 //if(OnFileModified != Window::OnFileModified && fileName)
7303 fileMonitor.fileName = fileName;
7307 return (bool)result; // Actually returning result from Yes/NoCancel message box
7310 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7312 Window document = activeChild;
7314 for(document = children.first; document; document = next)
7316 next = document.next;
7317 if(document.style.isDocument || document.fileName)
7318 document.MenuFileSave(selection, mods);
7323 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7327 for(document = children.first; document; document = document.next)
7328 //if(document.style.isDocument && document.state == minimized)
7329 if(document.style.isActiveClient && document.state == minimized)
7330 document.SetState(minimized, false, mods);
7334 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7336 Window document = activeChild;
7339 Window firstDocument = null;
7341 OldLink cycle = document.cycle.prev;
7346 if(child.style.isActiveClient && !child.style.hidden)
7350 firstDocument = child;
7351 if(child.state == minimized)
7352 child.SetState(minimized, false, mods);
7355 child.positionID = id++;
7356 child.SetState(normal, false, mods);
7357 child.anchor.left.type = cascade;
7360 child.normalSizeAnchor = *&child.sizeAnchor;
7361 child.normalAnchor = child.anchor;
7363 // Break the anchors for moveable/resizable windows
7364 if(child.style.fixed)
7366 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7368 (*&child.normalAnchor).left = x;
7369 (*&child.normalAnchor).top = y;
7370 (*&child.normalAnchor).right.type = none;
7371 (*&child.normalAnchor).bottom.type = none;
7373 child.normalSizeAnchor.isClientW = false;
7374 child.normalSizeAnchor.isClientH = false;
7375 child.normalSizeAnchor.size.w = w;
7376 child.normalSizeAnchor.size.h = h;
7377 child.anchored = false;
7380 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7382 child.stateAnchor = child.normalAnchor;
7383 child.stateSizeAnchor = child.normalSizeAnchor;
7385 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7386 child.Position(x, y, w, h, true, true, true, true, false, false);
7391 last = children.last;
7392 if(!child.style.stayOnTop)
7393 for(; last && last.style.stayOnTop; last = last.prev);
7394 children.Move(child, last);
7395 childrenOrder.Move(child.order, childrenOrder.last);
7397 if(cycle == document.cycle) break;
7401 firstDocument.Activate();
7406 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7413 // Close all closes all active clients, not all documents
7414 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7416 Window next, document;
7418 for(document = children.first; document; document = next)
7420 for(next = document.next; next && !(next.style.isActiveClient; next = next.next);
7421 if(document.style.isActiveClient)
7422 if(!document.Destroy(0) && !document.style.hidden)
7428 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7430 if(style.hasMaximize && state != maximized)
7431 SetState(maximized, 0, 0);
7435 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7437 if(style.hasMinimize && state != minimized)
7439 SetState(minimized, 0, 0);
7440 parent.CycleChildren(false, true, false, true);
7445 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7447 MenuMoveOrSize(false, selection ? true : false);
7451 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7453 CycleChildren(false, true, false, true);
7457 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7459 CycleChildren(true, true, false, true);
7463 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7465 MenuMoveOrSize(true, true);
7469 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7472 SetState(normal, 0, 0);
7476 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7479 int id = selection.id;
7480 OldLink cycle = activeClient.cycle;
7482 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7485 Window sibling = cycle.data;
7486 if(sibling.style.isActiveClient && sibling.visible && !sibling.style.nonClient)
7494 document = cycle.data;
7495 document.Activate();
7497 //if(activeChild.state == maximized)
7498 // document.SetState(maximized, false, mods);
7499 //else if(document.state == minimized)
7500 // document.SetState(normal, false, mods);
7504 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7506 stayOnTop = !style.stayOnTop;
7510 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7512 Window document = activeChild;
7515 Window firstDocument = null;
7516 OldLink cycle = document.cycle;
7520 Window child = cycle.data;
7521 if(child.style.isActiveClient && !child.style.hidden)
7523 if(!firstDocument) firstDocument = child;
7524 if(child.state == minimized)
7525 child.SetState(minimized, false, mods);
7528 child.positionID = id++;
7529 child.SetState(normal, false, mods);
7530 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7532 child.anchor.left.type = hTiled;
7535 child.normalSizeAnchor = *&child.sizeAnchor;
7536 child.normalAnchor = child.anchor;
7538 // Break the anchors for moveable/resizable windows
7539 if(child.style.fixed)
7541 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7543 (*&child.normalAnchor).left = x;
7544 (*&child.normalAnchor).top = y;
7545 (*&child.normalAnchor).right.type = none;
7546 (*&child.normalAnchor).bottom.type = none;
7547 child.normalSizeAnchor.isClientW = false;
7548 child.normalSizeAnchor.isClientH = false;
7549 child.normalSizeAnchor.size.w = w;
7550 child.normalSizeAnchor.size.h = h;
7551 child.anchored = false;
7554 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7556 child.stateAnchor = child.normalAnchor;
7557 child.stateSizeAnchor = child.normalSizeAnchor;
7559 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7560 child.Position(x,y, w, h, true, true, true, true, false, true);
7565 if((cycle = cycle.next) == document.cycle) break;
7568 firstDocument.Activate();
7573 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7575 Window document = activeChild;
7578 Window firstDocument = null;
7580 OldLink cycle = document.cycle;
7585 //if(child.style.isDocument)
7586 if(child.style.isActiveClient && !child.style.hidden)
7588 if(!firstDocument) firstDocument = child;
7589 if(child.state == minimized)
7590 child.SetState(minimized, false, mods);
7593 child.positionID = id++;
7594 child.SetState(normal, false, mods);
7595 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7597 child.anchor.left.type = vTiled;
7600 child.normalSizeAnchor = *&child.sizeAnchor;
7601 child.normalAnchor = child.anchor;
7603 // Break the anchors for moveable/resizable windows
7604 if(child.style.fixed)
7606 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7608 (*&child.normalAnchor).left = x;
7609 (*&child.normalAnchor).top = y;
7610 (*&child.normalAnchor).right.type = none;
7611 (*&child.normalAnchor).bottom.type = none;
7612 child.normalSizeAnchor.isClientW = false;
7613 child.normalSizeAnchor.isClientH = false;
7614 child.normalSizeAnchor.size.w = w;
7615 child.normalSizeAnchor.size.h = h;
7616 child.anchored = false;
7619 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7621 child.stateAnchor = child.normalAnchor;
7622 child.stateSizeAnchor = child.normalSizeAnchor;
7624 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7625 child.Position(x,y, w, h, true, true, true, true, false, true);
7630 if((cycle = cycle.next) == document.cycle) break;
7633 firstDocument.Activate();
7638 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7640 WindowList dialog { master = this };
7641 Window document = (Window)dialog.Modal();
7644 if(activeChild.state == maximized)
7645 document.SetState(maximized, false, mods);
7646 else if(document.state == minimized)
7647 document.SetState(normal, false, mods);
7648 document.Activate();
7654 virtual bool OnCreate(void);
7655 virtual void OnDestroy(void);
7656 virtual void OnDestroyed(void);
7657 virtual bool OnClose(bool parentClosing);
7658 virtual bool OnStateChange(WindowState state, Modifiers mods);
7659 virtual bool OnPostCreate(void);
7660 virtual bool OnMoving(int *x, int *y, int w, int h);
7661 virtual bool OnResizing(int *width, int *height);
7662 virtual void OnResize(int width, int height);
7663 virtual void OnPosition(int x, int y, int width, int height);
7664 virtual bool OnLoadGraphics(void);
7665 virtual void OnApplyGraphics(void);
7666 virtual void OnUnloadGraphics(void);
7667 virtual void OnRedraw(Surface surface);
7668 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7669 virtual void OnActivateClient(Window client, Window previous);
7670 virtual bool OnKeyDown(Key key, unichar ch);
7671 virtual bool OnKeyUp(Key key, unichar ch);
7672 virtual bool OnKeyHit(Key key, unichar ch);
7673 virtual bool OnSysKeyDown(Key key, unichar ch);
7674 virtual bool OnSysKeyUp(Key key, unichar ch);
7675 virtual bool OnSysKeyHit(Key key, unichar ch);
7676 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7677 virtual bool OnMouseLeave(Modifiers mods);
7678 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7679 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7680 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
7681 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
7682 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
7683 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
7684 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
7685 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
7686 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
7687 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
7688 virtual void OnMouseCaptureLost(void);
7689 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
7690 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
7691 virtual void OnDrawOverChildren(Surface surface);
7692 virtual bool OnFileModified(FileChange fileChange, char * param);
7693 virtual bool OnSaveFile(char * fileName);
7695 // Virtual Methods -- Children management (To support Stacker, for lack of built-in auto-layout)
7696 // Note: A 'client' would refer to isActiveClient, rather than
7697 // being confined to the 'client area' (nonClient == false)
7698 virtual void OnChildAddedOrRemoved(Window child, bool removed);
7699 virtual void OnChildVisibilityToggled(Window child, bool visible);
7700 virtual void OnChildResized(Window child, int x, int y, int w, int h);
7702 // Skins Virtual Functions
7703 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
7704 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
7705 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
7710 virtual void ShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7711 virtual void PreShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7712 virtual bool IsMouseMoving(int x, int y, int w, int h);
7713 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY);
7714 virtual void UpdateNonClient();
7715 virtual void SetBox(Box box);
7716 virtual bool IsInside(int x, int y)
7718 return box.IsPointInside({x, y});
7720 virtual bool IsOpaque()
7722 return (!style.drawBehind || background.a == 255);
7726 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
7727 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
7728 virtual void Window::NotifySaved(Window window, char * filePath);
7733 property Window parent
7735 property_category $"Layout"
7738 if(value || guiApp.desktop)
7741 Window oldParent = parent;
7742 Anchor anchor = this.anchor;
7744 if(value && value.IsDescendantOf(this)) return;
7745 if(value && value == this)
7747 if(!value) value = guiApp.desktop;
7749 if(value == oldParent) return;
7751 if(!master || (master == this.parent && master == guiApp.desktop))
7752 property::master = value;
7756 parent.children.Remove(this);
7757 parent.OnChildAddedOrRemoved(this, true);
7761 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7762 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
7763 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7764 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
7768 last = value.children.last;
7770 if(style.isDocument)
7773 parent.numDocuments--;
7774 documentID = value.GetDocumentID();
7777 if(style.isActiveClient && !style.hidden)
7779 if(parent && parent != guiApp.desktop && !(style.hidden))
7781 if(state == minimized) parent.numIcons--;
7782 parent.numPositions--;
7786 if(!style.stayOnTop)
7787 for(; last && last.style.stayOnTop; last = last.prev);
7789 value.children.Insert(last, this);
7791 // *** NEW HERE: ***
7793 parent.childrenCycle.Delete(cycle);
7795 parent.childrenOrder.Delete(order);
7803 int x = position.x, y = position.y, w = size.w, h = size.h;
7807 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
7808 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
7810 vpw = value.clientSize.w;
7811 vph = value.clientSize.h;
7817 else if(style.fixed)
7819 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
7820 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
7823 anchor = this.anchor;
7825 if(anchor.left.type == offset) anchor.left.distance = x;
7826 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
7827 if(anchor.top.type == offset) anchor.top.distance = y;
7828 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
7829 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
7830 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
7831 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
7832 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
7833 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
7834 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
7836 if(!anchor.left.type && !anchor.right.type)
7838 anchor.horz.distance = (x + w / 2) - (vpw / 2);
7839 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
7841 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
7842 if(!anchor.top.type && !anchor.bottom.type)
7844 anchor.vert.distance = (y + h / 2) - (vph / 2);
7845 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
7847 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
7850 parent.OnChildAddedOrRemoved(this, false);
7856 parent.childrenCycle.Insert(
7857 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
7858 cycle = OldLink { data = this });
7859 parent.childrenOrder.Insert(
7860 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
7861 order = OldLink { data = this });
7864 if(!style.hidden && style.isActiveClient)
7866 positionID = parent.GetPositionID(this);
7867 parent.numPositions++;
7868 if(state == minimized) parent.numIcons--;
7871 // *** FONT INHERITANCE ***
7872 if(!setFont && oldParent)
7873 stopwatching(oldParent, font);
7877 RemoveResource(systemFont);
7880 // TESTING WITH WATCHERS:
7881 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7882 // usedFont = setFont ? setFont : (systemFont);
7886 if(guiApp.currentSkin)
7888 systemFont = guiApp.currentSkin.SystemFont();
7891 usedFont = systemFont;
7892 AddResource(systemFont);
7900 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7909 if(value.rootWindow && value.rootWindow.display && rootWindow)
7911 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
7912 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
7915 UnloadGraphics(false);
7918 LoadGraphics(false, false);
7921 if(value.rootWindow != rootWindow)
7922 DisplayModeChanged();
7926 scrolledPos.x = MININT; // Prevent parent update
7927 property::anchor = anchor;
7931 if(guiApp.currentSkin)
7932 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
7934 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7935 Position(x, y, w, h, true, true, true, true, false, true);
7940 // else parent = value;
7943 get { return parent; }
7946 property Window master
7948 property_category $"Behavior"
7951 //if(this == value) return;
7952 if(value && value.IsSlaveOf(this)) return;
7958 OldLink slaveHolder;
7959 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
7960 if(slaveHolder.data == this)
7962 master.slaves.Delete(slaveHolder);
7969 value.slaves.Add(OldLink { data = this });
7974 master.hotKeys.Remove(hotKey);
7975 value.hotKeys.Add(hotKey);
7978 if(master && master.defaultControl == this)
7979 master.defaultControl = null;
7981 if(style.isDefault && !value.defaultControl)
7982 value.defaultControl = this;
7987 get { return master ? master : parent; }
7990 property char * caption
7992 property_category $"Appearance"
7999 caption = new char[strlen(value)+1];
8001 strcpy(caption, value);
8006 get { return caption; }
8011 property_category $"Behavior"
8020 master.hotKeys.Add(hotKey = HotKeySlot { });
8024 hotKey.window = this;
8029 master.hotKeys.Delete(hotKey);
8034 get { return hotKey ? hotKey.key : 0; }
8037 property Color background
8039 property_category $"Appearance"
8042 background.color = value;
8047 if(this == rootWindow)
8048 guiApp.interfaceDriver.SetRootWindowColor(this);
8051 get { return background.color; }
8054 property Percentage opacity
8056 property_category $"Appearance"
8059 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
8060 drawBehind = background.a ? false : true;
8062 get { return background.a / 255.0f; }
8065 property Color foreground
8067 property_category $"Appearance"
8075 get { return foreground; }
8078 property BorderStyle borderStyle
8080 property_category $"Appearance"
8083 if(!((BorderBits)value).fixed)
8085 style.hasClose = false;
8086 style.hasMaximize = false;
8087 style.hasMinimize = false;
8088 nativeDecorations = false;
8090 style.borderBits = value;
8094 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8096 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8097 Position(x, y, w, h, true, true, true, true, false, true);
8098 CreateSystemChildren();
8101 get { return (BorderStyle)style.borderBits; }
8104 property Size minClientSize
8106 property_category $"Layout"
8107 set { minSize = value; }
8108 get { value = minSize; }
8111 property Size maxClientSize
8113 property_category $"Layout"
8114 set { maxSize = value; }
8115 get { value = maxSize; }
8118 property bool hasMaximize
8120 property_category $"Window Style"
8123 style.hasMaximize = value;
8124 if(value) { style.fixed = true; style.contour = true; }
8128 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8130 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8131 Position(x, y, w, h, true, true, true, true, false, true);
8133 CreateSystemChildren();
8136 get { return style.hasMaximize; }
8139 property bool hasMinimize
8141 property_category $"Window Style"
8144 style.hasMinimize = value;
8145 if(value) { style.fixed = true; style.contour = true; }
8149 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8151 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8152 Position(x, y, w, h, true, true, true, true, false, true);
8154 CreateSystemChildren();
8157 get { return style.hasMinimize; }
8160 property bool hasClose
8162 property_category $"Window Style"
8165 style.hasClose = value;
8166 if(value) { style.fixed = true; style.contour = true; }
8170 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8171 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8172 Position(x, y, w, h, true, true, true, true, false, true);
8173 CreateSystemChildren();
8176 get { return style.hasClose; }
8179 property bool nonClient
8181 property_category $"Layout"
8184 style.nonClient = value;
8186 style.stayOnTop = true;
8188 get { return style.nonClient; }
8191 property bool inactive
8193 property_category $"Behavior"
8198 // *** NEW HERE: ***
8202 parent.childrenCycle.Delete(cycle);
8204 parent.childrenOrder.Delete(order);
8211 active = false; // true;
8212 if(parent.activeChild == this)
8213 parent.activeChild = null;
8214 if(parent.activeClient == this)
8215 parent.activeClient = null;
8224 parent.childrenCycle.Insert(
8225 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8226 cycle = OldLink { data = this });
8228 parent.childrenOrder.Insert(
8229 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8230 order = OldLink { data = this });
8233 style.inactive = value;
8235 get { return style.inactive; }
8238 property bool clickThrough
8240 property_category $"Behavior"
8241 set { style.clickThrough = value; }
8242 get { return style.clickThrough; }
8245 property bool isRemote
8247 property_category $"Behavior"
8248 set { style.isRemote = value; }
8249 get { return style.isRemote; }
8252 property bool noCycle
8254 property_category $"Behavior"
8255 set { style.noCycle = value; }
8256 get { return style.noCycle; }
8259 property bool isModal
8261 property_category $"Behavior"
8262 set { style.modal = value; }
8263 get { return style.modal; }
8266 property bool interim
8268 property_category $"Behavior"
8269 set { style.interim = value; }
8270 get { return style.interim; }
8273 property bool tabCycle
8275 property_category $"Behavior"
8276 set { style.tabCycle = value; }
8277 get { return style.tabCycle; }
8280 property bool isDefault
8282 property_category $"Behavior"
8290 /*for(sibling = parent.children.first; sibling; sibling = sibling.next)
8291 if(sibling != this && sibling.style.isDefault)
8292 sibling.style.isDefault = false;*/
8293 if(master.defaultControl)
8294 master.defaultControl.style.isDefault = false;
8295 master.defaultControl = this;
8297 else if(master.defaultControl == this)
8298 master.defaultControl = null;
8302 style.isDefault = value;
8304 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8306 get { return style.isDefault; }
8309 property bool drawBehind
8311 property_category $"Window Style"
8312 set { style.drawBehind = value; }
8313 get { return style.drawBehind; }
8316 property bool hasMenuBar
8318 property_category $"Window Style"
8328 if(created && !menuBar)
8335 anchor = Anchor { top = 23, left = 1, right = 1 },
8337 inactive = true, nonClient = true
8342 else if(created && menuBar)
8347 style.hasMenuBar = value;
8349 get { return style.hasMenuBar; }
8352 property bool hasStatusBar
8354 property_category $"Window Style"
8361 statusBar = StatusBar { this };
8369 style.hasStatusBar = value;
8371 get { return style.hasStatusBar; }
8373 property bool stayOnTop
8375 property_category $"Window Style"
8380 if(created && !style.stayOnTop)
8382 if(rootWindow == this)
8383 guiApp.interfaceDriver.OrderRootWindow(this, true);
8384 else if(parent.children.last != this)
8386 parent.children.Move(this, parent.children.last);
8390 style.stayOnTop = true;
8394 if(created && style.stayOnTop)
8396 if(rootWindow == this)
8397 guiApp.interfaceDriver.OrderRootWindow(this, false);
8404 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8405 order && ((Window)order.data).style.stayOnTop;
8406 order = (order == parent.childrenOrder.first) ? null : order.prev);
8407 last = order ? order.data : null;
8411 for(last = parent.children.last;
8412 last && last.style.stayOnTop;
8416 parent.children.Move(this, last);
8420 style.stayOnTop = false;
8423 get { return style.stayOnTop; }
8428 property_category $"Window Style"
8438 if(menuBar && !value)
8445 if(!menuBar && style.hasMenuBar && value)
8449 this, menu = value, isMenuBar = true,
8450 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8451 inactive = true, nonClient = true
8455 UpdateActiveDocument(null);
8458 get { return menu; }
8461 property FontResource font
8463 property_category $"Appearance"
8465 isset { return setFont ? true : false; }
8470 if(value && !setFont) { stopwatching(parent, font); }
8471 else if(!value && setFont)
8477 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8486 RemoveResource(setFont);
8491 RemoveResource(systemFont);
8498 AddResource(setFont);
8501 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8504 systemFont = guiApp.currentSkin.SystemFont();
8506 usedFont = systemFont;
8507 AddResource(systemFont);
8515 get { return usedFont; }
8518 property SizeAnchor sizeAnchor
8520 property_category $"Layout"
8523 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8524 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8525 sizeAnchor.isClientW != sizeAnchor.isClientH;
8532 normalSizeAnchor = sizeAnchor;
8534 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8536 stateAnchor = normalAnchor;
8537 stateSizeAnchor = normalSizeAnchor;
8539 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8540 Position(x,y, w, h, true, true, true, true, false, true);
8547 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8548 sizeAnchor.isClientW,
8549 sizeAnchor.isClientH
8556 property_category $"Layout"
8559 Anchor thisAnchor = anchor;
8560 SizeAnchor thisSizeAnchor = sizeAnchor;
8561 bool leftRight = (anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none);
8562 bool topBottom = (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none);
8563 bool isClient = !sizeAnchor.isClientW && !sizeAnchor.isClientH;
8564 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8565 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8566 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8572 sizeAnchor.isClientW = false;
8573 sizeAnchor.isClientH = false;
8574 sizeAnchor.size = value;
8576 normalSizeAnchor = sizeAnchor;
8578 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8580 stateAnchor = normalAnchor;
8581 stateSizeAnchor = normalSizeAnchor;
8583 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8584 Position(x, y, w, h, true, true, true, true, false, true);
8585 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
8588 get { value = size; }
8591 property Size clientSize
8593 property_category $"Layout"
8596 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8597 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8598 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8603 sizeAnchor.isClientW = true;
8604 sizeAnchor.isClientH = true;
8605 sizeAnchor.size = value;
8607 normalSizeAnchor = sizeAnchor;
8609 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8611 stateAnchor = normalAnchor;
8612 stateSizeAnchor = normalSizeAnchor;
8614 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8615 Position(x,y, w, h, true, true, true, true, false, true);
8618 get { value = clientSize; }
8621 property Size initSize { get { value = sizeAnchor.size; } };
8623 property Anchor anchor
8625 property_category $"Layout"
8626 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8632 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8634 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8635 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8637 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8639 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8640 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8644 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8646 anchor.left.distance = 0;
8647 anchor.horz.type = 0;
8649 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8651 anchor.top.distance = 0;
8652 anchor.vert.type = 0;
8661 normalAnchor = anchor;
8663 // Break the anchors for moveable/resizable windows
8664 /*if(style.fixed ) //&& value.left.type == cascade)
8666 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
8668 this.anchor = normalAnchor = Anchor { left = x, top = y };
8669 normalSizeAnchor = SizeAnchor { { w, h } };
8672 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8674 stateAnchor = normalAnchor;
8675 stateSizeAnchor = normalSizeAnchor;
8677 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8678 Position(x, y, w, h, true, true, true, true, false, true);
8687 get { value = this ? anchor : Anchor { }; }
8690 property Point position
8692 property_category $"Layout"
8695 if(value == null) return;
8697 anchor.left = value.x;
8698 anchor.top = value.y;
8699 anchor.right.type = none;
8700 anchor.bottom.type = none;
8705 normalAnchor = anchor;
8707 // Break the anchors for moveable/resizable windows
8711 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8713 normalAnchor.left = x;
8714 normalAnchor.top = y;
8715 normalAnchor.right.type = none;
8716 normalAnchor.bottom.type = none;
8717 normalSizeAnchor.size.width = w;
8718 normalSizeAnchor.size.height = h;
8722 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8724 stateAnchor = normalAnchor;
8725 stateSizeAnchor = normalSizeAnchor;
8727 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8728 Position(x,y, w, h, true, true, true, true, false, true);
8732 get { value = position; }
8735 property bool disabled
8737 property_category $"Behavior"
8740 if(this && disabled != value)
8747 get { return (bool)disabled; }
8750 property bool isEnabled
8755 for(parent = this; parent; parent = parent.parent)
8762 property WindowState state
8764 property_category $"Behavior"
8765 set { SetState(value, false, 0); }
8766 get { return this ? state : 0; }
8769 property bool visible
8771 property_category $"Behavior"
8774 if(this && !value && !style.hidden && parent)
8776 bool wasActiveChild = parent.activeChild == this;
8777 Window client = null;
8779 style.hidden = true;
8780 if(style.isActiveClient)
8782 parent.numPositions--;
8783 if(state == minimized) parent.numIcons--;
8788 OldLink prevOrder = null;
8790 if(rootWindow == this)
8791 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
8794 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
8797 box.left -= parent.clientStart.x;
8798 box.top -= parent.clientStart.y;
8799 box.right -= parent.clientStart.x;
8800 box.bottom -= parent.clientStart.y;
8804 if(_isModal && master && master.modalSlave == this)
8805 master.modalSlave = null;
8809 OldLink tmpPrev = order.prev;
8810 client = tmpPrev ? tmpPrev.data : null;
8811 if(client && !client.style.hidden && !client.destroyed && client.created)
8812 prevOrder = tmpPrev;
8815 client = tmpPrev ? tmpPrev.data : null;
8816 if(client == this) { client = null; break; }
8817 if(client && ((client.style.hidden) || client.destroyed || !client.created))
8819 tmpPrev = client.order.prev;
8824 prevOrder = tmpPrev;
8829 // If this window can be an active client, make sure the next window we activate can also be one
8830 if(!style.nonClient && style.isActiveClient)
8832 tmpPrev = prevOrder;
8835 client = tmpPrev ? tmpPrev.data : null;
8836 if(client == this) { client = null; break; }
8837 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
8839 tmpPrev = client.order.prev;
8844 prevOrder = tmpPrev;
8848 if(client && client.style.hidden) client = null;
8852 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
8854 if(order && prevOrder && prevOrder.data != this)
8855 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
8857 ActivateEx(false, false, false, true, null, null);
8859 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
8860 if(parent.activeClient == this)
8862 parent.activeClient = null;
8863 parent.UpdateActiveDocument(null);
8866 else if(parent.activeClient == this)
8868 parent.activeClient = client;
8869 parent.UpdateActiveDocument(this);
8872 // *** Not doing this anymore ***
8875 parent.childrenCycle.Delete(cycle);
8877 parent.childrenOrder.Delete(order);
8882 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8887 else if(this && value && style.hidden)
8889 style.hidden = false;
8892 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8893 if(rootWindow == this)
8894 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
8896 if(_isModal && master)
8897 master.modalSlave = this;
8899 if(style.isActiveClient)
8901 positionID = parent.GetPositionID(this);
8902 parent.numPositions++;
8903 if(state == minimized) parent.numIcons++;
8906 // *** NOT DOING THIS ANYMORE ***
8908 if(!(style.inactive))
8910 if(!(style.noCycle))
8912 cycle = parent.childrenCycle.AddAfter(
8913 (parent.activeChild && parent.activeChild.cycle) ?
8914 parent.activeChild.cycle.prev : null, sizeof(OldLink));
8917 order = parent.childrenOrder.AddAfter(
8918 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8925 if(true || !parent.activeChild)
8926 ActivateEx(true, false, true, true, null, null);
8928 if(creationActivation == activate)
8929 ActivateEx(true, false, true, true, null, null);
8930 else if(creationActivation == flash && !object)
8933 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8937 ConsequentialMouseMove(false);
8943 style.hidden = !value;
8946 get { return (style.hidden || !setVisible) ? false : true; }
8949 property bool isDocument
8951 property_category $"Document"
8952 set { style.isDocument = value; }
8953 get { return style.isDocument; }
8956 property bool mergeMenus
8958 property_category $"Window Style"
8959 set { mergeMenus = value; }
8960 get { return (bool)mergeMenus; }
8963 property bool hasHorzScroll
8965 property_category $"Window Style"
8970 if(!style.hasHorzScroll && created)
8972 CreateSystemChildren();
8973 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8976 else if(style.hasHorzScroll)
8980 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8982 style.hasHorzScroll = value;
8985 get { return style.hasHorzScroll; }
8988 property bool hasVertScroll
8990 property_category $"Window Style"
8995 if(!style.hasVertScroll && created)
8997 style.hasVertScroll = true;
8998 CreateSystemChildren();
8999 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9002 else if(style.hasVertScroll)
9006 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
9008 style.hasVertScroll = value;
9010 get { return style.hasVertScroll; }
9013 property bool dontHideScroll
9015 property_category $"Behavior"
9018 scrollFlags.dontHide = value;
9021 //UpdateScrollBars(true, true);
9022 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9026 // UpdateScrollBars(true, true);
9027 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9030 get { return scrollFlags.dontHide; }
9033 property bool dontScrollVert
9035 property_category $"Behavior"
9036 set { style.dontScrollVert = value; }
9037 get { return style.dontScrollVert; }
9039 property bool dontScrollHorz
9041 property_category $"Behavior"
9042 set { style.dontScrollHorz = value; }
9043 get { return style.dontScrollHorz; }
9046 property bool snapVertScroll
9048 property_category $"Behavior"
9051 scrollFlags.snapY = value;
9052 if(sbv) sbv.snap = value;
9054 get { return scrollFlags.snapY; }
9056 property bool snapHorzScroll
9058 property_category $"Behavior"
9061 scrollFlags.snapX = value;
9062 if(sbh) sbh.snap = value;
9064 get { return scrollFlags.snapX; }
9067 property Point scroll
9069 property_category $"Behavior"
9073 // TESTING THIS IMPLEMENTATION:
9074 SetScrollPosition(value.x, value.y);
9076 get { value = scroll; }
9079 property bool modifyVirtualArea
9081 property_category $"Behavior"
9082 set { modifyVirtArea = value; }
9083 get { return (bool)modifyVirtArea; }
9086 property char * fileName
9088 property_category $"Document"
9091 if(menu && ((!fileName && value) || (fileName && !value)))
9093 MenuItem item = menu.FindItem(MenuFileSave, 0);
9094 if(item) item.disabled = !modifiedDocument && value;
9099 if(value && value[0])
9100 fileName = CopyString(value);
9102 if(parent && this == parent.activeClient)
9103 parent.UpdateActiveDocument(null);
9107 // if(style.isDocument)
9109 fileMonitor.fileName = value;
9111 get { return fileName; }
9116 property_category $"Data"
9121 property bool modifiedDocument
9123 property_category $"Document"
9126 if(style.isDocument || fileName)
9130 MenuItem item = menu.FindItem(MenuFileSave, 0);
9131 if(item) item.disabled = !value && fileName;
9135 if(modifiedDocument != value)
9137 modifiedDocument = value;
9138 if(style.isDocument || fileName)
9142 get { return (bool)modifiedDocument; }
9145 property bool showInTaskBar
9147 property_category $"Window Style"
9148 set { style.showInTaskBar = value; }
9149 get { return (style.showInTaskBar; }
9151 property FileDialog saveDialog { set { saveDialog = value; } };
9152 property bool isActiveClient
9154 property_category $"Behavior"
9155 set { style.isActiveClient = value; }
9156 get { return style.isActiveClient; }
9159 property Cursor cursor
9161 property_category $"Appearance"
9165 SelectMouseCursor();
9167 get { return cursor; }
9170 //#if !defined(ECERE_VANILLA)
9171 property char * name
9173 property_category $"Design"
9176 return (this && object) ? object.name : null;
9181 activeDesigner.RenameObject(object, value);
9185 property char * displayDriver
9187 property_category $"Behavior"
9190 dispDriver = GetDisplayDriver(value);
9191 //DisplayModeChanged();
9195 return dispDriver ? dispDriver.name : null;
9199 // RUNTIME PROPERTIES
9200 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9201 property Size scrollArea
9203 property_category $"Behavior"
9207 SetScrollArea(value.w, value.h, false);
9209 SetScrollArea(0,0, true);
9211 get { value = scrollArea; }
9214 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9219 property_category $"Layout"
9220 set { if(this) is3D = value; }
9221 get { return (bool)is3D; }
9224 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9226 // Will be merged with font later
9227 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9228 property Point clientStart { get { value = clientStart; } };
9229 property Point absPosition { get { value = absPosition; } };
9230 property Anchor normalAnchor { get {value = normalAnchor; } };
9231 // property Size normalSizeAnchor { get { value = normalSizeAnchor; } };
9232 property bool active { get { return (bool)active; } };
9233 property bool created { get { return (bool)created; } };
9234 property bool destroyed { get { return (bool)destroyed; } };
9235 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9236 property Window firstChild { get { return children.first; } };
9237 property Window lastChild { get { return children.last; } };
9238 property Window activeClient { get { return activeClient; } };
9239 property Window activeChild { get { return activeChild; } };
9240 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9241 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9242 property ScrollBar horzScroll { get { return sbh; } };
9243 property ScrollBar vertScroll { get { return sbv; } };
9244 property StatusBar statusBar { get { return statusBar; } };
9245 property Window rootWindow { get { return rootWindow; } };
9246 property bool closing { get { return (bool)closing; } set { closing = value; } };
9247 property int documentID { get { return documentID; } };
9248 property Window previous { get { return prev; } }
9249 property Window next { get { return next; } }
9250 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9251 property PopupMenu menuBar { get { return menuBar; } }
9252 property ScrollBar sbv { get { return sbv; } }
9253 property ScrollBar sbh { get { return sbh; } }
9254 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9255 property void * systemHandle { get { return windowHandle; } }
9256 property Button minimizeButton { get { return sysButtons[0]; } };
9257 property Button maximizeButton { get { return sysButtons[1]; } };
9258 property Button closeButton { get { return sysButtons[2]; } };
9259 property BitmapResource icon
9261 get { return icon; }
9265 if(icon) incref icon;
9267 guiApp.interfaceDriver.SetIcon(this, value);
9270 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9271 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } };
9272 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9273 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9274 property bool nativeDecorations
9276 get { return (bool)nativeDecorations; }
9277 set { nativeDecorations = value; }
9278 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
9279 isset { return (nativeDecorations && (rootWindow == this || (formDesigner && activeDesigner && ((FormDesigner)activeDesigner.classDesigner).form && parent == ((FormDesigner)activeDesigner.classDesigner).form.parent))) != style.fixed; }
9282 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9284 property char * text
9286 property_category $"Deprecated"
9288 set { property::caption = value; }
9289 get { return property::caption; }
9295 WindowBits style; // Window Style
9296 char * caption; // Name / Caption
9297 Window parent; // Parent window
9298 OldList children; // List of children in Z order
9299 Window activeChild; // Child window having focus
9300 Window activeClient;
9301 Window previousActive; // Child active prior to activating the default child
9302 Window master; // Window owning and receiving notifications concerning this window
9303 OldList slaves; // List of windows belonging to this window
9304 Display display; // Display this window is drawn into
9306 Point position; // Position in parent window client area
9307 Point absPosition; // Absolute position
9308 Point clientStart; // Client area position from (0,0) in this window
9310 Size clientSize; // Client area size
9311 Size scrollArea; // Virtual Scroll area size
9312 Size reqScrollArea; // Requested virtual area size
9313 Point scroll; // Virtual area scrolling position
9314 public ScrollBar sbh, sbv; // Scrollbar window handles
9315 Cursor cursor; // Mouse cursor used for this window
9318 StatusBar statusBar;
9319 Button sysButtons[3];
9321 Box clientArea; // Client Area box clipped to parent
9323 HotKeySlot hotKey; // HotKey for this window
9327 ScrollFlags scrollFlags;// Window Scrollbar Flags
9328 int id; // Control ID
9330 ColorAlpha background; // Background color used to draw the window area
9332 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9333 OldList childrenCycle; // Cycling order
9334 OldLink cycle; // Element of parent's cycling order
9335 OldList childrenOrder; // Circular Z-Order
9336 OldLink order; // Element of parent's circular Z-Order
9337 Window modalSlave; // Slave window blocking this window's interaction
9339 Window rootWindow; // Topmost system managed window
9340 void * windowHandle; // System window handle
9342 DialogResult returnCode;// Return code for modal windows
9344 Point sbStep; // Scrollbar line scrolling steps
9347 SizeAnchor stateSizeAnchor;
9349 Anchor normalAnchor;
9350 SizeAnchor normalSizeAnchor;
9352 Size skinMinSize; // Minimal window size based on style
9353 Point scrolledPos; // Scrolled position
9354 Box box; // Window box clipped to parent
9355 Box * against; // What to clip the box to
9357 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9358 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9359 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9360 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9361 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9362 Point scrolledArea; // Distance to scroll area by
9363 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9365 OldList hotKeys; // List of the hotkeys of all children
9366 Window defaultControl; // Default child control
9370 ColorAlpha * palette; // Color palette used for this window
9372 int caretSize; // Size of caret, non zero if a caret is present
9373 Point caretPos; // Caret position
9375 void * systemParent; // Parent System Window for embedded windows
9382 WindowState lastState;
9384 FileMonitor fileMonitor
9386 this, FileChange { modified = true };
9388 bool OnFileNotify(FileChange action, char * param)
9391 fileMonitor.StopMonitoring();
9392 if(OnFileModified(action, param))
9393 fileMonitor.StartMonitoring();
9398 FontResource setFont, systemFont;
9399 FontResource usedFont;
9400 FontResource captionFont;
9402 FileDialog saveDialog;
9404 SizeAnchor sizeAnchor;
9406 // FormDesigner data
9409 Extent * tempExtents; //[4];
9410 BitmapResource icon;
9412 CreationActivationOption creationActivation;
9415 bool active:1; // true if window and ancestors are active
9416 bool acquiredInput:1; // true if the window is processing state based input
9417 bool modifiedDocument:1;
9418 bool disabled:1; // true if window cannot interact
9419 bool isForegroundWindow:1;// true while a root window is being activated
9420 bool visible:1; // Visibility flag
9421 bool destroyed:1; // true if window is being destroyed
9422 bool anchored:1; // true if this window is repositioned when the parent resizes
9423 bool dirty:1; // Flag set to true if any descendant must be redrawn
9429 bool modifyVirtArea:1;
9430 bool noAutoScrollArea:1;
9433 bool setVisible:1; // FOR FORM DESIGNER
9439 bool useSharedMemory:1;
9442 bool nativeDecorations:1;
9443 bool manageDisplay:1;
9444 bool formDesigner:1; // True if we this is running in the form editor
9447 // Checks used internally for them not to take effect in FormDesigner
9448 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9449 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9451 WindowController controller;
9452 public property WindowController controller { get { return controller; } set { delete controller; controller = value; if(controller) incref controller; } }
9455 public class CommonControl : Window
9457 // creationActivation = doNothing;
9460 public property String toolTip
9462 property_category $"Appearance"
9465 if(created) CommonControl::OnDestroy();
9467 toolTip = value ? ToolTip { tip = value; } : null;
9469 if(created) CommonControl::OnCreate();
9471 get { return toolTip ? toolTip.tip : null; }
9477 // (Very) Ugly work around for the fact that the parent watcher
9478 // won't fire when it's already been disconnected...
9479 eInstance_FireSelfWatchers(toolTip,
9480 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
9486 toolTip.parent = this;
9495 public class Percentage : float
9497 char * OnGetString(char * string, float * fieldData, bool * needClass)
9501 sprintf(string, "%.2f", this);
9502 c = strlen(string)-1;
9505 if(string[c] != '0')
9506 last = Max(last, c);
9507 if(string[c] == '.')
9520 public void ApplySkin(Class c, char * name, void ** vTbl)
9522 char className[1024];
9527 subclass(Window) wc = (subclass(Window))c;
9528 subclass(Window) base = (subclass(Window))c.base;
9530 sprintf(className, "%sSkin_%s", name, c.name);
9531 wc.pureVTbl = c._vTbl;
9532 c._vTbl = new void *[c.vTblSize];
9533 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9534 sc = eSystem_FindClass(c.module.application, className);
9538 for(m = 0; m < c.base.vTblSize; m++)
9540 if(c._vTbl[m] == base.pureVTbl[m])
9541 c._vTbl[m] = vTbl[m];
9546 for(m = 0; m < c.vTblSize; m++)
9548 if(sc._vTbl[m] != wc.pureVTbl[m])
9549 c._vTbl[m] = sc._vTbl[m];
9553 for(d = c.derivatives.first; d; d = d.next)
9555 ApplySkin(d.data, name, c._vTbl);
9559 public void UnapplySkin(Class c)
9561 char className[1024];
9563 subclass(Window) wc = (subclass(Window))c;
9564 subclass(Window) base = (subclass(Window))c.base;
9567 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9570 c._vTbl = wc.pureVTbl;
9574 for(d = c.derivatives.first; d; d = d.next)
9576 UnapplySkin(d.data);
9580 void CheckFontIntegrity(Window window)
9585 if(window.usedFont && window.usedFont.font == 0xecececec)
9587 FontResource uf = window.usedFont;
9588 char * className = window._class.name;
9589 char * text = window.text;
9592 for(c = window.firstChild; c; c = c.next)
9593 CheckFontIntegrity(c);
9597 public class ControllableWindow : Window
9599 /*WindowController controller;
9600 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9601 ~ControllableWindow() { delete controller; }*/
9604 class WindowControllerInterface : ControllableWindow
9606 bool OnKeyDown(Key key, unichar ch)
9608 bool result = ((int(*)())(void *)controller.OnKeyDown)((void *)controller.controlled, (void *)controller, key, ch);
9610 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown](controller.window, key, ch);
9614 bool OnKeyUp(Key key, unichar ch)
9616 bool result = ((int(*)())(void *)controller.OnKeyUp)((void *)controller.controlled, (void *)controller, key, ch);
9618 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp](controller.window, key, ch);
9622 bool OnKeyHit(Key key, unichar ch)
9624 bool result = ((int(*)())(void *)controller.OnKeyHit)((void *)controller.controlled, (void *)controller, key, ch);
9626 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit](controller.window, key, ch);
9630 bool OnMouseMove(int x, int y, Modifiers mods)
9632 bool result = ((int(*)())(void *)controller.OnMouseMove)((void *)controller.controlled, (void *)controller, x, y, mods);
9634 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove](controller.window, x, y, mods);
9638 bool OnLeftButtonDown(int x, int y, Modifiers mods)
9640 bool result = ((int(*)())(void *)controller.OnLeftButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9642 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown](controller.window, x, y, mods);
9646 bool OnLeftButtonUp(int x, int y, Modifiers mods)
9648 bool result = ((int(*)())(void *)controller.OnLeftButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9650 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp](controller.window, x, y, mods);
9654 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
9656 bool result = ((int(*)())(void *)controller.OnLeftDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9658 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick](controller.window, x, y, mods);
9662 bool OnRightButtonDown(int x, int y, Modifiers mods)
9664 bool result = ((int(*)())(void *)controller.OnRightButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9666 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown](controller.window, x, y, mods);
9670 bool OnRightButtonUp(int x, int y, Modifiers mods)
9672 bool result = ((int(*)())(void *)controller.OnRightButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9674 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp](controller.window, x, y, mods);
9678 bool OnRightDoubleClick(int x, int y, Modifiers mods)
9680 bool result = ((int(*)())(void *)controller.OnRightDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9682 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick](controller.window, x, y, mods);
9686 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
9688 bool result = ((int(*)())(void *)controller.OnMiddleButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9690 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown](controller.window, x, y, mods);
9694 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
9696 bool result = ((int(*)())(void *)controller.OnMiddleButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9698 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp](controller.window, x, y, mods);
9702 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
9704 bool result = ((int(*)())(void *)controller.OnMiddleDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9706 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick](controller.window, x, y, mods);
9710 void OnResize(int width, int height)
9712 ((int(*)())(void *)controller.OnResize)((void *)controller.controlled, (void *)controller, width, height);
9713 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize](controller.window, width, height);
9716 void OnRedraw(Surface surface)
9718 ((int(*)())(void *)controller.OnRedraw)((void *)controller.controlled, (void *)controller, surface);
9719 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw](controller.window, surface);
9724 bool result = ((int(*)())(void *)controller.OnCreate)((void *)controller.controlled, (void *)controller);
9726 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
9730 bool OnLoadGraphics()
9732 bool result = ((int(*)())(void *)controller.OnLoadGraphics)((void *)controller.controlled, (void *)controller);
9734 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLoadGraphics](controller.window);
9738 void OnUnloadGraphics()
9740 ((int(*)())(void *)controller.OnUnloadGraphics)((void *)controller.controlled, (void *)controller);
9741 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnUnloadGraphics](controller.window);
9745 public class WindowController<class V>
9748 property Window window
9752 uint size = class(Window).vTblSize;
9755 windowVTbl = new void *[size];
9756 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
9757 if(value._vTbl == value._class._vTbl)
9759 value._vTbl = new void *[value._class.vTblSize];
9760 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
9764 for(c = 0; c < size; c++)
9766 void * function = class(WindowControllerInterface)._vTbl[c];
9767 if(function != DefaultFunction)
9768 value._vTbl[c] = function;
9770 value._vTbl[c] = windowVTbl[c];
9775 memcpy(value._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
9778 get { return window; }
9780 property V controlled
9782 set { controlled = value; }
9783 get { return controlled; }
9785 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
9786 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
9787 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
9788 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
9789 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
9790 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
9791 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9792 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
9793 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
9794 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9795 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
9796 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
9797 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9798 virtual void V::OnResize(WindowController controller, int width, int height);
9799 virtual void V::OnRedraw(WindowController controller, Surface surface);
9800 virtual bool V::OnCreate(WindowController controller);
9801 virtual bool V::OnLoadGraphics(WindowController controller);
9802 virtual void V::OnUnloadGraphics(WindowController controller);
9805 int (** windowVTbl)();