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 text;
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;
543 // scrollFlags = ScrollFlags { snapX = true, snapY = true };
544 sbStep.x = sbStep.y = 8;
546 if(guiApp) // dynamic_cast<GuiApplication>(thisModule)
548 cursor = guiApp.GetCursor(arrow);
549 property::parent = guiApp.desktop;
561 stopwatching(parent, font);
562 if(parent.activeChild == this)
563 parent.activeChild = null;
564 if(parent.activeClient == this)
565 parent.activeClient = null;
570 // Prevent destructor from being called again...
576 /////////////////////////////////
579 OldLink slave = master.slaves.FindLink(this);
580 master.slaves.Delete(slave);
587 parent.childrenCycle.Remove(cycle);
589 parent.childrenOrder.Remove(order);
590 parent.children.Remove(this);
595 /////////////////////////////////
597 while(ptr = resources.first)
600 resources.Delete(ptr);
607 for(child = children.first; child; child = child.next)
609 // child.stopwatching(this, font);
611 eInstance_StopWatching(this, __ecereProp___ecereNameSpace__ecere__gui__Window_font, child);
612 // Don't want property here
613 *&child.parent = null;
616 while(slave = slaves.first)
618 // Don't want property here
619 *&((Window)slave.data).master = null;
620 slaves.Delete(slave);
623 // Because we do a decref in DestroyEx...
631 // Why was this commented?
632 //if(this != guiApp.desktop)
645 if(((subclass(Window))_class).pureVTbl)
647 if(_vTbl == _class._vTbl)
649 _vTbl = ((subclass(Window))_class).pureVTbl;
654 for(m = 0; m < _class.vTblSize; m++)
656 if(_vTbl[m] == _class._vTbl[m])
657 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
661 if(_vTbl == ((subclass(Window))_class).pureVTbl || _vTbl == _class._vTbl)
664 dirtyArea.Free(null);
665 renderArea.Free(null);
666 overRenderArea.Free(null);
667 clipExtent.Free(null);
668 scrollExtent.Free(null);
669 dirtyBack.Free(null);
673 tempExtents[0].Free(null);
674 tempExtents[1].Free(null);
675 tempExtents[2].Free(null);
676 tempExtents[3].Free(null);
681 //#if !defined(ECERE_VANILLA)
682 char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
684 if(this == activeDesigner)
688 char * name = property::name;
689 return name ? name : "";
694 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
695 bool OnGetDataFromString(char * string)
697 FormDesigner designer = (FormDesigner)activeDesigner.classDesigner;
700 if(!strcmp(string, "this") || !strcmp(string, designer.form.name))
701 this = designer.form;
702 else if(!strcmpi(string, "(Desktop)"))
703 this = activeDesigner;
705 return activeDesigner.FindObject(&this, string);
711 // --- Window updates system ---
713 // Setup a bitmap for Redrawing on client area of Window
714 Surface Redraw(Box box)
716 Surface surface = null;
718 Box clientArea = this.clientArea;
722 mox.left -= clientStart.x;
723 mox.top -= clientStart.y;
724 mox.right -= clientStart.x;
725 mox.bottom -= clientStart.y;
727 mox.Clip(clientArea);
728 // mox.ClipOffset(against, scrolledPos.x, scrolledPos.y);
730 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && mox.right >= mox.left && mox.bottom >= mox.top)
732 int x = absPosition.x + clientStart.x;
733 int y = absPosition.y + clientStart.y;
734 if(rootWindow.nativeDecorations)
736 x -= rootWindow.clientStart.x;
737 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
739 if(!guiApp.fullScreenMode || is3D)
741 x -= rootWindow.absPosition.x;
742 y -= rootWindow.absPosition.y;
746 x += rootWindow.parent.clientStart.x;
747 y += rootWindow.parent.clientStart.y;
749 mox.left += rootWindow.parent.clientStart.x;
750 mox.top += rootWindow.parent.clientStart.y;
751 mox.right += rootWindow.parent.clientStart.x;
752 mox.bottom += rootWindow.parent.clientStart.y;
757 surface = display.GetSurface(x, y, mox);
760 surface.width = clientSize.w;
761 surface.height = clientSize.h;
767 // Setup a bitmap for Redrawing on full Window
768 Surface RedrawFull(Box box)
770 Surface surface = null;
778 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && box.right >= box.left && box.bottom >= box.top)
780 int x = absPosition.x;
781 int y = absPosition.y;
782 if(rootWindow.nativeDecorations)
784 x -= rootWindow.clientStart.x;
785 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
787 if(!guiApp.fullScreenMode || is3D)
789 x -= rootWindow.absPosition.x;
790 y -= rootWindow.absPosition.y;
793 x += rootWindow.parent.clientStart.x;
794 y += rootWindow.parent.clientStart.y;
796 mox.left += rootWindow.parent.clientStart.x;
797 mox.top += rootWindow.parent.clientStart.y;
798 mox.right += rootWindow.parent.clientStart.x;
799 mox.bottom += rootWindow.parent.clientStart.y;
804 surface = display.GetSurface(x, y, mox);
807 surface.width = size.w;
808 surface.height = size.h;
814 void FigureCaption(char * caption)
818 strcpy(caption, this.caption);
819 if(style.isDocument || fileName)
821 if(caption[0]) strcat(caption, " - ");
823 strcat(caption, fileName);
827 sprintf(title, "Untitled %d", documentID);
828 strcat(caption, title);
831 strcat(caption, " *");
833 if(activeClient && menuBar &&
834 activeClient.state == maximized)
836 if(activeClient.caption)
838 if(caption[0]) strcat(caption, " - ");
839 strcat(caption, activeClient.caption);
841 if(activeClient.style.isDocument || activeClient.fileName)
843 if(caption[0]) strcat(caption, " - ");
844 strcat(caption, "[");
845 if(activeClient.fileName)
846 strcat(caption, activeClient.fileName);
850 sprintf(title, "Untitled %d", activeClient.documentID);
851 strcat(caption, title);
853 if(activeClient.modifiedDocument)
854 strcat(caption, " *");
855 strcat(caption, "]");
860 // Code for returning dirty from ScrollDisplay:
862 for(d = 0; d<scrollExtent.count; d++)
864 Box * box = &scrollExtent.boxes[d];
870 Min(box.right, box.left-scroll.x),box.bottom
872 dirtyArea.UnionBox(update);
878 Max(box.left, box.right-scroll.x), box.top,
879 box.right, box.bottom
881 dirtyArea.UnionBox(update);
889 box.right, Min(box.bottom, box.top-scroll.y),
891 dirtyArea.UnionBox(update);
897 box.left, Max(box.top, box.bottom-scroll.y),
898 box.right, box.bottom
900 dirtyArea.UnionBox(update);
905 void UpdateDecorations(void)
907 // TODO: *** TEMPORARY HACK ***
914 Update({ -clientStart.x, -clientStart.y, -clientStart.x + size.w-1, 0 });
916 Update({ -clientStart.x, clientSize.h, -clientStart.x + size.w-1, -clientStart.y + size.h-1 });
918 Update({ -clientStart.x,0, -1, clientSize.h-1 });
920 Update({ clientSize.w, 0, -clientStart.x + size.w-1, clientSize.h-1 });
923 // Returns w & h for Position
924 void ComputeAnchors(Anchor anchor, SizeAnchor sizeAnchor, int *ox, int *oy, int *ow, int *oh)
926 Window parent = this.parent ? this.parent : guiApp.desktop;
927 int vpw = parent ? parent.clientSize.w : 0;
928 int vph = parent ? parent.clientSize.h : 0;
929 int pw = parent ? parent.clientSize.w : 0;
930 int ph = parent ? parent.clientSize.h : 0;
931 int w = sizeAnchor.size.w, h = sizeAnchor.size.h;
932 int x = anchor.left.distance, y = anchor.top.distance;
934 MinMaxValue ew = 0, eh = 0;
936 float cascadeW, cascadeH;
938 int tilingW, tilingH, tilingSplit, tilingLastH;
939 int addX = 0, addY = 0;
941 if(parent && rootWindow == this && guiApp && guiApp.interfaceDriver)
943 Window masterWindow = this;
944 Box box { addX, addY, addX + vpw - 1, addY + vph - 1 };
947 if(master == guiApp.desktop)
948 masterWindow = guiApp.desktop.activeChild;
950 masterWindow = master.rootWindow;
951 if(!masterWindow) masterWindow = this;
953 guiApp.interfaceDriver.GetScreenArea(masterWindow, box);
954 if((anchor.left.type == offset && anchor.right.type == offset) || anchor.left.type == none)
957 pw = vpw = box.right - box.left + 1;
959 if((anchor.top.type == offset && anchor.bottom.type == offset) || anchor.top.type == none)
962 ph = vph = box.bottom - box.top + 1;
978 vpw = pw = parent.size.w;
979 vph = ph = parent.size.h;
981 else if(!style.fixed /*|| style.isDocument*/)
983 if(!style.dontScrollHorz && parent.scrollArea.w) vpw = parent.scrollArea.w;
984 if(!style.dontScrollVert && parent.scrollArea.h) vph = parent.scrollArea.h;
986 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
989 Desktop3D_FixSize(&pw, &ph);
990 Desktop3D_FixSize(&vpw, &vph);
993 if(pw < skinMinSize.w) pw = skinMinSize.w;
994 if(ph < skinMinSize.h) ph = skinMinSize.h;
995 if(vpw < skinMinSize.w) vpw = skinMinSize.w;
996 if(vph < skinMinSize.h) vph = skinMinSize.h;
998 // TODO: Must fix what we're snapping
1001 if(anchor.left.type)
1003 SNAPUP(x, textCellW);
1005 else if(anchor.right.type)
1007 SNAPDOWN(x, textCellW);
1012 SNAPUP(y, textCellH);
1014 else if(anchor.bottom.type)
1016 SNAPDOWN(y, textCellH);
1020 // This is required to get proper initial decoration size using native decorations on Windows
1021 if(nativeDecorations && guiApp && guiApp.interfaceDriver && !visible)
1022 guiApp.interfaceDriver.PositionRootWindow(this, x, y, Max(1, size.w), Max(1, size.h), true, true);
1023 GetDecorationsSize(&ew, &eh);
1025 if(anchor.left.type >= cascade && (state == normal /*|| state == Hidden*/))
1027 if(parent.sbv && !parent.sbv.style.hidden)
1028 pw += guiApp.currentSkin.VerticalSBW();
1029 if(parent.sbh && !parent.sbh.style.hidden)
1030 ph += guiApp.currentSkin.HorizontalSBH();
1032 if(anchor.left.type == cascade)
1034 w = (int)(pw * 0.80);
1035 h = (int)(ph * 0.80);
1037 else if(anchor.left.type >= vTiled)
1042 numTiling = parent.numPositions - parent.numIcons;
1043 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1044 if(anchor.left.type == vTiled)
1046 tilingH = (int)sqrt(numTiling);
1047 tilingW = numTiling / tilingH;
1051 tilingW = (int)sqrt(numTiling);
1052 tilingH = numTiling / tilingW;
1055 leftOver = numTiling - tilingH * tilingW;
1058 tilingSplit = (tilingW - leftOver) * tilingH;
1059 tilingLastH = tilingH+1;
1062 tilingSplit = numTiling;
1064 if(positionID >= tilingSplit)
1066 x = pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
1067 y = ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
1068 x2 = pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
1069 y2 = ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
1073 x = pw * (positionID / tilingH) / tilingW;
1074 y = ph * (positionID % tilingH) / tilingH;
1075 x2 = pw * (positionID / tilingH + 1) / tilingW;
1076 y2 = ph * ((positionID % tilingH) + 1) / tilingH;
1080 SNAPDOWN(x, textCellW);
1081 SNAPDOWN(y, textCellH);
1082 SNAPDOWN(x2, textCellW);
1083 SNAPDOWN(y2, textCellH);
1091 if(sizeAnchor.isClientW) w += ew;
1092 if(sizeAnchor.isClientH) h += eh;
1094 if(anchor.left.type == offset)
1095 x = anchor.left.distance;
1096 else if(anchor.left.type == relative)
1097 x = (anchor.left.percent < 0) ? ((int)(vpw * anchor.left.percent - 0.5)) : (int)(vpw * anchor.left.percent + 0.5);
1098 else if(anchor.right.type == relative)
1099 // ex = (anchor.right.percent < 0) ? ((int)(vpw * anchor.right.percent + 0)) : ((int)(vpw * anchor.right.percent + 0));
1100 ex = (anchor.right.percent < 0) ? ((int)(vpw * (1.0-anchor.right.percent) + 0)) : ((int)(vpw * (1.0-anchor.right.percent) + 0));
1101 else if(anchor.right.type == offset)
1102 ex = vpw - anchor.right.distance;
1104 if(anchor.top.type == offset)
1105 y = anchor.top.distance;
1106 else if(anchor.top.type == relative)
1107 y = (anchor.top.percent < 0) ? ((int)(vph * anchor.top.percent - 0.5)) : ((int)(vph * anchor.top.percent + 0.5));
1108 else if(anchor.bottom.type == relative)
1109 //ey = (anchor.bottom.percent < 0) ? ((int)(vph * anchor.bottom.percent + 0)) : ((int)(vph * anchor.bottom.percent + 0));
1110 ey = (anchor.bottom.percent < 0) ? ((int)(vph * (1.0-anchor.bottom.percent) + 0)) : ((int)(vph * (1.0-anchor.bottom.percent) + 0));
1111 else if(anchor.bottom.type == offset)
1112 ey = vph - anchor.bottom.distance;
1114 if(anchor.left.type && anchor.right.type)
1116 switch(anchor.right.type)
1119 ex = pw * (1.0f-anchor.right.percent);
1120 w = Max((int)(ex + 0.5) - x, 0);
1123 ex = vpw - anchor.right.distance;
1124 w = Max((int)(ex + 0.5) - x, 0);
1128 if(anchor.top.type && anchor.bottom.type)
1130 switch(anchor.bottom.type)
1133 ey = ph * (1.0f-anchor.bottom.percent);
1134 h = Max((int)(ey + 0.5) - y, 0);
1137 ey = vph - anchor.bottom.distance;
1138 h = Max((int)(ey + 0.5) - y, 0);
1147 if(state == normal /*|| state == Hidden*/)
1149 bool addSbV = false, addSbH = false;
1151 if(sizeAnchor.isClientW || (anchor.left.type && anchor.right.type)) w = Max(w, 1); else w = Max(w, 0);
1152 if(sizeAnchor.isClientH || (anchor.top.type && anchor.bottom.type)) h = Max(h, 1); else h = Max(h, 0);
1154 w = Max(w, minSize.w);
1155 h = Max(h, minSize.h);
1156 w = Min(w, maxSize.w);
1157 h = Min(h, maxSize.h);
1159 if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
1161 if(w) w -= guiApp.currentSkin.VerticalSBW();
1164 if((sizeAnchor.isClientH || !h || (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
1166 if(h) h -= guiApp.currentSkin.HorizontalSBH();
1170 if(!OnResizing(&w, &h))
1176 if((addSbV)) // || reqScrollArea.h > h) && sbv)
1177 w += guiApp.currentSkin.VerticalSBW();
1178 if((addSbH)) // || reqScrollArea.w > w) && sbh)
1179 h += guiApp.currentSkin.HorizontalSBH();
1181 w = Max(w, skinMinSize.w);
1182 h = Max(h, skinMinSize.h);
1195 SNAPDOWN(w, textCellW);
1196 SNAPDOWN(h, textCellH);
1199 if(anchor.left.type == cascade && (state == normal /*|| state == Hidden*/))
1201 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1204 (pw - w) / CASCADE_SPACE,
1205 (ph - h) / CASCADE_SPACE);
1211 cascW = (pw - w) / (numCascade-1);
1212 cascH = (ph - h) / (numCascade-1);
1213 SNAPDOWN(cascW, textCellW);
1214 SNAPDOWN(cascH, textCellH);
1215 cascadeW = (float)cascW;
1216 cascadeH = (float)cascH;
1220 numCascade = Max(numCascade, 2);
1221 cascadeW = (float)(pw - w) / (numCascade-1);
1222 cascadeH = (float)(ph - h) / (numCascade-1);
1225 x = (int)((positionID % numCascade) * cascadeW);
1226 y = (int)((positionID % numCascade) * cascadeH);
1228 else if(anchor.left.type < vTiled)
1230 if(!anchor.left.type || anchor.horz.type == middleRelative)
1232 if(!anchor.right.type)
1234 if(anchor.horz.type == middleRelative)
1235 x = (int)(vpw * (0.5 + anchor.horz.percent) - w / 2);
1237 x = vpw / 2 + anchor.horz.distance - w / 2;
1243 // case A_EDGE: x = x - w; break;
1245 if(!anchor.top.type || anchor.vert.type == middleRelative)
1247 if(!anchor.bottom.type)
1249 if(anchor.vert.type == middleRelative)
1250 y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
1252 y = vph / 2 + anchor.vert.distance - h / 2;
1258 // case A_EDGE: y = y - h; break;
1261 if((state == normal /*|| state == Hidden*/) && !OnMoving(&x, &y, w, h))
1269 SNAPDOWN(x, textCellW);
1270 SNAPDOWN(y, textCellH);
1282 if(anchored && style.fixed && style.isActiveClient)
1287 void UpdateCaret(bool forceUpdate, bool erase)
1289 static Window lastWindow = null;
1290 static int caretX, caretY, caretSize;
1292 if(guiApp && guiApp.caretOwner == this)
1294 int x = caretPos.x - scroll.x;
1295 int y = caretPos.y - scroll.y;
1297 if((erase || this.caretSize) &&
1298 x >= clientArea.left && x <= clientArea.right &&
1299 y >= clientArea.top && y <= clientArea.bottom)
1303 guiApp.interfaceDriver.SetCaret(
1304 x + absPosition.x + clientStart.x,
1305 y + absPosition.y + clientStart.y, this.caretSize);
1306 guiApp.caretEnabled = true;
1308 if(erase || lastWindow != this || caretX != x || caretY != y || caretSize != this.caretSize || forceUpdate)
1312 if(lastWindow != this)
1314 updateBox.left = x + 1;
1316 updateBox.right = x + 2;
1317 updateBox.bottom = y + this.caretSize - 1;
1321 updateBox.left = Min(x + 1, caretX + 1);
1322 updateBox.top = Min(y, caretY);
1323 updateBox.right = Max(x + 2, caretX + 2);
1324 updateBox.bottom = Max(y + this.caretSize - 1, caretY + caretSize - 1);
1327 guiApp.caretOwner.Update(updateBox);
1334 caretSize = this.caretSize;
1340 guiApp.interfaceDriver.SetCaret(0,0,0);
1341 guiApp.caretEnabled = false;
1347 void SetPosition(int x, int y, int w, int h, bool modifyArea, bool modifyThisArea, bool modifyClientArea)
1352 scrolledPos.x = position.x = x;
1353 scrolledPos.y = position.y = y;
1355 clientSize.w = size.w = w;
1356 clientSize.h = size.h = h;
1358 if(parent && !style.nonClient)
1360 //if(!style.fixed || style.isDocument)
1362 if(!style.dontScrollHorz) scrolledPos.x -= parent.scroll.x;
1363 if(!style.dontScrollVert) scrolledPos.y -= parent.scroll.y;
1367 clientStart.x = clientStart.y = 0;
1369 SetWindowArea(&clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1371 //if(!activeClient || activeClient.state != maximized)
1372 if(!noAutoScrollArea)
1374 // Check if scroll area must be modified
1375 if(guiApp && !guiApp.modeSwitching && (sbv || sbh))
1377 bool foundChild = false;
1379 int cw = clientSize.w;// + ((!sbv || sbv.range > 1) ? guiApp.currentSkin.VerticalSBW() : 0);
1380 int ch = clientSize.h;// + ((!sbh || sbh.rangw > 1) ? guiApp.currentSkin.HorizontalSBH() : 0);
1381 for(child = children.first; child; child = child.next)
1383 if(child.modifyVirtArea && !child.style.hidden && child.created && /*!child.anchored &&*/
1384 !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1386 if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == offset)
1387 w = Max(w, child.position.x + child.size.w);
1388 else if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == none)
1389 w = Max(w, Max(child.position.x, 0) + child.size.w);
1390 if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == offset)
1391 h = Max(h, child.position.y + child.size.h);
1392 else if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == none)
1393 h = Max(h, Max(child.position.y, 0) + child.size.h);
1398 if(foundChild && (w > cw || h > ch))
1400 //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
1402 int stepX = sbStep.x, stepY = sbStep.y;
1403 // Needed to make snapped down position match the skin's check of client area
1404 // against realvirtual
1407 SNAPDOWN(stepX, textCellW);
1408 SNAPDOWN(stepY, textCellH);
1409 stepX = Max(stepX, textCellW);
1410 stepY = Max(stepY, textCellH);
1412 if(scrollFlags.snapX)
1414 if(scrollFlags.snapY)
1417 reqScrollArea.w = w;
1418 reqScrollArea.h = h;
1421 else if(reqScrollArea.w || reqScrollArea.h)
1423 reqScrollArea.w = 0;
1424 reqScrollArea.h = 0;
1425 SetScrollPosition(0,0);
1430 // Automatic MDI Client Scrolling Area Adjustment
1431 if(parent && !parent.noAutoScrollArea)
1433 if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
1434 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
1436 Window parent = this.parent;
1437 int w = parent.reqScrollArea.w;
1438 int h = parent.reqScrollArea.h;
1440 if(stateAnchor.right.type == none && stateAnchor.left.type == offset)
1441 w = Max(w, position.x + size.w);
1442 else if(stateAnchor.right.type == none && stateAnchor.left.type == none)
1443 w = Max(w, Max(position.x, 0) + size.w);
1444 if(stateAnchor.bottom.type == none && stateAnchor.top.type == offset)
1445 h = Max(h, position.y + size.h);
1446 else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
1447 h = Max(h, Max(position.y, 0) + size.h);
1449 if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
1450 (h > parent.clientSize.h && h > parent.reqScrollArea.h))
1452 /*bool resize = false;
1453 int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
1454 // Needed to make snapped down position match the skin's check of client area
1455 // against realvirtual
1458 SNAPDOWN(stepX, textCellW);
1459 SNAPDOWN(stepY, textCellH);
1460 stepX = Max(stepX, textCellW);
1461 stepY = Max(stepY, textCellH);
1463 if(parent.scrollFlags.snapX)
1465 if(parent.scrollFlags.snapY)
1467 if(parent.reqScrollArea.w != w || parent.reqScrollArea.h != h)
1469 parent.reqScrollArea.w = w;
1470 parent.reqScrollArea.h = h;*/
1472 // parent.UpdateScrollBars(true, true);
1473 parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1474 false, true, true, true, false, false);
1479 GetRidOfVirtualArea();
1483 UpdateScrollBars(modifyThisArea, false);
1484 else if(guiApp.currentSkin)
1487 &clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1489 if(sbv && (scrollFlags.dontHide || sbv.range > 1))
1490 clientSize.w -= guiApp.currentSkin.VerticalSBW();
1491 if(sbh && (scrollFlags.dontHide || sbh.range > 1))
1492 clientSize.h -= guiApp.currentSkin.HorizontalSBH();
1495 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1496 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1498 absPosition = scrolledPos;
1499 if(guiApp && guiApp.driver != null && guiApp.interfaceDriver)
1500 guiApp.interfaceDriver.OffsetWindow(this, &absPosition.x, &absPosition.y);
1502 if(this != guiApp.desktop && parent)
1504 absPosition.x += parent.absPosition.x;
1505 absPosition.y += parent.absPosition.y;
1506 if(!style.nonClient && this != guiApp.desktop)
1508 absPosition.x += parent.clientStart.x;
1509 absPosition.y += parent.clientStart.y;
1513 box = Box { 0, 0, size.w - 1, size.h - 1 };
1518 // Clip against parent's client area
1519 box.ClipOffset(against, scrolledPos.x, scrolledPos.y);
1521 // Compute client area in this window coordinate system
1522 clientArea.left = 0;
1524 clientArea.right = clientSize.w - 1;
1525 clientArea.bottom = clientSize.h - 1;
1527 // Clip against parent's client area
1529 clientArea.ClipOffset(against, scrolledPos.x + clientStart.x, scrolledPos.y + clientStart.y);
1533 //absPosition.x -= parent.clientStart.x;
1534 //absPosition.y -= parent.clientStart.y;
1537 // Adjust all children
1538 for(child = children.first; child; child = child.next)
1539 child.SetPosition(child.position.x, child.position.y, child.size.w, child.size.h, false, true, true);
1541 UpdateCaret(false, false);
1544 void GetRidOfVirtualArea(void)
1546 if(parent && !parent.destroyed && style.fixed &&
1547 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient &&
1548 parent.reqScrollArea.w && parent.reqScrollArea.h)
1550 if(!parent.noAutoScrollArea)
1554 for(child = children.first; child; child = child.next)
1556 if(child.modifyVirtArea && !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1558 if(child.position.x + child.size.w > parent.clientSize.w + ((!parent.sbv || parent.sbv.style.hidden) ? 0 : guiApp.currentSkin.VerticalSBW()) ||
1559 child.position.y + child.size.h > parent.clientSize.h + ((!parent.sbh || parent.sbh.style.hidden) ? 0 : guiApp.currentSkin.HorizontalSBH()))
1568 Window parent = this.parent;
1570 parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1571 false, true, true, true, false, false);
1573 parent.SetScrollArea(0,0,true);
1574 parent.SetScrollPosition(0,0);
1580 public void ExternalPosition(int x, int y, int w, int h)
1582 Position(x, y, w, h, false, true, true, true, false, false);
1585 // (w, h): Full window size
1586 bool Position(int x, int y, int w, int h, bool force, bool processAnchors, bool modifyArea, bool updateScrollBars, bool thisOnly, bool changeRootWindow)
1588 bool result = false;
1589 int oldCW = clientSize.w, oldCH = clientSize.h;
1590 bool clientResized, windowResized, windowMoved;
1592 bool realResized = size.w != w || size.h != h;
1594 // TOCHECK: This wasn't in ecere.dll
1595 //if(!parent) return true;
1596 if(destroyed) return false;
1598 windowMoved = position.x != x || position.y != y || force;
1600 // windowResized = realResized || force;
1601 windowResized = size.w != w || size.h != h || force;
1603 if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
1609 scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
1610 scrolledPos.x - parent.clientStart.x + this.box.right,
1611 scrolledPos.y - parent.clientStart.y + this.box.bottom
1617 Box box { scrolledPos.x + this.box.left, scrolledPos.y + this.box.top, scrolledPos.x + this.box.right, scrolledPos.y + this.box.bottom};
1622 SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
1624 clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
1625 if(clientResized && this == rootWindow && nativeDecorations)
1626 windowResized = true;
1628 if(display && rootWindow != this)
1631 if(guiApp && guiApp.windowMoving)
1633 if(guiApp.windowMoving.style.nonClient)
1634 guiApp.windowMoving.parent.SetMouseRangeToWindow();
1636 guiApp.windowMoving.parent.SetMouseRangeToClient();
1646 // Buttons bitmap resources crash if we do this while switching mode
1647 if(!guiApp || !guiApp.modeSwitching)
1650 // Process Anchored Children
1654 for(child = children.first; child; child = child.next)
1657 ((child.stateAnchor.left.type != offset ||
1658 child.stateAnchor.top.type != offset ||
1659 child.stateAnchor.right.type != none ||
1660 child.stateAnchor.bottom.type != none) ||
1661 child.state == maximized || child.state == minimized))
1663 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1665 // child.Position(x, y, w, h, false, true, true, true, false);
1666 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1667 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1673 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1674 //if(updateScrollBars)
1676 OnResize(clientSize.w, clientSize.h);
1678 if((clientResized || windowMoved) && created)
1679 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1681 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1683 Window master = guiApp.interimWindow.master;
1684 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1687 if(rootWindow == this && !is3D)
1691 x -= guiApp.desktop.absPosition.x;
1692 y -= guiApp.desktop.absPosition.y;
1694 //guiApp.Log("Position %s\n", caption);
1695 if(windowResized || windowMoved)
1696 if(display && !display.flags.memBackBuffer && changeRootWindow)
1697 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1699 if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved))
1700 for(child = parent.children.first; child && child != this; child = child.next)
1701 if(child.rootWindow)
1702 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1706 if(windowMoved || windowResized)
1708 display.Lock(true /*false*/);
1711 display.Position(absPosition.x, absPosition.y);
1712 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1715 // result = realResized ? display.Resize(size.w, size.h) : true;
1716 if(nativeDecorations)
1718 int w = clientSize.w, h = clientSize.h;
1719 if(hasMenuBar) h += skinMenuHeight;
1720 if(hasStatusBar) h += statusBarHeight;
1721 if(sbv && sbv.visible) w += sbv.size.w;
1722 if(sbh && sbh.visible) h += sbh.size.h;
1723 result = manageDisplay ? display.Resize(w, h) : true;
1726 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1730 else if(clientResized)
1732 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1735 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1739 if(windowMoved || windowResized)
1744 if(guiApp.driver && changeRootWindow)
1746 if(windowResized || windowMoved)
1747 if(!display || display.flags.memBackBuffer)
1748 guiApp.interfaceDriver.PositionRootWindow(this,
1749 x, y, w, h, windowMoved, windowResized);
1750 guiApp.interfaceDriver.UpdateRootWindow(this);
1752 for(child = children.first; child; child = child.next)
1754 if(child.is3D && child.created)
1756 // Copy Display Content
1757 child.display.displaySystem = display.displaySystem;
1758 child.display.window = display.window;
1759 child.display.current = display.current;
1760 child.display.width = display.width;
1761 child.display.height = display.height;
1762 child.display.driverData = display.driverData;
1763 child.display.mutex = null;
1774 void UpdateScrollBars(bool flag, bool fullThing)
1777 bool resizeH = false, resizeV = false;
1778 bool scrolled = false;
1779 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1780 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1782 if(destroyed) return;
1783 if(guiApp.currentSkin)
1785 MinMaxValue cw = 0, ch = 0;
1786 bool sbvVisible, sbhVisible;
1788 int positionH, positionV;
1790 // First get client area with no respect to scroll bars
1795 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1797 if(scrollFlags.dontHide)
1800 cw -= guiApp.currentSkin.VerticalSBW();
1802 ch -= guiApp.currentSkin.HorizontalSBH();
1804 // Update the scrollbar visibility
1810 sbh.disabled = rangeH <= 1;
1811 if(sbh.style.hidden)
1821 sbv.disabled = rangeV <= 1;
1822 if(sbv.style.hidden)
1830 // Then start off with horizontal scrollbar range
1833 positionH = sbh.thumbPosition;
1838 ch -= guiApp.currentSkin.HorizontalSBH();
1841 // Do the same for vertical scrollbar
1844 positionV = sbv.thumbPosition;
1850 cw -= guiApp.currentSkin.VerticalSBW();
1851 // Maybe we need to set the range on the horizontal scrollbar again
1856 sbh.Action(setRange, positionH, 0);
1857 if(rangeH <= 1 && sbh.range > 1)
1859 ch -= guiApp.currentSkin.HorizontalSBH();
1863 sbv.Action(setRange, positionV, 0);
1870 // Update the scrollbar visibility
1871 if(!scrollFlags.dontHide)
1873 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
1877 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
1884 if(guiApp.currentSkin)
1891 sbhVisible = sbh.style.hidden ? true : false;
1893 sbvVisible = sbv.style.hidden ? true : false;
1895 // Do our resize here
1896 if(flag && (resizeH || resizeV) && fullThing)
1898 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
1903 OnResize(clientSize.w, clientSize.h);
1909 sbh.visible = sbhVisible;
1911 sbv.visible = sbvVisible;
1913 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1914 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1917 sbh.pageStep = clientSize.w;
1919 sbv.pageStep = clientSize.h;
1921 // Notify doesn't handle setRange anymore... process it here
1924 int positionH = sbh.thumbPosition;
1925 if(scroll.x != positionH)
1927 OnHScroll(setRange, positionH, 0);
1931 SNAPDOWN(positionH, textCellW);
1932 scroll.x = positionH;
1938 int seen = clientSize.w, total = reqScrollArea.w;
1941 if(scrollFlags.snapX)
1942 SNAPDOWN(seen, sbStep.x);
1944 if(!total) total = seen;
1945 range = total - seen + 1;
1947 range = Max(range, 1);
1949 if(x >= range) x = range - 1;
1951 if(scrollFlags.snapX)
1952 SNAPUP(x, sbStep.x);
1956 OnHScroll(setRange, x, 0);
1961 SNAPDOWN(x, textCellW);
1967 int positionV = sbv.thumbPosition;
1968 if(scroll.y != positionV)
1970 OnVScroll(setRange, positionV, 0);
1974 SNAPDOWN(positionV, textCellH);
1975 scroll.y = positionV;
1981 int seen = clientSize.h, total = reqScrollArea.h;
1984 if(scrollFlags.snapY)
1985 SNAPDOWN(seen, sbStep.y);
1987 if(!total) total = seen;
1988 range = total - seen + 1;
1989 range = Max(range, 1);
1991 if(y >= range) y = range - 1;
1993 if(scrollFlags.snapY)
1994 SNAPUP(y, sbStep.y);
1998 OnVScroll(setRange, y, 0);
2003 SNAPDOWN(y, textCellH);
2009 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2012 for(child = children.first; child; child = child.next)
2014 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2017 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2018 child.Position(x, y, w, h, false, true, false, true, false, false);
2025 // Process Scrollbars
2027 if(sbh) // && !sbh.style.hidden
2029 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2030 // Need to set the range again (should improve...) since the scrollbars didn't have
2031 // the right size when UpdateScrollArea set the range on it
2034 sbh.seen = clientSize.w;
2038 if(sbv) // && !sbv.state.hidden
2040 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2041 // Need to set the range again (should improve...) since the scrollbars didn't have
2042 // the right size when UpdateScrollArea set the range on it
2045 sbv.seen = clientSize.h;
2050 // TESTING THIS LOWER
2051 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2054 for(child = children.first; child; child = child.next)
2056 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2059 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2060 child.Position(x, y, w, h, false, true, false, true, false, false);
2066 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2068 SetState(maximized, false, mods);
2072 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2074 SetState(normal, false, mods);
2078 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2080 SetState(minimized, false, mods);
2081 parent.CycleChildren(false, true, false, true);
2085 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2088 // Scroll bar notifications
2089 if(action != setRange)
2091 bool changed = false;
2095 if(scroll.x != position)
2097 OnHScroll(action, position, keyFlags);
2102 SNAPDOWN(position, textCellW);
2104 scroll.x = position;
2108 if(scroll.y != position)
2110 OnVScroll(action, position, keyFlags);
2115 SNAPDOWN(position, textCellH);
2117 scroll.y = position;
2121 bool childMove = false;
2122 for(child = children.first; child; child = child.next)
2124 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2127 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2128 child.Position(x, y, w, h, false, true, false, true, false, false);
2132 // Testing this patch out to solve MDI workspace redraw bugs
2133 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2134 // Scroll offsets to blame?
2138 UpdateCaret(false, false);
2142 // Testing this patch out to solve MDI workspace redraw bugs
2143 for(child = children.first; child; child = child.next)
2145 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2154 void CreateSystemChildren(void)
2156 Window parent = this;
2157 bool scrollBarChanged = false;
2158 bool hasClose = false, hasMaxMin = false;
2159 Point scroll = this.scroll;
2161 if(state == maximized && this.parent.menuBar)
2163 if(this.parent.activeClient == this)
2164 parent = this.parent.menuBar;
2171 if(style.hasClose) hasClose = true;
2172 if(style.hasMaximize || style.hasMinimize)
2179 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2181 sysButtons[2].Destroy(0);
2182 sysButtons[2] = null;
2184 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2186 sysButtons[1].Destroy(0);
2187 sysButtons[1] = null;
2189 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2191 sysButtons[0].Destroy(0);
2192 sysButtons[0] = null;
2195 if(hasClose && parent)
2202 parent, master = this,
2203 inactive = true, nonClient = true, visible = false;
2205 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2211 if(this.parent == guiApp.desktop)
2212 sysButtons[2].hotKey = altF4;
2213 else if(style.isActiveClient)
2214 sysButtons[2].hotKey = ctrlF4;
2215 sysButtons[2].Create();
2218 sysButtons[2].symbol = 'X';
2219 sysButtons[2].disabled = !style.hasClose;
2222 if(hasMaxMin && parent)
2226 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2227 if(state == maximized)
2230 method = RestoreButtonClicked;
2236 method = MaximizeButtonClicked;
2244 parent, master = this,
2245 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2247 sysButtons[1].Create();
2249 sysButtons[1].NotifyClicked = method;
2251 sysButtons[1].symbol = symbol;
2252 sysButtons[1].disabled = !style.hasMaximize;
2255 if(hasMaxMin && parent)
2259 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2260 if (state == minimized)
2263 method = RestoreButtonClicked;
2269 method = MinimizeButtonClicked;
2277 parent, master = this,
2278 hotKey = altM, inactive = true, nonClient = true, visible = false
2280 sysButtons[0].Create();
2282 sysButtons[0].NotifyClicked = method;
2284 sysButtons[0].symbol = symbol;
2285 sysButtons[0].disabled = !style.hasMinimize;
2288 // Create the scrollbars
2289 if(style.hasHorzScroll && !sbh)
2295 direction = horizontal,
2299 snap = scrollFlags.snapX,
2300 NotifyScrolling = ScrollBarNotification
2303 scrollBarChanged = true;
2305 else if(sbh && !style.hasHorzScroll)
2311 if(style.hasVertScroll && !sbv)
2317 direction = vertical,
2321 snap = scrollFlags.snapY,
2322 NotifyScrolling = ScrollBarNotification
2325 scrollBarChanged = true;
2327 else if(sbv && !style.hasVertScroll)
2332 if(scrollBarChanged)
2334 SetScrollLineStep(sbStep.x, sbStep.y);
2335 UpdateScrollBars(true, true);
2339 if(scrollBarChanged)
2341 if(sbh) sbh.thumbPosition = scroll.x;
2342 if(sbv) sbv.thumbPosition = scroll.y;
2346 void UpdateCaption(void)
2348 if(rootWindow == this)
2351 FigureCaption(caption);
2352 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2354 UpdateDecorations();
2357 if(parent.rootWindow == parent && parent.activeClient == this) // Added this last check
2360 parent.FigureCaption(caption);
2361 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2363 parent.UpdateDecorations();
2367 void UpdateActiveDocument(Window previous)
2369 Window activeClient = this.activeClient;
2370 Window activeChild = this.activeChild;
2377 activeClient.CreateSystemChildren();
2379 previous.CreateSystemChildren();
2390 if(activeClient && activeClient.menu && activeClient.state != minimized)
2394 //activeClient.menu.Clean(activeClient);
2395 menu.Merge(activeClient.menu, true, activeClient);
2399 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2402 menu.Merge(activeChild.menu, true, activeChild);
2405 // Build window list
2408 Menu windowMenu = menu.FindMenu("Window");
2413 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2416 Window document = cycle.data;
2417 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2419 char name[2048], caption[2048];
2420 document.FigureCaption(caption);
2421 sprintf(name, "%d %s", id+1, caption);
2422 windowMenu.AddDynamic(MenuItem
2424 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2425 NotifySelect = MenuWindowSelectWindow
2429 if(activeClient.cycle == cycle) break;
2434 if((!previous && activeClient) || !activeClient)
2440 item = menu.FindItem(MenuWindowCloseAll, 0);
2441 if(item) item.disabled = false;
2442 item = menu.FindItem(MenuWindowNext, 0);
2443 if(item) item.disabled = false;
2444 item = menu.FindItem(MenuWindowPrevious, 0);
2445 if(item) item.disabled = false;
2446 item = menu.FindItem(MenuWindowCascade, 0);
2447 if(item) item.disabled = false;
2448 item = menu.FindItem(MenuWindowTileHorz, 0);
2449 if(item) item.disabled = false;
2450 item = menu.FindItem(MenuWindowTileVert, 0);
2451 if(item) item.disabled = false;
2452 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2453 if(item) item.disabled = false;
2454 item = menu.FindItem(MenuWindowWindows, 0);
2455 if(item) item.disabled = false;
2458 item = menu.FindItem(MenuFileClose, 0);
2459 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2460 item = menu.FindItem(MenuFileSaveAll, 0);
2461 if(item) item.disabled = numDocuments < 1;
2463 // This is called again for a child window change, with same active client
2464 OnActivateClient(activeClient, previous);
2467 void _ShowDecorations(Box box, bool post)
2469 if(rootWindow == this && nativeDecorations) return;
2470 if(visible && this != guiApp.desktop)
2472 Surface surface = RedrawFull(box);
2476 FigureCaption(caption);
2479 ShowDecorations(captionFont.font,
2482 active, //parent.activeClient == this
2483 guiApp.windowMoving == this);
2485 PreShowDecorations(captionFont.font,
2488 active, //parent.activeClient == this
2489 guiApp.windowMoving == this);
2496 void UpdateExtent(Box refresh)
2498 Surface surface = null;
2500 if(!manageDisplay) { OnRedraw(null);return; }
2501 _ShowDecorations(refresh, false);
2503 surface = Redraw(refresh);
2504 // Opaque background: just fill before EW_REDRAW (clear?)
2507 surface.SetBackground(background);
2508 surface.SetForeground(foreground);
2509 surface.DrawingChar(' ');
2510 if(this == rootWindow)
2512 if(style.drawBehind || background.a)
2513 surface.Clear(colorBuffer);
2515 else if(background.a)
2519 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2520 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2523 if(display.flags.alpha && background.a < 255 && background)
2525 surface.Area(0,0,clientSize.w, clientSize.h);
2526 /*if(style.clearDepthBuffer)
2527 surface.Clear(depthBuffer);*/
2529 else if(/*style.clearDepthBuffer || */background.a)
2531 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2532 surface.Clear(colorBuffer);
2537 surface.TextFont(usedFont.font);
2538 surface.TextOpacity(false);
2542 // Draw the caret ...
2543 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2545 // surface.SetBackground(0xFFFFFF - background.color);
2546 surface.SetBackground(~background.color);
2548 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2549 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2555 void DrawOverChildren(Box refresh)
2557 Surface surface = Redraw(refresh);
2561 surface.DrawingChar(' ');
2562 surface.SetBackground(background);
2563 surface.SetForeground(foreground);
2565 surface.TextFont(usedFont.font);
2566 surface.TextOpacity(false);
2568 OnDrawOverChildren(surface);
2573 _ShowDecorations(refresh, true);
2576 void ComputeClipExtents(void)
2579 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2581 clipExtent.Copy(this.clipExtent);
2583 for(child = children.last; child; child = child.prev)
2585 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2587 bool opaque = child.IsOpaque(); // TODO: acess background directly
2588 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2590 child.clipExtent.Copy(clipExtent);
2591 child.clipExtent.Offset(-dx, -dy);
2592 child.clipExtent.IntersectBox(child.box);
2594 child.ComputeClipExtents();
2596 if(opaque && !child.style.nonClient)
2598 // Adjust the box for the parent:
2599 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2600 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2605 // ??? Only do this for overlapped window or if parent has with clip children flag
2607 // Do this if window has clip children flag on (default false?)
2608 // this.clipExtent = clipExtent;
2610 clipExtent.Free(null);
2613 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2615 bool opaque = IsOpaque();
2617 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2618 if(rootWindow.nativeDecorations)
2620 offsetX -= rootWindow.clientStart.x;
2621 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2625 for(child = children.last; child; child = child.prev)
2627 ColorAlpha background = *(ColorAlpha *)&child.background;
2628 bool opaque = child.IsOpaque();
2629 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2633 // Adjust renderArea to the root window level
2634 Extent * renderArea = &rootWindow.tempExtents[1];
2636 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2637 if(child.rootWindow.nativeDecorations)
2639 offsetX -= child.rootWindow.clientStart.x;
2640 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2644 Extent childRenderArea;
2646 if(backBufferUpdate != null)
2648 childRenderArea.Copy(backBufferUpdate);
2649 childRenderArea.Offset(-offsetX, -offsetY);
2652 childRenderArea.Copy(child.dirtyArea);
2654 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2655 renderArea.Copy(dirtyExtent);
2656 renderArea.Offset(-offsetX, -offsetY);
2657 childRenderArea.Union(renderArea);
2660 // Intersect with the clip extent
2661 childRenderArea.Intersection(child.clipExtent);
2664 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2665 renderArea->Offset(offsetX, offsetY);
2666 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2667 // overDirtyExtent.Union(renderArea);
2668 renderArea->Empty();
2669 // childRenderArea.Free();
2671 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2676 for(child = children.last; child; child = child.prev)
2678 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2680 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2685 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2687 bool opaque = IsOpaque();
2688 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2690 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2691 if(rootWindow.nativeDecorations)
2693 offsetX -= rootWindow.clientStart.x;
2694 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2698 for(child = children.last; child; child = child.prev)
2700 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2702 ColorAlpha background = *(ColorAlpha *)&child.background;
2703 bool opaque = child.IsOpaque();
2704 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2708 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2709 // Adjust renderArea to the root window level
2711 renderArea.Copy(child.dirtyArea);
2712 renderArea.Offset(offsetX, offsetY);
2713 dirtyExtent.Union(renderArea);
2714 overDirtyExtent.Union(renderArea);
2720 for(child = children.last; child; child = child.prev)
2722 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2724 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2728 if(backBufferUpdate != null)
2730 renderArea.Copy(backBufferUpdate);
2731 renderArea.Offset(-offsetX, -offsetY);
2733 overRenderArea.Copy(backBufferUpdate);
2734 overRenderArea.Offset(-offsetX, -offsetY);
2740 renderArea.Copy(dirtyArea);
2742 overRenderArea.Copy(dirtyArea);
2745 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2746 dirtyExtentWindow->Copy(dirtyExtent);
2747 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2748 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2749 dirtyExtentWindow->Empty();
2751 // Intersect with the clip extent
2752 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2755 if(renderArea.count > 10)
2758 printf("\nToo many extents (%d):\n", renderArea.count);
2760 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2761 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2766 for(c = 0; c<10; c++)
2769 FASTLIST_LOOP(renderArea, extentBox)
2771 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2773 renderArea.Copy(extent);
2775 FASTLIST_LOOP(renderArea, extentBox)
2778 printf("(%d, %d) - (%d, %d)\n",
2779 extentBox.box.left, extentBox.box.top,
2780 extentBox.box.right, extentBox.box.bottom);
2784 printf("\nNow %d\n", renderArea.count);
2790 // WHY WAS THIS COMMENTED ??
2792 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2793 dirtyExtentWindow->Copy(overDirtyExtent);
2794 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2795 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2796 dirtyExtentWindow->Empty();
2798 // Intersect with the clip extent
2799 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2805 if(scrollExtent.count)
2807 // Subtract render extent from scrolling extent
2808 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
2810 if(backBufferUpdate == null)
2812 Extent * dirty = &rootWindow.tempExtents[3];
2815 // Intersect scrolling extent with clip extent
2816 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2818 // offset this scroll to be at the root window level
2819 scrollExtent.Offset(offsetX, offsetY);
2820 // Add area that was scrolled to the dirty extents of the back buffer
2821 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
2825 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
2826 for(scrollBox = (BoxItem)scrollExtent.first; scrollBox; scrollBox = (BoxItem)scrollBox.next)
2827 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
2832 scrollExtent.Empty();
2834 // Add the exposed extent to the window render area
2835 dirty->Offset(-offsetX, -offsetY);
2836 renderArea.Union(dirty, rootWindow.tempExtents[0]);
2841 // Subtract the window's box from the transparency forced extent
2842 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
2848 renderArea.Copy(this.renderArea);
2849 renderArea.Offset(offsetX, offsetY);
2850 dirtyExtent.Union(renderArea);
2856 Extent renderArea { };
2858 renderArea.Copy(overRenderArea);
2859 renderArea.Offset(offsetX, offsetY);
2860 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2865 if(backBufferUpdate != null)
2867 // Remove render area from dirty area
2868 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
2870 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
2877 // Remove the window render area from the dirty extents of the back buffer
2878 rootWindow.dirtyBack.Exclusion(renderArea);
2882 void Render(Extent updateExtent)
2886 Window rootWindow = this.rootWindow;
2887 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2888 if(rootWindow.nativeDecorations)
2890 offsetX -= rootWindow.clientStart.x;
2891 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2894 if(rootWindow.fullRender)
2903 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2904 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
2909 /*if(renderArea.count)
2910 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
2913 for(extentBox = (BoxItem)renderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2915 Box box = extentBox.box;
2918 /*printf("(%d, %d) - (%d, %d)\n",
2919 extentBox.box.left, extentBox.box.top,
2920 extentBox.box.right, extentBox.box.bottom);*/
2925 box.left += offsetX;
2927 box.right += offsetX;
2928 box.bottom += offsetY;
2930 if(updateExtent != null)
2931 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2935 for(child = children.first; child; child = child.next)
2936 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
2937 child.Render(updateExtent);
2939 if(rootWindow.fullRender)
2940 DrawOverChildren(box);
2943 // TO DO: There's an issue about draw over children...
2944 // TO DO: Don't wanna go through this if method isn't used
2945 for(extentBox = (BoxItem)overRenderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2946 //FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
2948 Box box = extentBox.box;
2950 DrawOverChildren(box);
2952 box.left += offsetX;
2954 box.right += offsetX;
2955 box.bottom += offsetY;
2957 if(updateExtent != null)
2958 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2961 for(child = children.first; child; child = child.next)
2962 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
2963 child.Render(updateExtent);
2966 overRenderArea.Empty();
2969 public void UpdateDisplay(void)
2971 if(!manageDisplay) { OnRedraw(null);return; }
2972 if(rootWindow && this != rootWindow)
2973 rootWindow.UpdateDisplay();
2976 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
2977 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
2980 dirtyExtent.Clear();
2983 clipExtent.AddBox(box);
2985 display.StartUpdate();
2987 if(!rootWindow.fullRender)
2989 ComputeClipExtents();
2990 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
2991 ComputeRenderArea(dirtyExtent, overExtent, null);
2994 clipExtent.Free(null);
2996 dirtyExtent.Free(null);
2997 overExtent.Free(null);
2999 if(display.flags.flipping)
3002 display.Update(null);
3006 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
3007 updateExtent.Clear();
3009 Render(updateExtent);
3011 updateExtent.UnionBox(this.box, tempExtents[0]);
3014 //printf("\n\nUpdate:\n------------------------------------------\n");
3017 //FASTLIST_LOOP(updateExtent, extentBox)
3018 for(extentBox = (BoxItem)updateExtent.first; extentBox; extentBox = (BoxItem)extentBox.next)
3021 /*printf("Updating (%d, %d) - (%d, %d)\n",
3022 extentBox.box.left, extentBox.box.top,
3023 extentBox.box.right, extentBox.box.bottom);*/
3026 display.Update(extentBox.box);
3029 updateExtent.Free(null);
3032 display.EndUpdate();
3040 void UpdateBackDisplay(Box box)
3046 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3048 //printf("UpdateBackDisplay going through!\n");
3049 display.StartUpdate();
3053 intersection.Copy(dirtyBack);
3054 intersection.IntersectBox(box);
3056 dirtyExtent.Clear();
3059 clipExtent.AddBox(box);
3061 if(!rootWindow.fullRender)
3063 ComputeClipExtents();
3064 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3067 clipExtent.Free(null);
3069 intersection.Free(null);
3070 dirtyExtent.Free(null);
3071 overExtent.Free(null);
3076 if(display.flags.flipping)
3077 display.Update(null);
3080 rootWindow.display.Update(box);
3083 display.EndUpdate();
3087 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3088 if(dirtyBack.count > MAX_DIRTY_BACK)
3090 BoxItem extentBox, next;
3091 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3092 for(extentBox = (BoxItem)dirtyBack.first; extentBox; extentBox = next)
3094 next = (BoxItem)extentBox.next;
3095 if(extentBox != first)
3097 if(extentBox.box.left < first.box.left)
3098 first.box.left = extentBox.box.left;
3099 if(extentBox.box.top < first.box.top)
3100 first.box.top = extentBox.box.top;
3101 if(extentBox.box.right > first.box.right)
3102 first.box.right = extentBox.box.right;
3103 if(extentBox.box.bottom > first.box.bottom)
3104 first.box.bottom = extentBox.box.bottom;
3105 dirtyBack.Delete(extentBox);
3114 // --- Window positioning ---
3115 // --- Window identification ---
3117 // Returns window at position "Position"
3118 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3120 Window child, result = null;
3122 box.left += absPosition.x;
3123 box.right += absPosition.x;
3124 box.top += absPosition.y;
3125 box.bottom += absPosition.y;
3127 if(!destroyed && visible && (acceptDisabled || !disabled))
3129 int lx = x - absPosition.x;
3130 int ly = y - absPosition.y;
3131 if(IsInside(lx, ly))
3132 // if(box.IsPointInside(Point{x, y}))
3134 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3135 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3138 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3140 if(child != statusBar && child.rootWindow == rootWindow)
3142 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3149 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3151 if(child != statusBar && child.rootWindow == rootWindow)
3153 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3165 Window FindModal(void)
3167 Window modalWindow = this, check;
3168 Window check2 = null;
3169 for(check = this; check.master; check = check.master)
3171 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3173 modalWindow = check.master.modalSlave;
3174 check = modalWindow;
3176 // TESTING THIS FOR DROPBOX...
3177 if(!rootWindow || !rootWindow.style.interim)
3179 for(check2 = check; check2.activeChild; check2 = check2.activeChild)
3181 if(check2.modalSlave && check2.modalSlave.created)
3183 modalWindow = check2.modalSlave;
3191 if(modalWindow == this)
3193 for(check = this; check.activeChild; check = check.activeChild)
3195 if(check.modalSlave)
3197 modalWindow = check.modalSlave;
3203 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3204 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3207 void StopMoving(void)
3209 if(this == guiApp.windowMoving)
3211 guiApp.windowMoving = null;
3212 UpdateDecorations();
3213 SetMouseRange(null);
3216 if(rootWindow.active)
3217 guiApp.interfaceDriver.StopMoving(rootWindow);
3220 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3221 guiApp.windowIsResizing = false;
3225 void SelectMouseCursor(void)
3230 Window cursorWindow = null;
3231 bool rx, ry, rex, rey;
3233 guiApp.desktop.GetMousePosition(&x, &y);
3234 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3236 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3237 guiApp.SetCurrentCursor(guiApp.systemCursors[moving]);
3238 else if(mouseWindow)
3240 modalWindow = mouseWindow.FindModal();
3241 x -= mouseWindow.absPosition.x;
3242 y -= mouseWindow.absPosition.y;
3243 if(guiApp.windowIsResizing)
3245 rex = guiApp.resizeEndX;
3246 rey = guiApp.resizeEndY;
3247 rx = guiApp.resizeX;
3248 ry = guiApp.resizeY;
3249 if((rex && rey) || (rx && ry))
3250 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3251 else if((rex && ry) || (rx && rey))
3252 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3253 else if((ry || rey) && (!rx && !rex))
3254 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3255 else if((rx || rex) && (!ry && !rey))
3256 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3258 else if(!modalWindow && !guiApp.windowCaptured &&
3259 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3260 &rx, &ry, &rex, &rey))
3262 if((rex && rey) || (rx && ry))
3263 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3264 else if((rex && ry) || (rx && rey))
3265 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3266 else if((ry || rey) && (!rx && !rex))
3267 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3268 else if((rx || rex) && (!ry && !rey))
3269 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3271 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3273 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}))
3274 cursorWindow = mouseWindow.parent;
3276 cursorWindow = mouseWindow;
3278 else if(!guiApp.interimWindow)
3279 cursorWindow = guiApp.windowCaptured;
3282 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient; cursorWindow = cursorWindow.parent);
3283 guiApp.SetCurrentCursor(cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3285 else if(modalWindow)
3287 guiApp.SetCurrentCursor(guiApp.systemCursors[arrow]);
3289 else if(guiApp.interimWindow)
3291 if(guiApp.interimWindow.cursor)
3292 guiApp.SetCurrentCursor(guiApp.interimWindow.cursor);
3294 guiApp.SetCurrentCursor(mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3299 // --- State based input ---
3300 bool AcquireInputEx(bool state)
3305 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3306 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3308 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3310 guiApp.acquiredWindow = state ? this : null;
3313 SetMouseRangeToClient();
3314 guiApp.interfaceDriver.SetMouseCursor((SystemCursor)-1);
3319 SelectMouseCursor();
3321 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3325 // --- Window activation ---
3326 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3329 if(!parent || !parent.style.inactive)
3331 Window parent = this.parent;
3334 if(rootWindow == this)
3335 Log(active ? "active\n" : "inactive\n");
3338 // Testing this here...
3339 if(!parent || parent == guiApp.desktop || parent.active)
3341 this.active = active;
3344 // TESTING THIS HERE
3345 UpdateDecorations();
3346 if(result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master)
3347 result = NotifyActivate(master, this, active, previous);
3350 this.active = !active;
3355 if(!parent || parent == guiApp.desktop || parent.active)
3357 this.active = active;
3359 AcquireInputEx(active);
3364 if(guiApp.caretOwner)
3368 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3369 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3370 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3371 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3373 guiApp.caretOwner.Update(extent);
3376 if(visible || !guiApp.caretOwner)
3377 guiApp.caretOwner = this;
3378 UpdateCaret(false, false);
3384 this.active = false;
3386 AcquireInputEx(active);
3388 if(!active && guiApp.caretOwner == this)
3390 UpdateCaret(false, true);
3391 guiApp.caretOwner = null;
3392 guiApp.interfaceDriver.SetCaret(0,0,0);
3393 guiApp.caretEnabled = false;
3398 if(!active && parent && parent.activeChild && parent.activeChild != this)
3399 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3405 if(!active && menuBar)
3408 menuBar.OnActivate(false, null, &goOn, true);
3409 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3414 Window aChild = activeChild;
3416 if(!aChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3428 void ConsequentialMouseMove(bool kbMoving)
3432 if(kbMoving || !guiApp.windowMoving)
3436 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3438 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3440 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3441 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3447 bool IsDescendantOf(Window ancestor)
3450 for(window = this; window && window != ancestor; window = window.parent);
3451 return window == ancestor;
3454 bool IsSlaveOf(Window master)
3457 for(window = this; window && window != master; window = window.master);
3458 return window == master;
3461 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3465 if(this && !destroyed /*&& state != Hidden*/)
3467 Window swap = externalSwap;
3475 if(activateParent &&
3476 (parent.activeChild != this ||
3477 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3478 active && _isModal &&
3479 parent != master && master)
3480 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3486 bool real = parent.activeChild != this;
3488 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3489 if(/*activateParent && */guiApp.interimWindow &&
3490 !IsDescendantOf(guiApp.interimWindow) &&
3491 !IsSlaveOf(guiApp.interimWindow))
3493 Window interimWindow = guiApp.interimWindow;
3494 while(interimWindow && interimWindow != this)
3496 Window master = interimWindow.master;
3498 guiApp.interimWindow = null;
3499 if(guiApp.caretOwner)
3500 guiApp.caretOwner.UpdateCaret(false, false);
3502 incref interimWindow;
3503 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3508 delete interimWindow;
3509 interimWindow = (master && master.style.interim) ? master : null;
3514 guiApp.interimWindow = this;
3515 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3516 guiApp.caretEnabled = false;*/
3517 UpdateCaret(false, true);
3522 bool acquireInput = false;
3524 parent.activeChild &&
3525 parent.activeChild.state == maximized &&
3526 parent != guiApp.desktop;
3528 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3533 swap = parent.activeChild;
3534 if(swap && swap.destroyed) swap = null;
3535 if(swap && swap != this)
3538 if(!swap.PropagateActive(false, this, &goOn, true))
3539 swap = parent.activeChild;
3550 if(!parent || parent.activeChild != this || style.interim)
3553 result = PropagateActive(true, swap, &goOn, true);
3554 if(!result && !goOn)
3559 acquireInput = true;
3563 if(style.hasMaximize && parent != guiApp.desktop)
3566 SetState(maximized, false, 0);
3567 else if(state != maximized)
3570 for(child = parent.children.first; child; child = child.next)
3572 if(this != child && child.state == maximized)
3573 child.SetState(normal, false, 0);
3580 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3582 Window previous = parent.activeClient;
3583 parent.activeChild = this;
3584 if(!style.nonClient /*&& style.isActiveClient*/)
3588 if(style.isActiveClient)
3589 parent.activeClient = this;
3590 // Moved UpdateActiveDocument inside hidden check
3591 // To prevent activating previous window while creating a new one
3592 // (It was messing up the privateModule in the CodeEditor)
3593 parent.UpdateActiveDocument(previous);
3599 //if(!style.isRemote)
3601 if(rootWindow != this)
3603 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3604 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3606 else if(!guiApp.fullScreenMode)
3608 Window modalRoot = FindModal();
3609 if(!modalRoot) modalRoot = this;
3610 if(!modalRoot.isForegroundWindow)
3612 modalRoot.isForegroundWindow = true;
3613 // To check : Why is parent null?
3614 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3616 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3618 modalRoot.isForegroundWindow = false;
3623 if(result && real && (!style.inactive || moveInactive) && parent)
3625 Window last = parent.children.last;
3627 if(!style.stayOnTop)
3628 for(; last && last.style.stayOnTop; last = last.prev);
3630 parent.children.Move(this, last);
3632 // Definitely don't want that: why not?
3636 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3642 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3649 parent.activeChild = null;
3650 if(!style.nonClient /*&& style.isActiveClient*/)
3652 Window previous = parent.activeClient;
3653 if(style.isActiveClient)
3654 parent.activeClient = null;
3655 parent.UpdateActiveDocument(previous);
3659 if(this == guiApp.interimWindow)
3661 guiApp.interimWindow = null;
3662 if(guiApp.caretOwner)
3663 guiApp.caretOwner.UpdateCaret(false, false);
3665 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3672 if(!active || !swap)
3673 UpdateDecorations();
3675 swap.UpdateDecorations();
3677 if(active && rootWindow != this)
3678 ConsequentialMouseMove(false);
3685 // --- Input Messages ---
3686 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3688 static bool reEntrancy = false;
3689 if(reEntrancy) return;
3693 guiApp.cursorUpdate = true;
3694 if(guiApp.windowScrolling && !consequential)
3696 guiApp.windowScrolling.SetScrollPosition(
3697 (guiApp.windowScrolling.sbh) ?
3698 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3699 (guiApp.windowScrolling.sbv) ?
3700 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3702 if(guiApp.windowMoving)
3704 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3706 Window window = guiApp.windowMoving;
3708 int w = window.size.w;
3709 int h = window.size.h;
3714 rx = mouseX - guiApp.windowMovingStart.x;
3715 ry = mouseY - guiApp.windowMovingStart.y;
3718 window.GetDecorationsSize(&ew, &eh);
3720 if(guiApp.windowIsResizing)
3722 x = window.scrolledPos.x;
3723 y = window.scrolledPos.y;
3727 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3728 rx = guiApp.windowResizingBefore.w - aw;
3729 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3730 w = guiApp.windowResizingBefore.w - rx;
3734 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3735 ry = guiApp.windowResizingBefore.h - ah;
3736 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3737 ry = Max(ry, -guiApp.windowMovingBefore.y);
3738 h = guiApp.windowResizingBefore.h - ry;
3740 if(guiApp.resizeEndX)
3742 w = guiApp.windowResizingBefore.w + rx;
3745 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3753 w = Max(w, window.minSize.w);
3754 h = Max(h, window.minSize.h);
3755 w = Min(w, window.maxSize.w);
3756 h = Min(h, window.maxSize.h);
3758 if(!window.OnResizing(&w, &h))
3760 w = window.clientSize.w;
3761 h = window.clientSize.h;
3764 w = Max(w, window.skinMinSize.w);
3765 h = Max(h, window.skinMinSize.h);
3772 SNAPDOWN(w, textCellW);
3773 SNAPDOWN(h, textCellH);
3778 aw = Max(w,window.skinMinSize.w);
3779 rx = guiApp.windowResizingBefore.w - aw;
3780 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3781 w = guiApp.windowResizingBefore.w - rx;
3785 ah = Max(h,window.skinMinSize.h);
3786 ry = guiApp.windowResizingBefore.h - ah;
3787 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3788 ry = Max(ry, -guiApp.windowMovingBefore.y);
3789 h = guiApp.windowResizingBefore.h - ry;
3794 if(!guiApp.windowIsResizing || guiApp.resizeX)
3795 x = guiApp.windowMovingBefore.x + rx;
3796 if(!guiApp.windowIsResizing || guiApp.resizeY)
3797 y = guiApp.windowMovingBefore.y + ry;
3799 if(!guiApp.windowIsResizing)
3802 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
3804 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
3805 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
3806 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
3807 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
3811 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
3812 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
3818 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
3820 if(!window.OnMoving(&x, &y, w, h))
3822 x = window.scrolledPos.x;
3823 y = window.scrolledPos.y;
3829 SNAPDOWN(x, textCellW);
3830 SNAPDOWN(y, textCellH);
3833 if(!window.style.nonClient)
3835 if(!window.style.fixed /*|| window.style.isDocument*/)
3837 if(!window.style.dontScrollHorz)
3838 x += window.parent.scroll.x;
3839 if(!window.style.dontScrollVert)
3840 y += window.parent.scroll.y;
3844 // Break the anchors for moveable/resizable windows
3845 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
3846 if(window.style.fixed)
3848 if(window.state == normal)
3850 window.normalAnchor = Anchor { left = x, top = y };
3851 window.normalSizeAnchor = SizeAnchor { { w, h } };
3852 window.anchored = false;
3856 window.stateAnchor = Anchor { left = x, top = y };
3857 window.stateSizeAnchor = SizeAnchor { { w, h } };
3859 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
3860 // TOCHECK: Investigate why the following only redraws the scrollbars
3861 //window.Position(x, y, w, h, false, true, true, true, false, true);
3863 guiApp.movingLast.x = mouseX;
3864 guiApp.movingLast.y = mouseY;
3870 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
3873 bool wasMoving = guiApp.windowMoving ? true : false;
3874 bool wasScrolling = guiApp.windowScrolling ? true : false;
3876 while(result && w != this)
3878 Window msgWindow = GetAtPosition(x,y, false, true, w);
3879 Window trueWindow = GetAtPosition(x,y, false, false, w);
3880 bool windowDragged = false;
3885 window = (w && !w.disabled) ? w : null;
3887 if(trueWindow) incref trueWindow;
3889 if(consequential) mods->isSideEffect = true;
3891 UpdateMouseMove(x, y, consequential);
3893 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
3895 if(!guiApp.windowCaptured.isEnabled)
3896 guiApp.windowCaptured.ReleaseCapture();
3898 window = guiApp.windowCaptured;
3901 if(trueWindow && activate &&
3902 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3903 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3904 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3905 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3907 if(mods->alt && !mods->ctrl && !mods->shift)
3909 Window moved = trueWindow;
3910 for(moved = trueWindow; moved; moved = moved.parent)
3911 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3916 windowDragged = true;
3918 // Cancel the ALT menu toggling...
3919 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
3924 if(window && activate &&
3925 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3926 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3927 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3928 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3930 Window modalWindow = window.FindModal();
3932 /*if(mods->alt && !mods->shift && !mods->ctrl)
3934 Window moved = window;
3935 for(moved = window; moved; moved = moved.parent)
3936 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3941 windowDragged = true;
3943 // Cancel the ALT menu toggling...
3944 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
3950 Window activateWindow = modalWindow ? modalWindow : window;
3951 if(activateWindow && !activateWindow.isRemote)
3953 bool doActivation = true;
3954 //bool needToDoActivation = false;
3955 Window check = activateWindow;
3957 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
3959 if(!check.style.inactive)
3961 //needToDoActivation = true;
3963 doActivation = false;
3968 if(!needToDoActivation)
3969 doActivation = false;
3972 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
3973 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
3975 // Let the OnLeftButtonDown do the activating instead
3976 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
3984 incref activateWindow;
3985 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
3987 delete activateWindow;
3991 if(activateWindow._refCount == 1)
3993 delete activateWindow;
3997 delete activateWindow;
3999 mods->isActivate = true;
4003 if(!modalWindow && window && !window.destroyed)
4005 if(!guiApp.windowCaptured || windowDragged)
4007 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
4009 bool moving = ((window.state != maximized &&
4010 window.IsMouseMoving(
4011 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4012 || (guiApp.windowMoving && !guiApp.windowIsResizing);
4014 if(!moving && window.IsMouseResizing(
4015 x - window.absPosition.x,
4016 y - window.absPosition.y,
4017 window.size.w, window.size.h,
4018 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
4020 guiApp.windowIsResizing = true;
4021 guiApp.windowResizingBefore.w = window.size.w;
4022 guiApp.windowResizingBefore.h = window.size.h;
4024 if(guiApp.windowIsResizing || windowDragged || moving)
4027 guiApp.windowMoving = window;
4028 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4029 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4030 guiApp.windowMovingBefore.x = window.position.x;//s;
4031 guiApp.windowMovingBefore.y = window.position.y;//s;
4032 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4033 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4036 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4038 if(window.style.fixed &&
4040 window.IsMouseMoving(
4041 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4043 window.ShowSysMenu(x, y);
4047 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4049 if(window.sbv || window.sbh)
4052 guiApp.windowScrolling = window;
4053 guiApp.windowScrollingStart.x = x;
4054 guiApp.windowScrollingStart.y = y;
4055 guiApp.windowScrollingBefore.x = window.scroll.x;
4056 guiApp.windowScrollingBefore.y = window.scroll.y;
4059 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4061 if(window.style.hasMaximize &&
4062 window.IsMouseMoving(
4063 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4066 (window.state == maximized) ? normal : maximized, false, *mods);
4074 if(guiApp.windowMoving)
4076 if(guiApp.windowMoving.parent)
4078 if(guiApp.windowMoving.style.nonClient)
4079 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4081 guiApp.windowMoving.parent.SetMouseRangeToClient();
4085 window.UpdateDecorations();
4088 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4090 // Log("\n*** LEFT BUTTON UP ***\n");
4091 if(guiApp.windowMoving)
4092 guiApp.windowMoving.StopMoving();
4094 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4096 if(guiApp.windowScrolling)
4098 Window windowScrolling = guiApp.windowScrolling;
4099 guiApp.windowScrolling = null;
4100 windowScrolling.ReleaseCapture();
4104 if(!result || (window && window.destroyed)) window = null;
4106 if(window && window.FindModal())
4109 if(trueWindow && trueWindow.FindModal())
4117 msgWindow = GetAtPosition(x,y, true, false);
4119 msgWindow.SelectMouseCursor();
4122 if(guiApp.windowCaptured || trueWindow)
4124 Window prevWindow = guiApp.prevWindow;
4125 if(guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4127 guiApp.prevWindow.mouseInside = false;
4128 guiApp.prevWindow = null;
4130 // Eventually fix this not to include captured?
4131 if(!prevWindow.OnMouseLeave(*mods))
4134 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4136 Box box = trueWindow.box;
4137 box.left += trueWindow.absPosition.x;
4138 box.right += trueWindow.absPosition.x;
4139 box.top += trueWindow.absPosition.y;
4140 box.bottom += trueWindow.absPosition.y;
4142 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4144 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4145 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4147 overX = Max(Min(overX, 32767),-32768);
4148 overY = Max(Min(overY, 32767),-32768);
4150 trueWindow.mouseInside = true;
4151 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4155 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4156 guiApp.prevWindow = trueWindow;
4158 guiApp.prevWindow = null;
4160 SelectMouseCursor();
4162 if(window && !guiApp.windowMoving && !wasMoving && !wasScrolling)
4164 int clientX = x - (window.absPosition.x + window.clientStart.x);
4165 int clientY = y - (window.absPosition.y + window.clientStart.y);
4167 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4169 clientX = Max(Min(clientX, 32767),-32768);
4170 clientY = Max(Min(clientY, 32767),-32768);
4172 MouseMethod = (void *)window._vTbl[method];
4174 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4177 if(!MouseMethod(window, clientX, clientY, *mods))
4184 if(result && w && w.clickThrough && w.parent)
4189 if(!result || !w || !w.clickThrough)
4196 // --- Mouse cursor management ---
4198 bool KeyMessage(uint method, Key key, unichar character)
4203 if(guiApp.interimWindow)
4204 this = guiApp.interimWindow;
4207 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4211 if(!style.inactive || rootWindow != this)
4213 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4214 Window modalWindow = FindModal();
4215 Window interimMaster = master ? master.rootWindow : null;
4219 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4220 status = OnSysKeyDown(key, character);
4221 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4222 status = OnSysKeyHit(key, character);
4223 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4224 status = OnSysKeyUp(key, character);
4231 // Process Key Message for Internal UI Keyboard actions
4232 if(status && !destroyed && menuBar && state != minimized)
4235 if((SmartKey)key != alt)
4236 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4239 SmartKey sk = (SmartKey) key;
4240 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4242 status = menuBar.KeyMessage(method, key, character);
4247 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4248 menuBar.OnKeyHit(escape, 0);
4250 if(!menuBar.focus && guiApp.caretOwner)
4251 guiApp.caretOwner.UpdateCaret(true, false);
4254 if(!destroyed && status)
4256 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4260 case left: case up: case right: case down:
4261 if(guiApp.windowMoving == this)
4264 int w = guiApp.windowMoving.size.w;
4265 int h = guiApp.windowMoving.size.h;
4266 int x = guiApp.windowMoving.scrolledPos.x;
4267 int y = guiApp.windowMoving.scrolledPos.y;
4271 if(key == down || key == up)
4272 step = Max(step, textCellH);
4274 step = Max(step, textCellW);
4277 if(guiApp.windowIsResizing)
4281 case left: w-=step; break;
4282 case right: w+=step; break;
4283 case up: h-=step; break;
4284 case down: h+=step; break;
4291 case left: x-=step; break;
4292 case right: x+=step; break;
4293 case up: y-=step; break;
4294 case down: y+=step; break;
4298 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4299 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4301 if(!guiApp.windowIsResizing || guiApp.resizeX)
4302 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4304 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4306 if(!guiApp.windowIsResizing || guiApp.resizeY)
4307 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4309 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4311 guiApp.interfaceDriver.SetMousePosition(x, y);
4312 ConsequentialMouseMove(true);
4320 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4322 guiApp.windowMoving.StopMoving();
4323 ConsequentialMouseMove(false);
4331 ShowSysMenu(absPosition.x, absPosition.y);
4339 if(!destroyed && status && state != minimized)
4341 // Process all the way down the children
4342 if(activeChild && !activeChild.disabled)
4344 status = activeChild.KeyMessage(method, key, character);
4346 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4347 key.code != left && key.code != right && key.code != up && key.code != down)
4349 status = activeClient.KeyMessage(method, key, character);
4353 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4355 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4356 // && defaultControl != activeChild)
4358 delete previousActive;
4359 previousActive = activeChild;
4360 if(previousActive) incref previousActive;
4362 ConsequentialMouseMove(false);
4363 if((defaultControl.active ||
4364 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4365 defaultControl.KeyMessage(method, defaultKey, character);
4371 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4373 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4380 ShowSysMenu(absPosition.x, absPosition.y);
4387 if(this != guiApp.desktop)
4389 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4391 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4393 MenuMoveOrSize(key.shift, true);
4397 else if(guiApp.windowMoving)
4399 guiApp.windowMoving.StopMoving();
4400 ConsequentialMouseMove(false);
4408 if(!destroyed && status && state != minimized)
4410 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4414 case tab: case shiftTab:
4416 Window cycleParent = this;
4417 if(this == guiApp.interimWindow && !master.style.interim && !cycleParent.style.tabCycle)
4418 cycleParent = master.parent;
4420 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4422 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4424 Window child = cycleParent.activeChild;
4426 // Scroll the window to include the active control
4428 if(cycleParent.sbh && !child.style.dontScrollHorz)
4430 if(child.scrolledPos.x < 0)
4431 cycleParent.sbh.Action(Position,
4432 cycleParent.scroll.x + child.scrolledPos.x, 0);
4433 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4434 cycleParent.sbh.Action(Position,
4435 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4437 if(cycleParent.sbv && !child.style.dontScrollVert)
4439 if(child.scrolledPos.y < 0)
4440 cycleParent.sbv.Action(Position,
4441 cycleParent.scroll.y + child.scrolledPos.y, 0);
4442 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4443 cycleParent.sbv.Action(Position,
4444 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4447 cycleParent.ConsequentialMouseMove(false);
4453 case f6: case shiftF6:
4454 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4456 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4457 if(parent == guiApp.desktop)
4458 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4463 if(style.tabCycle ||
4464 CycleChildren(key.shift, true, false, true))
4472 // mIRC Style Window Shortcuts
4473 case alt1: case alt2: case alt3: case alt4: case alt5:
4474 case alt6: case alt7: case alt8: case alt9: case alt0:
4479 for(document = children.first; document; document = document.next)
4481 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4483 if(document == activeChild)
4485 if(document.state == minimized)
4486 document.SetState(normal, false, key);
4489 document.SetState(minimized, false, key);
4490 CycleChildren(false, true, false);
4495 if(activeChild.state == maximized && document.style.hasMaximize)
4496 document.SetState(maximized, false, key);
4497 else if(document.state == minimized)
4498 document.SetState(normal, false, key);
4499 document.Activate();
4514 if(!destroyed && status)
4516 if(state == minimized)
4521 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4523 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4525 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4526 previousActive.ActivateEx(true, false, false, true, null, null);
4527 delete previousActive;
4533 if(!destroyed && status)
4535 status = ProcessHotKeys(method, key, character);
4537 if(!destroyed && status && !modalWindow && state != minimized)
4540 status = KeyMethod(this, key, character);
4541 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4542 status = OnKeyHit(key, character);
4543 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4545 bool result = false;
4548 case ctrlUp: case ctrlDown:
4549 if(sbv && !guiApp.windowScrolling)
4550 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4552 case wheelUp: case wheelDown:
4553 if(sbv && !guiApp.windowScrolling)
4555 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4556 // Do we want to do a consequential move regardless of result in this case?
4557 ConsequentialMouseMove(false);
4560 case ctrlPageUp: case ctrlPageDown:
4561 if(sbh && !guiApp.windowScrolling)
4562 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4567 ConsequentialMouseMove(false);
4572 if(status && !destroyed && menuBar && state != minimized)
4573 status = menuBar.KeyMessage(method, key, character);
4575 if(style.interim && /*destroyed && */status && interimMaster)
4577 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4578 status = interimMaster.KeyMessage(method, key, character);
4585 bool ProcessHotKeys(uint method, Key key, unichar character)
4590 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4591 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4592 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4594 Window hotKeyWindow = hotKey.window;
4595 Window parent = hotKeyWindow.parent;
4596 Window prevActiveWindow = activeChild;
4598 // Don't process non-visible buttons, but make an exception for the Alt-F4 with Native Decorations turned on
4599 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1] )))
4602 if(prevActiveWindow) incref prevActiveWindow;
4603 incref hotKeyWindow;
4604 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient)
4605 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4608 delete hotKeyWindow;
4609 delete prevActiveWindow;
4613 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4614 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4615 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4617 // ********* WORKING ON THIS ***********
4618 if(prevActiveWindow && !guiApp.interimWindow)
4619 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4622 else if(hotKeyWindow.style.inactive)
4623 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4625 delete prevActiveWindow;
4626 delete hotKeyWindow;
4627 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4628 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4632 if(status && tabCycle)
4635 for(child = children.first; child; child = child.next)
4637 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4648 // --- Windows and graphics initialization / termination ---
4649 bool SetupRoot(void)
4653 // Setup relationship with outside world (bb root || !bb)
4654 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4655 (_displayDriver && dispDriver != parent.dispDriver))
4659 tempExtents = new0 Extent[4];
4664 /*if(guiApp.fullScreenMode)
4665 rootWindow = guiApp.desktop;
4667 //rootWindow = parent.created ? parent.rootWindow : null;
4668 rootWindow = parent.rootWindow;
4671 against = &parent.box;
4673 against = &parent.clientArea;
4676 for(child = children.first; child; child = child.next)
4679 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
4682 bool Setup(bool positionChildren)
4684 bool result = false;
4687 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && dispDriver != parent.dispDriver))))
4689 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
4690 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
4692 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
4694 // This was here, is it really needed?
4695 //guiApp.interfaceDriver.ActivateRootWindow(this);
4699 displaySystem = DisplaySystem {};
4700 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
4702 delete displaySystem;
4707 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData };
4708 if(display.Create(displaySystem, windowHandle))
4715 guiApp.interfaceDriver.SetIcon(this, icon);
4717 else if(this != guiApp.desktop)
4719 display = rootWindow ? rootWindow.display : null;
4725 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
4726 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
4728 for(child = children.first; child; child = child.next)
4730 if(child.created && !child.Setup(false))
4736 bool SetupDisplay(void)
4738 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
4739 if(is3D) return Window3D_SetupDisplay(this); else
4746 class_data void ** pureVTbl;
4748 bool LoadGraphics(bool creation, bool resetAnchors)
4750 bool result = false;
4751 bool success = false;
4753 WindowState stateBackup = state;
4756 if(!rootWindow.created)
4760 if(((subclass(Window))_class).pureVTbl)
4762 if(_vTbl == _class._vTbl)
4764 _vTbl = ((subclass(Window))_class).pureVTbl;
4769 for(m = 0; m < _class.vTblSize; m++)
4771 if(_vTbl[m] == _class._vTbl[m])
4772 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
4776 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
4778 if(_vTbl == ((subclass(Window))_class).pureVTbl)
4780 _vTbl = _class._vTbl;
4785 for(m = 0; m < _class.vTblSize; m++)
4787 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
4788 _vTbl[m] = _class._vTbl[m];
4793 if(guiApp.fullScreenMode || this != guiApp.desktop)
4795 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
4801 display.Lock(false);
4802 if(rootWindow == this)
4804 // Set Color Palette
4805 display.SetPalette(palette, true);
4809 if(guiApp.fullScreenMode && this == guiApp.desktop)
4814 for(c=0; c<SystemCursor::enumSize; c++)
4815 if(!guiApp.systemCursors[c].bitmap)
4817 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
4818 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
4819 if(guiApp.systemCursors[c].bitmapName)
4821 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
4822 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
4823 if(guiApp.systemCursors[c].bitmap)
4824 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
4829 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
4831 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
4832 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
4834 cursor.bitmap.paletteShades = cursor.paletteShades;
4838 guiApp.cursorUpdate = true;
4841 ConsequentialMouseMove(false);
4847 // Load Window Graphic Resources
4850 if(usedFont == setFont || usedFont == window.systemFont)
4851 RemoveResource(usedFont);
4854 RemoveResource(setFont); // TESTING setFont instead of usedFont);
4857 RemoveResource(systemFont);
4860 RemoveResource(captionFont);
4862 for(ptr = resources.first; ptr; ptr = ptr.next)
4864 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
4867 AddResource(setFont);
4869 AddResource(systemFont);
4871 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
4878 //if(master && master.font)
4879 if(parent && parent.font)
4883 faceName = parent.font.faceName,
4884 size = parent.font.size,
4885 bold = parent.font.bold,
4886 italic = parent.font.italic,
4887 underline = parent.font.underline
4889 //font = parent.font;
4890 watch(parent) { font { } };
4893 font = guiApp.currentSkin.SystemFont();
4900 captionFont = guiApp.currentSkin.CaptionFont();
4901 AddResource(captionFont);
4903 if(OnLoadGraphics())
4909 //SetScrollLineStep(sbStep.x, sbStep.y);
4911 if(this != guiApp.desktop)
4915 normalAnchor = anchor;
4916 normalSizeAnchor = sizeAnchor;
4919 // Break the anchors for moveable/resizable windows
4921 if(style.fixed && style.isDocument)
4923 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
4935 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
4936 stateSizeAnchor = SizeAnchor {};
4941 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
4946 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
4947 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
4950 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
4954 stateAnchor = normalAnchor;
4955 stateSizeAnchor = normalSizeAnchor;
4958 position = Point { };
4959 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
4970 if(Position(x, y, w, h, true, false, true, true, true, true))
4972 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
4975 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
4992 success = result = true;
4995 if(!creation && result)
4997 // Load menu bar first because sys buttons are on it...
5000 if(!menuBar.LoadGraphics(false, resetAnchors))
5006 for(child = children.first; child; child = child.next)
5008 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
5015 CreateSystemChildren();
5019 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5022 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5027 //guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, caption);
5028 guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, class.name);
5031 // Do this here to avoid problems on Windows
5032 if(stateBackup == maximized)
5033 property::state = maximized;
5037 void UnloadGraphics(bool destroyWindows)
5041 // Free children's graphics
5042 for(child = children.first; child; child = child.next)
5043 child.UnloadGraphics(destroyWindows);
5046 display.Lock(false);
5049 if(guiApp.fullScreenMode && this == guiApp.desktop)
5054 for(c=0; c<SystemCursor::enumSize; c++)
5055 if(guiApp.systemCursors[c].bitmap)
5056 delete guiApp.systemCursors[c].bitmap;
5058 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5059 delete cursor.bitmap;
5061 guiApp.cursorBackground.Free();
5064 if(display && display.displaySystem)
5068 for(ptr = resources.first; ptr; ptr = ptr.next)
5072 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5077 // Free window graphics
5080 // Free skin graphics
5081 if(rootWindow == this)
5083 DisplaySystem displaySystem = display.displaySystem;
5086 display.driverData = null;
5087 display.displaySystem = null;
5091 if(displaySystem && !displaySystem.numDisplays && !is3D)
5092 delete displaySystem;
5101 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5102 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5104 if(this == guiApp.desktop || parent == guiApp.desktop)
5106 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5107 guiApp.interfaceDriver.DestroyRootWindow(this);
5111 // --- Window Hiding ---
5113 void SetVisibility(bool state)
5115 bool visible = (style.hidden || !created) ? false : state;
5116 if(visible != this.visible)
5120 this.visible = visible;
5121 for(child = children.first; child; child = child.next)
5122 child.SetVisibility(visible);
5124 ConsequentialMouseMove(false);
5125 if(parent && !nonClient) parent.OnChildVisibilityToggled(this, visible);
5129 // --- Windows and graphics initialization / termination ---
5131 bool DisplayModeChanged(void)
5133 bool result = false;
5134 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5136 guiApp.modeSwitching = true;
5137 UnloadGraphics(false);
5139 if(LoadGraphics(false, false))
5141 guiApp.modeSwitching = false;
5146 // --- Window updates system ---
5148 void UpdateDirty(Box updateBox)
5150 if(!manageDisplay) { OnRedraw(null);return; }
5153 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5156 if(display.flags.flipping)
5159 rootWindow.UpdateDisplay();
5162 UpdateBackDisplay(updateBox);
5164 if(guiApp.fullScreenMode)
5166 guiApp.cursorUpdate = true;
5167 guiApp.PreserveAndDrawCursor();
5169 if(guiApp.fullScreenMode)
5170 guiApp.RestoreCursorBackground();
5176 // This function is strictly called as a result of system window activation
5177 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5180 Window interimMaster = null;
5181 Window interimWindow = guiApp.interimWindow;
5182 if(interimWindow && interimWindow.master)
5183 interimMaster = interimWindow.master.rootWindow;
5185 if(active && state == minimized) // && (!window.nativeDecorations || window.rootWindow != window)
5186 // SetState(normal, false, 0);
5187 SetState(lastState, false, 0);
5189 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5193 /* WTH is this doing here?
5194 while(swap && swap.activeChild)
5196 swap = swap.activeChild;
5199 // TESTING THIS BEFORE...
5200 if(interimWindow && this == interimMaster)
5204 // Window interimSwap = this;
5205 Window menuBar = this.menuBar;
5206 if(menuBar && interimWindow.master == menuBar)
5209 while(interimSwap && interimSwap.activeChild)
5210 interimSwap = interimSwap.activeChild;
5212 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5213 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5215 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5216 //result = ActivateEx(true, true, false, activateRoot, window, null);
5221 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5222 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5224 if(interimWindow == this && interimMaster && !active)
5226 while(interimMaster && interimMaster.interim && interimMaster.master)
5228 // printf("Going up one master %s\n", interimMaster._class.name);
5229 interimMaster = interimMaster.master.rootWindow;
5231 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5232 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5238 bool DestroyEx(int returnCode)
5241 Timer timer, nextTimer;
5243 OldLink prevOrder = null;
5244 Window client = null;
5246 if(parent) stopwatching(parent, font);
5248 // if(window.modalSlave) return false;
5249 if(destroyed || !created)
5256 OldLink slave = master.slaves.FindLink(this);
5257 master.slaves.Delete(slave);
5260 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5266 this.returnCode = (DialogResult)returnCode;
5268 AcquireInput(false);
5273 master.hotKeys.Delete(hotKey);
5277 if(guiApp.prevWindow == this)
5279 guiApp.prevWindow = null;
5282 if(guiApp.caretOwner == this)
5284 guiApp.interfaceDriver.SetCaret(0,0,0);
5285 UpdateCaret(false, true);
5286 guiApp.caretEnabled = false;
5291 parent.childrenCycle.Remove(cycle);
5295 OldLink tmpPrev = order.prev;
5296 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5297 prevOrder = tmpPrev;
5300 client = tmpPrev ? tmpPrev.data : null;
5301 if(client == this) { client = null; break; }
5302 if(client && (client.style.hidden || client.destroyed || !client.created))
5303 tmpPrev = client.order.prev;
5307 prevOrder = tmpPrev;
5312 // If this window can be an active client, make sure the next window we activate can also be one
5313 if(!style.nonClient && style.isActiveClient)
5315 tmpPrev = prevOrder;
5318 client = tmpPrev ? tmpPrev.data : null;
5319 if(client == this) { client = null; break; }
5320 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5321 tmpPrev = client.order.prev;
5325 prevOrder = tmpPrev;
5329 if(client && client.style.hidden) client = null;
5331 // parent.childrenOrder.Remove(order);
5334 if(parent && style.isActiveClient && visible)
5336 if(state == minimized) parent.numIcons--;
5337 parent.numPositions--;
5340 // TESTING THIS HERE!
5344 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5345 // to create a window inside a rootwindow that's being destroyed)
5346 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5348 if(master && !master.destroyed /*&&
5349 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5351 if(master.defaultControl == this)
5352 master.defaultControl = null;
5354 if(parent && !parent.destroyed /*&&
5355 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5357 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5359 if(order && prevOrder && prevOrder.data != this && active)
5361 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5363 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5364 if(parent.activeClient == this)
5366 parent.activeClient = null;
5367 parent.UpdateActiveDocument(null);
5372 if(guiApp.interimWindow == this)
5375 PropagateActive(false, null, &goOn, true);
5379 //if(window.parent.activeChild == window)
5380 parent.activeChild = null;
5381 if(!style.nonClient /*&& style.isActiveClient*/)
5383 Window previous = parent.activeClient;
5384 if(style.isActiveClient)
5385 parent.activeClient = null;
5386 parent.UpdateActiveDocument(previous);
5391 else if(parent.activeClient == this)
5393 parent.activeClient = client;
5394 parent.UpdateActiveDocument(this);
5398 if(guiApp.interimWindow == this)
5400 guiApp.interimWindow = null;
5401 if(guiApp.caretOwner)
5403 Window desktop = guiApp.desktop;
5404 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5405 guiApp.caretOwner.UpdateCaret(false, false);
5410 if(_isModal && master && master.modalSlave == this)
5411 master.modalSlave = null;
5415 if(!guiApp.caretOwner && parent.caretSize)
5417 guiApp.caretOwner = parent;
5418 parent.UpdateCaret(false, false);
5419 parent.Update(null);
5422 // Why was this commented out?
5423 GetRidOfVirtualArea();
5429 dirtyArea.Free(null);
5430 dirtyBack.Free(null);
5431 scrollExtent.Free(null);
5433 /* ATTEMPTING TO MOVE THAT ABOVE
5442 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5443 for(;(child = window.children.first);)
5445 for(; child && (child.destroyed || !child.created); child = child.next);
5454 UnloadGraphics(true);
5457 delete previousActive;
5460 // statusBar = null;
5463 if(master && !master.destroyed)
5465 //master.NotifyDestroyed(this, this.returnCode);
5466 NotifyDestroyed(master, this, this.returnCode);
5469 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5471 nextTimer = timer.next;
5472 if(timer.window == this)
5474 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5475 // timer.window = null;
5481 if(this == guiApp.windowMoving)
5484 if(guiApp.windowCaptured == this)
5486 //guiApp.windowCaptured = null;
5488 if(rootWindow != this && rootWindow)
5489 rootWindow.ConsequentialMouseMove(false);
5497 //for(child = children.first; next = child ? child.next : null, child; child = next)
5498 for(;(child = children.first); )
5500 for(; child && (child.destroyed || !child.created); child = child.next);
5510 /* // MOVED THIS UP...
5513 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5514 for(;(child = window.children.first); )
5516 for(; child && (child.destroyed || !child.created); child = child.next);
5525 while((slave = slaves.first))
5527 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5529 ((Window)slave.data).DestroyEx(0);
5534 if(guiApp.caretOwner == this)
5535 guiApp.caretOwner = null;
5537 sysButtons[0] = null;
5538 sysButtons[1] = null;
5539 sysButtons[2] = null;
5542 if(rootWindow != this)
5544 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5547 box.left -= parent.clientStart.x;
5548 box.top -= parent.clientStart.y;
5549 box.right -= parent.clientStart.x;
5550 box.bottom -= parent.clientStart.y;
5552 if(parent) parent.Update(box);
5557 OldLink slave = master.slaves.FindVoid(this);
5558 master.slaves.Delete(slave);
5564 parent.children.Remove(this);
5569 //autoCreate = false;
5572 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5573 if(((subclass(Window))_class).pureVTbl)
5575 if(_vTbl == _class._vTbl)
5577 _vTbl = ((subclass(Window))_class).pureVTbl;
5582 for(m = 0; m < _class.vTblSize; m++)
5584 if(_vTbl[m] == _class._vTbl[m])
5585 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5594 void SetStateEx(WindowState newState, bool activate)
5597 WindowState prevState = state;
5601 if(prevState != newState)
5602 lastState = prevState;
5604 if(rootWindow != this || !nativeDecorations)
5606 if(style.isActiveClient && !style.hidden && prevState == minimized)
5609 // This block used to be at the end of the function... moved it for flicker problem in X
5610 // ------------------------------------------------------
5614 stateAnchor = normalAnchor;
5615 stateSizeAnchor = normalSizeAnchor;
5618 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5619 stateSizeAnchor = SizeAnchor {};
5623 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5626 byte * idBuffer = new0 byte[size];
5628 for(child = parent.children.first; child; child = child.next)
5630 if(child != this && child.state == minimized)
5632 if(child.iconID > size - 2)
5634 idBuffer = renew0 idBuffer byte[size*2];
5635 memset(idBuffer + size, 0, size);
5638 idBuffer[child.iconID] = (byte)bool::true;
5641 for(c = 0; c<size; c++)
5646 if(style.isActiveClient && !style.hidden)
5649 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5650 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5654 // TOCHECK: Why was this here?
5655 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5656 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5657 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5659 Position(x, y, w, h, true, true, true, true, false, true);
5661 if(!style.inactive && !style.interim && this == parent.activeClient)
5662 parent.UpdateActiveDocument(null);
5665 CreateSystemChildren();
5666 // ------------------------------------------------------
5669 int GetPositionID(Window forChild)
5673 byte * idBuffer = new0 byte[size];
5676 for(child = children.first; child; child = child.next)
5678 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
5680 if(child.positionID > size - 2)
5682 idBuffer = renew0 idBuffer byte[size*2];
5683 memset(idBuffer + size, 0, size);
5686 idBuffer[child.positionID] = (byte)bool::true;
5689 for(c = 0; c<size; c++)
5696 // --- Window related graphics ---
5698 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
5700 palette = newPalette;
5701 if(rootWindow.display)
5702 rootWindow.display.SetPalette(palette, colorMatch);
5705 public bool AcquireInput(bool acquired)
5708 if(acquiredInput != acquired)
5710 if(active || (!visible && creationActivation == activate))
5711 result = AcquireInputEx(acquired);
5716 acquiredInput = acquired ? result : !result;
5721 void ListChildren(ListBox listBox)
5725 for(child = children.first; child; child = child.next)
5727 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
5729 DataRow row = listBox.AddRow();
5730 row.tag = (int)child;
5731 child.FigureCaption(caption);
5732 row.SetData(null, caption);
5737 void UpdateVisual(Box extent)
5739 if(guiApp.driver != null)
5741 if(guiApp.fullScreenMode && guiApp.desktop.display)
5743 guiApp.desktop.mutex.Wait();
5744 guiApp.desktop.display.Lock(true);
5747 if(guiApp.desktop.active)
5749 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
5751 if(guiApp.desktop.display.flags.flipping)
5752 guiApp.desktop.Update(null);
5753 guiApp.desktop.UpdateDisplay();
5754 guiApp.cursorUpdate = true;
5756 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
5758 guiApp.PreserveAndDrawCursor();
5759 // guiApp.desktop.display.ShowScreen();
5760 guiApp.cursorUpdate = false;
5761 guiApp.desktop.dirty = false;
5762 guiApp.RestoreCursorBackground();
5766 guiApp.desktop.display.Unlock();
5767 guiApp.desktop.mutex.Release();
5771 Window rootWindow = this.rootWindow;
5772 rootWindow.mutex.Wait();
5777 guiApp.SignalEvent();
5780 guiApp.waitMutex.Wait();
5781 guiApp.interfaceDriver.Lock(rootWindow);
5782 if(!rootWindow.style.hidden && rootWindow.dirty)
5784 if(rootWindow.display)
5786 rootWindow.UpdateDisplay();
5787 //rootWindow.display.ShowScreen(null);
5789 rootWindow.dirty = false;
5791 guiApp.interfaceDriver.Unlock(rootWindow);
5792 guiApp.waitMutex.Release();
5795 rootWindow.mutex.Release();
5800 void UnlockDisplay(void)
5802 guiApp.interfaceDriver.Unlock(rootWindow);
5805 void LockDisplay(void)
5807 guiApp.interfaceDriver.Lock(rootWindow);
5810 Surface GetSurface(Box box)
5812 return Redraw((box == null) ? this.box : box);
5815 void SetMousePosition(int x, int y)
5817 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
5821 void IntegrationActivate(bool active)
5823 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
5825 isForegroundWindow = true;
5826 ActivateEx(active, active, false, false, null, null);
5827 isForegroundWindow = false;
5832 Window QueryCapture(void)
5834 return guiApp.windowCaptured;
5837 int GetDocumentID(void)
5841 byte * idBuffer = new0 byte[size];
5844 for(child = children.first; child; child = child.next)
5846 if(child.style.isDocument)
5848 if(child.documentID-1 > size - 2)
5850 idBuffer = renew0 idBuffer byte[size*2];
5851 memset(idBuffer + size, 0, size);
5854 idBuffer[child.documentID-1] = 1;
5857 for(c = 0; c<size; c++)
5865 void SetInitSize(Size size)
5868 sizeAnchor.size = size;
5869 normalSizeAnchor = sizeAnchor;
5871 // Break the anchors for moveable/resizable windows
5872 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
5874 stateAnchor = normalAnchor;
5875 stateSizeAnchor = normalSizeAnchor;
5877 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5878 Position(x,y, w, h, true, true, true, true, false, true);
5882 void MenuMoveOrSize(bool resize, bool setCursorPosition)
5884 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
5886 guiApp.windowIsResizing = resize;
5887 guiApp.windowMoving = this;
5888 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
5889 if(guiApp.windowIsResizing)
5891 guiApp.windowMovingStart.x += size.w - 1;
5892 guiApp.windowMovingStart.y += size.h - 1;
5894 guiApp.windowMovingBefore = scrolledPos;
5895 guiApp.windowResizingBefore = size;
5896 guiApp.windowMoving.UpdateDecorations();
5897 if(guiApp.windowIsResizing)
5898 guiApp.resizeEndX = guiApp.resizeEndY = true;
5900 if(setCursorPosition)
5901 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
5905 guiApp.interfaceDriver.GetMousePosition(&x, &y);
5906 guiApp.windowMovingStart.x += x - absPosition.x;
5907 guiApp.windowMovingStart.y += y - absPosition.y;
5910 if(guiApp.windowMoving)
5912 if(guiApp.windowMoving.style.nonClient)
5913 guiApp.windowMoving.parent.SetMouseRangeToWindow();
5915 guiApp.windowMoving.parent.SetMouseRangeToClient();
5920 if(this == rootWindow)
5921 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
5929 bool result = false;
5933 else if(guiApp && guiApp.driver != null)
5935 void * systemParent = null;
5936 OldLink slaveHolder;
5938 bool visible = !style.hidden;
5942 systemParent = parent;
5943 parent = guiApp.desktop;
5945 last = parent ? parent.children.last : null;
5947 if((parent && parent != guiApp.desktop && !parent.created) ||
5948 (master && master != guiApp.desktop && !master.created))
5952 property::parent = guiApp.desktop;
5953 if(!master) master = parent;
5955 if(_isModal && master.modalSlave)
5956 property::master = master.modalSlave;
5960 parent.children.Remove(this);
5963 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
5964 if(slaveHolder.data == this)
5966 master.slaves.Delete(slaveHolder);
5971 if(parent == guiApp.desktop && !mutex)
5974 if(style.isDocument)
5977 parent.numDocuments--;
5978 documentID = parent.GetDocumentID();
5981 if(!style.stayOnTop)
5982 for(; last && last.style.stayOnTop; last = last.prev);
5984 parent.children.Insert((last == this) ? null : last, this);
5985 //parent.children.Add(this);
5988 dispDriver = parent.dispDriver;
5991 master.modalSlave = this;
5993 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
5998 master.slaves.Add(slaveHolder = OldLink { data = this });
6003 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
6005 if(style.isDefault && !master.defaultControl)
6006 master.defaultControl = this;
6008 stateAnchor = normalAnchor = anchor;
6009 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
6011 // TOCHECK: Why is this here?
6012 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
6013 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
6015 this.visible = false;
6016 style.hidden = true;
6019 // autoCreate = true;
6027 if(parent == guiApp.desktop)
6028 Log("LoadGraphics %s\n", caption);
6030 if(LoadGraphics(true, false))
6038 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6045 if(style.hasMenuBar /*&& menu*/)
6051 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6052 interim = false, inactive = true, nonClient = true, size.h = 24
6060 // Create the system buttons
6061 CreateSystemChildren();
6063 UpdateActiveDocument(null);
6065 if(style.isDocument)
6069 MenuItem item = menu.FindItem(MenuFileSave, 0);
6070 if(item) item.disabled = !modifiedDocument && fileName;
6075 if(parent == guiApp.desktop)
6076 Log("Preemptive SetState %s\n", caption);
6079 // Preemptive Set State to ensure proper anchoring
6080 SetStateEx(state, false);
6082 style.hidden = true;
6088 for(child = children.first; child; child = next)
6091 if(!child.created && (child.autoCreate || child.wasCreated))
6098 for(link = slaves.first; link; link = next)
6100 Window slave = link.data;
6102 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6111 if(parent == guiApp.desktop)
6112 Log("Real SetState %s\n", caption);
6115 if(isActiveClient && visible)
6117 parent.numPositions--;
6118 if(state == minimized) parent.numIcons--;
6121 // Real set state & activate for proper display & activation
6122 property::visible = visible;
6123 // SetState(state & 0x00000003, true, 0);
6128 /*if(rootWindow == this)
6129 guiApp.interfaceDriver.ActivateRootWindow(this);
6131 if(creationActivation == activate)
6132 ActivateEx(true, false, true, true, null, null);
6133 else if(creationActivation == flash)
6138 rootWindow.ConsequentialMouseMove(false);
6149 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6155 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6157 //style.hidden = true; // !visible;
6158 style.hidden = !visible;
6159 if(master.modalSlave == this)
6160 master.modalSlave = null;
6167 void WriteCaption(Surface surface, int x, int y)
6170 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6173 void Update(Box region)
6179 rootWindow = this.rootWindow;
6181 // rootWindow.mutex.Wait();
6182 if(!destroyed && visible && display)
6187 // Testing this to avoid repetitve full update to take time...
6188 if(dirtyArea.count == 1)
6190 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6191 if(item.box.left <= box.left &&
6192 item.box.top <= box.top &&
6193 item.box.right >= box.right &&
6194 item.box.bottom >= box.bottom)
6196 rootWindow.dirty = true;
6201 if(display.flags.flipping && !rootWindow.dirty)
6203 if(this == rootWindow)
6207 rootWindow.Update(null);
6212 rootWindow.dirty = true;
6217 realBox.left += clientStart.x;
6218 realBox.top += clientStart.y;
6219 realBox.right += clientStart.x;
6220 realBox.bottom += clientStart.y;
6226 if(realBox.right >= realBox.left &&
6227 realBox.bottom >= realBox.top)
6229 // if(!rootWindow.fullRender)
6230 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6232 for(child = children.first; child; child = child.next)
6237 box.left -= child.absPosition.x - absPosition.x;
6238 box.top -= child.absPosition.y - absPosition.y;
6239 box.right -= child.absPosition.x - absPosition.x;
6240 box.bottom -= child.absPosition.y - absPosition.y;
6241 if(box.right >= child.box.left && box.left <= child.box.right &&
6242 box.bottom >= child.box.top && box.top <= child.box.bottom)
6244 box.left -= child.clientStart.x;
6245 box.top -= child.clientStart.y;
6246 box.right -= child.clientStart.x;
6247 box.bottom -= child.clientStart.y;
6253 realBox.left += absPosition.x - rootWindow.absPosition.x;
6254 realBox.top += absPosition.y - rootWindow.absPosition.y;
6255 realBox.right += absPosition.x - rootWindow.absPosition.x;
6256 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6257 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6260 else if(this == guiApp.desktop)
6263 for(window = children.first; window; window = window.next)
6269 Box childBox = region;
6271 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6272 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6273 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6274 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6276 window.Update(childBox);
6279 window.Update(null);
6284 // rootWindow.mutex.Release();
6291 if(guiApp.windowCaptured != this)
6293 if(guiApp.windowCaptured)
6297 //Logf("Captured %s (%s)\n", caption, class.name);
6298 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6299 guiApp.windowCaptured = this;
6305 bool Destroy(int code)
6310 if(!destroyed && !CloseConfirmation(false)) return false;
6314 // TOCHECK: Should autoCreate be set to false here?
6325 void Move(int x, int y, int w, int h)
6327 normalAnchor = Anchor { left = x, top = y };
6328 normalSizeAnchor = SizeAnchor { size = { w, h } };
6330 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6332 if(destroyed) return;
6334 stateAnchor = normalAnchor;
6335 stateSizeAnchor = normalSizeAnchor;
6337 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6338 Position(x,y, w, h, true, true, true, true, false, true);
6342 DialogResult Modal(void)
6348 // FIXES MEMORY LEAK IF Create() FAILED
6354 void SetScrollArea(int width, int height, bool snapToStep)
6356 bool resize = false;
6359 int stepX = sbStep.x, stepY = sbStep.y;
6360 // Needed to make snapped down position match the skin's check of client area
6361 // against realvirtual
6364 SNAPDOWN(stepX, textCellW);
6365 SNAPDOWN(stepY, textCellH);
6366 stepX = Max(stepX, textCellW);
6367 stepY = Max(stepY, textCellH);
6369 if(scrollFlags.snapX)
6370 SNAPUP(width, stepX);
6371 if(scrollFlags.snapY)
6372 SNAPUP(height, stepY);
6375 reqScrollArea.w = width;
6376 reqScrollArea.h = height;
6377 noAutoScrollArea = (width > 0 || height > 0);
6379 UpdateScrollBars(true, true);
6382 void SetScrollPosition(int x, int y)
6385 sbh.Action(setPosition, x, 0);
6389 int seen = clientSize.w, total = reqScrollArea.w;
6391 if(scrollFlags.snapX)
6392 SNAPDOWN(seen, sbStep.x);
6394 if(!total) total = seen;
6395 range = total - seen + 1;
6396 range = Max(range, 1);
6398 if(x >= range) x = range - 1;
6400 if(scrollFlags.snapX)
6401 SNAPUP(x, sbStep.x);
6404 OnHScroll(setPosition, x, 0);
6408 SNAPDOWN(x, textCellW);
6414 sbv.Action(setPosition, y, 0);
6418 int seen = clientSize.h, total = reqScrollArea.h;
6421 if(scrollFlags.snapY)
6422 SNAPDOWN(seen, sbStep.y);
6424 if(!total) total = seen;
6425 range = total - seen + 1;
6426 range = Max(range, 1);
6428 if(y >= range) y = range - 1;
6430 if(scrollFlags.snapY)
6431 SNAPUP(y, sbStep.y);
6434 OnVScroll(setPosition, y, 0);
6437 SNAPDOWN(y, textCellH);
6442 UpdateCaret(false, false);
6445 void SetScrollLineStep(int stepX, int stepY)
6451 SNAPDOWN(stepX, textCellW);
6452 SNAPDOWN(stepY, textCellH);
6453 stepX = Max(stepX, textCellW);
6454 stepY = Max(stepY, textCellH);
6457 sbh.lineStep = stepX;
6459 sbv.lineStep = stepY;
6462 void SetState(WindowState newState, bool activate, Modifiers mods)
6466 if(state == newState || OnStateChange(newState, mods))
6468 WindowState prevState = state;
6472 // This used to be at the end of the brackets... moved for X, testing...
6473 // This has the effect of activating the window through the system...
6474 if(rootWindow == this)
6475 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6477 SetStateEx(newState, activate);
6479 if(rootWindow == this && !rootWindow.nativeDecorations)
6481 int x = position.x, y = position.y;
6484 x -= guiApp.desktop.absPosition.x;
6485 y -= guiApp.desktop.absPosition.y;
6487 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6491 //state = prevState;
6493 if(state != maximized && style.hasMaximize)
6496 for(child = parent.children.first; child; child = child.next)
6498 if(child != this && child.state == maximized)
6499 child.SetStateEx(normal, false);
6503 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6504 parent.UpdateScrollBars(true, true);
6507 // Do we really need this stuff here?
6508 // Shouldn't the Activate stuff take care of it?
6509 if(parent.rootWindow == parent && style)
6512 parent.FigureCaption(caption);
6513 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6514 parent.UpdateDecorations();
6518 rootWindow.ConsequentialMouseMove(false);
6525 BitmapResource GetIcon(SkinBitmap iconID)
6527 return guiApp.currentSkin.GetBitmap(iconID);
6530 void SetMouseRange(Box range)
6532 if(range || guiApp.fullScreenMode)
6537 clip.left = range.left + absPosition.x + clientStart.x;
6538 clip.top = range.top + absPosition.y + clientStart.y;
6539 clip.right = range.right + absPosition.x + clientStart.x;
6540 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6544 clip.left = guiApp.desktop.box.left;
6545 clip.top = guiApp.desktop.box.top;
6546 clip.right = guiApp.desktop.box.right;
6547 clip.bottom = guiApp.desktop.box.bottom;
6549 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6552 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6555 void SetMouseRangeToClient(void)
6557 if(guiApp.fullScreenMode || this != guiApp.desktop)
6559 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6560 box.Clip(clientArea);
6564 SetMouseRange(null);
6567 void SetMouseRangeToWindow(void)
6569 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6570 if(this == guiApp.desktop)
6571 SetMouseRangeToClient();
6576 // x, y: Desktop Coordinates
6577 void ShowSysMenu(int x, int y)
6580 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6583 menu, $"Restore", r, NotifySelect = MenuWindowRestore,
6584 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6588 menu, $"Move", m, NotifySelect = MenuWindowMove,
6589 disabled = !style.fixed || state == maximized
6593 menu, $"Size", s, NotifySelect = MenuWindowSize,
6594 disabled = !style.sizable || state != normal
6598 menu, $"Minimize", n, NotifySelect = MenuWindowMinimize,
6599 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6603 menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6604 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6608 menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6609 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6611 MenuDivider { menu };
6614 menu, $"Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6615 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6617 windowMenu.Create();
6622 ActivateEx(true, true, true, true, null, null);
6625 void MakeActive(void)
6627 ActivateEx(true, false, true, false, null, null);
6630 void SoftActivate(void)
6632 if(guiApp.desktop.active)
6638 void Deactivate(void)
6640 ActivateEx(false, true, true, true, null, null);
6645 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
6648 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
6650 bool result = false;
6651 if(activeChild && activeChild.cycle)
6653 Window modalWindow, child = activeChild;
6654 if(!clientOnly /*&& parent.tabCycle*/)
6656 Window next = child;
6659 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
6663 if(parent && parent.CycleChildren(backward, false, true, true))
6671 next = next.cycle.prev.data;
6673 next = next.cycle.next.data;
6674 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
6679 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
6680 parent.tabCycle && parent.CycleChildren(backward, false, false))
6684 if(tabCycleOnly && !tabCycle) return false;
6691 child = child.cycle.prev.data;
6693 child = child.cycle.next.data;
6694 if(child == child.parent.activeChild)
6696 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
6699 modalWindow = child.FindModal();
6702 // Scroll the window to include the active control
6703 if(sbh && !child.style.dontScrollHorz)
6705 if(child.scrolledPos.x < 0)
6706 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
6707 else if(child.scrolledPos.x + child.size.w > clientSize.w)
6708 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
6710 if(sbv && !child.style.dontScrollVert)
6712 if(child.scrolledPos.y < 0)
6713 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
6714 else if(child.scrolledPos.y + child.size.h > clientSize.h)
6715 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
6719 child = modalWindow ? modalWindow : child;
6720 child.ActivateEx(true, true, true, true, null, null);
6721 if(child.tabCycle && child.childrenCycle.first)
6722 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
6730 ConsequentialMouseMove(false);
6734 void AddResource(Resource resource)
6738 ResPtr ptr { resource = resource };
6742 // Load Graphics here if window is created already
6743 if(/*created && */display)
6745 display.Lock(false);
6746 ptr.loaded = display.displaySystem.LoadResource(resource);
6750 // Temporary hack to load font right away for listbox in dropbox ...
6751 else if(master && master.display)
6753 master.display.Lock(false);
6754 master.display.displaySystem.LoadResource(resource);
6755 master.display.Unlock();
6761 void RemoveResource(Resource resource)
6766 for(ptr = resources.first; ptr; ptr = ptr.next)
6768 if(ptr.resource == resource)
6774 // Unload Graphics here if window is created already
6775 if(/*created && */display)
6779 display.Lock(false);
6780 display.displaySystem.UnloadResource(resource, ptr.loaded);
6786 resources.Delete(ptr);
6791 void SetCaret(int x, int y, int size)
6798 if(active && !style.interim)
6800 if(visible || !guiApp.caretOwner)
6801 guiApp.caretOwner = size ? this : null;
6803 UpdateCaret(false, false);
6806 guiApp.interfaceDriver.SetCaret(0,0,0);
6807 UpdateCaret(false, true);
6808 guiApp.caretEnabled = false;
6811 else if(style.inactive && active)
6813 guiApp.interfaceDriver.SetCaret(0,0,0);
6814 UpdateCaret(false, true);
6815 guiApp.caretEnabled = false;
6820 void Scroll(int x, int y)
6822 bool opaque = !style.drawBehind || background.a;
6823 if(opaque && display && display.flags.scrolling)
6825 Box box = clientArea;
6826 box.left += clientStart.x;
6827 box.top += clientStart.y;
6828 box.right += clientStart.x;
6829 box.bottom += clientStart.y;
6831 //scrollExtent.Free(null);
6832 scrollExtent.AddBox(box);
6833 scrolledArea.x += x;
6834 scrolledArea.y += y;
6836 //scrollExtent.Free();
6837 //scrollExtent.AddBox(clientArea);
6838 //scrollExtent.Offset(clientStart.x, clientStart.y);
6839 //scrolledArea.x = x;
6840 //scrolledArea.y = y;
6846 rootWindow.dirty = true;
6849 void ReleaseCapture()
6851 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
6853 Window oldCaptured = guiApp.windowCaptured;
6854 guiApp.windowCaptured = null;
6855 guiApp.prevWindow = null;
6858 //guiApp.Log("Released Capture\n");
6860 guiApp.interfaceDriver.SetMouseCapture(null);
6862 //oldCaptured.OnMouseCaptureLost();
6865 oldCaptured.ConsequentialMouseMove(false);
6870 void SetText(char * format, ...)
6877 char caption[MAX_F_STRING];
6879 va_start(args, format);
6880 vsprintf(caption, format, args);
6883 this.caption = new char[strlen(caption)+1];
6885 strcpy(this.caption, caption);
6894 bool Grab(Bitmap bitmap, Box box, bool decorations)
6896 bool result = false;
6897 if(display || this == guiApp.desktop)
6899 Box clip = {MININT, MININT, MAXINT, MAXINT};
6905 clip.Clip(clientArea);
6907 clip.Clip(this.box);
6909 if(rootWindow != this)
6911 clip.left += absPosition.y;
6912 clip.top += absPosition.y;
6913 clip.right += absPosition.x;
6914 clip.bottom += absPosition.y;
6917 clip.left += decorations ? 0 : clientStart.x;
6918 clip.top += decorations ? 0 : clientStart.y;
6919 clip.right += decorations ? 0 : clientStart.x;
6920 clip.bottom += decorations ? 0 : clientStart.y;
6922 if(display && display.flags.flipping)
6924 rootWindow.Update(null);
6925 rootWindow.UpdateDisplay();
6932 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
6933 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6937 result = display.Grab(bitmap, clip.left, clip.top,
6938 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6940 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
6942 if(!bitmap.Convert(null, pixelFormat888, null))
6949 void GetMousePosition(int * x, int * y)
6951 int mouseX = 0, mouseY = 0;
6952 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
6955 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
6956 if(this != guiApp.desktop)
6958 mouseX -= absPosition.x + clientStart.x;
6959 mouseY -= absPosition.y + clientStart.y;
6966 DialogResult DoModal()
6968 DialogResult returnCode = 0;
6969 int terminated = terminateX;
6972 while(!destroyed && guiApp.driver != null)
6974 if(terminateX != terminated)
6976 terminated = terminateX;
6977 guiApp.desktop.Destroy(0);
6978 if(guiApp.desktop.created)
6981 //printf("Resetting terminate X to 0\n");
6987 guiApp.UpdateDisplay();
6988 if(!guiApp.ProcessInput(false))
6991 returnCode = this.returnCode;
7004 return !destroyed && guiApp.driver != null && terminateX < 2;
7007 DialogResult DoModalEnd()
7009 DialogResult returnCode = this.returnCode;
7014 // --- Window manipulation ---
7015 /*bool GetDisabled()
7017 bool disabled = this.disabled;
7019 for(window = this; (window = window.master); )
7030 // --- Mouse Manipulation ---
7031 void GetNCMousePosition(int * x, int * y)
7033 GetMousePosition(x, y);
7034 if(x) *x += clientStart.x;
7035 if(y) *y += clientStart.y;
7038 // --- Carets manipulation ---
7039 void GetCaretPosition(Point caretPos)
7041 caretPos = this.caretPos;
7044 int GetCaretSize(void)
7049 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7055 bool CloseConfirmation(bool parentClosing)
7068 if(!OnClose(parentClosing))
7071 // If you want to skip this, simply set modifiedDocument to false in OnClose
7072 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7074 DialogResult dialogRes;
7077 sprintf(message, $"Save changes to %s?", fileName);
7079 sprintf(message, $"Save changes to Untitled %d?", documentID);
7081 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption, contents = message }.Modal();
7083 if(dialogRes == yes)
7085 // TOFIX: Precomp error if brackets are taken out
7086 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7088 else if(dialogRes == cancel)
7094 for(slave = slaves.first; slave; slave = slave.next)
7095 if(!((Window)slave.data).CloseConfirmation(true))
7097 // ((Window)slave.data).CloseConfirmation(true);
7105 for(child = children.first; child; child = child.next)
7106 if(child.master != this && !child.CloseConfirmation(true))
7116 // Static methods... move them somewhere else?
7117 void ::RestoreCaret()
7119 if(guiApp.caretOwner)
7120 guiApp.caretOwner.UpdateCaret(false, false);
7123 void ::FreeMouseRange()
7125 guiApp.interfaceDriver.SetMouseRange(null, null);
7129 bool MenuFileClose(MenuItem selection, Modifiers mods)
7131 Window document = activeChild;
7133 document.Destroy(0);
7137 bool MenuFileExit(MenuItem selection, Modifiers mods)
7143 bool MenuFileSave(MenuItem selection, Modifiers mods)
7147 fileMonitor.fileName = null;
7150 if(OnSaveFile(fileName))
7152 //if(OnFileModified != Window::OnFileModified)
7155 fileMonitor.fileName = fileName;
7161 MessageBox dialog { master = master, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7162 DialogResult answer = dialog.Modal();
7164 if(answer != yes) return (bool)answer;
7167 return MenuFileSaveAs(selection, mods);
7170 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7172 DialogResult result = (DialogResult)bool::true;
7173 FileDialog fileDialog = saveDialog;
7176 fileDialog = FileDialog {};
7181 fileDialog.filePath = fileName;
7184 char filePath[MAX_FILENAME];
7185 sprintf(filePath, "Untitled %d", documentID);
7186 fileDialog.filePath = filePath;
7188 fileMonitor.fileName = null;
7190 fileDialog.type = save;
7191 fileDialog.text = $"Save As";
7195 fileDialog.master = master.parent ? master : this;
7196 if(fileDialog.Modal() == ok)
7198 char * filePath = fileDialog.filePath;
7200 if(OnSaveFile(filePath))
7203 property::fileName = filePath;
7204 NotifySaved(master, this, filePath);
7209 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7210 DialogResult answer = dialog.Modal();
7225 //if(OnFileModified != Window::OnFileModified && fileName)
7228 fileMonitor.fileName = fileName;
7232 return (bool)result; // Actually returning result from Yes/NoCancel message box
7235 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7237 Window document = activeChild;
7239 for(document = children.first; document; document = next)
7241 next = document.next;
7242 if(document.style.isDocument || document.fileName)
7243 document.MenuFileSave(selection, mods);
7248 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7252 for(document = children.first; document; document = document.next)
7253 //if(document.style.isDocument && document.state == minimized)
7254 if(document.style.isActiveClient && document.state == minimized)
7255 document.SetState(minimized, false, mods);
7259 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7261 Window document = activeChild;
7264 Window firstDocument = null;
7266 OldLink cycle = document.cycle.prev;
7271 if(child.style.isActiveClient && !child.style.hidden)
7275 firstDocument = child;
7276 if(child.state == minimized)
7277 child.SetState(minimized, false, mods);
7280 child.positionID = id++;
7281 child.SetState(normal, false, mods);
7282 child.anchor.left.type = cascade;
7285 child.normalSizeAnchor = *&child.sizeAnchor;
7286 child.normalAnchor = child.anchor;
7288 // Break the anchors for moveable/resizable windows
7289 if(child.style.fixed)
7291 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7293 (*&child.normalAnchor).left = x;
7294 (*&child.normalAnchor).top = y;
7295 (*&child.normalAnchor).right.type = none;
7296 (*&child.normalAnchor).bottom.type = none;
7298 child.normalSizeAnchor.isClientW = false;
7299 child.normalSizeAnchor.isClientH = false;
7300 child.normalSizeAnchor.size.w = w;
7301 child.normalSizeAnchor.size.h = h;
7302 child.anchored = false;
7305 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7307 child.stateAnchor = child.normalAnchor;
7308 child.stateSizeAnchor = child.normalSizeAnchor;
7310 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7311 child.Position(x, y, w, h, true, true, true, true, false, false);
7316 last = children.last;
7317 if(!child.style.stayOnTop)
7318 for(; last && last.style.stayOnTop; last = last.prev);
7319 children.Move(child, last);
7320 childrenOrder.Move(child.order, childrenOrder.last);
7322 if(cycle == document.cycle) break;
7326 firstDocument.Activate();
7331 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7338 // Close all closes all active clients, not all documents
7339 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7341 Window next, document;
7343 for(document = children.first; document; document = next)
7345 for(next = document.next; next && !(next.style.isActiveClient; next = next.next);
7346 if(document.style.isActiveClient)
7347 if(!document.Destroy(0) && !document.style.hidden)
7353 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7355 if(style.hasMaximize && state != maximized)
7356 SetState(maximized, 0, 0);
7360 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7362 if(style.hasMinimize && state != minimized)
7364 SetState(minimized, 0, 0);
7365 parent.CycleChildren(false, true, false, true);
7370 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7372 MenuMoveOrSize(false, selection ? true : false);
7376 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7378 CycleChildren(false, true, false, true);
7382 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7384 CycleChildren(true, true, false, true);
7388 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7390 MenuMoveOrSize(true, true);
7394 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7397 SetState(normal, 0, 0);
7401 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7404 int id = selection.id;
7405 OldLink cycle = activeClient.cycle;
7407 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7410 Window sibling = cycle.data;
7411 if(sibling.style.isActiveClient)
7419 document = cycle.data;
7420 document.Activate();
7422 //if(activeChild.state == maximized)
7423 // document.SetState(maximized, false, mods);
7424 //else if(document.state == minimized)
7425 // document.SetState(normal, false, mods);
7429 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7431 stayOnTop = !style.stayOnTop;
7435 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7437 Window document = activeChild;
7440 Window firstDocument = null;
7441 OldLink cycle = document.cycle;
7445 Window child = cycle.data;
7446 if(child.style.isActiveClient && !child.style.hidden)
7448 if(!firstDocument) firstDocument = child;
7449 if(child.state == minimized)
7450 child.SetState(minimized, false, mods);
7453 child.positionID = id++;
7454 child.SetState(normal, false, mods);
7455 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7457 child.anchor.left.type = hTiled;
7460 child.normalSizeAnchor = *&child.sizeAnchor;
7461 child.normalAnchor = child.anchor;
7463 // Break the anchors for moveable/resizable windows
7464 if(child.style.fixed)
7466 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7468 (*&child.normalAnchor).left = x;
7469 (*&child.normalAnchor).top = y;
7470 (*&child.normalAnchor).right.type = none;
7471 (*&child.normalAnchor).bottom.type = none;
7472 child.normalSizeAnchor.isClientW = false;
7473 child.normalSizeAnchor.isClientH = false;
7474 child.normalSizeAnchor.size.w = w;
7475 child.normalSizeAnchor.size.h = h;
7476 child.anchored = false;
7479 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7481 child.stateAnchor = child.normalAnchor;
7482 child.stateSizeAnchor = child.normalSizeAnchor;
7484 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7485 child.Position(x,y, w, h, true, true, true, true, false, true);
7490 if((cycle = cycle.next) == document.cycle) break;
7493 firstDocument.Activate();
7498 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7500 Window document = activeChild;
7503 Window firstDocument = null;
7505 OldLink cycle = document.cycle;
7510 //if(child.style.isDocument)
7511 if(child.style.isActiveClient && !child.style.hidden)
7513 if(!firstDocument) firstDocument = child;
7514 if(child.state == minimized)
7515 child.SetState(minimized, false, mods);
7518 child.positionID = id++;
7519 child.SetState(normal, false, mods);
7520 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7522 child.anchor.left.type = vTiled;
7525 child.normalSizeAnchor = *&child.sizeAnchor;
7526 child.normalAnchor = child.anchor;
7528 // Break the anchors for moveable/resizable windows
7529 if(child.style.fixed)
7531 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7533 (*&child.normalAnchor).left = x;
7534 (*&child.normalAnchor).top = y;
7535 (*&child.normalAnchor).right.type = none;
7536 (*&child.normalAnchor).bottom.type = none;
7537 child.normalSizeAnchor.isClientW = false;
7538 child.normalSizeAnchor.isClientH = false;
7539 child.normalSizeAnchor.size.w = w;
7540 child.normalSizeAnchor.size.h = h;
7541 child.anchored = false;
7544 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7546 child.stateAnchor = child.normalAnchor;
7547 child.stateSizeAnchor = child.normalSizeAnchor;
7549 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7550 child.Position(x,y, w, h, true, true, true, true, false, true);
7555 if((cycle = cycle.next) == document.cycle) break;
7558 firstDocument.Activate();
7563 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7565 WindowList dialog { master = this };
7566 Window document = (Window)dialog.Modal();
7569 if(activeChild.state == maximized)
7570 document.SetState(maximized, false, mods);
7571 else if(document.state == minimized)
7572 document.SetState(normal, false, mods);
7573 document.Activate();
7579 virtual bool OnCreate(void);
7580 virtual void OnDestroy(void);
7581 virtual void OnDestroyed(void);
7582 virtual bool OnClose(bool parentClosing);
7583 virtual bool OnStateChange(WindowState state, Modifiers mods);
7584 virtual bool OnPostCreate(void);
7585 virtual bool OnMoving(int *x, int *y, int w, int h);
7586 virtual bool OnResizing(int *width, int *height);
7587 virtual void OnResize(int width, int height);
7588 virtual void OnPosition(int x, int y, int width, int height);
7589 virtual bool OnLoadGraphics(void);
7590 virtual void OnApplyGraphics(void);
7591 virtual void OnUnloadGraphics(void);
7592 virtual void OnRedraw(Surface surface);
7593 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7594 virtual void OnActivateClient(Window client, Window previous);
7595 virtual bool OnKeyDown(Key key, unichar ch);
7596 virtual bool OnKeyUp(Key key, unichar ch);
7597 virtual bool OnKeyHit(Key key, unichar ch);
7598 virtual bool OnSysKeyDown(Key key, unichar ch);
7599 virtual bool OnSysKeyUp(Key key, unichar ch);
7600 virtual bool OnSysKeyHit(Key key, unichar ch);
7601 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7602 virtual bool OnMouseLeave(Modifiers mods);
7603 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7604 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7605 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
7606 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
7607 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
7608 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
7609 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
7610 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
7611 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
7612 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
7613 virtual void OnMouseCaptureLost(void);
7614 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
7615 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
7616 virtual void OnDrawOverChildren(Surface surface);
7617 virtual bool OnFileModified(FileChange fileChange, char * param);
7618 virtual bool OnSaveFile(char * fileName);
7620 // Virtual Methods -- Children management (To support Stacker, for lack of built-in auto-layout)
7621 // Note: A 'client' would refer to isActiveClient, rather than
7622 // being confined to the 'client area' (nonClient == false)
7623 virtual void OnChildAddedOrRemoved(Window child, bool removed);
7624 virtual void OnChildVisibilityToggled(Window child, bool visible);
7625 virtual void OnChildResized(Window child, int x, int y, int w, int h);
7627 // Skins Virtual Functions
7628 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
7629 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
7630 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
7635 virtual void ShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7636 virtual void PreShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7637 virtual bool IsMouseMoving(int x, int y, int w, int h);
7638 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY);
7639 virtual void UpdateNonClient();
7640 virtual void SetBox(Box box);
7641 virtual bool IsInside(int x, int y)
7643 return box.IsPointInside({x, y});
7645 virtual bool IsOpaque()
7647 return (!style.drawBehind || background.a == 255);
7651 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
7652 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
7653 virtual void Window::NotifySaved(Window window, char * filePath);
7658 property Window parent
7660 property_category $"Layout"
7663 if(value || guiApp.desktop)
7666 Window oldParent = parent;
7667 Anchor anchor = this.anchor;
7669 if(value && value.IsDescendantOf(this)) return;
7670 if(value && value == this)
7672 if(!value) value = guiApp.desktop;
7674 if(value == oldParent) return;
7676 if(!master || (master == this.parent && master == guiApp.desktop))
7677 property::master = value;
7681 parent.children.Remove(this);
7682 parent.OnChildAddedOrRemoved(this, true);
7686 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7687 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
7688 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7689 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
7693 last = value.children.last;
7695 if(style.isDocument)
7698 parent.numDocuments--;
7699 documentID = value.GetDocumentID();
7702 if(style.isActiveClient && !style.hidden)
7704 if(parent && parent != guiApp.desktop && !(style.hidden))
7706 if(state == minimized) parent.numIcons--;
7707 parent.numPositions--;
7711 if(!style.stayOnTop)
7712 for(; last && last.style.stayOnTop; last = last.prev);
7714 value.children.Insert(last, this);
7716 // *** NEW HERE: ***
7718 parent.childrenCycle.Delete(cycle);
7720 parent.childrenOrder.Delete(order);
7728 int x = position.x, y = position.y, w = size.w, h = size.h;
7732 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
7733 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
7735 vpw = value.clientSize.w;
7736 vph = value.clientSize.h;
7742 else if(style.fixed)
7744 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
7745 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
7748 anchor = this.anchor;
7750 if(anchor.left.type == offset) anchor.left.distance = x;
7751 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
7752 if(anchor.top.type == offset) anchor.top.distance = y;
7753 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
7754 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
7755 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
7756 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
7757 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
7758 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
7759 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
7761 if(!anchor.left.type && !anchor.right.type)
7763 anchor.horz.distance = (x + w / 2) - (vpw / 2);
7764 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
7766 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
7767 if(!anchor.top.type && !anchor.bottom.type)
7769 anchor.vert.distance = (y + h / 2) - (vph / 2);
7770 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
7772 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
7775 parent.OnChildAddedOrRemoved(this, false);
7781 parent.childrenCycle.Insert(
7782 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
7783 cycle = OldLink { data = this });
7784 parent.childrenOrder.Insert(
7785 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
7786 order = OldLink { data = this });
7789 if(!style.hidden && style.isActiveClient)
7791 positionID = parent.GetPositionID(this);
7792 parent.numPositions++;
7793 if(state == minimized) parent.numIcons--;
7796 // *** FONT INHERITANCE ***
7797 if(!setFont && oldParent)
7798 stopwatching(oldParent, font);
7802 RemoveResource(systemFont);
7805 // TESTING WITH WATCHERS:
7806 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7807 // usedFont = setFont ? setFont : (systemFont);
7811 if(guiApp.currentSkin)
7813 systemFont = guiApp.currentSkin.SystemFont();
7816 usedFont = systemFont;
7817 AddResource(systemFont);
7825 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7834 if(value.rootWindow && value.rootWindow.display && rootWindow)
7836 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
7837 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
7840 UnloadGraphics(false);
7843 LoadGraphics(false, false);
7846 if(value.rootWindow != rootWindow)
7847 DisplayModeChanged();
7851 scrolledPos.x = MININT; // Prevent parent update
7852 property::anchor = anchor;
7856 if(guiApp.currentSkin)
7857 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
7859 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7860 Position(x, y, w, h, true, true, true, true, false, true);
7865 // else parent = value;
7868 get { return parent; }
7871 property Window master
7873 property_category $"Behavior"
7876 //if(this == value) return;
7877 if(value && value.IsSlaveOf(this)) return;
7883 OldLink slaveHolder;
7884 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
7885 if(slaveHolder.data == this)
7887 master.slaves.Delete(slaveHolder);
7894 value.slaves.Add(OldLink { data = this });
7899 master.hotKeys.Remove(hotKey);
7900 value.hotKeys.Add(hotKey);
7903 if(master && master.defaultControl == this)
7904 master.defaultControl = null;
7906 if(style.isDefault && !value.defaultControl)
7907 value.defaultControl = this;
7912 get { return master ? master : parent; }
7915 property char * text
7917 property_category $"Appearance"
7924 caption = new char[strlen(value)+1];
7926 strcpy(caption, value);
7931 get { return caption; }
7936 property_category $"Behavior"
7945 master.hotKeys.Add(hotKey = HotKeySlot { });
7949 hotKey.window = this;
7954 master.hotKeys.Delete(hotKey);
7959 get { return hotKey ? hotKey.key : 0; }
7962 property Color background
7964 property_category $"Appearance"
7967 background.color = value;
7972 if(this == rootWindow)
7973 guiApp.interfaceDriver.SetRootWindowColor(this);
7976 get { return background.color; }
7979 property Percentage opacity
7981 property_category $"Appearance"
7984 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
7985 drawBehind = background.a ? false : true;
7987 get { return background.a / 255.0f; }
7990 property Color foreground
7992 property_category $"Appearance"
8000 get { return foreground; }
8003 property BorderStyle borderStyle
8005 property_category $"Appearance"
8008 if(!((BorderBits)value).fixed)
8010 style.hasClose = false;
8011 style.hasMaximize = false;
8012 style.hasMinimize = false;
8014 style.borderBits = value;
8018 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8020 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8021 Position(x, y, w, h, true, true, true, true, false, true);
8022 CreateSystemChildren();
8025 get { return (BorderStyle)style.borderBits; }
8028 property Size minClientSize
8030 property_category $"Layout"
8031 set { minSize = value; }
8032 get { value = minSize; }
8035 property Size maxClientSize
8037 property_category $"Layout"
8038 set { maxSize = value; }
8039 get { value = maxSize; }
8042 property bool hasMaximize
8044 property_category $"Window Style"
8047 style.hasMaximize = value;
8048 if(value) { style.fixed = true; style.contour = true; }
8052 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8054 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8055 Position(x, y, w, h, true, true, true, true, false, true);
8057 CreateSystemChildren();
8060 get { return style.hasMaximize; }
8063 property bool hasMinimize
8065 property_category $"Window Style"
8068 style.hasMinimize = value;
8069 if(value) { style.fixed = true; style.contour = true; }
8073 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8075 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8076 Position(x, y, w, h, true, true, true, true, false, true);
8078 CreateSystemChildren();
8081 get { return style.hasMinimize; }
8084 property bool hasClose
8086 property_category $"Window Style"
8089 style.hasClose = value;
8090 if(value) { style.fixed = true; style.contour = true; }
8094 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8095 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8096 Position(x, y, w, h, true, true, true, true, false, true);
8097 CreateSystemChildren();
8100 get { return style.hasClose; }
8103 property bool nonClient
8105 property_category $"Layout"
8108 style.nonClient = value;
8110 style.stayOnTop = true;
8112 get { return style.nonClient; }
8115 property bool inactive
8117 property_category $"Behavior"
8122 // *** NEW HERE: ***
8126 parent.childrenCycle.Delete(cycle);
8128 parent.childrenOrder.Delete(order);
8135 active = false; // true;
8136 if(parent.activeChild == this)
8137 parent.activeChild = null;
8138 if(parent.activeClient == this)
8139 parent.activeClient = null;
8148 parent.childrenCycle.Insert(
8149 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8150 cycle = OldLink { data = this });
8152 parent.childrenOrder.Insert(
8153 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8154 order = OldLink { data = this });
8157 style.inactive = value;
8159 get { return style.inactive; }
8162 property bool clickThrough
8164 property_category $"Behavior"
8165 set { style.clickThrough = value; }
8166 get { return style.clickThrough; }
8169 property bool isRemote
8171 property_category $"Behavior"
8172 set { style.isRemote = value; }
8173 get { return style.isRemote; }
8176 property bool noCycle
8178 property_category $"Behavior"
8179 set { style.noCycle = value; }
8180 get { return style.noCycle; }
8183 property bool isModal
8185 property_category $"Behavior"
8186 set { style.modal = value; }
8187 get { return style.modal; }
8190 property bool interim
8192 property_category $"Behavior"
8193 set { style.interim = value; }
8194 get { return style.interim; }
8197 property bool tabCycle
8199 property_category $"Behavior"
8200 set { style.tabCycle = value; }
8201 get { return style.tabCycle; }
8204 property bool isDefault
8206 property_category $"Behavior"
8214 /*for(sibling = parent.children.first; sibling; sibling = sibling.next)
8215 if(sibling != this && sibling.style.isDefault)
8216 sibling.style.isDefault = false;*/
8217 if(master.defaultControl)
8218 master.defaultControl.style.isDefault = false;
8219 master.defaultControl = this;
8221 else if(master.defaultControl == this)
8222 master.defaultControl = null;
8226 style.isDefault = value;
8228 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8230 get { return style.isDefault; }
8233 property bool drawBehind
8235 property_category $"Window Style"
8236 set { style.drawBehind = value; }
8237 get { return style.drawBehind; }
8240 property bool hasMenuBar
8242 property_category $"Window Style"
8252 if(created && !menuBar)
8259 anchor = Anchor { top = 23, left = 1, right = 1 },
8261 inactive = true, nonClient = true
8266 else if(created && menuBar)
8271 style.hasMenuBar = value;
8273 get { return style.hasMenuBar; }
8276 property bool hasStatusBar
8278 property_category $"Window Style"
8285 statusBar = StatusBar { this };
8293 style.hasStatusBar = value;
8295 get { return style.hasStatusBar; }
8297 property bool stayOnTop
8299 property_category $"Window Style"
8304 if(created && !style.stayOnTop)
8306 if(rootWindow == this)
8307 guiApp.interfaceDriver.OrderRootWindow(this, true);
8308 else if(parent.children.last != this)
8310 parent.children.Move(this, parent.children.last);
8314 style.stayOnTop = true;
8318 if(created && style.stayOnTop)
8320 if(rootWindow == this)
8321 guiApp.interfaceDriver.OrderRootWindow(this, false);
8328 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8329 order && ((Window)order.data).style.stayOnTop;
8330 order = (order == parent.childrenOrder.first) ? null : order.prev);
8331 last = order ? order.data : null;
8335 for(last = parent.children.last;
8336 last && last.style.stayOnTop;
8340 parent.children.Move(this, last);
8344 style.stayOnTop = false;
8347 get { return style.stayOnTop; }
8352 property_category $"Window Style"
8362 if(menuBar && !value)
8369 if(!menuBar && style.hasMenuBar && value)
8373 this, menu = value, isMenuBar = true,
8374 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8375 inactive = true, nonClient = true
8379 UpdateActiveDocument(null);
8382 get { return menu; }
8385 property FontResource font
8387 property_category $"Appearance"
8389 isset { return setFont ? true : false; }
8394 if(value && !setFont) { stopwatching(parent, font); }
8395 else if(!value && setFont)
8401 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8410 RemoveResource(setFont);
8415 RemoveResource(systemFont);
8422 AddResource(setFont);
8425 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8428 systemFont = guiApp.currentSkin.SystemFont();
8430 usedFont = systemFont;
8431 AddResource(systemFont);
8439 get { return usedFont; }
8442 property SizeAnchor sizeAnchor
8444 property_category $"Layout"
8447 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8448 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8449 sizeAnchor.isClientW != sizeAnchor.isClientH;
8456 normalSizeAnchor = sizeAnchor;
8458 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8460 stateAnchor = normalAnchor;
8461 stateSizeAnchor = normalSizeAnchor;
8463 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8464 Position(x,y, w, h, true, true, true, true, false, true);
8471 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8472 sizeAnchor.isClientW,
8473 sizeAnchor.isClientH
8480 property_category $"Layout"
8483 Anchor thisAnchor = anchor;
8484 SizeAnchor thisSizeAnchor = sizeAnchor;
8485 bool leftRight = (anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none);
8486 bool topBottom = (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none);
8487 bool isClient = !sizeAnchor.isClientW && !sizeAnchor.isClientH;
8488 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8489 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8490 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8496 sizeAnchor.isClientW = false;
8497 sizeAnchor.isClientH = false;
8498 sizeAnchor.size = value;
8500 normalSizeAnchor = sizeAnchor;
8502 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8504 stateAnchor = normalAnchor;
8505 stateSizeAnchor = normalSizeAnchor;
8507 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8508 Position(x, y, w, h, true, true, true, true, false, true);
8509 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
8512 get { value = size; }
8515 property Size clientSize
8517 property_category $"Layout"
8520 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8521 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8522 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8527 sizeAnchor.isClientW = true;
8528 sizeAnchor.isClientH = true;
8529 sizeAnchor.size = value;
8531 normalSizeAnchor = sizeAnchor;
8533 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8535 stateAnchor = normalAnchor;
8536 stateSizeAnchor = normalSizeAnchor;
8538 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8539 Position(x,y, w, h, true, true, true, true, false, true);
8542 get { value = clientSize; }
8545 property Size initSize { get { value = sizeAnchor.size; } };
8547 property Anchor anchor
8549 property_category $"Layout"
8550 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8556 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8558 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8559 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8561 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8563 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8564 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8568 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8570 anchor.left.distance = 0;
8571 anchor.horz.type = 0;
8573 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8575 anchor.top.distance = 0;
8576 anchor.vert.type = 0;
8585 normalAnchor = anchor;
8587 // Break the anchors for moveable/resizable windows
8588 /*if(style.fixed ) //&& value.left.type == cascade)
8590 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
8592 this.anchor = normalAnchor = Anchor { left = x, top = y };
8593 normalSizeAnchor = SizeAnchor { { w, h } };
8596 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8598 stateAnchor = normalAnchor;
8599 stateSizeAnchor = normalSizeAnchor;
8601 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8602 Position(x, y, w, h, true, true, true, true, false, true);
8611 get { value = this ? anchor : Anchor { }; }
8614 property Point position
8616 property_category $"Layout"
8619 if(value == null) return;
8621 anchor.left = value.x;
8622 anchor.top = value.y;
8623 anchor.right.type = none;
8624 anchor.bottom.type = none;
8629 normalAnchor = anchor;
8631 // Break the anchors for moveable/resizable windows
8635 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8637 normalAnchor.left = x;
8638 normalAnchor.top = y;
8639 normalAnchor.right.type = none;
8640 normalAnchor.bottom.type = none;
8641 normalSizeAnchor.size.width = w;
8642 normalSizeAnchor.size.height = h;
8646 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8648 stateAnchor = normalAnchor;
8649 stateSizeAnchor = normalSizeAnchor;
8651 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8652 Position(x,y, w, h, true, true, true, true, false, true);
8656 get { value = position; }
8659 property bool disabled
8661 property_category $"Behavior"
8664 if(this && disabled != value)
8671 get { return (bool)disabled; }
8674 property bool isEnabled
8679 for(parent = this; parent; parent = parent.parent)
8686 property WindowState state
8688 property_category $"Behavior"
8689 set { SetState(value, false, 0); }
8690 get { return this ? state : 0; }
8693 property bool visible
8695 property_category $"Behavior"
8698 if(this && !value && !style.hidden && parent)
8700 bool wasActiveChild = parent.activeChild == this;
8701 Window client = null;
8703 style.hidden = true;
8704 if(style.isActiveClient)
8706 parent.numPositions--;
8707 if(state == minimized) parent.numIcons--;
8712 OldLink prevOrder = null;
8714 if(rootWindow == this)
8715 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
8718 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
8721 box.left -= parent.clientStart.x;
8722 box.top -= parent.clientStart.y;
8723 box.right -= parent.clientStart.x;
8724 box.bottom -= parent.clientStart.y;
8728 if(_isModal && master && master.modalSlave == this)
8729 master.modalSlave = null;
8733 OldLink tmpPrev = order.prev;
8734 client = tmpPrev ? tmpPrev.data : null;
8735 if(client && !client.style.hidden && !client.destroyed && client.created)
8736 prevOrder = tmpPrev;
8739 client = tmpPrev ? tmpPrev.data : null;
8740 if(client == this) { client = null; break; }
8741 if(client && ((client.style.hidden) || client.destroyed || !client.created))
8743 tmpPrev = client.order.prev;
8748 prevOrder = tmpPrev;
8753 // If this window can be an active client, make sure the next window we activate can also be one
8754 if(!style.nonClient && style.isActiveClient)
8756 tmpPrev = prevOrder;
8759 client = tmpPrev ? tmpPrev.data : null;
8760 if(client == this) { client = null; break; }
8761 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
8763 tmpPrev = client.order.prev;
8768 prevOrder = tmpPrev;
8772 if(client && client.style.hidden) client = null;
8776 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
8778 if(order && prevOrder && prevOrder.data != this)
8779 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
8781 ActivateEx(false, false, false, true, null, null);
8783 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
8784 if(parent.activeClient == this)
8786 parent.activeClient = null;
8787 parent.UpdateActiveDocument(null);
8790 else if(parent.activeClient == this)
8792 parent.activeClient = client;
8793 parent.UpdateActiveDocument(this);
8796 // *** Not doing this anymore ***
8799 parent.childrenCycle.Delete(cycle);
8801 parent.childrenOrder.Delete(order);
8806 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8811 else if(this && value && style.hidden)
8813 style.hidden = false;
8816 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8817 if(rootWindow == this)
8818 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
8820 if(_isModal && master)
8821 master.modalSlave = this;
8823 if(style.isActiveClient)
8825 positionID = parent.GetPositionID(this);
8826 parent.numPositions++;
8827 if(state == minimized) parent.numIcons++;
8830 // *** NOT DOING THIS ANYMORE ***
8832 if(!(style.inactive))
8834 if(!(style.noCycle))
8836 cycle = parent.childrenCycle.AddAfter(
8837 (parent.activeChild && parent.activeChild.cycle) ?
8838 parent.activeChild.cycle.prev : null, sizeof(OldLink));
8841 order = parent.childrenOrder.AddAfter(
8842 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8849 if(true || !parent.activeChild)
8850 ActivateEx(true, false, true, true, null, null);
8852 if(creationActivation == activate)
8853 ActivateEx(true, false, true, true, null, null);
8854 else if(creationActivation == flash && !object)
8857 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8861 ConsequentialMouseMove(false);
8867 style.hidden = !value;
8870 get { return (style.hidden || !setVisible) ? false : true; }
8873 property bool isDocument
8875 property_category $"Document"
8876 set { style.isDocument = value; }
8877 get { return style.isDocument; }
8880 property bool mergeMenus
8882 property_category $"Window Style"
8883 set { mergeMenus = value; }
8884 get { return (bool)mergeMenus; }
8887 property bool hasHorzScroll
8889 property_category $"Window Style"
8894 if(!style.hasHorzScroll && created)
8896 CreateSystemChildren();
8897 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8900 else if(style.hasHorzScroll)
8904 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8906 style.hasHorzScroll = value;
8909 get { return style.hasHorzScroll; }
8912 property bool hasVertScroll
8914 property_category $"Window Style"
8919 if(!style.hasVertScroll && created)
8921 style.hasVertScroll = true;
8922 CreateSystemChildren();
8923 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8926 else if(style.hasVertScroll)
8930 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8932 style.hasVertScroll = value;
8934 get { return style.hasVertScroll; }
8937 property bool dontHideScroll
8939 property_category $"Behavior"
8942 scrollFlags.dontHide = value;
8945 //UpdateScrollBars(true, true);
8946 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8950 // UpdateScrollBars(true, true);
8951 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8954 get { return scrollFlags.dontHide; }
8957 property bool dontScrollVert
8959 property_category $"Behavior"
8960 set { style.dontScrollVert = value; }
8961 get { return style.dontScrollVert; }
8963 property bool dontScrollHorz
8965 property_category $"Behavior"
8966 set { style.dontScrollHorz = value; }
8967 get { return style.dontScrollHorz; }
8970 property bool snapVertScroll
8972 property_category $"Behavior"
8975 scrollFlags.snapY = value;
8976 if(sbv) sbv.snap = value;
8978 get { return scrollFlags.snapY; }
8980 property bool snapHorzScroll
8982 property_category $"Behavior"
8985 scrollFlags.snapX = value;
8986 if(sbh) sbh.snap = value;
8988 get { return scrollFlags.snapX; }
8991 property Point scroll
8993 property_category $"Behavior"
8997 // TESTING THIS IMPLEMENTATION:
8998 SetScrollPosition(value.x, value.y);
9000 get { value = scroll; }
9003 property bool modifyVirtualArea
9005 property_category $"Behavior"
9006 set { modifyVirtArea = value; }
9007 get { return (bool)modifyVirtArea; }
9010 property char * fileName
9012 property_category $"Document"
9015 if(menu && ((!fileName && value) || (fileName && !value)))
9017 MenuItem item = menu.FindItem(MenuFileSave, 0);
9018 if(item) item.disabled = !modifiedDocument && value;
9023 if(value && value[0])
9024 fileName = CopyString(value);
9026 if(parent && this == parent.activeClient)
9027 parent.UpdateActiveDocument(null);
9031 // if(style.isDocument)
9033 fileMonitor.fileName = value;
9035 get { return fileName; }
9040 property_category $"Data"
9045 property bool modifiedDocument
9047 property_category $"Document"
9050 if(style.isDocument || fileName)
9054 MenuItem item = menu.FindItem(MenuFileSave, 0);
9055 if(item) item.disabled = !value && fileName;
9059 if(modifiedDocument != value)
9061 modifiedDocument = value;
9062 if(style.isDocument || fileName)
9066 get { return (bool)modifiedDocument; }
9069 property bool showInTaskBar
9071 property_category $"Window Style"
9072 set { style.showInTaskBar = value; }
9073 get { return (style.showInTaskBar; }
9075 property FileDialog saveDialog { set { saveDialog = value; } };
9076 property bool isActiveClient
9078 property_category $"Behavior"
9079 set { style.isActiveClient = value; }
9080 get { return style.isActiveClient; }
9083 property Cursor cursor
9085 property_category $"Appearance"
9089 SelectMouseCursor();
9091 get { return cursor; }
9094 //#if !defined(ECERE_VANILLA)
9095 property char * name
9097 property_category $"Design"
9100 return (this && object) ? object.name : null;
9105 activeDesigner.RenameObject(object, value);
9109 property char * displayDriver
9111 property_category $"Behavior"
9114 dispDriver = GetDisplayDriver(value);
9115 //DisplayModeChanged();
9119 return dispDriver ? dispDriver.name : null;
9123 // RUNTIME PROPERTIES
9124 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9125 property Size scrollArea
9127 property_category $"Behavior"
9131 SetScrollArea(value.w, value.h, false);
9133 SetScrollArea(0,0, true);
9135 get { value = scrollArea; }
9138 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9143 property_category $"Layout"
9144 set { if(this) is3D = value; }
9145 get { return (bool)is3D; }
9148 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9150 // Will be merged with font later
9151 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9152 property Point clientStart { get { value = clientStart; } };
9153 property Point absPosition { get { value = absPosition; } };
9154 property Anchor normalAnchor { get {value = normalAnchor; } };
9155 // property Size normalSizeAnchor { get { value = normalSizeAnchor; } };
9156 property bool active { get { return (bool)active; } };
9157 property bool created { get { return (bool)created; } };
9158 property bool destroyed { get { return (bool)destroyed; } };
9159 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9160 property Window firstChild { get { return children.first; } };
9161 property Window lastChild { get { return children.last; } };
9162 property Window activeClient { get { return activeClient; } };
9163 property Window activeChild { get { return activeChild; } };
9164 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9165 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9166 property ScrollBar horzScroll { get { return sbh; } };
9167 property ScrollBar vertScroll { get { return sbv; } };
9168 property StatusBar statusBar { get { return statusBar; } };
9169 property Window rootWindow { get { return rootWindow; } };
9170 property bool closing { get { return (bool)closing; } set { closing = value; } };
9171 property int documentID { get { return documentID; } };
9172 property Window previous { get { return prev; } }
9173 property Window next { get { return next; } }
9174 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9175 property PopupMenu menuBar { get { return menuBar; } }
9176 property ScrollBar sbv { get { return sbv; } }
9177 property ScrollBar sbh { get { return sbh; } }
9178 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9179 property void * systemHandle { get { return windowHandle; } }
9180 property Button minimizeButton { get { return sysButtons[0]; } };
9181 property Button maximizeButton { get { return sysButtons[1]; } };
9182 property Button closeButton { get { return sysButtons[2]; } };
9183 property BitmapResource icon
9185 get { return icon; }
9189 if(icon) incref icon;
9191 guiApp.interfaceDriver.SetIcon(this, value);
9194 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9195 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } };
9196 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9197 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9198 property bool nativeDecorations { get { return (bool)nativeDecorations && (formDesigner || rootWindow == this); } set { nativeDecorations = value; } };
9199 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9205 WindowBits style; // Window Style
9206 char * caption; // Name / Caption
9207 Window parent; // Parent window
9208 OldList children; // List of children in Z order
9209 Window activeChild; // Child window having focus
9210 Window activeClient;
9211 Window previousActive; // Child active prior to activating the default child
9212 Window master; // Window owning and receiving notifications concerning this window
9213 OldList slaves; // List of windows belonging to this window
9214 Display display; // Display this window is drawn into
9216 Point position; // Position in parent window client area
9217 Point absPosition; // Absolute position
9218 Point clientStart; // Client area position from (0,0) in this window
9220 Size clientSize; // Client area size
9221 Size scrollArea; // Virtual Scroll area size
9222 Size reqScrollArea; // Requested virtual area size
9223 Point scroll; // Virtual area scrolling position
9224 public ScrollBar sbh, sbv; // Scrollbar window handles
9225 Cursor cursor; // Mouse cursor used for this window
9228 StatusBar statusBar;
9229 Button sysButtons[3];
9231 Box clientArea; // Client Area box clipped to parent
9233 HotKeySlot hotKey; // HotKey for this window
9237 ScrollFlags scrollFlags;// Window Scrollbar Flags
9238 int id; // Control ID
9240 ColorAlpha background; // Background color used to draw the window area
9242 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9243 OldList childrenCycle; // Cycling order
9244 OldLink cycle; // Element of parent's cycling order
9245 OldList childrenOrder; // Circular Z-Order
9246 OldLink order; // Element of parent's circular Z-Order
9247 Window modalSlave; // Slave window blocking this window's interaction
9249 Window rootWindow; // Topmost system managed window
9250 void * windowHandle; // System window handle
9252 DialogResult returnCode;// Return code for modal windows
9254 Point sbStep; // Scrollbar line scrolling steps
9257 SizeAnchor stateSizeAnchor;
9259 Anchor normalAnchor;
9260 SizeAnchor normalSizeAnchor;
9262 Size skinMinSize; // Minimal window size based on style
9263 Point scrolledPos; // Scrolled position
9264 Box box; // Window box clipped to parent
9265 Box * against; // What to clip the box to
9267 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9268 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9269 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9270 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9271 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9272 Point scrolledArea; // Distance to scroll area by
9273 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9275 OldList hotKeys; // List of the hotkeys of all children
9276 Window defaultControl; // Default child control
9280 ColorAlpha * palette; // Color palette used for this window
9282 int caretSize; // Size of caret, non zero if a caret is present
9283 Point caretPos; // Caret position
9285 void * systemParent; // Parent System Window for embedded windows
9292 WindowState lastState;
9294 FileMonitor fileMonitor
9296 this, FileChange { modified = true };
9298 bool OnFileNotify(FileChange action, char * param)
9301 fileMonitor.StopMonitoring();
9302 if(OnFileModified(action, param))
9303 fileMonitor.StartMonitoring();
9308 FontResource setFont, systemFont;
9309 FontResource usedFont;
9310 FontResource captionFont;
9312 FileDialog saveDialog;
9314 SizeAnchor sizeAnchor;
9316 // FormDesigner data
9319 Extent * tempExtents; //[4];
9320 BitmapResource icon;
9322 CreationActivationOption creationActivation;
9325 bool active:1; // true if window and ancestors are active
9326 bool acquiredInput:1; // true if the window is processing state based input
9327 bool modifiedDocument:1;
9328 bool disabled:1; // true if window cannot interact
9329 bool isForegroundWindow:1;// true while a root window is being activated
9330 bool visible:1; // Visibility flag
9331 bool destroyed:1; // true if window is being destroyed
9332 bool anchored:1; // true if this window is repositioned when the parent resizes
9333 bool dirty:1; // Flag set to true if any descendant must be redrawn
9339 bool modifyVirtArea:1;
9340 bool noAutoScrollArea:1;
9343 bool setVisible:1; // FOR FORM DESIGNER
9349 bool useSharedMemory:1;
9352 bool nativeDecorations:1;
9353 bool manageDisplay:1;
9354 bool formDesigner:1; // True if we this is running in the form editor
9357 // Checks used internally for them not to take effect in FormDesigner
9358 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9359 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9361 WindowController controller;
9362 public property WindowController controller { get { return controller; } set { delete controller; controller = value; if(controller) incref controller; } }
9365 public class CommonControl : Window
9367 // creationActivation = doNothing;
9370 public property String toolTip
9372 property_category $"Appearance"
9375 if(created) CommonControl::OnDestroy();
9377 toolTip = value ? ToolTip { tip = value; } : null;
9379 if(created) CommonControl::OnCreate();
9381 get { return toolTip ? toolTip.tip : null; }
9387 // (Very) Ugly work around for the fact that the parent watcher
9388 // won't fire when it's already been disconnected...
9389 eInstance_FireSelfWatchers(toolTip,
9390 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
9396 toolTip.parent = this;
9405 public class Percentage : float
9407 char * OnGetString(char * string, float * fieldData, bool * needClass)
9411 sprintf(string, "%.2f", this);
9412 c = strlen(string)-1;
9415 if(string[c] != '0')
9416 last = Max(last, c);
9417 if(string[c] == '.')
9430 public void ApplySkin(Class c, char * name, void ** vTbl)
9432 char className[1024];
9437 subclass(Window) wc = (subclass(Window))c;
9438 subclass(Window) base = (subclass(Window))c.base;
9440 sprintf(className, "%sSkin_%s", name, c.name);
9441 wc.pureVTbl = c._vTbl;
9442 c._vTbl = new void *[c.vTblSize];
9443 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9444 sc = eSystem_FindClass(c.module.application, className);
9448 for(m = 0; m < c.base.vTblSize; m++)
9450 if(c._vTbl[m] == base.pureVTbl[m])
9451 c._vTbl[m] = vTbl[m];
9456 for(m = 0; m < c.vTblSize; m++)
9458 if(sc._vTbl[m] != wc.pureVTbl[m])
9459 c._vTbl[m] = sc._vTbl[m];
9463 for(d = c.derivatives.first; d; d = d.next)
9465 ApplySkin(d.data, name, c._vTbl);
9469 public void UnapplySkin(Class c)
9471 char className[1024];
9473 subclass(Window) wc = (subclass(Window))c;
9474 subclass(Window) base = (subclass(Window))c.base;
9477 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9480 c._vTbl = wc.pureVTbl;
9484 for(d = c.derivatives.first; d; d = d.next)
9486 UnapplySkin(d.data);
9490 void CheckFontIntegrity(Window window)
9495 if(window.usedFont && window.usedFont.font == 0xecececec)
9497 FontResource uf = window.usedFont;
9498 char * className = window._class.name;
9499 char * text = window.text;
9502 for(c = window.firstChild; c; c = c.next)
9503 CheckFontIntegrity(c);
9507 public class ControllableWindow : Window
9509 /*WindowController controller;
9510 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9511 ~ControllableWindow() { delete controller; }*/
9514 class WindowControllerInterface : ControllableWindow
9516 bool OnKeyDown(Key key, unichar ch)
9518 bool result = ((int(*)())(void *)controller.OnKeyDown)((void *)controller.controlled, (void *)controller, key, ch);
9520 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown](controller.window, key, ch);
9524 bool OnKeyUp(Key key, unichar ch)
9526 bool result = ((int(*)())(void *)controller.OnKeyUp)((void *)controller.controlled, (void *)controller, key, ch);
9528 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp](controller.window, key, ch);
9532 bool OnKeyHit(Key key, unichar ch)
9534 bool result = ((int(*)())(void *)controller.OnKeyHit)((void *)controller.controlled, (void *)controller, key, ch);
9536 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit](controller.window, key, ch);
9540 bool OnMouseMove(int x, int y, Modifiers mods)
9542 bool result = ((int(*)())(void *)controller.OnMouseMove)((void *)controller.controlled, (void *)controller, x, y, mods);
9544 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove](controller.window, x, y, mods);
9548 bool OnLeftButtonDown(int x, int y, Modifiers mods)
9550 bool result = ((int(*)())(void *)controller.OnLeftButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9552 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown](controller.window, x, y, mods);
9556 bool OnLeftButtonUp(int x, int y, Modifiers mods)
9558 bool result = ((int(*)())(void *)controller.OnLeftButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9560 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp](controller.window, x, y, mods);
9564 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
9566 bool result = ((int(*)())(void *)controller.OnLeftDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9568 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick](controller.window, x, y, mods);
9572 bool OnRightButtonDown(int x, int y, Modifiers mods)
9574 bool result = ((int(*)())(void *)controller.OnRightButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9576 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown](controller.window, x, y, mods);
9580 bool OnRightButtonUp(int x, int y, Modifiers mods)
9582 bool result = ((int(*)())(void *)controller.OnRightButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9584 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp](controller.window, x, y, mods);
9588 bool OnRightDoubleClick(int x, int y, Modifiers mods)
9590 bool result = ((int(*)())(void *)controller.OnRightDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9592 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick](controller.window, x, y, mods);
9596 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
9598 bool result = ((int(*)())(void *)controller.OnMiddleButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9600 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown](controller.window, x, y, mods);
9604 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
9606 bool result = ((int(*)())(void *)controller.OnMiddleButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9608 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp](controller.window, x, y, mods);
9612 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
9614 bool result = ((int(*)())(void *)controller.OnMiddleDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9616 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick](controller.window, x, y, mods);
9620 void OnResize(int width, int height)
9622 ((int(*)())(void *)controller.OnResize)((void *)controller.controlled, (void *)controller, width, height);
9623 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize](controller.window, width, height);
9626 void OnRedraw(Surface surface)
9628 ((int(*)())(void *)controller.OnRedraw)((void *)controller.controlled, (void *)controller, surface);
9629 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw](controller.window, surface);
9634 bool result = ((int(*)())(void *)controller.OnCreate)((void *)controller.controlled, (void *)controller);
9636 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
9641 public class WindowController<class V>
9644 property Window window
9648 uint size = class(Window).vTblSize;
9651 windowVTbl = new void *[size];
9652 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
9653 if(value._vTbl == value._class._vTbl)
9655 value._vTbl = new void *[value._class.vTblSize];
9656 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
9660 for(c = 0; c < size; c++)
9662 void * function = class(WindowControllerInterface)._vTbl[c];
9663 if(function != DefaultFunction)
9664 value._vTbl[c] = function;
9666 value._vTbl[c] = windowVTbl[c];
9671 memcpy(value._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
9674 get { return window; }
9676 property V controlled
9678 set { controlled = value; }
9679 get { return controlled; }
9681 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
9682 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
9683 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
9684 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
9685 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
9686 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
9687 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9688 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
9689 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
9690 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9691 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
9692 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
9693 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9694 virtual void V::OnResize(WindowController controller, int width, int height);
9695 virtual void V::OnRedraw(WindowController controller, Surface surface);
9696 virtual bool V::OnCreate(WindowController controller);
9699 int (** windowVTbl)();