7 import "GuiApplication"
28 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
32 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
41 // Had to define this here for native decorations support, because the menu bar is part of total decoration's size, but not part of the system decorations
42 define skinMenuHeight = 25;
43 define statusBarHeight = 18;
45 default extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
47 public enum DialogResult { cancel, yes, no, ok };
49 public class MouseButtons
52 bool left:1, right:1, middle:1;
55 public struct SizeAnchor
58 bool isClientW, isClientH;
63 #define SNAPDOWN(x, d) \
66 if(x < 0) x -= ((d) - Abs(x) % (d)); else x -= x % (d); \
69 #define SNAPUP(x, d) \
72 if(x > 0) x += ((d) - Abs(x) % (d)); else x += x % (d); \
75 /*static */define MAX_DIRTY_BACK = 10;
77 /////////////////////////////////////////////////////////////////////////////
78 ////////// EXTENT MANIPULATION //////////////////////////////////////////////
79 /////////////////////////////////////////////////////////////////////////////
81 #define ACCESS_ITEM(l, id) \
84 #define FASTLIST_LOOP(l, v) \
85 for(v = (BoxItem)l.first; v; v = (BoxItem)v.next)
87 #define FASTLIST_LOOPN(l, v, n) \
88 for(v = (BoxItem)l.first, n = (BoxItem)(v ? v.next : null); v; v = (BoxItem)next, n = (BoxItem)(v ? v.next : null))
91 #define ACCESS_ITEM(l, id) \
92 ((FastItem)(((id) == -1) ? null : (((byte *)((l).items)) + (id) * (l).itemSize)))
94 #define FASTLIST_LOOP(l, v) \
95 for(v = (void *)ACCESS_ITEM((l), (l).first); v; v = (void *)ACCESS_ITEM((l), v.next))
97 #define FASTLIST_LOOPN(l, v, n) \
98 for( v = (void *)ACCESS_ITEM((l), (l).first), \
99 n = v ? ((void *)ACCESS_ITEM((l), v.next)): null; \
100 v; v = n, n = n ? (void *)ACCESS_ITEM((l), n.next) : null)
103 private class FastItem : struct
108 private struct FastList
113 int count, size, itemSize;
120 first = last = free = -1;
128 // FASTLIST_LOOPN(this, item, next) { Delete(item); };
131 FastItem Add(uint itemSize)
134 if(free == -1 || !size)
141 newSize = (size + (size >> 1));
142 items = (FastItem)renew items byte[newSize * itemSize];
147 this.itemSize = itemSize;
148 items = (FastItem)new byte[newSize * itemSize];
151 for(c = size; c<newSize-1; c++)
153 ACCESS_ITEM(this, c).prev = -1;
154 ACCESS_ITEM(this, c).next = c+1;
156 ACCESS_ITEM(this, c).prev = -1;
157 ACCESS_ITEM(this, c).next = -1;
161 item = ACCESS_ITEM(this, free);
164 ACCESS_ITEM(this, item.prev).next = free;
174 void Delete(FastItem item)
177 ACCESS_ITEM(this, item.prev).next = item.next;
179 ACCESS_ITEM(this, item.next).prev = item.prev;
181 if(ACCESS_ITEM(this, first) == item)
183 if(ACCESS_ITEM(this, last) == item)
188 free = ((byte *)item - (byte *)items) / itemSize;
196 free = first = last = -1;
200 private class BoxItem : Item //FastItem
205 public /*private */struct Extent : OldList //FastList
214 //BoxItem extentBox = (BoxItem)Add(sizeof(class BoxItem));
215 Add(BoxItem { box = box });
218 void Copy(Extent source)
224 //FASTLIST_LOOP(source, extentBox)
225 for(extentBox = (BoxItem)source.first; extentBox; extentBox = (BoxItem)extentBox.next)
226 AddBox(extentBox.box);
229 void IntersectBox(Box box)
231 // Clip all boxes of extent against inside of the new box
232 BoxItem extentBox, next;
234 //FASTLIST_LOOPN(this, extentBox, next) // Macros still mess up the parser!
235 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
237 next = (BoxItem)extentBox.next;
238 if(box.left > extentBox.box.left) extentBox.box.left = box.left;
239 if(box.top > extentBox.box.top) extentBox.box.top = box.top;
240 if(box.right < extentBox.box.right) extentBox.box.right = box.right;
241 if(box.bottom < extentBox.box.bottom) extentBox.box.bottom = box.bottom;
242 if(extentBox.box.right < extentBox.box.left || extentBox.box.bottom < extentBox.box.top)
247 void ExcludeBox(Box box, Extent temp)
254 for(extentBox = (BoxItem)temp.first; extentBox; extentBox = (BoxItem)extentBox.next)
256 if(extentBox.box.left < box.right && extentBox.box.right > box.left &&
257 extentBox.box.top < box.bottom && extentBox.box.bottom > box.top)
260 if(extentBox.box.top < box.top && extentBox.box.bottom >= box.top)
264 extentBox.box.left, extentBox.box.top,
265 extentBox.box.right, Min(extentBox.box.bottom, box.top -1)
271 if(extentBox.box.bottom > box.bottom && extentBox.box.top <= box.bottom)
275 extentBox.box.left, Max(extentBox.box.top,box.bottom +1),
276 extentBox.box.right, extentBox.box.bottom
282 if(extentBox.box.bottom >= box.top && extentBox.box.top <= box.bottom)
285 if(extentBox.box.left < box.left && extentBox.box.right >= box.left)
289 extentBox.box.left, Max(extentBox.box.top, box.top),
290 Min(extentBox.box.right, box.left-1), Min(extentBox.box.bottom, box.bottom)
296 if(extentBox.box.right > box.right && extentBox.box.left <= box.right)
300 Max(extentBox.box.left, box.right+1), Max(extentBox.box.top, box.top),
301 extentBox.box.right, Min(extentBox.box.bottom, box.bottom)
309 AddBox(extentBox.box);
315 void UnionBox(Box box, Extent temp)
317 BoxItem extentBox, next;
319 // First pass: check if this box is not already covered by one of the extent's box
320 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
322 if(extentBox.box.left <= box.left && extentBox.box.right >= box.right &&
323 extentBox.box.top <= box.top && extentBox.box.bottom >= box.bottom)
330 // Second pass: only keep boxes not completely covered in the new box
331 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
333 next = (BoxItem)extentBox.next;
334 if(extentBox.box.left >= box.left && extentBox.box.right <= box.right &&
335 extentBox.box.top >= box.top && extentBox.box.bottom <= box.bottom)
339 // Add the exclusion to the extent
340 ExcludeBox(box, temp);
343 if(box.bottom >= box.top && box.right >= box.left)
345 // Optimization: if the resulting boxes touch, add them smarter
346 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
348 if(box.top == extentBox.box.top && box.bottom == extentBox.box.bottom)
350 if(Abs(box.right - extentBox.box.left) <= 1)
352 extentBox.box.left = box.left;
355 else if(Abs(box.left - extentBox.box.right) <= 1)
357 extentBox.box.right = box.right;
361 else if(box.left == extentBox.box.left && box.right == extentBox.box.right)
363 if(Abs(box.bottom - extentBox.box.top) <= 1)
365 extentBox.box.top = box.top;
368 else if(Abs(box.top - extentBox.box.bottom) <= 1)
370 extentBox.box.bottom = box.bottom;
382 void Union(Extent b, Extent temp)
386 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
387 UnionBox(extentBox.box, temp);
390 void Intersection(Extent b, Extent temp, Extent temp2, Extent temp3)
397 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
400 temp2.IntersectBox(extentBox.box);
407 void Exclusion(Extent b, Extent temp)
410 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
411 ExcludeBox(extentBox.box, temp);
414 void Offset(int x, int y)
417 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
419 extentBox.box.left += x;
420 extentBox.box.top += y;
421 extentBox.box.right += x;
422 extentBox.box.bottom += y;
427 private define MINIMIZED_WIDTH = 160;
428 private define CASCADE_SPACE = 16;
430 // namespace Windows;
432 private class ScrollFlags
434 bool snapX:1, snapY:1, dontHide:1;
437 public class BorderBits { public: bool contour:1, fixed:1, sizable:1, deep:1, bevel:1, thin:1; };
439 class WindowBits : BorderBits
441 BorderBits borderBits:6:0;
442 bool hidden:1, isActiveClient:1, hasHorzScroll:1, hasVertScroll:1, stayOnTop:1, modal:1, isDefault:1, inactive:1, isRemote:1, drawBehind:1;
443 bool interim:1, tabCycle:1, noCycle:1, dontScrollHorz:1, dontScrollVert:1, hasMaximize:1, hasMinimize:1, hasClose:1;
444 bool embedded:1, hasMenuBar:1, isDocument:1, showInTaskBar:1, hasStatusBar:1, nonClient:1, clickThrough:1;
447 public enum BorderStyle : BorderBits
450 contour = BorderBits { contour = true },
451 fixed = BorderBits { fixed = true } | contour,
452 sizable = BorderBits { sizable = true } | fixed,
453 thin = BorderBits { fixed = true, thin = true } | contour,
454 sizableThin = BorderBits { sizable = true } | thin,
455 deep = BorderBits { deep = true },
456 bevel = BorderBits { bevel = true },
457 sizableDeep = sizable|deep,
458 sizableBevel = sizable|bevel,
459 fixedDeep = fixed|deep,
460 fixedBevel = fixed|bevel,
461 deepContour = deep|contour
464 public enum CreationActivationOption
466 activate, flash, doNothing
469 public enum WindowState { normal, minimized, maximized };
471 private class ResPtr : struct
478 private class HotKeySlot : struct
480 HotKeySlot prev, next;
488 class_data char * icon;
490 class_default_property caption;
491 // class_initialize GuiApplication::Initialize;
492 class_designer FormDesigner;
493 class_property char * icon
495 set { class_data(icon) = value; }
496 get { return class_data(icon); }
501 if(guiApp) guiApp.Initialize(true);
503 if(guiApp && guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
505 if(_vTbl == ((subclass(Window))_class).pureVTbl)
507 _vTbl = _class._vTbl;
509 else if(_vTbl != _class._vTbl)
512 for(m = 0; m < _class.vTblSize; m++)
514 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
515 _vTbl[m] = _class._vTbl[m];
520 //tempExtents[0] = { /*first = -1, last = -1, free = -1*/ };
521 //tempExtents[1] = { /*first = -1, last = -1, free = -1*/ };
522 //tempExtents[2] = { /*first = -1, last = -1, free = -1*/ };
523 //tempExtents[3] = { /*first = -1, last = -1, free = -1*/ };
527 // caption = CopyString(class.name);
529 children.offset = (byte*)&prev - (byte*)this;
530 childrenOrder.circ = true;
531 childrenCycle.circ = true;
533 maxSize = Size { MAXINT, MAXINT };
537 //style.isActiveClient = true;
540 modifyVirtArea = true;
541 manageDisplay = true;
542 nativeDecorations = true;
544 // scrollFlags = ScrollFlags { snapX = true, snapY = true };
545 sbStep.x = sbStep.y = 8;
547 if(guiApp) // dynamic_cast<GuiApplication>(thisModule)
549 cursor = guiApp.GetCursor(arrow);
550 property::parent = guiApp.desktop;
562 stopwatching(parent, font);
563 if(parent.activeChild == this)
564 parent.activeChild = null;
565 if(parent.activeClient == this)
566 parent.activeClient = null;
571 // Prevent destructor from being called again...
577 /////////////////////////////////
580 OldLink slave = master.slaves.FindLink(this);
581 master.slaves.Delete(slave);
588 parent.childrenCycle.Remove(cycle);
590 parent.childrenOrder.Remove(order);
591 parent.children.Remove(this);
596 /////////////////////////////////
598 while(ptr = resources.first)
601 resources.Delete(ptr);
608 for(child = children.first; child; child = child.next)
610 // child.stopwatching(this, font);
612 eInstance_StopWatching(this, __ecereProp___ecereNameSpace__ecere__gui__Window_font, child);
613 // Don't want property here
614 *&child.parent = null;
617 while(slave = slaves.first)
619 // Don't want property here
620 *&((Window)slave.data).master = null;
621 slaves.Delete(slave);
624 // Because we do a decref in DestroyEx...
632 // Why was this commented?
633 //if(this != guiApp.desktop)
646 if(((subclass(Window))_class).pureVTbl)
648 if(_vTbl == _class._vTbl)
650 _vTbl = ((subclass(Window))_class).pureVTbl;
655 for(m = 0; m < _class.vTblSize; m++)
657 if(_vTbl[m] == _class._vTbl[m])
658 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
662 if(_vTbl == ((subclass(Window))_class).pureVTbl || _vTbl == _class._vTbl)
665 dirtyArea.Free(null);
666 renderArea.Free(null);
667 overRenderArea.Free(null);
668 clipExtent.Free(null);
669 scrollExtent.Free(null);
670 dirtyBack.Free(null);
674 tempExtents[0].Free(null);
675 tempExtents[1].Free(null);
676 tempExtents[2].Free(null);
677 tempExtents[3].Free(null);
682 //#if !defined(ECERE_VANILLA)
683 char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
685 if(this == activeDesigner)
689 char * name = property::name;
690 return name ? name : "";
695 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
696 bool OnGetDataFromString(char * string)
698 FormDesigner designer = (FormDesigner)activeDesigner.classDesigner;
701 if(!strcmp(string, "this") || !strcmp(string, designer.form.name))
702 this = designer.form;
703 else if(!strcmpi(string, "(Desktop)"))
704 this = activeDesigner;
706 return activeDesigner.FindObject(&this, string);
712 // --- Window updates system ---
714 // Setup a bitmap for Redrawing on client area of Window
715 Surface Redraw(Box box)
717 Surface surface = null;
719 Box clientArea = this.clientArea;
723 mox.left -= clientStart.x;
724 mox.top -= clientStart.y;
725 mox.right -= clientStart.x;
726 mox.bottom -= clientStart.y;
728 mox.Clip(clientArea);
729 // mox.ClipOffset(against, scrolledPos.x, scrolledPos.y);
731 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && mox.right >= mox.left && mox.bottom >= mox.top)
733 int x = absPosition.x + clientStart.x;
734 int y = absPosition.y + clientStart.y;
735 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
737 x -= rootWindow.clientStart.x;
738 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
740 if(!guiApp.fullScreenMode || is3D)
742 x -= rootWindow.absPosition.x;
743 y -= rootWindow.absPosition.y;
747 x += rootWindow.parent.clientStart.x;
748 y += rootWindow.parent.clientStart.y;
750 mox.left += rootWindow.parent.clientStart.x;
751 mox.top += rootWindow.parent.clientStart.y;
752 mox.right += rootWindow.parent.clientStart.x;
753 mox.bottom += rootWindow.parent.clientStart.y;
758 surface = display.GetSurface(x, y, mox);
761 surface.width = clientSize.w;
762 surface.height = clientSize.h;
768 // Setup a bitmap for Redrawing on full Window
769 Surface RedrawFull(Box box)
771 Surface surface = null;
779 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && box.right >= box.left && box.bottom >= box.top)
781 int x = absPosition.x;
782 int y = absPosition.y;
783 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
785 x -= rootWindow.clientStart.x;
786 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
788 if(!guiApp.fullScreenMode || is3D)
790 x -= rootWindow.absPosition.x;
791 y -= rootWindow.absPosition.y;
794 x += rootWindow.parent.clientStart.x;
795 y += rootWindow.parent.clientStart.y;
797 mox.left += rootWindow.parent.clientStart.x;
798 mox.top += rootWindow.parent.clientStart.y;
799 mox.right += rootWindow.parent.clientStart.x;
800 mox.bottom += rootWindow.parent.clientStart.y;
805 surface = display.GetSurface(x, y, mox);
808 surface.width = size.w;
809 surface.height = size.h;
815 void FigureCaption(char * caption)
817 Window activeClient = null;
821 strcpy(caption, this.caption);
822 if(style.isDocument || fileName)
824 if(caption[0]) strcat(caption, " - ");
826 strcat(caption, fileName);
830 sprintf(title, "Untitled %d", documentID);
831 strcat(caption, title);
834 strcat(caption, " *");
839 for(activeClient = this.activeClient; activeClient && !((BorderBits)activeClient.borderStyle).fixed; activeClient = activeClient.activeClient);
841 if(activeClient && activeClient.state == maximized)
843 if(activeClient.caption)
845 if(caption[0]) strcat(caption, " - ");
846 strcat(caption, activeClient.caption);
848 if(activeClient.style.isDocument || activeClient.fileName)
850 if(caption[0]) strcat(caption, " - ");
851 strcat(caption, "[");
852 if(activeClient.fileName)
853 strcat(caption, activeClient.fileName);
857 sprintf(title, "Untitled %d", activeClient.documentID);
858 strcat(caption, title);
860 if(activeClient.modifiedDocument)
861 strcat(caption, " *");
862 strcat(caption, "]");
867 // Code for returning dirty from ScrollDisplay:
869 for(d = 0; d<scrollExtent.count; d++)
871 Box * box = &scrollExtent.boxes[d];
877 Min(box.right, box.left-scroll.x),box.bottom
879 dirtyArea.UnionBox(update);
885 Max(box.left, box.right-scroll.x), box.top,
886 box.right, box.bottom
888 dirtyArea.UnionBox(update);
896 box.right, Min(box.bottom, box.top-scroll.y),
898 dirtyArea.UnionBox(update);
904 box.left, Max(box.top, box.bottom-scroll.y),
905 box.right, box.bottom
907 dirtyArea.UnionBox(update);
912 void UpdateDecorations(void)
914 // TODO: *** TEMPORARY HACK ***
921 Update({ -clientStart.x, -clientStart.y, -clientStart.x + size.w-1, 0 });
923 Update({ -clientStart.x, clientSize.h, -clientStart.x + size.w-1, -clientStart.y + size.h-1 });
925 Update({ -clientStart.x,0, -1, clientSize.h-1 });
927 Update({ clientSize.w, 0, -clientStart.x + size.w-1, clientSize.h-1 });
930 // Returns w & h for Position
931 void ComputeAnchors(Anchor anchor, SizeAnchor sizeAnchor, int *ox, int *oy, int *ow, int *oh)
933 Window parent = this.parent ? this.parent : guiApp.desktop;
934 int vpw = parent ? parent.clientSize.w : 0;
935 int vph = parent ? parent.clientSize.h : 0;
936 int pw = parent ? parent.clientSize.w : 0;
937 int ph = parent ? parent.clientSize.h : 0;
938 int w = sizeAnchor.size.w, h = sizeAnchor.size.h;
939 int x = anchor.left.distance, y = anchor.top.distance;
941 MinMaxValue ew = 0, eh = 0;
943 float cascadeW, cascadeH;
945 int tilingW, tilingH, tilingSplit, tilingLastH;
946 int addX = 0, addY = 0;
948 if(parent && rootWindow == this && guiApp && guiApp.interfaceDriver)
950 Window masterWindow = this;
951 Box box { addX, addY, addX + vpw - 1, addY + vph - 1 };
954 if(master == guiApp.desktop)
955 masterWindow = guiApp.desktop.activeChild;
957 masterWindow = master.rootWindow;
958 if(!masterWindow) masterWindow = this;
960 guiApp.interfaceDriver.GetScreenArea(masterWindow, box);
961 if((anchor.left.type == offset && anchor.right.type == offset) || anchor.left.type == none)
964 pw = vpw = box.right - box.left + 1;
966 if((anchor.top.type == offset && anchor.bottom.type == offset) || anchor.top.type == none)
969 ph = vph = box.bottom - box.top + 1;
985 vpw = pw = parent.size.w;
986 vph = ph = parent.size.h;
988 else if(!style.fixed /*|| style.isDocument*/)
990 if(!style.dontScrollHorz && parent.scrollArea.w) vpw = parent.scrollArea.w;
991 if(!style.dontScrollVert && parent.scrollArea.h) vph = parent.scrollArea.h;
993 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
996 Desktop3D_FixSize(&pw, &ph);
997 Desktop3D_FixSize(&vpw, &vph);
1000 if(pw < skinMinSize.w) pw = skinMinSize.w;
1001 if(ph < skinMinSize.h) ph = skinMinSize.h;
1002 if(vpw < skinMinSize.w) vpw = skinMinSize.w;
1003 if(vph < skinMinSize.h) vph = skinMinSize.h;
1005 // TODO: Must fix what we're snapping
1008 if(anchor.left.type)
1010 SNAPUP(x, textCellW);
1012 else if(anchor.right.type)
1014 SNAPDOWN(x, textCellW);
1019 SNAPUP(y, textCellH);
1021 else if(anchor.bottom.type)
1023 SNAPDOWN(y, textCellH);
1027 // This is required to get proper initial decoration size using native decorations on Windows
1028 if(nativeDecorations && windowHandle && guiApp && guiApp.interfaceDriver && !visible)
1029 guiApp.interfaceDriver.PositionRootWindow(this, x, y, Max(1, size.w), Max(1, size.h), true, true);
1030 GetDecorationsSize(&ew, &eh);
1032 if(anchor.left.type >= cascade && (state == normal /*|| state == Hidden*/))
1034 if(parent.sbv && !parent.sbv.style.hidden)
1035 pw += guiApp.currentSkin.VerticalSBW();
1036 if(parent.sbh && !parent.sbh.style.hidden)
1037 ph += guiApp.currentSkin.HorizontalSBH();
1039 if(anchor.left.type == cascade)
1041 w = (int)(pw * 0.80);
1042 h = (int)(ph * 0.80);
1044 else if(anchor.left.type >= vTiled)
1049 numTiling = parent.numPositions - parent.numIcons;
1050 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1051 if(anchor.left.type == vTiled)
1053 tilingH = (int)sqrt(numTiling);
1054 tilingW = numTiling / tilingH;
1058 tilingW = (int)sqrt(numTiling);
1059 tilingH = numTiling / tilingW;
1062 leftOver = numTiling - tilingH * tilingW;
1065 tilingSplit = (tilingW - leftOver) * tilingH;
1066 tilingLastH = tilingH+1;
1069 tilingSplit = numTiling;
1071 if(positionID >= tilingSplit)
1073 x = pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
1074 y = ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
1075 x2 = pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
1076 y2 = ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
1080 x = pw * (positionID / tilingH) / tilingW;
1081 y = ph * (positionID % tilingH) / tilingH;
1082 x2 = pw * (positionID / tilingH + 1) / tilingW;
1083 y2 = ph * ((positionID % tilingH) + 1) / tilingH;
1087 SNAPDOWN(x, textCellW);
1088 SNAPDOWN(y, textCellH);
1089 SNAPDOWN(x2, textCellW);
1090 SNAPDOWN(y2, textCellH);
1098 if(sizeAnchor.isClientW) w += ew;
1099 if(sizeAnchor.isClientH) h += eh;
1101 if(anchor.left.type == offset)
1102 x = anchor.left.distance;
1103 else if(anchor.left.type == relative)
1104 x = (anchor.left.percent < 0) ? ((int)(vpw * anchor.left.percent - 0.5)) : (int)(vpw * anchor.left.percent + 0.5);
1105 else if(anchor.right.type == relative)
1106 // ex = (anchor.right.percent < 0) ? ((int)(vpw * anchor.right.percent + 0)) : ((int)(vpw * anchor.right.percent + 0));
1107 ex = (anchor.right.percent < 0) ? ((int)(vpw * (1.0-anchor.right.percent) + 0)) : ((int)(vpw * (1.0-anchor.right.percent) + 0));
1108 else if(anchor.right.type == offset)
1109 ex = vpw - anchor.right.distance;
1111 if(anchor.top.type == offset)
1112 y = anchor.top.distance;
1113 else if(anchor.top.type == relative)
1114 y = (anchor.top.percent < 0) ? ((int)(vph * anchor.top.percent - 0.5)) : ((int)(vph * anchor.top.percent + 0.5));
1115 else if(anchor.bottom.type == relative)
1116 //ey = (anchor.bottom.percent < 0) ? ((int)(vph * anchor.bottom.percent + 0)) : ((int)(vph * anchor.bottom.percent + 0));
1117 ey = (anchor.bottom.percent < 0) ? ((int)(vph * (1.0-anchor.bottom.percent) + 0)) : ((int)(vph * (1.0-anchor.bottom.percent) + 0));
1118 else if(anchor.bottom.type == offset)
1119 ey = vph - anchor.bottom.distance;
1121 if(anchor.left.type && anchor.right.type)
1123 switch(anchor.right.type)
1126 ex = pw * (1.0f-anchor.right.percent);
1127 w = Max((int)(ex + 0.5) - x, 0);
1130 ex = vpw - anchor.right.distance;
1131 w = Max((int)(ex + 0.5) - x, 0);
1135 if(anchor.top.type && anchor.bottom.type)
1137 switch(anchor.bottom.type)
1140 ey = ph * (1.0f-anchor.bottom.percent);
1141 h = Max((int)(ey + 0.5) - y, 0);
1144 ey = vph - anchor.bottom.distance;
1145 h = Max((int)(ey + 0.5) - y, 0);
1154 if(state == normal /*|| state == Hidden*/)
1156 bool addSbV = false, addSbH = false;
1158 if(sizeAnchor.isClientW || (anchor.left.type && anchor.right.type)) w = Max(w, 1); else w = Max(w, 0);
1159 if(sizeAnchor.isClientH || (anchor.top.type && anchor.bottom.type)) h = Max(h, 1); else h = Max(h, 0);
1161 w = Max(w, minSize.w);
1162 h = Max(h, minSize.h);
1163 w = Min(w, maxSize.w);
1164 h = Min(h, maxSize.h);
1166 if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
1168 if(w) w -= guiApp.currentSkin.VerticalSBW();
1171 if((sizeAnchor.isClientH || !h || (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
1173 if(h) h -= guiApp.currentSkin.HorizontalSBH();
1177 if(!OnResizing(&w, &h))
1183 if((addSbV)) // || reqScrollArea.h > h) && sbv)
1184 w += guiApp.currentSkin.VerticalSBW();
1185 if((addSbH)) // || reqScrollArea.w > w) && sbh)
1186 h += guiApp.currentSkin.HorizontalSBH();
1188 w = Max(w, skinMinSize.w);
1189 h = Max(h, skinMinSize.h);
1202 SNAPDOWN(w, textCellW);
1203 SNAPDOWN(h, textCellH);
1206 if(anchor.left.type == cascade && (state == normal /*|| state == Hidden*/))
1208 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1211 (pw - w) / CASCADE_SPACE,
1212 (ph - h) / CASCADE_SPACE);
1218 cascW = (pw - w) / (numCascade-1);
1219 cascH = (ph - h) / (numCascade-1);
1220 SNAPDOWN(cascW, textCellW);
1221 SNAPDOWN(cascH, textCellH);
1222 cascadeW = (float)cascW;
1223 cascadeH = (float)cascH;
1227 numCascade = Max(numCascade, 2);
1228 cascadeW = (float)(pw - w) / (numCascade-1);
1229 cascadeH = (float)(ph - h) / (numCascade-1);
1232 x = (int)((positionID % numCascade) * cascadeW);
1233 y = (int)((positionID % numCascade) * cascadeH);
1235 else if(anchor.left.type < vTiled)
1237 if(!anchor.left.type || anchor.horz.type == middleRelative)
1239 if(!anchor.right.type)
1241 if(anchor.horz.type == middleRelative)
1242 x = (int)(vpw * (0.5 + anchor.horz.percent) - w / 2);
1244 x = vpw / 2 + anchor.horz.distance - w / 2;
1250 // case A_EDGE: x = x - w; break;
1252 if(!anchor.top.type || anchor.vert.type == middleRelative)
1254 if(!anchor.bottom.type)
1256 if(anchor.vert.type == middleRelative)
1257 y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
1259 y = vph / 2 + anchor.vert.distance - h / 2;
1265 // case A_EDGE: y = y - h; break;
1268 if((state == normal /*|| state == Hidden*/) && !OnMoving(&x, &y, w, h))
1276 SNAPDOWN(x, textCellW);
1277 SNAPDOWN(y, textCellH);
1289 if(anchored && style.fixed && style.isActiveClient)
1294 void UpdateCaret(bool forceUpdate, bool erase)
1296 static Window lastWindow = null;
1297 static int caretX, caretY, caretSize;
1299 if(guiApp && guiApp.caretOwner == this)
1301 int x = caretPos.x - scroll.x;
1302 int y = caretPos.y - scroll.y;
1304 if((erase || this.caretSize) &&
1305 x >= clientArea.left && x <= clientArea.right &&
1306 y >= clientArea.top && y <= clientArea.bottom)
1310 guiApp.interfaceDriver.SetCaret(
1311 x + absPosition.x + clientStart.x,
1312 y + absPosition.y + clientStart.y, this.caretSize);
1313 guiApp.caretEnabled = true;
1315 if(erase || lastWindow != this || caretX != x || caretY != y || caretSize != this.caretSize || forceUpdate)
1319 if(lastWindow != this)
1321 updateBox.left = x + 1;
1323 updateBox.right = x + 2;
1324 updateBox.bottom = y + this.caretSize - 1;
1328 updateBox.left = Min(x + 1, caretX + 1);
1329 updateBox.top = Min(y, caretY);
1330 updateBox.right = Max(x + 2, caretX + 2);
1331 updateBox.bottom = Max(y + this.caretSize - 1, caretY + caretSize - 1);
1334 guiApp.caretOwner.Update(updateBox);
1341 caretSize = this.caretSize;
1347 guiApp.interfaceDriver.SetCaret(0,0,0);
1348 guiApp.caretEnabled = false;
1354 void SetPosition(int x, int y, int w, int h, bool modifyArea, bool modifyThisArea, bool modifyClientArea)
1359 scrolledPos.x = position.x = x;
1360 scrolledPos.y = position.y = y;
1362 clientSize.w = size.w = w;
1363 clientSize.h = size.h = h;
1365 if(parent && !style.nonClient)
1367 //if(!style.fixed || style.isDocument)
1369 if(!style.dontScrollHorz) scrolledPos.x -= parent.scroll.x;
1370 if(!style.dontScrollVert) scrolledPos.y -= parent.scroll.y;
1374 clientStart.x = clientStart.y = 0;
1376 SetWindowArea(&clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1378 //if(!activeClient || activeClient.state != maximized)
1379 if(!noAutoScrollArea)
1381 // Check if scroll area must be modified
1382 if(guiApp && !guiApp.modeSwitching && (sbv || sbh))
1384 bool foundChild = false;
1386 int cw = clientSize.w;// + ((!sbv || sbv.range > 1) ? guiApp.currentSkin.VerticalSBW() : 0);
1387 int ch = clientSize.h;// + ((!sbh || sbh.rangw > 1) ? guiApp.currentSkin.HorizontalSBH() : 0);
1388 for(child = children.first; child; child = child.next)
1390 if(child.modifyVirtArea && !child.style.hidden && child.created && /*!child.anchored &&*/
1391 !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1393 if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == offset)
1394 w = Max(w, child.position.x + child.size.w);
1395 else if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == none)
1396 w = Max(w, Max(child.position.x, 0) + child.size.w);
1397 if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == offset)
1398 h = Max(h, child.position.y + child.size.h);
1399 else if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == none)
1400 h = Max(h, Max(child.position.y, 0) + child.size.h);
1405 if(foundChild && (w > cw || h > ch))
1407 //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
1409 int stepX = sbStep.x, stepY = sbStep.y;
1410 // Needed to make snapped down position match the skin's check of client area
1411 // against realvirtual
1414 SNAPDOWN(stepX, textCellW);
1415 SNAPDOWN(stepY, textCellH);
1416 stepX = Max(stepX, textCellW);
1417 stepY = Max(stepY, textCellH);
1419 if(scrollFlags.snapX)
1421 if(scrollFlags.snapY)
1424 reqScrollArea.w = w;
1425 reqScrollArea.h = h;
1428 else if(reqScrollArea.w || reqScrollArea.h)
1430 reqScrollArea.w = 0;
1431 reqScrollArea.h = 0;
1432 SetScrollPosition(0,0);
1437 // Automatic MDI Client Scrolling Area Adjustment
1438 if(parent && !parent.noAutoScrollArea)
1440 if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
1441 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
1443 Window parent = this.parent;
1444 int w = parent.reqScrollArea.w;
1445 int h = parent.reqScrollArea.h;
1447 if(stateAnchor.right.type == none && stateAnchor.left.type == offset)
1448 w = Max(w, position.x + size.w);
1449 else if(stateAnchor.right.type == none && stateAnchor.left.type == none)
1450 w = Max(w, Max(position.x, 0) + size.w);
1451 if(stateAnchor.bottom.type == none && stateAnchor.top.type == offset)
1452 h = Max(h, position.y + size.h);
1453 else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
1454 h = Max(h, Max(position.y, 0) + size.h);
1456 if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
1457 (h > parent.clientSize.h && h > parent.reqScrollArea.h))
1459 /*bool resize = false;
1460 int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
1461 // Needed to make snapped down position match the skin's check of client area
1462 // against realvirtual
1465 SNAPDOWN(stepX, textCellW);
1466 SNAPDOWN(stepY, textCellH);
1467 stepX = Max(stepX, textCellW);
1468 stepY = Max(stepY, textCellH);
1470 if(parent.scrollFlags.snapX)
1472 if(parent.scrollFlags.snapY)
1474 if(parent.reqScrollArea.w != w || parent.reqScrollArea.h != h)
1476 parent.reqScrollArea.w = w;
1477 parent.reqScrollArea.h = h;*/
1479 // parent.UpdateScrollBars(true, true);
1480 parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1481 false, true, true, true, false, false);
1486 GetRidOfVirtualArea();
1490 UpdateScrollBars(modifyThisArea, false);
1491 else if(guiApp.currentSkin)
1494 &clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1496 if(sbv && (scrollFlags.dontHide || sbv.range > 1))
1497 clientSize.w -= guiApp.currentSkin.VerticalSBW();
1498 if(sbh && (scrollFlags.dontHide || sbh.range > 1))
1499 clientSize.h -= guiApp.currentSkin.HorizontalSBH();
1502 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1503 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1505 absPosition = scrolledPos;
1506 if(guiApp && guiApp.driver != null && guiApp.interfaceDriver)
1507 guiApp.interfaceDriver.OffsetWindow(this, &absPosition.x, &absPosition.y);
1509 if(this != guiApp.desktop && parent)
1511 absPosition.x += parent.absPosition.x;
1512 absPosition.y += parent.absPosition.y;
1513 if(!style.nonClient && this != guiApp.desktop)
1515 absPosition.x += parent.clientStart.x;
1516 absPosition.y += parent.clientStart.y;
1520 box = Box { 0, 0, size.w - 1, size.h - 1 };
1525 // Clip against parent's client area
1526 box.ClipOffset(against, scrolledPos.x, scrolledPos.y);
1528 // Compute client area in this window coordinate system
1529 clientArea.left = 0;
1531 clientArea.right = clientSize.w - 1;
1532 clientArea.bottom = clientSize.h - 1;
1534 // Clip against parent's client area
1536 clientArea.ClipOffset(against, scrolledPos.x + clientStart.x, scrolledPos.y + clientStart.y);
1540 //absPosition.x -= parent.clientStart.x;
1541 //absPosition.y -= parent.clientStart.y;
1544 // Adjust all children
1545 for(child = children.first; child; child = child.next)
1546 child.SetPosition(child.position.x, child.position.y, child.size.w, child.size.h, false, true, true);
1548 UpdateCaret(false, false);
1551 void GetRidOfVirtualArea(void)
1553 if(parent && !parent.destroyed && style.fixed &&
1554 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient &&
1555 parent.reqScrollArea.w && parent.reqScrollArea.h)
1557 if(!parent.noAutoScrollArea)
1561 for(child = children.first; child; child = child.next)
1563 if(child.modifyVirtArea && !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1565 if(child.position.x + child.size.w > parent.clientSize.w + ((!parent.sbv || parent.sbv.style.hidden) ? 0 : guiApp.currentSkin.VerticalSBW()) ||
1566 child.position.y + child.size.h > parent.clientSize.h + ((!parent.sbh || parent.sbh.style.hidden) ? 0 : guiApp.currentSkin.HorizontalSBH()))
1575 Window parent = this.parent;
1577 parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1578 false, true, true, true, false, false);
1580 parent.SetScrollArea(0,0,true);
1581 parent.SetScrollPosition(0,0);
1587 public void ExternalPosition(int x, int y, int w, int h)
1589 Position(x, y, w, h, false, true, true, true, false, false);
1592 // (w, h): Full window size
1593 bool Position(int x, int y, int w, int h, bool force, bool processAnchors, bool modifyArea, bool updateScrollBars, bool thisOnly, bool changeRootWindow)
1595 bool result = false;
1596 int oldCW = clientSize.w, oldCH = clientSize.h;
1597 bool clientResized, windowResized, windowMoved;
1599 bool realResized = size.w != w || size.h != h;
1601 // TOCHECK: This wasn't in ecere.dll
1602 //if(!parent) return true;
1603 if(destroyed) return false;
1605 windowMoved = position.x != x || position.y != y || force;
1607 // windowResized = realResized || force;
1608 windowResized = size.w != w || size.h != h || force;
1610 if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
1616 scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
1617 scrolledPos.x - parent.clientStart.x + this.box.right,
1618 scrolledPos.y - parent.clientStart.y + this.box.bottom
1624 Box box { scrolledPos.x + this.box.left, scrolledPos.y + this.box.top, scrolledPos.x + this.box.right, scrolledPos.y + this.box.bottom};
1629 SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
1631 clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
1632 if(clientResized && this == rootWindow && nativeDecorations && rootWindow.windowHandle)
1633 windowResized = true;
1635 if(display && rootWindow != this)
1638 if(guiApp && guiApp.windowMoving)
1640 if(guiApp.windowMoving.style.nonClient)
1641 guiApp.windowMoving.parent.SetMouseRangeToWindow();
1643 guiApp.windowMoving.parent.SetMouseRangeToClient();
1653 // Buttons bitmap resources crash if we do this while switching mode
1654 if(!guiApp || !guiApp.modeSwitching)
1657 // Process Anchored Children
1661 for(child = children.first; child; child = child.next)
1664 ((child.stateAnchor.left.type != offset ||
1665 child.stateAnchor.top.type != offset ||
1666 child.stateAnchor.right.type != none ||
1667 child.stateAnchor.bottom.type != none) ||
1668 child.state == maximized || child.state == minimized))
1670 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1672 // child.Position(x, y, w, h, false, true, true, true, false);
1673 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1674 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1680 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1681 //if(updateScrollBars)
1683 OnResize(clientSize.w, clientSize.h);
1685 if((clientResized || windowMoved) && created)
1686 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1688 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1690 Window master = guiApp.interimWindow.master;
1691 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1694 if(rootWindow == this && !is3D)
1698 x -= guiApp.desktop.absPosition.x;
1699 y -= guiApp.desktop.absPosition.y;
1701 //guiApp.Log("Position %s\n", caption);
1704 if(windowResized || windowMoved)
1705 if(display && !display.flags.memBackBuffer && changeRootWindow)
1706 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1708 if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved))
1709 for(child = parent.children.first; child && child != this; child = child.next)
1710 if(child.rootWindow)
1711 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1716 if(windowMoved || windowResized)
1718 display.Lock(true /*false*/);
1721 display.Position(absPosition.x, absPosition.y);
1722 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1725 // result = realResized ? display.Resize(size.w, size.h) : true;
1726 if(nativeDecorations && rootWindow.windowHandle)
1728 int w = clientSize.w, h = clientSize.h;
1729 if(hasMenuBar) h += skinMenuHeight;
1730 if(hasStatusBar) h += statusBarHeight;
1731 if(sbv && sbv.visible) w += sbv.size.w;
1732 if(sbh && sbh.visible) h += sbh.size.h;
1733 result = manageDisplay ? display.Resize(w, h) : true;
1736 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1740 else if(clientResized)
1742 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1745 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1749 if(windowMoved || windowResized)
1754 if(guiApp.driver && changeRootWindow && windowHandle)
1756 if(windowResized || windowMoved)
1757 if(!display || display.flags.memBackBuffer)
1758 guiApp.interfaceDriver.PositionRootWindow(this,
1759 x, y, w, h, windowMoved, windowResized);
1760 guiApp.interfaceDriver.UpdateRootWindow(this);
1762 for(child = children.first; child; child = child.next)
1764 if(child.is3D && child.created)
1766 // Copy Display Content
1767 child.display.displaySystem = display.displaySystem;
1768 child.display.window = display.window;
1769 child.display.current = display.current;
1770 child.display.width = display.width;
1771 child.display.height = display.height;
1772 child.display.driverData = display.driverData;
1773 child.display.mutex = null;
1784 void UpdateScrollBars(bool flag, bool fullThing)
1787 bool resizeH = false, resizeV = false;
1788 bool scrolled = false;
1789 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1790 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1792 if(destroyed) return;
1793 if(guiApp.currentSkin)
1795 MinMaxValue cw = 0, ch = 0;
1796 bool sbvVisible, sbhVisible;
1798 int positionH, positionV;
1800 // First get client area with no respect to scroll bars
1805 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1807 if(scrollFlags.dontHide)
1810 cw -= guiApp.currentSkin.VerticalSBW();
1812 ch -= guiApp.currentSkin.HorizontalSBH();
1814 // Update the scrollbar visibility
1820 sbh.disabled = rangeH <= 1;
1821 if(sbh.style.hidden)
1831 sbv.disabled = rangeV <= 1;
1832 if(sbv.style.hidden)
1840 // Then start off with horizontal scrollbar range
1843 positionH = sbh.thumbPosition;
1848 ch -= guiApp.currentSkin.HorizontalSBH();
1851 // Do the same for vertical scrollbar
1854 positionV = sbv.thumbPosition;
1860 cw -= guiApp.currentSkin.VerticalSBW();
1861 // Maybe we need to set the range on the horizontal scrollbar again
1866 sbh.Action(setRange, positionH, 0);
1867 if(rangeH <= 1 && sbh.range > 1)
1869 ch -= guiApp.currentSkin.HorizontalSBH();
1873 sbv.Action(setRange, positionV, 0);
1880 // Update the scrollbar visibility
1881 if(!scrollFlags.dontHide)
1883 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
1887 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
1894 if(guiApp.currentSkin)
1901 sbhVisible = sbh.style.hidden ? true : false;
1903 sbvVisible = sbv.style.hidden ? true : false;
1905 // Do our resize here
1906 if(flag && (resizeH || resizeV) && fullThing)
1908 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
1913 OnResize(clientSize.w, clientSize.h);
1919 sbh.visible = sbhVisible;
1921 sbv.visible = sbvVisible;
1923 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1924 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1927 sbh.pageStep = clientSize.w;
1929 sbv.pageStep = clientSize.h;
1931 // Notify doesn't handle setRange anymore... process it here
1934 int positionH = sbh.thumbPosition;
1935 if(scroll.x != positionH)
1937 OnHScroll(setRange, positionH, 0);
1941 SNAPDOWN(positionH, textCellW);
1942 scroll.x = positionH;
1948 int seen = clientSize.w, total = reqScrollArea.w;
1951 if(scrollFlags.snapX)
1952 SNAPDOWN(seen, sbStep.x);
1954 if(!total) total = seen;
1955 range = total - seen + 1;
1957 range = Max(range, 1);
1959 if(x >= range) x = range - 1;
1961 if(scrollFlags.snapX)
1962 SNAPUP(x, sbStep.x);
1966 OnHScroll(setRange, x, 0);
1971 SNAPDOWN(x, textCellW);
1977 int positionV = sbv.thumbPosition;
1978 if(scroll.y != positionV)
1980 OnVScroll(setRange, positionV, 0);
1984 SNAPDOWN(positionV, textCellH);
1985 scroll.y = positionV;
1991 int seen = clientSize.h, total = reqScrollArea.h;
1994 if(scrollFlags.snapY)
1995 SNAPDOWN(seen, sbStep.y);
1997 if(!total) total = seen;
1998 range = total - seen + 1;
1999 range = Max(range, 1);
2001 if(y >= range) y = range - 1;
2003 if(scrollFlags.snapY)
2004 SNAPUP(y, sbStep.y);
2008 OnVScroll(setRange, y, 0);
2013 SNAPDOWN(y, textCellH);
2019 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2022 for(child = children.first; child; child = child.next)
2024 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2027 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2028 child.Position(x, y, w, h, false, true, false, true, false, false);
2035 // Process Scrollbars
2037 if(sbh) // && !sbh.style.hidden
2039 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2040 // Need to set the range again (should improve...) since the scrollbars didn't have
2041 // the right size when UpdateScrollArea set the range on it
2044 sbh.seen = clientSize.w;
2048 if(sbv) // && !sbv.state.hidden
2050 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2051 // Need to set the range again (should improve...) since the scrollbars didn't have
2052 // the right size when UpdateScrollArea set the range on it
2055 sbv.seen = clientSize.h;
2060 // TESTING THIS LOWER
2061 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2064 for(child = children.first; child; child = child.next)
2066 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2069 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2070 child.Position(x, y, w, h, false, true, false, true, false, false);
2076 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2078 SetState(maximized, false, mods);
2082 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2084 SetState(normal, false, mods);
2088 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2090 SetState(minimized, false, mods);
2091 parent.CycleChildren(false, true, false, true);
2095 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2098 // Scroll bar notifications
2099 if(action != setRange)
2101 bool changed = false;
2105 if(scroll.x != position)
2107 OnHScroll(action, position, keyFlags);
2112 SNAPDOWN(position, textCellW);
2114 scroll.x = position;
2118 if(scroll.y != position)
2120 OnVScroll(action, position, keyFlags);
2125 SNAPDOWN(position, textCellH);
2127 scroll.y = position;
2131 bool childMove = false;
2132 for(child = children.first; child; child = child.next)
2134 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2137 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2138 child.Position(x, y, w, h, false, true, false, true, false, false);
2142 // Testing this patch out to solve MDI workspace redraw bugs
2143 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2144 // Scroll offsets to blame?
2148 UpdateCaret(false, false);
2152 // Testing this patch out to solve MDI workspace redraw bugs
2153 for(child = children.first; child; child = child.next)
2155 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2164 Window GetParentMenuBar()
2166 Window menuBarParent;
2167 for(menuBarParent = this; menuBarParent; menuBarParent = menuBarParent.parent)
2169 if(menuBarParent.menuBar) break;
2170 if(menuBarParent.parent && /*menuBarParent != */!menuBarParent.parent.activeClient)
2172 menuBarParent = null;
2176 return menuBarParent ? menuBarParent.menuBar : null;
2179 void CreateSystemChildren(void)
2181 Window parent = this;
2182 bool scrollBarChanged = false;
2183 bool hasClose = false, hasMaxMin = false;
2184 Point scroll = this.scroll;
2186 if(state == maximized)
2187 parent = GetParentMenuBar();
2191 if(style.hasClose) hasClose = true;
2192 if(style.hasMaximize || style.hasMinimize)
2199 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2201 sysButtons[2].Destroy(0);
2202 sysButtons[2] = null;
2204 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2206 sysButtons[1].Destroy(0);
2207 sysButtons[1] = null;
2209 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2211 sysButtons[0].Destroy(0);
2212 sysButtons[0] = null;
2215 if(hasClose && parent)
2222 parent, master = this,
2223 inactive = true, nonClient = true, visible = false;
2225 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2231 if(this.parent == guiApp.desktop)
2232 sysButtons[2].hotKey = altF4;
2233 else if(style.isActiveClient)
2234 sysButtons[2].hotKey = ctrlF4;
2235 sysButtons[2].Create();
2238 sysButtons[2].symbol = 'X';
2239 sysButtons[2].disabled = !style.hasClose;
2242 if(hasMaxMin && parent)
2246 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2247 if(state == maximized)
2250 method = RestoreButtonClicked;
2256 method = MaximizeButtonClicked;
2264 parent, master = this,
2265 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2267 sysButtons[1].Create();
2269 sysButtons[1].NotifyClicked = method;
2271 sysButtons[1].symbol = symbol;
2272 sysButtons[1].disabled = !style.hasMaximize;
2275 if(hasMaxMin && parent)
2279 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2280 if (state == minimized)
2283 method = RestoreButtonClicked;
2289 method = MinimizeButtonClicked;
2297 parent, master = this,
2298 hotKey = altM, inactive = true, nonClient = true, visible = false
2300 sysButtons[0].Create();
2302 sysButtons[0].NotifyClicked = method;
2304 sysButtons[0].symbol = symbol;
2305 sysButtons[0].disabled = !style.hasMinimize;
2308 // Create the scrollbars
2309 if(style.hasHorzScroll && !sbh)
2315 direction = horizontal,
2319 snap = scrollFlags.snapX,
2320 NotifyScrolling = ScrollBarNotification
2323 scrollBarChanged = true;
2325 else if(sbh && !style.hasHorzScroll)
2331 if(style.hasVertScroll && !sbv)
2337 direction = vertical,
2341 snap = scrollFlags.snapY,
2342 NotifyScrolling = ScrollBarNotification
2345 scrollBarChanged = true;
2347 else if(sbv && !style.hasVertScroll)
2352 if(scrollBarChanged)
2354 SetScrollLineStep(sbStep.x, sbStep.y);
2355 UpdateScrollBars(true, true);
2359 if(scrollBarChanged)
2361 if(sbh) sbh.thumbPosition = scroll.x;
2362 if(sbv) sbv.thumbPosition = scroll.y;
2366 void UpdateCaption(void)
2368 if(rootWindow == this)
2371 FigureCaption(caption);
2372 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2374 UpdateDecorations();
2377 if(parent.activeClient == this) // Added this last check
2379 if(parent.rootWindow == parent)
2382 parent.FigureCaption(caption);
2383 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2386 parent.UpdateCaption();
2388 parent.UpdateDecorations();
2392 void UpdateActiveDocument(Window previous)
2394 Window activeClient = this.activeClient;
2395 Window activeChild = this.activeChild;
2402 activeClient.CreateSystemChildren();
2404 previous.CreateSystemChildren();
2416 // Build window list
2419 Menu windowMenu = menu.FindMenu("Window");
2424 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2427 Window document = cycle.data;
2428 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2430 char name[2048], caption[2048];
2431 document.FigureCaption(caption);
2432 sprintf(name, "%d %s", id+1, caption);
2433 windowMenu.AddDynamic(MenuItem
2435 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2436 NotifySelect = MenuWindowSelectWindow
2440 if(activeClient.cycle == cycle) break;
2445 if((!previous && activeClient) || !activeClient)
2451 item = menu.FindItem(MenuWindowCloseAll, 0);
2452 if(item) item.disabled = false;
2453 item = menu.FindItem(MenuWindowNext, 0);
2454 if(item) item.disabled = false;
2455 item = menu.FindItem(MenuWindowPrevious, 0);
2456 if(item) item.disabled = false;
2457 item = menu.FindItem(MenuWindowCascade, 0);
2458 if(item) item.disabled = false;
2459 item = menu.FindItem(MenuWindowTileHorz, 0);
2460 if(item) item.disabled = false;
2461 item = menu.FindItem(MenuWindowTileVert, 0);
2462 if(item) item.disabled = false;
2463 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2464 if(item) item.disabled = false;
2465 item = menu.FindItem(MenuWindowWindows, 0);
2466 if(item) item.disabled = false;
2469 item = menu.FindItem(MenuFileClose, 0);
2470 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2471 item = menu.FindItem(MenuFileSaveAll, 0);
2472 if(item) item.disabled = numDocuments < 1;
2474 if(activeClient && activeClient.menu && activeClient.state != minimized)
2478 //activeClient.menu.Clean(activeClient);
2479 menu.Merge(activeClient.menu, true, activeClient);
2483 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2486 menu.Merge(activeChild.menu, true, activeChild);
2489 // This is called again for a child window change, with same active client
2490 OnActivateClient(activeClient, previous);
2491 if(!menuBar && !((BorderBits)borderStyle).fixed && parent && parent.activeClient == this)
2492 parent.UpdateActiveDocument(null);
2495 void _ShowDecorations(Box box, bool post)
2497 if(rootWindow == this && nativeDecorations) return;
2498 if(visible && this != guiApp.desktop)
2500 Surface surface = RedrawFull(box);
2504 FigureCaption(caption);
2507 ShowDecorations(captionFont.font,
2510 active, //parent.activeClient == this
2511 guiApp.windowMoving == this);
2513 PreShowDecorations(captionFont.font,
2516 active, //parent.activeClient == this
2517 guiApp.windowMoving == this);
2524 void UpdateExtent(Box refresh)
2526 Surface surface = null;
2528 if(!manageDisplay) { OnRedraw(null);return; }
2529 _ShowDecorations(refresh, false);
2531 surface = Redraw(refresh);
2532 // Opaque background: just fill before EW_REDRAW (clear?)
2535 surface.SetBackground(background);
2536 surface.SetForeground(foreground);
2537 surface.DrawingChar(' ');
2538 if(this == rootWindow)
2540 if(style.drawBehind || background.a)
2542 int a = background.a;
2543 // Premultiply alpha for clear color
2544 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2545 surface.Clear(colorBuffer);
2546 surface.SetBackground(background);
2549 else if(background.a)
2553 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2554 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2557 if(display.flags.alpha && background.a < 255 && background)
2559 surface.Area(0,0,clientSize.w, clientSize.h);
2560 /*if(style.clearDepthBuffer)
2561 surface.Clear(depthBuffer);*/
2563 else if(/*style.clearDepthBuffer || */background.a)
2565 int a = background.a;
2566 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2567 // Premultiply alpha for clear color
2568 surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
2569 surface.Clear(colorBuffer);
2570 surface.SetBackground(background);
2575 surface.TextFont(usedFont.font);
2576 surface.TextOpacity(false);
2580 // Draw the caret ...
2581 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2583 // surface.SetBackground(0xFFFFFF - background.color);
2584 surface.SetBackground(~background.color);
2586 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2587 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2593 void DrawOverChildren(Box refresh)
2595 Surface surface = Redraw(refresh);
2599 surface.DrawingChar(' ');
2600 surface.SetBackground(background);
2601 surface.SetForeground(foreground);
2603 surface.TextFont(usedFont.font);
2604 surface.TextOpacity(false);
2606 OnDrawOverChildren(surface);
2611 _ShowDecorations(refresh, true);
2614 void ComputeClipExtents(void)
2617 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2619 clipExtent.Copy(this.clipExtent);
2621 for(child = children.last; child; child = child.prev)
2623 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2625 bool opaque = child.IsOpaque(); // TODO: acess background directly
2626 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2628 child.clipExtent.Copy(clipExtent);
2629 child.clipExtent.Offset(-dx, -dy);
2630 child.clipExtent.IntersectBox(child.box);
2632 child.ComputeClipExtents();
2634 if(opaque && !child.style.nonClient)
2636 // Adjust the box for the parent:
2637 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2638 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2643 // ??? Only do this for overlapped window or if parent has with clip children flag
2645 // Do this if window has clip children flag on (default false?)
2646 // this.clipExtent = clipExtent;
2648 clipExtent.Free(null);
2651 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2653 bool opaque = IsOpaque();
2655 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2656 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2658 offsetX -= rootWindow.clientStart.x;
2659 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2663 for(child = children.last; child; child = child.prev)
2665 ColorAlpha background = *(ColorAlpha *)&child.background;
2666 bool opaque = child.IsOpaque();
2667 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2671 // Adjust renderArea to the root window level
2672 Extent * renderArea = &rootWindow.tempExtents[1];
2674 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2675 if(child.rootWindow.nativeDecorations && rootWindow.windowHandle)
2677 offsetX -= child.rootWindow.clientStart.x;
2678 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2682 Extent childRenderArea;
2684 if(backBufferUpdate != null)
2686 childRenderArea.Copy(backBufferUpdate);
2687 childRenderArea.Offset(-offsetX, -offsetY);
2690 childRenderArea.Copy(child.dirtyArea);
2692 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2693 renderArea.Copy(dirtyExtent);
2694 renderArea.Offset(-offsetX, -offsetY);
2695 childRenderArea.Union(renderArea);
2698 // Intersect with the clip extent
2699 childRenderArea.Intersection(child.clipExtent);
2702 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2703 renderArea->Offset(offsetX, offsetY);
2704 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2705 // overDirtyExtent.Union(renderArea);
2706 renderArea->Empty();
2707 // childRenderArea.Free();
2709 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2714 for(child = children.last; child; child = child.prev)
2716 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2718 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2723 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2725 bool opaque = IsOpaque();
2726 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2728 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2729 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2731 offsetX -= rootWindow.clientStart.x;
2732 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2736 for(child = children.last; child; child = child.prev)
2738 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2740 ColorAlpha background = *(ColorAlpha *)&child.background;
2741 bool opaque = child.IsOpaque();
2742 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2746 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2747 // Adjust renderArea to the root window level
2749 renderArea.Copy(child.dirtyArea);
2750 renderArea.Offset(offsetX, offsetY);
2751 dirtyExtent.Union(renderArea);
2752 overDirtyExtent.Union(renderArea);
2758 for(child = children.last; child; child = child.prev)
2760 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2762 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2766 if(backBufferUpdate != null)
2768 renderArea.Copy(backBufferUpdate);
2769 renderArea.Offset(-offsetX, -offsetY);
2771 overRenderArea.Copy(backBufferUpdate);
2772 overRenderArea.Offset(-offsetX, -offsetY);
2778 renderArea.Copy(dirtyArea);
2780 overRenderArea.Copy(dirtyArea);
2783 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2784 dirtyExtentWindow->Copy(dirtyExtent);
2785 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2786 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2787 dirtyExtentWindow->Empty();
2789 // Intersect with the clip extent
2790 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2793 if(renderArea.count > 10)
2796 printf("\nToo many extents (%d):\n", renderArea.count);
2798 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2799 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2804 for(c = 0; c<10; c++)
2807 FASTLIST_LOOP(renderArea, extentBox)
2809 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2811 renderArea.Copy(extent);
2813 FASTLIST_LOOP(renderArea, extentBox)
2816 printf("(%d, %d) - (%d, %d)\n",
2817 extentBox.box.left, extentBox.box.top,
2818 extentBox.box.right, extentBox.box.bottom);
2822 printf("\nNow %d\n", renderArea.count);
2828 // WHY WAS THIS COMMENTED ??
2830 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2831 dirtyExtentWindow->Copy(overDirtyExtent);
2832 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2833 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2834 dirtyExtentWindow->Empty();
2836 // Intersect with the clip extent
2837 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2843 if(scrollExtent.count)
2845 // Subtract render extent from scrolling extent
2846 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
2848 if(backBufferUpdate == null)
2850 Extent * dirty = &rootWindow.tempExtents[3];
2853 // Intersect scrolling extent with clip extent
2854 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2856 // offset this scroll to be at the root window level
2857 scrollExtent.Offset(offsetX, offsetY);
2858 // Add area that was scrolled to the dirty extents of the back buffer
2859 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
2863 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
2864 for(scrollBox = (BoxItem)scrollExtent.first; scrollBox; scrollBox = (BoxItem)scrollBox.next)
2865 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
2870 scrollExtent.Empty();
2872 // Add the exposed extent to the window render area
2873 dirty->Offset(-offsetX, -offsetY);
2874 renderArea.Union(dirty, rootWindow.tempExtents[0]);
2879 // Subtract the window's box from the transparency forced extent
2880 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
2886 renderArea.Copy(this.renderArea);
2887 renderArea.Offset(offsetX, offsetY);
2888 dirtyExtent.Union(renderArea);
2894 Extent renderArea { };
2896 renderArea.Copy(overRenderArea);
2897 renderArea.Offset(offsetX, offsetY);
2898 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2903 if(backBufferUpdate != null)
2905 // Remove render area from dirty area
2906 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
2908 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
2915 // Remove the window render area from the dirty extents of the back buffer
2916 rootWindow.dirtyBack.Exclusion(renderArea);
2920 void Render(Extent updateExtent)
2924 Window rootWindow = this.rootWindow;
2925 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2926 if(rootWindow.nativeDecorations && rootWindow.windowHandle)
2928 offsetX -= rootWindow.clientStart.x;
2929 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2932 if(rootWindow.fullRender)
2941 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2942 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
2947 /*if(renderArea.count)
2948 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
2951 for(extentBox = (BoxItem)renderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2953 Box box = extentBox.box;
2956 /*printf("(%d, %d) - (%d, %d)\n",
2957 extentBox.box.left, extentBox.box.top,
2958 extentBox.box.right, extentBox.box.bottom);*/
2963 box.left += offsetX;
2965 box.right += offsetX;
2966 box.bottom += offsetY;
2968 if(updateExtent != null)
2969 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2973 for(child = children.first; child; child = child.next)
2974 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
2975 child.Render(updateExtent);
2977 if(rootWindow.fullRender)
2978 DrawOverChildren(box);
2981 // TO DO: There's an issue about draw over children...
2982 // TO DO: Don't wanna go through this if method isn't used
2983 for(extentBox = (BoxItem)overRenderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2984 //FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
2986 Box box = extentBox.box;
2988 DrawOverChildren(box);
2990 box.left += offsetX;
2992 box.right += offsetX;
2993 box.bottom += offsetY;
2995 if(updateExtent != null)
2996 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2999 for(child = children.first; child; child = child.next)
3000 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
3001 child.Render(updateExtent);
3004 overRenderArea.Empty();
3007 public void UpdateDisplay(void)
3009 if(!manageDisplay) { OnRedraw(null);return; }
3010 if(rootWindow && this != rootWindow)
3011 rootWindow.UpdateDisplay();
3014 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
3015 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
3018 dirtyExtent.Clear();
3021 clipExtent.AddBox(box);
3023 display.StartUpdate();
3025 if(!rootWindow.fullRender)
3027 ComputeClipExtents();
3028 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
3029 ComputeRenderArea(dirtyExtent, overExtent, null);
3032 clipExtent.Free(null);
3034 dirtyExtent.Free(null);
3035 overExtent.Free(null);
3037 if(display.flags.flipping)
3040 display.Update(null);
3044 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
3045 updateExtent.Clear();
3047 Render(updateExtent);
3049 updateExtent.UnionBox(this.box, tempExtents[0]);
3052 //printf("\n\nUpdate:\n------------------------------------------\n");
3055 //FASTLIST_LOOP(updateExtent, extentBox)
3056 for(extentBox = (BoxItem)updateExtent.first; extentBox; extentBox = (BoxItem)extentBox.next)
3059 /*printf("Updating (%d, %d) - (%d, %d)\n",
3060 extentBox.box.left, extentBox.box.top,
3061 extentBox.box.right, extentBox.box.bottom);*/
3064 display.Update(extentBox.box);
3067 updateExtent.Free(null);
3070 display.EndUpdate();
3078 void UpdateBackDisplay(Box box)
3084 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3086 //printf("UpdateBackDisplay going through!\n");
3087 display.StartUpdate();
3091 intersection.Copy(dirtyBack);
3092 intersection.IntersectBox(box);
3094 dirtyExtent.Clear();
3097 clipExtent.AddBox(box);
3099 if(!rootWindow.fullRender)
3101 ComputeClipExtents();
3102 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3105 clipExtent.Free(null);
3107 intersection.Free(null);
3108 dirtyExtent.Free(null);
3109 overExtent.Free(null);
3114 if(display.flags.flipping)
3115 display.Update(null);
3118 rootWindow.display.Update(box);
3121 display.EndUpdate();
3125 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3126 if(dirtyBack.count > MAX_DIRTY_BACK)
3128 BoxItem extentBox, next;
3129 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3130 for(extentBox = (BoxItem)dirtyBack.first; extentBox; extentBox = next)
3132 next = (BoxItem)extentBox.next;
3133 if(extentBox != first)
3135 if(extentBox.box.left < first.box.left)
3136 first.box.left = extentBox.box.left;
3137 if(extentBox.box.top < first.box.top)
3138 first.box.top = extentBox.box.top;
3139 if(extentBox.box.right > first.box.right)
3140 first.box.right = extentBox.box.right;
3141 if(extentBox.box.bottom > first.box.bottom)
3142 first.box.bottom = extentBox.box.bottom;
3143 dirtyBack.Delete(extentBox);
3152 // --- Window positioning ---
3153 // --- Window identification ---
3155 // Returns window at position "Position"
3156 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3158 Window child, result = null;
3160 box.left += absPosition.x;
3161 box.right += absPosition.x;
3162 box.top += absPosition.y;
3163 box.bottom += absPosition.y;
3165 if(!destroyed && visible && (acceptDisabled || !disabled))
3167 int lx = x - absPosition.x;
3168 int ly = y - absPosition.y;
3169 if(IsInside(lx, ly))
3170 // if(box.IsPointInside(Point{x, y}))
3172 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3173 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3176 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3178 if(child != statusBar && child.rootWindow == rootWindow)
3180 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3187 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3189 if(child != statusBar && child.rootWindow == rootWindow)
3191 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3203 Window FindModal(void)
3205 Window modalWindow = this, check;
3206 Window check2 = null;
3207 for(check = this; check.master; check = check.master)
3209 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3211 modalWindow = check.master.modalSlave;
3212 check = modalWindow;
3214 // TESTING THIS FOR DROPBOX...
3215 if(!rootWindow || !rootWindow.style.interim)
3217 for(check2 = check; check2.activeChild; check2 = check2.activeChild)
3219 if(check2.modalSlave && check2.modalSlave.created)
3221 modalWindow = check2.modalSlave;
3229 if(modalWindow == this)
3231 for(check = this; check.activeChild; check = check.activeChild)
3233 if(check.modalSlave)
3235 modalWindow = check.modalSlave;
3241 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3242 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3245 void StopMoving(void)
3247 if(this == guiApp.windowMoving)
3249 guiApp.windowMoving = null;
3250 UpdateDecorations();
3251 SetMouseRange(null);
3254 if(rootWindow.active)
3255 guiApp.interfaceDriver.StopMoving(rootWindow);
3258 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3259 guiApp.windowIsResizing = false;
3263 void SelectMouseCursor(void)
3268 Window cursorWindow = null;
3269 bool rx, ry, rex, rey;
3271 guiApp.desktop.GetMousePosition(&x, &y);
3272 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3274 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3275 guiApp.SetCurrentCursor(guiApp.systemCursors[moving]);
3276 else if(mouseWindow)
3278 modalWindow = mouseWindow.FindModal();
3279 x -= mouseWindow.absPosition.x;
3280 y -= mouseWindow.absPosition.y;
3281 if(guiApp.windowIsResizing)
3283 rex = guiApp.resizeEndX;
3284 rey = guiApp.resizeEndY;
3285 rx = guiApp.resizeX;
3286 ry = guiApp.resizeY;
3287 if((rex && rey) || (rx && ry))
3288 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3289 else if((rex && ry) || (rx && rey))
3290 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3291 else if((ry || rey) && (!rx && !rex))
3292 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3293 else if((rx || rex) && (!ry && !rey))
3294 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3296 else if(!modalWindow && !guiApp.windowCaptured &&
3297 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3298 &rx, &ry, &rex, &rey))
3300 if((rex && rey) || (rx && ry))
3301 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3302 else if((rex && ry) || (rx && rey))
3303 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3304 else if((ry || rey) && (!rx && !rex))
3305 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3306 else if((rx || rex) && (!ry && !rey))
3307 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3309 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3311 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}))
3312 cursorWindow = mouseWindow.parent;
3314 cursorWindow = mouseWindow;
3316 else if(!guiApp.interimWindow)
3317 cursorWindow = guiApp.windowCaptured;
3320 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient; cursorWindow = cursorWindow.parent);
3321 guiApp.SetCurrentCursor(cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3323 else if(modalWindow)
3325 guiApp.SetCurrentCursor(guiApp.systemCursors[arrow]);
3327 else if(guiApp.interimWindow)
3329 if(guiApp.interimWindow.cursor)
3330 guiApp.SetCurrentCursor(guiApp.interimWindow.cursor);
3332 guiApp.SetCurrentCursor(mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3337 // --- State based input ---
3338 bool AcquireInputEx(bool state)
3343 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3344 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3346 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3348 guiApp.acquiredWindow = state ? this : null;
3351 SetMouseRangeToClient();
3352 guiApp.interfaceDriver.SetMouseCursor((SystemCursor)-1);
3357 SelectMouseCursor();
3359 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3363 // --- Window activation ---
3364 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3367 if(!parent || !parent.style.inactive)
3369 Window parent = this.parent;
3372 if(rootWindow == this)
3373 Log(active ? "active\n" : "inactive\n");
3376 // Testing this here...
3377 if(!parent || parent == guiApp.desktop || parent.active)
3379 this.active = active;
3382 // TESTING THIS HERE
3383 UpdateDecorations();
3384 if(result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master)
3385 result = NotifyActivate(master, this, active, previous);
3388 this.active = !active;
3393 if(!parent || parent == guiApp.desktop || parent.active)
3395 this.active = active;
3397 AcquireInputEx(active);
3402 if(guiApp.caretOwner)
3406 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3407 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3408 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3409 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3411 guiApp.caretOwner.Update(extent);
3414 if(visible || !guiApp.caretOwner)
3415 guiApp.caretOwner = this;
3416 UpdateCaret(false, false);
3422 this.active = false;
3424 AcquireInputEx(active);
3426 if(!active && guiApp.caretOwner == this)
3428 UpdateCaret(false, true);
3429 guiApp.caretOwner = null;
3430 guiApp.interfaceDriver.SetCaret(0,0,0);
3431 guiApp.caretEnabled = false;
3436 if(!active && parent && parent.activeChild && parent.activeChild != this)
3437 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3443 if(!active && menuBar)
3446 menuBar.OnActivate(false, null, &goOn, true);
3447 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3452 Window aChild = activeChild;
3454 if(!aChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3466 void ConsequentialMouseMove(bool kbMoving)
3470 if(kbMoving || !guiApp.windowMoving)
3474 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3476 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3478 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3479 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3485 bool IsDescendantOf(Window ancestor)
3488 for(window = this; window && window != ancestor; window = window.parent);
3489 return window == ancestor;
3492 bool IsSlaveOf(Window master)
3495 for(window = this; window && window != master; window = window.master);
3496 return window == master;
3499 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3503 if(this && !destroyed /*&& state != Hidden*/)
3505 Window swap = externalSwap;
3513 if(activateParent &&
3514 (parent.activeChild != this ||
3515 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3516 active && _isModal &&
3517 parent != master && master)
3518 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3524 bool real = parent.activeChild != this;
3526 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3527 if(/*activateParent && */guiApp.interimWindow &&
3528 !IsDescendantOf(guiApp.interimWindow) &&
3529 !IsSlaveOf(guiApp.interimWindow))
3531 Window interimWindow = guiApp.interimWindow;
3532 while(interimWindow && interimWindow != this)
3534 Window master = interimWindow.master;
3536 guiApp.interimWindow = null;
3537 if(guiApp.caretOwner)
3538 guiApp.caretOwner.UpdateCaret(false, false);
3540 incref interimWindow;
3541 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3546 delete interimWindow;
3547 interimWindow = (master && master.style.interim) ? master : null;
3552 guiApp.interimWindow = this;
3553 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3554 guiApp.caretEnabled = false;*/
3555 UpdateCaret(false, true);
3560 bool acquireInput = false;
3562 parent.activeChild &&
3563 parent.activeChild.state == maximized &&
3564 parent != guiApp.desktop;
3566 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3571 swap = parent.activeChild;
3572 if(swap && swap.destroyed) swap = null;
3573 if(swap && swap != this)
3576 if(!swap.PropagateActive(false, this, &goOn, true))
3577 swap = parent.activeChild;
3588 if(!parent || parent.activeChild != this || style.interim)
3591 result = PropagateActive(true, swap, &goOn, true);
3592 if(!result && !goOn)
3597 acquireInput = true;
3601 if(style.hasMaximize && parent != guiApp.desktop)
3604 SetState(maximized, false, 0);
3605 else if(state != maximized)
3608 for(child = parent.children.first; child; child = child.next)
3610 if(this != child && child.state == maximized)
3611 child.SetState(normal, false, 0);
3618 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3620 Window previous = parent.activeClient;
3621 parent.activeChild = this;
3622 if(!style.nonClient /*&& style.isActiveClient*/)
3626 if(style.isActiveClient)
3627 parent.activeClient = this;
3628 // Moved UpdateActiveDocument inside hidden check
3629 // To prevent activating previous window while creating a new one
3630 // (It was messing up the privateModule in the CodeEditor)
3631 parent.UpdateActiveDocument(previous);
3637 //if(!style.isRemote)
3639 if(rootWindow != this)
3641 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3642 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3644 else if(!guiApp.fullScreenMode)
3646 Window modalRoot = FindModal();
3647 if(!modalRoot) modalRoot = this;
3648 if(!modalRoot.isForegroundWindow)
3650 modalRoot.isForegroundWindow = true;
3651 // To check : Why is parent null?
3652 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3654 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3656 modalRoot.isForegroundWindow = false;
3661 if(result && real && (!style.inactive || moveInactive) && parent)
3663 Window last = parent.children.last;
3665 if(!style.stayOnTop)
3666 for(; last && last.style.stayOnTop; last = last.prev);
3668 parent.children.Move(this, last);
3670 // Definitely don't want that: why not?
3674 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3680 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3687 parent.activeChild = null;
3688 if(!style.nonClient /*&& style.isActiveClient*/)
3690 Window previous = parent.activeClient;
3691 if(style.isActiveClient)
3692 parent.activeClient = null;
3693 parent.UpdateActiveDocument(previous);
3697 if(this == guiApp.interimWindow)
3699 guiApp.interimWindow = null;
3700 if(guiApp.caretOwner)
3701 guiApp.caretOwner.UpdateCaret(false, false);
3703 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3710 if(!active || !swap)
3711 UpdateDecorations();
3713 swap.UpdateDecorations();
3715 if(active && rootWindow != this)
3716 ConsequentialMouseMove(false);
3723 // --- Input Messages ---
3724 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3726 static bool reEntrancy = false;
3727 if(reEntrancy) return;
3731 guiApp.cursorUpdate = true;
3732 if(guiApp.windowScrolling && !consequential)
3734 guiApp.windowScrolling.SetScrollPosition(
3735 (guiApp.windowScrolling.sbh) ?
3736 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3737 (guiApp.windowScrolling.sbv) ?
3738 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3740 if(guiApp.windowMoving)
3742 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3744 Window window = guiApp.windowMoving;
3746 int w = window.size.w;
3747 int h = window.size.h;
3752 rx = mouseX - guiApp.windowMovingStart.x;
3753 ry = mouseY - guiApp.windowMovingStart.y;
3756 window.GetDecorationsSize(&ew, &eh);
3758 if(guiApp.windowIsResizing)
3760 x = window.scrolledPos.x;
3761 y = window.scrolledPos.y;
3765 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3766 rx = guiApp.windowResizingBefore.w - aw;
3767 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3768 w = guiApp.windowResizingBefore.w - rx;
3772 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3773 ry = guiApp.windowResizingBefore.h - ah;
3774 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3775 ry = Max(ry, -guiApp.windowMovingBefore.y);
3776 h = guiApp.windowResizingBefore.h - ry;
3778 if(guiApp.resizeEndX)
3780 w = guiApp.windowResizingBefore.w + rx;
3783 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3791 w = Max(w, window.minSize.w);
3792 h = Max(h, window.minSize.h);
3793 w = Min(w, window.maxSize.w);
3794 h = Min(h, window.maxSize.h);
3796 if(!window.OnResizing(&w, &h))
3798 w = window.clientSize.w;
3799 h = window.clientSize.h;
3802 w = Max(w, window.skinMinSize.w);
3803 h = Max(h, window.skinMinSize.h);
3810 SNAPDOWN(w, textCellW);
3811 SNAPDOWN(h, textCellH);
3816 aw = Max(w,window.skinMinSize.w);
3817 rx = guiApp.windowResizingBefore.w - aw;
3818 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3819 w = guiApp.windowResizingBefore.w - rx;
3823 ah = Max(h,window.skinMinSize.h);
3824 ry = guiApp.windowResizingBefore.h - ah;
3825 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3826 ry = Max(ry, -guiApp.windowMovingBefore.y);
3827 h = guiApp.windowResizingBefore.h - ry;
3832 if(!guiApp.windowIsResizing || guiApp.resizeX)
3833 x = guiApp.windowMovingBefore.x + rx;
3834 if(!guiApp.windowIsResizing || guiApp.resizeY)
3835 y = guiApp.windowMovingBefore.y + ry;
3837 if(!guiApp.windowIsResizing)
3840 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
3842 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
3843 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
3844 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
3845 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
3849 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
3850 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
3856 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
3858 if(!window.OnMoving(&x, &y, w, h))
3860 x = window.scrolledPos.x;
3861 y = window.scrolledPos.y;
3867 SNAPDOWN(x, textCellW);
3868 SNAPDOWN(y, textCellH);
3871 if(!window.style.nonClient)
3873 if(!window.style.fixed /*|| window.style.isDocument*/)
3875 if(!window.style.dontScrollHorz)
3876 x += window.parent.scroll.x;
3877 if(!window.style.dontScrollVert)
3878 y += window.parent.scroll.y;
3882 // Break the anchors for moveable/resizable windows
3883 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
3884 if(window.style.fixed)
3886 if(window.state == normal)
3888 window.normalAnchor = Anchor { left = x, top = y };
3889 window.normalSizeAnchor = SizeAnchor { { w, h } };
3890 window.anchored = false;
3894 window.stateAnchor = Anchor { left = x, top = y };
3895 window.stateSizeAnchor = SizeAnchor { { w, h } };
3897 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
3898 // TOCHECK: Investigate why the following only redraws the scrollbars
3899 //window.Position(x, y, w, h, false, true, true, true, false, true);
3901 guiApp.movingLast.x = mouseX;
3902 guiApp.movingLast.y = mouseY;
3908 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
3911 bool wasMoving = guiApp.windowMoving ? true : false;
3912 bool wasScrolling = guiApp.windowScrolling ? true : false;
3914 while(result && w != this)
3916 Window msgWindow = GetAtPosition(x,y, false, true, w);
3917 Window trueWindow = GetAtPosition(x,y, false, false, w);
3918 bool windowDragged = false;
3923 window = (w && !w.disabled) ? w : null;
3925 if(trueWindow) incref trueWindow;
3927 if(consequential) mods->isSideEffect = true;
3929 UpdateMouseMove(x, y, consequential);
3931 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
3933 if(!guiApp.windowCaptured.isEnabled)
3934 guiApp.windowCaptured.ReleaseCapture();
3936 window = guiApp.windowCaptured;
3939 if(trueWindow && activate &&
3940 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3941 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3942 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3943 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3945 if(mods->alt && !mods->ctrl && !mods->shift)
3947 Window moved = trueWindow;
3948 for(moved = trueWindow; moved; moved = moved.parent)
3949 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3954 windowDragged = true;
3956 // Cancel the ALT menu toggling...
3957 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
3962 if(window && activate &&
3963 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3964 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3965 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3966 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3968 Window modalWindow = window.FindModal();
3970 /*if(mods->alt && !mods->shift && !mods->ctrl)
3972 Window moved = window;
3973 for(moved = window; moved; moved = moved.parent)
3974 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3979 windowDragged = true;
3981 // Cancel the ALT menu toggling...
3982 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
3988 Window activateWindow = modalWindow ? modalWindow : window;
3989 if(activateWindow && !activateWindow.isRemote)
3991 bool doActivation = true;
3992 //bool needToDoActivation = false;
3993 Window check = activateWindow;
3995 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
3997 if(!check.style.inactive)
3999 //needToDoActivation = true;
4001 doActivation = false;
4006 if(!needToDoActivation)
4007 doActivation = false;
4010 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
4011 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
4013 // Let the OnLeftButtonDown do the activating instead
4014 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4022 incref activateWindow;
4023 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
4025 delete activateWindow;
4029 if(activateWindow._refCount == 1)
4031 delete activateWindow;
4035 delete activateWindow;
4037 mods->isActivate = true;
4041 if(!modalWindow && window && !window.destroyed)
4043 if(!guiApp.windowCaptured || windowDragged)
4045 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
4047 bool moving = ((window.state != maximized &&
4048 window.IsMouseMoving(
4049 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4050 || (guiApp.windowMoving && !guiApp.windowIsResizing);
4052 if(!moving && window.IsMouseResizing(
4053 x - window.absPosition.x,
4054 y - window.absPosition.y,
4055 window.size.w, window.size.h,
4056 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
4058 guiApp.windowIsResizing = true;
4059 guiApp.windowResizingBefore.w = window.size.w;
4060 guiApp.windowResizingBefore.h = window.size.h;
4062 if(guiApp.windowIsResizing || windowDragged || moving)
4065 guiApp.windowMoving = window;
4066 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4067 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4068 guiApp.windowMovingBefore.x = window.position.x;//s;
4069 guiApp.windowMovingBefore.y = window.position.y;//s;
4070 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4071 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4074 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4076 if(window.style.fixed &&
4078 window.IsMouseMoving(
4079 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4081 window.ShowSysMenu(x, y);
4085 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4087 if(window.sbv || window.sbh)
4090 guiApp.windowScrolling = window;
4091 guiApp.windowScrollingStart.x = x;
4092 guiApp.windowScrollingStart.y = y;
4093 guiApp.windowScrollingBefore.x = window.scroll.x;
4094 guiApp.windowScrollingBefore.y = window.scroll.y;
4097 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4099 if(window.style.hasMaximize &&
4100 window.IsMouseMoving(
4101 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4104 (window.state == maximized) ? normal : maximized, false, *mods);
4112 if(guiApp.windowMoving)
4114 if(guiApp.windowMoving.parent)
4116 if(guiApp.windowMoving.style.nonClient)
4117 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4119 guiApp.windowMoving.parent.SetMouseRangeToClient();
4123 window.UpdateDecorations();
4126 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4128 // Log("\n*** LEFT BUTTON UP ***\n");
4129 if(guiApp.windowMoving)
4130 guiApp.windowMoving.StopMoving();
4132 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4134 if(guiApp.windowScrolling)
4136 Window windowScrolling = guiApp.windowScrolling;
4137 guiApp.windowScrolling = null;
4138 windowScrolling.ReleaseCapture();
4142 if(!result || (window && window.destroyed)) window = null;
4144 if(window && window.FindModal())
4147 if(trueWindow && trueWindow.FindModal())
4155 msgWindow = GetAtPosition(x,y, true, false);
4157 msgWindow.SelectMouseCursor();
4160 if(guiApp.windowCaptured || trueWindow)
4162 Window prevWindow = guiApp.prevWindow;
4163 if(guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4165 guiApp.prevWindow.mouseInside = false;
4166 guiApp.prevWindow = null;
4168 // Eventually fix this not to include captured?
4169 if(!prevWindow.OnMouseLeave(*mods))
4172 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4174 Box box = trueWindow.box;
4175 box.left += trueWindow.absPosition.x;
4176 box.right += trueWindow.absPosition.x;
4177 box.top += trueWindow.absPosition.y;
4178 box.bottom += trueWindow.absPosition.y;
4180 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4182 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4183 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4185 overX = Max(Min(overX, 32767),-32768);
4186 overY = Max(Min(overY, 32767),-32768);
4188 trueWindow.mouseInside = true;
4189 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4193 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4194 guiApp.prevWindow = trueWindow;
4196 guiApp.prevWindow = null;
4198 SelectMouseCursor();
4200 if(window && !guiApp.windowMoving && !wasMoving && !wasScrolling)
4202 int clientX = x - (window.absPosition.x + window.clientStart.x);
4203 int clientY = y - (window.absPosition.y + window.clientStart.y);
4205 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4207 clientX = Max(Min(clientX, 32767),-32768);
4208 clientY = Max(Min(clientY, 32767),-32768);
4210 MouseMethod = (void *)window._vTbl[method];
4212 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4215 if(!MouseMethod(window, clientX, clientY, *mods))
4222 if(result && w && w.clickThrough && w.parent)
4227 if(!result || !w || !w.clickThrough)
4234 // --- Mouse cursor management ---
4236 bool KeyMessage(uint method, Key key, unichar character)
4241 if(guiApp.interimWindow)
4242 this = guiApp.interimWindow;
4245 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4249 if(!style.inactive || rootWindow != this)
4251 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4252 Window modalWindow = FindModal();
4253 Window interimMaster = master ? master.rootWindow : null;
4257 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4258 status = OnSysKeyDown(key, character);
4259 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4260 status = OnSysKeyHit(key, character);
4261 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4262 status = OnSysKeyUp(key, character);
4269 // Process Key Message for Internal UI Keyboard actions
4270 if(status && !destroyed && menuBar && state != minimized)
4273 if((SmartKey)key != alt)
4274 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4277 SmartKey sk = (SmartKey) key;
4278 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4280 status = menuBar.KeyMessage(method, key, character);
4285 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4286 menuBar.OnKeyHit(escape, 0);
4288 if(!menuBar.focus && guiApp.caretOwner)
4289 guiApp.caretOwner.UpdateCaret(true, false);
4292 if(!destroyed && status)
4294 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4298 case left: case up: case right: case down:
4299 if(guiApp.windowMoving == this)
4302 int w = guiApp.windowMoving.size.w;
4303 int h = guiApp.windowMoving.size.h;
4304 int x = guiApp.windowMoving.scrolledPos.x;
4305 int y = guiApp.windowMoving.scrolledPos.y;
4309 if(key == down || key == up)
4310 step = Max(step, textCellH);
4312 step = Max(step, textCellW);
4315 if(guiApp.windowIsResizing)
4319 case left: w-=step; break;
4320 case right: w+=step; break;
4321 case up: h-=step; break;
4322 case down: h+=step; break;
4329 case left: x-=step; break;
4330 case right: x+=step; break;
4331 case up: y-=step; break;
4332 case down: y+=step; break;
4336 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4337 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4339 if(!guiApp.windowIsResizing || guiApp.resizeX)
4340 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4342 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4344 if(!guiApp.windowIsResizing || guiApp.resizeY)
4345 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4347 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4349 guiApp.interfaceDriver.SetMousePosition(x, y);
4350 ConsequentialMouseMove(true);
4358 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4360 guiApp.windowMoving.StopMoving();
4361 ConsequentialMouseMove(false);
4369 ShowSysMenu(absPosition.x, absPosition.y);
4377 if(!destroyed && status && state != minimized)
4379 // Process all the way down the children
4380 if(activeChild && !activeChild.disabled)
4382 status = activeChild.KeyMessage(method, key, character);
4384 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4385 key.code != left && key.code != right && key.code != up && key.code != down)
4387 status = activeClient.KeyMessage(method, key, character);
4391 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4393 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4394 // && defaultControl != activeChild)
4396 delete previousActive;
4397 previousActive = activeChild;
4398 if(previousActive) incref previousActive;
4400 ConsequentialMouseMove(false);
4401 if((defaultControl.active ||
4402 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4403 defaultControl.KeyMessage(method, defaultKey, character);
4409 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4411 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4418 ShowSysMenu(absPosition.x, absPosition.y);
4425 if(this != guiApp.desktop)
4427 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4429 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4431 MenuMoveOrSize(key.shift, true);
4435 else if(guiApp.windowMoving)
4437 guiApp.windowMoving.StopMoving();
4438 ConsequentialMouseMove(false);
4446 if(!destroyed && status && state != minimized)
4448 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4452 case tab: case shiftTab:
4454 Window cycleParent = this;
4455 if(this == guiApp.interimWindow && !master.style.interim && !cycleParent.style.tabCycle)
4456 cycleParent = master.parent;
4458 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4460 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4462 Window child = cycleParent.activeChild;
4464 // Scroll the window to include the active control
4466 if(cycleParent.sbh && !child.style.dontScrollHorz)
4468 if(child.scrolledPos.x < 0)
4469 cycleParent.sbh.Action(Position,
4470 cycleParent.scroll.x + child.scrolledPos.x, 0);
4471 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4472 cycleParent.sbh.Action(Position,
4473 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4475 if(cycleParent.sbv && !child.style.dontScrollVert)
4477 if(child.scrolledPos.y < 0)
4478 cycleParent.sbv.Action(Position,
4479 cycleParent.scroll.y + child.scrolledPos.y, 0);
4480 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4481 cycleParent.sbv.Action(Position,
4482 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4485 cycleParent.ConsequentialMouseMove(false);
4491 case f6: case shiftF6:
4492 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4494 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4495 if(parent == guiApp.desktop)
4496 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4506 if(CycleChildren(key.shift, true, false, true))
4514 // mIRC Style Window Shortcuts
4515 case alt1: case alt2: case alt3: case alt4: case alt5:
4516 case alt6: case alt7: case alt8: case alt9: case alt0:
4521 for(document = children.first; document; document = document.next)
4523 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4525 if(document == activeChild)
4527 if(document.state == minimized)
4528 document.SetState(normal, false, key);
4531 document.SetState(minimized, false, key);
4532 CycleChildren(false, true, false);
4537 if(activeChild.state == maximized && document.style.hasMaximize)
4538 document.SetState(maximized, false, key);
4539 else if(document.state == minimized)
4540 document.SetState(normal, false, key);
4541 document.Activate();
4556 if(!destroyed && status)
4558 if(state == minimized)
4563 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4565 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4567 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4568 previousActive.ActivateEx(true, false, false, true, null, null);
4569 delete previousActive;
4575 if(!destroyed && status)
4577 status = ProcessHotKeys(method, key, character);
4579 if(!destroyed && status && !modalWindow && state != minimized)
4582 status = KeyMethod(this, key, character);
4583 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4584 status = OnKeyHit(key, character);
4585 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4587 bool result = false;
4590 case ctrlUp: case ctrlDown:
4591 if(sbv && !guiApp.windowScrolling)
4592 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4594 case wheelUp: case wheelDown:
4595 if(sbv && !guiApp.windowScrolling)
4597 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4598 // Do we want to do a consequential move regardless of result in this case?
4599 ConsequentialMouseMove(false);
4602 case ctrlPageUp: case ctrlPageDown:
4603 if(sbh && !guiApp.windowScrolling)
4604 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4609 ConsequentialMouseMove(false);
4614 if(status && !destroyed && menuBar && state != minimized)
4615 status = menuBar.KeyMessage(method, key, character);
4617 if(style.interim && /*destroyed && */status && interimMaster)
4619 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4620 status = interimMaster.KeyMessage(method, key, character);
4627 bool ProcessHotKeys(uint method, Key key, unichar character)
4632 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4633 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4634 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4636 Window hotKeyWindow = hotKey.window;
4637 Window parent = hotKeyWindow.parent;
4638 Window prevActiveWindow = activeChild;
4640 // Don't process non-visible buttons, but make an exception for the Alt-F4 with Native Decorations turned on
4641 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1] )))
4644 if(prevActiveWindow) incref prevActiveWindow;
4645 incref hotKeyWindow;
4646 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient)
4647 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4650 delete hotKeyWindow;
4651 delete prevActiveWindow;
4655 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4656 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4657 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4659 // ********* WORKING ON THIS ***********
4660 if(prevActiveWindow && !guiApp.interimWindow)
4661 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4664 else if(hotKeyWindow.style.inactive)
4665 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4667 delete prevActiveWindow;
4668 delete hotKeyWindow;
4669 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4670 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4674 if(status && tabCycle)
4677 for(child = children.first; child; child = child.next)
4679 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4690 // --- Windows and graphics initialization / termination ---
4691 bool SetupRoot(void)
4695 // Setup relationship with outside world (bb root || !bb)
4696 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4697 (_displayDriver && dispDriver != parent.dispDriver))
4701 tempExtents = new0 Extent[4];
4706 /*if(guiApp.fullScreenMode)
4707 rootWindow = guiApp.desktop;
4709 //rootWindow = parent.created ? parent.rootWindow : null;
4710 rootWindow = parent.rootWindow;
4713 against = &parent.box;
4715 against = &parent.clientArea;
4718 for(child = children.first; child; child = child.next)
4721 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
4724 bool Setup(bool positionChildren)
4726 bool result = false;
4729 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && dispDriver != parent.dispDriver))))
4731 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
4732 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
4734 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
4736 // This was here, is it really needed?
4737 //guiApp.interfaceDriver.ActivateRootWindow(this);
4741 displaySystem = DisplaySystem {};
4742 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
4744 delete displaySystem;
4749 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData };
4750 if(display.Create(displaySystem, windowHandle))
4757 // Sometimes icon does not show up on Windows XP if we set here...
4758 // guiApp.interfaceDriver.SetIcon(this, icon);
4760 else if(this != guiApp.desktop)
4762 display = rootWindow ? rootWindow.display : null;
4768 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
4769 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
4771 for(child = children.first; child; child = child.next)
4773 if(child.created && !child.Setup(false))
4779 bool SetupDisplay(void)
4781 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
4782 if(is3D) return Window3D_SetupDisplay(this); else
4789 class_data void ** pureVTbl;
4791 bool LoadGraphics(bool creation, bool resetAnchors)
4793 bool result = false;
4794 bool success = false;
4796 WindowState stateBackup = state;
4799 if(!rootWindow.created)
4803 if(((subclass(Window))_class).pureVTbl)
4805 if(_vTbl == _class._vTbl)
4807 _vTbl = ((subclass(Window))_class).pureVTbl;
4812 for(m = 0; m < _class.vTblSize; m++)
4814 if(_vTbl[m] == _class._vTbl[m])
4815 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
4819 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
4821 if(_vTbl == ((subclass(Window))_class).pureVTbl)
4823 _vTbl = _class._vTbl;
4828 for(m = 0; m < _class.vTblSize; m++)
4830 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
4831 _vTbl[m] = _class._vTbl[m];
4836 if(guiApp.fullScreenMode || this != guiApp.desktop)
4838 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
4844 display.Lock(false);
4845 if(rootWindow == this)
4847 // Set Color Palette
4848 display.SetPalette(palette, true);
4852 if(guiApp.fullScreenMode && this == guiApp.desktop)
4857 for(c=0; c<SystemCursor::enumSize; c++)
4858 if(!guiApp.systemCursors[c].bitmap)
4860 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
4861 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
4862 if(guiApp.systemCursors[c].bitmapName)
4864 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
4865 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
4866 if(guiApp.systemCursors[c].bitmap)
4867 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
4872 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
4874 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
4875 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
4877 cursor.bitmap.paletteShades = cursor.paletteShades;
4881 guiApp.cursorUpdate = true;
4884 ConsequentialMouseMove(false);
4890 // Load Window Graphic Resources
4893 if(usedFont == setFont || usedFont == window.systemFont)
4894 RemoveResource(usedFont);
4897 RemoveResource(setFont); // TESTING setFont instead of usedFont);
4900 RemoveResource(systemFont);
4903 RemoveResource(captionFont);
4905 for(ptr = resources.first; ptr; ptr = ptr.next)
4907 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
4910 AddResource(setFont);
4912 AddResource(systemFont);
4914 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
4921 //if(master && master.font)
4922 if(parent && parent.font)
4926 faceName = parent.font.faceName,
4927 size = parent.font.size,
4928 bold = parent.font.bold,
4929 italic = parent.font.italic,
4930 underline = parent.font.underline
4932 //font = parent.font;
4933 watch(parent) { font { } };
4936 font = guiApp.currentSkin.SystemFont();
4943 captionFont = guiApp.currentSkin.CaptionFont();
4944 AddResource(captionFont);
4946 if(OnLoadGraphics())
4952 //SetScrollLineStep(sbStep.x, sbStep.y);
4954 if(this != guiApp.desktop)
4958 normalAnchor = anchor;
4959 normalSizeAnchor = sizeAnchor;
4962 // Break the anchors for moveable/resizable windows
4964 if(style.fixed && style.isDocument)
4966 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
4978 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
4979 stateSizeAnchor = SizeAnchor {};
4984 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
4989 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
4990 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
4993 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
4997 stateAnchor = normalAnchor;
4998 stateSizeAnchor = normalSizeAnchor;
5001 position = Point { };
5002 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5013 if(Position(x, y, w, h, true, false, true, true, true, true))
5015 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
5018 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
5035 success = result = true;
5038 if(!creation && result)
5040 // Load menu bar first because sys buttons are on it...
5043 if(!menuBar.LoadGraphics(false, resetAnchors))
5049 for(child = children.first; child; child = child.next)
5051 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
5058 CreateSystemChildren();
5062 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5065 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5070 //guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, caption);
5071 guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, class.name);
5074 // Do this here to avoid problems on Windows
5075 if(stateBackup == maximized)
5076 property::state = maximized;
5080 void UnloadGraphics(bool destroyWindows)
5084 // Free children's graphics
5085 for(child = children.first; child; child = child.next)
5086 child.UnloadGraphics(destroyWindows);
5089 display.Lock(false);
5092 if(guiApp.fullScreenMode && this == guiApp.desktop)
5097 for(c=0; c<SystemCursor::enumSize; c++)
5098 if(guiApp.systemCursors[c].bitmap)
5099 delete guiApp.systemCursors[c].bitmap;
5101 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5102 delete cursor.bitmap;
5104 guiApp.cursorBackground.Free();
5107 if(display && display.displaySystem)
5111 for(ptr = resources.first; ptr; ptr = ptr.next)
5115 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5120 // Free window graphics
5123 // Free skin graphics
5124 if(rootWindow == this)
5126 DisplaySystem displaySystem = display.displaySystem;
5129 display.driverData = null;
5130 display.displaySystem = null;
5134 if(displaySystem && !displaySystem.numDisplays && !is3D)
5135 delete displaySystem;
5144 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5145 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5147 if(this == guiApp.desktop || parent == guiApp.desktop)
5149 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5150 guiApp.interfaceDriver.DestroyRootWindow(this);
5154 // --- Window Hiding ---
5156 void SetVisibility(bool state)
5158 bool visible = (style.hidden || !created) ? false : state;
5159 if(visible != this.visible)
5163 this.visible = visible;
5164 for(child = children.first; child; child = child.next)
5165 child.SetVisibility(visible);
5167 ConsequentialMouseMove(false);
5168 if(parent && !nonClient) parent.OnChildVisibilityToggled(this, visible);
5172 // --- Windows and graphics initialization / termination ---
5174 bool DisplayModeChanged(void)
5176 bool result = false;
5177 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5179 guiApp.modeSwitching = true;
5180 UnloadGraphics(false);
5182 if(LoadGraphics(false, false))
5184 guiApp.modeSwitching = false;
5189 // --- Window updates system ---
5191 void UpdateDirty(Box updateBox)
5193 if(!manageDisplay) { OnRedraw(null);return; }
5196 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5199 if(display.flags.flipping)
5202 rootWindow.UpdateDisplay();
5205 UpdateBackDisplay(updateBox);
5207 if(guiApp.fullScreenMode)
5209 guiApp.cursorUpdate = true;
5210 guiApp.PreserveAndDrawCursor();
5212 if(guiApp.fullScreenMode)
5213 guiApp.RestoreCursorBackground();
5219 // This function is strictly called as a result of system window activation
5220 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5223 Window interimMaster = null;
5224 Window interimWindow = guiApp.interimWindow;
5225 if(interimWindow && interimWindow.master)
5226 interimMaster = interimWindow.master.rootWindow;
5228 if(active && state == minimized) // && (!window.nativeDecorations || window.rootWindow != window)
5229 // SetState(normal, false, 0);
5230 SetState(lastState, false, 0);
5232 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5236 /* WTH is this doing here?
5237 while(swap && swap.activeChild)
5239 swap = swap.activeChild;
5242 // TESTING THIS BEFORE...
5243 if(interimWindow && this == interimMaster)
5247 // Window interimSwap = this;
5248 Window menuBar = this.menuBar;
5249 if(menuBar && interimWindow.master == menuBar)
5252 while(interimSwap && interimSwap.activeChild)
5253 interimSwap = interimSwap.activeChild;
5255 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5256 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5258 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5259 //result = ActivateEx(true, true, false, activateRoot, window, null);
5264 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5265 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5267 if(interimWindow == this && interimMaster && !active)
5269 while(interimMaster && interimMaster.interim && interimMaster.master)
5271 // printf("Going up one master %s\n", interimMaster._class.name);
5272 interimMaster = interimMaster.master.rootWindow;
5274 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5275 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5281 bool DestroyEx(int returnCode)
5284 Timer timer, nextTimer;
5286 OldLink prevOrder = null;
5287 Window client = null;
5289 if(parent) stopwatching(parent, font);
5291 // if(window.modalSlave) return false;
5292 if(destroyed || !created)
5299 OldLink slave = master.slaves.FindLink(this);
5300 master.slaves.Delete(slave);
5303 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5309 this.returnCode = (DialogResult)returnCode;
5311 AcquireInput(false);
5316 master.hotKeys.Delete(hotKey);
5320 if(guiApp.prevWindow == this)
5322 guiApp.prevWindow = null;
5325 if(guiApp.caretOwner == this)
5327 guiApp.interfaceDriver.SetCaret(0,0,0);
5328 UpdateCaret(false, true);
5329 guiApp.caretEnabled = false;
5334 parent.childrenCycle.Remove(cycle);
5338 OldLink tmpPrev = order.prev;
5339 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5340 prevOrder = tmpPrev;
5343 client = tmpPrev ? tmpPrev.data : null;
5344 if(client == this) { client = null; break; }
5345 if(client && (client.style.hidden || client.destroyed || !client.created))
5346 tmpPrev = client.order.prev;
5350 prevOrder = tmpPrev;
5355 // If this window can be an active client, make sure the next window we activate can also be one
5356 if(!style.nonClient && style.isActiveClient)
5358 tmpPrev = prevOrder;
5361 client = tmpPrev ? tmpPrev.data : null;
5362 if(client == this) { client = null; break; }
5363 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5364 tmpPrev = client.order.prev;
5368 prevOrder = tmpPrev;
5372 if(client && client.style.hidden) client = null;
5374 // parent.childrenOrder.Remove(order);
5377 if(parent && style.isActiveClient && visible)
5379 if(state == minimized) parent.numIcons--;
5380 parent.numPositions--;
5383 // TESTING THIS HERE!
5387 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5388 // to create a window inside a rootwindow that's being destroyed)
5389 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5391 if(master && !master.destroyed /*&&
5392 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5394 if(master.defaultControl == this)
5395 master.defaultControl = null;
5397 if(parent && !parent.destroyed /*&&
5398 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5400 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5402 if(order && prevOrder && prevOrder.data != this && active)
5404 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5406 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5407 if(parent.activeClient == this)
5409 parent.activeClient = null;
5410 parent.UpdateActiveDocument(null);
5415 if(guiApp.interimWindow == this)
5418 PropagateActive(false, null, &goOn, true);
5422 //if(window.parent.activeChild == window)
5423 parent.activeChild = null;
5424 if(!style.nonClient /*&& style.isActiveClient*/)
5426 Window previous = parent.activeClient;
5427 if(style.isActiveClient)
5428 parent.activeClient = null;
5429 parent.UpdateActiveDocument(previous);
5434 else if(parent.activeClient == this)
5436 parent.activeClient = client;
5437 parent.UpdateActiveDocument(this);
5441 if(guiApp.interimWindow == this)
5443 guiApp.interimWindow = null;
5444 if(guiApp.caretOwner)
5446 Window desktop = guiApp.desktop;
5447 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5448 guiApp.caretOwner.UpdateCaret(false, false);
5453 if(_isModal && master && master.modalSlave == this)
5454 master.modalSlave = null;
5458 if(!guiApp.caretOwner && parent.caretSize)
5460 guiApp.caretOwner = parent;
5461 parent.UpdateCaret(false, false);
5462 parent.Update(null);
5465 // Why was this commented out?
5466 GetRidOfVirtualArea();
5472 dirtyArea.Free(null);
5473 dirtyBack.Free(null);
5474 scrollExtent.Free(null);
5476 /* ATTEMPTING TO MOVE THAT ABOVE
5485 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5486 for(;(child = window.children.first);)
5488 for(; child && (child.destroyed || !child.created); child = child.next);
5497 UnloadGraphics(true);
5500 delete previousActive;
5503 // statusBar = null;
5506 if(master && !master.destroyed)
5508 //master.NotifyDestroyed(this, this.returnCode);
5509 NotifyDestroyed(master, this, this.returnCode);
5512 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5514 nextTimer = timer.next;
5515 if(timer.window == this)
5517 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5518 // timer.window = null;
5524 if(this == guiApp.windowMoving)
5527 if(guiApp.windowCaptured == this)
5529 //guiApp.windowCaptured = null;
5531 if(rootWindow != this && rootWindow)
5532 rootWindow.ConsequentialMouseMove(false);
5540 //for(child = children.first; next = child ? child.next : null, child; child = next)
5541 for(;(child = children.first); )
5543 for(; child && (child.destroyed || !child.created); child = child.next);
5553 /* // MOVED THIS UP...
5556 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5557 for(;(child = window.children.first); )
5559 for(; child && (child.destroyed || !child.created); child = child.next);
5568 while((slave = slaves.first))
5570 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5572 ((Window)slave.data).DestroyEx(0);
5577 if(guiApp.caretOwner == this)
5578 guiApp.caretOwner = null;
5580 sysButtons[0] = null;
5581 sysButtons[1] = null;
5582 sysButtons[2] = null;
5585 if(rootWindow != this)
5587 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5590 box.left -= parent.clientStart.x;
5591 box.top -= parent.clientStart.y;
5592 box.right -= parent.clientStart.x;
5593 box.bottom -= parent.clientStart.y;
5595 if(parent) parent.Update(box);
5600 OldLink slave = master.slaves.FindVoid(this);
5601 master.slaves.Delete(slave);
5607 parent.children.Remove(this);
5612 //autoCreate = false;
5615 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5616 if(((subclass(Window))_class).pureVTbl)
5618 if(_vTbl == _class._vTbl)
5620 _vTbl = ((subclass(Window))_class).pureVTbl;
5625 for(m = 0; m < _class.vTblSize; m++)
5627 if(_vTbl[m] == _class._vTbl[m])
5628 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5637 void SetStateEx(WindowState newState, bool activate)
5640 WindowState prevState = state;
5644 if(prevState != newState)
5645 lastState = prevState;
5647 if(rootWindow != this || !nativeDecorations || !windowHandle)
5649 if(style.isActiveClient && !style.hidden && prevState == minimized)
5652 // This block used to be at the end of the function... moved it for flicker problem in X
5653 // ------------------------------------------------------
5657 stateAnchor = normalAnchor;
5658 stateSizeAnchor = normalSizeAnchor;
5661 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5662 stateSizeAnchor = SizeAnchor {};
5666 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5669 byte * idBuffer = new0 byte[size];
5671 for(child = parent.children.first; child; child = child.next)
5673 if(child != this && child.state == minimized)
5675 if(child.iconID > size - 2)
5677 idBuffer = renew0 idBuffer byte[size*2];
5678 memset(idBuffer + size, 0, size);
5681 idBuffer[child.iconID] = (byte)bool::true;
5684 for(c = 0; c<size; c++)
5689 if(style.isActiveClient && !style.hidden)
5692 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5693 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5697 // TOCHECK: Why was this here?
5698 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5699 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5700 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5702 Position(x, y, w, h, true, true, true, true, false, true);
5704 if(!style.inactive && !style.interim && this == parent.activeClient)
5705 parent.UpdateActiveDocument(null);
5708 CreateSystemChildren();
5709 // ------------------------------------------------------
5712 int GetPositionID(Window forChild)
5716 byte * idBuffer = new0 byte[size];
5719 for(child = children.first; child; child = child.next)
5721 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
5723 if(child.positionID > size - 2)
5725 idBuffer = renew0 idBuffer byte[size*2];
5726 memset(idBuffer + size, 0, size);
5729 idBuffer[child.positionID] = (byte)bool::true;
5732 for(c = 0; c<size; c++)
5739 // --- Window related graphics ---
5741 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
5743 palette = newPalette;
5744 if(rootWindow.display)
5745 rootWindow.display.SetPalette(palette, colorMatch);
5748 public bool AcquireInput(bool acquired)
5751 if(acquiredInput != acquired)
5753 if(active || (!visible && creationActivation == activate))
5754 result = AcquireInputEx(acquired);
5759 acquiredInput = acquired ? result : !result;
5764 void ListChildren(ListBox listBox)
5768 for(child = children.first; child; child = child.next)
5770 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
5772 DataRow row = listBox.AddRow();
5773 row.tag = (int)child;
5774 child.FigureCaption(caption);
5775 row.SetData(null, caption);
5780 void UpdateVisual(Box extent)
5782 if(guiApp.driver != null)
5784 if(guiApp.fullScreenMode && guiApp.desktop.display)
5786 guiApp.desktop.mutex.Wait();
5787 guiApp.desktop.display.Lock(true);
5790 if(guiApp.desktop.active)
5792 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
5794 if(guiApp.desktop.display.flags.flipping)
5795 guiApp.desktop.Update(null);
5796 guiApp.desktop.UpdateDisplay();
5797 guiApp.cursorUpdate = true;
5799 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
5801 guiApp.PreserveAndDrawCursor();
5802 // guiApp.desktop.display.ShowScreen();
5803 guiApp.cursorUpdate = false;
5804 guiApp.desktop.dirty = false;
5805 guiApp.RestoreCursorBackground();
5809 guiApp.desktop.display.Unlock();
5810 guiApp.desktop.mutex.Release();
5814 Window rootWindow = this.rootWindow;
5815 rootWindow.mutex.Wait();
5820 guiApp.SignalEvent();
5823 guiApp.waitMutex.Wait();
5824 guiApp.interfaceDriver.Lock(rootWindow);
5825 if(!rootWindow.style.hidden && rootWindow.dirty)
5827 if(rootWindow.display)
5829 rootWindow.UpdateDisplay();
5830 //rootWindow.display.ShowScreen(null);
5832 rootWindow.dirty = false;
5834 guiApp.interfaceDriver.Unlock(rootWindow);
5835 guiApp.waitMutex.Release();
5838 rootWindow.mutex.Release();
5843 void UnlockDisplay(void)
5845 guiApp.interfaceDriver.Unlock(rootWindow);
5848 void LockDisplay(void)
5850 guiApp.interfaceDriver.Lock(rootWindow);
5853 Surface GetSurface(Box box)
5855 return Redraw((box == null) ? this.box : box);
5858 void SetMousePosition(int x, int y)
5860 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
5864 void IntegrationActivate(bool active)
5866 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
5868 isForegroundWindow = true;
5869 ActivateEx(active, active, false, false, null, null);
5870 isForegroundWindow = false;
5875 Window QueryCapture(void)
5877 return guiApp.windowCaptured;
5880 int GetDocumentID(void)
5884 byte * idBuffer = new0 byte[size];
5887 for(child = children.first; child; child = child.next)
5889 // TO CHECK: Do we want a documentID when we already have a file name?
5890 if(child.style.isDocument && !child.fileName)
5892 if(child.documentID-1 > size - 2)
5894 idBuffer = renew0 idBuffer byte[size*2];
5895 memset(idBuffer + size, 0, size);
5898 idBuffer[child.documentID-1] = 1;
5901 for(c = 0; c<size; c++)
5909 void SetInitSize(Size size)
5912 sizeAnchor.size = size;
5913 normalSizeAnchor = sizeAnchor;
5915 // Break the anchors for moveable/resizable windows
5916 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
5918 stateAnchor = normalAnchor;
5919 stateSizeAnchor = normalSizeAnchor;
5921 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5922 Position(x,y, w, h, true, true, true, true, false, true);
5926 void MenuMoveOrSize(bool resize, bool setCursorPosition)
5928 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
5930 guiApp.windowIsResizing = resize;
5931 guiApp.windowMoving = this;
5932 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
5933 if(guiApp.windowIsResizing)
5935 guiApp.windowMovingStart.x += size.w - 1;
5936 guiApp.windowMovingStart.y += size.h - 1;
5938 guiApp.windowMovingBefore = scrolledPos;
5939 guiApp.windowResizingBefore = size;
5940 guiApp.windowMoving.UpdateDecorations();
5941 if(guiApp.windowIsResizing)
5942 guiApp.resizeEndX = guiApp.resizeEndY = true;
5944 if(setCursorPosition)
5945 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
5949 guiApp.interfaceDriver.GetMousePosition(&x, &y);
5950 guiApp.windowMovingStart.x += x - absPosition.x;
5951 guiApp.windowMovingStart.y += y - absPosition.y;
5954 if(guiApp.windowMoving)
5956 if(guiApp.windowMoving.style.nonClient)
5957 guiApp.windowMoving.parent.SetMouseRangeToWindow();
5959 guiApp.windowMoving.parent.SetMouseRangeToClient();
5964 if(this == rootWindow)
5965 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
5973 bool result = false;
5977 else if(guiApp && guiApp.driver != null)
5979 void * systemParent = null;
5980 OldLink slaveHolder;
5982 bool visible = !style.hidden;
5986 systemParent = parent;
5987 parent = guiApp.desktop;
5989 last = parent ? parent.children.last : null;
5991 if((parent && parent != guiApp.desktop && !parent.created) ||
5992 (master && master != guiApp.desktop && !master.created))
5996 property::parent = guiApp.desktop;
5997 if(!master) master = parent;
5999 if(_isModal && master.modalSlave)
6000 property::master = master.modalSlave;
6004 parent.children.Remove(this);
6007 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
6008 if(slaveHolder.data == this)
6010 master.slaves.Delete(slaveHolder);
6015 if(parent == guiApp.desktop && !mutex)
6018 if(style.isDocument)
6021 parent.numDocuments--;
6022 documentID = parent.GetDocumentID();
6025 if(!style.stayOnTop)
6026 for(; last && last.style.stayOnTop; last = last.prev);
6028 parent.children.Insert((last == this) ? null : last, this);
6029 //parent.children.Add(this);
6032 dispDriver = parent.dispDriver;
6035 master.modalSlave = this;
6037 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
6042 master.slaves.Add(slaveHolder = OldLink { data = this });
6047 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
6049 if(style.isDefault && !master.defaultControl)
6050 master.defaultControl = this;
6052 stateAnchor = normalAnchor = anchor;
6053 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
6055 // TOCHECK: Why is this here?
6056 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
6057 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
6059 this.visible = false;
6060 style.hidden = true;
6063 // autoCreate = true;
6071 if(parent == guiApp.desktop)
6072 Log("LoadGraphics %s\n", caption);
6074 if(LoadGraphics(true, false))
6082 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6089 if(style.hasMenuBar /*&& menu*/)
6095 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6096 interim = false, inactive = true, nonClient = true, size.h = 24
6104 // Create the system buttons
6105 CreateSystemChildren();
6107 UpdateActiveDocument(null);
6109 if(style.isDocument)
6113 MenuItem item = menu.FindItem(MenuFileSave, 0);
6114 if(item) item.disabled = !modifiedDocument && fileName;
6119 if(parent == guiApp.desktop)
6120 Log("Preemptive SetState %s\n", caption);
6123 // Preemptive Set State to ensure proper anchoring
6124 SetStateEx(state, false);
6126 style.hidden = true;
6132 for(child = children.first; child; child = next)
6135 if(!child.created && (child.autoCreate || child.wasCreated))
6142 for(link = slaves.first; link; link = next)
6144 Window slave = link.data;
6146 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6149 // Things might have happened that invalidated 'next'...
6150 // Start over the search for slaves to create.
6151 // (Added this to fix crash with Stacker & Toolbar)
6152 next = slaves.first;
6161 if(parent == guiApp.desktop)
6162 Log("Real SetState %s\n", caption);
6165 if(isActiveClient && visible)
6167 parent.numPositions--;
6168 if(state == minimized) parent.numIcons--;
6171 // Real set state & activate for proper display & activation
6172 property::visible = visible;
6173 // SetState(state & 0x00000003, true, 0);
6174 guiApp.interfaceDriver.SetIcon(this, icon);
6179 /*if(rootWindow == this)
6180 guiApp.interfaceDriver.ActivateRootWindow(this);
6182 if(creationActivation == activate)
6183 ActivateEx(true, false, true, true, null, null);
6184 else if(creationActivation == flash)
6189 rootWindow.ConsequentialMouseMove(false);
6200 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6206 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6208 //style.hidden = true; // !visible;
6209 style.hidden = !visible;
6210 if(master.modalSlave == this)
6211 master.modalSlave = null;
6218 void WriteCaption(Surface surface, int x, int y)
6221 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6224 void Update(Box region)
6230 rootWindow = this.rootWindow;
6232 // rootWindow.mutex.Wait();
6233 if(!destroyed && visible && display)
6238 // Testing this to avoid repetitve full update to take time...
6239 if(dirtyArea.count == 1)
6241 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6242 if(item.box.left <= box.left &&
6243 item.box.top <= box.top &&
6244 item.box.right >= box.right &&
6245 item.box.bottom >= box.bottom)
6247 rootWindow.dirty = true;
6252 if(display.flags.flipping && !rootWindow.dirty)
6254 if(this == rootWindow)
6258 rootWindow.Update(null);
6263 rootWindow.dirty = true;
6268 realBox.left += clientStart.x;
6269 realBox.top += clientStart.y;
6270 realBox.right += clientStart.x;
6271 realBox.bottom += clientStart.y;
6277 if(realBox.right >= realBox.left &&
6278 realBox.bottom >= realBox.top)
6280 // if(!rootWindow.fullRender)
6281 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6283 for(child = children.first; child; child = child.next)
6288 box.left -= child.absPosition.x - absPosition.x;
6289 box.top -= child.absPosition.y - absPosition.y;
6290 box.right -= child.absPosition.x - absPosition.x;
6291 box.bottom -= child.absPosition.y - absPosition.y;
6292 if(box.right >= child.box.left && box.left <= child.box.right &&
6293 box.bottom >= child.box.top && box.top <= child.box.bottom)
6295 box.left -= child.clientStart.x;
6296 box.top -= child.clientStart.y;
6297 box.right -= child.clientStart.x;
6298 box.bottom -= child.clientStart.y;
6304 realBox.left += absPosition.x - rootWindow.absPosition.x;
6305 realBox.top += absPosition.y - rootWindow.absPosition.y;
6306 realBox.right += absPosition.x - rootWindow.absPosition.x;
6307 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6308 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6311 else if(this == guiApp.desktop)
6314 for(window = children.first; window; window = window.next)
6320 Box childBox = region;
6322 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6323 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6324 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6325 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6327 window.Update(childBox);
6330 window.Update(null);
6335 // rootWindow.mutex.Release();
6342 if(guiApp.windowCaptured != this)
6344 if(guiApp.windowCaptured)
6348 //Logf("Captured %s (%s)\n", caption, class.name);
6349 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6350 guiApp.windowCaptured = this;
6356 bool Destroy(int code)
6361 if(!destroyed && !CloseConfirmation(false)) return false;
6365 // TOCHECK: Should autoCreate be set to false here?
6376 void Move(int x, int y, int w, int h)
6378 normalAnchor = Anchor { left = x, top = y };
6379 normalSizeAnchor = SizeAnchor { size = { w, h } };
6381 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6383 if(destroyed) return;
6385 stateAnchor = normalAnchor;
6386 stateSizeAnchor = normalSizeAnchor;
6388 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6389 Position(x,y, w, h, true, true, true, true, false, true);
6393 DialogResult Modal(void)
6399 // FIXES MEMORY LEAK IF Create() FAILED
6405 void SetScrollArea(int width, int height, bool snapToStep)
6407 bool resize = false;
6410 int stepX = sbStep.x, stepY = sbStep.y;
6411 // Needed to make snapped down position match the skin's check of client area
6412 // against realvirtual
6415 SNAPDOWN(stepX, textCellW);
6416 SNAPDOWN(stepY, textCellH);
6417 stepX = Max(stepX, textCellW);
6418 stepY = Max(stepY, textCellH);
6420 if(scrollFlags.snapX)
6421 SNAPUP(width, stepX);
6422 if(scrollFlags.snapY)
6423 SNAPUP(height, stepY);
6426 reqScrollArea.w = width;
6427 reqScrollArea.h = height;
6428 noAutoScrollArea = (width > 0 || height > 0);
6430 UpdateScrollBars(true, true);
6433 void SetScrollPosition(int x, int y)
6436 sbh.Action(setPosition, x, 0);
6440 int seen = clientSize.w, total = reqScrollArea.w;
6442 if(scrollFlags.snapX)
6443 SNAPDOWN(seen, sbStep.x);
6445 if(!total) total = seen;
6446 range = total - seen + 1;
6447 range = Max(range, 1);
6449 if(x >= range) x = range - 1;
6451 if(scrollFlags.snapX)
6452 SNAPUP(x, sbStep.x);
6455 OnHScroll(setPosition, x, 0);
6459 SNAPDOWN(x, textCellW);
6465 sbv.Action(setPosition, y, 0);
6469 int seen = clientSize.h, total = reqScrollArea.h;
6472 if(scrollFlags.snapY)
6473 SNAPDOWN(seen, sbStep.y);
6475 if(!total) total = seen;
6476 range = total - seen + 1;
6477 range = Max(range, 1);
6479 if(y >= range) y = range - 1;
6481 if(scrollFlags.snapY)
6482 SNAPUP(y, sbStep.y);
6485 OnVScroll(setPosition, y, 0);
6488 SNAPDOWN(y, textCellH);
6493 UpdateCaret(false, false);
6496 void SetScrollLineStep(int stepX, int stepY)
6502 SNAPDOWN(stepX, textCellW);
6503 SNAPDOWN(stepY, textCellH);
6504 stepX = Max(stepX, textCellW);
6505 stepY = Max(stepY, textCellH);
6508 sbh.lineStep = stepX;
6510 sbv.lineStep = stepY;
6513 void SetState(WindowState newState, bool activate, Modifiers mods)
6517 if(state == newState || OnStateChange(newState, mods))
6519 WindowState prevState = state;
6523 // This used to be at the end of the brackets... moved for X, testing...
6524 // This has the effect of activating the window through the system...
6525 if(rootWindow == this)
6526 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6528 SetStateEx(newState, activate);
6530 if(rootWindow == this && !rootWindow.nativeDecorations)
6532 int x = position.x, y = position.y;
6535 x -= guiApp.desktop.absPosition.x;
6536 y -= guiApp.desktop.absPosition.y;
6538 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6542 //state = prevState;
6544 if(state != maximized && style.hasMaximize)
6547 for(child = parent.children.first; child; child = child.next)
6549 if(child != this && child.state == maximized)
6550 child.SetStateEx(normal, false);
6554 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6555 parent.UpdateScrollBars(true, true);
6558 // Do we really need this stuff here?
6559 // Shouldn't the Activate stuff take care of it?
6560 if(parent.rootWindow == parent && style)
6563 parent.FigureCaption(caption);
6564 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6565 parent.UpdateDecorations();
6569 rootWindow.ConsequentialMouseMove(false);
6576 BitmapResource GetIcon(SkinBitmap iconID)
6578 return guiApp.currentSkin.GetBitmap(iconID);
6581 void SetMouseRange(Box range)
6583 if(range || guiApp.fullScreenMode)
6588 clip.left = range.left + absPosition.x + clientStart.x;
6589 clip.top = range.top + absPosition.y + clientStart.y;
6590 clip.right = range.right + absPosition.x + clientStart.x;
6591 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6595 clip.left = guiApp.desktop.box.left;
6596 clip.top = guiApp.desktop.box.top;
6597 clip.right = guiApp.desktop.box.right;
6598 clip.bottom = guiApp.desktop.box.bottom;
6600 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6603 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6606 void SetMouseRangeToClient(void)
6608 if(guiApp.fullScreenMode || this != guiApp.desktop)
6610 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6611 box.Clip(clientArea);
6615 SetMouseRange(null);
6618 void SetMouseRangeToWindow(void)
6620 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6621 if(this == guiApp.desktop)
6622 SetMouseRangeToClient();
6627 // x, y: Desktop Coordinates
6628 void ShowSysMenu(int x, int y)
6631 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6634 menu, $"Restore", r, NotifySelect = MenuWindowRestore,
6635 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6639 menu, $"Move", m, NotifySelect = MenuWindowMove,
6640 disabled = !style.fixed || state == maximized
6644 menu, $"Size", s, NotifySelect = MenuWindowSize,
6645 disabled = !style.sizable || state != normal
6649 menu, $"Minimize", n, NotifySelect = MenuWindowMinimize,
6650 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6654 menu, $"Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6655 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6659 menu, $"Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6660 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6662 MenuDivider { menu };
6665 menu, $"Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6666 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6668 windowMenu.Create();
6673 ActivateEx(true, true, true, true, null, null);
6676 void MakeActive(void)
6678 ActivateEx(true, false, true, false, null, null);
6681 void SoftActivate(void)
6683 if(guiApp.desktop.active)
6689 void Deactivate(void)
6691 ActivateEx(false, true, true, true, null, null);
6696 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
6699 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
6701 bool result = false;
6702 if(activeChild && activeChild.cycle)
6704 Window modalWindow, child = activeChild;
6705 if(!clientOnly /*&& parent.tabCycle*/)
6707 Window next = child;
6710 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
6714 if(parent && parent.CycleChildren(backward, false, true, true))
6722 next = next.cycle.prev.data;
6724 next = next.cycle.next.data;
6725 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
6730 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
6731 parent.tabCycle && parent.CycleChildren(backward, false, false))
6735 if(tabCycleOnly && !tabCycle) return false;
6742 child = child.cycle.prev.data;
6744 child = child.cycle.next.data;
6745 if(child == child.parent.activeChild)
6747 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
6750 modalWindow = child.FindModal();
6753 // Scroll the window to include the active control
6754 if(sbh && !child.style.dontScrollHorz)
6756 if(child.scrolledPos.x < 0)
6757 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
6758 else if(child.scrolledPos.x + child.size.w > clientSize.w)
6759 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
6761 if(sbv && !child.style.dontScrollVert)
6763 if(child.scrolledPos.y < 0)
6764 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
6765 else if(child.scrolledPos.y + child.size.h > clientSize.h)
6766 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
6770 child = modalWindow ? modalWindow : child;
6771 child.ActivateEx(true, true, true, true, null, null);
6772 if(child.tabCycle && child.childrenCycle.first)
6773 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
6781 ConsequentialMouseMove(false);
6785 void AddResource(Resource resource)
6789 ResPtr ptr { resource = resource };
6793 // Load Graphics here if window is created already
6794 if(/*created && */display)
6796 display.Lock(false);
6797 ptr.loaded = display.displaySystem.LoadResource(resource);
6801 // Temporary hack to load font right away for listbox in dropbox ...
6802 else if(master && master.display)
6804 master.display.Lock(false);
6805 master.display.displaySystem.LoadResource(resource);
6806 master.display.Unlock();
6812 void RemoveResource(Resource resource)
6817 for(ptr = resources.first; ptr; ptr = ptr.next)
6819 if(ptr.resource == resource)
6825 // Unload Graphics here if window is created already
6826 if(/*created && */display)
6830 display.Lock(false);
6831 display.displaySystem.UnloadResource(resource, ptr.loaded);
6837 resources.Delete(ptr);
6842 void SetCaret(int x, int y, int size)
6849 if(active && !style.interim)
6851 if(visible || !guiApp.caretOwner)
6852 guiApp.caretOwner = size ? this : null;
6854 UpdateCaret(false, false);
6857 guiApp.interfaceDriver.SetCaret(0,0,0);
6858 UpdateCaret(false, true);
6859 guiApp.caretEnabled = false;
6862 else if(style.inactive && active)
6864 guiApp.interfaceDriver.SetCaret(0,0,0);
6865 UpdateCaret(false, true);
6866 guiApp.caretEnabled = false;
6871 void Scroll(int x, int y)
6873 bool opaque = !style.drawBehind || background.a;
6874 if(opaque && display && display.flags.scrolling)
6876 Box box = clientArea;
6877 box.left += clientStart.x;
6878 box.top += clientStart.y;
6879 box.right += clientStart.x;
6880 box.bottom += clientStart.y;
6882 //scrollExtent.Free(null);
6883 scrollExtent.AddBox(box);
6884 scrolledArea.x += x;
6885 scrolledArea.y += y;
6887 //scrollExtent.Free();
6888 //scrollExtent.AddBox(clientArea);
6889 //scrollExtent.Offset(clientStart.x, clientStart.y);
6890 //scrolledArea.x = x;
6891 //scrolledArea.y = y;
6897 rootWindow.dirty = true;
6900 void ReleaseCapture()
6902 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
6904 Window oldCaptured = guiApp.windowCaptured;
6905 guiApp.windowCaptured = null;
6906 guiApp.prevWindow = null;
6909 //guiApp.Log("Released Capture\n");
6911 guiApp.interfaceDriver.SetMouseCapture(null);
6913 //oldCaptured.OnMouseCaptureLost();
6916 oldCaptured.ConsequentialMouseMove(false);
6921 void SetText(char * format, ...)
6928 char caption[MAX_F_STRING];
6930 va_start(args, format);
6931 vsprintf(caption, format, args);
6934 this.caption = new char[strlen(caption)+1];
6936 strcpy(this.caption, caption);
6945 bool Grab(Bitmap bitmap, Box box, bool decorations)
6947 bool result = false;
6948 if(display || this == guiApp.desktop)
6950 Box clip = {MININT, MININT, MAXINT, MAXINT};
6956 clip.Clip(clientArea);
6958 clip.Clip(this.box);
6960 if(rootWindow != this)
6962 clip.left += absPosition.y;
6963 clip.top += absPosition.y;
6964 clip.right += absPosition.x;
6965 clip.bottom += absPosition.y;
6968 clip.left += decorations ? 0 : clientStart.x;
6969 clip.top += decorations ? 0 : clientStart.y;
6970 clip.right += decorations ? 0 : clientStart.x;
6971 clip.bottom += decorations ? 0 : clientStart.y;
6973 if(display && display.flags.flipping)
6975 rootWindow.Update(null);
6976 rootWindow.UpdateDisplay();
6983 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
6984 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6988 result = display.Grab(bitmap, clip.left, clip.top,
6989 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6991 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
6993 if(!bitmap.Convert(null, pixelFormat888, null))
7000 void GetMousePosition(int * x, int * y)
7002 int mouseX = 0, mouseY = 0;
7003 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
7006 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
7007 if(this != guiApp.desktop)
7009 mouseX -= absPosition.x + clientStart.x;
7010 mouseY -= absPosition.y + clientStart.y;
7017 DialogResult DoModal()
7019 DialogResult returnCode = 0;
7020 int terminated = terminateX;
7023 while(!destroyed && guiApp.driver != null)
7025 if(terminateX != terminated)
7027 terminated = terminateX;
7028 guiApp.desktop.Destroy(0);
7029 if(guiApp.desktop.created)
7032 //printf("Resetting terminate X to 0\n");
7038 guiApp.UpdateDisplay();
7039 if(!guiApp.ProcessInput(false))
7042 returnCode = this.returnCode;
7055 return !destroyed && guiApp.driver != null && terminateX < 2;
7058 DialogResult DoModalEnd()
7060 DialogResult returnCode = this.returnCode;
7065 // --- Window manipulation ---
7066 /*bool GetDisabled()
7068 bool disabled = this.disabled;
7070 for(window = this; (window = window.master); )
7081 // --- Mouse Manipulation ---
7082 void GetNCMousePosition(int * x, int * y)
7084 GetMousePosition(x, y);
7085 if(x) *x += clientStart.x;
7086 if(y) *y += clientStart.y;
7089 // --- Carets manipulation ---
7090 void GetCaretPosition(Point caretPos)
7092 caretPos = this.caretPos;
7095 int GetCaretSize(void)
7100 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7106 bool CloseConfirmation(bool parentClosing)
7119 if(!OnClose(parentClosing))
7122 // If you want to skip this, simply set modifiedDocument to false in OnClose
7123 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7125 DialogResult dialogRes;
7128 sprintf(message, $"Save changes to %s?", fileName);
7130 sprintf(message, $"Save changes to Untitled %d?", documentID);
7132 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption ? parent.caption : rootWindow.caption, contents = message }.Modal();
7134 if(dialogRes == yes)
7136 // TOFIX: Precomp error if brackets are taken out
7137 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7139 else if(dialogRes == cancel)
7145 for(slave = slaves.first; slave; slave = slave.next)
7147 Window w = slave.data;
7148 if((w.parent == this || !w.IsDescendantOf(this)) && !w.CloseConfirmation(true))
7150 // ((Window)slave.data).CloseConfirmation(true);
7159 for(child = children.first; child; child = child.next)
7160 if(child.master != this && !child.CloseConfirmation(true))
7170 // Static methods... move them somewhere else?
7171 void ::RestoreCaret()
7173 if(guiApp.caretOwner)
7174 guiApp.caretOwner.UpdateCaret(false, false);
7177 void ::FreeMouseRange()
7179 guiApp.interfaceDriver.SetMouseRange(null, null);
7183 bool MenuFileClose(MenuItem selection, Modifiers mods)
7185 Window document = activeChild;
7187 document.Destroy(0);
7191 bool MenuFileExit(MenuItem selection, Modifiers mods)
7197 bool MenuFileSave(MenuItem selection, Modifiers mods)
7201 fileMonitor.fileName = null;
7204 if(OnSaveFile(fileName))
7206 //if(OnFileModified != Window::OnFileModified)
7209 fileMonitor.fileName = fileName;
7215 MessageBox dialog { master = master, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7216 DialogResult answer = dialog.Modal();
7218 if(answer != yes) return (bool)answer;
7221 return MenuFileSaveAs(selection, mods);
7224 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7226 DialogResult result = (DialogResult)bool::true;
7227 FileDialog fileDialog = saveDialog;
7230 fileDialog = FileDialog {};
7235 fileDialog.filePath = fileName;
7238 char filePath[MAX_FILENAME];
7239 sprintf(filePath, "Untitled %d", documentID);
7240 fileDialog.filePath = filePath;
7242 fileMonitor.fileName = null;
7244 fileDialog.type = save;
7245 fileDialog.text = $"Save As";
7249 fileDialog.master = master.parent ? master : this;
7250 if(fileDialog.Modal() == ok)
7252 char * filePath = fileDialog.filePath;
7254 if(OnSaveFile(filePath))
7257 property::fileName = filePath;
7258 NotifySaved(master, this, filePath);
7263 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = $"Error writing file", contents = $"Save as a different file?" };
7264 DialogResult answer = dialog.Modal();
7279 //if(OnFileModified != Window::OnFileModified && fileName)
7282 fileMonitor.fileName = fileName;
7286 return (bool)result; // Actually returning result from Yes/NoCancel message box
7289 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7291 Window document = activeChild;
7293 for(document = children.first; document; document = next)
7295 next = document.next;
7296 if(document.style.isDocument || document.fileName)
7297 document.MenuFileSave(selection, mods);
7302 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7306 for(document = children.first; document; document = document.next)
7307 //if(document.style.isDocument && document.state == minimized)
7308 if(document.style.isActiveClient && document.state == minimized)
7309 document.SetState(minimized, false, mods);
7313 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7315 Window document = activeChild;
7318 Window firstDocument = null;
7320 OldLink cycle = document.cycle.prev;
7325 if(child.style.isActiveClient && !child.style.hidden)
7329 firstDocument = child;
7330 if(child.state == minimized)
7331 child.SetState(minimized, false, mods);
7334 child.positionID = id++;
7335 child.SetState(normal, false, mods);
7336 child.anchor.left.type = cascade;
7339 child.normalSizeAnchor = *&child.sizeAnchor;
7340 child.normalAnchor = child.anchor;
7342 // Break the anchors for moveable/resizable windows
7343 if(child.style.fixed)
7345 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7347 (*&child.normalAnchor).left = x;
7348 (*&child.normalAnchor).top = y;
7349 (*&child.normalAnchor).right.type = none;
7350 (*&child.normalAnchor).bottom.type = none;
7352 child.normalSizeAnchor.isClientW = false;
7353 child.normalSizeAnchor.isClientH = false;
7354 child.normalSizeAnchor.size.w = w;
7355 child.normalSizeAnchor.size.h = h;
7356 child.anchored = false;
7359 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7361 child.stateAnchor = child.normalAnchor;
7362 child.stateSizeAnchor = child.normalSizeAnchor;
7364 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7365 child.Position(x, y, w, h, true, true, true, true, false, false);
7370 last = children.last;
7371 if(!child.style.stayOnTop)
7372 for(; last && last.style.stayOnTop; last = last.prev);
7373 children.Move(child, last);
7374 childrenOrder.Move(child.order, childrenOrder.last);
7376 if(cycle == document.cycle) break;
7380 firstDocument.Activate();
7385 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7392 // Close all closes all active clients, not all documents
7393 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7395 Window next, document;
7397 for(document = children.first; document; document = next)
7399 for(next = document.next; next && !(next.style.isActiveClient; next = next.next);
7400 if(document.style.isActiveClient)
7401 if(!document.Destroy(0) && !document.style.hidden)
7407 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7409 if(style.hasMaximize && state != maximized)
7410 SetState(maximized, 0, 0);
7414 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7416 if(style.hasMinimize && state != minimized)
7418 SetState(minimized, 0, 0);
7419 parent.CycleChildren(false, true, false, true);
7424 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7426 MenuMoveOrSize(false, selection ? true : false);
7430 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7432 CycleChildren(false, true, false, true);
7436 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7438 CycleChildren(true, true, false, true);
7442 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7444 MenuMoveOrSize(true, true);
7448 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7451 SetState(normal, 0, 0);
7455 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7458 int id = selection.id;
7459 OldLink cycle = activeClient.cycle;
7461 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7464 Window sibling = cycle.data;
7465 if(sibling.style.isActiveClient && sibling.visible && !sibling.style.nonClient)
7473 document = cycle.data;
7474 document.Activate();
7476 //if(activeChild.state == maximized)
7477 // document.SetState(maximized, false, mods);
7478 //else if(document.state == minimized)
7479 // document.SetState(normal, false, mods);
7483 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7485 stayOnTop = !style.stayOnTop;
7489 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7491 Window document = activeChild;
7494 Window firstDocument = null;
7495 OldLink cycle = document.cycle;
7499 Window child = cycle.data;
7500 if(child.style.isActiveClient && !child.style.hidden)
7502 if(!firstDocument) firstDocument = child;
7503 if(child.state == minimized)
7504 child.SetState(minimized, false, mods);
7507 child.positionID = id++;
7508 child.SetState(normal, false, mods);
7509 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7511 child.anchor.left.type = hTiled;
7514 child.normalSizeAnchor = *&child.sizeAnchor;
7515 child.normalAnchor = child.anchor;
7517 // Break the anchors for moveable/resizable windows
7518 if(child.style.fixed)
7520 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7522 (*&child.normalAnchor).left = x;
7523 (*&child.normalAnchor).top = y;
7524 (*&child.normalAnchor).right.type = none;
7525 (*&child.normalAnchor).bottom.type = none;
7526 child.normalSizeAnchor.isClientW = false;
7527 child.normalSizeAnchor.isClientH = false;
7528 child.normalSizeAnchor.size.w = w;
7529 child.normalSizeAnchor.size.h = h;
7530 child.anchored = false;
7533 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7535 child.stateAnchor = child.normalAnchor;
7536 child.stateSizeAnchor = child.normalSizeAnchor;
7538 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7539 child.Position(x,y, w, h, true, true, true, true, false, true);
7544 if((cycle = cycle.next) == document.cycle) break;
7547 firstDocument.Activate();
7552 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7554 Window document = activeChild;
7557 Window firstDocument = null;
7559 OldLink cycle = document.cycle;
7564 //if(child.style.isDocument)
7565 if(child.style.isActiveClient && !child.style.hidden)
7567 if(!firstDocument) firstDocument = child;
7568 if(child.state == minimized)
7569 child.SetState(minimized, false, mods);
7572 child.positionID = id++;
7573 child.SetState(normal, false, mods);
7574 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7576 child.anchor.left.type = vTiled;
7579 child.normalSizeAnchor = *&child.sizeAnchor;
7580 child.normalAnchor = child.anchor;
7582 // Break the anchors for moveable/resizable windows
7583 if(child.style.fixed)
7585 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7587 (*&child.normalAnchor).left = x;
7588 (*&child.normalAnchor).top = y;
7589 (*&child.normalAnchor).right.type = none;
7590 (*&child.normalAnchor).bottom.type = none;
7591 child.normalSizeAnchor.isClientW = false;
7592 child.normalSizeAnchor.isClientH = false;
7593 child.normalSizeAnchor.size.w = w;
7594 child.normalSizeAnchor.size.h = h;
7595 child.anchored = false;
7598 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7600 child.stateAnchor = child.normalAnchor;
7601 child.stateSizeAnchor = child.normalSizeAnchor;
7603 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7604 child.Position(x,y, w, h, true, true, true, true, false, true);
7609 if((cycle = cycle.next) == document.cycle) break;
7612 firstDocument.Activate();
7617 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7619 WindowList dialog { master = this };
7620 Window document = (Window)dialog.Modal();
7623 if(activeChild.state == maximized)
7624 document.SetState(maximized, false, mods);
7625 else if(document.state == minimized)
7626 document.SetState(normal, false, mods);
7627 document.Activate();
7633 virtual bool OnCreate(void);
7634 virtual void OnDestroy(void);
7635 virtual void OnDestroyed(void);
7636 virtual bool OnClose(bool parentClosing);
7637 virtual bool OnStateChange(WindowState state, Modifiers mods);
7638 virtual bool OnPostCreate(void);
7639 virtual bool OnMoving(int *x, int *y, int w, int h);
7640 virtual bool OnResizing(int *width, int *height);
7641 virtual void OnResize(int width, int height);
7642 virtual void OnPosition(int x, int y, int width, int height);
7643 virtual bool OnLoadGraphics(void);
7644 virtual void OnApplyGraphics(void);
7645 virtual void OnUnloadGraphics(void);
7646 virtual void OnRedraw(Surface surface);
7647 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7648 virtual void OnActivateClient(Window client, Window previous);
7649 virtual bool OnKeyDown(Key key, unichar ch);
7650 virtual bool OnKeyUp(Key key, unichar ch);
7651 virtual bool OnKeyHit(Key key, unichar ch);
7652 virtual bool OnSysKeyDown(Key key, unichar ch);
7653 virtual bool OnSysKeyUp(Key key, unichar ch);
7654 virtual bool OnSysKeyHit(Key key, unichar ch);
7655 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7656 virtual bool OnMouseLeave(Modifiers mods);
7657 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7658 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7659 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
7660 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
7661 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
7662 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
7663 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
7664 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
7665 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
7666 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
7667 virtual void OnMouseCaptureLost(void);
7668 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
7669 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
7670 virtual void OnDrawOverChildren(Surface surface);
7671 virtual bool OnFileModified(FileChange fileChange, char * param);
7672 virtual bool OnSaveFile(char * fileName);
7674 // Virtual Methods -- Children management (To support Stacker, for lack of built-in auto-layout)
7675 // Note: A 'client' would refer to isActiveClient, rather than
7676 // being confined to the 'client area' (nonClient == false)
7677 virtual void OnChildAddedOrRemoved(Window child, bool removed);
7678 virtual void OnChildVisibilityToggled(Window child, bool visible);
7679 virtual void OnChildResized(Window child, int x, int y, int w, int h);
7681 // Skins Virtual Functions
7682 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
7683 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
7684 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
7689 virtual void ShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7690 virtual void PreShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7691 virtual bool IsMouseMoving(int x, int y, int w, int h);
7692 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY);
7693 virtual void UpdateNonClient();
7694 virtual void SetBox(Box box);
7695 virtual bool IsInside(int x, int y)
7697 return box.IsPointInside({x, y});
7699 virtual bool IsOpaque()
7701 return (!style.drawBehind || background.a == 255);
7705 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
7706 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
7707 virtual void Window::NotifySaved(Window window, char * filePath);
7712 property Window parent
7714 property_category $"Layout"
7717 if(value || guiApp.desktop)
7720 Window oldParent = parent;
7721 Anchor anchor = this.anchor;
7723 if(value && value.IsDescendantOf(this)) return;
7724 if(value && value == this)
7726 if(!value) value = guiApp.desktop;
7728 if(value == oldParent) return;
7730 if(!master || (master == this.parent && master == guiApp.desktop))
7731 property::master = value;
7735 parent.children.Remove(this);
7736 parent.OnChildAddedOrRemoved(this, true);
7740 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7741 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
7742 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7743 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
7747 last = value.children.last;
7749 if(style.isDocument)
7752 parent.numDocuments--;
7753 documentID = value.GetDocumentID();
7756 if(style.isActiveClient && !style.hidden)
7758 if(parent && parent != guiApp.desktop && !(style.hidden))
7760 if(state == minimized) parent.numIcons--;
7761 parent.numPositions--;
7765 if(!style.stayOnTop)
7766 for(; last && last.style.stayOnTop; last = last.prev);
7768 value.children.Insert(last, this);
7770 // *** NEW HERE: ***
7772 parent.childrenCycle.Delete(cycle);
7774 parent.childrenOrder.Delete(order);
7782 int x = position.x, y = position.y, w = size.w, h = size.h;
7786 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
7787 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
7789 vpw = value.clientSize.w;
7790 vph = value.clientSize.h;
7796 else if(style.fixed)
7798 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
7799 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
7802 anchor = this.anchor;
7804 if(anchor.left.type == offset) anchor.left.distance = x;
7805 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
7806 if(anchor.top.type == offset) anchor.top.distance = y;
7807 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
7808 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
7809 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
7810 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
7811 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
7812 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
7813 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
7815 if(!anchor.left.type && !anchor.right.type)
7817 anchor.horz.distance = (x + w / 2) - (vpw / 2);
7818 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
7820 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
7821 if(!anchor.top.type && !anchor.bottom.type)
7823 anchor.vert.distance = (y + h / 2) - (vph / 2);
7824 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
7826 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
7829 parent.OnChildAddedOrRemoved(this, false);
7835 parent.childrenCycle.Insert(
7836 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
7837 cycle = OldLink { data = this });
7838 parent.childrenOrder.Insert(
7839 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
7840 order = OldLink { data = this });
7843 if(!style.hidden && style.isActiveClient)
7845 positionID = parent.GetPositionID(this);
7846 parent.numPositions++;
7847 if(state == minimized) parent.numIcons--;
7850 // *** FONT INHERITANCE ***
7851 if(!setFont && oldParent)
7852 stopwatching(oldParent, font);
7856 RemoveResource(systemFont);
7859 // TESTING WITH WATCHERS:
7860 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7861 // usedFont = setFont ? setFont : (systemFont);
7865 if(guiApp.currentSkin)
7867 systemFont = guiApp.currentSkin.SystemFont();
7870 usedFont = systemFont;
7871 AddResource(systemFont);
7879 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7888 if(value.rootWindow && value.rootWindow.display && rootWindow)
7890 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
7891 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
7894 UnloadGraphics(false);
7897 LoadGraphics(false, false);
7900 if(value.rootWindow != rootWindow)
7901 DisplayModeChanged();
7905 scrolledPos.x = MININT; // Prevent parent update
7906 property::anchor = anchor;
7910 if(guiApp.currentSkin)
7911 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
7913 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7914 Position(x, y, w, h, true, true, true, true, false, true);
7919 // else parent = value;
7922 get { return parent; }
7925 property Window master
7927 property_category $"Behavior"
7930 //if(this == value) return;
7931 if(value && value.IsSlaveOf(this)) return;
7937 OldLink slaveHolder;
7938 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
7939 if(slaveHolder.data == this)
7941 master.slaves.Delete(slaveHolder);
7948 value.slaves.Add(OldLink { data = this });
7953 master.hotKeys.Remove(hotKey);
7954 value.hotKeys.Add(hotKey);
7957 if(master && master.defaultControl == this)
7958 master.defaultControl = null;
7960 if(style.isDefault && !value.defaultControl)
7961 value.defaultControl = this;
7966 get { return master ? master : parent; }
7969 property char * caption
7971 property_category $"Appearance"
7978 caption = new char[strlen(value)+1];
7980 strcpy(caption, value);
7985 get { return caption; }
7990 property_category $"Behavior"
7999 master.hotKeys.Add(hotKey = HotKeySlot { });
8003 hotKey.window = this;
8008 master.hotKeys.Delete(hotKey);
8013 get { return hotKey ? hotKey.key : 0; }
8016 property Color background
8018 property_category $"Appearance"
8021 background.color = value;
8026 if(this == rootWindow)
8027 guiApp.interfaceDriver.SetRootWindowColor(this);
8030 get { return background.color; }
8033 property Percentage opacity
8035 property_category $"Appearance"
8038 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
8039 drawBehind = background.a ? false : true;
8041 get { return background.a / 255.0f; }
8044 property Color foreground
8046 property_category $"Appearance"
8054 get { return foreground; }
8057 property BorderStyle borderStyle
8059 property_category $"Appearance"
8062 if(!((BorderBits)value).fixed)
8064 style.hasClose = false;
8065 style.hasMaximize = false;
8066 style.hasMinimize = false;
8067 nativeDecorations = false;
8069 style.borderBits = value;
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);
8077 CreateSystemChildren();
8080 get { return (BorderStyle)style.borderBits; }
8083 property Size minClientSize
8085 property_category $"Layout"
8086 set { minSize = value; }
8087 get { value = minSize; }
8090 property Size maxClientSize
8092 property_category $"Layout"
8093 set { maxSize = value; }
8094 get { value = maxSize; }
8097 property bool hasMaximize
8099 property_category $"Window Style"
8102 style.hasMaximize = value;
8103 if(value) { style.fixed = true; style.contour = true; }
8107 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8109 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8110 Position(x, y, w, h, true, true, true, true, false, true);
8112 CreateSystemChildren();
8115 get { return style.hasMaximize; }
8118 property bool hasMinimize
8120 property_category $"Window Style"
8123 style.hasMinimize = value;
8124 if(value) { style.fixed = true; style.contour = true; }
8128 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8130 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8131 Position(x, y, w, h, true, true, true, true, false, true);
8133 CreateSystemChildren();
8136 get { return style.hasMinimize; }
8139 property bool hasClose
8141 property_category $"Window Style"
8144 style.hasClose = value;
8145 if(value) { style.fixed = true; style.contour = true; }
8149 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8150 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8151 Position(x, y, w, h, true, true, true, true, false, true);
8152 CreateSystemChildren();
8155 get { return style.hasClose; }
8158 property bool nonClient
8160 property_category $"Layout"
8163 style.nonClient = value;
8165 style.stayOnTop = true;
8167 get { return style.nonClient; }
8170 property bool inactive
8172 property_category $"Behavior"
8177 // *** NEW HERE: ***
8181 parent.childrenCycle.Delete(cycle);
8183 parent.childrenOrder.Delete(order);
8190 active = false; // true;
8191 if(parent.activeChild == this)
8192 parent.activeChild = null;
8193 if(parent.activeClient == this)
8194 parent.activeClient = null;
8203 parent.childrenCycle.Insert(
8204 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8205 cycle = OldLink { data = this });
8207 parent.childrenOrder.Insert(
8208 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8209 order = OldLink { data = this });
8212 style.inactive = value;
8214 get { return style.inactive; }
8217 property bool clickThrough
8219 property_category $"Behavior"
8220 set { style.clickThrough = value; }
8221 get { return style.clickThrough; }
8224 property bool isRemote
8226 property_category $"Behavior"
8227 set { style.isRemote = value; }
8228 get { return style.isRemote; }
8231 property bool noCycle
8233 property_category $"Behavior"
8234 set { style.noCycle = value; }
8235 get { return style.noCycle; }
8238 property bool isModal
8240 property_category $"Behavior"
8241 set { style.modal = value; }
8242 get { return style.modal; }
8245 property bool interim
8247 property_category $"Behavior"
8248 set { style.interim = value; }
8249 get { return style.interim; }
8252 property bool tabCycle
8254 property_category $"Behavior"
8255 set { style.tabCycle = value; }
8256 get { return style.tabCycle; }
8259 property bool isDefault
8261 property_category $"Behavior"
8269 /*for(sibling = parent.children.first; sibling; sibling = sibling.next)
8270 if(sibling != this && sibling.style.isDefault)
8271 sibling.style.isDefault = false;*/
8272 if(master.defaultControl)
8273 master.defaultControl.style.isDefault = false;
8274 master.defaultControl = this;
8276 else if(master.defaultControl == this)
8277 master.defaultControl = null;
8281 style.isDefault = value;
8283 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8285 get { return style.isDefault; }
8288 property bool drawBehind
8290 property_category $"Window Style"
8291 set { style.drawBehind = value; }
8292 get { return style.drawBehind; }
8295 property bool hasMenuBar
8297 property_category $"Window Style"
8307 if(created && !menuBar)
8314 anchor = Anchor { top = 23, left = 1, right = 1 },
8316 inactive = true, nonClient = true
8321 else if(created && menuBar)
8326 style.hasMenuBar = value;
8328 get { return style.hasMenuBar; }
8331 property bool hasStatusBar
8333 property_category $"Window Style"
8340 statusBar = StatusBar { this };
8348 style.hasStatusBar = value;
8350 get { return style.hasStatusBar; }
8352 property bool stayOnTop
8354 property_category $"Window Style"
8359 if(created && !style.stayOnTop)
8361 if(rootWindow == this)
8362 guiApp.interfaceDriver.OrderRootWindow(this, true);
8363 else if(parent.children.last != this)
8365 parent.children.Move(this, parent.children.last);
8369 style.stayOnTop = true;
8373 if(created && style.stayOnTop)
8375 if(rootWindow == this)
8376 guiApp.interfaceDriver.OrderRootWindow(this, false);
8383 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8384 order && ((Window)order.data).style.stayOnTop;
8385 order = (order == parent.childrenOrder.first) ? null : order.prev);
8386 last = order ? order.data : null;
8390 for(last = parent.children.last;
8391 last && last.style.stayOnTop;
8395 parent.children.Move(this, last);
8399 style.stayOnTop = false;
8402 get { return style.stayOnTop; }
8407 property_category $"Window Style"
8417 if(menuBar && !value)
8424 if(!menuBar && style.hasMenuBar && value)
8428 this, menu = value, isMenuBar = true,
8429 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8430 inactive = true, nonClient = true
8434 UpdateActiveDocument(null);
8437 get { return menu; }
8440 property FontResource font
8442 property_category $"Appearance"
8444 isset { return setFont ? true : false; }
8449 if(value && !setFont) { stopwatching(parent, font); }
8450 else if(!value && setFont)
8456 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8465 RemoveResource(setFont);
8470 RemoveResource(systemFont);
8477 AddResource(setFont);
8480 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8483 systemFont = guiApp.currentSkin.SystemFont();
8485 usedFont = systemFont;
8486 AddResource(systemFont);
8494 get { return usedFont; }
8497 property SizeAnchor sizeAnchor
8499 property_category $"Layout"
8502 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8503 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8504 sizeAnchor.isClientW != sizeAnchor.isClientH;
8511 normalSizeAnchor = sizeAnchor;
8513 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8515 stateAnchor = normalAnchor;
8516 stateSizeAnchor = normalSizeAnchor;
8518 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8519 Position(x,y, w, h, true, true, true, true, false, true);
8526 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8527 sizeAnchor.isClientW,
8528 sizeAnchor.isClientH
8535 property_category $"Layout"
8538 Anchor thisAnchor = anchor;
8539 SizeAnchor thisSizeAnchor = sizeAnchor;
8540 bool leftRight = (anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none);
8541 bool topBottom = (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none);
8542 bool isClient = !sizeAnchor.isClientW && !sizeAnchor.isClientH;
8543 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8544 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8545 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8551 sizeAnchor.isClientW = false;
8552 sizeAnchor.isClientH = false;
8553 sizeAnchor.size = value;
8555 normalSizeAnchor = sizeAnchor;
8557 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8559 stateAnchor = normalAnchor;
8560 stateSizeAnchor = normalSizeAnchor;
8562 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8563 Position(x, y, w, h, true, true, true, true, false, true);
8564 if(parent && parent.created && !nonClient) parent.OnChildResized(this, x, y, w, h);
8567 get { value = size; }
8570 property Size clientSize
8572 property_category $"Layout"
8575 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8576 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8577 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8582 sizeAnchor.isClientW = true;
8583 sizeAnchor.isClientH = true;
8584 sizeAnchor.size = value;
8586 normalSizeAnchor = sizeAnchor;
8588 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8590 stateAnchor = normalAnchor;
8591 stateSizeAnchor = normalSizeAnchor;
8593 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8594 Position(x,y, w, h, true, true, true, true, false, true);
8597 get { value = clientSize; }
8600 property Size initSize { get { value = sizeAnchor.size; } };
8602 property Anchor anchor
8604 property_category $"Layout"
8605 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8611 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8613 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8614 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8616 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8618 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8619 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8623 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8625 anchor.left.distance = 0;
8626 anchor.horz.type = 0;
8628 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8630 anchor.top.distance = 0;
8631 anchor.vert.type = 0;
8640 normalAnchor = anchor;
8642 // Break the anchors for moveable/resizable windows
8643 /*if(style.fixed ) //&& value.left.type == cascade)
8645 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
8647 this.anchor = normalAnchor = Anchor { left = x, top = y };
8648 normalSizeAnchor = SizeAnchor { { w, h } };
8651 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8653 stateAnchor = normalAnchor;
8654 stateSizeAnchor = normalSizeAnchor;
8656 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8657 Position(x, y, w, h, true, true, true, true, false, true);
8666 get { value = this ? anchor : Anchor { }; }
8669 property Point position
8671 property_category $"Layout"
8674 if(value == null) return;
8676 anchor.left = value.x;
8677 anchor.top = value.y;
8678 anchor.right.type = none;
8679 anchor.bottom.type = none;
8684 normalAnchor = anchor;
8686 // Break the anchors for moveable/resizable windows
8690 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8692 normalAnchor.left = x;
8693 normalAnchor.top = y;
8694 normalAnchor.right.type = none;
8695 normalAnchor.bottom.type = none;
8696 normalSizeAnchor.size.width = w;
8697 normalSizeAnchor.size.height = h;
8701 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8703 stateAnchor = normalAnchor;
8704 stateSizeAnchor = normalSizeAnchor;
8706 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8707 Position(x,y, w, h, true, true, true, true, false, true);
8711 get { value = position; }
8714 property bool disabled
8716 property_category $"Behavior"
8719 if(this && disabled != value)
8726 get { return (bool)disabled; }
8729 property bool isEnabled
8734 for(parent = this; parent; parent = parent.parent)
8741 property WindowState state
8743 property_category $"Behavior"
8744 set { SetState(value, false, 0); }
8745 get { return this ? state : 0; }
8748 property bool visible
8750 property_category $"Behavior"
8753 if(this && !value && !style.hidden && parent)
8755 bool wasActiveChild = parent.activeChild == this;
8756 Window client = null;
8758 style.hidden = true;
8759 if(style.isActiveClient)
8761 parent.numPositions--;
8762 if(state == minimized) parent.numIcons--;
8767 OldLink prevOrder = null;
8769 if(rootWindow == this)
8770 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
8773 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
8776 box.left -= parent.clientStart.x;
8777 box.top -= parent.clientStart.y;
8778 box.right -= parent.clientStart.x;
8779 box.bottom -= parent.clientStart.y;
8783 if(_isModal && master && master.modalSlave == this)
8784 master.modalSlave = null;
8788 OldLink tmpPrev = order.prev;
8789 client = tmpPrev ? tmpPrev.data : null;
8790 if(client && !client.style.hidden && !client.destroyed && client.created)
8791 prevOrder = tmpPrev;
8794 client = tmpPrev ? tmpPrev.data : null;
8795 if(client == this) { client = null; break; }
8796 if(client && ((client.style.hidden) || client.destroyed || !client.created))
8798 tmpPrev = client.order.prev;
8803 prevOrder = tmpPrev;
8808 // If this window can be an active client, make sure the next window we activate can also be one
8809 if(!style.nonClient && style.isActiveClient)
8811 tmpPrev = prevOrder;
8814 client = tmpPrev ? tmpPrev.data : null;
8815 if(client == this) { client = null; break; }
8816 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
8818 tmpPrev = client.order.prev;
8823 prevOrder = tmpPrev;
8827 if(client && client.style.hidden) client = null;
8831 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
8833 if(order && prevOrder && prevOrder.data != this)
8834 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
8836 ActivateEx(false, false, false, true, null, null);
8838 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
8839 if(parent.activeClient == this)
8841 parent.activeClient = null;
8842 parent.UpdateActiveDocument(null);
8845 else if(parent.activeClient == this)
8847 parent.activeClient = client;
8848 parent.UpdateActiveDocument(this);
8851 // *** Not doing this anymore ***
8854 parent.childrenCycle.Delete(cycle);
8856 parent.childrenOrder.Delete(order);
8861 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8866 else if(this && value && style.hidden)
8868 style.hidden = false;
8871 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8872 if(rootWindow == this)
8873 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
8875 if(_isModal && master)
8876 master.modalSlave = this;
8878 if(style.isActiveClient)
8880 positionID = parent.GetPositionID(this);
8881 parent.numPositions++;
8882 if(state == minimized) parent.numIcons++;
8885 // *** NOT DOING THIS ANYMORE ***
8887 if(!(style.inactive))
8889 if(!(style.noCycle))
8891 cycle = parent.childrenCycle.AddAfter(
8892 (parent.activeChild && parent.activeChild.cycle) ?
8893 parent.activeChild.cycle.prev : null, sizeof(OldLink));
8896 order = parent.childrenOrder.AddAfter(
8897 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8904 if(true || !parent.activeChild)
8905 ActivateEx(true, false, true, true, null, null);
8907 if(creationActivation == activate)
8908 ActivateEx(true, false, true, true, null, null);
8909 else if(creationActivation == flash && !object)
8912 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8916 ConsequentialMouseMove(false);
8922 style.hidden = !value;
8925 get { return (style.hidden || !setVisible) ? false : true; }
8928 property bool isDocument
8930 property_category $"Document"
8931 set { style.isDocument = value; }
8932 get { return style.isDocument; }
8935 property bool mergeMenus
8937 property_category $"Window Style"
8938 set { mergeMenus = value; }
8939 get { return (bool)mergeMenus; }
8942 property bool hasHorzScroll
8944 property_category $"Window Style"
8949 if(!style.hasHorzScroll && created)
8951 CreateSystemChildren();
8952 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8955 else if(style.hasHorzScroll)
8959 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8961 style.hasHorzScroll = value;
8964 get { return style.hasHorzScroll; }
8967 property bool hasVertScroll
8969 property_category $"Window Style"
8974 if(!style.hasVertScroll && created)
8976 style.hasVertScroll = true;
8977 CreateSystemChildren();
8978 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8981 else if(style.hasVertScroll)
8985 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8987 style.hasVertScroll = value;
8989 get { return style.hasVertScroll; }
8992 property bool dontHideScroll
8994 property_category $"Behavior"
8997 scrollFlags.dontHide = value;
9000 //UpdateScrollBars(true, true);
9001 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9005 // UpdateScrollBars(true, true);
9006 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
9009 get { return scrollFlags.dontHide; }
9012 property bool dontScrollVert
9014 property_category $"Behavior"
9015 set { style.dontScrollVert = value; }
9016 get { return style.dontScrollVert; }
9018 property bool dontScrollHorz
9020 property_category $"Behavior"
9021 set { style.dontScrollHorz = value; }
9022 get { return style.dontScrollHorz; }
9025 property bool snapVertScroll
9027 property_category $"Behavior"
9030 scrollFlags.snapY = value;
9031 if(sbv) sbv.snap = value;
9033 get { return scrollFlags.snapY; }
9035 property bool snapHorzScroll
9037 property_category $"Behavior"
9040 scrollFlags.snapX = value;
9041 if(sbh) sbh.snap = value;
9043 get { return scrollFlags.snapX; }
9046 property Point scroll
9048 property_category $"Behavior"
9052 // TESTING THIS IMPLEMENTATION:
9053 SetScrollPosition(value.x, value.y);
9055 get { value = scroll; }
9058 property bool modifyVirtualArea
9060 property_category $"Behavior"
9061 set { modifyVirtArea = value; }
9062 get { return (bool)modifyVirtArea; }
9065 property char * fileName
9067 property_category $"Document"
9070 if(menu && ((!fileName && value) || (fileName && !value)))
9072 MenuItem item = menu.FindItem(MenuFileSave, 0);
9073 if(item) item.disabled = !modifiedDocument && value;
9078 if(value && value[0])
9079 fileName = CopyString(value);
9081 if(parent && this == parent.activeClient)
9082 parent.UpdateActiveDocument(null);
9086 // if(style.isDocument)
9088 fileMonitor.fileName = value;
9090 get { return fileName; }
9095 property_category $"Data"
9100 property bool modifiedDocument
9102 property_category $"Document"
9105 if(style.isDocument || fileName)
9109 MenuItem item = menu.FindItem(MenuFileSave, 0);
9110 if(item) item.disabled = !value && fileName;
9114 if(modifiedDocument != value)
9116 modifiedDocument = value;
9117 if(style.isDocument || fileName)
9121 get { return (bool)modifiedDocument; }
9124 property bool showInTaskBar
9126 property_category $"Window Style"
9127 set { style.showInTaskBar = value; }
9128 get { return (style.showInTaskBar; }
9130 property FileDialog saveDialog { set { saveDialog = value; } };
9131 property bool isActiveClient
9133 property_category $"Behavior"
9134 set { style.isActiveClient = value; }
9135 get { return style.isActiveClient; }
9138 property Cursor cursor
9140 property_category $"Appearance"
9144 SelectMouseCursor();
9146 get { return cursor; }
9149 //#if !defined(ECERE_VANILLA)
9150 property char * name
9152 property_category $"Design"
9155 return (this && object) ? object.name : null;
9160 activeDesigner.RenameObject(object, value);
9164 property char * displayDriver
9166 property_category $"Behavior"
9169 dispDriver = GetDisplayDriver(value);
9170 //DisplayModeChanged();
9174 return dispDriver ? dispDriver.name : null;
9178 // RUNTIME PROPERTIES
9179 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9180 property Size scrollArea
9182 property_category $"Behavior"
9186 SetScrollArea(value.w, value.h, false);
9188 SetScrollArea(0,0, true);
9190 get { value = scrollArea; }
9193 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9198 property_category $"Layout"
9199 set { if(this) is3D = value; }
9200 get { return (bool)is3D; }
9203 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9205 // Will be merged with font later
9206 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9207 property Point clientStart { get { value = clientStart; } };
9208 property Point absPosition { get { value = absPosition; } };
9209 property Anchor normalAnchor { get {value = normalAnchor; } };
9210 // property Size normalSizeAnchor { get { value = normalSizeAnchor; } };
9211 property bool active { get { return (bool)active; } };
9212 property bool created { get { return (bool)created; } };
9213 property bool destroyed { get { return (bool)destroyed; } };
9214 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9215 property Window firstChild { get { return children.first; } };
9216 property Window lastChild { get { return children.last; } };
9217 property Window activeClient { get { return activeClient; } };
9218 property Window activeChild { get { return activeChild; } };
9219 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9220 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9221 property ScrollBar horzScroll { get { return sbh; } };
9222 property ScrollBar vertScroll { get { return sbv; } };
9223 property StatusBar statusBar { get { return statusBar; } };
9224 property Window rootWindow { get { return rootWindow; } };
9225 property bool closing { get { return (bool)closing; } set { closing = value; } };
9226 property int documentID { get { return documentID; } };
9227 property Window previous { get { return prev; } }
9228 property Window next { get { return next; } }
9229 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9230 property PopupMenu menuBar { get { return menuBar; } }
9231 property ScrollBar sbv { get { return sbv; } }
9232 property ScrollBar sbh { get { return sbh; } }
9233 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9234 property void * systemHandle { get { return windowHandle; } }
9235 property Button minimizeButton { get { return sysButtons[0]; } };
9236 property Button maximizeButton { get { return sysButtons[1]; } };
9237 property Button closeButton { get { return sysButtons[2]; } };
9238 property BitmapResource icon
9240 get { return icon; }
9244 if(icon) incref icon;
9246 guiApp.interfaceDriver.SetIcon(this, value);
9249 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9250 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } };
9251 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9252 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9253 property bool nativeDecorations
9255 get { return (bool)nativeDecorations; }
9256 set { nativeDecorations = value; }
9257 #ifndef ECERE_VANILLA
9258 isset { return (nativeDecorations && (rootWindow == this || (formDesigner && activeDesigner && ((FormDesigner)activeDesigner.classDesigner).form && parent == ((FormDesigner)activeDesigner.classDesigner).form.parent))) != style.fixed; }
9261 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9263 property char * text
9265 property_category $"Deprecated"
9267 set { property::caption = value; }
9268 get { return property::caption; }
9274 WindowBits style; // Window Style
9275 char * caption; // Name / Caption
9276 Window parent; // Parent window
9277 OldList children; // List of children in Z order
9278 Window activeChild; // Child window having focus
9279 Window activeClient;
9280 Window previousActive; // Child active prior to activating the default child
9281 Window master; // Window owning and receiving notifications concerning this window
9282 OldList slaves; // List of windows belonging to this window
9283 Display display; // Display this window is drawn into
9285 Point position; // Position in parent window client area
9286 Point absPosition; // Absolute position
9287 Point clientStart; // Client area position from (0,0) in this window
9289 Size clientSize; // Client area size
9290 Size scrollArea; // Virtual Scroll area size
9291 Size reqScrollArea; // Requested virtual area size
9292 Point scroll; // Virtual area scrolling position
9293 public ScrollBar sbh, sbv; // Scrollbar window handles
9294 Cursor cursor; // Mouse cursor used for this window
9297 StatusBar statusBar;
9298 Button sysButtons[3];
9300 Box clientArea; // Client Area box clipped to parent
9302 HotKeySlot hotKey; // HotKey for this window
9306 ScrollFlags scrollFlags;// Window Scrollbar Flags
9307 int id; // Control ID
9309 ColorAlpha background; // Background color used to draw the window area
9311 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9312 OldList childrenCycle; // Cycling order
9313 OldLink cycle; // Element of parent's cycling order
9314 OldList childrenOrder; // Circular Z-Order
9315 OldLink order; // Element of parent's circular Z-Order
9316 Window modalSlave; // Slave window blocking this window's interaction
9318 Window rootWindow; // Topmost system managed window
9319 void * windowHandle; // System window handle
9321 DialogResult returnCode;// Return code for modal windows
9323 Point sbStep; // Scrollbar line scrolling steps
9326 SizeAnchor stateSizeAnchor;
9328 Anchor normalAnchor;
9329 SizeAnchor normalSizeAnchor;
9331 Size skinMinSize; // Minimal window size based on style
9332 Point scrolledPos; // Scrolled position
9333 Box box; // Window box clipped to parent
9334 Box * against; // What to clip the box to
9336 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9337 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9338 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9339 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9340 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9341 Point scrolledArea; // Distance to scroll area by
9342 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9344 OldList hotKeys; // List of the hotkeys of all children
9345 Window defaultControl; // Default child control
9349 ColorAlpha * palette; // Color palette used for this window
9351 int caretSize; // Size of caret, non zero if a caret is present
9352 Point caretPos; // Caret position
9354 void * systemParent; // Parent System Window for embedded windows
9361 WindowState lastState;
9363 FileMonitor fileMonitor
9365 this, FileChange { modified = true };
9367 bool OnFileNotify(FileChange action, char * param)
9370 fileMonitor.StopMonitoring();
9371 if(OnFileModified(action, param))
9372 fileMonitor.StartMonitoring();
9377 FontResource setFont, systemFont;
9378 FontResource usedFont;
9379 FontResource captionFont;
9381 FileDialog saveDialog;
9383 SizeAnchor sizeAnchor;
9385 // FormDesigner data
9388 Extent * tempExtents; //[4];
9389 BitmapResource icon;
9391 CreationActivationOption creationActivation;
9394 bool active:1; // true if window and ancestors are active
9395 bool acquiredInput:1; // true if the window is processing state based input
9396 bool modifiedDocument:1;
9397 bool disabled:1; // true if window cannot interact
9398 bool isForegroundWindow:1;// true while a root window is being activated
9399 bool visible:1; // Visibility flag
9400 bool destroyed:1; // true if window is being destroyed
9401 bool anchored:1; // true if this window is repositioned when the parent resizes
9402 bool dirty:1; // Flag set to true if any descendant must be redrawn
9408 bool modifyVirtArea:1;
9409 bool noAutoScrollArea:1;
9412 bool setVisible:1; // FOR FORM DESIGNER
9418 bool useSharedMemory:1;
9421 bool nativeDecorations:1;
9422 bool manageDisplay:1;
9423 bool formDesigner:1; // True if we this is running in the form editor
9426 // Checks used internally for them not to take effect in FormDesigner
9427 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9428 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9430 WindowController controller;
9431 public property WindowController controller { get { return controller; } set { delete controller; controller = value; if(controller) incref controller; } }
9434 public class CommonControl : Window
9436 // creationActivation = doNothing;
9439 public property String toolTip
9441 property_category $"Appearance"
9444 if(created) CommonControl::OnDestroy();
9446 toolTip = value ? ToolTip { tip = value; } : null;
9448 if(created) CommonControl::OnCreate();
9450 get { return toolTip ? toolTip.tip : null; }
9456 // (Very) Ugly work around for the fact that the parent watcher
9457 // won't fire when it's already been disconnected...
9458 eInstance_FireSelfWatchers(toolTip,
9459 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
9465 toolTip.parent = this;
9474 public class Percentage : float
9476 char * OnGetString(char * string, float * fieldData, bool * needClass)
9480 sprintf(string, "%.2f", this);
9481 c = strlen(string)-1;
9484 if(string[c] != '0')
9485 last = Max(last, c);
9486 if(string[c] == '.')
9499 public void ApplySkin(Class c, char * name, void ** vTbl)
9501 char className[1024];
9506 subclass(Window) wc = (subclass(Window))c;
9507 subclass(Window) base = (subclass(Window))c.base;
9509 sprintf(className, "%sSkin_%s", name, c.name);
9510 wc.pureVTbl = c._vTbl;
9511 c._vTbl = new void *[c.vTblSize];
9512 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9513 sc = eSystem_FindClass(c.module.application, className);
9517 for(m = 0; m < c.base.vTblSize; m++)
9519 if(c._vTbl[m] == base.pureVTbl[m])
9520 c._vTbl[m] = vTbl[m];
9525 for(m = 0; m < c.vTblSize; m++)
9527 if(sc._vTbl[m] != wc.pureVTbl[m])
9528 c._vTbl[m] = sc._vTbl[m];
9532 for(d = c.derivatives.first; d; d = d.next)
9534 ApplySkin(d.data, name, c._vTbl);
9538 public void UnapplySkin(Class c)
9540 char className[1024];
9542 subclass(Window) wc = (subclass(Window))c;
9543 subclass(Window) base = (subclass(Window))c.base;
9546 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9549 c._vTbl = wc.pureVTbl;
9553 for(d = c.derivatives.first; d; d = d.next)
9555 UnapplySkin(d.data);
9559 void CheckFontIntegrity(Window window)
9564 if(window.usedFont && window.usedFont.font == 0xecececec)
9566 FontResource uf = window.usedFont;
9567 char * className = window._class.name;
9568 char * text = window.text;
9571 for(c = window.firstChild; c; c = c.next)
9572 CheckFontIntegrity(c);
9576 public class ControllableWindow : Window
9578 /*WindowController controller;
9579 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9580 ~ControllableWindow() { delete controller; }*/
9583 class WindowControllerInterface : ControllableWindow
9585 bool OnKeyDown(Key key, unichar ch)
9587 bool result = ((int(*)())(void *)controller.OnKeyDown)((void *)controller.controlled, (void *)controller, key, ch);
9589 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown](controller.window, key, ch);
9593 bool OnKeyUp(Key key, unichar ch)
9595 bool result = ((int(*)())(void *)controller.OnKeyUp)((void *)controller.controlled, (void *)controller, key, ch);
9597 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp](controller.window, key, ch);
9601 bool OnKeyHit(Key key, unichar ch)
9603 bool result = ((int(*)())(void *)controller.OnKeyHit)((void *)controller.controlled, (void *)controller, key, ch);
9605 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit](controller.window, key, ch);
9609 bool OnMouseMove(int x, int y, Modifiers mods)
9611 bool result = ((int(*)())(void *)controller.OnMouseMove)((void *)controller.controlled, (void *)controller, x, y, mods);
9613 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove](controller.window, x, y, mods);
9617 bool OnLeftButtonDown(int x, int y, Modifiers mods)
9619 bool result = ((int(*)())(void *)controller.OnLeftButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9621 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown](controller.window, x, y, mods);
9625 bool OnLeftButtonUp(int x, int y, Modifiers mods)
9627 bool result = ((int(*)())(void *)controller.OnLeftButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9629 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp](controller.window, x, y, mods);
9633 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
9635 bool result = ((int(*)())(void *)controller.OnLeftDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9637 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick](controller.window, x, y, mods);
9641 bool OnRightButtonDown(int x, int y, Modifiers mods)
9643 bool result = ((int(*)())(void *)controller.OnRightButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9645 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown](controller.window, x, y, mods);
9649 bool OnRightButtonUp(int x, int y, Modifiers mods)
9651 bool result = ((int(*)())(void *)controller.OnRightButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9653 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp](controller.window, x, y, mods);
9657 bool OnRightDoubleClick(int x, int y, Modifiers mods)
9659 bool result = ((int(*)())(void *)controller.OnRightDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9661 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick](controller.window, x, y, mods);
9665 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
9667 bool result = ((int(*)())(void *)controller.OnMiddleButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9669 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown](controller.window, x, y, mods);
9673 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
9675 bool result = ((int(*)())(void *)controller.OnMiddleButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9677 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp](controller.window, x, y, mods);
9681 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
9683 bool result = ((int(*)())(void *)controller.OnMiddleDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9685 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick](controller.window, x, y, mods);
9689 void OnResize(int width, int height)
9691 ((int(*)())(void *)controller.OnResize)((void *)controller.controlled, (void *)controller, width, height);
9692 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize](controller.window, width, height);
9695 void OnRedraw(Surface surface)
9697 ((int(*)())(void *)controller.OnRedraw)((void *)controller.controlled, (void *)controller, surface);
9698 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw](controller.window, surface);
9703 bool result = ((int(*)())(void *)controller.OnCreate)((void *)controller.controlled, (void *)controller);
9705 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
9709 bool OnLoadGraphics()
9711 bool result = ((int(*)())(void *)controller.OnLoadGraphics)((void *)controller.controlled, (void *)controller);
9713 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLoadGraphics](controller.window);
9717 void OnUnloadGraphics()
9719 ((int(*)())(void *)controller.OnUnloadGraphics)((void *)controller.controlled, (void *)controller);
9720 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnUnloadGraphics](controller.window);
9724 public class WindowController<class V>
9727 property Window window
9731 uint size = class(Window).vTblSize;
9734 windowVTbl = new void *[size];
9735 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
9736 if(value._vTbl == value._class._vTbl)
9738 value._vTbl = new void *[value._class.vTblSize];
9739 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
9743 for(c = 0; c < size; c++)
9745 void * function = class(WindowControllerInterface)._vTbl[c];
9746 if(function != DefaultFunction)
9747 value._vTbl[c] = function;
9749 value._vTbl[c] = windowVTbl[c];
9754 memcpy(value._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
9757 get { return window; }
9759 property V controlled
9761 set { controlled = value; }
9762 get { return controlled; }
9764 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
9765 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
9766 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
9767 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
9768 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
9769 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
9770 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9771 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
9772 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
9773 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9774 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
9775 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
9776 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9777 virtual void V::OnResize(WindowController controller, int width, int height);
9778 virtual void V::OnRedraw(WindowController controller, Surface surface);
9779 virtual bool V::OnCreate(WindowController controller);
9780 virtual bool V::OnLoadGraphics(WindowController controller);
9781 virtual void V::OnUnloadGraphics(WindowController controller);
9784 int (** windowVTbl)();